NetSurf
treeview.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 - 2013 Michael Drake <tlsa@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 *
22 * Treeview handling implementation.
23 */
24
25#include "utils/config.h"
26
27#include <string.h>
28
29#include "utils/utils.h"
30#include "utils/log.h"
31#include "utils/nsurl.h"
32#include "utils/nscolour.h"
33#include "utils/nsoption.h"
34#include "netsurf/bitmap.h"
35#include "netsurf/content.h"
36#include "netsurf/plotters.h"
37#include "netsurf/clipboard.h"
38#include "netsurf/layout.h"
39#include "netsurf/keypress.h"
40#include "netsurf/core_window.h"
41#include "content/hlcache.h"
42#include "css/utils.h"
43
44#include "desktop/bitmap.h"
45#include "desktop/knockout.h"
46#include "desktop/textarea.h"
47#include "desktop/treeview.h"
48#include "desktop/cw_helper.h"
51
52/**
53 * The maximum horizontal size a treeview can possibly be.
54 *
55 * \todo get rid of REDRAW_MAX -- need to be able to know window size
56 */
57#define REDRAW_MAX 8000
58
59
60/**
61 * Treeview handling global context
62 */
64 unsigned initialised;
73
74
75/**
76 * Section type of a treeview at a point
77 */
79 TV_NODE_PART_TOGGLE, /**< Expansion toggle */
80 TV_NODE_PART_ON_NODE, /**< Node content (text, icon) */
81 TV_NODE_PART_NONE /**< Empty area */
82};
83
84
85/**
86 * Text within a treeview field or node
87 */
89 const char *data; /**< Text string */
90 uint32_t len; /**< Length of string in bytes */
91 int width; /**< Width of text in px */
92};
93
94
95/**
96 * a treeview field
97 */
99 /** flags controlling how field is interpreted */
101
102 lwc_string *field; /**< field contents */
103 struct treeview_text value; /**< field text */
104};
105
106
107/**
108 * flags indicating render state of node.
109 */
111 TV_NFLAGS_NONE = 0, /**< No node flags set */
112 TV_NFLAGS_EXPANDED = (1 << 0), /**< Whether node is expanded */
113 TV_NFLAGS_SELECTED = (1 << 1), /**< Whether node is selected */
114 TV_NFLAGS_SPECIAL = (1 << 2), /**< Render as special node */
115 TV_NFLAGS_MATCHED = (1 << 3), /**< Whether node matches search */
116};
117
118
119/**
120 * Treeview target position
121 */
128
129
130/**
131 * Treeview node
132 */
134 enum treeview_node_flags flags; /**< Node flags */
135 enum treeview_node_type type; /**< Node type */
136
137 int height; /**< Includes height of any descendants (pixels) */
138 int inset; /**< Node's inset depending on tree depth (pixels) */
139
140 treeview_node *parent; /**< parent node */
141 treeview_node *prev_sib; /**< previous sibling node */
142 treeview_node *next_sib; /**< next sibling node */
143 treeview_node *children; /**< first child node */
144
145 void *client_data; /**< Passed to client on node event msg callback */
146
147 struct treeview_text text; /** Text to show for node (default field) */
148};
149
150
151/**
152 * Node entry
153 *
154 * node entry contains a base node at the beginning allowing for
155 * trivial containerof by cast and some number of fields.
156 */
158 treeview_node base; /**< Entry class inherits node base class */
160};
161
162
163/**
164 * A mouse position wrt treeview
165 */
167 int x; /**< Mouse X coordinate */
168 int y; /**< Mouse Y coordinate */
169 int node_y; /**< Top of node at y */
170 int node_h; /**< Height of node at y */
171};
172
173
174/**
175 * Treeview drag state
176 */
178 enum {
184 } type; /**< Drag type */
185 treeview_node *start_node; /**< Start node */
186 bool selected; /**< Start node is selected */
187 enum treeview_node_part part; /**< Node part at start */
188 struct treeview_pos start; /**< Start pos */
189 struct treeview_pos prev; /**< Previous pos */
190};
191
192
193/**
194 * Treeview node move details
195 */
197 treeview_node *root; /**< Head of yanked node list */
198 treeview_node *target; /**< Move target */
199 struct rect target_area; /**< Pos/size of target indicator */
200 enum treeview_target_pos target_pos; /**< Pos wrt render node */
201};
202
203
204/**
205 * Treeview node edit details
206 */
208 treeview_node *node; /**< Node being edited, or NULL */
209 struct textarea *textarea; /**< Textarea for edit, or NULL */
210 lwc_string *field; /**< The field being edited, or NULL */
211 int x; /**< Textarea x position */
212 int y; /**< Textarea y position */
213 int w; /**< Textarea width */
214 int h; /**< Textarea height */
215};
216
217
218/**
219 * Treeview search box details
220 */
222 struct textarea *textarea; /**< Search box. */
223 bool active; /**< Whether the search box has focus. */
224 bool search; /**< Whether we have a search term. */
225 int height; /**< Current search display height. */
226};
227
228
229/**
230 * The treeview context
231 */
232struct treeview {
233 uint32_t view_width; /**< Viewport horizontal size */
234
235 treeview_flags flags; /**< Treeview behaviour settings */
236
237 treeview_node *root; /**< Root node */
238
239 struct treeview_field *fields; /**< Array of fields */
240 int n_fields; /**< fields[n_fields] is folder, lower are entry fields */
241 int field_width; /**< Max width of shown field names */
242
243 struct treeview_drag drag; /**< Drag state */
244 struct treeview_move move; /**< Move drag details */
245 struct treeview_edit edit; /**< Edit details */
246
247 struct treeview_search search; /**< Treeview search box */
248
249 const struct treeview_callback_table *callbacks; /**< For node events */
250
251 const struct core_window_callback_table *cw_t; /**< Window cb table */
252 struct core_window *cw_h; /**< Core window handle */
253};
254
255
256/**
257 * Treeview furniture states.
258 */
264
265
266/**
267 * style for a node
268 */
270 plot_style_t bg; /**< Background */
272 plot_font_style_t itext; /**< Entry field text */
273
274 plot_style_t sbg; /**< Selected background */
275 plot_font_style_t stext; /**< Selected text */
276 plot_font_style_t sitext; /**< Selected entry field text */
277
278 struct {
279 int size;
280 struct bitmap *bmp;
281 struct bitmap *sel;
283};
284
285
286/**
287 * Plot style for odd rows
288 */
290
291
292/**
293 * Plot style for even rows
294 */
296
297
298/**
299 * Treeview content resource data
300 */
302 const char *url;
305 bool ready;
306};
307
308
309/**
310 * treeview resource indexes
311 */
320
321
322/**
323 * Treeview content resources
324 */
326 { "resource:icons/arrow-l.png", NULL, 0, false },
327 { "resource:icons/content.png", NULL, 0, false },
328 { "resource:icons/directory.png", NULL, 0, false },
329 { "resource:icons/directory2.png", NULL, 0, false },
330 { "resource:icons/search.png", NULL, 0, false }
331};
332
333
334/**
335 * Get the display height of the treeview data component of the display.
336 *
337 * \param[in] tree Treeview to get the height of.
338 * \return the display height in pixels.
339 */
340static inline int treeview__get_display_height(const treeview *tree)
341{
342 return (tree->search.search == false) ?
343 tree->root->height :
344 tree->search.height;
345}
346
347
348/**
349 * Corewindow callback wrapper: Request a redraw of the window
350 *
351 * \param[in] tree The treeview to request redraw on.
352 * \param[in] r rectangle to redraw
353 */
355 const struct treeview *tree,
356 const struct rect *r)
357{
358 if (tree->cw_t != NULL) {
359 tree->cw_t->invalidate(tree->cw_h, r);
360 }
361}
362
363
364/**
365 * Corewindow callback wrapper: Request a full redraw of the window
366 *
367 * \param[in] tree The treeview to request redraw on.
368 */
369static inline void treeview__cw_full_redraw(
370 const struct treeview *tree)
371{
372 if (tree->cw_t != NULL) {
373 static const struct rect r = {
374 .x0 = 0,
375 .y0 = 0,
376 .x1 = REDRAW_MAX,
377 .y1 = REDRAW_MAX,
378 };
379 tree->cw_t->invalidate(tree->cw_h, &r);
380 }
381}
382
383
384/**
385 * Get height used by treeview's search bar (or 0 if not present).
386 *
387 * \param tree Treeview object to check.
388 * \return height used by search bar in pixels.
389 */
390static inline unsigned treeview__get_search_height(
391 const treeview *tree)
392{
393 return (tree->flags & TREEVIEW_SEARCHABLE) ?
395}
396
397
398/**
399 * Corewindow callback wrapper: Update the limits of the window
400 *
401 * \param[in] tree The treeview to update size for.
402 * \param[in] width the width in px, or negative if don't care
403 * \param[in] height the height in px, or negative if don't care
404 */
405static inline void treeview__cw_update_size(
406 const struct treeview *tree,
407 int width, int height)
408{
409 if (tree->cw_t != NULL) {
410 tree->cw_t->update_size(tree->cw_h, width,
412 }
413}
414
415
416/**
417 * Corewindow callback_wrapper: Scroll to top of window.
418 *
419 * \param[in] tree The treeview to scroll.
420 */
421static inline void treeview__cw_scroll_top(
422 const struct treeview *tree)
423{
424 struct rect r = {
425 .x0 = 0,
426 .y0 = 0,
428 .y1 = tree_g.line_height,
429 };
430
431 cw_helper_scroll_visible(tree->cw_t, tree->cw_h, &r);
432}
433
434
435/**
436 * Corewindow callback wrapper: Get window viewport dimensions
437 *
438 * \param[in] tree The treeview to get dimensions for.
439 * \param[out] width to be set to viewport width in px
440 * \param[out] height to be set to viewport height in px
441 */
443 const struct treeview *tree,
444 int *width, int *height)
445{
446 if (tree->cw_t != NULL) {
448 }
449}
450
451
452/**
453 * Corewindow callback wrapper: Inform corewindow owner of drag status
454 *
455 * \param[in] tree The treeview to report status on.
456 * \param[in] ds the current drag status
457 */
458static inline void treeview__cw_drag_status(
459 const struct treeview *tree,
461{
462 if (tree->cw_t != NULL) {
463 tree->cw_t->drag_status(tree->cw_h, ds);
464 }
465}
466
467
468/**
469 * Helper function to access the given field of a node
470 *
471 * \param tree Treeview that node belongs to
472 * \param n Node to get field from
473 * \param i Index of field of interest
474 * \return text entry for field or NULL.
475 */
476static inline struct treeview_text *
478{
479 if (i == 0) {
480 return &n->text;
481
482 } else if (i < tree->n_fields && n->type == TREE_NODE_ENTRY) {
483 struct treeview_node_entry *e = (struct treeview_node_entry *)n;
484 return &e->fields[i - 1].value;
485 }
486
487 assert(0 && "Bad field index for node");
488 return NULL;
489}
490
491
492/**
493 * Find the next node in depth first tree order
494 *
495 * \param node Start node
496 * \param full Iff true, visit children of collapsed nodes
497 * \return next node, or NULL if \a node is last node
498 */
499static inline treeview_node * treeview_node_next(treeview_node *node, bool full)
500{
501 assert(node != NULL);
502
503 if ((full || (node->flags & TV_NFLAGS_EXPANDED)) &&
504 node->children != NULL) {
505 /* Next node is child */
506 node = node->children;
507 } else {
508 /* No children. As long as we're not at the root,
509 * go to next sibling if present, or nearest ancestor
510 * with a next sibling. */
511
512 while (node->parent != NULL && node->next_sib == NULL) {
513 node = node->parent;
514 }
515
516 if (node->type == TREE_NODE_ROOT) {
517 node = NULL;
518
519 } else {
520 node = node->next_sib;
521 }
522 }
523
524 return node;
525}
526
527
528/**
529 * Find node at given y-position
530 *
531 * \param tree Treeview object to delete node from
532 * \param target_y Target y-position
533 * \return node at y_target
534 */
535static treeview_node * treeview_y_node(treeview *tree, int target_y)
536{
537 int y = treeview__get_search_height(tree);
538 treeview_node *n;
539
540 assert(tree != NULL);
541 assert(tree->root != NULL);
542
543 n = treeview_node_next(tree->root, false);
544
545 while (n != NULL) {
546 int h = (n->type == TREE_NODE_ENTRY) ?
548 if (target_y >= y && target_y < y + h)
549 return n;
550 y += h;
551
552 n = treeview_node_next(n, false);
553 }
554
555 return NULL;
556}
557
558
559/**
560 * Find y position of the top of a node
561 *
562 * \param tree Treeview object to delete node from
563 * \param node Node to get position of
564 * \return node's y position
565 */
567 const treeview *tree,
568 const treeview_node *node)
569{
570 treeview_node *n;
571 int y = treeview__get_search_height(tree);
572
573 assert(tree != NULL);
574 assert(tree->root != NULL);
575
576 n = treeview_node_next(tree->root, false);
577
578 while (n != NULL && n != node) {
579 y += (n->type == TREE_NODE_ENTRY) ?
581
582 n = treeview_node_next(n, false);
583 }
584
585 return y;
586}
587
588
589/**
590 * Corewindow callback_wrapper: Scroll to make node visible
591 *
592 * \param[in] tree The treeview to scroll.
593 * \param[in] node The treeview node to scroll to visibility.
594 */
596 const struct treeview *tree,
597 const struct treeview_node *node)
598{
599 struct rect r = {
600 .x0 = 0,
601 .y0 = treeview_node_y(tree, node),
602 .x1 = 1,
603 .y1 = ((node->type == TREE_NODE_ENTRY) ?
604 node->height : tree_g.line_height),
605 };
606
607 r.y1 += r.y0; /* Apply the Y offset to the second Y coordinate */
608
609 cw_helper_scroll_visible(tree->cw_t, tree->cw_h, &r);
610}
611
612
613/**
614 * Redraw tree from given node to the bottom.
615 *
616 * \param[in] tree Tree to redraw from node in.
617 * \param[in] node Node to redraw from.
618 */
620 const treeview *tree,
621 const treeview_node *node)
622{
623 struct rect r = {
624 .x0 = 0,
625 .y0 = treeview_node_y(tree, node),
626 .x1 = REDRAW_MAX,
627 .y1 = treeview__get_display_height(tree) +
629 };
630
631 assert(tree != NULL);
632
634}
635
636
637/**
638 * The treeview walk mode. Controls which nodes are visited in a walk.
639 */
641 /**
642 * Walk to all nodes in the (sub)tree.
643 */
645
646 /**
647 * Walk to expanded nodes in the (sub)tree only. Children of
648 * collapsed nodes are not visited.
649 */
651
652 /**
653 * Walk displayed nodes. This differs from the
654 * `TREEVIEW_WALK_MODE_LOGICAL_EXPANDED` mode when there is
655 * an active search filter display.
656 */
658};
659
660
661/**
662 * Walk a treeview subtree, calling a callback at each node (depth first)
663 *
664 * \param tree Treeview being walked.
665 * \param root Root to walk tree from (doesn't get a callback call)
666 * \param mode The treeview walk mode to use.
667 * \param callback_bwd Function to call on each node in backwards order
668 * \param callback_fwd Function to call on each node in forwards order
669 * \param ctx Context to pass to callback
670 * \return NSERROR_OK on success, or appropriate error otherwise
671 *
672 * \note Any node deletion must happen in callback_bwd.
673 */
675 treeview *tree,
678 nserror (*callback_bwd)(
679 treeview_node *n,
680 void *ctx,
681 bool *end),
682 nserror (*callback_fwd)(
683 treeview_node *n,
684 void *ctx,
685 bool *skip_children,
686 bool *end),
687 void *ctx)
688{
689 treeview_node *node, *child, *parent, *next_sibling;
690 bool walking_search = (mode == TREEVIEW_WALK_MODE_DISPLAY &&
691 tree->search.search == true);
692 bool skip_children = false;
693 bool abort = false;
694 bool full = false;
695 nserror err;
696 bool entry;
697
698 assert(root != NULL);
699
700 if (mode == TREEVIEW_WALK_MODE_LOGICAL_COMPLETE || walking_search) {
701 /* We need to visit children of collapsed folders. */
702 full = true;
703 }
704
705 node = root;
706 parent = node->parent;
707 next_sibling = node->next_sib;
708 child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
709 node->children : NULL;
710
711 while (node != NULL) {
712
713 if (child != NULL && !skip_children) {
714 /* Down to children */
715 node = child;
716 } else {
717 /* No children. As long as we're not at the root,
718 * go to next sibling if present, or nearest ancestor
719 * with a next sibling. */
720
721 while (node != root && next_sibling == NULL) {
722 entry = (node->type == TREE_NODE_ENTRY);
723 if (callback_bwd != NULL &&
724 (entry || !walking_search)) {
725 /* Backwards callback */
726 err = callback_bwd(node, ctx, &abort);
727
728 if (err != NSERROR_OK) {
729 return err;
730
731 } else if (abort) {
732 /* callback requested early
733 * termination */
734 return NSERROR_OK;
735 }
736 }
737 node = parent;
738 parent = node->parent;
739 next_sibling = node->next_sib;
740 }
741
742 if (node == root)
743 break;
744
745 if (callback_bwd != NULL) {
746 /* Backwards callback */
747 err = callback_bwd(node, ctx, &abort);
748
749 if (err != NSERROR_OK) {
750 return err;
751
752 } else if (abort) {
753 /* callback requested early
754 * termination */
755 return NSERROR_OK;
756 }
757 }
758 node = next_sibling;
759 }
760
761 assert(node != NULL);
762 assert(node != root);
763
764 entry = (node->type == TREE_NODE_ENTRY);
765
766 parent = node->parent;
767 next_sibling = node->next_sib;
768 child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
769 node->children : NULL;
770
771 if (walking_search && (!entry ||
772 !(node->flags & TV_NFLAGS_MATCHED))) {
773 continue;
774 }
775
776 if (callback_fwd != NULL) {
777 /* Forwards callback */
778 err = callback_fwd(node, ctx, &skip_children, &abort);
779
780 if (err != NSERROR_OK) {
781 return err;
782
783 } else if (abort) {
784 /* callback requested early termination */
785 return NSERROR_OK;
786 }
787 }
788 }
789 return NSERROR_OK;
790}
791
792
793/**
794 * Data used when doing a treeview walk for search.
795 */
797 treeview *tree; /**< The treeview to search. */
798 const char *text; /**< The string being searched for. */
799 const unsigned int len; /**< Length of string being searched for. */
800 int window_height; /**< Accumulate height for matching entries. */
801};
802
803
804/**
805 * Treewalk node callback for handling search.
806 *
807 * \param[in] n Current node.
808 * \param[in] ctx Treeview search context.
809 * \param[in,out] skip_children Flag to allow children to be skipped.
810 * \param[in,out] end Flag to allow iteration to be finished early.
811 * \return NSERROR_OK on success else error code.
812 */
814 treeview_node *n,
815 void *ctx,
816 bool *skip_children,
817 bool *end)
818{
819 struct treeview_search_walk_data *sw = ctx;
820
821 if (n->type != TREE_NODE_ENTRY) {
822 return NSERROR_OK;
823 }
824
825 if (sw->len == 0) {
826 n->flags &= ~TV_NFLAGS_MATCHED;
827 } else {
828 struct treeview_node_entry *entry =
829 (struct treeview_node_entry *)n;
830 bool matched = false;
831
832 for (int i = 0; i < sw->tree->n_fields; i++) {
833 struct treeview_field *ef = &(sw->tree->fields[i + 1]);
834 if (ef->flags & TREE_FLAG_SEARCHABLE) {
835 if (strcasestr(entry->fields[i].value.data,
836 sw->text) != NULL) {
837 matched = true;
838 break;
839 }
840 }
841 }
842
843 if (!matched && strcasestr(n->text.data, sw->text) != NULL) {
844 matched = true;
845 }
846
847 if (matched) {
849 sw->window_height += n->height;
850 } else {
851 n->flags &= ~TV_NFLAGS_MATCHED;
852 }
853 }
854
855 return NSERROR_OK;
856}
857
858
859/**
860 * Search treeview for text.
861 *
862 * \param[in] tree Treeview to search.
863 * \param[in] text UTF-8 string to search for. (NULL-terminated.)
864 * \param[in] len Byte length of UTF-8 string.
865 * \return NSERROR_OK on success, appropriate error otherwise.
866 */
868 treeview *tree,
869 const char *text,
870 unsigned int len)
871{
872 nserror err;
873 uint32_t height;
874 uint32_t prev_height = treeview__get_display_height(tree);
875 int search_height = treeview__get_search_height(tree);
876 struct treeview_search_walk_data sw = {
877 .len = len,
878 .text = text,
879 .tree = tree,
880 .window_height = 0,
881 };
882 struct rect r = {
883 .x0 = 0,
884 .y0 = search_height,
885 .x1 = REDRAW_MAX,
886 };
887
888 assert(text[len] == '\0');
889
890 if (tree->root == NULL) {
891 return NSERROR_OK;
892 }
893
894 err = treeview_walk_internal(tree, tree->root,
897 if (err != NSERROR_OK) {
898 return err;
899 }
900
901 if (len > 0) {
902 tree->search.height = sw.window_height;
903 tree->search.search = true;
905 } else {
906 tree->search.search = false;
907 height = tree->root->height;
908 }
909
910 r.y1 = ((height > prev_height) ? height : prev_height) + search_height;
914
915 return NSERROR_OK;
916}
917
918
919/**
920 * Cancel a treeview search, optionally droping focus from search widget.
921 *
922 * \param[in] tree Treeview to cancel search in.
923 * \param[in] drop_focus Iff true, drop input focus from search widget.
924 */
925static void treeview__search_cancel(treeview *tree, bool drop_focus)
926{
927 struct rect r = {
929 .x1 = 600,
930 .y0 = 0,
931 .y1 = tree_g.line_height,
932 };
933
934 tree->search.search = false;
935 if (tree->search.active == false) {
936 return;
937 }
938
939 if (textarea_get_text(tree->search.textarea, NULL, 0) == 1) {
940 // If there's no text in the search box, we drop focus on a
941 // cancel. Note '1' because it includes the trailing \0
942 drop_focus = true;
943 }
944
945 if (drop_focus) {
946 tree->search.active = false;
948 } else {
950 }
951
954}
955
956/**
957 * Convert from treeview drag to core window drag type.
958 *
959 * \param[in] tree A treeview.
960 * \return Core window drag type.
961 */
963 const treeview *tree)
964{
965 assert(tree != NULL);
966
967 switch (tree->drag.type) {
968 case TV_DRAG_NONE:
970
971 case TV_DRAG_SELECTION:
973
974 case TV_DRAG_TEXTAREA: /* Fall through.*/
975 case TV_DRAG_SEARCH:
977
978 case TV_DRAG_MOVE:
980 }
981
983}
984
985/**
986 * Callback for textarea_create, in desktop/treeview.h
987 *
988 * \param data treeview context
989 * \param msg textarea message
990 */
992 struct textarea_msg *msg)
993{
994 treeview *tree = data;
995 struct rect *r;
996
997 if (tree->search.active == false || tree->root == NULL) {
998 return;
999 }
1000
1001 switch (msg->type) {
1003 if (msg->data.drag == TEXTAREA_DRAG_NONE) {
1004 /* Textarea drag finished */
1005 tree->drag.type = TV_DRAG_NONE;
1006 } else {
1007 /* Textarea drag started */
1008 tree->drag.type = TV_DRAG_SEARCH;
1009 }
1012 break;
1013
1015 r = &msg->data.redraw;
1017 r->y0 += 0;
1018 r->x1 += 600;
1019 r->y1 += tree_g.line_height;
1020
1021 /* Redraw the textarea */
1023 break;
1024
1026 /* Textarea length includes trailing NULL, so subtract it. */
1027 treeview__search(tree,
1028 msg->data.modified.text,
1029 msg->data.modified.len - 1);
1030 break;
1031
1032 default:
1033 break;
1034 }
1035}
1036
1037
1038/**
1039 * Update the layout for any active search.
1040 *
1041 * \param[in] tree The tree to update.
1042 */
1044 treeview *tree)
1045{
1046 const char *string;
1047 unsigned int len;
1048
1049 if (tree->search.search == false) {
1050 /* No active search to update view for. */
1051 return;
1052 }
1053
1054 string = textarea_data(tree->search.textarea, &len);
1055 if (string == NULL || len == 0) {
1056 return;
1057 }
1058
1059 treeview__search(tree, string, len - 1);
1060}
1061
1062
1063/**
1064 * Create treeview's root node
1065 *
1066 * \param[out] root Returns root node
1067 * \return NSERROR_OK on success, appropriate error otherwise
1068 */
1070{
1071 treeview_node *n;
1072
1073 n = malloc(sizeof(struct treeview_node));
1074 if (n == NULL) {
1075 return NSERROR_NOMEM;
1076 }
1077
1079 n->type = TREE_NODE_ROOT;
1080
1081 n->height = 0;
1083
1084 n->text.data = NULL;
1085 n->text.len = 0;
1086 n->text.width = 0;
1087
1088 n->parent = NULL;
1089 n->next_sib = NULL;
1090 n->prev_sib = NULL;
1091 n->children = NULL;
1092
1093 n->client_data = NULL;
1094
1095 *root = n;
1096
1097 return NSERROR_OK;
1098}
1099
1100
1101/**
1102 * Set a node's inset from its parent
1103 *
1104 * This may be used as treeview walk callback
1105 *
1106 * \param[in] n node to set inset on
1107 * \param[in] ctx context unused
1108 * \param[out] skip_children set to false so child nodes are not skipped.
1109 * \param[out] end unused flag so treewalk in not terminated early.
1110 */
1111static nserror
1113 void *ctx,
1114 bool *skip_children,
1115 bool *end)
1116{
1117 if (n->parent != NULL)
1118 n->inset = n->parent->inset + tree_g.step_width;
1119
1120 *skip_children = false;
1121 return NSERROR_OK;
1122}
1123
1124
1125/**
1126 * Insert a treeview node into a treeview
1127 *
1128 * \param tree the treeview to insert node into.
1129 * \param a parentless node to insert
1130 * \param b tree node to insert a as a relation of
1131 * \param rel The relationship between \a a and \a b
1132 */
1133static inline void
1135 treeview *tree,
1136 treeview_node *a,
1137 treeview_node *b,
1138 enum treeview_relationship rel)
1139{
1140 assert(a != NULL);
1141 assert(a->parent == NULL);
1142 assert(b != NULL);
1143
1144 switch (rel) {
1146 assert(b->type != TREE_NODE_ENTRY);
1147 a->parent = b;
1148 a->next_sib = b->children;
1149 if (a->next_sib)
1150 a->next_sib->prev_sib = a;
1151 b->children = a;
1152 break;
1153
1155 assert(b->type != TREE_NODE_ROOT);
1156 a->prev_sib = b;
1157 a->next_sib = b->next_sib;
1158 a->parent = b->parent;
1159 b->next_sib = a;
1160 if (a->next_sib)
1161 a->next_sib->prev_sib = a;
1162 break;
1163
1164 default:
1165 assert(0);
1166 break;
1167 }
1168
1169 assert(a->parent != NULL);
1170
1171 a->inset = a->parent->inset + tree_g.step_width;
1172 if (a->children != NULL) {
1173 treeview_walk_internal(tree, a,
1176 }
1177
1178 if (a->parent->flags & TV_NFLAGS_EXPANDED) {
1179 int height = a->height;
1180 /* Parent is expanded, so inserted node will be visible and
1181 * affect layout */
1182 if (a->text.width == 0) {
1184 a->text.data,
1185 a->text.len,
1186 &(a->text.width));
1187 }
1188
1189 do {
1190 a->parent->height += height;
1191 a = a->parent;
1192 } while (a->parent != NULL);
1193 }
1194}
1195
1196
1197/* Exported interface, documented in treeview.h */
1198nserror
1200 treeview_node **folder,
1201 treeview_node *relation,
1202 enum treeview_relationship rel,
1203 const struct treeview_field_data *field,
1204 void *data,
1206{
1207 treeview_node *n;
1208
1209 assert(data != NULL);
1210 assert(tree != NULL);
1211 assert(tree->root != NULL);
1212
1213 if (relation == NULL) {
1214 relation = tree->root;
1216 }
1217
1218 n = malloc(sizeof(struct treeview_node));
1219 if (n == NULL) {
1220 return NSERROR_NOMEM;
1221 }
1222
1223 n->flags = (flags & TREE_OPTION_SPECIAL_DIR) ?
1226
1228
1229 n->text.data = field->value;
1230 n->text.len = field->value_len;
1231 n->text.width = 0;
1232
1233 n->parent = NULL;
1234 n->next_sib = NULL;
1235 n->prev_sib = NULL;
1236 n->children = NULL;
1237
1238 n->client_data = data;
1239
1240 treeview_insert_node(tree, n, relation, rel);
1241
1242 if (n->parent->flags & TV_NFLAGS_EXPANDED) {
1243 /* Inform front end of change in dimensions */
1244 if (!(flags & TREE_OPTION_SUPPRESS_RESIZE))
1245 treeview__cw_update_size(tree, -1,
1246 tree->root->height);
1247
1248 /* Redraw */
1249 if (!(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
1250 struct rect r;
1251 r.x0 = 0;
1252 r.y0 = treeview_node_y(tree, n);
1253 r.x1 = REDRAW_MAX;
1254 r.y1 = tree->root->height;
1256 }
1257 }
1258
1259 *folder = n;
1260
1261 return NSERROR_OK;
1262}
1263
1264
1265/* Exported interface, documented in treeview.h */
1266nserror
1268 treeview_node *folder,
1269 const struct treeview_field_data *field,
1270 void *data)
1271{
1272 bool match;
1273
1274 assert(data != NULL);
1275 assert(tree != NULL);
1276 assert(folder != NULL);
1277 assert(data == folder->client_data);
1278 assert(folder->parent != NULL);
1279
1280 assert(field != NULL);
1281 assert(lwc_string_isequal(tree->fields[tree->n_fields].field,
1282 field->field, &match) == lwc_error_ok &&
1283 match == true);
1284 folder->text.data = field->value;
1285 folder->text.len = field->value_len;
1286 folder->text.width = 0;
1287
1288 if (folder->parent->flags & TV_NFLAGS_EXPANDED) {
1289 /* Text will be seen, get its width */
1291 folder->text.data,
1292 folder->text.len,
1293 &(folder->text.width));
1294 } else {
1295 /* Just invalidate the width, since it's not needed now */
1296 folder->text.width = 0;
1297 }
1298
1299 /* Redraw */
1300 if (folder->parent->flags & TV_NFLAGS_EXPANDED) {
1301 struct rect r;
1302 r.x0 = 0;
1303 r.y0 = treeview_node_y(tree, folder);
1304 r.x1 = REDRAW_MAX;
1305 r.y1 = r.y0 + tree_g.line_height;
1307 }
1308
1309 return NSERROR_OK;
1310}
1311
1312
1313/* Exported interface, documented in treeview.h */
1314nserror
1316 treeview_node *entry,
1317 const struct treeview_field_data fields[],
1318 void *data)
1319{
1320 bool match;
1321 struct treeview_node_entry *e = (struct treeview_node_entry *)entry;
1322 int i;
1323
1324 assert(data != NULL);
1325 assert(tree != NULL);
1326 assert(entry != NULL);
1327 assert(data == entry->client_data);
1328 assert(entry->parent != NULL);
1329
1330 assert(fields != NULL);
1331 assert(fields[0].field != NULL);
1332 assert(lwc_string_isequal(tree->fields[0].field,
1333 fields[0].field, &match) == lwc_error_ok &&
1334 match == true);
1335 entry->text.data = fields[0].value;
1336 entry->text.len = fields[0].value_len;
1337 entry->text.width = 0;
1338
1339 if (entry->parent->flags & TV_NFLAGS_EXPANDED) {
1340 /* Text will be seen, get its width */
1342 entry->text.data,
1343 entry->text.len,
1344 &(entry->text.width));
1345 } else {
1346 /* Just invalidate the width, since it's not needed now */
1347 entry->text.width = 0;
1348 }
1349
1350 for (i = 1; i < tree->n_fields; i++) {
1351 assert(fields[i].field != NULL);
1352 assert(lwc_string_isequal(tree->fields[i].field,
1353 fields[i].field, &match) == lwc_error_ok &&
1354 match == true);
1355
1356 e->fields[i - 1].value.data = fields[i].value;
1357 e->fields[i - 1].value.len = fields[i].value_len;
1358
1359 if (entry->flags & TV_NFLAGS_EXPANDED) {
1360 /* Text will be seen, get its width */
1362 e->fields[i - 1].value.data,
1363 e->fields[i - 1].value.len,
1364 &(e->fields[i - 1].value.width));
1365 } else {
1366 /* Invalidate the width, since it's not needed yet */
1367 e->fields[i - 1].value.width = 0;
1368 }
1369 }
1370
1372
1373 /* Redraw */
1374 if (entry->parent->flags & TV_NFLAGS_EXPANDED) {
1375 struct rect r;
1376 r.x0 = 0;
1377 r.y0 = treeview_node_y(tree, entry);
1378 r.x1 = REDRAW_MAX;
1379 r.y1 = r.y0 + entry->height;
1381 }
1382
1383 return NSERROR_OK;
1384}
1385
1386
1387/* Exported interface, documented in treeview.h */
1388nserror
1390 treeview_node **entry,
1391 treeview_node *relation,
1392 enum treeview_relationship rel,
1393 const struct treeview_field_data fields[],
1394 void *data,
1396{
1397 bool match;
1398 struct treeview_node_entry *e;
1399 treeview_node *n;
1400 int i;
1401
1402 assert(data != NULL);
1403 assert(tree != NULL);
1404 assert(tree->root != NULL);
1405
1406 if (relation == NULL) {
1407 relation = tree->root;
1409 }
1410
1411 e = malloc(sizeof(struct treeview_node_entry) +
1412 (tree->n_fields - 1) * sizeof(struct treeview_field));
1413 if (e == NULL) {
1414 return NSERROR_NOMEM;
1415 }
1416
1417
1418 n = (treeview_node *) e;
1419
1420 n->flags = TV_NFLAGS_NONE;
1421 n->type = TREE_NODE_ENTRY;
1422
1424
1425 assert(fields != NULL);
1426 assert(fields[0].field != NULL);
1427 assert(lwc_string_isequal(tree->fields[0].field,
1428 fields[0].field, &match) == lwc_error_ok &&
1429 match == true);
1430 n->text.data = fields[0].value;
1431 n->text.len = fields[0].value_len;
1432 n->text.width = 0;
1433
1434 n->parent = NULL;
1435 n->next_sib = NULL;
1436 n->prev_sib = NULL;
1437 n->children = NULL;
1438
1439 n->client_data = data;
1440
1441 for (i = 1; i < tree->n_fields; i++) {
1442 assert(fields[i].field != NULL);
1443 assert(lwc_string_isequal(tree->fields[i].field,
1444 fields[i].field, &match) == lwc_error_ok &&
1445 match == true);
1446
1447 e->fields[i - 1].value.data = fields[i].value;
1448 e->fields[i - 1].value.len = fields[i].value_len;
1449 e->fields[i - 1].value.width = 0;
1450 }
1451
1452 treeview_insert_node(tree, n, relation, rel);
1453
1454 if (n->parent->flags & TV_NFLAGS_EXPANDED) {
1455 /* Inform front end of change in dimensions */
1456 if (!(flags & TREE_OPTION_SUPPRESS_RESIZE))
1457 treeview__cw_update_size(tree, -1,
1458 tree->root->height);
1459
1460 /* Redraw */
1461 if (!(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
1462 struct rect r;
1463 r.x0 = 0;
1464 r.y0 = treeview_node_y(tree, n);
1465 r.x1 = REDRAW_MAX;
1466 r.y1 = tree->root->height;
1468 }
1469 }
1470
1472
1473 *entry = n;
1474
1475 return NSERROR_OK;
1476}
1477
1478
1479/**
1480 * Treewalk iterator context
1481 */
1482struct treeview_walk_ctx {
1485 void *ctx;
1487};
1488
1489
1490/**
1491 * Treewalk node enter callback.
1492 *
1493 * \param n current node
1494 * \param ctx treewalk context
1495 * \param skip_children set if child nodes should be skipped
1496 * \param end set if iteration should end early
1497 */
1498static nserror
1500 void *ctx,
1501 bool *skip_children,
1502 bool *end)
1503{
1504 struct treeview_walk_ctx *tw = ctx;
1505
1506 if (n->type & tw->type) {
1507 return tw->enter_cb(tw->ctx, n->client_data, n->type, end);
1508 }
1509
1510 return NSERROR_OK;
1511}
1512
1513
1514/**
1515 * Treewalk node leave callback.
1516 *
1517 * \param n current node
1518 * \param ctx treewalk context
1519 * \param end set if iteration should end early
1520 */
1521static nserror treeview_walk_bwd_cb(treeview_node *n, void *ctx, bool *end)
1522{
1523 struct treeview_walk_ctx *tw = ctx;
1524
1525 if (n->type & tw->type) {
1526 return tw->leave_cb(tw->ctx, n->client_data, n->type, end);
1527 }
1528
1529 return NSERROR_OK;
1530}
1531
1532
1533/* Exported interface, documented in treeview.h */
1534nserror
1539 void *ctx,
1541{
1542 struct treeview_walk_ctx tw = {
1543 .enter_cb = enter_cb,
1544 .leave_cb = leave_cb,
1545 .ctx = ctx,
1546 .type = type
1547 };
1548
1549 assert(tree != NULL);
1550 assert(tree->root != NULL);
1551
1552 if (root == NULL)
1553 root = tree->root;
1554
1555 return treeview_walk_internal(tree, root,
1557 (leave_cb != NULL) ? treeview_walk_bwd_cb : NULL,
1558 (enter_cb != NULL) ? treeview_walk_fwd_cb : NULL,
1559 &tw);
1560}
1561
1562
1563/**
1564 * Unlink a treeview node
1565 *
1566 * \param n Node to unlink
1567 * \return true iff ancestor heights need to be reduced
1568 */
1570{
1571 /* Unlink node from tree */
1572 if (n->parent != NULL && n->parent->children == n) {
1573 /* Node is a first child */
1574 n->parent->children = n->next_sib;
1575
1576 } else if (n->prev_sib != NULL) {
1577 /* Node is not first child */
1578 n->prev_sib->next_sib = n->next_sib;
1579 }
1580
1581 if (n->next_sib != NULL) {
1582 /* Always need to do this */
1583 n->next_sib->prev_sib = n->prev_sib;
1584 }
1585
1586 /* Reduce ancestor heights */
1587 if ((n->parent != NULL) &&
1589 return true;
1590 }
1591
1592 return false;
1593}
1594
1595
1596/**
1597 * Cancel the editing of a treeview node
1598 *
1599 * \param tree Treeview object to cancel node editing in
1600 * \param redraw Set true iff redraw of removed textarea area required
1601 */
1602static void treeview_edit_cancel(treeview *tree, bool redraw)
1603{
1604 struct rect r;
1605
1606 if (tree->edit.textarea == NULL)
1607 return;
1608
1610
1611 tree->edit.textarea = NULL;
1612 tree->edit.node = NULL;
1613
1614 if (tree->drag.type == TV_DRAG_TEXTAREA)
1615 tree->drag.type = TV_DRAG_NONE;
1616
1617 if (redraw) {
1618 r.x0 = tree->edit.x;
1619 r.y0 = tree->edit.y;
1620 r.x1 = tree->edit.x + tree->edit.w;
1621 r.y1 = tree->edit.y + tree->edit.h;
1623 }
1624}
1625
1626
1627/**
1628 * Complete a treeview edit
1629 *
1630 * Complete edit by informing the client with a change request msg
1631 *
1632 * \param tree Treeview object to complete edit in
1633 */
1635{
1636 int len, error;
1637 char* new_text;
1638 treeview_node *n = tree->edit.node;
1639 struct treeview_node_msg msg;
1640 msg.msg = TREE_MSG_NODE_EDIT;
1641
1642 if (tree->edit.textarea == NULL) {
1643 return;
1644 }
1645
1646 assert(n != NULL);
1647
1648 /* Get new text length */
1649 len = textarea_get_text(tree->edit.textarea, NULL, 0);
1650
1651 new_text = malloc(len);
1652 if (new_text == NULL) {
1653 /* TODO: don't just silently ignore */
1654 return;
1655 }
1656
1657 /* Get the new text from textarea */
1658 error = textarea_get_text(tree->edit.textarea, new_text, len);
1659 if (error == -1) {
1660 /* TODO: don't just silently ignore */
1661 free(new_text);
1662 return;
1663 }
1664
1665 /* Inform the treeview client with change request message */
1666 msg.data.node_edit.field = tree->edit.field;
1667 msg.data.node_edit.text = new_text;
1668
1669 switch (n->type) {
1670 case TREE_NODE_ENTRY:
1671 tree->callbacks->entry(msg, n->client_data);
1672 break;
1673 case TREE_NODE_FOLDER:
1674 tree->callbacks->folder(msg, n->client_data);
1675 break;
1676 case TREE_NODE_ROOT:
1677 break;
1678 default:
1679 break;
1680 }
1681
1682 /* Finished with the new text */
1683 free(new_text);
1684
1685 /* Finally, destroy the treeview, and redraw */
1686 treeview_edit_cancel(tree, true);
1687}
1688
1689
1690/**
1691 * context for treeview node deletion iterator
1692 */
1697};
1698
1699
1700/**
1701 * Treewalk node callback deleting nodes.
1702 */
1703static nserror
1705{
1706 struct treeview_node_delete *nd = (struct treeview_node_delete *)ctx;
1707 struct treeview_node_msg msg;
1708
1710 msg.data.delete.user = nd->user_interaction;
1711
1712 assert(n->children == NULL);
1713
1714 if (treeview_unlink_node(n))
1715 nd->h_reduction += (n->type == TREE_NODE_ENTRY) ?
1717
1718 /* Handle any special treatment */
1719 switch (n->type) {
1720 case TREE_NODE_ENTRY:
1721 nd->tree->callbacks->entry(msg, n->client_data);
1722 break;
1723
1724 case TREE_NODE_FOLDER:
1725 nd->tree->callbacks->folder(msg, n->client_data);
1726 break;
1727
1728 case TREE_NODE_ROOT:
1729 break;
1730
1731 default:
1732 return NSERROR_BAD_PARAMETER;
1733 }
1734
1735 /* Cancel any edit of this node */
1736 if (nd->tree->edit.textarea != NULL &&
1737 nd->tree->edit.node == n) {
1738 treeview_edit_cancel(nd->tree, false);
1739 }
1740
1741 /* Free the node */
1742 free(n);
1743
1744 return NSERROR_OK;
1745}
1746
1747
1748/**
1749 * Delete a treeview node
1750 *
1751 * Will emit folder or entry deletion msg callback.
1752 *
1753 * \note this can be called from inside a treeview_walk fwd callback.
1754 * For example walking the tree and calling this for any node that's selected.
1755 *
1756 * This function does not delete empty nodes, so if TREEVIEW_DEL_EMPTY_DIRS is
1757 * set, caller must also call treeview_delete_empty.
1758 *
1759 * \param tree Treeview object to delete node from
1760 * \param n Node to delete
1761 * \param interaction Delete is result of user interaction with treeview
1762 * \param flags Treeview node options flags
1763 * \return NSERROR_OK on success, appropriate error otherwise
1764 */
1765static nserror
1767 treeview_node *n,
1768 bool interaction,
1770{
1771 nserror err;
1772 treeview_node *p = n->parent;
1773 struct treeview_node_delete nd = {
1774 .tree = tree,
1775 .h_reduction = 0,
1776 .user_interaction = interaction
1777 };
1778
1779 if (interaction && (tree->flags & TREEVIEW_NO_DELETES)) {
1780 return NSERROR_OK;
1781 }
1782
1783 /* Delete any children first */
1786 treeview_delete_node_walk_cb, NULL, &nd);
1787 if (err != NSERROR_OK) {
1788 return err;
1789 }
1790
1791 /* Now delete node */
1792 if (n == tree->root)
1793 tree->root = NULL;
1794 err = treeview_delete_node_walk_cb(n, &nd, false);
1795 if (err != NSERROR_OK) {
1796 return err;
1797 }
1798
1799 n = p;
1800 /* Reduce ancestor heights */
1801 while (n != NULL && n->flags & TV_NFLAGS_EXPANDED) {
1802 n->height -= nd.h_reduction;
1803 n = n->parent;
1804 }
1805
1806 /* Inform front end of change in dimensions */
1807 if (tree->root != NULL && p != NULL && p->flags & TV_NFLAGS_EXPANDED &&
1808 nd.h_reduction > 0 &&
1809 !(flags & TREE_OPTION_SUPPRESS_RESIZE)) {
1811 tree->root->height);
1812 }
1813
1815
1816 return NSERROR_OK;
1817}
1818
1819
1820/**
1821 * Delete any empty treeview folder nodes
1822 *
1823 * \param tree Treeview object to delete empty nodes from
1824 * \param interaction Delete is result of user interaction with treeview
1825 * \return NSERROR_OK on success, appropriate error otherwise
1826 *
1827 * Note this must not be called within a treeview_walk. It may delete the
1828 * walker's 'current' node, making it impossible to move on without invalid
1829 * reads.
1830 */
1832{
1833 treeview_node *node, *child, *parent, *next_sibling, *p;
1834 bool abort = false;
1835 nserror err;
1836 struct treeview_node_delete nd = {
1837 .tree = tree,
1838 .h_reduction = 0,
1839 .user_interaction = interaction
1840 };
1841
1842 assert(tree != NULL);
1843 assert(tree->root != NULL);
1844
1845 node = tree->root;
1846 parent = node->parent;
1847 next_sibling = node->next_sib;
1848 child = (node->flags & TV_NFLAGS_EXPANDED) ? node->children : NULL;
1849
1850 while (node != NULL) {
1851
1852 if (child != NULL) {
1853 /* Down to children */
1854 node = child;
1855 } else {
1856 /* No children. As long as we're not at the root,
1857 * go to next sibling if present, or nearest ancestor
1858 * with a next sibling. */
1859
1860 while (node->parent != NULL &&
1861 next_sibling == NULL) {
1862 if (node->type == TREE_NODE_FOLDER &&
1863 node->children == NULL) {
1864 /* Delete node */
1865 p = node->parent;
1867 node, &nd, &abort);
1868 if (err != NSERROR_OK) {
1869 return err;
1870 }
1871
1872 /* Reduce ancestor heights */
1873 while (p != NULL &&
1874 p->flags &
1876 p->height -= nd.h_reduction;
1877 p = p->parent;
1878 }
1879 nd.h_reduction = 0;
1880 }
1881 node = parent;
1882 parent = node->parent;
1883 next_sibling = node->next_sib;
1884 }
1885
1886 if (node->parent == NULL)
1887 break;
1888
1889 if (node->type == TREE_NODE_FOLDER &&
1890 node->children == NULL) {
1891 /* Delete node */
1892 p = node->parent;
1894 node, &nd, &abort);
1895 if (err != NSERROR_OK) {
1896 return err;
1897 }
1898
1899 /* Reduce ancestor heights */
1900 while (p != NULL &&
1902 p->height -= nd.h_reduction;
1903 p = p->parent;
1904 }
1905 nd.h_reduction = 0;
1906 }
1907 node = next_sibling;
1908 }
1909
1910 assert(node != NULL);
1911 assert(node->parent != NULL);
1912
1913 parent = node->parent;
1914 next_sibling = node->next_sib;
1915 child = (node->flags & TV_NFLAGS_EXPANDED) ?
1916 node->children : NULL;
1917 }
1918
1919 return NSERROR_OK;
1920}
1921
1922
1923/* Exported interface, documented in treeview.h */
1924nserror
1926 treeview_node *n,
1928{
1929 nserror err;
1930 struct rect r;
1931 bool visible;
1932
1933 assert(tree != NULL);
1934 assert(n != NULL);
1935 assert(n->parent != NULL);
1936
1937 visible = n->parent->flags & TV_NFLAGS_EXPANDED;
1938
1939 r.y0 = treeview_node_y(tree, n);
1940 r.y1 = tree->root->height;
1941
1942 err = treeview_delete_node_internal(tree, n, false, flags);
1943 if (err != NSERROR_OK)
1944 return err;
1945
1946 if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) {
1947 int h = tree->root->height;
1948 /* Delete any empty nodes */
1949 err = treeview_delete_empty_nodes(tree, false);
1950 if (err != NSERROR_OK)
1951 return err;
1952
1953 /* Inform front end of change in dimensions */
1954 if (tree->root->height != h) {
1955 r.y0 = 0;
1956 if (!(flags & TREE_OPTION_SUPPRESS_RESIZE)) {
1957 treeview__cw_update_size(tree, -1,
1958 tree->root->height);
1959 }
1960 }
1961 }
1962
1963 /* Redraw */
1964 if (visible && !(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
1965 r.x0 = 0;
1966 r.x1 = REDRAW_MAX;
1968 }
1969
1970 return NSERROR_OK;
1971}
1972
1973
1974/**
1975 * Helper to create a textarea.
1976 *
1977 * \param[in] tree The treeview we're creating the textarea for.
1978 * \param[in] width The width of the textarea.
1979 * \param[in] height The height of the textarea.
1980 * \param[in] border The border colour to use.
1981 * \param[in] background The background colour to use.
1982 * \param[in] foreground The foreground colour to use.
1983 * \param[in] text The text style to use for the text area.
1984 * \param[in] ta_callback The textarea callback function to give the textarea.
1985 * \return the textarea pointer on success, or NULL on failure.
1986 */
1988 treeview *tree,
1989 int width,
1990 int height,
1991 colour border,
1992 colour background,
1993 colour foreground,
1995 textarea_client_callback ta_callback)
1996{
1997 /* Configure the textarea */
1999 textarea_setup ta_setup = {
2000 .text = text,
2001 .width = width,
2002 .height = height,
2003 .pad_top = 0,
2004 .pad_left = 2,
2005 .pad_right = 2,
2006 .pad_bottom = 0,
2007 .border_width = 1,
2008 .border_col = border,
2009 .selected_bg = foreground,
2010 .selected_text = background,
2011 };
2012
2013 ta_setup.text.foreground = foreground;
2014 ta_setup.text.background = background;
2015
2016 /* Create text area */
2017 return textarea_create(ta_flags, &ta_setup, ta_callback, tree);
2018}
2019
2020
2021/* Exported interface, documented in treeview.h */
2022nserror
2024 const struct treeview_callback_table *callbacks,
2025 int n_fields,
2026 struct treeview_field_desc fields[],
2027 const struct core_window_callback_table *cw_t,
2028 struct core_window *cw,
2030{
2031 nserror error;
2032 int i;
2033
2034 assert((cw_t == NULL && cw == NULL) || (cw_t != NULL && cw != NULL));
2035 assert(callbacks != NULL);
2036
2037 assert(fields != NULL);
2038 assert(fields[0].flags & TREE_FLAG_DEFAULT);
2039 assert(fields[n_fields - 1].flags & TREE_FLAG_DEFAULT);
2040 assert(n_fields >= 2);
2041
2042 *tree = malloc(sizeof(struct treeview));
2043 if (*tree == NULL) {
2044 return NSERROR_NOMEM;
2045 }
2046
2047 (*tree)->fields = malloc(sizeof(struct treeview_field) * n_fields);
2048 if ((*tree)->fields == NULL) {
2049 free(*tree);
2050 return NSERROR_NOMEM;
2051 }
2052
2053 error = treeview_create_node_root(&((*tree)->root));
2054 if (error != NSERROR_OK) {
2055 free((*tree)->fields);
2056 free(*tree);
2057 return error;
2058 }
2059
2060 (*tree)->field_width = 0;
2061 for (i = 0; i < n_fields; i++) {
2062 struct treeview_field *f = &((*tree)->fields[i]);
2063
2064 f->flags = fields[i].flags;
2065 f->field = lwc_string_ref(fields[i].field);
2066 f->value.data = lwc_string_data(fields[i].field);
2067 f->value.len = lwc_string_length(fields[i].field);
2068
2070 f->value.len, &(f->value.width));
2071
2072 if (f->flags & TREE_FLAG_SHOW_NAME)
2073 if ((*tree)->field_width < f->value.width)
2074 (*tree)->field_width = f->value.width;
2075 }
2076
2077 (*tree)->field_width += tree_g.step_width;
2078
2079 (*tree)->callbacks = callbacks;
2080 (*tree)->n_fields = n_fields - 1;
2081
2082 (*tree)->drag.type = TV_DRAG_NONE;
2083 (*tree)->drag.start_node = NULL;
2084 (*tree)->drag.start.x = 0;
2085 (*tree)->drag.start.y = 0;
2086 (*tree)->drag.start.node_y = 0;
2087 (*tree)->drag.start.node_h = 0;
2088 (*tree)->drag.prev.x = 0;
2089 (*tree)->drag.prev.y = 0;
2090 (*tree)->drag.prev.node_y = 0;
2091 (*tree)->drag.prev.node_h = 0;
2092
2093 (*tree)->move.root = NULL;
2094 (*tree)->move.target = NULL;
2095 (*tree)->move.target_pos = TV_TARGET_NONE;
2096
2097 (*tree)->edit.textarea = NULL;
2098 (*tree)->edit.node = NULL;
2099
2100 if (flags & TREEVIEW_SEARCHABLE) {
2101 (*tree)->search.textarea = treeview__create_textarea(
2102 *tree, 600, tree_g.line_height,
2108 if ((*tree)->search.textarea == NULL) {
2109 treeview_destroy(*tree);
2110 return NSERROR_NOMEM;
2111 }
2112 } else {
2113 (*tree)->search.textarea = NULL;
2114 }
2115 (*tree)->search.active = false;
2116 (*tree)->search.search = false;
2117
2118 (*tree)->flags = flags;
2119
2120 (*tree)->cw_t = cw_t;
2121 (*tree)->cw_h = cw;
2122
2123 return NSERROR_OK;
2124}
2125
2126
2127/* Exported interface, documented in treeview.h */
2128nserror
2130 const struct core_window_callback_table *cw_t,
2131 struct core_window *cw)
2132{
2133 assert(cw_t != NULL);
2134 assert(cw != NULL);
2135
2136 if (tree->cw_t != NULL || tree->cw_h != NULL) {
2137 NSLOG(netsurf, INFO, "Treeview already attached.");
2138 return NSERROR_UNKNOWN;
2139 }
2140 tree->cw_t = cw_t;
2141 tree->cw_h = cw;
2142
2143 return NSERROR_OK;
2144}
2145
2146
2147/* Exported interface, documented in treeview.h */
2149{
2150 tree->cw_t = NULL;
2151 tree->cw_h = NULL;
2152
2153 treeview__search_cancel(tree, true);
2154
2155 return NSERROR_OK;
2156}
2157
2158
2159/* Exported interface, documented in treeview.h */
2161{
2162 int f;
2163
2164 assert(tree != NULL);
2165
2166 if (tree->search.textarea != NULL) {
2167 tree->search.active = false;
2168 tree->search.search = false;
2170 }
2171
2172 /* Destroy nodes */
2173 treeview_delete_node_internal(tree, tree->root, false,
2176
2177 /* Destroy feilds */
2178 for (f = 0; f <= tree->n_fields; f++) {
2179 lwc_string_unref(tree->fields[f].field);
2180 }
2181 free(tree->fields);
2182
2183 /* Free treeview */
2184 free(tree);
2185
2186 return NSERROR_OK;
2187}
2188
2189
2190/**
2191 * Expand a treeview's nodes
2192 *
2193 * \param tree Treeview object to expand nodes in
2194 * \param node The node to expand.
2195 * \return NSERROR_OK on success, appropriate error otherwise.
2196 */
2197static nserror
2199{
2200 treeview_node *child;
2201 struct treeview_node_entry *e;
2202 int additional_height_folders = 0;
2203 int additional_height_entries = 0;
2204 int i;
2205
2206 assert(tree != NULL);
2207 assert(node != NULL);
2208
2209 if (node->flags & TV_NFLAGS_EXPANDED) {
2210 /* What madness is this? */
2211 NSLOG(netsurf, INFO, "Tried to expand an expanded node.");
2212 return NSERROR_OK;
2213 }
2214
2215 switch (node->type) {
2216 case TREE_NODE_FOLDER:
2217 child = node->children;
2218 if (child == NULL) {
2219 /* Allow expansion of empty folders */
2220 break;
2221 }
2222
2223 do {
2224 if (child->text.width == 0) {
2226 child->text.data,
2227 child->text.len,
2228 &(child->text.width));
2229 }
2230
2231 additional_height_folders += child->height;
2232
2233 child = child->next_sib;
2234 } while (child != NULL);
2235
2236 break;
2237
2238 case TREE_NODE_ENTRY:
2239 assert(node->children == NULL);
2240
2241 e = (struct treeview_node_entry *)node;
2242
2243 for (i = 0; i < tree->n_fields - 1; i++) {
2244
2245 if (e->fields[i].value.width == 0) {
2247 e->fields[i].value.data,
2248 e->fields[i].value.len,
2249 &(e->fields[i].value.width));
2250 }
2251
2252 /* Add height for field */
2253 additional_height_entries += tree_g.line_height;
2254 }
2255
2256 break;
2257
2258 case TREE_NODE_ROOT:
2259 case TREE_NODE_NONE:
2260 assert(node->type != TREE_NODE_ROOT);
2261 assert(node->type != TREE_NODE_NONE);
2262 break;
2263 }
2264
2265 /* Update the node */
2266 node->flags |= TV_NFLAGS_EXPANDED;
2267
2268 /* And node heights */
2269 for (struct treeview_node *n = node;
2270 (n != NULL) && (n->flags & TV_NFLAGS_EXPANDED);
2271 n = n->parent) {
2272 n->height += additional_height_entries +
2273 additional_height_folders;
2274 }
2275
2276 if (tree->search.search &&
2277 node->type == TREE_NODE_ENTRY &&
2278 node->flags & TV_NFLAGS_MATCHED) {
2279 tree->search.height += additional_height_entries;
2280 }
2281
2282 /* Inform front end of change in dimensions */
2283 if (additional_height_entries + additional_height_folders != 0) {
2284 treeview__cw_update_size(tree, -1,
2286 }
2287
2288 return NSERROR_OK;
2289}
2290
2291
2292/* Exported interface, documented in treeview.h */
2294{
2295 nserror res;
2296
2297 res = treeview_node_expand_internal(tree, node);
2298 NSLOG(netsurf, INFO, "Expanding!");
2299 if (res == NSERROR_OK) {
2300 /* expansion was successful, attempt redraw */
2301 treeview__redraw_from_node(tree, node);
2302 NSLOG(netsurf, INFO, "Expanded!");
2303 }
2304
2305 return res;
2306}
2307
2308
2309/**
2310 * context for treeview contraction callback
2311 */
2315};
2316
2317
2318/**
2319 * Treewalk node callback for handling node contraction.
2320 *
2321 * \param n node
2322 * \param ctx contract iterator context
2323 * \param end flag to end iteration now
2324 * \return NSERROR_OK on success else appropriate error code
2325 */
2326static nserror treeview_node_contract_cb(treeview_node *n, void *ctx, bool *end)
2327{
2328 struct treeview_contract_data *data = ctx;
2329 int h_reduction_folder = 0;
2330 int h_reduction_entry = 0;
2331
2332 assert(n != NULL);
2333 assert(n->type != TREE_NODE_ROOT);
2334
2335 n->flags &= ~TV_NFLAGS_SELECTED;
2336
2337 if ((n->flags & TV_NFLAGS_EXPANDED) == false ||
2338 (n->type == TREE_NODE_FOLDER && data->only_entries)) {
2339 /* Nothing to do. */
2340 return NSERROR_OK;
2341 }
2342
2343
2344 switch (n->type) {
2345 case TREE_NODE_FOLDER:
2346 h_reduction_folder = n->height - tree_g.line_height;
2347 break;
2348
2349 case TREE_NODE_ENTRY:
2350 h_reduction_entry = n->height - tree_g.line_height;
2351 break;
2352
2353 default:
2354 break;
2355 }
2356
2357
2358 assert(h_reduction_folder + h_reduction_entry >= 0);
2359 for (struct treeview_node *node = n;
2360 (node != NULL) && (node->flags & TV_NFLAGS_EXPANDED);
2361 node = node->parent) {
2362 node->height -= h_reduction_folder + h_reduction_entry;
2363 }
2364
2365 if (data->tree->search.search) {
2366 data->tree->search.height -= h_reduction_entry;
2367 }
2368
2370
2371 return NSERROR_OK;
2372}
2373
2374
2375/**
2376 * Contract a treeview node
2377 *
2378 * \param tree Treeview object to contract node in
2379 * \param node Node to contract
2380 * \return NSERROR_OK on success, appropriate error otherwise
2381 */
2382static nserror
2384{
2385 struct treeview_contract_data data;
2386 bool selected;
2387 assert(node != NULL);
2388
2389 if ((node->flags & TV_NFLAGS_EXPANDED) == false) {
2390 /* What madness is this? */
2391 NSLOG(netsurf, INFO, "Tried to contract a contracted node.");
2392 return NSERROR_OK;
2393 }
2394
2395 data.tree = tree;
2396 data.only_entries = false;
2397 selected = node->flags & TV_NFLAGS_SELECTED;
2398
2399 /* Contract children. */
2401 treeview_node_contract_cb, NULL, &data);
2402
2403 /* Contract node */
2404 treeview_node_contract_cb(node, &data, false);
2405
2406 if (selected)
2407 node->flags |= TV_NFLAGS_SELECTED;
2408
2409 /* Inform front end of change in dimensions */
2411
2412 return NSERROR_OK;
2413}
2414
2415
2416/* Exported interface, documented in treeview.h */
2418{
2419 nserror res;
2420
2421 assert(tree != NULL);
2422
2424 NSLOG(netsurf, INFO, "Contracting!");
2425 if (res == NSERROR_OK) {
2426 /* successful contraction, request redraw */
2428 NSLOG(netsurf, INFO, "Contracted!");
2429 }
2430
2431 return res;
2432}
2433
2434
2435/* Exported interface, documented in treeview.h */
2437{
2438 int search_height = treeview__get_search_height(tree);
2439 struct treeview_contract_data data;
2440 bool selected;
2441 treeview_node *n;
2442 struct rect r;
2443
2444 assert(tree != NULL);
2445 assert(tree->root != NULL);
2446
2447 r.x0 = 0;
2448 r.y0 = 0;
2449 r.x1 = REDRAW_MAX;
2450 r.y1 = tree->root->height + search_height;
2451
2452 data.tree = tree;
2453 data.only_entries = !all;
2454
2455 for (n = tree->root->children; n != NULL; n = n->next_sib) {
2456 if ((n->flags & TV_NFLAGS_EXPANDED) == false) {
2457 continue;
2458 }
2459
2460 selected = n->flags & TV_NFLAGS_SELECTED;
2461
2462 /* Contract children. */
2463 treeview_walk_internal(tree, n,
2465 treeview_node_contract_cb, NULL, &data);
2466
2467 /* Contract node */
2468 treeview_node_contract_cb(n, &data, false);
2469
2470 if (selected)
2472 }
2473
2474 /* Inform front end of change in dimensions */
2475 treeview__cw_update_size(tree, -1, tree->root->height);
2476
2477 /* Redraw */
2479
2480 return NSERROR_OK;
2481}
2482
2483
2484/**
2485 * context data for treeview expansion
2486 */
2490};
2491
2492
2493/**
2494 * Treewalk node callback for handling recursive node expansion.
2495 *
2496 * \param n current node
2497 * \param ctx node expansion context
2498 * \param skip_children flag to allow children to be skipped
2499 * \param end flag to allow iteration to be finished early.
2500 * \return NSERROR_OK on success else error code.
2501 */
2502static nserror
2504 void *ctx,
2505 bool *skip_children,
2506 bool *end)
2507{
2508 struct treeview_expand_data *data = ctx;
2509 nserror err;
2510
2511 assert(n != NULL);
2512 assert(n->type != TREE_NODE_ROOT);
2513
2514 if (n->flags & TV_NFLAGS_EXPANDED ||
2515 (data->only_folders && n->type != TREE_NODE_FOLDER)) {
2516 /* Nothing to do. */
2517 return NSERROR_OK;
2518 }
2519
2520 err = treeview_node_expand_internal(data->tree, n);
2521
2522 return err;
2523}
2524
2525
2526/* Exported interface, documented in treeview.h */
2528{
2529 struct treeview_expand_data data;
2530 nserror res;
2531 struct rect r;
2532
2533 assert(tree != NULL);
2534 assert(tree->root != NULL);
2535
2536 data.tree = tree;
2537 data.only_folders = only_folders;
2538
2539 res = treeview_walk_internal(tree, tree->root,
2541 NULL, treeview_expand_cb, &data);
2542 if (res == NSERROR_OK) {
2543 /* expansion succeeded, schedule redraw */
2544
2545 r.x0 = 0;
2546 r.y0 = 0;
2547 r.x1 = REDRAW_MAX;
2548 r.y1 = tree->root->height;
2549
2551 }
2552 return res;
2553}
2554
2555
2556/**
2557 * Draw a treeview normally, in tree mode.
2558 *
2559 * \param[in] tree The treeview we're rendering.
2560 * \param[in] x X coordinate we're rendering the treeview at.
2561 * \param[in] y Y coordinate we're rendering the treeview at.
2562 * \param[in,out] render_y Current vertical position in tree, updated on exit.
2563 * \param[in] r Clip rectangle.
2564 * \param[in] data Redraw data for rendering contents.
2565 * \param[in] ctx Current render context.
2566 */
2568 treeview *tree,
2569 const int x,
2570 const int y,
2571 int *render_y_in_out,
2572 const struct rect *r,
2573 struct content_redraw_data *data,
2574 const struct redraw_context *ctx)
2575{
2576 struct treeview_node_style *style = &plot_style_odd;
2578 int baseline = (tree_g.line_height * 3 + 2) / 4;
2579 plot_font_style_t *infotext_style;
2580 treeview_node *root = tree->root;
2581 treeview_node *node = tree->root;
2582 int render_y = *render_y_in_out;
2583 plot_font_style_t *text_style;
2584 plot_style_t *bg_style;
2585 int sel_min, sel_max;
2586 uint32_t count = 0;
2587 struct rect rect;
2588 int inset;
2589 int x0;
2590
2591 if (tree->drag.start.y > tree->drag.prev.y) {
2592 sel_min = tree->drag.prev.y;
2593 sel_max = tree->drag.start.y;
2594 } else {
2595 sel_min = tree->drag.start.y;
2596 sel_max = tree->drag.prev.y;
2597 }
2598
2599 while (node != NULL) {
2600 struct treeview_node_entry *entry;
2601 struct bitmap *furniture;
2602 bool invert_selection;
2603 treeview_node *next;
2604 int height;
2605 int i;
2606
2607 next = (node->flags & TV_NFLAGS_EXPANDED) ?
2608 node->children : NULL;
2609
2610 if (next != NULL) {
2611 /* down to children */
2612 node = next;
2613 } else {
2614 /* No children. As long as we're not at the root,
2615 * go to next sibling if present, or nearest ancestor
2616 * with a next sibling. */
2617
2618 while (node != root &&
2619 node->next_sib == NULL) {
2620 node = node->parent;
2621 }
2622
2623 if (node == root)
2624 break;
2625
2626 node = node->next_sib;
2627 }
2628
2629 assert(node != NULL);
2630 assert(node != root);
2631 assert(node->type == TREE_NODE_FOLDER ||
2632 node->type == TREE_NODE_ENTRY);
2633
2634 count++;
2635 inset = x + node->inset;
2636 height = (node->type == TREE_NODE_ENTRY) ? node->height :
2638
2639 if ((render_y + height) < r->y0) {
2640 /* This node's line is above clip region */
2641 render_y += height;
2642 continue;
2643 }
2644
2645 style = (count & 0x1) ? &plot_style_odd : &plot_style_even;
2646 if (tree->drag.type == TV_DRAG_SELECTION &&
2647 (render_y + height >= sel_min &&
2648 render_y < sel_max)) {
2649 invert_selection = true;
2650 } else {
2651 invert_selection = false;
2652 }
2653 if ((node->flags & TV_NFLAGS_SELECTED && !invert_selection) ||
2654 (!(node->flags & TV_NFLAGS_SELECTED) &&
2655 invert_selection)) {
2656 bg_style = &style->sbg;
2657 text_style = &style->stext;
2658 infotext_style = &style->sitext;
2659 furniture = (node->flags & TV_NFLAGS_EXPANDED) ?
2660 style->furn[TREE_FURN_CONTRACT].sel :
2661 style->furn[TREE_FURN_EXPAND].sel;
2662 } else {
2663 bg_style = &style->bg;
2664 text_style = &style->text;
2665 infotext_style = &style->itext;
2666 furniture = (node->flags & TV_NFLAGS_EXPANDED) ?
2667 style->furn[TREE_FURN_CONTRACT].bmp :
2668 style->furn[TREE_FURN_EXPAND].bmp;
2669 }
2670
2671 /* Render background */
2672 rect.x0 = r->x0;
2673 rect.y0 = render_y;
2674 rect.x1 = r->x1;
2675 rect.y1 = render_y + height;
2676 ctx->plot->rectangle(ctx, bg_style, &rect);
2677
2678 /* Render toggle */
2679 ctx->plot->bitmap(ctx,
2680 furniture,
2681 inset,
2682 render_y + tree_g.line_height / 4,
2683 style->furn[TREE_FURN_EXPAND].size,
2684 style->furn[TREE_FURN_EXPAND].size,
2685 bg_style->fill_colour,
2686 BITMAPF_NONE);
2687
2688 /* Render icon */
2689 if (node->type == TREE_NODE_ENTRY) {
2690 res = TREE_RES_CONTENT;
2691 } else if (node->flags & TV_NFLAGS_SPECIAL) {
2693 } else {
2694 res = TREE_RES_FOLDER;
2695 }
2696
2697 if (treeview_res[res].ready) {
2698 /* Icon resource is available */
2699 data->x = inset + tree_g.step_width;
2700 data->y = render_y + ((tree_g.line_height -
2701 treeview_res[res].height + 1) / 2);
2702 data->background_colour = bg_style->fill_colour;
2703
2704 content_redraw(treeview_res[res].c, data, r, ctx);
2705 }
2706
2707 /* Render text */
2708 x0 = inset + tree_g.step_width + tree_g.icon_step;
2709 ctx->plot->text(ctx,
2710 text_style,
2711 x0, render_y + baseline,
2712 node->text.data,
2713 node->text.len);
2714
2715 /* Rendered the node */
2716 render_y += tree_g.line_height;
2717 if (render_y > r->y1) {
2718 /* Passed the bottom of what's in the clip region.
2719 * Done. */
2720 break;
2721 }
2722
2723
2724 if (node->type != TREE_NODE_ENTRY ||
2725 !(node->flags & TV_NFLAGS_EXPANDED))
2726 /* Done everything for this node */
2727 continue;
2728
2729 /* Render expanded entry fields */
2730 entry = (struct treeview_node_entry *)node;
2731 for (i = 0; i < tree->n_fields - 1; i++) {
2732 struct treeview_field *ef = &(tree->fields[i + 1]);
2733
2734 if (ef->flags & TREE_FLAG_SHOW_NAME) {
2735 int max_width = tree->field_width;
2736
2737 ctx->plot->text(ctx,
2738 infotext_style,
2739 x0 + max_width - ef->value.width - tree_g.step_width,
2740 render_y + baseline,
2741 ef->value.data,
2742 ef->value.len);
2743
2744 ctx->plot->text(ctx,
2745 infotext_style,
2746 x0 + max_width,
2747 render_y + baseline,
2748 entry->fields[i].value.data,
2749 entry->fields[i].value.len);
2750 } else {
2751 ctx->plot->text(ctx,
2752 infotext_style,
2753 x0, render_y + baseline,
2754 entry->fields[i].value.data,
2755 entry->fields[i].value.len);
2756 }
2757
2758 /* Rendered the expanded entry field */
2759 render_y += tree_g.line_height;
2760 }
2761
2762 /* Finished rendering expanded entry */
2763
2764 if (render_y > r->y1) {
2765 /* Passed the bottom of what's in the clip region.
2766 * Done. */
2767 break;
2768 }
2769 }
2770
2771 *render_y_in_out = render_y;
2772}
2773
2774
2775/**
2776 * Draw a treeview normally, in tree mode.
2777 *
2778 * \param[in] tree The treeview we're rendering.
2779 * \param[in] x X coordinate we're rendering the treeview at.
2780 * \param[in] y Y coordinate we're rendering the treeview at.
2781 * \param[in,out] render_y Current vertical position in tree, updated on exit.
2782 * \param[in] r Clip rectangle.
2783 * \param[in] data Redraw data for rendering contents.
2784 * \param[in] ctx Current render context.
2785 */
2787 treeview *tree,
2788 const int x,
2789 const int y,
2790 int *render_y_in_out,
2791 const struct rect *r,
2792 struct content_redraw_data *data,
2793 const struct redraw_context *ctx)
2794{
2795 struct treeview_node_style *style = &plot_style_odd;
2797 int baseline = (tree_g.line_height * 3 + 2) / 4;
2798 plot_font_style_t *infotext_style;
2799 treeview_node *root = tree->root;
2800 treeview_node *node = tree->root;
2801 int render_y = *render_y_in_out;
2802 plot_font_style_t *text_style;
2803 plot_style_t *bg_style;
2804 int sel_min, sel_max;
2805 uint32_t count = 0;
2806 struct rect rect;
2807 int inset;
2808 int x0;
2809
2810 if (tree->drag.start.y > tree->drag.prev.y) {
2811 sel_min = tree->drag.prev.y;
2812 sel_max = tree->drag.start.y;
2813 } else {
2814 sel_min = tree->drag.start.y;
2815 sel_max = tree->drag.prev.y;
2816 }
2817
2818 while (node != NULL) {
2819 struct treeview_node_entry *entry;
2820 struct bitmap *furniture;
2821 bool invert_selection;
2822 treeview_node *next;
2823 int height;
2824 int i;
2825
2826 next = node->children;
2827
2828 if (next != NULL) {
2829 /* down to children */
2830 node = next;
2831 } else {
2832 /* No children. As long as we're not at the root,
2833 * go to next sibling if present, or nearest ancestor
2834 * with a next sibling. */
2835
2836 while (node != root &&
2837 node->next_sib == NULL) {
2838 node = node->parent;
2839 }
2840
2841 if (node == root)
2842 break;
2843
2844 node = node->next_sib;
2845 }
2846
2847 assert(node != NULL);
2848 assert(node != root);
2849 assert(node->type == TREE_NODE_FOLDER ||
2850 node->type == TREE_NODE_ENTRY);
2851
2852 if (node->type == TREE_NODE_FOLDER ||
2853 !(node->flags & TV_NFLAGS_MATCHED)) {
2854 continue;
2855 }
2856
2857 count++;
2858 inset = x + tree_g.window_padding;
2859 height = node->height;
2860
2861 if ((render_y + height) < r->y0) {
2862 /* This node's line is above clip region */
2863 render_y += height;
2864 continue;
2865 }
2866
2867 style = (count & 0x1) ? &plot_style_odd : &plot_style_even;
2868 if (tree->drag.type == TV_DRAG_SELECTION &&
2869 (render_y + height >= sel_min &&
2870 render_y < sel_max)) {
2871 invert_selection = true;
2872 } else {
2873 invert_selection = false;
2874 }
2875 if ((node->flags & TV_NFLAGS_SELECTED && !invert_selection) ||
2876 (!(node->flags & TV_NFLAGS_SELECTED) &&
2877 invert_selection)) {
2878 bg_style = &style->sbg;
2879 text_style = &style->stext;
2880 infotext_style = &style->sitext;
2881 furniture = (node->flags & TV_NFLAGS_EXPANDED) ?
2882 style->furn[TREE_FURN_CONTRACT].sel :
2883 style->furn[TREE_FURN_EXPAND].sel;
2884 } else {
2885 bg_style = &style->bg;
2886 text_style = &style->text;
2887 infotext_style = &style->itext;
2888 furniture = (node->flags & TV_NFLAGS_EXPANDED) ?
2889 style->furn[TREE_FURN_CONTRACT].bmp :
2890 style->furn[TREE_FURN_EXPAND].bmp;
2891 }
2892
2893 /* Render background */
2894 rect.x0 = r->x0;
2895 rect.y0 = render_y;
2896 rect.x1 = r->x1;
2897 rect.y1 = render_y + height;
2898 ctx->plot->rectangle(ctx, bg_style, &rect);
2899
2900 /* Render toggle */
2901 ctx->plot->bitmap(ctx,
2902 furniture,
2903 inset,
2904 render_y + tree_g.line_height / 4,
2905 style->furn[TREE_FURN_EXPAND].size,
2906 style->furn[TREE_FURN_EXPAND].size,
2907 bg_style->fill_colour,
2908 BITMAPF_NONE);
2909
2910 /* Render icon */
2911 if (node->type == TREE_NODE_ENTRY) {
2912 res = TREE_RES_CONTENT;
2913 } else if (node->flags & TV_NFLAGS_SPECIAL) {
2915 } else {
2916 res = TREE_RES_FOLDER;
2917 }
2918
2919 if (treeview_res[res].ready) {
2920 /* Icon resource is available */
2921 data->x = inset + tree_g.step_width;
2922 data->y = render_y + ((tree_g.line_height -
2923 treeview_res[res].height + 1) / 2);
2924 data->background_colour = bg_style->fill_colour;
2925
2926 content_redraw(treeview_res[res].c, data, r, ctx);
2927 }
2928
2929 /* Render text */
2930 x0 = inset + tree_g.step_width + tree_g.icon_step;
2931 ctx->plot->text(ctx,
2932 text_style,
2933 x0, render_y + baseline,
2934 node->text.data,
2935 node->text.len);
2936
2937 /* Rendered the node */
2938 render_y += tree_g.line_height;
2939 if (render_y > r->y1) {
2940 /* Passed the bottom of what's in the clip region.
2941 * Done. */
2942 break;
2943 }
2944
2945
2946 if (node->type != TREE_NODE_ENTRY ||
2947 !(node->flags & TV_NFLAGS_EXPANDED))
2948 /* Done everything for this node */
2949 continue;
2950
2951 /* Render expanded entry fields */
2952 entry = (struct treeview_node_entry *)node;
2953 for (i = 0; i < tree->n_fields - 1; i++) {
2954 struct treeview_field *ef = &(tree->fields[i + 1]);
2955
2956 if (ef->flags & TREE_FLAG_SHOW_NAME) {
2957 int max_width = tree->field_width;
2958
2959 ctx->plot->text(ctx,
2960 infotext_style,
2961 x0 + max_width - ef->value.width - tree_g.step_width,
2962 render_y + baseline,
2963 ef->value.data,
2964 ef->value.len);
2965
2966 ctx->plot->text(ctx,
2967 infotext_style,
2968 x0 + max_width,
2969 render_y + baseline,
2970 entry->fields[i].value.data,
2971 entry->fields[i].value.len);
2972 } else {
2973 ctx->plot->text(ctx,
2974 infotext_style,
2975 x0, render_y + baseline,
2976 entry->fields[i].value.data,
2977 entry->fields[i].value.len);
2978 }
2979
2980 /* Rendered the expanded entry field */
2981 render_y += tree_g.line_height;
2982 }
2983
2984 /* Finished rendering expanded entry */
2985
2986 if (render_y > r->y1) {
2987 /* Passed the bottom of what's in the clip region.
2988 * Done. */
2989 break;
2990 }
2991 }
2992
2993 *render_y_in_out = render_y;
2994}
2995
2996
2997/* Exported interface, documented in treeview.h */
2998void
3000 const int x,
3001 const int y,
3002 struct rect *clip,
3003 const struct redraw_context *ctx)
3004{
3005 struct redraw_context new_ctx = *ctx;
3006 struct content_redraw_data data;
3007 struct rect r;
3008 struct rect rect;
3009 int render_y = y;
3010
3011 assert(tree != NULL);
3012 assert(tree->root != NULL);
3013 assert(tree->root->flags & TV_NFLAGS_EXPANDED);
3014
3015 /* Start knockout rendering if it's available for this plotter */
3016 if (ctx->plot->option_knockout) {
3017 knockout_plot_start(ctx, &new_ctx);
3018 }
3019
3020 /* Set up clip rectangle */
3021 r.x0 = clip->x0 + x;
3022 r.y0 = clip->y0 + y;
3023 r.x1 = clip->x1 + x;
3024 r.y1 = clip->y1 + y;
3025 new_ctx.plot->clip(&new_ctx, &r);
3026
3027 /* Setup common content redraw data */
3028 data.width = tree_g.icon_size;
3029 data.height = tree_g.icon_size;
3030 data.scale = 1;
3031 data.repeat_x = false;
3032 data.repeat_y = false;
3033
3034 if (tree->flags & TREEVIEW_SEARCHABLE) {
3035 if (render_y < r.y1) {
3037
3038 /* Fill the blank area at the bottom */
3039 rect.x0 = r.x0;
3040 rect.y0 = render_y;
3041 rect.x1 = r.x1;
3042 rect.y1 = render_y + tree_g.line_height;
3043 new_ctx.plot->rectangle(&new_ctx, &plot_style_even.bg,
3044 &rect);
3045
3046 if (treeview_res[icon].ready) {
3047 /* Icon resource is available */
3048 data.x = tree_g.window_padding;
3049 data.y = render_y + ((tree_g.line_height -
3050 treeview_res[icon].height + 1) /
3051 2);
3053 fill_colour;
3054
3056 &data, &r, &new_ctx);
3057 }
3058
3061 tree_g.icon_step, y,
3063 &r, &new_ctx);
3064 }
3065 render_y += tree_g.line_height;
3066 }
3067
3068 /* Render the treeview data */
3069 if (tree->search.search == true) {
3070 treeview_redraw_search(tree, x, y,
3071 &render_y, &r, &data, &new_ctx);
3072 } else {
3073 treeview_redraw_tree(tree, x, y,
3074 &render_y, &r, &data, &new_ctx);
3075 }
3076
3077 if (render_y < r.y1) {
3078 /* Fill the blank area at the bottom */
3079 rect.x0 = r.x0;
3080 rect.y0 = render_y;
3081 rect.x1 = r.x1;
3082 rect.y1 = r.y1;
3083 new_ctx.plot->rectangle(&new_ctx, &plot_style_even.bg, &rect);
3084 }
3085
3086 /* All normal treeview rendering is done; render any overlays */
3087 if ((tree->move.target_pos != TV_TARGET_NONE) &&
3089 /* Got a MOVE drag; render move indicator arrow */
3090 data.x = tree->move.target_area.x0 + x;
3091 data.y = tree->move.target_area.y0 + y;
3093
3094 content_redraw(treeview_res[TREE_RES_ARROW].c, &data, &r, &new_ctx);
3095
3096 } else if (tree->edit.textarea != NULL) {
3097 /* Edit in progress; render textarea */
3099 tree->edit.x + x, tree->edit.y + y,
3101 &r, &new_ctx);
3102 }
3103
3104 /* Rendering complete */
3105 if (ctx->plot->option_knockout) {
3106 knockout_plot_end(ctx);
3107 }
3108}
3109
3110
3111/**
3112 * context for treeview selection
3113 */
3115 enum {
3126 union {
3128 struct {
3130 struct rect *rect;
3132 struct {
3136 struct {
3140 struct {
3143 struct {
3144 char *text;
3145 uint32_t len;
3150};
3151
3152
3153/**
3154 * Treewalk node callback for handling selection related actions.
3155 *
3156 * \param n current node
3157 * \param ctx node selection context
3158 * \param skip_children flag to allow children to be skipped
3159 * \param end flag to allow iteration to be finished early.
3160 * \return NSERROR_OK on success else error code.
3161 */
3162static nserror
3164 void *ctx,
3165 bool *skip_children,
3166 bool *end)
3167{
3168 struct treeview_selection_walk_data *sw = ctx;
3169 int height;
3170 bool changed = false;
3171 nserror err;
3172
3174 sw->current_y += height;
3175
3176 switch (sw->purpose) {
3178 if (n->flags & TV_NFLAGS_SELECTED) {
3179 sw->data.has_selection = true;
3180 *end = true; /* Can abort tree walk */
3181 return NSERROR_OK;
3182 }
3183 break;
3184
3186 if (n->flags & TV_NFLAGS_SELECTED) {
3187 sw->data.first.n = n;
3188 *end = true; /* Can abort tree walk */
3189 return NSERROR_OK;
3190 }
3191 break;
3192
3194 if (n->flags & TV_NFLAGS_SELECTED) {
3195 err = treeview_delete_node_internal(sw->tree, n, true,
3197 if (err != NSERROR_OK) {
3198 return err;
3199 }
3200 *skip_children = true;
3201 changed = true;
3202 }
3203 break;
3204
3206 if (n->parent != NULL &&
3208 !(n->flags & TV_NFLAGS_SELECTED)) {
3210 changed = true;
3211 }
3212 break;
3213
3215 if (n->flags & TV_NFLAGS_SELECTED) {
3217 changed = true;
3218 }
3219 break;
3220
3222 if (!(n->flags & TV_NFLAGS_SELECTED)) {
3224 changed = true;
3225 }
3226 break;
3227
3229 if (sw->current_y >= sw->data.drag.sel_min &&
3230 sw->current_y - height <
3231 sw->data.drag.sel_max) {
3233 }
3234 return NSERROR_OK;
3235
3237 if (n->flags & TV_NFLAGS_SELECTED) {
3238 treeview_node *p = n->parent;
3239 int h = 0;
3240
3241 if (n == sw->data.yank.fixed) {
3242 break;
3243 }
3244
3246 h = n->height;
3247
3248 /* Reduce ancestor heights */
3249 while (p != NULL && p->flags & TV_NFLAGS_EXPANDED) {
3250 p->height -= h;
3251 p = p->parent;
3252 }
3253 if (sw->data.yank.prev == NULL) {
3254 sw->tree->move.root = n;
3255 n->parent = NULL;
3256 n->prev_sib = NULL;
3257 n->next_sib = NULL;
3258 } else {
3259 n->parent = NULL;
3260 n->prev_sib = sw->data.yank.prev;
3261 n->next_sib = NULL;
3262 sw->data.yank.prev->next_sib = n;
3263 }
3264 sw->data.yank.prev = n;
3265
3266 *skip_children = true;
3267 }
3268 break;
3269
3271 if (n->flags & TV_NFLAGS_SELECTED &&
3272 n->type == TREE_NODE_ENTRY) {
3273 int i;
3274 char *temp;
3275 uint32_t len;
3276 const char *text;
3277 struct treeview_field *ef;
3278 struct treeview_text *val;
3279
3280 for (i = 0; i < sw->tree->n_fields; i++) {
3281 ef = &(sw->tree->fields[i]);
3282
3283 if (!(ef->flags & TREE_FLAG_COPY_TEXT)) {
3284 continue;
3285 }
3287 n, i);
3288 text = val->data;
3289 len = val->len;
3290
3291 temp = realloc(sw->data.copy.text,
3292 sw->data.copy.len + len + 1);
3293 if (temp == NULL) {
3294 free(sw->data.copy.text);
3295 sw->data.copy.text = NULL;
3296 sw->data.copy.len = 0;
3297 return NSERROR_NOMEM;
3298 }
3299
3300 if (sw->data.copy.len != 0) {
3301 temp[sw->data.copy.len - 1] = '\n';
3302 }
3303 memcpy(temp + sw->data.copy.len, text, len);
3304 temp[sw->data.copy.len + len] = '\0';
3305 sw->data.copy.len += len + 1;
3306 sw->data.copy.text = temp;
3307 }
3308 }
3309 break;
3310 }
3311
3312 if (changed) {
3313 if (sw->data.redraw.required == false) {
3314 sw->data.redraw.required = true;
3315 sw->data.redraw.rect->y0 = sw->current_y - height;
3316 }
3317
3318 if (sw->current_y > sw->data.redraw.rect->y1) {
3319 sw->data.redraw.rect->y1 = sw->current_y;
3320 }
3321 }
3322
3323 return NSERROR_OK;
3324}
3325
3326
3327/* Exported interface, documented in treeview.h */
3329{
3331
3333 sw.data.has_selection = false;
3334
3338
3339 return sw.data.has_selection;
3340}
3341
3342
3343/**
3344 * Get first selected node (in any)
3345 *
3346 * \param tree Treeview object in which to create folder
3347 * \return the first selected treeview node, or NULL
3348 */
3350{
3352
3354 sw.data.first.n = NULL;
3355
3359
3360 return sw.data.first.n;
3361}
3362
3363
3364/* Exported interface, documented in treeview.h */
3366 void **node_data)
3367{
3369
3370 assert(tree != NULL);
3371
3373
3374 if (n != NULL && n->type & (TREE_NODE_ENTRY | TREE_NODE_FOLDER)) {
3375 *node_data = n->client_data;
3376 return n->type;
3377 }
3378
3379 *node_data = NULL;
3380 return TREE_NODE_NONE;
3381}
3382
3383
3384/**
3385 * Clear any selection in a treeview
3386 *
3387 * \param tree Treeview object to clear selection in
3388 * \param rect Redraw rectangle (if redraw required)
3389 * \return true iff redraw required
3390 */
3392{
3394
3395 rect->x0 = 0;
3396 rect->y0 = 0;
3397 rect->x1 = REDRAW_MAX;
3398 rect->y1 = 0;
3399
3401 sw.data.redraw.required = false;
3402 sw.data.redraw.rect = rect;
3404
3408
3409 return sw.data.redraw.required;
3410}
3411
3412
3413/**
3414 * Select all in a treeview
3415 *
3416 * \param tree Treeview object to select all in
3417 * \param rect Redraw rectangle (if redraw required)
3418 * \return true iff redraw required
3419 */
3421{
3423
3424 rect->x0 = 0;
3425 rect->y0 = 0;
3426 rect->x1 = REDRAW_MAX;
3427 rect->y1 = 0;
3428
3430 sw.data.redraw.required = false;
3431 sw.data.redraw.rect = rect;
3433
3437
3438 return sw.data.redraw.required;
3439}
3440
3441
3442/**
3443 * Commit a current selection drag, modifying the node's selection state.
3444 *
3445 * \param tree Treeview object to commit drag selection in
3446 */
3448{
3450
3453
3454 if (tree->drag.start.y > tree->drag.prev.y) {
3455 sw.data.drag.sel_min = tree->drag.prev.y;
3457 } else {
3459 sw.data.drag.sel_max = tree->drag.prev.y;
3460 }
3461
3465}
3466
3467
3468/**
3469 * Yank a selection to the node move list.
3470 *
3471 * \param tree Treeview object to yank selection from
3472 * \param fixed Treeview node that should not be yanked
3473 */
3475{
3477
3479 sw.data.yank.fixed = fixed;
3480 sw.data.yank.prev = NULL;
3481 sw.tree = tree;
3482
3486}
3487
3488
3489/**
3490 * Copy a selection to the clipboard.
3491 *
3492 * \param tree Treeview object to yank selection from
3493 */
3495{
3497 nserror err;
3498
3500 sw.data.copy.text = NULL;
3501 sw.data.copy.len = 0;
3502 sw.tree = tree;
3503
3507 if (err != NSERROR_OK) {
3508 return;
3509 }
3510
3511 if (sw.data.copy.text != NULL) {
3513 sw.data.copy.len - 1, NULL, 0);
3514 free(sw.data.copy.text);
3515 }
3516}
3517
3518
3519/**
3520 * Delete a selection.
3521 *
3522 * \param tree Treeview object to delete selected nodes from
3523 * \param rect Updated to redraw rectangle
3524 * \return true iff redraw required.
3525 */
3527{
3529
3530 assert(tree != NULL);
3531 assert(tree->root != NULL);
3532
3533 rect->x0 = 0;
3534 rect->y0 = 0;
3535 rect->x1 = REDRAW_MAX;
3537
3539 sw.data.redraw.required = false;
3540 sw.data.redraw.rect = rect;
3542 sw.tree = tree;
3543
3547
3548 return sw.data.redraw.required;
3549}
3550
3551
3552/**
3553 * Propagate selection to visible descendants of selected nodes.
3554 *
3555 * \param tree Treeview object to propagate selection in
3556 * \param rect Redraw rectangle (if redraw required)
3557 * \return true iff redraw required
3558 */
3560{
3562
3563 assert(tree != NULL);
3564 assert(tree->root != NULL);
3565
3566 rect->x0 = 0;
3567 rect->y0 = 0;
3568 rect->x1 = REDRAW_MAX;
3569 rect->y1 = 0;
3570
3572 sw.data.redraw.required = false;
3573 sw.data.redraw.rect = rect;
3575 sw.tree = tree;
3576
3580
3581 return sw.data.redraw.required;
3582}
3583
3584
3585/**
3586 * Move a selection according to the current move drag.
3587 *
3588 * \param tree Treeview object to move selected nodes in
3589 * \param rect Redraw rectangle
3590 * \return NSERROR_OK on success else appropriate error code
3591 */
3593{
3594 treeview_node *node, *next, *parent;
3595 treeview_node *relation;
3596 enum treeview_relationship relationship;
3597 int height;
3598
3599 assert(tree != NULL);
3600 assert(tree->root != NULL);
3601 assert(tree->root->children != NULL);
3602 assert(tree->move.target_pos != TV_TARGET_NONE);
3603
3604 height = tree->root->height;
3605
3606 /* Identify target location */
3607 switch (tree->move.target_pos) {
3608 case TV_TARGET_ABOVE:
3609 if (tree->move.target == NULL) {
3610 /* Target: After last child of root */
3611 relation = tree->root->children;
3612 while (relation->next_sib != NULL) {
3613 relation = relation->next_sib;
3614 }
3615 relationship = TREE_REL_NEXT_SIBLING;
3616
3617 } else if (tree->move.target->prev_sib != NULL) {
3618 /* Target: After previous sibling */
3619 relation = tree->move.target->prev_sib;
3620 relationship = TREE_REL_NEXT_SIBLING;
3621
3622 } else {
3623 /* Target: Target: First child of parent */
3624 assert(tree->move.target->parent != NULL);
3625 relation = tree->move.target->parent;
3626 relationship = TREE_REL_FIRST_CHILD;
3627 }
3628 break;
3629
3630 case TV_TARGET_INSIDE:
3631 assert(tree->move.target != NULL);
3632 relation = tree->move.target;
3633 relationship = TREE_REL_FIRST_CHILD;
3634 break;
3635
3636 case TV_TARGET_BELOW:
3637 assert(tree->move.target != NULL);
3638 relation = tree->move.target;
3639 relationship = TREE_REL_NEXT_SIBLING;
3640 break;
3641
3642 default:
3643 NSLOG(netsurf, INFO, "Bad drop target for move.");
3644 return NSERROR_BAD_PARAMETER;
3645 }
3646
3647 if (relationship == TREE_REL_FIRST_CHILD) {
3648 parent = relation;
3649 } else {
3650 parent = relation->parent;
3651 }
3652
3653 /* Move all selected nodes from treeview to tree->move.root */
3655
3656 /* Move all nodes on tree->move.root to target location */
3657 for (node = tree->move.root; node != NULL; node = next) {
3658 next = node->next_sib;
3659
3660 if (node == relation) {
3661 continue;
3662 }
3663
3664 if (!(parent->flags & TV_NFLAGS_EXPANDED)) {
3665 if (node->flags & TV_NFLAGS_EXPANDED)
3667 node->flags &= ~TV_NFLAGS_SELECTED;
3668 }
3669
3670 treeview_insert_node(tree, node, relation, relationship);
3671
3672 relation = node;
3673 relationship = TREE_REL_NEXT_SIBLING;
3674 }
3675 tree->move.root = NULL;
3676
3677 /* Tell window, if height has changed */
3678 if (height != tree->root->height)
3680
3681 /* TODO: Deal with redraw area properly */
3682 rect->x0 = 0;
3683 rect->y0 = 0;
3684 rect->x1 = REDRAW_MAX;
3685 rect->y1 = REDRAW_MAX;
3686
3687 return NSERROR_OK;
3688}
3689
3690
3691/**
3692 * context for treeview launch action
3693 */
3697};
3698
3699
3700/**
3701 * Treewalk node walk backward callback for tracking folder selection.
3702 */
3703static nserror
3705{
3706 struct treeview_launch_walk_data *lw = ctx;
3707
3708 if (n->type == TREE_NODE_FOLDER && n->flags == TV_NFLAGS_SELECTED) {
3709 lw->selected_depth--;
3710 }
3711
3712 return NSERROR_OK;
3713}
3714
3715
3716/**
3717 * Treewalk node walk forward callback for launching nodes.
3718 *
3719 * \param n current node
3720 * \param ctx node launch context
3721 * \param skip_children flag to allow children to be skipped
3722 * \param end flag to allow iteration to be finished early.
3723 * \return NSERROR_OK on success else error code.
3724 */
3725static nserror
3727 void *ctx,
3728 bool *skip_children,
3729 bool *end)
3730{
3731 struct treeview_launch_walk_data *lw = ctx;
3732 nserror ret = NSERROR_OK;
3733
3734 if (n->type == TREE_NODE_FOLDER && n->flags & TV_NFLAGS_SELECTED) {
3735 lw->selected_depth++;
3736
3737 } else if (n->type == TREE_NODE_ENTRY &&
3738 (n->flags & TV_NFLAGS_SELECTED ||
3739 lw->selected_depth > 0)) {
3740 struct treeview_node_msg msg;
3742 msg.data.node_launch.mouse = BROWSER_MOUSE_HOVER;
3743 ret = lw->tree->callbacks->entry(msg, n->client_data);
3744 }
3745
3746 return ret;
3747}
3748
3749
3750/**
3751 * Launch a selection.
3752 *
3753 * \note Selected entries are launched. Entries that are descendants
3754 * of selected folders are also launched.
3755 *
3756 * \param tree Treeview object to launch selected nodes in
3757 * \return NSERROR_OK on success, appropriate error otherwise
3758 */
3760{
3761 struct treeview_launch_walk_data lw;
3762
3763 assert(tree != NULL);
3764 assert(tree->root != NULL);
3765
3766 lw.selected_depth = 0;
3767 lw.tree = tree;
3768
3773}
3774
3775
3776/* Exported interface, documented in treeview.h */
3777nserror
3779 treeview_node **relation,
3780 enum treeview_relationship *rel,
3781 bool at_y,
3782 int y)
3783{
3784 treeview_node *n;
3785
3786 assert(tree != NULL);
3787
3788 if (at_y) {
3789 n = treeview_y_node(tree, y);
3790
3791 } else {
3793 }
3794
3795 if (n != NULL && n->parent != NULL) {
3796 if (n == n->parent->children) {
3797 /* First child */
3798 *relation = n->parent;
3799 *rel = TREE_REL_FIRST_CHILD;
3800 } else {
3801 /* Not first child */
3802 *relation = n->prev_sib;
3803 *rel = TREE_REL_NEXT_SIBLING;
3804 }
3805 } else {
3806 if (tree->root->children == NULL) {
3807 /* First child of root */
3808 *relation = tree->root;
3809 *rel = TREE_REL_FIRST_CHILD;
3810 } else {
3811 /* Last child of root */
3812 n = tree->root->children;
3813 while (n->next_sib != NULL)
3814 n = n->next_sib;
3815 *relation = n;
3816 *rel = TREE_REL_NEXT_SIBLING;
3817 }
3818 }
3819
3820 return NSERROR_OK;
3821}
3822
3823
3824/**
3825 * context for treeview keyboard action
3826 */
3835};
3836
3837
3838/**
3839 * Treewalk node callback for handling mouse action.
3840 *
3841 * \param node current node
3842 * \param ctx node context
3843 * \param skip_children flag to allow children to be skipped
3844 * \param end flag to allow iteration to be finished early.
3845 * \return NSERROR_OK on success else error code.
3846 */
3847static nserror
3849 void *ctx,
3850 bool *skip_children,
3851 bool *end)
3852{
3853 struct treeview_nav_state *ns = ctx;
3854
3855 if (node == ns->tree->root)
3856 return NSERROR_OK;
3857
3858 if (node->flags & TV_NFLAGS_SELECTED) {
3859 ns->n_selected++;
3860 if (ns->curr == NULL) {
3861 ns->curr = node;
3862 }
3863
3864 } else {
3865 if (ns->n_selected == 0) {
3866 ns->prev = node;
3867
3868 } else if (ns->prev_n_selected < ns->n_selected) {
3869 ns->next = node;
3870 ns->prev_n_selected = ns->n_selected;
3871 }
3872 }
3873 ns->last = node;
3874
3875 return NSERROR_OK;
3876}
3877
3878
3879/**
3880 * Handle keyboard navigation.
3881 *
3882 * \note Selected entries are launched.
3883 * Entries that are descendants of selected folders are also launched.
3884 *
3885 * \param tree Treeview object to launch selected nodes in
3886 * \param key The ucs4 character codepoint
3887 * \param rect Updated to redraw rectangle
3888 * \return true if treeview needs redraw, false otherwise
3889 */
3890static bool
3892{
3893 struct treeview_nav_state ns = {
3894 .tree = tree,
3895 .prev = NULL,
3896 .curr = NULL,
3897 .next = NULL,
3898 .last = NULL,
3899 .n_selected = 0,
3900 .prev_n_selected = 0
3901 };
3902 int search_height = treeview__get_search_height(tree);
3903 int h = treeview__get_display_height(tree) + search_height;
3904 bool redraw = false;
3905 struct treeview_node *scroll_to_node = NULL;
3906
3907 /* Fill out the nav. state struct, by examining the current selection
3908 * state */
3909 treeview_walk_internal(tree, tree->root,
3912
3913 scroll_to_node = ns.curr;
3914
3915 if (tree->search.search == false) {
3916 if (ns.next == NULL)
3917 ns.next = tree->root->children;
3918 if (ns.prev == NULL)
3919 ns.prev = ns.last;
3920 }
3921
3922 /* Clear any existing selection */
3923 redraw = treeview_clear_selection(tree, rect);
3924
3925 switch (key) {
3926 case NS_KEY_LEFT:
3927 if (tree->search.search == true) {
3928 break;
3929 }
3930 if (ns.curr != NULL &&
3931 ns.curr->parent != NULL &&
3932 ns.curr->parent->type != TREE_NODE_ROOT) {
3933 /* Step to parent */
3935 scroll_to_node = ns.curr->parent;
3936
3937 } else if (ns.curr != NULL && tree->root->children != NULL) {
3938 /* Select first node in tree */
3940 scroll_to_node = tree->root->children;
3941 }
3942 break;
3943
3944 case NS_KEY_RIGHT:
3945 if (ns.curr != NULL) {
3946 if (!(ns.curr->flags & TV_NFLAGS_EXPANDED)) {
3947 /* Toggle node to expanded */
3949 if (ns.curr->children != NULL) {
3950 /* Step to first child */
3951 ns.curr->children->flags |=
3953 scroll_to_node = ns.curr->children;
3954 } else {
3955 /* Retain current node selection */
3957 }
3958 } else {
3959 /* Toggle node to contracted */
3961 /* Retain current node selection */
3963 }
3964
3965 } else if (ns.curr != NULL) {
3966 /* Retain current node selection */
3968 }
3969 break;
3970
3971 case NS_KEY_UP:
3972 if (ns.prev != NULL) {
3973 /* Step to previous node */
3975 scroll_to_node = ns.prev;
3976 }
3977 break;
3978
3979 case NS_KEY_DOWN:
3980 if (ns.next != NULL) {
3981 /* Step to next node */
3983 scroll_to_node = ns.next;
3984 }
3985 break;
3986
3987 default:
3988 break;
3989 }
3990
3991 treeview__cw_scroll_to_node(tree, scroll_to_node);
3992
3993 /* TODO: Deal with redraw area properly */
3994 rect->x0 = 0;
3995 rect->y0 = 0;
3996 rect->x1 = REDRAW_MAX;
3997 if (treeview__get_display_height(tree) + search_height > h)
3998 rect->y1 = treeview__get_display_height(tree) + search_height;
3999 else
4000 rect->y1 = h;
4001 redraw = true;
4002
4003 return redraw;
4004}
4005
4006
4007/* Exported interface, documented in treeview.h */
4008bool treeview_keypress(treeview *tree, uint32_t key)
4009{
4010 struct rect r; /**< Redraw rectangle */
4011 bool redraw = false;
4012
4013 assert(tree != NULL);
4014
4015 /* Pass to any textarea, if editing in progress */
4016 if (tree->edit.textarea != NULL) {
4017 switch (key) {
4018 case NS_KEY_ESCAPE:
4019 treeview_edit_cancel(tree, true);
4020 return true;
4021 case NS_KEY_NL:
4022 case NS_KEY_CR:
4023 treeview_edit_done(tree);
4024 return true;
4025 default:
4026 return textarea_keypress(tree->edit.textarea, key);
4027 }
4028 } else if (tree->search.active == true) {
4029 switch (key) {
4030 case NS_KEY_ESCAPE:
4031 treeview__search_cancel(tree, false);
4032 return true;
4033 case NS_KEY_NL:
4034 case NS_KEY_CR:
4035 return true;
4036 default:
4037 return textarea_keypress(tree->search.textarea, key);
4038 }
4039 }
4040
4041 /* Keypress to be handled by treeview */
4042 switch (key) {
4043 case NS_KEY_SELECT_ALL:
4044 redraw = treeview_select_all(tree, &r);
4045 break;
4048 break;
4049 case NS_KEY_DELETE_LEFT:
4051 redraw = treeview_delete_selection(tree, &r);
4052
4053 if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) {
4054 int h = tree->root->height;
4055 /* Delete any empty nodes */
4056 treeview_delete_empty_nodes(tree, false);
4057
4058 /* Inform front end of change in dimensions */
4059 if (tree->root->height != h) {
4060 r.y0 = 0;
4061 treeview__cw_update_size(tree, -1,
4062 tree->root->height);
4063 }
4064 }
4065 break;
4066 case NS_KEY_CR:
4067 case NS_KEY_NL:
4069 break;
4070 case NS_KEY_ESCAPE:
4072 redraw = treeview_clear_selection(tree, &r);
4073 break;
4074 case NS_KEY_LEFT:
4075 case NS_KEY_RIGHT:
4076 case NS_KEY_UP:
4077 case NS_KEY_DOWN:
4078 redraw = treeview_keyboard_navigation(tree, key, &r);
4079 break;
4080 default:
4081 return false;
4082 }
4083
4084 if (redraw) {
4086 }
4087
4088 return true;
4089}
4090
4091
4092/**
4093 * Set the drag&drop drop indicator
4094 *
4095 * \param tree Treeview object to set node indicator in
4096 * \param need_redraw True iff we already have a redraw region
4097 * \param target The treeview node with mouse pointer over it
4098 * \param node_height The height of node
4099 * \param node_y The Y coord of the top of target node
4100 * \param mouse_y Y coord of mouse position
4101 * \param rect Redraw rectangle (if redraw required)
4102 * \return true iff redraw required
4103 */
4104static bool
4106 bool need_redraw,
4107 treeview_node *target,
4108 int node_height,
4109 int node_y,
4110 int mouse_y,
4111 struct rect *rect)
4112{
4113 treeview_node *orig = target;
4114 enum treeview_target_pos target_pos;
4115 int mouse_pos = mouse_y - node_y;
4116 int x;
4117
4118 assert(tree != NULL);
4119 assert(tree->root != NULL);
4120 assert(tree->root->children != NULL);
4121 assert(target != NULL);
4122
4123 if (target->flags & TV_NFLAGS_SELECTED) {
4124 /* Find top selected ancestor */
4125 while (target->parent &&
4126 target->parent->flags & TV_NFLAGS_SELECTED) {
4127 target = target->parent;
4128 }
4129
4130 /* Find top adjacent selected sibling */
4131 while (target->prev_sib &&
4132 target->prev_sib->flags & TV_NFLAGS_SELECTED) {
4133 target = target->prev_sib;
4134 }
4135 target_pos = TV_TARGET_ABOVE;
4136
4137 } else switch (target->type) {
4138 case TREE_NODE_FOLDER:
4139 if (mouse_pos <= node_height / 4) {
4140 target_pos = TV_TARGET_ABOVE;
4141 } else if (mouse_pos <= (3 * node_height) / 4 ||
4142 target->flags & TV_NFLAGS_EXPANDED) {
4143 target_pos = TV_TARGET_INSIDE;
4144 } else {
4145 target_pos = TV_TARGET_BELOW;
4146 }
4147 break;
4148
4149 case TREE_NODE_ENTRY:
4150 if (mouse_pos <= node_height / 2) {
4151 target_pos = TV_TARGET_ABOVE;
4152 } else {
4153 target_pos = TV_TARGET_BELOW;
4154 }
4155 break;
4156
4157 default:
4158 assert(target->type != TREE_NODE_ROOT);
4159 return false;
4160 }
4161
4162 if (target_pos == tree->move.target_pos &&
4163 target == tree->move.target) {
4164 /* No change */
4165 return need_redraw;
4166 }
4167
4168 if (tree->move.target_pos != TV_TARGET_NONE) {
4169 /* Need to clear old indicator position */
4170 if (need_redraw) {
4171 if (rect->x0 > tree->move.target_area.x0)
4172 rect->x0 = tree->move.target_area.x0;
4173 if (tree->move.target_area.x1 > rect->x1)
4174 rect->x1 = tree->move.target_area.x1;
4175 if (rect->y0 > tree->move.target_area.y0)
4176 rect->y0 = tree->move.target_area.y0;
4177 if (tree->move.target_area.y1 > rect->y1)
4178 rect->y1 = tree->move.target_area.y1;
4179 } else {
4180 *rect = tree->move.target_area;
4181 need_redraw = true;
4182 }
4183 }
4184
4185 /* Offset for ABOVE / BELOW */
4186 if (target_pos == TV_TARGET_ABOVE) {
4187 if (target != orig) {
4188 node_y = treeview_node_y(tree, target);
4189 }
4190 node_y -= (tree_g.line_height + 1) / 2;
4191 } else if (target_pos == TV_TARGET_BELOW) {
4192 node_y += node_height - (tree_g.line_height + 1) / 2;
4193 }
4194
4195 /* Oftsets are all relative to centred (INSIDE) */
4196 node_y += (tree_g.line_height -
4198
4199 x = target->inset + tree_g.move_offset;
4200
4201 /* Update target details */
4202 tree->move.target = target;
4203 tree->move.target_pos = target_pos;
4204 tree->move.target_area.x0 = x;
4205 tree->move.target_area.y0 = node_y;
4206 tree->move.target_area.x1 = tree_g.icon_size + x;
4207 tree->move.target_area.y1 = tree_g.icon_size + node_y;
4208
4209 if (target_pos != TV_TARGET_NONE) {
4210 /* Need to draw new indicator position */
4211 if (need_redraw) {
4212 if (rect->x0 > tree->move.target_area.x0)
4213 rect->x0 = tree->move.target_area.x0;
4214 if (tree->move.target_area.x1 > rect->x1)
4215 rect->x1 = tree->move.target_area.x1;
4216 if (rect->y0 > tree->move.target_area.y0)
4217 rect->y0 = tree->move.target_area.y0;
4218 if (tree->move.target_area.y1 > rect->y1)
4219 rect->y1 = tree->move.target_area.y1;
4220 } else {
4221 *rect = tree->move.target_area;
4222 need_redraw = true;
4223 }
4224 }
4225
4226 return need_redraw;
4227}
4228
4229
4230/**
4231 * Callback for textarea_create, in desktop/treeview.h
4232 *
4233 * \param data treeview context
4234 * \param msg textarea message
4235 */
4236static void treeview_textarea_callback(void *data, struct textarea_msg *msg)
4237{
4238 treeview *tree = data;
4239 struct rect *r;
4240
4241 switch (msg->type) {
4243 if (msg->data.drag == TEXTAREA_DRAG_NONE) {
4244 /* Textarea drag finished */
4245 tree->drag.type = TV_DRAG_NONE;
4246 } else {
4247 /* Textarea drag started */
4248 tree->drag.type = TV_DRAG_TEXTAREA;
4249 }
4252 break;
4253
4255 r = &msg->data.redraw;
4256 r->x0 += tree->edit.x;
4257 r->y0 += tree->edit.y;
4258 r->x1 += tree->edit.x;
4259 r->y1 += tree->edit.y;
4260
4261 /* Redraw the textarea */
4263 break;
4264
4265 default:
4266 break;
4267 }
4268}
4269
4270
4271/**
4272 * Start edit of node field, at given y-coord, if editable
4273 *
4274 * \param tree Treeview object to consider editing in
4275 * \param n The treeview node to try editing
4276 * \param node_y The Y coord of the top of n
4277 * \param mouse_x X coord of mouse position
4278 * \param mouse_y Y coord of mouse position
4279 * \param rect Redraw rectangle (if redraw required)
4280 * \return true iff redraw required
4281 */
4282static bool
4284 treeview_node *n,
4285 int node_y,
4286 int mouse_x,
4287 int mouse_y,
4288 struct rect *rect)
4289{
4290 struct treeview_text *field_data = NULL;
4291 struct treeview_field *ef, *field_desc = NULL;
4292 int pos = node_y + tree_g.line_height;
4293 int field_y = node_y;
4294 int field_x;
4295 int width, height;
4296 bool success;
4297
4298 /* If the main field is editable, make field_data point to it */
4299 if (n->type == TREE_NODE_ENTRY)
4300 ef = &(tree->fields[0]);
4301 else
4302 ef = &(tree->fields[tree->n_fields]);
4303 if (ef->flags & TREE_FLAG_ALLOW_EDIT) {
4304 field_data = &n->text;
4305 field_desc = ef;
4306 field_y = node_y;
4307 }
4308
4309 /* Check for editable entry fields */
4310 if (n->type == TREE_NODE_ENTRY && n->height != tree_g.line_height) {
4311 struct treeview_node_entry *e = (struct treeview_node_entry *)n;
4312 int i;
4313
4314 for (i = 0; i < tree->n_fields - 1; i++) {
4315 if (mouse_y <= pos)
4316 continue;
4317
4318 ef = &(tree->fields[i + 1]);
4319 pos += tree_g.line_height;
4320 if (mouse_y <= pos && (ef->flags &
4322 field_data = &e->fields[i].value;
4323 field_desc = ef;
4324 field_y = pos - tree_g.line_height;
4325 }
4326 }
4327 }
4328
4329 if (field_data == NULL || field_desc == NULL) {
4330 /* No editable field */
4331 return false;
4332 }
4333
4334 /* Get window width/height */
4336
4337 /* Calculate textarea width/height */
4338 field_x = n->inset + tree_g.step_width + tree_g.icon_step - 3;
4339 width -= field_x;
4341
4342 /* Create text area */
4344 0x000000, 0xffffff, 0x000000, plot_style_odd.text,
4346 if (tree->edit.textarea == NULL) {
4347 return false;
4348 }
4349
4350 success = textarea_set_text(tree->edit.textarea, field_data->data);
4351 if (!success) {
4353 return false;
4354 }
4355
4356 tree->edit.node = n;
4357 tree->edit.field = field_desc->field;
4358
4359 /* Position the caret */
4360 mouse_x -= field_x;
4361 if (mouse_x < 0)
4362 mouse_x = 0;
4363 else if (mouse_x >= width)
4364 mouse_x = width - 1;
4365
4369
4370 /* Position the textarea */
4371 tree->edit.x = field_x;
4372 tree->edit.y = field_y;
4373 tree->edit.w = width;
4374 tree->edit.h = height;
4375
4376 /* Setup redraw rectangle */
4377 if (rect->x0 > field_x)
4378 rect->x0 = field_x;
4379 if (rect->y0 > field_y)
4380 rect->y0 = field_y;
4381 if (rect->x1 < field_x + width)
4382 rect->x1 = field_x + width;
4383 if (rect->y1 < field_y + height)
4384 rect->y1 = field_y + height;
4385
4386 return true;
4387}
4388
4389
4390/* Exported interface, documented in treeview.h */
4392{
4393 struct rect rect;
4394 treeview_node *n;
4395 bool redraw;
4396 int y;
4397
4398 assert(tree != NULL);
4399 assert(tree->root != NULL);
4400
4401 /* Get first selected node */
4403
4404 if (n == NULL)
4405 return;
4406
4407 /* Get node's y-position */
4408 y = treeview_node_y(tree, n);
4409
4410 /* Edit node at y */
4411 redraw = treeview_edit_node_at_point(tree, n, y,
4412 0, y + tree_g.line_height / 2, &rect);
4413
4414 if (redraw == false)
4415 return;
4416
4417 /* Redraw */
4418 rect.x0 = 0;
4419 rect.y0 = y;
4420 rect.x1 = REDRAW_MAX;
4421 rect.y1 = y + tree_g.line_height;
4423}
4424
4425
4426/**
4427 * context for treeview mouse handling
4428 */
4432 int x;
4433 int y;
4434 int current_y; /* Y coordinate value of top of current node */
4436};
4437
4438
4439/**
4440 * Treewalk node callback for handling mouse action.
4441 *
4442 * \param node current node
4443 * \param ctx node context
4444 * \param skip_children flag to allow children to be skipped
4445 * \param end flag to allow iteration to be finished early.
4446 * \return NSERROR_OK on success else error code.
4447 */
4448static nserror
4450 void *ctx,
4451 bool *skip_children,
4452 bool *end)
4453{
4454 struct treeview_mouse_action *ma = ctx;
4455 struct rect r;
4456 bool redraw = false;
4457 bool click;
4458 int height;
4459 enum {
4460 TV_NODE_ACTION_NONE = 0,
4461 TV_NODE_ACTION_SELECTION = (1 << 0)
4462 } action = TV_NODE_ACTION_NONE;
4464 nserror err;
4465
4466 r.x0 = 0;
4467 r.x1 = REDRAW_MAX;
4468
4469 height = (node->type == TREE_NODE_ENTRY) ? node->height :
4471
4472 /* Skip line if we've not reached mouse y */
4473 if (ma->y > ma->current_y + height) {
4474 ma->current_y += height;
4475 return NSERROR_OK; /* Don't want to abort tree walk */
4476 }
4477
4478 /* Find where the mouse is */
4479 if (ma->y <= ma->current_y + tree_g.line_height) {
4480 int inset = node->inset;
4481 if (ma->tree->search.search == true) {
4482 inset = tree_g.window_padding;
4483 }
4484 if (ma->x >= inset - 1 &&
4485 ma->x < inset + tree_g.step_width) {
4486 /* Over expansion toggle */
4487 part = TV_NODE_PART_TOGGLE;
4488
4489 } else if (ma->x >= inset + tree_g.step_width &&
4490 ma->x < inset + tree_g.step_width +
4491 tree_g.icon_step + node->text.width) {
4492 /* On node */
4493 part = TV_NODE_PART_ON_NODE;
4494 }
4495 } else if (node->type == TREE_NODE_ENTRY &&
4497 /* Expanded entries */
4498 int x = node->inset + tree_g.step_width + tree_g.icon_step;
4499 int y = ma->current_y + tree_g.line_height;
4500 int i;
4501 struct treeview_node_entry *entry =
4502 (struct treeview_node_entry *)node;
4503 for (i = 0; i < ma->tree->n_fields - 1; i++) {
4504 struct treeview_field *ef = &(ma->tree->fields[i + 1]);
4505
4506 if (ma->y > y + tree_g.line_height) {
4507 y += tree_g.line_height;
4508 continue;
4509 }
4510
4511 if (ef->flags & TREE_FLAG_SHOW_NAME) {
4512 int max_width = ma->tree->field_width;
4513
4514 if (ma->x >= x + max_width - ef->value.width -
4516 ma->x < x + max_width -
4518 /* On a field name */
4519 part = TV_NODE_PART_ON_NODE;
4520
4521 } else if (ma->x >= x + max_width &&
4522 ma->x < x + max_width +
4523 entry->fields[i].value.width) {
4524 /* On a field value */
4525 part = TV_NODE_PART_ON_NODE;
4526 }
4527 } else {
4528 if (ma->x >= x && ma->x < x +
4529 entry->fields[i].value.width) {
4530 /* On a field value */
4531 part = TV_NODE_PART_ON_NODE;
4532 }
4533 }
4534
4535 break;
4536 }
4537 }
4538
4539 /* Record what position / part a drag started on */
4541 ma->tree->drag.type == TV_DRAG_NONE) {
4542 ma->tree->drag.selected = node->flags & TV_NFLAGS_SELECTED;
4543 ma->tree->drag.start_node = node;
4544 ma->tree->drag.part = part;
4545 ma->tree->drag.start.x = ma->x;
4546 ma->tree->drag.start.y = ma->y;
4547 ma->tree->drag.start.node_y = ma->current_y;
4548 ma->tree->drag.start.node_h = height;
4549
4550 ma->tree->drag.prev.x = ma->x;
4551 ma->tree->drag.prev.y = ma->y;
4552 ma->tree->drag.prev.node_y = ma->current_y;
4553 ma->tree->drag.prev.node_h = height;
4554 }
4555
4556 /* Handle drag start */
4557 if (ma->tree->drag.type == TV_DRAG_NONE) {
4558 if (ma->mouse & BROWSER_MOUSE_DRAG_1 &&
4559 ma->tree->drag.selected == false &&
4560 ma->tree->drag.part == TV_NODE_PART_NONE) {
4561 ma->tree->drag.type = TV_DRAG_SELECTION;
4564
4565 } else if (ma->tree->search.search == false &&
4566 !(ma->tree->flags & TREEVIEW_NO_MOVES) &&
4568 (ma->tree->drag.selected == true ||
4570 ma->tree->drag.type = TV_DRAG_MOVE;
4573 redraw |= treeview_propagate_selection(ma->tree, &r);
4574
4575 } else if (ma->mouse & BROWSER_MOUSE_DRAG_2) {
4576 ma->tree->drag.type = TV_DRAG_SELECTION;
4579 }
4580
4581 if (ma->tree->drag.start_node != NULL &&
4582 ma->tree->drag.type == TV_DRAG_SELECTION) {
4584 }
4585 }
4586
4587 /* Handle active drags */
4588 switch (ma->tree->drag.type) {
4589 case TV_DRAG_SELECTION:
4590 {
4591 int curr_y1 = ma->current_y + height;
4592 int prev_y1 = ma->tree->drag.prev.node_y +
4593 ma->tree->drag.prev.node_h;
4594
4595 r.y0 = (ma->current_y < ma->tree->drag.prev.node_y) ?
4596 ma->current_y : ma->tree->drag.prev.node_y;
4597 r.y1 = (curr_y1 > prev_y1) ? curr_y1 : prev_y1;
4598
4599 redraw = true;
4600
4601 ma->tree->drag.prev.x = ma->x;
4602 ma->tree->drag.prev.y = ma->y;
4603 ma->tree->drag.prev.node_y = ma->current_y;
4604 ma->tree->drag.prev.node_h = height;
4605 }
4606 break;
4607
4608 case TV_DRAG_MOVE:
4609 redraw |= treeview_set_move_indicator(ma->tree, redraw,
4610 node, height,
4611 ma->current_y, ma->y, &r);
4612 break;
4613
4614 default:
4615 break;
4616 }
4617
4619
4620 if (((node->type == TREE_NODE_FOLDER) &&
4621 (ma->mouse & BROWSER_MOUSE_DOUBLE_CLICK) && click) ||
4622 (part == TV_NODE_PART_TOGGLE && click)) {
4623 int h = treeview__get_display_height(ma->tree) +
4624 ma->search_height;
4625
4626 /* Clear any existing selection */
4627 redraw |= treeview_clear_selection(ma->tree, &r);
4628
4629 /* Toggle node expansion */
4630 if (node->flags & TV_NFLAGS_EXPANDED) {
4631 err = treeview_node_contract_internal(ma->tree, node);
4632 } else {
4633 err = treeview_node_expand_internal(ma->tree, node);
4634 }
4635 if (err != NSERROR_OK) {
4636 return err;
4637 }
4638
4639 /* Set up redraw */
4640 if (!redraw || r.y0 > ma->current_y)
4641 r.y0 = ma->current_y;
4642 if (h > treeview__get_display_height(ma->tree) +
4643 ma->search_height) {
4644 r.y1 = h;
4645 } else {
4647 ma->search_height;
4648 }
4649 redraw = true;
4650
4651 } else if ((node->type == TREE_NODE_ENTRY) &&
4652 (ma->mouse & BROWSER_MOUSE_DOUBLE_CLICK) && click) {
4653 struct treeview_node_msg msg;
4655 msg.data.node_launch.mouse = ma->mouse;
4656
4657 /* Clear any existing selection */
4658 redraw |= treeview_clear_selection(ma->tree, &r);
4659
4660 /* Tell client an entry was launched */
4661 ma->tree->callbacks->entry(msg, node->client_data);
4662
4663 } else if (ma->mouse & BROWSER_MOUSE_PRESS_2 ||
4665 ma->mouse & BROWSER_MOUSE_MOD_2)) {
4666 /* Toggle selection of node */
4667 action |= TV_NODE_ACTION_SELECTION;
4668
4669 } else if (ma->mouse & BROWSER_MOUSE_CLICK_1 &&
4670 ma->mouse &
4672 part != TV_NODE_PART_TOGGLE) {
4673
4674 /* Clear any existing selection */
4675 redraw |= treeview_clear_selection(ma->tree, &r);
4676
4677 /* Edit node */
4678 redraw |= treeview_edit_node_at_point(ma->tree, node,
4679 ma->current_y, ma->x,
4680 ma->y, &r);
4681
4682 } else if (ma->mouse & BROWSER_MOUSE_PRESS_1 &&
4683 !(ma->mouse &
4685 !(node->flags & TV_NFLAGS_SELECTED) &&
4686 part != TV_NODE_PART_TOGGLE) {
4687 /* Clear any existing selection */
4688 redraw |= treeview_clear_selection(ma->tree, &r);
4689
4690 /* Select node */
4691 action |= TV_NODE_ACTION_SELECTION;
4692
4693 }
4694
4695 if (action & TV_NODE_ACTION_SELECTION) {
4696 /* Handle change in selection */
4697 node->flags ^= TV_NFLAGS_SELECTED;
4698
4699 /* Redraw */
4700 if (!redraw) {
4701 r.y0 = ma->current_y;
4702 r.y1 = ma->current_y + height;
4703 redraw = true;
4704 } else {
4705 if (r.y0 > ma->current_y) {
4706 r.y0 = ma->current_y;
4707 }
4708 if (r.y1 < ma->current_y + height) {
4709 r.y1 = ma->current_y + height;
4710 }
4711 }
4712 }
4713
4714 if (redraw) {
4716 }
4717
4718 *end = true; /* Reached line with click; stop walking tree */
4719 return NSERROR_OK;
4720}
4721
4722
4723/* Exported interface, documented in treeview.h */
4724void
4726{
4727 struct rect r;
4728 bool redraw = false;
4729 int search_height = treeview__get_search_height(tree);
4730
4731 assert(tree != NULL);
4732 assert(tree->root != NULL);
4733
4734 /* Not interested in whether mouse leaves window. */
4735 if (mouse == BROWSER_MOUSE_LEAVE) {
4736 return;
4737 }
4738
4739 /* Handle mouse drag captured by textarea */
4740 if (tree->drag.type == TV_DRAG_TEXTAREA) {
4741 textarea_mouse_action(tree->edit.textarea, mouse,
4742 x - tree->edit.x, y - tree->edit.y);
4743 return;
4744 } else if (tree->drag.type == TV_DRAG_SEARCH) {
4745 if (tree->search.active == false) {
4746 tree->search.active = true;
4747 if (treeview_clear_selection(tree, &r)) {
4749 }
4750 }
4753 y);
4754 return;
4755 } else if (mouse & (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_PRESS_2) &&
4756 y < search_height && tree->search.active == false) {
4757 tree->search.active = true;
4758 if (treeview_clear_selection(tree, &r)) {
4760 }
4763 y);
4764 return;
4765 } else if (mouse & (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_PRESS_2) &&
4766 tree->search.active == true) {
4767
4768 tree->search.active = false;
4770 r.x0 = 0;
4771 r.y0 = 0;
4772 r.x1 = REDRAW_MAX;
4773 r.y1 = tree_g.line_height;
4775 }
4776
4777 /* Handle textarea related mouse action */
4778 if (tree->edit.textarea != NULL) {
4779 int ta_x = x - tree->edit.x;
4780 int ta_y = y - tree->edit.y;
4781
4782 if (ta_x > 0 && ta_x < tree->edit.w &&
4783 ta_y > 0 && ta_y < tree->edit.h) {
4784 /* Inside textarea */
4785 textarea_mouse_action(tree->edit.textarea, mouse,
4786 ta_x, ta_y);
4787 return;
4788
4789 } else if (mouse != BROWSER_MOUSE_HOVER) {
4790 /* Action outside textarea */
4791 treeview_edit_cancel(tree, true);
4792 }
4793 }
4794
4795 /* Handle drag ends */
4796 if (mouse == BROWSER_MOUSE_HOVER) {
4797 switch (tree->drag.type) {
4798 case TV_DRAG_SELECTION:
4800 tree->drag.type = TV_DRAG_NONE;
4801 tree->drag.start_node = NULL;
4802
4804 return;
4805 case TV_DRAG_MOVE:
4806 treeview_move_selection(tree, &r);
4807 tree->drag.type = TV_DRAG_NONE;
4808 tree->drag.start_node = NULL;
4809
4810 tree->move.target = NULL;
4812
4815 return;
4816 default:
4817 /* No drag to end */
4818 break;
4819 }
4820 }
4821
4822 if (y > treeview__get_display_height(tree) + search_height) {
4823 /* Below tree */
4824
4825 r.x0 = 0;
4826 r.x1 = REDRAW_MAX;
4827
4828 /* Record what position / part a drag started on */
4830 tree->drag.type == TV_DRAG_NONE) {
4831 tree->drag.selected = false;
4832 tree->drag.start_node = NULL;
4833 tree->drag.part = TV_NODE_PART_NONE;
4834 tree->drag.start.x = x;
4835 tree->drag.start.y = y;
4836 tree->drag.start.node_y = tree->root->height;
4837 tree->drag.start.node_h = 0;
4838
4839 tree->drag.prev.x = x;
4840 tree->drag.prev.y = y;
4841 tree->drag.prev.node_y = tree->root->height;
4842 tree->drag.prev.node_h = 0;
4843 }
4844
4845 /* Handle drag start */
4846 if (tree->drag.type == TV_DRAG_NONE) {
4847 if (mouse & BROWSER_MOUSE_DRAG_1 &&
4848 tree->drag.selected == false &&
4849 tree->drag.part == TV_NODE_PART_NONE) {
4850 tree->drag.type = TV_DRAG_SELECTION;
4853 } else if (mouse & BROWSER_MOUSE_DRAG_2) {
4854 tree->drag.type = TV_DRAG_SELECTION;
4857 }
4858
4859 if (tree->drag.start_node != NULL &&
4860 tree->drag.type == TV_DRAG_SELECTION) {
4861 tree->drag.start_node->flags ^=
4863 }
4864 }
4865
4866 /* Handle selection drags */
4867 if (tree->drag.type == TV_DRAG_SELECTION) {
4868 int curr_y1 = tree->root->height;
4869 int prev_y1 = tree->drag.prev.node_y +
4870 tree->drag.prev.node_h;
4871
4872 r.y0 = tree->drag.prev.node_y;
4873 r.y1 = (curr_y1 > prev_y1) ? curr_y1 : prev_y1;
4874
4875 redraw = true;
4876
4877 tree->drag.prev.x = x;
4878 tree->drag.prev.y = y;
4879 tree->drag.prev.node_y = curr_y1;
4880 tree->drag.prev.node_h = 0;
4881 }
4882
4883 if (mouse & BROWSER_MOUSE_PRESS_1) {
4884 /* Clear any existing selection */
4885 redraw |= treeview_clear_selection(tree, &r);
4886 }
4887
4888 if (redraw) {
4890 }
4891
4892 } else {
4893 /* On tree */
4894 struct treeview_mouse_action ma = {
4895 .tree = tree,
4896 .mouse = mouse,
4897 .x = x,
4898 .y = y,
4899 .current_y = search_height,
4900 .search_height = search_height,
4901 };
4902
4906 }
4907}
4908
4909/* Exported interface, documented in treeview.h */
4911{
4914
4915 assert(tree != NULL);
4916 assert(tree->root != NULL);
4917
4919
4920 return height + search_height;
4921}
4922
4923/* Exported interface, documented in treeview.h */
4925 treeview *tree,
4926 const char *string)
4927{
4928 if (!(tree->flags & TREEVIEW_SEARCHABLE)) {
4929 return NSERROR_BAD_PARAMETER;
4930 }
4931
4932 if (string == NULL || strlen(string) == 0) {
4933 tree->search.active = false;
4934 tree->search.search = false;
4935 return treeview__search(tree, "", 0);
4936 }
4937
4938 tree->search.active = true;
4939 tree->search.search = true;
4940 if (!textarea_set_text(tree->search.textarea, string)) {
4941 return NSERROR_UNKNOWN;
4942 }
4943
4945
4946 return NSERROR_OK;
4947}
4948
4949/**
4950 * Initialise the plot styles from CSS system colour values.
4951 *
4952 * \param font_pt_size font size to use
4953 * \return NSERROR_OK on success else appropriate error code
4954 */
4955static nserror treeview_init_plot_styles(int font_pt_size)
4956{
4957 /* Background colour */
4963
4964 /* Text colour */
4966 plot_style_even.text.size = font_pt_size;
4971
4972 /* Entry field text colour */
4975
4976 /* Selected background colour */
4979
4980 /* Selected text colour */
4984
4985 /* Selected entry field text colour */
4988
4989 /* Odd numbered node styles */
4996
5000
5001 return NSERROR_OK;
5002}
5003
5004
5005/**
5006 * Callback for hlcache retrieving resources.
5007 *
5008 * \param handle content hlcache handle
5009 * \param event The event that occurred on the content
5010 * \param pw treeview resource context
5011 */
5012static nserror
5014 const hlcache_event *event,
5015 void *pw)
5016{
5017 struct treeview_resource *r = pw;
5018
5019 switch (event->type) {
5020 case CONTENT_MSG_READY:
5021 case CONTENT_MSG_DONE:
5022 r->ready = true;
5023 r->height = content_get_height(handle);
5024 break;
5025
5026 default:
5027 break;
5028 }
5029
5030 return NSERROR_OK;
5031}
5032
5033
5034/**
5035 * Fetch content resources used by treeview.
5036 */
5038{
5039 int i;
5040
5041 for (i = 0; i < TREE_RES_LAST; i++) {
5042 nsurl *url;
5043 treeview_res[i].ready = false;
5044 treeview_res[i].height = 0;
5046 hlcache_handle_retrieve(url, 0, NULL, NULL,
5048 &(treeview_res[i]), NULL,
5050 &(treeview_res[i].c));
5052 }
5053 }
5054}
5055
5056
5057/**
5058 * Create a right-pointing anti-aliased triangle bitmap
5059 *
5060 * \param bg background colour
5061 * \param fg foreground colour
5062 * \param size required bitmap size
5063 */
5064static struct bitmap *
5066{
5067 struct bitmap *b = NULL;
5068 int x, y;
5069 unsigned char *rpos;
5070 unsigned char *pos;
5071 size_t stride;
5072
5073 /* Set up required colour graduations. Ignores screen gamma. */
5074 colour colour0 = bg;
5075 colour colour1 = mix_colour(bg, fg, 255 * 3 / 4);
5076 colour colour2 = blend_colour(bg, fg);
5077 colour colour3 = mix_colour(bg, fg, 255 * 1 / 4);
5078 colour colour4 = fg;
5079
5080 /* Create the bitmap */
5082 if (b == NULL)
5083 return NULL;
5084
5085 rpos = guit->bitmap->get_buffer(b);
5086 stride = guit->bitmap->get_rowstride(b);
5087
5088 /* Draw the triangle */
5089 for (y = 0; y < size; y++) {
5090 pos = rpos;
5091
5092 if (y < size / 2) {
5093 /* Top half */
5094 for (x = 0; x < y * 2; x++) {
5095 pos[bitmap_layout.r] = red_from_colour(colour4);
5096 pos[bitmap_layout.g] = green_from_colour(colour4);
5097 pos[bitmap_layout.b] = blue_from_colour(colour4);
5098 pos[bitmap_layout.a] = 0xff;
5099 pos += 4;
5100 }
5101 pos[bitmap_layout.r] = red_from_colour(colour3);
5102 pos[bitmap_layout.g] = green_from_colour(colour3);
5103 pos[bitmap_layout.b] = blue_from_colour(colour3);
5104 pos[bitmap_layout.a] = 0xff;
5105 pos += 4;
5106 pos[bitmap_layout.r] = red_from_colour(colour1);
5107 pos[bitmap_layout.g] = green_from_colour(colour1);
5108 pos[bitmap_layout.b] = blue_from_colour(colour1);
5109 pos[bitmap_layout.a] = 0xff;
5110 pos += 4;
5111 for (x = y * 2 + 2; x < size ; x++) {
5112 pos[bitmap_layout.r] = red_from_colour(colour0);
5113 pos[bitmap_layout.g] = green_from_colour(colour0);
5114 pos[bitmap_layout.b] = blue_from_colour(colour0);
5115 pos[bitmap_layout.a] = 0xff;
5116 pos += 4;
5117 }
5118 } else if ((y == size / 2) && (size & 0x1)) {
5119 /* Middle row */
5120 for (x = 0; x < size - 1; x++) {
5121 pos[bitmap_layout.r] = red_from_colour(colour4);
5122 pos[bitmap_layout.g] = green_from_colour(colour4);
5123 pos[bitmap_layout.b] = blue_from_colour(colour4);
5124 pos[bitmap_layout.a] = 0xff;
5125 pos += 4;
5126 }
5127 pos[bitmap_layout.r] = red_from_colour(colour2);
5128 pos[bitmap_layout.g] = green_from_colour(colour2);
5129 pos[bitmap_layout.b] = blue_from_colour(colour2);
5130 pos[bitmap_layout.a] = 0xff;
5131 pos += 4;
5132 } else {
5133 /* Bottom half */
5134 for (x = 0; x < (size - y - 1) * 2; x++) {
5135 pos[bitmap_layout.r] = red_from_colour(colour4);
5136 pos[bitmap_layout.g] = green_from_colour(colour4);
5137 pos[bitmap_layout.b] = blue_from_colour(colour4);
5138 pos[bitmap_layout.a] = 0xff;
5139 pos += 4;
5140 }
5141 pos[bitmap_layout.r] = red_from_colour(colour3);
5142 pos[bitmap_layout.g] = green_from_colour(colour3);
5143 pos[bitmap_layout.b] = blue_from_colour(colour3);
5144 pos[bitmap_layout.a] = 0xff;
5145 pos += 4;
5146 pos[bitmap_layout.r] = red_from_colour(colour1);
5147 pos[bitmap_layout.g] = green_from_colour(colour1);
5148 pos[bitmap_layout.b] = blue_from_colour(colour1);
5149 pos[bitmap_layout.a] = 0xff;
5150 pos += 4;
5151 for (x = (size - y) * 2; x < size ; x++) {
5152 pos[bitmap_layout.r] = red_from_colour(colour0);
5153 pos[bitmap_layout.g] = green_from_colour(colour0);
5154 pos[bitmap_layout.b] = blue_from_colour(colour0);
5155 pos[bitmap_layout.a] = 0xff;
5156 pos += 4;
5157 }
5158 }
5159
5160 rpos += stride;
5161 }
5162
5163 guit->bitmap->modified(b);
5164
5165 return b;
5166}
5167
5168
5169/**
5170 * Create bitmap copy of another bitmap
5171 *
5172 * \param orig bitmap to copy
5173 * \param size required bitmap size
5174 */
5175static struct bitmap *
5177{
5178 struct bitmap *b = NULL;
5179 unsigned char *data;
5180 unsigned char *orig_data;
5181 size_t stride;
5182
5183 if (orig == NULL)
5184 return NULL;
5185
5186 assert(size == guit->bitmap->get_width(orig));
5187 assert(size == guit->bitmap->get_height(orig));
5188
5189 /* Create the bitmap */
5191 if (b == NULL)
5192 return NULL;
5193
5194 stride = guit->bitmap->get_rowstride(b);
5195 assert(stride == guit->bitmap->get_rowstride(orig));
5196
5197 data = guit->bitmap->get_buffer(b);
5198 orig_data = guit->bitmap->get_buffer(orig);
5199
5200 /* Copy the bitmap */
5201 memcpy(data, orig_data, stride * size);
5202
5203 guit->bitmap->modified(b);
5204
5205 /* We've not modified the original image, but we called
5206 * bitmap_get_buffer(), so we need to pair that with a
5207 * bitmap_modified() call to appease certain front ends. */
5208 guit->bitmap->modified(orig);
5209
5210 return b;
5211}
5212
5213
5214/**
5215 * Create bitmap from rotation of another bitmap
5216 *
5217 * \param orig bitmap to create rotation of
5218 * \param size required bitmap size
5219 */
5220static struct bitmap *
5222{
5223 struct bitmap *b = NULL;
5224 int x, y;
5225 unsigned char *rpos;
5226 unsigned char *pos;
5227 unsigned char *orig_data;
5228 unsigned char *orig_pos;
5229 size_t stride;
5230
5231 if (orig == NULL)
5232 return NULL;
5233
5234 assert(size == guit->bitmap->get_width(orig));
5235 assert(size == guit->bitmap->get_height(orig));
5236
5237 /* Create the bitmap */
5239 if (b == NULL)
5240 return NULL;
5241
5242 stride = guit->bitmap->get_rowstride(b);
5243 assert(stride == guit->bitmap->get_rowstride(orig));
5244
5245 rpos = guit->bitmap->get_buffer(b);
5246 orig_data = guit->bitmap->get_buffer(orig);
5247
5248 /* Copy the rotated bitmap */
5249 for (y = 0; y < size; y++) {
5250 pos = rpos;
5251
5252 for (x = 0; x < size; x++) {
5253 orig_pos = orig_data + x * stride + y * 4;
5254 *(pos++) = *(orig_pos++);
5255 *(pos++) = *(orig_pos++);
5256 *(pos++) = *(orig_pos);
5257 *(pos++) = 0xff;
5258
5259 }
5260
5261 rpos += stride;
5262 }
5263
5264 guit->bitmap->modified(b);
5265
5266 /* We've not modified the original image, but we called
5267 * bitmap_get_buffer(), so we need to pair that with a
5268 * bitmap_modified() call to appease certain front ends.
5269 */
5270 guit->bitmap->modified(orig);
5271
5272 return b;
5273}
5274
5275
5276/**
5277 * Measures width of characters used to represent treeview furniture.
5278 *
5279 * \return NSERROR_OK on success else error code
5280 */
5282{
5283 int size = tree_g.line_height / 2;
5284
5294
5303
5311
5319
5320 if (plot_style_odd.furn[TREE_FURN_EXPAND].bmp == NULL ||
5328 return NSERROR_NOMEM;
5329
5331
5332 return NSERROR_OK;
5333}
5334
5335
5336/* Exported interface, documented in treeview.h */
5338{
5339 long long font_px_size;
5340 long long font_pt_size;
5341 nserror res;
5342
5343 if (tree_g.initialised > 0) {
5345 return NSERROR_OK;
5346 }
5347
5348 NSLOG(netsurf, INFO, "Initialising treeview module");
5349
5350 font_pt_size = nsoption_int(treeview_font_size);
5351 if (font_pt_size <= 0) {
5352 font_pt_size = 11 * 10;
5353 }
5354
5355 font_px_size = (font_pt_size * FIXTOINT(nscss_screen_dpi) /
5356 10 + 36) / 72;
5357 tree_g.line_height = (font_px_size * 8 + 3) / 6;
5358
5359 res = treeview_init_plot_styles(font_pt_size * PLOT_STYLE_SCALE / 10);
5360 if (res != NSERROR_OK) {
5361 return res;
5362 }
5363
5365
5367 if (res != NSERROR_OK) {
5368 return res;
5369 }
5370
5373 tree_g.icon_size = 17;
5374 tree_g.icon_step = 23;
5375 tree_g.move_offset = 18;
5376
5378
5379 NSLOG(netsurf, INFO, "Initialised treeview module");
5380
5381 return NSERROR_OK;
5382}
5383
5384
5385/* Exported interface, documented in treeview.h */
5387{
5388 int i;
5389
5390 if (tree_g.initialised > 1) {
5392 return NSERROR_OK;
5393
5394 } else if (tree_g.initialised == 0) {
5395 NSLOG(netsurf, INFO,
5396 "Warning: tried to finalise uninitialised treeview module");
5397 return NSERROR_OK;
5398 }
5399
5400 NSLOG(netsurf, INFO, "Finalising treeview module");
5401
5402 for (i = 0; i < TREE_RES_LAST; i++) {
5404 }
5405
5414
5416
5417 NSLOG(netsurf, INFO, "Finalised treeview module");
5418
5419 return NSERROR_OK;
5420}
static os_mode mode
The current sprite mode.
Definition: buffer.c:72
static uint32_t count(const http_directive *list, lwc_string *key)
char * strcasestr(const char *haystack, const char *needle)
Case insensitive strstr implementation.
Definition: utils.c:310
@ CONTENT_IMAGE
All images.
Definition: content_type.h:67
@ CONTENT_MSG_DONE
content has finished processing
Definition: content_type.h:119
@ CONTENT_MSG_READY
may be displayed
Definition: content_type.h:116
Interface to core window handling.
core_window_drag_status
drag status passed to drag_status callback
Definition: core_window.h:41
@ CORE_WINDOW_DRAG_NONE
Definition: core_window.h:42
@ CORE_WINDOW_DRAG_MOVE
Definition: core_window.h:45
@ CORE_WINDOW_DRAG_TEXT_SELECTION
Definition: core_window.h:44
@ CORE_WINDOW_DRAG_SELECTION
Definition: core_window.h:43
css_fixed nscss_screen_dpi
Screen DPI in fixed point units: defaults to 90, which RISC OS uses.
Definition: css.c:44
nserror cw_helper_scroll_visible(const struct core_window_callback_table *cw_t, struct core_window *cw_h, const struct rect *r)
Scroll a core window to make the given rectangle visible.
Definition: cw_helper.c:34
Helpers to simplify core use of corewindow.
Internal core bitmap interface.
void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale, const struct rect *clip, const struct redraw_context *ctx)
Handle redraw requests for text areas.
Definition: textarea.c:2131
struct textarea * textarea_create(const textarea_flags flags, const textarea_setup *setup, textarea_client_callback callback, void *data)
Create a text area.
Definition: textarea.c:1852
void textarea_destroy(struct textarea *ta)
Destroy a text area.
Definition: textarea.c:1975
bool textarea_set_caret(struct textarea *ta, int caret)
Set the caret's position.
Definition: textarea.c:2112
bool textarea_set_text(struct textarea *ta, const char *text)
Set the text in a text area, discarding any current text.
Definition: textarea.c:1995
int textarea_get_text(struct textarea *ta, char *buf, unsigned int len)
Extract the text from a text area.
Definition: textarea.c:2078
const char * textarea_data(struct textarea *ta, unsigned int *len)
Access text data in a text area.
Definition: textarea.c:2101
textarea_mouse_status textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: textarea.c:3069
bool textarea_keypress(struct textarea *ta, uint32_t key)
Key press handling for text areas.
Definition: textarea.c:2450
Single/Multi-line UTF-8 text area interface.
void(* textarea_client_callback)(void *data, struct textarea_msg *msg)
Client callback for the textarea.
Definition: textarea.h:156
textarea_flags
Text area flags.
Definition: textarea.h:40
@ TEXTAREA_INTERNAL_CARET
Render own caret.
Definition: textarea.h:44
@ TEXTAREA_DRAG_NONE
Definition: textarea.h:53
@ TEXTAREA_MSG_TEXT_MODIFIED
Textarea text modified.
Definition: textarea.h:67
@ TEXTAREA_MSG_DRAG_REPORT
Textarea drag start/end report.
Definition: textarea.h:63
@ TEXTAREA_MSG_REDRAW_REQUEST
Textarea redraw request.
Definition: textarea.h:65
static nserror treeview_node_mouse_action_cb(treeview_node *node, void *ctx, bool *skip_children, bool *end)
Treewalk node callback for handling mouse action.
Definition: treeview.c:4449
static nserror treeview_node_contract_internal(treeview *tree, treeview_node *node)
Contract a treeview node.
Definition: treeview.c:2383
nserror treeview_cw_detach(treeview *tree)
Detach a treeview from a corewindow.
Definition: treeview.c:2148
static unsigned treeview__get_search_height(const treeview *tree)
Get height used by treeview's search bar (or 0 if not present).
Definition: treeview.c:390
static void treeview_insert_node(treeview *tree, treeview_node *a, treeview_node *b, enum treeview_relationship rel)
Insert a treeview node into a treeview.
Definition: treeview.c:1134
static bool treeview_select_all(treeview *tree, struct rect *rect)
Select all in a treeview.
Definition: treeview.c:3420
static void treeview_init_resources(void)
Fetch content resources used by treeview.
Definition: treeview.c:5037
static void treeview_textarea_search_callback(void *data, struct textarea_msg *msg)
Callback for textarea_create, in desktop/treeview.h.
Definition: treeview.c:991
static nserror treeview_node_selection_walk_cb(treeview_node *n, void *ctx, bool *skip_children, bool *end)
Treewalk node callback for handling selection related actions.
Definition: treeview.c:3163
#define REDRAW_MAX
The maximum horizontal size a treeview can possibly be.
Definition: treeview.c:57
nserror treeview_node_contract(treeview *tree, treeview_node *node)
Contract a treeview node.
Definition: treeview.c:2417
static void treeview__cw_get_window_dimensions(const struct treeview *tree, int *width, int *height)
Corewindow callback wrapper: Get window viewport dimensions.
Definition: treeview.c:442
static nserror treeview_delete_node_internal(treeview *tree, treeview_node *n, bool interaction, treeview_node_options_flags flags)
Delete a treeview node.
Definition: treeview.c:1766
static nserror treeview_walk_fwd_cb(treeview_node *n, void *ctx, bool *skip_children, bool *end)
Treewalk node enter callback.
Definition: treeview.c:1499
void treeview_mouse_action(treeview *tree, browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: treeview.c:4725
static nserror treeview_launch_selection(treeview *tree)
Launch a selection.
Definition: treeview.c:3759
static bool treeview_set_move_indicator(treeview *tree, bool need_redraw, treeview_node *target, int node_height, int node_y, int mouse_y, struct rect *rect)
Set the drag&drop drop indicator.
Definition: treeview.c:4105
static void treeview__cw_update_size(const struct treeview *tree, int width, int height)
Corewindow callback wrapper: Update the limits of the window.
Definition: treeview.c:405
static bool treeview_keyboard_navigation(treeview *tree, uint32_t key, struct rect *rect)
Handle keyboard navigation.
Definition: treeview.c:3891
static void treeview_move_yank_selection(treeview *tree, treeview_node *fixed)
Yank a selection to the node move list.
Definition: treeview.c:3474
static struct bitmap * treeview_generate_rotate_bitmap(struct bitmap *orig, int size)
Create bitmap from rotation of another bitmap.
Definition: treeview.c:5221
nserror treeview_contract(treeview *tree, bool all)
Contract a treeview's nodes.
Definition: treeview.c:2436
nserror treeview_cw_attach(treeview *tree, const struct core_window_callback_table *cw_t, struct core_window *cw)
Attach a treeview to a corewindow.
Definition: treeview.c:2129
static bool treeview_unlink_node(treeview_node *n)
Unlink a treeview node.
Definition: treeview.c:1569
nserror treeview_delete_node(treeview *tree, treeview_node *n, treeview_node_options_flags flags)
Delete a treeview node.
Definition: treeview.c:1925
static nserror treeview__search(treeview *tree, const char *text, unsigned int len)
Search treeview for text.
Definition: treeview.c:867
nserror treeview_create(treeview **tree, const struct treeview_callback_table *callbacks, int n_fields, struct treeview_field_desc fields[], const struct core_window_callback_table *cw_t, struct core_window *cw, treeview_flags flags)
Create a treeview.
Definition: treeview.c:2023
enum treeview_node_type treeview_get_selection(treeview *tree, void **node_data)
Get the first selected node.
Definition: treeview.c:3365
nserror treeview_fini(void)
Finalise the treeview module (all treeviews must have been destroyed first)
Definition: treeview.c:5386
static nserror treeview_expand_cb(treeview_node *n, void *ctx, bool *skip_children, bool *end)
Treewalk node callback for handling recursive node expansion.
Definition: treeview.c:2503
treeview_walk_mode
The treeview walk mode.
Definition: treeview.c:640
@ TREEVIEW_WALK_MODE_LOGICAL_EXPANDED
Walk to expanded nodes in the (sub)tree only.
Definition: treeview.c:650
@ TREEVIEW_WALK_MODE_DISPLAY
Walk displayed nodes.
Definition: treeview.c:657
@ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE
Walk to all nodes in the (sub)tree.
Definition: treeview.c:644
static void treeview__redraw_from_node(const treeview *tree, const treeview_node *node)
Redraw tree from given node to the bottom.
Definition: treeview.c:619
static nserror treeview_init_plot_styles(int font_pt_size)
Initialise the plot styles from CSS system colour values.
Definition: treeview.c:4955
void treeview_edit_selection(treeview *tree)
Edit the first selected node.
Definition: treeview.c:4391
struct treeview_globals tree_g
static void treeview__search_update_display(treeview *tree)
Update the layout for any active search.
Definition: treeview.c:1043
bool treeview_has_selection(treeview *tree)
Determine whether treeview has a selection.
Definition: treeview.c:3328
static nserror treeview_node_launch_walk_fwd_cb(treeview_node *n, void *ctx, bool *skip_children, bool *end)
Treewalk node walk forward callback for launching nodes.
Definition: treeview.c:3726
static treeview_node * treeview_get_first_selected(treeview *tree)
Get first selected node (in any)
Definition: treeview.c:3349
treeview_target_pos
Treeview target position.
Definition: treeview.c:122
@ TV_TARGET_BELOW
Definition: treeview.c:125
@ TV_TARGET_NONE
Definition: treeview.c:126
@ TV_TARGET_INSIDE
Definition: treeview.c:124
@ TV_TARGET_ABOVE
Definition: treeview.c:123
static int treeview__get_display_height(const treeview *tree)
Get the display height of the treeview data component of the display.
Definition: treeview.c:340
bool treeview_keypress(treeview *tree, uint32_t key)
Key press handling for treeviews.
Definition: treeview.c:4008
static struct textarea * treeview__create_textarea(treeview *tree, int width, int height, colour border, colour background, colour foreground, plot_font_style_t text, textarea_client_callback ta_callback)
Helper to create a textarea.
Definition: treeview.c:1987
static struct treeview_resource treeview_res[TREE_RES_LAST]
Treeview content resources.
Definition: treeview.c:325
nserror treeview_update_node_entry(treeview *tree, treeview_node *entry, const struct treeview_field_data fields[], void *data)
Update an entry node in given treeview.
Definition: treeview.c:1315
static bool treeview_clear_selection(treeview *tree, struct rect *rect)
Clear any selection in a treeview.
Definition: treeview.c:3391
static int treeview_node_y(const treeview *tree, const treeview_node *node)
Find y position of the top of a node.
Definition: treeview.c:566
nserror treeview_get_relation(treeview *tree, treeview_node **relation, enum treeview_relationship *rel, bool at_y, int y)
Find a relation for node creation.
Definition: treeview.c:3778
nserror treeview_create_node_folder(treeview *tree, treeview_node **folder, treeview_node *relation, enum treeview_relationship rel, const struct treeview_field_data *field, void *data, treeview_node_options_flags flags)
Create a folder node in given treeview.
Definition: treeview.c:1199
nserror treeview_destroy(treeview *tree)
Destroy a treeview object.
Definition: treeview.c:2160
static void treeview_redraw_search(treeview *tree, const int x, const int y, int *render_y_in_out, const struct rect *r, struct content_redraw_data *data, const struct redraw_context *ctx)
Draw a treeview normally, in tree mode.
Definition: treeview.c:2786
static void treeview_copy_selection(treeview *tree)
Copy a selection to the clipboard.
Definition: treeview.c:3494
static nserror treeview_node_nav_cb(treeview_node *node, void *ctx, bool *skip_children, bool *end)
Treewalk node callback for handling mouse action.
Definition: treeview.c:3848
static void treeview__cw_scroll_to_node(const struct treeview *tree, const struct treeview_node *node)
Corewindow callback_wrapper: Scroll to make node visible.
Definition: treeview.c:595
static nserror treeview_walk_internal(treeview *tree, treeview_node *root, enum treeview_walk_mode mode, nserror(*callback_bwd)(treeview_node *n, void *ctx, bool *end), nserror(*callback_fwd)(treeview_node *n, void *ctx, bool *skip_children, bool *end), void *ctx)
Walk a treeview subtree, calling a callback at each node (depth first)
Definition: treeview.c:674
static nserror treeview__search_walk_cb(treeview_node *n, void *ctx, bool *skip_children, bool *end)
Treewalk node callback for handling search.
Definition: treeview.c:813
nserror treeview_walk(treeview *tree, treeview_node *root, treeview_walk_cb enter_cb, treeview_walk_cb leave_cb, void *ctx, enum treeview_node_type type)
Walk (depth first) a treeview subtree, calling a callback at each node of required type.
Definition: treeview.c:1535
static bool treeview_edit_node_at_point(treeview *tree, treeview_node *n, int node_y, int mouse_x, int mouse_y, struct rect *rect)
Start edit of node field, at given y-coord, if editable.
Definition: treeview.c:4283
static void treeview__cw_invalidate_area(const struct treeview *tree, const struct rect *r)
Corewindow callback wrapper: Request a redraw of the window.
Definition: treeview.c:354
int treeview_get_height(treeview *tree)
Find current height of a treeview.
Definition: treeview.c:4910
static void treeview__search_cancel(treeview *tree, bool drop_focus)
Cancel a treeview search, optionally droping focus from search widget.
Definition: treeview.c:925
struct treeview_node_style plot_style_even
Plot style for even rows.
Definition: treeview.c:295
void treeview_redraw(treeview *tree, const int x, const int y, struct rect *clip, const struct redraw_context *ctx)
Redraw a treeview object.
Definition: treeview.c:2999
treeview_resource_id
treeview resource indexes
Definition: treeview.c:312
@ TREE_RES_FOLDER_SPECIAL
Definition: treeview.c:316
@ TREE_RES_SEARCH
Definition: treeview.c:317
@ TREE_RES_ARROW
Definition: treeview.c:313
@ TREE_RES_CONTENT
Definition: treeview.c:314
@ TREE_RES_FOLDER
Definition: treeview.c:315
@ TREE_RES_LAST
Definition: treeview.c:318
static void treeview__cw_drag_status(const struct treeview *tree, core_window_drag_status ds)
Corewindow callback wrapper: Inform corewindow owner of drag status.
Definition: treeview.c:458
treeview_node_flags
flags indicating render state of node.
Definition: treeview.c:110
@ TV_NFLAGS_SELECTED
Whether node is selected.
Definition: treeview.c:113
@ TV_NFLAGS_NONE
No node flags set.
Definition: treeview.c:111
@ TV_NFLAGS_SPECIAL
Render as special node.
Definition: treeview.c:114
@ TV_NFLAGS_MATCHED
Whether node matches search.
Definition: treeview.c:115
@ TV_NFLAGS_EXPANDED
Whether node is expanded.
Definition: treeview.c:112
static void treeview_edit_cancel(treeview *tree, bool redraw)
Cancel the editing of a treeview node.
Definition: treeview.c:1602
static void treeview_redraw_tree(treeview *tree, const int x, const int y, int *render_y_in_out, const struct rect *r, struct content_redraw_data *data, const struct redraw_context *ctx)
Draw a treeview normally, in tree mode.
Definition: treeview.c:2567
nserror treeview_node_expand(treeview *tree, treeview_node *node)
Expand a treeview node.
Definition: treeview.c:2293
static nserror treeview_move_selection(treeview *tree, struct rect *rect)
Move a selection according to the current move drag.
Definition: treeview.c:3592
static nserror treeview_node_launch_walk_bwd_cb(treeview_node *n, void *ctx, bool *end)
Treewalk node walk backward callback for tracking folder selection.
Definition: treeview.c:3704
static struct bitmap * treeview_generate_copy_bitmap(struct bitmap *orig, int size)
Create bitmap copy of another bitmap.
Definition: treeview.c:5176
static nserror treeview_node_expand_internal(treeview *tree, treeview_node *node)
Expand a treeview's nodes.
Definition: treeview.c:2198
nserror treeview_init(void)
Prepare treeview module for treeview usage.
Definition: treeview.c:5337
static struct treeview_text * treeview_get_text_for_field(treeview *tree, treeview_node *n, int i)
Helper function to access the given field of a node.
Definition: treeview.c:477
static nserror treeview_delete_empty_nodes(treeview *tree, bool interaction)
Delete any empty treeview folder nodes.
Definition: treeview.c:1831
static treeview_node * treeview_y_node(treeview *tree, int target_y)
Find node at given y-position.
Definition: treeview.c:535
nserror treeview_create_node_entry(treeview *tree, treeview_node **entry, treeview_node *relation, enum treeview_relationship rel, const struct treeview_field_data fields[], void *data, treeview_node_options_flags flags)
Create an entry node in given treeview.
Definition: treeview.c:1389
static core_window_drag_status treeview__get_cw_drag_type(const treeview *tree)
Convert from treeview drag to core window drag type.
Definition: treeview.c:962
static void treeview_edit_done(treeview *tree)
Complete a treeview edit.
Definition: treeview.c:1634
nserror treeview_expand(treeview *tree, bool only_folders)
Expand a treeview's nodes.
Definition: treeview.c:2527
static nserror treeview_res_cb(struct hlcache_handle *handle, const hlcache_event *event, void *pw)
Callback for hlcache retrieving resources.
Definition: treeview.c:5013
static nserror treeview_create_node_root(treeview_node **root)
Create treeview's root node.
Definition: treeview.c:1069
static void treeview__cw_full_redraw(const struct treeview *tree)
Corewindow callback wrapper: Request a full redraw of the window.
Definition: treeview.c:369
nserror treeview_set_search_string(treeview *tree, const char *string)
Set the search string for a treeview with TREEVIEW_SEARCHABLE.
Definition: treeview.c:4924
treeview_node_part
Section type of a treeview at a point.
Definition: treeview.c:78
@ TV_NODE_PART_TOGGLE
Expansion toggle.
Definition: treeview.c:79
@ TV_NODE_PART_NONE
Empty area.
Definition: treeview.c:81
@ TV_NODE_PART_ON_NODE
Node content (text, icon)
Definition: treeview.c:80
static nserror treeview_init_furniture(void)
Measures width of characters used to represent treeview furniture.
Definition: treeview.c:5281
treeview_furniture_id
Treeview furniture states.
Definition: treeview.c:259
@ TREE_FURN_CONTRACT
Definition: treeview.c:261
@ TREE_FURN_EXPAND
Definition: treeview.c:260
@ TREE_FURN_LAST
Definition: treeview.c:262
static bool treeview_delete_selection(treeview *tree, struct rect *rect)
Delete a selection.
Definition: treeview.c:3526
static void treeview_textarea_callback(void *data, struct textarea_msg *msg)
Callback for textarea_create, in desktop/treeview.h.
Definition: treeview.c:4236
static void treeview_commit_selection_drag(treeview *tree)
Commit a current selection drag, modifying the node's selection state.
Definition: treeview.c:3447
struct treeview_node_style plot_style_odd
Plot style for odd rows.
Definition: treeview.c:289
static bool treeview_propagate_selection(treeview *tree, struct rect *rect)
Propagate selection to visible descendants of selected nodes.
Definition: treeview.c:3559
static nserror treeview_walk_bwd_cb(treeview_node *n, void *ctx, bool *end)
Treewalk node leave callback.
Definition: treeview.c:1521
static nserror treeview_delete_node_walk_cb(treeview_node *n, void *ctx, bool *end)
Treewalk node callback deleting nodes.
Definition: treeview.c:1704
static void treeview__cw_scroll_top(const struct treeview *tree)
Corewindow callback_wrapper: Scroll to top of window.
Definition: treeview.c:421
static nserror treeview_node_contract_cb(treeview_node *n, void *ctx, bool *end)
Treewalk node callback for handling node contraction.
Definition: treeview.c:2326
nserror treeview_update_node_folder(treeview *tree, treeview_node *folder, const struct treeview_field_data *field, void *data)
Update an folder node in given treeview.
Definition: treeview.c:1267
static struct bitmap * treeview_generate_triangle_bitmap(colour bg, colour fg, int size)
Create a right-pointing anti-aliased triangle bitmap.
Definition: treeview.c:5065
static treeview_node * treeview_node_next(treeview_node *node, bool full)
Find the next node in depth first tree order.
Definition: treeview.c:499
static nserror treeview_set_inset_from_parent(treeview_node *n, void *ctx, bool *skip_children, bool *end)
Set a node's inset from its parent.
Definition: treeview.c:1112
Treeview handling interface.
nserror(* treeview_walk_cb)(void *ctx, void *node_data, enum treeview_node_type type, bool *abort)
Client callback for treeview_walk.
Definition: treeview.h:346
@ TREE_MSG_NODE_EDIT
Node to be edited.
Definition: treeview.h:88
@ TREE_MSG_NODE_LAUNCH
Node to be launched.
Definition: treeview.h:89
@ TREE_MSG_NODE_DELETE
Node to be deleted.
Definition: treeview.h:87
treeview_node_type
treeview node type
Definition: treeview.h:44
@ TREE_NODE_ENTRY
Node is an entry.
Definition: treeview.h:48
@ TREE_NODE_NONE
No node
Definition: treeview.h:45
@ TREE_NODE_FOLDER
Node is folder.
Definition: treeview.h:47
@ TREE_NODE_ROOT
Node is treeview's root.
Definition: treeview.h:46
treeview_node_options_flags
Node change handling options.
Definition: treeview.h:64
@ TREE_OPTION_NONE
Definition: treeview.h:65
@ TREE_OPTION_SUPPRESS_RESIZE
Definition: treeview.h:67
@ TREE_OPTION_SPECIAL_DIR
Definition: treeview.h:66
@ TREE_OPTION_SUPPRESS_REDRAW
Definition: treeview.h:68
treeview_field_flags
treeview field flags
Definition: treeview.h:116
@ TREE_FLAG_SEARCHABLE
Whether field is searchable.
Definition: treeview.h:122
@ TREE_FLAG_SHOW_NAME
Whether field name shown.
Definition: treeview.h:120
@ TREE_FLAG_COPY_TEXT
Whether to copy to clipb.
Definition: treeview.h:121
@ TREE_FLAG_ALLOW_EDIT
Whether allow edit field.
Definition: treeview.h:118
@ TREE_FLAG_DEFAULT
Whether field is default.
Definition: treeview.h:119
treeview_relationship
Relationship between nodes.
Definition: treeview.h:55
@ TREE_REL_FIRST_CHILD
Definition: treeview.h:56
@ TREE_REL_NEXT_SIBLING
Definition: treeview.h:57
treeview_flags
treeview control flags
Definition: treeview.h:74
@ TREEVIEW_NO_DELETES
No node deletes.
Definition: treeview.h:77
@ TREEVIEW_DEL_EMPTY_DIRS
Delete dirs on empty.
Definition: treeview.h:79
@ TREEVIEW_SEARCHABLE
Treeview has search bar.
Definition: treeview.h:80
@ TREEVIEW_NO_MOVES
No node drags.
Definition: treeview.h:76
wimp_w parent
Definition: dialog.c:88
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_BAD_PARAMETER
Bad Parameter.
Definition: errors.h:48
@ NSERROR_UNKNOWN
Unknown error - DO NOT USE.
Definition: errors.h:31
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
static struct directory * root
Definition: filename.c:55
const char * type
Definition: filetype.cpp:44
static struct core_window_callback_table cw_t
Declare Core Window Callbacks:
Definition: treeview.c:534
struct netsurf_table * guit
The global interface table.
Definition: gui_factory.c:49
Interface to core interface table.
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
Definition: hlcache.c:740
nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags, nsurl *referer, llcache_post_data *post, hlcache_handle_callback cb, void *pw, hlcache_child_context *child, content_type accepted_types, hlcache_handle **result)
Retrieve a high-level cache handle for an object.
Definition: hlcache.c:679
High-level resource cache interface.
Generic bitmap handling interface.
@ BITMAP_OPAQUE
image is opaque
Definition: bitmap.h:38
bitmap_layout
NetSurf bitmap pixel layout.
Definition: bitmap.h:48
Interface to platform-specific clipboard operations.
Public content interface.
bool content_redraw(struct hlcache_handle *h, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Display content on screen with optional tiling.
Definition: content.c:558
int content_get_height(struct hlcache_handle *h)
Retrieve height of content.
Definition: content.c:1175
Interface to platform-specific layout operation table.
browser_mouse_state
Mouse state.
Definition: mouse.h:43
@ BROWSER_MOUSE_PRESS_1
button 1 pressed
Definition: mouse.h:50
@ BROWSER_MOUSE_CLICK_2
button 2 clicked.
Definition: mouse.h:57
@ BROWSER_MOUSE_PRESS_2
button 2 pressed
Definition: mouse.h:52
@ BROWSER_MOUSE_HOVER
No mouse buttons pressed, May be used to indicate hover or end of drag.
Definition: mouse.h:47
@ BROWSER_MOUSE_CLICK_1
button 1 clicked.
Definition: mouse.h:55
@ BROWSER_MOUSE_MOD_2
2nd modifier key pressed (eg.
Definition: mouse.h:80
@ BROWSER_MOUSE_DOUBLE_CLICK
button double clicked
Definition: mouse.h:60
@ BROWSER_MOUSE_MOD_3
3rd modifier key pressed (eg.
Definition: mouse.h:82
@ BROWSER_MOUSE_MOD_1
1st modifier key pressed (eg.
Definition: mouse.h:78
@ BROWSER_MOUSE_DRAG_1
start of button 1 drag
Definition: mouse.h:65
@ BROWSER_MOUSE_LEAVE
pointer leaving window
Definition: mouse.h:85
@ BROWSER_MOUSE_DRAG_2
start of button 2 drag
Definition: mouse.h:67
Target independent plotting interface.
#define BITMAPF_NONE
Definition: plotters.h:37
Interface to key press operations.
@ NS_KEY_CR
Definition: keypress.h:40
@ NS_KEY_RIGHT
Definition: keypress.h:51
@ NS_KEY_LEFT
Definition: keypress.h:50
@ NS_KEY_SELECT_ALL
Definition: keypress.h:32
@ NS_KEY_COPY_SELECTION
Definition: keypress.h:33
@ NS_KEY_DOWN
Definition: keypress.h:53
@ NS_KEY_DELETE_RIGHT
Definition: keypress.h:55
@ NS_KEY_NL
Definition: keypress.h:38
@ NS_KEY_CLEAR_SELECTION
Definition: keypress.h:45
@ NS_KEY_DELETE_LEFT
Definition: keypress.h:35
@ NS_KEY_UP
Definition: keypress.h:52
@ NS_KEY_ESCAPE
Definition: keypress.h:47
bool knockout_plot_end(const struct redraw_context *ctx)
End a knockout plotting session.
Definition: knockout.c:997
bool knockout_plot_start(const struct redraw_context *ctx, struct redraw_context *knk_ctx)
Start a knockout plotting session.
Definition: knockout.c:971
Knockout rendering (interface).
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
colour nscolours[NSCOLOUR__COUNT]
NetSurf UI colour table.
Definition: nscolour.c:38
NetSurf UI colours (interface).
@ NSCOLOUR_WIN_EVEN_FG
Definition: nscolour.h:44
@ NSCOLOUR_TEXT_INPUT_FG
Definition: nscolour.h:51
@ NSCOLOUR_WIN_ODD_BG
Definition: nscolour.h:34
@ NSCOLOUR_SEL_FG
Definition: nscolour.h:54
@ NSCOLOUR_SEL_BG
Definition: nscolour.h:53
@ NSCOLOUR_TEXT_INPUT_BG
Definition: nscolour.h:50
@ NSCOLOUR_WIN_EVEN_BG
Definition: nscolour.h:42
@ NSCOLOUR_WIN_EVEN_FG_FADED
Definition: nscolour.h:46
@ NSCOLOUR_SEL_FG_SUBTLE
Definition: nscolour.h:55
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
#define blend_colour(c0, c1)
Definition: plot_style.h:163
#define red_from_colour(c)
Definition: plot_style.h:205
@ PLOT_OP_TYPE_NONE
No operation.
Definition: plot_style.h:66
@ PLOT_OP_TYPE_SOLID
Solid colour.
Definition: plot_style.h:67
@ FONTF_NONE
Definition: plot_style.h:102
#define mix_colour(c0, c1, p)
Definition: plot_style.h:198
@ PLOT_FONT_FAMILY_SANS_SERIF
Definition: plot_style.h:89
#define blue_from_colour(c)
Definition: plot_style.h:213
#define green_from_colour(c)
Definition: plot_style.h:209
#define PLOT_STYLE_SCALE
Scaling factor for plot styles.
Definition: plot_style.h:45
int width
Definition: gui.c:159
int height
Definition: gui.c:160
static BList * callbacks
List of all callbacks.
Definition: schedule.cpp:44
Interface to utility string handling.
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
uint32 size
Definition: bitmap.c:73
Container for border values during table border calculations.
Definition: table.c:42
parameters to content redraw
Definition: content.h:40
int height
vertical dimension
Definition: content.h:48
bool repeat_y
whether content is tiled in y direction
Definition: content.h:59
bool repeat_x
whether content is tiled in x direction
Definition: content.h:58
int y
coordinate for top-left of redraw
Definition: content.h:42
int x
coordinate for top-left of redraw
Definition: content.h:41
colour background_colour
The background colour.
Definition: content.h:51
int width
dimensions to render content at (for scaling contents with intrinsic dimensions)
Definition: content.h:47
float scale
Scale for redraw (for scaling contents without intrinsic dimensions)
Definition: content.h:56
Callbacks to achieve various core window functionality.
Definition: core_window.h:51
nserror(* get_window_dimensions)(const struct core_window *cw, int *width, int *height)
Get window viewport dimensions.
Definition: core_window.h:113
nserror(* drag_status)(struct core_window *cw, core_window_drag_status ds)
Inform corewindow owner of drag status.
Definition: core_window.h:123
nserror(* update_size)(struct core_window *cw, int width, int height)
Update the limits of the window.
Definition: core_window.h:79
nserror(* invalidate)(struct core_window *cw, const struct rect *rect)
Invalidate an area of a window.
Definition: core_window.h:69
int(* get_height)(void *bitmap)
Get the bitmap height.
Definition: bitmap.h:193
void(* destroy)(void *bitmap)
Destroy a bitmap.
Definition: bitmap.h:143
void *(* create)(int width, int height, enum gui_bitmap_flags flags)
Create a new bitmap.
Definition: bitmap.h:136
int(* get_width)(void *bitmap)
Get the bitmap width.
Definition: bitmap.h:185
size_t(* get_rowstride)(void *bitmap)
Get the number of bytes per row of the image.
Definition: bitmap.h:177
void(* modified)(void *bitmap)
Marks a bitmap as modified.
Definition: bitmap.h:200
unsigned char *(* get_buffer)(void *bitmap)
Get the image buffer from a bitmap.
Definition: bitmap.h:169
void(* set)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles)
Core tells front end to put given text in clipboard.
Definition: clipboard.h:59
nserror(* width)(const struct plot_font_style *fstyle, const char *string, size_t length, int *width)
Measure the width of a string.
Definition: layout.h:49
High-level cache event.
Definition: hlcache.h:43
content_msg type
Event type.
Definition: hlcache.h:44
High-level cache handle.
Definition: hlcache.c:66
struct gui_clipboard_table * clipboard
Clipboard table.
Definition: gui_table.h:78
struct gui_bitmap_table * bitmap
Bitmap table.
Definition: gui_table.h:144
struct gui_layout_table * layout
Layout table.
Definition: gui_table.h:154
Font style for plotting.
Definition: plot_style.h:111
plot_font_generic_family_t family
Generic family to plot with.
Definition: plot_style.h:118
colour foreground
Colour of text.
Definition: plot_style.h:123
plot_font_flags_t flags
Font flags.
Definition: plot_style.h:121
plot_style_fixed size
Font size, in pt.
Definition: plot_style.h:119
colour background
Background colour to blend to, if appropriate.
Definition: plot_style.h:122
int weight
Font weight: value in range [100,900] as per CSS.
Definition: plot_style.h:120
Plot style for stroke/fill plotters.
Definition: plot_style.h:76
colour fill_colour
Colour of fill.
Definition: plot_style.h:81
plot_style_fixed stroke_width
Width of stroke, in pixels.
Definition: plot_style.h:78
plot_operation_type_t fill_type
Fill plot type.
Definition: plot_style.h:80
colour stroke_colour
Colour of stroke.
Definition: plot_style.h:79
plot_operation_type_t stroke_type
Stroke plot type.
Definition: plot_style.h:77
bool option_knockout
flag to enable knockout rendering.
Definition: plotters.h:328
nserror(* text)(const struct redraw_context *ctx, const plot_font_style_t *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plotters.h:278
nserror(* rectangle)(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *rectangle)
Plots a rectangle.
Definition: plotters.h:188
nserror(* clip)(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plotters.h:111
nserror(* bitmap)(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Plot a bitmap.
Definition: plotters.h:257
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Redraw context.
Definition: plotters.h:51
const struct plotter_table * plot
Current plot operation table.
Definition: plotters.h:73
textarea message
Definition: textarea.h:74
unsigned int len
Byte length of text.
Definition: textarea.h:99
const char * text
UTF8 text.
Definition: textarea.h:98
textarea_msg_type type
Indicates message data type.
Definition: textarea.h:77
struct rect redraw
With _REDRAW_REQUEST.
Definition: textarea.h:84
struct textarea_msg::@79::@82 modified
With _TEXT_MODIFIED.
union textarea_msg::@79 data
Depends on msg type.
textarea_drag_type drag
With _DRAG_REPORT.
Definition: textarea.h:79
textarea setup parameters
Definition: textarea.h:108
plot_font_style_t text
Textarea background colour and font.
Definition: textarea.h:122
unsigned int flags
Textarea flags.
Definition: textarea.c:98
Client callbacks for events concerning nodes.
Definition: treeview.h:148
nserror(* folder)(struct treeview_node_msg msg, void *data)
Definition: treeview.h:149
nserror(* entry)(struct treeview_node_msg msg, void *data)
Definition: treeview.h:150
context for treeview contraction callback
Definition: treeview.c:2312
Treeview drag state.
Definition: treeview.c:177
struct treeview_pos start
Start pos.
Definition: treeview.c:188
treeview_node * start_node
Start node.
Definition: treeview.c:185
struct treeview_pos prev
Previous pos.
Definition: treeview.c:189
bool selected
Start node is selected.
Definition: treeview.c:186
enum treeview_drag::@85 type
Drag type.
@ TV_DRAG_SELECTION
Definition: treeview.c:180
@ TV_DRAG_TEXTAREA
Definition: treeview.c:182
enum treeview_node_part part
Node part at start.
Definition: treeview.c:187
Treeview node edit details.
Definition: treeview.c:207
int h
Textarea height.
Definition: treeview.c:214
int w
Textarea width.
Definition: treeview.c:213
struct textarea * textarea
Textarea for edit, or NULL.
Definition: treeview.c:209
treeview_node * node
Node being edited, or NULL.
Definition: treeview.c:208
lwc_string * field
The field being edited, or NULL.
Definition: treeview.c:210
int y
Textarea y position.
Definition: treeview.c:212
int x
Textarea x position.
Definition: treeview.c:211
context data for treeview expansion
Definition: treeview.c:2487
Treeview field data.
Definition: treeview.h:138
const char * value
Field value.
Definition: treeview.h:140
lwc_string * field
Field name.
Definition: treeview.h:139
size_t value_len
Field value length (bytes)
Definition: treeview.h:141
Treeview field description.
Definition: treeview.h:129
enum treeview_field_flags flags
Flags for field.
Definition: treeview.h:131
a treeview field
Definition: treeview.c:98
struct treeview_text value
field text
Definition: treeview.c:103
enum treeview_field_flags flags
flags controlling how field is interpreted
Definition: treeview.c:100
lwc_string * field
field contents
Definition: treeview.c:102
Treeview handling global context.
Definition: treeview.c:63
unsigned initialised
Definition: treeview.c:64
int furniture_width
Definition: treeview.c:66
int window_padding
Definition: treeview.c:68
context for treeview launch action
Definition: treeview.c:3694
context for treeview mouse handling
Definition: treeview.c:4429
browser_mouse_state mouse
Definition: treeview.c:4431
Treeview node move details.
Definition: treeview.c:196
enum treeview_target_pos target_pos
Pos wrt render node.
Definition: treeview.c:200
treeview_node * target
Move target.
Definition: treeview.c:198
struct rect target_area
Pos/size of target indicator.
Definition: treeview.c:199
treeview_node * root
Head of yanked node list.
Definition: treeview.c:197
context for treeview keyboard action
Definition: treeview.c:3827
treeview * tree
Definition: treeview.c:3828
treeview_node * last
Definition: treeview.c:3832
treeview_node * curr
Definition: treeview.c:3830
treeview_node * next
Definition: treeview.c:3831
treeview_node * prev
Definition: treeview.c:3829
context for treeview node deletion iterator
Definition: treeview.c:1693
Node entry.
Definition: treeview.c:157
treeview_node base
Entry class inherits node base class.
Definition: treeview.c:158
struct treeview_field fields[FLEX_ARRAY_LEN_DECL]
Definition: treeview.c:159
treeview message
Definition: treeview.h:96
browser_mouse_state mouse
Definition: treeview.h:107
enum treeview_msg msg
The message type.
Definition: treeview.h:97
style for a node
Definition: treeview.c:269
plot_font_style_t sitext
Selected entry field text.
Definition: treeview.c:276
struct treeview_node_style::@86 furn[TREE_FURN_LAST]
plot_style_t bg
Background.
Definition: treeview.c:270
plot_font_style_t itext
Entry field text.
Definition: treeview.c:272
plot_font_style_t text
Text.
Definition: treeview.c:271
struct bitmap * bmp
Definition: treeview.c:280
plot_style_t sbg
Selected background.
Definition: treeview.c:274
struct bitmap * sel
Definition: treeview.c:281
plot_font_style_t stext
Selected text.
Definition: treeview.c:275
Treeview node.
Definition: treeview.c:133
enum treeview_node_type type
Node type.
Definition: treeview.c:135
treeview_node * prev_sib
previous sibling node
Definition: treeview.c:141
treeview_node * next_sib
next sibling node
Definition: treeview.c:142
struct treeview_text text
Definition: treeview.c:147
treeview_node * parent
parent node
Definition: treeview.c:140
enum treeview_node_flags flags
Node flags.
Definition: treeview.c:134
treeview_node * children
first child node
Definition: treeview.c:143
int inset
Node's inset depending on tree depth (pixels)
Definition: treeview.c:138
void * client_data
Passed to client on node event msg callback.
Definition: treeview.c:145
int height
Includes height of any descendants (pixels)
Definition: treeview.c:137
A mouse position wrt treeview.
Definition: treeview.c:166
int node_h
Height of node at y.
Definition: treeview.c:170
int y
Mouse Y coordinate.
Definition: treeview.c:168
int x
Mouse X coordinate.
Definition: treeview.c:167
int node_y
Top of node at y.
Definition: treeview.c:169
Treeview content resource data.
Definition: treeview.c:301
const char * url
Definition: treeview.c:302
struct hlcache_handle * c
Definition: treeview.c:303
Data used when doing a treeview walk for search.
Definition: treeview.c:796
const char * text
The string being searched for.
Definition: treeview.c:798
const unsigned int len
Length of string being searched for.
Definition: treeview.c:799
treeview * tree
The treeview to search.
Definition: treeview.c:797
int window_height
Accumulate height for matching entries.
Definition: treeview.c:800
Treeview search box details.
Definition: treeview.c:221
struct textarea * textarea
Search box.
Definition: treeview.c:222
int height
Current search display height.
Definition: treeview.c:225
bool active
Whether the search box has focus.
Definition: treeview.c:223
bool search
Whether we have a search term.
Definition: treeview.c:224
context for treeview selection
Definition: treeview.c:3114
union treeview_selection_walk_data::@88 data
enum treeview_selection_walk_data::@87 purpose
struct treeview_selection_walk_data::@88::@92 first
struct treeview_selection_walk_data::@88::@93 copy
struct treeview_selection_walk_data::@88::@91 yank
struct treeview_selection_walk_data::@88::@90 drag
struct treeview_selection_walk_data::@88::@89 redraw
Text within a treeview field or node.
Definition: treeview.c:88
uint32_t len
Length of string in bytes.
Definition: treeview.c:90
const char * data
Text string.
Definition: treeview.c:89
int width
Width of text in px.
Definition: treeview.c:91
Treewalk iterator context.
treeview_walk_cb enter_cb
Definition: treeview.c:1483
enum treeview_node_type type
Definition: treeview.c:1486
treeview_walk_cb leave_cb
Definition: treeview.c:1484
The treeview context.
Definition: treeview.c:232
int n_fields
fields[n_fields] is folder, lower are entry fields
Definition: treeview.c:240
struct treeview_search search
Treeview search box.
Definition: treeview.c:247
treeview_flags flags
Treeview behaviour settings.
Definition: treeview.c:235
const struct treeview_callback_table * callbacks
For node events.
Definition: treeview.c:249
const struct core_window_callback_table * cw_t
Window cb table.
Definition: treeview.c:251
treeview_node * root
Root node.
Definition: treeview.c:237
int field_width
Max width of shown field names.
Definition: treeview.c:241
struct treeview_move move
Move drag details.
Definition: treeview.c:244
struct treeview_drag drag
Drag state.
Definition: treeview.c:243
struct treeview_edit edit
Edit details.
Definition: treeview.c:245
uint32_t view_width
Viewport horizontal size.
Definition: treeview.c:233
struct core_window * cw_h
Core window handle.
Definition: treeview.c:252
struct treeview_field * fields
Array of fields.
Definition: treeview.c:239
Interface to system colour values.
uint32_t colour
Colour type: XBGR.
Definition: types.h:35
struct rect rect
Rectangle coordinates.
static int mouse_x
Definition: url_complete.c:66
static int mouse_y
Definition: url_complete.c:67
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:279
Interface to a number of general purpose functionality.
#define FLEX_ARRAY_LEN_DECL
Definition: utils.h:66
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357