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 struct core_window *cw_h; /**< Core window handle */
252};
253
254
255/**
256 * Treeview furniture states.
257 */
263
264
265/**
266 * style for a node
267 */
269 plot_style_t bg; /**< Background */
271 plot_font_style_t itext; /**< Entry field text */
272
273 plot_style_t sbg; /**< Selected background */
274 plot_font_style_t stext; /**< Selected text */
275 plot_font_style_t sitext; /**< Selected entry field text */
276
277 struct {
278 int size;
279 struct bitmap *bmp;
280 struct bitmap *sel;
282};
283
284
285/**
286 * Plot style for odd rows
287 */
289
290
291/**
292 * Plot style for even rows
293 */
295
296
297/**
298 * Treeview content resource data
299 */
301 const char *url;
304 bool ready;
305};
306
307
308/**
309 * treeview resource indexes
310 */
319
320
321/**
322 * Treeview content resources
323 */
325 { "resource:icons/arrow-l.png", NULL, 0, false },
326 { "resource:icons/content.png", NULL, 0, false },
327 { "resource:icons/directory.png", NULL, 0, false },
328 { "resource:icons/directory2.png", NULL, 0, false },
329 { "resource:icons/search.png", NULL, 0, false }
330};
331
332
333/**
334 * Get the display height of the treeview data component of the display.
335 *
336 * \param[in] tree Treeview to get the height of.
337 * \return the display height in pixels.
338 */
339static inline int treeview__get_display_height(const treeview *tree)
340{
341 return (tree->search.search == false) ?
342 tree->root->height :
343 tree->search.height;
344}
345
346
347/**
348 * Corewindow callback wrapper: Request a redraw of the window
349 *
350 * \param[in] tree The treeview to request redraw on.
351 * \param[in] r rectangle to redraw
352 */
354 const struct treeview *tree,
355 const struct rect *r)
356{
357 if (tree->cw_h != NULL) {
358 guit->corewindow->invalidate(tree->cw_h, r);
359 }
360}
361
362
363/**
364 * Corewindow callback wrapper: Request a full redraw of the window
365 *
366 * \param[in] tree The treeview to request redraw on.
367 */
368static inline void treeview__cw_full_redraw(
369 const struct treeview *tree)
370{
371 if (tree->cw_h != NULL) {
372 static const struct rect r = {
373 .x0 = 0,
374 .y0 = 0,
375 .x1 = REDRAW_MAX,
376 .y1 = REDRAW_MAX,
377 };
378 guit->corewindow->invalidate(tree->cw_h, &r);
379 }
380}
381
382
383/**
384 * Get height used by treeview's search bar (or 0 if not present).
385 *
386 * \param tree Treeview object to check.
387 * \return height used by search bar in pixels.
388 */
389static inline unsigned treeview__get_search_height(
390 const treeview *tree)
391{
392 return (tree->flags & TREEVIEW_SEARCHABLE) ?
394}
395
396
397/**
398 * Corewindow callback wrapper: Update the limits of the window
399 *
400 * \param[in] tree The treeview to update size for.
401 * \param[in] width the width in px, or negative if don't care
402 * \param[in] height the height in px, or negative if don't care
403 */
404static inline void treeview__cw_update_size(
405 const struct treeview *tree,
406 int width, int height)
407{
408 if (tree->cw_h != NULL) {
410 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
432}
433
434/**
435 * Corewindow callback wrapper: Get window viewport dimensions
436 *
437 * \param[in] tree The treeview to get dimensions for.
438 * \param[out] width to be set to viewport width in px
439 * \param[out] height to be set to viewport height in px
440 */
442 const struct treeview *tree,
443 int *width, int *height)
444{
445 if (tree->cw_h != NULL) {
447 }
448}
449
450
451/**
452 * Corewindow callback wrapper: Inform corewindow owner of drag status
453 *
454 * \param[in] tree The treeview to report status on.
455 * \param[in] ds the current drag status
456 */
457static inline void treeview__cw_drag_status(
458 const struct treeview *tree,
460{
461 if (tree->cw_h != NULL) {
462 guit->corewindow->drag_status(tree->cw_h, ds);
463 }
464}
465
466
467/**
468 * Helper function to access the given field of a node
469 *
470 * \param tree Treeview that node belongs to
471 * \param n Node to get field from
472 * \param i Index of field of interest
473 * \return text entry for field or NULL.
474 */
475static inline struct treeview_text *
477{
478 if (i == 0) {
479 return &n->text;
480
481 } else if (i < tree->n_fields && n->type == TREE_NODE_ENTRY) {
482 struct treeview_node_entry *e = (struct treeview_node_entry *)n;
483 return &e->fields[i - 1].value;
484 }
485
486 assert(0 && "Bad field index for node");
487 return NULL;
488}
489
490
491/**
492 * Find the next node in depth first tree order
493 *
494 * \param node Start node
495 * \param full Iff true, visit children of collapsed nodes
496 * \return next node, or NULL if \a node is last node
497 */
498static inline treeview_node * treeview_node_next(treeview_node *node, bool full)
499{
500 assert(node != NULL);
501
502 if ((full || (node->flags & TV_NFLAGS_EXPANDED)) &&
503 node->children != NULL) {
504 /* Next node is child */
505 node = node->children;
506 } else {
507 /* No children. As long as we're not at the root,
508 * go to next sibling if present, or nearest ancestor
509 * with a next sibling. */
510
511 while (node->parent != NULL && node->next_sib == NULL) {
512 node = node->parent;
513 }
514
515 if (node->type == TREE_NODE_ROOT) {
516 node = NULL;
517
518 } else {
519 node = node->next_sib;
520 }
521 }
522
523 return node;
524}
525
526
527/**
528 * Find node at given y-position
529 *
530 * \param tree Treeview object to delete node from
531 * \param target_y Target y-position
532 * \return node at y_target
533 */
534static treeview_node * treeview_y_node(treeview *tree, int target_y)
535{
536 int y = treeview__get_search_height(tree);
537 treeview_node *n;
538
539 assert(tree != NULL);
540 assert(tree->root != NULL);
541
542 n = treeview_node_next(tree->root, false);
543
544 while (n != NULL) {
545 int h = (n->type == TREE_NODE_ENTRY) ?
547 if (target_y >= y && target_y < y + h)
548 return n;
549 y += h;
550
551 n = treeview_node_next(n, false);
552 }
553
554 return NULL;
555}
556
557
558/**
559 * Find y position of the top of a node
560 *
561 * \param tree Treeview object to delete node from
562 * \param node Node to get position of
563 * \return node's y position
564 */
566 const treeview *tree,
567 const treeview_node *node)
568{
569 treeview_node *n;
570 int y = treeview__get_search_height(tree);
571
572 assert(tree != NULL);
573 assert(tree->root != NULL);
574
575 n = treeview_node_next(tree->root, false);
576
577 while (n != NULL && n != node) {
578 y += (n->type == TREE_NODE_ENTRY) ?
580
581 n = treeview_node_next(n, false);
582 }
583
584 return y;
585}
586
587
588/**
589 * Corewindow callback_wrapper: Scroll to make node visible
590 *
591 * \param[in] tree The treeview to scroll.
592 * \param[in] node The treeview node to scroll to visibility.
593 */
595 const struct treeview *tree,
596 const struct treeview_node *node)
597{
598 struct rect r = {
599 .x0 = 0,
600 .y0 = treeview_node_y(tree, node),
601 .x1 = 1,
602 .y1 = (((node != NULL) && (node->type == TREE_NODE_ENTRY)) ?
603 node->height : tree_g.line_height),
604 };
605
606 r.y1 += r.y0; /* Apply the Y offset to the second Y coordinate */
607
609}
610
611
612/**
613 * Redraw tree from given node to the bottom.
614 *
615 * \param[in] tree Tree to redraw from node in.
616 * \param[in] node Node to redraw from.
617 */
619 const treeview *tree,
620 const treeview_node *node)
621{
622 struct rect r = {
623 .x0 = 0,
624 .y0 = treeview_node_y(tree, node),
625 .x1 = REDRAW_MAX,
626 .y1 = treeview__get_display_height(tree) +
628 };
629
630 assert(tree != NULL);
631
633}
634
635
636/**
637 * The treeview walk mode. Controls which nodes are visited in a walk.
638 */
640 /**
641 * Walk to all nodes in the (sub)tree.
642 */
644
645 /**
646 * Walk to expanded nodes in the (sub)tree only. Children of
647 * collapsed nodes are not visited.
648 */
650
651 /**
652 * Walk displayed nodes. This differs from the
653 * `TREEVIEW_WALK_MODE_LOGICAL_EXPANDED` mode when there is
654 * an active search filter display.
655 */
657};
658
659
660/**
661 * Walk a treeview subtree, calling a callback at each node (depth first)
662 *
663 * \param tree Treeview being walked.
664 * \param root Root to walk tree from (doesn't get a callback call)
665 * \param mode The treeview walk mode to use.
666 * \param callback_bwd Function to call on each node in backwards order
667 * \param callback_fwd Function to call on each node in forwards order
668 * \param ctx Context to pass to callback
669 * \return NSERROR_OK on success, or appropriate error otherwise
670 *
671 * \note Any node deletion must happen in callback_bwd.
672 */
674 treeview *tree,
677 nserror (*callback_bwd)(
678 treeview_node *n,
679 void *ctx,
680 bool *end),
681 nserror (*callback_fwd)(
682 treeview_node *n,
683 void *ctx,
684 bool *skip_children,
685 bool *end),
686 void *ctx)
687{
688 treeview_node *node, *child, *parent, *next_sibling;
689 bool walking_search = (mode == TREEVIEW_WALK_MODE_DISPLAY &&
690 tree->search.search == true);
691 bool skip_children = false;
692 bool abort = false;
693 bool full = false;
694 nserror err;
695 bool entry;
696
697 assert(root != NULL);
698
699 if (mode == TREEVIEW_WALK_MODE_LOGICAL_COMPLETE || walking_search) {
700 /* We need to visit children of collapsed folders. */
701 full = true;
702 }
703
704 node = root;
705 parent = node->parent;
706 next_sibling = node->next_sib;
707 child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
708 node->children : NULL;
709
710 while (node != NULL) {
711
712 if (child != NULL && !skip_children) {
713 /* Down to children */
714 node = child;
715 } else {
716 /* No children. As long as we're not at the root,
717 * go to next sibling if present, or nearest ancestor
718 * with a next sibling. */
719
720 while (node != root && next_sibling == NULL) {
721 entry = (node->type == TREE_NODE_ENTRY);
722 if (callback_bwd != NULL &&
723 (entry || !walking_search)) {
724 /* Backwards callback */
725 err = callback_bwd(node, ctx, &abort);
726
727 if (err != NSERROR_OK) {
728 return err;
729
730 } else if (abort) {
731 /* callback requested early
732 * termination */
733 return NSERROR_OK;
734 }
735 }
736 node = parent;
737 parent = node->parent;
738 next_sibling = node->next_sib;
739 }
740
741 if (node == root)
742 break;
743
744 if (callback_bwd != NULL) {
745 /* Backwards callback */
746 err = callback_bwd(node, ctx, &abort);
747
748 if (err != NSERROR_OK) {
749 return err;
750
751 } else if (abort) {
752 /* callback requested early
753 * termination */
754 return NSERROR_OK;
755 }
756 }
757 node = next_sibling;
758 }
759
760 assert(node != NULL);
761 assert(node != root);
762
763 entry = (node->type == TREE_NODE_ENTRY);
764
765 parent = node->parent;
766 next_sibling = node->next_sib;
767 child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
768 node->children : NULL;
769
770 if (walking_search && (!entry ||
771 !(node->flags & TV_NFLAGS_MATCHED))) {
772 continue;
773 }
774
775 if (callback_fwd != NULL) {
776 /* Forwards callback */
777 err = callback_fwd(node, ctx, &skip_children, &abort);
778
779 if (err != NSERROR_OK) {
780 return err;
781
782 } else if (abort) {
783 /* callback requested early termination */
784 return NSERROR_OK;
785 }
786 }
787 }
788 return NSERROR_OK;
789}
790
791
792/**
793 * Data used when doing a treeview walk for search.
794 */
796 treeview *tree; /**< The treeview to search. */
797 const char *text; /**< The string being searched for. */
798 const unsigned int len; /**< Length of string being searched for. */
799 int window_height; /**< Accumulate height for matching entries. */
800};
801
802
803/**
804 * Treewalk node callback for handling search.
805 *
806 * \param[in] n Current node.
807 * \param[in] ctx Treeview search context.
808 * \param[in,out] skip_children Flag to allow children to be skipped.
809 * \param[in,out] end Flag to allow iteration to be finished early.
810 * \return NSERROR_OK on success else error code.
811 */
813 treeview_node *n,
814 void *ctx,
815 bool *skip_children,
816 bool *end)
817{
818 struct treeview_search_walk_data *sw = ctx;
819
820 /* only entry nodes can be searched */
821 if (n->type != TREE_NODE_ENTRY) {
822 return NSERROR_OK;
823 }
824
825 /* empty string will never match */
826 if (sw->len == 0) {
827 n->flags &= ~TV_NFLAGS_MATCHED;
828 return NSERROR_OK;
829 }
830
831 struct treeview_node_entry *entry = (struct treeview_node_entry *)n;
832 bool matched = false;
833
834 for (int i = 0; i < sw->tree->n_fields; i++) {
835 struct treeview_field *ef = &(sw->tree->fields[i + 1]);
836 if (ef->flags & TREE_FLAG_SEARCHABLE) {
837 if (strcasestr(entry->fields[i].value.data,
838 sw->text) != NULL) {
839 matched = true;
840 break;
841 }
842 }
843 }
844
845 if (!matched && strcasestr(n->text.data, sw->text) != NULL) {
846 matched = true;
847 }
848
849 if (matched) {
851 sw->window_height += n->height;
852 } else {
853 n->flags &= ~TV_NFLAGS_MATCHED;
854 }
855
856 return NSERROR_OK;
857}
858
859
860/**
861 * Search treeview for text.
862 *
863 * \param[in] tree Treeview to search.
864 * \param[in] text UTF-8 string to search for. (NULL-terminated.)
865 * \param[in] len Byte length of UTF-8 string.
866 * \return NSERROR_OK on success, appropriate error otherwise.
867 */
869 treeview *tree,
870 const char *text,
871 unsigned int len)
872{
873 nserror err;
874 uint32_t height;
875 uint32_t prev_height = treeview__get_display_height(tree);
876 int search_height = treeview__get_search_height(tree);
877 struct treeview_search_walk_data sw = {
878 .len = len,
879 .text = text,
880 .tree = tree,
881 .window_height = 0,
882 };
883 struct rect r = {
884 .x0 = 0,
885 .y0 = search_height,
886 .x1 = REDRAW_MAX,
887 };
888
889 assert(text[len] == '\0');
890
891 if (tree->root == NULL) {
892 return NSERROR_OK;
893 }
894
895 err = treeview_walk_internal(tree, tree->root,
898 if (err != NSERROR_OK) {
899 return err;
900 }
901
902 if (len > 0) {
903 tree->search.height = sw.window_height;
904 tree->search.search = true;
906 } else {
907 tree->search.search = false;
908 height = tree->root->height;
909 }
910
911 r.y1 = ((height > prev_height) ? height : prev_height) + search_height;
915
916 return NSERROR_OK;
917}
918
919
920/**
921 * Cancel a treeview search, optionally droping focus from search widget.
922 *
923 * \param[in] tree Treeview to cancel search in.
924 * \param[in] drop_focus Iff true, drop input focus from search widget.
925 */
926static void treeview__search_cancel(treeview *tree, bool drop_focus)
927{
928 struct rect r = {
930 .x1 = 600,
931 .y0 = 0,
932 .y1 = tree_g.line_height,
933 };
934
935 tree->search.search = false;
936 if (tree->search.active == false) {
937 return;
938 }
939
940 if (textarea_get_text(tree->search.textarea, NULL, 0) == 1) {
941 // If there's no text in the search box, we drop focus on a
942 // cancel. Note '1' because it includes the trailing \0
943 drop_focus = true;
944 }
945
946 if (drop_focus) {
947 tree->search.active = false;
949 } else {
951 }
952
955}
956
957/**
958 * Convert from treeview drag to core window drag type.
959 *
960 * \param[in] tree A treeview.
961 * \return Core window drag type.
962 */
964 const treeview *tree)
965{
966 assert(tree != NULL);
967
968 switch (tree->drag.type) {
969 case TV_DRAG_NONE:
971
972 case TV_DRAG_SELECTION:
974
975 case TV_DRAG_TEXTAREA: /* Fall through.*/
976 case TV_DRAG_SEARCH:
978
979 case TV_DRAG_MOVE:
981 }
982
984}
985
986/**
987 * Callback for textarea_create, in desktop/treeview.h
988 *
989 * \param data treeview context
990 * \param msg textarea message
991 */
993 struct textarea_msg *msg)
994{
995 treeview *tree = data;
996 struct rect *r;
997
998 if (tree->search.active == false || tree->root == NULL) {
999 return;
1000 }
1001
1002 switch (msg->type) {
1004 if (msg->data.drag == TEXTAREA_DRAG_NONE) {
1005 /* Textarea drag finished */
1006 tree->drag.type = TV_DRAG_NONE;
1007 } else {
1008 /* Textarea drag started */
1009 tree->drag.type = TV_DRAG_SEARCH;
1010 }
1013 break;
1014
1016 r = &msg->data.redraw;
1018 r->y0 += 0;
1019 r->x1 += 600;
1020 r->y1 += tree_g.line_height;
1021
1022 /* Redraw the textarea */
1024 break;
1025
1027 /* Textarea length includes trailing NULL, so subtract it. */
1028 treeview__search(tree,
1029 msg->data.modified.text,
1030 msg->data.modified.len - 1);
1031 break;
1032
1033 default:
1034 break;
1035 }
1036}
1037
1038
1039/**
1040 * Update the layout for any active search.
1041 *
1042 * \param[in] tree The tree to update.
1043 */
1045 treeview *tree)
1046{
1047 const char *string;
1048 unsigned int len;
1049
1050 if (tree->search.search == false) {
1051 /* No active search to update view for. */
1052 return;
1053 }
1054
1055 string = textarea_data(tree->search.textarea, &len);
1056 if (string == NULL || len == 0) {
1057 return;
1058 }
1059
1060 treeview__search(tree, string, len - 1);
1061}
1062
1063
1064/**
1065 * Create treeview's root node
1066 *
1067 * \param[out] root Returns root node
1068 * \return NSERROR_OK on success, appropriate error otherwise
1069 */
1071{
1072 treeview_node *n;
1073
1074 n = malloc(sizeof(struct treeview_node));
1075 if (n == NULL) {
1076 return NSERROR_NOMEM;
1077 }
1078
1080 n->type = TREE_NODE_ROOT;
1081
1082 n->height = 0;
1084
1085 n->text.data = NULL;
1086 n->text.len = 0;
1087 n->text.width = 0;
1088
1089 n->parent = NULL;
1090 n->next_sib = NULL;
1091 n->prev_sib = NULL;
1092 n->children = NULL;
1093
1094 n->client_data = NULL;
1095
1096 *root = n;
1097
1098 return NSERROR_OK;
1099}
1100
1101
1102/**
1103 * Set a node's inset from its parent
1104 *
1105 * This may be used as treeview walk callback
1106 *
1107 * \param[in] n node to set inset on
1108 * \param[in] ctx context unused
1109 * \param[out] skip_children set to false so child nodes are not skipped.
1110 * \param[out] end unused flag so treewalk in not terminated early.
1111 */
1112static nserror
1114 void *ctx,
1115 bool *skip_children,
1116 bool *end)
1117{
1118 if (n->parent != NULL)
1119 n->inset = n->parent->inset + tree_g.step_width;
1120
1121 *skip_children = false;
1122 return NSERROR_OK;
1123}
1124
1125
1126/**
1127 * Insert a treeview node into a treeview
1128 *
1129 * \param tree the treeview to insert node into.
1130 * \param a parentless node to insert
1131 * \param b tree node to insert a as a relation of
1132 * \param rel The relationship between \a a and \a b
1133 */
1134static inline void
1136 treeview *tree,
1137 treeview_node *a,
1138 treeview_node *b,
1139 enum treeview_relationship rel)
1140{
1141 assert(a != NULL);
1142 assert(a->parent == NULL);
1143 assert(b != NULL);
1144
1145 switch (rel) {
1147 assert(b->type != TREE_NODE_ENTRY);
1148 a->parent = b;
1149 a->next_sib = b->children;
1150 if (a->next_sib)
1151 a->next_sib->prev_sib = a;
1152 b->children = a;
1153 break;
1154
1156 assert(b->type != TREE_NODE_ROOT);
1157 a->prev_sib = b;
1158 a->next_sib = b->next_sib;
1159 a->parent = b->parent;
1160 b->next_sib = a;
1161 if (a->next_sib)
1162 a->next_sib->prev_sib = a;
1163 break;
1164
1165 default:
1166 assert(0);
1167 break;
1168 }
1169
1170 assert(a->parent != NULL);
1171
1172 a->inset = a->parent->inset + tree_g.step_width;
1173 if (a->children != NULL) {
1174 treeview_walk_internal(tree, a,
1177 }
1178
1179 if (a->parent->flags & TV_NFLAGS_EXPANDED) {
1180 int height = a->height;
1181 /* Parent is expanded, so inserted node will be visible and
1182 * affect layout */
1183 if (a->text.width == 0) {
1185 a->text.data,
1186 a->text.len,
1187 &(a->text.width));
1188 }
1189
1190 do {
1191 a->parent->height += height;
1192 a = a->parent;
1193 } while (a->parent != NULL);
1194 }
1195}
1196
1197
1198/* Exported interface, documented in treeview.h */
1199nserror
1201 treeview_node **folder,
1202 treeview_node *relation,
1203 enum treeview_relationship rel,
1204 const struct treeview_field_data *field,
1205 void *data,
1207{
1208 treeview_node *n;
1209
1210 assert(data != NULL);
1211 assert(tree != NULL);
1212 assert(tree->root != NULL);
1213
1214 if (relation == NULL) {
1215 relation = tree->root;
1217 }
1218
1219 n = malloc(sizeof(struct treeview_node));
1220 if (n == NULL) {
1221 return NSERROR_NOMEM;
1222 }
1223
1224 n->flags = (flags & TREE_OPTION_SPECIAL_DIR) ?
1227
1229
1230 n->text.data = field->value;
1231 n->text.len = field->value_len;
1232 n->text.width = 0;
1233
1234 n->parent = NULL;
1235 n->next_sib = NULL;
1236 n->prev_sib = NULL;
1237 n->children = NULL;
1238
1239 n->client_data = data;
1240
1241 treeview_insert_node(tree, n, relation, rel);
1242
1243 if (n->parent->flags & TV_NFLAGS_EXPANDED) {
1244 /* Inform front end of change in dimensions */
1245 if (!(flags & TREE_OPTION_SUPPRESS_RESIZE))
1246 treeview__cw_update_size(tree, -1,
1247 tree->root->height);
1248
1249 /* Redraw */
1250 if (!(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
1251 struct rect r;
1252 r.x0 = 0;
1253 r.y0 = treeview_node_y(tree, n);
1254 r.x1 = REDRAW_MAX;
1255 r.y1 = tree->root->height;
1257 }
1258 }
1259
1260 *folder = n;
1261
1262 return NSERROR_OK;
1263}
1264
1265
1266/* Exported interface, documented in treeview.h */
1267nserror
1269 treeview_node *folder,
1270 const struct treeview_field_data *field,
1271 void *data)
1272{
1273 bool match;
1274
1275 assert(data != NULL);
1276 assert(tree != NULL);
1277 assert(folder != NULL);
1278 assert(data == folder->client_data);
1279 assert(folder->parent != NULL);
1280
1281 assert(field != NULL);
1282 assert(lwc_string_isequal(tree->fields[tree->n_fields].field,
1283 field->field, &match) == lwc_error_ok &&
1284 match == true);
1285 folder->text.data = field->value;
1286 folder->text.len = field->value_len;
1287 folder->text.width = 0;
1288
1289 if (folder->parent->flags & TV_NFLAGS_EXPANDED) {
1290 /* Text will be seen, get its width */
1292 folder->text.data,
1293 folder->text.len,
1294 &(folder->text.width));
1295 } else {
1296 /* Just invalidate the width, since it's not needed now */
1297 folder->text.width = 0;
1298 }
1299
1300 /* Redraw */
1301 if (folder->parent->flags & TV_NFLAGS_EXPANDED) {
1302 struct rect r;
1303 r.x0 = 0;
1304 r.y0 = treeview_node_y(tree, folder);
1305 r.x1 = REDRAW_MAX;
1306 r.y1 = r.y0 + tree_g.line_height;
1308 }
1309
1310 return NSERROR_OK;
1311}
1312
1313
1314/* Exported interface, documented in treeview.h */
1315nserror
1317 treeview_node *entry,
1318 const struct treeview_field_data fields[],
1319 void *data)
1320{
1321 bool match;
1322 struct treeview_node_entry *e = (struct treeview_node_entry *)entry;
1323 int i;
1324
1325 assert(data != NULL);
1326 assert(tree != NULL);
1327 assert(entry != NULL);
1328 assert(data == entry->client_data);
1329 assert(entry->parent != NULL);
1330
1331 assert(fields != NULL);
1332 assert(fields[0].field != NULL);
1333 assert(lwc_string_isequal(tree->fields[0].field,
1334 fields[0].field, &match) == lwc_error_ok &&
1335 match == true);
1336 entry->text.data = fields[0].value;
1337 entry->text.len = fields[0].value_len;
1338 entry->text.width = 0;
1339
1340 if (entry->parent->flags & TV_NFLAGS_EXPANDED) {
1341 /* Text will be seen, get its width */
1343 entry->text.data,
1344 entry->text.len,
1345 &(entry->text.width));
1346 } else {
1347 /* Just invalidate the width, since it's not needed now */
1348 entry->text.width = 0;
1349 }
1350
1351 for (i = 1; i < tree->n_fields; i++) {
1352 assert(fields[i].field != NULL);
1353 assert(lwc_string_isequal(tree->fields[i].field,
1354 fields[i].field, &match) == lwc_error_ok &&
1355 match == true);
1356
1357 e->fields[i - 1].value.data = fields[i].value;
1358 e->fields[i - 1].value.len = fields[i].value_len;
1359
1360 if (entry->flags & TV_NFLAGS_EXPANDED) {
1361 /* Text will be seen, get its width */
1363 e->fields[i - 1].value.data,
1364 e->fields[i - 1].value.len,
1365 &(e->fields[i - 1].value.width));
1366 } else {
1367 /* Invalidate the width, since it's not needed yet */
1368 e->fields[i - 1].value.width = 0;
1369 }
1370 }
1371
1373
1374 /* Redraw */
1375 if (entry->parent->flags & TV_NFLAGS_EXPANDED) {
1376 struct rect r;
1377 r.x0 = 0;
1378 r.y0 = treeview_node_y(tree, entry);
1379 r.x1 = REDRAW_MAX;
1380 r.y1 = r.y0 + entry->height;
1382 }
1383
1384 return NSERROR_OK;
1385}
1386
1387
1388/* Exported interface, documented in treeview.h */
1389nserror
1391 treeview_node **entry,
1392 treeview_node *relation,
1393 enum treeview_relationship rel,
1394 const struct treeview_field_data fields[],
1395 void *data,
1397{
1398 bool match;
1399 struct treeview_node_entry *e;
1400 treeview_node *n;
1401 int i;
1402
1403 assert(data != NULL);
1404 assert(tree != NULL);
1405 assert(tree->root != NULL);
1406
1407 if (relation == NULL) {
1408 relation = tree->root;
1410 }
1411
1412 e = malloc(sizeof(struct treeview_node_entry) +
1413 (tree->n_fields - 1) * sizeof(struct treeview_field));
1414 if (e == NULL) {
1415 return NSERROR_NOMEM;
1416 }
1417
1418
1419 n = (treeview_node *) e;
1420
1421 n->flags = TV_NFLAGS_NONE;
1422 n->type = TREE_NODE_ENTRY;
1423
1425
1426 assert(fields != NULL);
1427 assert(fields[0].field != NULL);
1428 assert(lwc_string_isequal(tree->fields[0].field,
1429 fields[0].field, &match) == lwc_error_ok &&
1430 match == true);
1431 n->text.data = fields[0].value;
1432 n->text.len = fields[0].value_len;
1433 n->text.width = 0;
1434
1435 n->parent = NULL;
1436 n->next_sib = NULL;
1437 n->prev_sib = NULL;
1438 n->children = NULL;
1439
1440 n->client_data = data;
1441
1442 for (i = 1; i < tree->n_fields; i++) {
1443 assert(fields[i].field != NULL);
1444 assert(lwc_string_isequal(tree->fields[i].field,
1445 fields[i].field, &match) == lwc_error_ok &&
1446 match == true);
1447
1448 e->fields[i - 1].value.data = fields[i].value;
1449 e->fields[i - 1].value.len = fields[i].value_len;
1450 e->fields[i - 1].value.width = 0;
1451 }
1452
1453 treeview_insert_node(tree, n, relation, rel);
1454
1455 if (n->parent->flags & TV_NFLAGS_EXPANDED) {
1456 /* Inform front end of change in dimensions */
1457 if (!(flags & TREE_OPTION_SUPPRESS_RESIZE))
1458 treeview__cw_update_size(tree, -1,
1459 tree->root->height);
1460
1461 /* Redraw */
1462 if (!(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
1463 struct rect r;
1464 r.x0 = 0;
1465 r.y0 = treeview_node_y(tree, n);
1466 r.x1 = REDRAW_MAX;
1467 r.y1 = tree->root->height;
1469 }
1470 }
1471
1473
1474 *entry = n;
1475
1476 return NSERROR_OK;
1477}
1478
1479
1480/**
1481 * Treewalk iterator context
1482 */
1483struct treeview_walk_ctx {
1486 void *ctx;
1488};
1489
1490
1491/**
1492 * Treewalk node enter callback.
1493 *
1494 * \param n current node
1495 * \param ctx treewalk context
1496 * \param skip_children set if child nodes should be skipped
1497 * \param end set if iteration should end early
1498 */
1499static nserror
1501 void *ctx,
1502 bool *skip_children,
1503 bool *end)
1504{
1505 struct treeview_walk_ctx *tw = ctx;
1506
1507 if (n->type & tw->type) {
1508 return tw->enter_cb(tw->ctx, n->client_data, n->type, end);
1509 }
1510
1511 return NSERROR_OK;
1512}
1513
1514
1515/**
1516 * Treewalk node leave callback.
1517 *
1518 * \param n current node
1519 * \param ctx treewalk context
1520 * \param end set if iteration should end early
1521 */
1522static nserror treeview_walk_bwd_cb(treeview_node *n, void *ctx, bool *end)
1523{
1524 struct treeview_walk_ctx *tw = ctx;
1525
1526 if (n->type & tw->type) {
1527 return tw->leave_cb(tw->ctx, n->client_data, n->type, end);
1528 }
1529
1530 return NSERROR_OK;
1531}
1532
1533
1534/* Exported interface, documented in treeview.h */
1535nserror
1540 void *ctx,
1542{
1543 struct treeview_walk_ctx tw = {
1544 .enter_cb = enter_cb,
1545 .leave_cb = leave_cb,
1546 .ctx = ctx,
1547 .type = type
1548 };
1549
1550 assert(tree != NULL);
1551 assert(tree->root != NULL);
1552
1553 if (root == NULL)
1554 root = tree->root;
1555
1556 return treeview_walk_internal(tree, root,
1558 (leave_cb != NULL) ? treeview_walk_bwd_cb : NULL,
1559 (enter_cb != NULL) ? treeview_walk_fwd_cb : NULL,
1560 &tw);
1561}
1562
1563
1564/**
1565 * Unlink a treeview node
1566 *
1567 * \param n Node to unlink
1568 * \return true iff ancestor heights need to be reduced
1569 */
1571{
1572 /* Unlink node from tree */
1573 if (n->parent != NULL && n->parent->children == n) {
1574 /* Node is a first child */
1575 n->parent->children = n->next_sib;
1576
1577 } else if (n->prev_sib != NULL) {
1578 /* Node is not first child */
1579 n->prev_sib->next_sib = n->next_sib;
1580 }
1581
1582 if (n->next_sib != NULL) {
1583 /* Always need to do this */
1584 n->next_sib->prev_sib = n->prev_sib;
1585 }
1586
1587 /* Reduce ancestor heights */
1588 if ((n->parent != NULL) &&
1590 return true;
1591 }
1592
1593 return false;
1594}
1595
1596
1597/**
1598 * Cancel the editing of a treeview node
1599 *
1600 * \param tree Treeview object to cancel node editing in
1601 * \param redraw Set true iff redraw of removed textarea area required
1602 */
1603static void treeview_edit_cancel(treeview *tree, bool redraw)
1604{
1605 struct rect r;
1606
1607 if (tree->edit.textarea == NULL)
1608 return;
1609
1611
1612 tree->edit.textarea = NULL;
1613 tree->edit.node = NULL;
1614
1615 if (tree->drag.type == TV_DRAG_TEXTAREA)
1616 tree->drag.type = TV_DRAG_NONE;
1617
1618 if (redraw) {
1619 r.x0 = tree->edit.x;
1620 r.y0 = tree->edit.y;
1621 r.x1 = tree->edit.x + tree->edit.w;
1622 r.y1 = tree->edit.y + tree->edit.h;
1624 }
1625}
1626
1627
1628/**
1629 * Complete a treeview edit
1630 *
1631 * Complete edit by informing the client with a change request msg
1632 *
1633 * \param tree Treeview object to complete edit in
1634 */
1636{
1637 int len, error;
1638 char* new_text;
1639 treeview_node *n = tree->edit.node;
1640 struct treeview_node_msg msg;
1641 msg.msg = TREE_MSG_NODE_EDIT;
1642
1643 if (tree->edit.textarea == NULL) {
1644 return;
1645 }
1646
1647 assert(n != NULL);
1648
1649 /* Get new text length */
1650 len = textarea_get_text(tree->edit.textarea, NULL, 0);
1651
1652 new_text = malloc(len);
1653 if (new_text == NULL) {
1654 /* TODO: don't just silently ignore */
1655 return;
1656 }
1657
1658 /* Get the new text from textarea */
1659 error = textarea_get_text(tree->edit.textarea, new_text, len);
1660 if (error == -1) {
1661 /* TODO: don't just silently ignore */
1662 free(new_text);
1663 return;
1664 }
1665
1666 /* Inform the treeview client with change request message */
1667 msg.data.node_edit.field = tree->edit.field;
1668 msg.data.node_edit.text = new_text;
1669
1670 switch (n->type) {
1671 case TREE_NODE_ENTRY:
1672 tree->callbacks->entry(msg, n->client_data);
1673 break;
1674 case TREE_NODE_FOLDER:
1675 tree->callbacks->folder(msg, n->client_data);
1676 break;
1677 case TREE_NODE_ROOT:
1678 break;
1679 default:
1680 break;
1681 }
1682
1683 /* Finished with the new text */
1684 free(new_text);
1685
1686 /* Finally, destroy the treeview, and redraw */
1687 treeview_edit_cancel(tree, true);
1688}
1689
1690
1691/**
1692 * context for treeview node deletion iterator
1693 */
1698};
1699
1700
1701/**
1702 * Treewalk node callback deleting nodes.
1703 */
1704static nserror
1706{
1707 struct treeview_node_delete *nd = (struct treeview_node_delete *)ctx;
1708 struct treeview_node_msg msg;
1709
1711 msg.data.delete.user = nd->user_interaction;
1712
1713 assert(n->children == NULL);
1714
1715 if (treeview_unlink_node(n))
1716 nd->h_reduction += (n->type == TREE_NODE_ENTRY) ?
1718
1719 /* Handle any special treatment */
1720 switch (n->type) {
1721 case TREE_NODE_ENTRY:
1722 nd->tree->callbacks->entry(msg, n->client_data);
1723 break;
1724
1725 case TREE_NODE_FOLDER:
1726 nd->tree->callbacks->folder(msg, n->client_data);
1727 break;
1728
1729 case TREE_NODE_ROOT:
1730 break;
1731
1732 default:
1733 return NSERROR_BAD_PARAMETER;
1734 }
1735
1736 /* Cancel any edit of this node */
1737 if (nd->tree->edit.textarea != NULL &&
1738 nd->tree->edit.node == n) {
1739 treeview_edit_cancel(nd->tree, false);
1740 }
1741
1742 /* Free the node */
1743 free(n);
1744
1745 return NSERROR_OK;
1746}
1747
1748
1749/**
1750 * Delete a treeview node
1751 *
1752 * Will emit folder or entry deletion msg callback.
1753 *
1754 * \note this can be called from inside a treeview_walk fwd callback.
1755 * For example walking the tree and calling this for any node that's selected.
1756 *
1757 * This function does not delete empty nodes, so if TREEVIEW_DEL_EMPTY_DIRS is
1758 * set, caller must also call treeview_delete_empty.
1759 *
1760 * \param tree Treeview object to delete node from
1761 * \param n Node to delete
1762 * \param interaction Delete is result of user interaction with treeview
1763 * \param flags Treeview node options flags
1764 * \return NSERROR_OK on success, appropriate error otherwise
1765 */
1766static nserror
1768 treeview_node *n,
1769 bool interaction,
1771{
1772 nserror err;
1773 treeview_node *p = n->parent;
1774 struct treeview_node_delete nd = {
1775 .tree = tree,
1776 .h_reduction = 0,
1777 .user_interaction = interaction
1778 };
1779
1780 if (interaction && (tree->flags & TREEVIEW_NO_DELETES)) {
1781 return NSERROR_OK;
1782 }
1783
1784 /* Delete any children first */
1787 treeview_delete_node_walk_cb, NULL, &nd);
1788 if (err != NSERROR_OK) {
1789 return err;
1790 }
1791
1792 /* Now delete node */
1793 if (n == tree->root)
1794 tree->root = NULL;
1795 err = treeview_delete_node_walk_cb(n, &nd, false);
1796 if (err != NSERROR_OK) {
1797 return err;
1798 }
1799
1800 n = p;
1801 /* Reduce ancestor heights */
1802 while (n != NULL && n->flags & TV_NFLAGS_EXPANDED) {
1803 n->height -= nd.h_reduction;
1804 n = n->parent;
1805 }
1806
1807 /* Inform front end of change in dimensions */
1808 if (tree->root != NULL && p != NULL && p->flags & TV_NFLAGS_EXPANDED &&
1809 nd.h_reduction > 0 &&
1810 !(flags & TREE_OPTION_SUPPRESS_RESIZE)) {
1812 tree->root->height);
1813 }
1814
1816
1817 return NSERROR_OK;
1818}
1819
1820
1821/**
1822 * Delete any empty treeview folder nodes
1823 *
1824 * \param tree Treeview object to delete empty nodes from
1825 * \param interaction Delete is result of user interaction with treeview
1826 * \return NSERROR_OK on success, appropriate error otherwise
1827 *
1828 * Note this must not be called within a treeview_walk. It may delete the
1829 * walker's 'current' node, making it impossible to move on without invalid
1830 * reads.
1831 */
1833{
1834 treeview_node *node, *child, *parent, *next_sibling, *p;
1835 bool abort = false;
1836 nserror err;
1837 struct treeview_node_delete nd = {
1838 .tree = tree,
1839 .h_reduction = 0,
1840 .user_interaction = interaction
1841 };
1842
1843 assert(tree != NULL);
1844 assert(tree->root != NULL);
1845
1846 node = tree->root;
1847 parent = node->parent;
1848 next_sibling = node->next_sib;
1849 child = (node->flags & TV_NFLAGS_EXPANDED) ? node->children : NULL;
1850
1851 while (node != NULL) {
1852
1853 if (child != NULL) {
1854 /* Down to children */
1855 node = child;
1856 } else {
1857 /* No children. As long as we're not at the root,
1858 * go to next sibling if present, or nearest ancestor
1859 * with a next sibling. */
1860
1861 while (node->parent != NULL &&
1862 next_sibling == NULL) {
1863 if (node->type == TREE_NODE_FOLDER &&
1864 node->children == NULL) {
1865 /* Delete node */
1866 p = node->parent;
1868 node, &nd, &abort);
1869 if (err != NSERROR_OK) {
1870 return err;
1871 }
1872
1873 /* Reduce ancestor heights */
1874 while (p != NULL &&
1875 p->flags &
1877 p->height -= nd.h_reduction;
1878 p = p->parent;
1879 }
1880 nd.h_reduction = 0;
1881 }
1882 node = parent;
1883 parent = node->parent;
1884 next_sibling = node->next_sib;
1885 }
1886
1887 if (node->parent == NULL)
1888 break;
1889
1890 if (node->type == TREE_NODE_FOLDER &&
1891 node->children == NULL) {
1892 /* Delete node */
1893 p = node->parent;
1895 node, &nd, &abort);
1896 if (err != NSERROR_OK) {
1897 return err;
1898 }
1899
1900 /* Reduce ancestor heights */
1901 while (p != NULL &&
1903 p->height -= nd.h_reduction;
1904 p = p->parent;
1905 }
1906 nd.h_reduction = 0;
1907 }
1908 node = next_sibling;
1909 }
1910
1911 assert(node != NULL);
1912 assert(node->parent != NULL);
1913
1914 parent = node->parent;
1915 next_sibling = node->next_sib;
1916 child = (node->flags & TV_NFLAGS_EXPANDED) ?
1917 node->children : NULL;
1918 }
1919
1920 return NSERROR_OK;
1921}
1922
1923
1924/* Exported interface, documented in treeview.h */
1925nserror
1927 treeview_node *n,
1929{
1930 nserror err;
1931 struct rect r;
1932 bool visible;
1933
1934 assert(tree != NULL);
1935 assert(n != NULL);
1936 assert(n->parent != NULL);
1937
1938 visible = n->parent->flags & TV_NFLAGS_EXPANDED;
1939
1940 r.y0 = treeview_node_y(tree, n);
1941 r.y1 = tree->root->height;
1942
1943 err = treeview_delete_node_internal(tree, n, false, flags);
1944 if (err != NSERROR_OK)
1945 return err;
1946
1947 if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) {
1948 int h = tree->root->height;
1949 /* Delete any empty nodes */
1950 err = treeview_delete_empty_nodes(tree, false);
1951 if (err != NSERROR_OK)
1952 return err;
1953
1954 /* Inform front end of change in dimensions */
1955 if (tree->root->height != h) {
1956 r.y0 = 0;
1957 if (!(flags & TREE_OPTION_SUPPRESS_RESIZE)) {
1958 treeview__cw_update_size(tree, -1,
1959 tree->root->height);
1960 }
1961 }
1962 }
1963
1964 /* Redraw */
1965 if (visible && !(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
1966 r.x0 = 0;
1967 r.x1 = REDRAW_MAX;
1969 }
1970
1971 return NSERROR_OK;
1972}
1973
1974
1975/**
1976 * Helper to create a textarea.
1977 *
1978 * \param[in] tree The treeview we're creating the textarea for.
1979 * \param[in] width The width of the textarea.
1980 * \param[in] height The height of the textarea.
1981 * \param[in] border The border colour to use.
1982 * \param[in] background The background colour to use.
1983 * \param[in] foreground The foreground colour to use.
1984 * \param[in] text The text style to use for the text area.
1985 * \param[in] ta_callback The textarea callback function to give the textarea.
1986 * \return the textarea pointer on success, or NULL on failure.
1987 */
1989 treeview *tree,
1990 int width,
1991 int height,
1992 colour border,
1993 colour background,
1994 colour foreground,
1996 textarea_client_callback ta_callback)
1997{
1998 /* Configure the textarea */
2000 textarea_setup ta_setup = {
2001 .text = text,
2002 .width = width,
2003 .height = height,
2004 .pad_top = 0,
2005 .pad_left = 2,
2006 .pad_right = 2,
2007 .pad_bottom = 0,
2008 .border_width = 1,
2009 .border_col = border,
2010 .selected_bg = foreground,
2011 .selected_text = background,
2012 };
2013
2014 ta_setup.text.foreground = foreground;
2015 ta_setup.text.background = background;
2016
2017 /* Create text area */
2018 return textarea_create(ta_flags, &ta_setup, ta_callback, tree);
2019}
2020
2021
2022/* Exported interface, documented in treeview.h */
2023nserror
2025 const struct treeview_callback_table *callbacks,
2026 int n_fields,
2027 struct treeview_field_desc fields[],
2028 struct core_window *cw,
2030{
2031 treeview *tree;
2032 nserror error;
2033 int fldidx;
2034
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 (fldidx = 0; fldidx < n_fields; fldidx++) {
2062 struct treeview_field *f = &(tree->fields[fldidx]);
2063
2064 f->flags = fields[fldidx].flags;
2065 f->field = lwc_string_ref(fields[fldidx].field);
2066 f->value.data = lwc_string_data(fields[fldidx].field);
2067 f->value.len = lwc_string_length(fields[fldidx].field);
2068
2070 f->value.data,
2071 f->value.len,
2072 &(f->value.width));
2073
2074 if (f->flags & TREE_FLAG_SHOW_NAME) {
2075 if (tree->field_width < f->value.width) {
2076 tree->field_width = f->value.width;
2077 }
2078 }
2079 }
2080
2081 tree->field_width += tree_g.step_width;
2082
2083 tree->callbacks = callbacks;
2084 tree->n_fields = n_fields - 1;
2085
2086 tree->drag.type = TV_DRAG_NONE;
2087 tree->drag.start_node = NULL;
2088 tree->drag.start.x = 0;
2089 tree->drag.start.y = 0;
2090 tree->drag.start.node_y = 0;
2091 tree->drag.start.node_h = 0;
2092 tree->drag.prev.x = 0;
2093 tree->drag.prev.y = 0;
2094 tree->drag.prev.node_y = 0;
2095 tree->drag.prev.node_h = 0;
2096
2097 tree->move.root = NULL;
2098 tree->move.target = NULL;
2100
2101 tree->edit.textarea = NULL;
2102 tree->edit.node = NULL;
2103
2104 if (flags & TREEVIEW_SEARCHABLE) {
2106 tree, 600, tree_g.line_height,
2112 if (tree->search.textarea == NULL) {
2113 treeview_destroy(tree);
2114 return NSERROR_NOMEM;
2115 }
2116 } else {
2117 tree->search.textarea = NULL;
2118 }
2119 tree->search.active = false;
2120 tree->search.search = false;
2121
2122 tree->flags = flags;
2123
2124 tree->cw_h = cw;
2125
2126 *treeout = tree;
2127
2128 return NSERROR_OK;
2129}
2130
2131
2132/* Exported interface, documented in treeview.h */
2133nserror
2134treeview_cw_attach(treeview *tree, struct core_window *cw)
2135{
2136 assert(cw != NULL);
2137
2138 if (tree->cw_h != NULL) {
2139 NSLOG(netsurf, INFO, "Treeview already attached.");
2140 return NSERROR_UNKNOWN;
2141 }
2142 tree->cw_h = cw;
2143
2144 return NSERROR_OK;
2145}
2146
2147
2148/* Exported interface, documented in treeview.h */
2150{
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;
4936 return NSERROR_UNKNOWN;
4937 }
4938 return treeview__search(tree, "", 0);
4939 }
4940
4941 tree->search.active = true;
4942 tree->search.search = true;
4943 if (!textarea_set_text(tree->search.textarea, string)) {
4944 return NSERROR_UNKNOWN;
4945 }
4946
4948
4949 return NSERROR_OK;
4950}
4951
4952/**
4953 * Initialise the plot styles from CSS system colour values.
4954 *
4955 * \param font_pt_size font size to use
4956 * \return NSERROR_OK on success else appropriate error code
4957 */
4958static nserror treeview_init_plot_styles(int font_pt_size)
4959{
4960 /* Background colour */
4966
4967 /* Text colour */
4969 plot_style_even.text.size = font_pt_size;
4974
4975 /* Entry field text colour */
4978
4979 /* Selected background colour */
4982
4983 /* Selected text colour */
4987
4988 /* Selected entry field text colour */
4991
4992 /* Odd numbered node styles */
4999
5003
5004 return NSERROR_OK;
5005}
5006
5007
5008/**
5009 * Callback for hlcache retrieving resources.
5010 *
5011 * \param handle content hlcache handle
5012 * \param event The event that occurred on the content
5013 * \param pw treeview resource context
5014 */
5015static nserror
5017 const hlcache_event *event,
5018 void *pw)
5019{
5020 struct treeview_resource *r = pw;
5021
5022 switch (event->type) {
5023 case CONTENT_MSG_READY:
5024 case CONTENT_MSG_DONE:
5025 r->ready = true;
5026 r->height = content_get_height(handle);
5027 break;
5028
5029 default:
5030 break;
5031 }
5032
5033 return NSERROR_OK;
5034}
5035
5036
5037/**
5038 * Fetch content resources used by treeview.
5039 */
5041{
5042 int i;
5043
5044 for (i = 0; i < TREE_RES_LAST; i++) {
5045 nsurl *url;
5046 treeview_res[i].ready = false;
5047 treeview_res[i].height = 0;
5049 hlcache_handle_retrieve(url, 0, NULL, NULL,
5051 &(treeview_res[i]), NULL,
5053 &(treeview_res[i].c));
5055 }
5056 }
5057}
5058
5059
5060/**
5061 * Create a right-pointing anti-aliased triangle bitmap
5062 *
5063 * \param bg background colour
5064 * \param fg foreground colour
5065 * \param size required bitmap size
5066 */
5067static struct bitmap *
5069{
5070 struct bitmap *b = NULL;
5071 int x, y;
5072 unsigned char *rpos;
5073 unsigned char *pos;
5074 size_t stride;
5075
5076 /* Set up required colour graduations. Ignores screen gamma. */
5077 colour colour0 = bg;
5078 colour colour1 = mix_colour(bg, fg, 255 * 3 / 4);
5079 colour colour2 = blend_colour(bg, fg);
5080 colour colour3 = mix_colour(bg, fg, 255 * 1 / 4);
5081 colour colour4 = fg;
5082
5083 /* Create the bitmap */
5085 if (b == NULL)
5086 return NULL;
5087
5088 rpos = guit->bitmap->get_buffer(b);
5089 stride = guit->bitmap->get_rowstride(b);
5090
5091 /* Draw the triangle */
5092 for (y = 0; y < size; y++) {
5093 pos = rpos;
5094
5095 if (y < size / 2) {
5096 /* Top half */
5097 for (x = 0; x < y * 2; x++) {
5098 pos[bitmap_layout.r] = red_from_colour(colour4);
5099 pos[bitmap_layout.g] = green_from_colour(colour4);
5100 pos[bitmap_layout.b] = blue_from_colour(colour4);
5101 pos[bitmap_layout.a] = 0xff;
5102 pos += 4;
5103 }
5104 pos[bitmap_layout.r] = red_from_colour(colour3);
5105 pos[bitmap_layout.g] = green_from_colour(colour3);
5106 pos[bitmap_layout.b] = blue_from_colour(colour3);
5107 pos[bitmap_layout.a] = 0xff;
5108 pos += 4;
5109 pos[bitmap_layout.r] = red_from_colour(colour1);
5110 pos[bitmap_layout.g] = green_from_colour(colour1);
5111 pos[bitmap_layout.b] = blue_from_colour(colour1);
5112 pos[bitmap_layout.a] = 0xff;
5113 pos += 4;
5114 for (x = y * 2 + 2; x < size ; x++) {
5115 pos[bitmap_layout.r] = red_from_colour(colour0);
5116 pos[bitmap_layout.g] = green_from_colour(colour0);
5117 pos[bitmap_layout.b] = blue_from_colour(colour0);
5118 pos[bitmap_layout.a] = 0xff;
5119 pos += 4;
5120 }
5121 } else if ((y == size / 2) && (size & 0x1)) {
5122 /* Middle row */
5123 for (x = 0; x < size - 1; x++) {
5124 pos[bitmap_layout.r] = red_from_colour(colour4);
5125 pos[bitmap_layout.g] = green_from_colour(colour4);
5126 pos[bitmap_layout.b] = blue_from_colour(colour4);
5127 pos[bitmap_layout.a] = 0xff;
5128 pos += 4;
5129 }
5130 pos[bitmap_layout.r] = red_from_colour(colour2);
5131 pos[bitmap_layout.g] = green_from_colour(colour2);
5132 pos[bitmap_layout.b] = blue_from_colour(colour2);
5133 pos[bitmap_layout.a] = 0xff;
5134 pos += 4;
5135 } else {
5136 /* Bottom half */
5137 for (x = 0; x < (size - y - 1) * 2; x++) {
5138 pos[bitmap_layout.r] = red_from_colour(colour4);
5139 pos[bitmap_layout.g] = green_from_colour(colour4);
5140 pos[bitmap_layout.b] = blue_from_colour(colour4);
5141 pos[bitmap_layout.a] = 0xff;
5142 pos += 4;
5143 }
5144 pos[bitmap_layout.r] = red_from_colour(colour3);
5145 pos[bitmap_layout.g] = green_from_colour(colour3);
5146 pos[bitmap_layout.b] = blue_from_colour(colour3);
5147 pos[bitmap_layout.a] = 0xff;
5148 pos += 4;
5149 pos[bitmap_layout.r] = red_from_colour(colour1);
5150 pos[bitmap_layout.g] = green_from_colour(colour1);
5151 pos[bitmap_layout.b] = blue_from_colour(colour1);
5152 pos[bitmap_layout.a] = 0xff;
5153 pos += 4;
5154 for (x = (size - y) * 2; x < size ; x++) {
5155 pos[bitmap_layout.r] = red_from_colour(colour0);
5156 pos[bitmap_layout.g] = green_from_colour(colour0);
5157 pos[bitmap_layout.b] = blue_from_colour(colour0);
5158 pos[bitmap_layout.a] = 0xff;
5159 pos += 4;
5160 }
5161 }
5162
5163 rpos += stride;
5164 }
5165
5166 guit->bitmap->modified(b);
5167
5168 return b;
5169}
5170
5171
5172/**
5173 * Create bitmap copy of another bitmap
5174 *
5175 * \param orig bitmap to copy
5176 * \param size required bitmap size
5177 */
5178static struct bitmap *
5180{
5181 struct bitmap *b = NULL;
5182 unsigned char *data;
5183 unsigned char *orig_data;
5184 size_t stride;
5185
5186 if (orig == NULL)
5187 return NULL;
5188
5189 assert(size == guit->bitmap->get_width(orig));
5190 assert(size == guit->bitmap->get_height(orig));
5191
5192 /* Create the bitmap */
5194 if (b == NULL)
5195 return NULL;
5196
5197 stride = guit->bitmap->get_rowstride(b);
5198 assert(stride == guit->bitmap->get_rowstride(orig));
5199
5200 data = guit->bitmap->get_buffer(b);
5201 orig_data = guit->bitmap->get_buffer(orig);
5202
5203 /* Copy the bitmap */
5204 memcpy(data, orig_data, stride * size);
5205
5206 guit->bitmap->modified(b);
5207
5208 /* We've not modified the original image, but we called
5209 * bitmap_get_buffer(), so we need to pair that with a
5210 * bitmap_modified() call to appease certain front ends. */
5211 guit->bitmap->modified(orig);
5212
5213 return b;
5214}
5215
5216
5217/**
5218 * Create bitmap from rotation of another bitmap
5219 *
5220 * \param orig bitmap to create rotation of
5221 * \param size required bitmap size
5222 */
5223static struct bitmap *
5225{
5226 struct bitmap *b = NULL;
5227 int x, y;
5228 unsigned char *rpos;
5229 unsigned char *pos;
5230 unsigned char *orig_data;
5231 unsigned char *orig_pos;
5232 size_t stride;
5233
5234 if (orig == NULL)
5235 return NULL;
5236
5237 assert(size == guit->bitmap->get_width(orig));
5238 assert(size == guit->bitmap->get_height(orig));
5239
5240 /* Create the bitmap */
5242 if (b == NULL)
5243 return NULL;
5244
5245 stride = guit->bitmap->get_rowstride(b);
5246 assert(stride == guit->bitmap->get_rowstride(orig));
5247
5248 rpos = guit->bitmap->get_buffer(b);
5249 orig_data = guit->bitmap->get_buffer(orig);
5250
5251 /* Copy the rotated bitmap */
5252 for (y = 0; y < size; y++) {
5253 pos = rpos;
5254
5255 for (x = 0; x < size; x++) {
5256 orig_pos = orig_data + x * stride + y * 4;
5257 *(pos++) = *(orig_pos++);
5258 *(pos++) = *(orig_pos++);
5259 *(pos++) = *(orig_pos);
5260 *(pos++) = 0xff;
5261
5262 }
5263
5264 rpos += stride;
5265 }
5266
5267 guit->bitmap->modified(b);
5268
5269 /* We've not modified the original image, but we called
5270 * bitmap_get_buffer(), so we need to pair that with a
5271 * bitmap_modified() call to appease certain front ends.
5272 */
5273 guit->bitmap->modified(orig);
5274
5275 return b;
5276}
5277
5278
5279/**
5280 * Measures width of characters used to represent treeview furniture.
5281 *
5282 * \return NSERROR_OK on success else error code
5283 */
5285{
5286 int size = tree_g.line_height / 2;
5287
5297
5306
5314
5322
5323 if (plot_style_odd.furn[TREE_FURN_EXPAND].bmp == NULL ||
5331 return NSERROR_NOMEM;
5332
5334
5335 return NSERROR_OK;
5336}
5337
5338
5339/* Exported interface, documented in treeview.h */
5341{
5342 long long font_px_size;
5343 long long font_pt_size;
5344 nserror res;
5345
5346 if (tree_g.initialised > 0) {
5348 return NSERROR_OK;
5349 }
5350
5351 NSLOG(netsurf, INFO, "Initialising treeview module");
5352
5353 font_pt_size = nsoption_int(treeview_font_size);
5354 if (font_pt_size <= 0) {
5355 font_pt_size = 11 * 10;
5356 }
5357
5358 font_px_size = (font_pt_size * FIXTOINT(nscss_screen_dpi) /
5359 10 + 36) / 72;
5360 tree_g.line_height = (font_px_size * 8 + 3) / 6;
5361
5362 res = treeview_init_plot_styles(font_pt_size * PLOT_STYLE_SCALE / 10);
5363 if (res != NSERROR_OK) {
5364 return res;
5365 }
5366
5368
5370 if (res != NSERROR_OK) {
5371 return res;
5372 }
5373
5376 tree_g.icon_size = 17;
5377 tree_g.icon_step = 23;
5378 tree_g.move_offset = 18;
5379
5381
5382 NSLOG(netsurf, INFO, "Initialised treeview module");
5383
5384 return NSERROR_OK;
5385}
5386
5387
5388/* Exported interface, documented in treeview.h */
5390{
5391 int i;
5392
5393 if (tree_g.initialised > 1) {
5395 return NSERROR_OK;
5396
5397 } else if (tree_g.initialised == 0) {
5398 NSLOG(netsurf, INFO,
5399 "Warning: tried to finalise uninitialised treeview module");
5400 return NSERROR_OK;
5401 }
5402
5403 NSLOG(netsurf, INFO, "Finalising treeview module");
5404
5405 for (i = 0; i < TREE_RES_LAST; i++) {
5407 }
5408
5417
5419
5420 NSLOG(netsurf, INFO, "Finalised treeview module");
5421
5422 return NSERROR_OK;
5423}
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(struct core_window *cw_h, const struct rect *r)
Scroll a core window to make the given rectangle visible.
Definition: cw_helper.c:35
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
nserror treeview_create(treeview **treeout, const struct treeview_callback_table *callbacks, int n_fields, struct treeview_field_desc fields[], struct core_window *cw, treeview_flags flags)
Create a treeview.
Definition: treeview.c:2024
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:2149
nserror treeview_cw_attach(treeview *tree, struct core_window *cw)
Attach a treeview to a corewindow.
Definition: treeview.c:2134
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:389
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:1135
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:5040
static void treeview_textarea_search_callback(void *data, struct textarea_msg *msg)
Callback for textarea_create, in desktop/treeview.h.
Definition: treeview.c:992
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:441
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:1767
static nserror treeview_walk_fwd_cb(treeview_node *n, void *ctx, bool *skip_children, bool *end)
Treewalk node enter callback.
Definition: treeview.c:1500
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:404
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:5224
nserror treeview_contract(treeview *tree, bool all)
Contract a treeview's nodes.
Definition: treeview.c:2436
static bool treeview_unlink_node(treeview_node *n)
Unlink a treeview node.
Definition: treeview.c:1570
nserror treeview_delete_node(treeview *tree, treeview_node *n, treeview_node_options_flags flags)
Delete a treeview node.
Definition: treeview.c:1926
static nserror treeview__search(treeview *tree, const char *text, unsigned int len)
Search treeview for text.
Definition: treeview.c:868
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:5389
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:639
@ TREEVIEW_WALK_MODE_LOGICAL_EXPANDED
Walk to expanded nodes in the (sub)tree only.
Definition: treeview.c:649
@ TREEVIEW_WALK_MODE_DISPLAY
Walk displayed nodes.
Definition: treeview.c:656
@ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE
Walk to all nodes in the (sub)tree.
Definition: treeview.c:643
static void treeview__redraw_from_node(const treeview *tree, const treeview_node *node)
Redraw tree from given node to the bottom.
Definition: treeview.c:618
static nserror treeview_init_plot_styles(int font_pt_size)
Initialise the plot styles from CSS system colour values.
Definition: treeview.c:4958
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:1044
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:339
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:1988
static struct treeview_resource treeview_res[TREE_RES_LAST]
Treeview content resources.
Definition: treeview.c:324
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:1316
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:565
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:1200
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:594
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:673
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:812
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:1536
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:353
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:926
struct treeview_node_style plot_style_even
Plot style for even rows.
Definition: treeview.c:294
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:311
@ TREE_RES_FOLDER_SPECIAL
Definition: treeview.c:315
@ TREE_RES_SEARCH
Definition: treeview.c:316
@ TREE_RES_ARROW
Definition: treeview.c:312
@ TREE_RES_CONTENT
Definition: treeview.c:313
@ TREE_RES_FOLDER
Definition: treeview.c:314
@ TREE_RES_LAST
Definition: treeview.c:317
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:457
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:1603
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:5179
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:5340
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:476
static nserror treeview_delete_empty_nodes(treeview *tree, bool interaction)
Delete any empty treeview folder nodes.
Definition: treeview.c:1832
static treeview_node * treeview_y_node(treeview *tree, int target_y)
Find node at given y-position.
Definition: treeview.c:534
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:1390
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:963
static void treeview_edit_done(treeview *tree)
Complete a treeview edit.
Definition: treeview.c:1635
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:5016
static nserror treeview_create_node_root(treeview_node **root)
Create treeview's root node.
Definition: treeview.c:1070
static void treeview__cw_full_redraw(const struct treeview *tree)
Corewindow callback wrapper: Request a full redraw of the window.
Definition: treeview.c:368
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:5284
treeview_furniture_id
Treeview furniture states.
Definition: treeview.c:258
@ TREE_FURN_CONTRACT
Definition: treeview.c:260
@ TREE_FURN_EXPAND
Definition: treeview.c:259
@ TREE_FURN_LAST
Definition: treeview.c:261
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:288
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:1522
static nserror treeview_delete_node_walk_cb(treeview_node *n, void *ctx, bool *end)
Treewalk node callback deleting nodes.
Definition: treeview.c:1705
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:1268
static struct bitmap * treeview_generate_triangle_bitmap(colour bg, colour fg, int size)
Create a right-pointing anti-aliased triangle bitmap.
Definition: treeview.c:5068
static treeview_node * treeview_node_next(treeview_node *node, bool full)
Find the next node in depth first tree order.
Definition: treeview.c:498
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:1113
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:344
@ TREE_MSG_NODE_EDIT
Node to be edited.
Definition: treeview.h:87
@ TREE_MSG_NODE_LAUNCH
Node to be launched.
Definition: treeview.h:88
@ TREE_MSG_NODE_DELETE
Node to be deleted.
Definition: treeview.h:86
treeview_node_type
treeview node type
Definition: treeview.h:43
@ TREE_NODE_ENTRY
Node is an entry.
Definition: treeview.h:47
@ TREE_NODE_NONE
No node
Definition: treeview.h:44
@ TREE_NODE_FOLDER
Node is folder.
Definition: treeview.h:46
@ TREE_NODE_ROOT
Node is treeview's root.
Definition: treeview.h:45
treeview_node_options_flags
Node change handling options.
Definition: treeview.h:63
@ TREE_OPTION_NONE
Definition: treeview.h:64
@ TREE_OPTION_SUPPRESS_RESIZE
Definition: treeview.h:66
@ TREE_OPTION_SPECIAL_DIR
Definition: treeview.h:65
@ TREE_OPTION_SUPPRESS_REDRAW
Definition: treeview.h:67
treeview_field_flags
treeview field flags
Definition: treeview.h:115
@ TREE_FLAG_SEARCHABLE
Whether field is searchable.
Definition: treeview.h:121
@ TREE_FLAG_SHOW_NAME
Whether field name shown.
Definition: treeview.h:119
@ TREE_FLAG_COPY_TEXT
Whether to copy to clipb.
Definition: treeview.h:120
@ TREE_FLAG_ALLOW_EDIT
Whether allow edit field.
Definition: treeview.h:117
@ TREE_FLAG_DEFAULT
Whether field is default.
Definition: treeview.h:118
treeview_relationship
Relationship between nodes.
Definition: treeview.h:54
@ TREE_REL_FIRST_CHILD
Definition: treeview.h:55
@ TREE_REL_NEXT_SIBLING
Definition: treeview.h:56
treeview_flags
treeview control flags
Definition: treeview.h:73
@ TREEVIEW_NO_DELETES
No node deletes.
Definition: treeview.h:76
@ TREEVIEW_DEL_EMPTY_DIRS
Delete dirs on empty.
Definition: treeview.h:78
@ TREEVIEW_SEARCHABLE
Treeview has search bar.
Definition: treeview.h:79
@ TREEVIEW_NO_MOVES
No node drags.
Definition: treeview.h:75
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
struct netsurf_table * guit
The global interface table.
Definition: gui_factory.c:50
Interface to core interface table.
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
Definition: hlcache.c:736
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:675
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:1167
Interface to platform-specific layout operation table.
browser_mouse_state
Mouse state: 1 is primary mouse button.
Definition: mouse.h:52
@ BROWSER_MOUSE_PRESS_1
primary button pressed
Definition: mouse.h:59
@ BROWSER_MOUSE_CLICK_2
button 2 clicked.
Definition: mouse.h:72
@ BROWSER_MOUSE_PRESS_2
auxillary button pressed
Definition: mouse.h:61
@ BROWSER_MOUSE_HOVER
No mouse buttons pressed, May be used to indicate hover or end of drag.
Definition: mouse.h:56
@ BROWSER_MOUSE_CLICK_1
button 1 clicked.
Definition: mouse.h:70
@ BROWSER_MOUSE_MOD_2
2nd modifier key pressed (eg.
Definition: mouse.h:101
@ BROWSER_MOUSE_DOUBLE_CLICK
button double clicked
Definition: mouse.h:81
@ BROWSER_MOUSE_MOD_3
3rd modifier key pressed (eg.
Definition: mouse.h:103
@ BROWSER_MOUSE_MOD_1
1st modifier key pressed (eg.
Definition: mouse.h:99
@ BROWSER_MOUSE_DRAG_1
start of button 1 drag
Definition: mouse.h:86
@ BROWSER_MOUSE_LEAVE
pointer leaving window
Definition: mouse.h:108
@ BROWSER_MOUSE_DRAG_2
start of button 2 drag
Definition: mouse.h:88
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:161
int height
Definition: gui.c:162
static BList * callbacks
List of all callbacks.
Definition: schedule.cpp:45
Interface to utility string handling.
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
colour bg
Definition: bitmap.c:84
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
nserror(* set_extent)(struct core_window *cw, int width, int height)
Update the logical extent of the window.
Definition: core_window.h:81
nserror(* get_dimensions)(const struct core_window *cw, int *width, int *height)
Get window viewport dimensions.
Definition: core_window.h:115
nserror(* drag_status)(struct core_window *cw, core_window_drag_status ds)
Inform corewindow owner of drag status.
Definition: core_window.h:125
nserror(* invalidate)(struct core_window *cw, const struct rect *rect)
Invalidate an area of a window.
Definition: core_window.h:71
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:87
struct core_window_table * corewindow
Core window table.
Definition: gui_table.h:75
struct gui_bitmap_table * bitmap
Bitmap table.
Definition: gui_table.h:153
struct gui_layout_table * layout
Layout table.
Definition: gui_table.h:163
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:340
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:290
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:269
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:147
nserror(* folder)(struct treeview_node_msg msg, void *data)
Definition: treeview.h:148
nserror(* entry)(struct treeview_node_msg msg, void *data)
Definition: treeview.h:149
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:137
const char * value
Field value.
Definition: treeview.h:139
lwc_string * field
Field name.
Definition: treeview.h:138
size_t value_len
Field value length (bytes)
Definition: treeview.h:140
Treeview field description.
Definition: treeview.h:128
enum treeview_field_flags flags
Flags for field.
Definition: treeview.h:130
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:1694
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:95
browser_mouse_state mouse
Definition: treeview.h:106
enum treeview_msg msg
The message type.
Definition: treeview.h:96
style for a node
Definition: treeview.c:268
plot_font_style_t sitext
Selected entry field text.
Definition: treeview.c:275
struct treeview_node_style::@86 furn[TREE_FURN_LAST]
plot_style_t bg
Background.
Definition: treeview.c:269
plot_font_style_t itext
Entry field text.
Definition: treeview.c:271
plot_font_style_t text
Text.
Definition: treeview.c:270
struct bitmap * bmp
Definition: treeview.c:279
plot_style_t sbg
Selected background.
Definition: treeview.c:273
struct bitmap * sel
Definition: treeview.c:280
plot_font_style_t stext
Selected text.
Definition: treeview.c:274
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:300
const char * url
Definition: treeview.c:301
struct hlcache_handle * c
Definition: treeview.c:302
Data used when doing a treeview walk for search.
Definition: treeview.c:795
const char * text
The string being searched for.
Definition: treeview.c:797
const unsigned int len
Length of string being searched for.
Definition: treeview.c:798
treeview * tree
The treeview to search.
Definition: treeview.c:796
int window_height
Accumulate height for matching entries.
Definition: treeview.c:799
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:1484
enum treeview_node_type type
Definition: treeview.c:1487
treeview_walk_cb leave_cb
Definition: treeview.c:1485
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
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:251
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:317
Interface to a number of general purpose functionality.
#define FLEX_ARRAY_LEN_DECL
Definition: utils.h:70
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