Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/ec4b9a5dd008785e6498dcefb025f6234965f529
...commit
http://git.netsurf-browser.org/netsurf.git/commit/ec4b9a5dd008785e6498dcefb025f6234965f529
...tree
http://git.netsurf-browser.org/netsurf.git/tree/ec4b9a5dd008785e6498dcefb025f6234965f529
The branch, master has been updated
via ec4b9a5dd008785e6498dcefb025f6234965f529 (commit)
via 9b0a3cc35ed482b31d35c3ad804c7a2fc48d190f (commit)
via e8b9678d3e4ccecad44724878fb5cfd162fd48af (commit)
via fae758f5a98a0e382a25044259eb2b2ae7e70e53 (commit)
via bfdabbf4781ab14c9586f8d4e99839f5c567125a (commit)
via fb5344df09494427dc719a0c24ae56f9f1f924dc (commit)
via 88c9a2e12de078103b78d58f9da0c7e0f3141470 (commit)
via 4e224135ec13ca0c7a115e6c7fadb5e4a88749a8 (commit)
via 39ab8b623397784dddc7f63cab4dcc5519ea4ba6 (commit)
via 2a294adfb179f8209f074e6ff810b0526c6dd4fb (commit)
via 4d842226546bf1abb84dbdce798d99490845d200 (commit)
via f211b6c89aabb1174bf5f1966f91c5d883245fd2 (commit)
via 89dd127a80951dcc7105c04d0e207c1561c5d8bf (commit)
via 283fb3633938971d04b2bf8f2b690ce9c8a83951 (commit)
via f142b3684cd98ace5271c0a72600761585cdfa58 (commit)
via 45a7e6269b2328de9178af76ff4aed41c2e69129 (commit)
via 0a0ad71bdb181bb309ba86d283704ba7b0e89dc1 (commit)
via db6b3441c412cdc2e6eb197f9601056c2c85dcf8 (commit)
from 0a6e8fc0b072da21c7ec9c8d602b7ffad6bd4100 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=ec4b9a5dd008785e6498dcefb025f6234965f529
commit ec4b9a5dd008785e6498dcefb025f6234965f529
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Hotlist (bookmarks): Include the URL field in search.
diff --git a/desktop/hotlist.c b/desktop/hotlist.c
index 79fc286..4bdd7c8 100644
--- a/desktop/hotlist.c
+++ b/desktop/hotlist.c
@@ -1198,8 +1198,10 @@ static nserror hotlist_initialise_entry_fields(void)
goto error;
}
- hl_ctx.fields[HL_URL].flags = TREE_FLAG_ALLOW_EDIT |
- TREE_FLAG_COPY_TEXT;
+ hl_ctx.fields[HL_URL].flags =
+ TREE_FLAG_ALLOW_EDIT |
+ TREE_FLAG_COPY_TEXT |
+ TREE_FLAG_SEARCHABLE;
label = "TreeviewLabelURL";
label = messages_get(label);
if (lwc_intern_string(label, strlen(label),
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=9b0a3cc35ed482b31d35c3ad804c7a2fc48d190f
commit 9b0a3cc35ed482b31d35c3ad804c7a2fc48d190f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Global history: Flag the URL field as searchable, as well.
diff --git a/desktop/global_history.c b/desktop/global_history.c
index 3a06b31..ad39a3e 100644
--- a/desktop/global_history.c
+++ b/desktop/global_history.c
@@ -536,7 +536,9 @@ static nserror global_history_initialise_entry_fields(void)
goto error;
}
- gh_ctx.fields[GH_URL].flags = TREE_FLAG_COPY_TEXT;
+ gh_ctx.fields[GH_URL].flags =
+ TREE_FLAG_COPY_TEXT |
+ TREE_FLAG_SEARCHABLE;
label = "TreeviewLabelURL";
label = messages_get(label);
if (lwc_intern_string(label, strlen(label),
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=e8b9678d3e4ccecad44724878fb5cfd162fd48af
commit e8b9678d3e4ccecad44724878fb5cfd162fd48af
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Cookie manager: Flag the domain field as searchable; more use than name.
diff --git a/desktop/cookie_manager.c b/desktop/cookie_manager.c
index d27a8d6..a2aab8e 100644
--- a/desktop/cookie_manager.c
+++ b/desktop/cookie_manager.c
@@ -576,7 +576,9 @@ static nserror cookie_manager_init_entry_fields(void)
goto error;
}
- cm_ctx.fields[COOKIE_M_DOMAIN].flags = TREE_FLAG_SHOW_NAME;
+ cm_ctx.fields[COOKIE_M_DOMAIN].flags =
+ TREE_FLAG_SHOW_NAME |
+ TREE_FLAG_SEARCHABLE;
label = "TreeviewLabelDomain";
label = messages_get(label);
if (lwc_intern_string(label, strlen(label),
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=fae758f5a98a0e382a25044259eb2b2ae7e70e53
commit fae758f5a98a0e382a25044259eb2b2ae7e70e53
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Avoid searching empty treeview.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index d820d15..4841db9 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -806,6 +806,10 @@ static nserror treeview__search(
assert(text[len] == '\0');
+ if (tree->root == NULL) {
+ return NSERROR_OK;
+ }
+
err = treeview_walk_internal(tree, tree->root,
TREEVIEW_WALK_MODE_LOGICAL_COMPLETE, NULL,
treeview__search_walk_cb, &sw);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=bfdabbf4781ab14c9586f8d4e99839f5c567125a
commit bfdabbf4781ab14c9586f8d4e99839f5c567125a
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Cookie manager: Enable search feature.
diff --git a/desktop/cookie_manager.c b/desktop/cookie_manager.c
index 987a85c..d27a8d6 100644
--- a/desktop/cookie_manager.c
+++ b/desktop/cookie_manager.c
@@ -809,7 +809,9 @@ nserror cookie_manager_init(struct
core_window_callback_table *cw_t,
err = treeview_create(&cm_ctx.tree, &cm_tree_cb_t,
COOKIE_M_N_FIELDS, cm_ctx.fields,
cw_t, core_window_handle,
- TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS);
+ TREEVIEW_NO_MOVES |
+ TREEVIEW_DEL_EMPTY_DIRS |
+ TREEVIEW_SEARCHABLE);
if (err != NSERROR_OK) {
cm_ctx.tree = NULL;
return err;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=fb5344df09494427dc719a0c24ae56f9f1f924dc
commit fb5344df09494427dc719a0c24ae56f9f1f924dc
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Hotlist (bookmarks): Enable search feature.
diff --git a/desktop/hotlist.c b/desktop/hotlist.c
index 13a52d0..79fc286 100644
--- a/desktop/hotlist.c
+++ b/desktop/hotlist.c
@@ -1313,7 +1313,7 @@ nserror hotlist_init(
/* Create the hotlist treeview */
err = treeview_create(&hl_ctx.tree, &hl_tree_cb_t,
HL_N_FIELDS, hl_ctx.fields, NULL, NULL,
- TREEVIEW_NO_FLAGS);
+ TREEVIEW_SEARCHABLE);
if (err != NSERROR_OK) {
free(hl_ctx.save_path);
hl_ctx.tree = NULL;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=88c9a2e12de078103b78d58f9da0c7e0f3141470
commit 88c9a2e12de078103b78d58f9da0c7e0f3141470
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Global history: Enable search feature.
diff --git a/desktop/global_history.c b/desktop/global_history.c
index e699321..3a06b31 100644
--- a/desktop/global_history.c
+++ b/desktop/global_history.c
@@ -752,7 +752,8 @@ nserror global_history_init(struct
core_window_callback_table *cw_t,
err = treeview_create(&gh_ctx.tree, &gh_tree_cb_t,
N_FIELDS, gh_ctx.fields,
cw_t, core_window_handle,
- TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS);
+ TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS |
+ TREEVIEW_SEARCHABLE);
if (err != NSERROR_OK) {
gh_ctx.tree = NULL;
return err;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=4e224135ec13ca0c7a115e6c7fadb5e4a88749a8
commit 4e224135ec13ca0c7a115e6c7fadb5e4a88749a8
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Handle node expansion on switch between search and normal view.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index b2cd421..d820d15 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -824,7 +824,7 @@ static nserror treeview__search(
r.y1 = ((height > prev_height) ? height : prev_height) + search_height;
treeview__cw_invalidate_area(tree, &r);
- treeview__cw_update_size(tree, -1, height + search_height);
+ treeview__cw_update_size(tree, -1, height);
treeview__cw_scroll_top(tree);
return NSERROR_OK;
@@ -843,7 +843,7 @@ static void treeview_textarea_search_callback(void *data,
treeview *tree = data;
struct rect *r;
- if (tree->search.active == false) {
+ if (tree->search.active == false || tree->root == NULL) {
return;
}
@@ -2064,7 +2064,6 @@ treeview_node_expand_internal(treeview *tree,
treeview_node *node)
}
do {
- assert((child->flags & TV_NFLAGS_EXPANDED) == false);
if (child->text.width == 0) {
guit->layout->width(&plot_style_odd.text,
child->text.data,
@@ -2109,17 +2108,21 @@ treeview_node_expand_internal(treeview *tree,
treeview_node *node)
/* Update the node */
node->flags |= TV_NFLAGS_EXPANDED;
- /* And parent's heights */
- do {
- node->height += additional_height;
- node = node->parent;
- } while (node->parent != NULL);
+ /* And node heights */
+ for (struct treeview_node *n = node;
+ (n != NULL) && (n->flags & TV_NFLAGS_EXPANDED);
+ n = n->parent) {
+ n->height += additional_height;
+ }
- node->height += additional_height;
+ if (tree->search.search) {
+ tree->search.height += additional_height;
+ }
/* Inform front end of change in dimensions */
if (additional_height != 0) {
- treeview__cw_update_size(tree, -1, tree->root->height);
+ treeview__cw_update_size(tree, -1,
+ treeview__get_display_height(tree));
}
return NSERROR_OK;
@@ -2138,7 +2141,7 @@ nserror treeview_node_expand(treeview *tree,
treeview_node *node)
r.x0 = 0;
r.y0 = treeview_node_y(tree, node);
r.x1 = REDRAW_MAX;
- r.y1 = tree->root->height;
+ r.y1 = treeview__get_display_height(tree);
treeview__cw_invalidate_area(tree, &r);
}
@@ -2151,6 +2154,7 @@ nserror treeview_node_expand(treeview *tree,
treeview_node *node)
* context for treeview contraction callback
*/
struct treeview_contract_data {
+ treeview *tree;
bool only_entries;
};
@@ -2179,15 +2183,20 @@ static nserror treeview_node_contract_cb(treeview_node
*n, void *ctx, bool *end)
return NSERROR_OK;
}
- n->flags ^= TV_NFLAGS_EXPANDED;
h_reduction = n->height - tree_g.line_height;
assert(h_reduction >= 0);
+ for (struct treeview_node *node = n;
+ (node != NULL) && (node->flags & TV_NFLAGS_EXPANDED);
+ node = node->parent) {
+ node->height -= h_reduction;
+ }
- do {
- n->height -= h_reduction;
- n = n->parent;
- } while (n != NULL);
+ if (data->tree->search.search) {
+ data->tree->search.height -= h_reduction;
+ }
+
+ n->flags ^= TV_NFLAGS_EXPANDED;
return NSERROR_OK;
}
@@ -2213,6 +2222,7 @@ treeview_node_contract_internal(treeview *tree,
treeview_node *node)
return NSERROR_OK;
}
+ data.tree = tree;
data.only_entries = false;
selected = node->flags & TV_NFLAGS_SELECTED;
@@ -2227,7 +2237,7 @@ treeview_node_contract_internal(treeview *tree,
treeview_node *node)
node->flags |= TV_NFLAGS_SELECTED;
/* Inform front end of change in dimensions */
- treeview__cw_update_size(tree, -1, tree->root->height);
+ treeview__cw_update_size(tree, -1, treeview__get_display_height(tree));
return NSERROR_OK;
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=39ab8b623397784dddc7f63cab4dcc5519ea4ba6
commit 39ab8b623397784dddc7f63cab4dcc5519ea4ba6
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Update search filtered display on treeview changes.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index d2cb2db..b2cd421 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -709,6 +709,206 @@ static nserror treeview_walk_internal(
/**
+ * Data used when doing a treeview walk for search.
+ */
+struct treeview_search_walk_data {
+ treeview *tree; /**< The treeview to search. */
+ const char *text; /**< The string being searched for. */
+ const unsigned int len; /**< Length of string being searched for. */
+ int window_height; /**< Accumulate height for matching entries. */
+};
+
+
+/**
+ * Treewalk node callback for handling search.
+ *
+ * \param[in] n Current node.
+ * \param[in] ctx Treeview search context.
+ * \param[in,out] skip_children Flag to allow children to be skipped.
+ * \param[in,out] end Flag to allow iteration to be finished early.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror treeview__search_walk_cb(
+ treeview_node *n,
+ void *ctx,
+ bool *skip_children,
+ bool *end)
+{
+ struct treeview_search_walk_data *sw = ctx;
+
+ if (n->type != TREE_NODE_ENTRY) {
+ return NSERROR_OK;
+ }
+
+ if (sw->len == 0) {
+ n->flags &= ~TV_NFLAGS_MATCHED;
+ } else {
+ struct treeview_node_entry *entry =
+ (struct treeview_node_entry *)n;
+ bool matched = false;
+
+ for (int i = 0; i < sw->tree->n_fields; i++) {
+ struct treeview_field *ef = &(sw->tree->fields[i + 1]);
+ if (ef->flags & TREE_FLAG_SEARCHABLE) {
+ if (strcasestr(entry->fields[i].value.data,
+ sw->text) != NULL) {
+ matched = true;
+ break;
+ }
+ }
+ }
+
+ if (!matched && strcasestr(n->text.data, sw->text) != NULL) {
+ matched = true;
+ }
+
+ if (matched) {
+ n->flags |= TV_NFLAGS_MATCHED;
+ sw->window_height += n->height;
+ } else {
+ n->flags &= ~TV_NFLAGS_MATCHED;
+ }
+ }
+
+ return NSERROR_OK;
+}
+
+
+/**
+ * Search treeview for text.
+ *
+ * \param[in] tree Treeview to search.
+ * \param[in] text UTF-8 string to search for. (NULL-terminated.)
+ * \param[in] len Byte length of UTF-8 string.
+ * \return NSERROR_OK on success, appropriate error otherwise.
+ */
+static nserror treeview__search(
+ treeview *tree,
+ const char *text,
+ unsigned int len)
+{
+ nserror err;
+ uint32_t height;
+ uint32_t prev_height = treeview__get_display_height(tree);
+ int search_height = (tree->flags & TREEVIEW_SEARCHABLE) ?
+ tree_g.line_height : 0;
+ struct treeview_search_walk_data sw = {
+ .len = len,
+ .text = text,
+ .tree = tree,
+ .window_height = 0,
+ };
+ struct rect r = {
+ .x0 = 0,
+ .y0 = search_height,
+ .x1 = REDRAW_MAX,
+ };
+
+ assert(text[len] == '\0');
+
+ err = treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE, NULL,
+ treeview__search_walk_cb, &sw);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ if (len > 0) {
+ tree->search.height = sw.window_height;
+ tree->search.search = true;
+ height = sw.window_height;
+ } else {
+ tree->search.search = false;
+ height = tree->root->height;
+ }
+
+ r.y1 = ((height > prev_height) ? height : prev_height) + search_height;
+ treeview__cw_invalidate_area(tree, &r);
+ treeview__cw_update_size(tree, -1, height + search_height);
+ treeview__cw_scroll_top(tree);
+
+ return NSERROR_OK;
+}
+
+
+/**
+ * Callback for textarea_create, in desktop/treeview.h
+ *
+ * \param data treeview context
+ * \param msg textarea message
+ */
+static void treeview_textarea_search_callback(void *data,
+ struct textarea_msg *msg)
+{
+ treeview *tree = data;
+ struct rect *r;
+
+ if (tree->search.active == false) {
+ return;
+ }
+
+ switch (msg->type) {
+ case TEXTAREA_MSG_DRAG_REPORT:
+ if (msg->data.drag == TEXTAREA_DRAG_NONE) {
+ /* Textarea drag finished */
+ tree->drag.type = TV_DRAG_NONE;
+ } else {
+ /* Textarea drag started */
+ tree->drag.type = TV_DRAG_SEARCH;
+ }
+ treeview__cw_drag_status(tree, tree->drag.type);
+ break;
+
+ case TEXTAREA_MSG_REDRAW_REQUEST:
+ r = &msg->data.redraw;
+ r->x0 += tree_g.window_padding + tree_g.icon_size;
+ r->y0 += 0;
+ r->x1 += 600;
+ r->y1 += tree_g.line_height;
+
+ /* Redraw the textarea */
+ treeview__cw_invalidate_area(tree, r);
+ break;
+
+ case TEXTAREA_MSG_TEXT_MODIFIED:
+ /* Textarea length includes trailing NULL, so subtract it. */
+ treeview__search(tree,
+ msg->data.modified.text,
+ msg->data.modified.len - 1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/**
+ * Update the layout for any active search.
+ *
+ * \param[in] tree The tree to update.
+ */
+static void treeview__search_update_display(
+ treeview *tree)
+{
+ const char *string;
+ unsigned int len;
+
+ if (tree->search.search == false) {
+ /* No active search to update view for. */
+ return;
+ }
+
+ string = textarea_data(tree->search.textarea, &len);
+ if (string == NULL || len == 0) {
+ return;
+ }
+
+ treeview__search(tree, string, len - 1);
+}
+
+
+/**
* Create treeview's root node
*
* \param[out] root Returns root node
@@ -1016,6 +1216,8 @@ treeview_update_node_entry(treeview *tree,
}
}
+ treeview__search_update_display(tree);
+
/* Redraw */
if (entry->parent->flags & TV_NFLAGS_EXPANDED) {
struct rect r;
@@ -1114,6 +1316,8 @@ treeview_create_node_entry(treeview *tree,
}
}
+ treeview__search_update_display(tree);
+
*entry = n;
return NSERROR_OK;
@@ -1455,6 +1659,8 @@ treeview_delete_node_internal(treeview *tree,
tree->root->height);
}
+ treeview__search_update_display(tree);
+
return NSERROR_OK;
}
@@ -1660,181 +1866,6 @@ static struct textarea *treeview__create_textarea(
}
-/**
- * Data used when doing a treeview walk for search.
- */
-struct treeview_search_walk_data {
- treeview *tree; /**< The treeview to search. */
- const char *text; /**< The string being searched for. */
- const unsigned int len; /**< Length of string being searched for. */
- int window_height; /**< Accumulate height for matching entries. */
-};
-
-
-/**
- * Treewalk node callback for handling search.
- *
- * \param[in] n Current node.
- * \param[in] ctx Treeview search context.
- * \param[in,out] skip_children Flag to allow children to be skipped.
- * \param[in,out] end Flag to allow iteration to be finished early.
- * \return NSERROR_OK on success else error code.
- */
-static nserror treeview__search_walk_cb(
- treeview_node *n,
- void *ctx,
- bool *skip_children,
- bool *end)
-{
- struct treeview_search_walk_data *sw = ctx;
-
- if (n->type != TREE_NODE_ENTRY) {
- return NSERROR_OK;
- }
-
- if (sw->len == 0) {
- n->flags &= ~TV_NFLAGS_MATCHED;
- } else {
- struct treeview_node_entry *entry =
- (struct treeview_node_entry *)n;
- bool matched = false;
-
- for (int i = 0; i < sw->tree->n_fields; i++) {
- struct treeview_field *ef = &(sw->tree->fields[i + 1]);
- if (ef->flags & TREE_FLAG_SEARCHABLE) {
- if (strcasestr(entry->fields[i].value.data,
- sw->text) != NULL) {
- matched = true;
- break;
- }
- }
- }
-
- if (!matched && strcasestr(n->text.data, sw->text) != NULL) {
- matched = true;
- }
-
- if (matched) {
- n->flags |= TV_NFLAGS_MATCHED;
- sw->window_height += n->height;
- } else {
- n->flags &= ~TV_NFLAGS_MATCHED;
- }
- }
-
- return NSERROR_OK;
-}
-
-
-/**
- * Search treeview for text.
- *
- * \param[in] tree Treeview to search.
- * \param[in] text UTF-8 string to search for. (NULL-terminated.)
- * \param[in] len Byte length of UTF-8 string.
- * \return NSERROR_OK on success, appropriate error otherwise.
- */
-static nserror treeview__search(
- treeview *tree,
- const char *text,
- unsigned int len)
-{
- nserror err;
- uint32_t height;
- uint32_t prev_height = treeview__get_display_height(tree);
- int search_height = (tree->flags & TREEVIEW_SEARCHABLE) ?
- tree_g.line_height : 0;
- struct treeview_search_walk_data sw = {
- .len = len,
- .text = text,
- .tree = tree,
- .window_height = 0,
- };
- struct rect r = {
- .x0 = 0,
- .y0 = search_height,
- .x1 = REDRAW_MAX,
- };
-
- assert(text[len] == '\0');
-
- err = treeview_walk_internal(tree, tree->root,
- TREEVIEW_WALK_MODE_LOGICAL_COMPLETE, NULL,
- treeview__search_walk_cb, &sw);
- if (err != NSERROR_OK) {
- return err;
- }
-
- if (len > 0) {
- tree->search.height = sw.window_height;
- tree->search.search = true;
- height = sw.window_height;
- } else {
- tree->search.search = false;
- height = tree->root->height;
- }
-
- r.y1 = ((height > prev_height) ? height : prev_height) + search_height;
- treeview__cw_invalidate_area(tree, &r);
- treeview__cw_update_size(tree, -1, height + search_height);
- treeview__cw_scroll_top(tree);
-
- return NSERROR_OK;
-}
-
-
-/**
- * Callback for textarea_create, in desktop/treeview.h
- *
- * \param data treeview context
- * \param msg textarea message
- */
-static void treeview_textarea_search_callback(void *data,
- struct textarea_msg *msg)
-{
- treeview *tree = data;
- struct rect *r;
-
- if (tree->search.active == false) {
- return;
- }
-
- switch (msg->type) {
- case TEXTAREA_MSG_DRAG_REPORT:
- if (msg->data.drag == TEXTAREA_DRAG_NONE) {
- /* Textarea drag finished */
- tree->drag.type = TV_DRAG_NONE;
- } else {
- /* Textarea drag started */
- tree->drag.type = TV_DRAG_SEARCH;
- }
- treeview__cw_drag_status(tree, tree->drag.type);
- break;
-
- case TEXTAREA_MSG_REDRAW_REQUEST:
- r = &msg->data.redraw;
- r->x0 += tree_g.window_padding + tree_g.icon_size;
- r->y0 += 0;
- r->x1 += 600;
- r->y1 += tree_g.line_height;
-
- /* Redraw the textarea */
- treeview__cw_invalidate_area(tree, r);
- break;
-
- case TEXTAREA_MSG_TEXT_MODIFIED:
- /* Textarea length includes trailing NULL, so subtract it. */
- treeview__search(tree,
- msg->data.modified.text,
- msg->data.modified.len - 1);
- break;
-
- default:
- break;
- }
-}
-
-
/* Exported interface, documented in treeview.h */
nserror
treeview_create(treeview **tree,
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=2a294adfb179f8209f074e6ff810b0526c6dd4fb
commit 2a294adfb179f8209f074e6ff810b0526c6dd4fb
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Textarea: Add API to access current textarea contents.
diff --git a/desktop/textarea.c b/desktop/textarea.c
index 1cbb767..3fb18e1 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -2074,6 +2074,17 @@ int textarea_get_text(struct textarea *ta, char *buf,
unsigned int len)
/* exported interface, documented in textarea.h */
+const char * textarea_data(struct textarea *ta, unsigned int *len)
+{
+ if (len != NULL) {
+ *len = ta->text.len;
+ }
+
+ return ta->text.data;
+}
+
+
+/* exported interface, documented in textarea.h */
bool textarea_set_caret(struct textarea *ta, int caret)
{
int b_off;
diff --git a/desktop/textarea.h b/desktop/textarea.h
index 8986097..b386e50 100644
--- a/desktop/textarea.h
+++ b/desktop/textarea.h
@@ -213,6 +213,16 @@ int textarea_get_text(struct textarea *ta, char *buf,
unsigned int len);
/**
+ * Access text data in a text area
+ *
+ * \param[in] ta Text area
+ * \param[out] len Returns byte length of returned text, if passed non-NULL.
+ * \return textarea string data.
+ */
+const char * textarea_data(struct textarea *ta, unsigned int *len);
+
+
+/**
* Set the caret's position
*
* \param ta Text area
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=4d842226546bf1abb84dbdce798d99490845d200
commit 4d842226546bf1abb84dbdce798d99490845d200
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Update search bar display when it loses focus.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 8021782..d2cb2db 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -4527,7 +4527,11 @@ treeview_mouse_action(treeview *tree,
browser_mouse_state mouse, int x, int y)
tree->search.active = false;
textarea_set_caret(tree->search.textarea, -1);
- return;
+ r.x0 = 0;
+ r.y0 = 0;
+ r.x1 = REDRAW_MAX;
+ r.y1 = tree_g.line_height;
+ treeview__cw_invalidate_area(tree, &r);
}
/* Handle textarea related mouse action */
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=f211b6c89aabb1174bf5f1966f91c5d883245fd2
commit f211b6c89aabb1174bf5f1966f91c5d883245fd2
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Only let search textarea consume mouse if not dragging.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 717c90c..8021782 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -4509,7 +4509,9 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
textarea_mouse_action(tree->edit.textarea, mouse,
x - tree->edit.x, y - tree->edit.y);
return;
- } else if (tree->drag.type == TV_DRAG_SEARCH || y < search_height) {
+ } else if (tree->drag.type == TV_DRAG_SEARCH ||
+ (y < search_height &&
+ tree->drag.type == TV_DRAG_NONE)) {
if (tree->search.active == false) {
tree->search.active = true;
if (treeview_clear_selection(tree, &r)) {
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=89dd127a80951dcc7105c04d0e207c1561c5d8bf
commit 89dd127a80951dcc7105c04d0e207c1561c5d8bf
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Update mouse handling details for filtered view.
No moves are allowed in viltered view.
Node indents are constant in filtered view.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 7ba487a..717c90c 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -4256,14 +4256,18 @@ treeview_node_mouse_action_cb(treeview_node *node,
/* Find where the mouse is */
if (ma->y <= ma->current_y + tree_g.line_height) {
- if (ma->x >= node->inset - 1 &&
- ma->x < node->inset + tree_g.step_width) {
+ int inset = node->inset;
+ if (ma->tree->search.search == true) {
+ inset = tree_g.window_padding;
+ }
+ if (ma->x >= inset - 1 &&
+ ma->x < inset + tree_g.step_width) {
/* Over expansion toggle */
part = TV_NODE_PART_TOGGLE;
- } else if (ma->x >= node->inset + tree_g.step_width &&
- ma->x < node->inset + tree_g.step_width +
- tree_g.icon_step + node->text.width) {
+ } else if (ma->x >= inset + tree_g.step_width &&
+ ma->x < inset + tree_g.step_width +
+ tree_g.icon_step + node->text.width) {
/* On node */
part = TV_NODE_PART_ON_NODE;
}
@@ -4337,7 +4341,8 @@ treeview_node_mouse_action_cb(treeview_node *node,
treeview__cw_drag_status(ma->tree,
CORE_WINDOW_DRAG_SELECTION);
- } else if (!(ma->tree->flags & TREEVIEW_NO_MOVES) &&
+ } else if (ma->tree->search.search == false &&
+ !(ma->tree->flags & TREEVIEW_NO_MOVES) &&
ma->mouse & BROWSER_MOUSE_DRAG_1 &&
(ma->tree->drag.selected == true ||
ma->tree->drag.part == TV_NODE_PART_ON_NODE)) {
@@ -4377,7 +4382,7 @@ treeview_node_mouse_action_cb(treeview_node *node,
ma->tree->drag.prev.node_y = ma->current_y;
ma->tree->drag.prev.node_h = height;
}
- break;
+ break;
case TV_DRAG_MOVE:
redraw |= treeview_set_move_indicator(ma->tree, redraw,
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=283fb3633938971d04b2bf8f2b690ce9c8a83951
commit 283fb3633938971d04b2bf8f2b690ce9c8a83951
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Update treeview walker to handle walking the filtered display.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 029fd9d..7ba487a 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -553,10 +553,35 @@ static int treeview_node_y(treeview *tree, treeview_node
*node)
/**
+ * The treeview walk mode. Controls which nodes are visited in a walk.
+ */
+enum treeview_walk_mode {
+ /**
+ * Walk to all nodes in the (sub)tree.
+ */
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+
+ /**
+ * Walk to expanded nodes in the (sub)tree only. Children of
+ * collapsed nodes are not visited.
+ */
+ TREEVIEW_WALK_MODE_LOGICAL_EXPANDED,
+
+ /**
+ * Walk displayed nodes. This differs from the
+ * `TREEVIEW_WALK_MODE_LOGICAL_EXPANDED` mode when there is
+ * an active search filter display.
+ */
+ TREEVIEW_WALK_MODE_DISPLAY,
+};
+
+
+/**
* Walk a treeview subtree, calling a callback at each node (depth first)
*
+ * \param tree Treeview being walked.
* \param root Root to walk tree from (doesn't get a callback call)
- * \param full Iff true, visit children of collapsed nodes
+ * \param mode The treeview walk mode to use.
* \param callback_bwd Function to call on each node in backwards order
* \param callback_fwd Function to call on each node in forwards order
* \param ctx Context to pass to callback
@@ -564,20 +589,37 @@ static int treeview_node_y(treeview *tree, treeview_node
*node)
*
* \note Any node deletion must happen in callback_bwd.
*/
-static nserror
-treeview_walk_internal(treeview_node *root,
- bool full,
- 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)
+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)
{
treeview_node *node, *child, *parent, *next_sibling;
- bool abort = false;
+ bool walking_search = (mode == TREEVIEW_WALK_MODE_DISPLAY &&
+ tree->search.search == true);
bool skip_children = false;
+ bool abort = false;
+ bool full = false;
nserror err;
+ bool entry;
assert(root != NULL);
+ if (mode == TREEVIEW_WALK_MODE_LOGICAL_COMPLETE || walking_search) {
+ /* We need to visit children of collapsed folders. */
+ full = true;
+ }
+
node = root;
parent = node->parent;
next_sibling = node->next_sib;
@@ -594,9 +636,10 @@ treeview_walk_internal(treeview_node *root,
* go to next sibling if present, or nearest ancestor
* with a next sibling. */
- while (node != root &&
- next_sibling == NULL) {
- if (callback_bwd != NULL) {
+ while (node != root && next_sibling == NULL) {
+ entry = (node->type == TREE_NODE_ENTRY);
+ if (callback_bwd != NULL &&
+ (entry || !walking_search)) {
/* Backwards callback */
err = callback_bwd(node, ctx, &abort);
@@ -636,11 +679,18 @@ treeview_walk_internal(treeview_node *root,
assert(node != NULL);
assert(node != root);
+ entry = (node->type == TREE_NODE_ENTRY);
+
parent = node->parent;
next_sibling = node->next_sib;
child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
node->children : NULL;
+ if (walking_search && (!entry ||
+ !(node->flags & TV_NFLAGS_MATCHED))) {
+ continue;
+ }
+
if (callback_fwd != NULL) {
/* Forwards callback */
err = callback_fwd(node, ctx, &skip_children, &abort);
@@ -723,14 +773,17 @@ treeview_set_inset_from_parent(treeview_node *n,
/**
* Insert a treeview node into a treeview
*
- * \param a parentless node to insert
- * \param b tree node to insert a as a relation of
+ * \param tree the treeview to insert node into.
+ * \param a parentless node to insert
+ * \param b tree node to insert a as a relation of
* \param rel The relationship between \a a and \a b
*/
static inline void
-treeview_insert_node(treeview_node *a,
- treeview_node *b,
- enum treeview_relationship rel)
+treeview_insert_node(
+ treeview *tree,
+ treeview_node *a,
+ treeview_node *b,
+ enum treeview_relationship rel)
{
assert(a != NULL);
assert(a->parent == NULL);
@@ -765,8 +818,9 @@ treeview_insert_node(treeview_node *a,
a->inset = a->parent->inset + tree_g.step_width;
if (a->children != NULL) {
- treeview_walk_internal(a, true, NULL,
- treeview_set_inset_from_parent, NULL);
+ treeview_walk_internal(tree, a,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE, NULL,
+ treeview_set_inset_from_parent, NULL);
}
if (a->parent->flags & TV_NFLAGS_EXPANDED) {
@@ -831,7 +885,7 @@ treeview_create_node_folder(treeview *tree,
n->client_data = data;
- treeview_insert_node(n, relation, rel);
+ treeview_insert_node(tree, n, relation, rel);
if (n->parent->flags & TV_NFLAGS_EXPANDED) {
/* Inform front end of change in dimensions */
@@ -1041,7 +1095,7 @@ treeview_create_node_entry(treeview *tree,
e->fields[i - 1].value.width = 0;
}
- treeview_insert_node(n, relation, rel);
+ treeview_insert_node(tree, n, relation, rel);
if (n->parent->flags & TV_NFLAGS_EXPANDED) {
/* Inform front end of change in dimensions */
@@ -1142,7 +1196,8 @@ treeview_walk(treeview *tree,
if (root == NULL)
root = tree->root;
- return treeview_walk_internal(root, true,
+ return treeview_walk_internal(tree, root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
(leave_cb != NULL) ? treeview_walk_bwd_cb : NULL,
(enter_cb != NULL) ? treeview_walk_fwd_cb : NULL,
&tw);
@@ -1370,8 +1425,9 @@ treeview_delete_node_internal(treeview *tree,
}
/* Delete any children first */
- err = treeview_walk_internal(n, true, treeview_delete_node_walk_cb,
- NULL, &nd);
+ err = treeview_walk_internal(tree, n,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+ treeview_delete_node_walk_cb, NULL, &nd);
if (err != NSERROR_OK) {
return err;
}
@@ -1702,7 +1758,8 @@ static nserror treeview__search(
assert(text[len] == '\0');
- err = treeview_walk_internal(tree->root, true, NULL,
+ err = treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE, NULL,
treeview__search_walk_cb, &sw);
if (err != NSERROR_OK) {
return err;
@@ -2129,8 +2186,8 @@ treeview_node_contract_internal(treeview *tree,
treeview_node *node)
selected = node->flags & TV_NFLAGS_SELECTED;
/* Contract children. */
- treeview_walk_internal(node, false, treeview_node_contract_cb,
- NULL, &data);
+ treeview_walk_internal(tree, node, TREEVIEW_WALK_MODE_LOGICAL_EXPANDED,
+ treeview_node_contract_cb, NULL, &data);
/* Contract node */
treeview_node_contract_cb(node, &data, false);
@@ -2194,8 +2251,9 @@ nserror treeview_contract(treeview *tree, bool all)
selected = n->flags & TV_NFLAGS_SELECTED;
/* Contract children. */
- treeview_walk_internal(n, false,
- treeview_node_contract_cb, NULL, &data);
+ treeview_walk_internal(tree, n,
+ TREEVIEW_WALK_MODE_LOGICAL_EXPANDED,
+ treeview_node_contract_cb, NULL, &data);
/* Contract node */
treeview_node_contract_cb(n, &data, false);
@@ -2269,11 +2327,9 @@ nserror treeview_expand(treeview *tree, bool
only_folders)
data.tree = tree;
data.only_folders = only_folders;
- res = treeview_walk_internal(tree->root,
- true,
- NULL,
- treeview_expand_cb,
- &data);
+ res = treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+ NULL, treeview_expand_cb, &data);
if (res == NSERROR_OK) {
/* expansion succeeded, schedule redraw */
@@ -3062,8 +3118,9 @@ bool treeview_has_selection(treeview *tree)
sw.purpose = TREEVIEW_WALK_HAS_SELECTION;
sw.data.has_selection = false;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.has_selection;
}
@@ -3082,8 +3139,9 @@ static treeview_node *
treeview_get_first_selected(treeview *tree)
sw.purpose = TREEVIEW_WALK_GET_FIRST_SELECTED;
sw.data.first.n = NULL;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.first.n;
}
@@ -3131,8 +3189,9 @@ static bool treeview_clear_selection(treeview *tree,
struct rect *rect)
sw.current_y = (tree->flags & TREEVIEW_SEARCHABLE) ?
tree_g.line_height : 0;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3160,8 +3219,9 @@ static bool treeview_select_all(treeview *tree, struct
rect *rect)
sw.current_y = (tree->flags & TREEVIEW_SEARCHABLE) ?
tree_g.line_height : 0;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3188,8 +3248,9 @@ static void treeview_commit_selection_drag(treeview *tree)
sw.data.drag.sel_max = tree->drag.prev.y;
}
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
}
@@ -3206,8 +3267,9 @@ static void treeview_move_yank_selection(treeview *tree)
sw.data.yank.prev = NULL;
sw.tree = tree;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
}
@@ -3226,8 +3288,9 @@ static void treeview_copy_selection(treeview *tree)
sw.data.copy.len = 0;
sw.tree = tree;
- err = treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ err = treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
if (err != NSERROR_OK) {
return;
}
@@ -3265,8 +3328,9 @@ static bool treeview_delete_selection(treeview *tree,
struct rect *rect)
sw.current_y = 0;
sw.tree = tree;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3297,8 +3361,9 @@ static bool treeview_propagate_selection(treeview *tree,
struct rect *rect)
sw.current_y = 0;
sw.tree = tree;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3388,7 +3453,7 @@ static nserror treeview_move_selection(treeview *tree,
struct rect *rect)
node->flags &= ~TV_NFLAGS_SELECTED;
}
- treeview_insert_node(node, relation, relationship);
+ treeview_insert_node(tree, node, relation, relationship);
relation = node;
relationship = TREE_REL_NEXT_SIBLING;
@@ -3487,9 +3552,10 @@ static nserror treeview_launch_selection(treeview *tree)
lw.selected_depth = 0;
lw.tree = tree;
- return treeview_walk_internal(tree->root, true,
- treeview_node_launch_walk_bwd_cb,
- treeview_node_launch_walk_fwd_cb, &lw);
+ return treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+ treeview_node_launch_walk_bwd_cb,
+ treeview_node_launch_walk_fwd_cb, &lw);
}
@@ -3624,18 +3690,25 @@ treeview_keyboard_navigation(treeview *tree, uint32_t
key, struct rect *rect)
/* Fill out the nav. state struct, by examining the current selection
* state */
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_nav_cb, &ns);
- if (ns.next == NULL)
- ns.next = tree->root->children;
- if (ns.prev == NULL)
- ns.prev = ns.last;
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_nav_cb, &ns);
+
+ if (tree->search.search == false) {
+ if (ns.next == NULL)
+ ns.next = tree->root->children;
+ if (ns.prev == NULL)
+ ns.prev = ns.last;
+ }
/* Clear any existing selection */
redraw = treeview_clear_selection(tree, rect);
switch (key) {
case NS_KEY_LEFT:
+ if (tree->search.search == true) {
+ break;
+ }
if (ns.curr != NULL &&
ns.curr->parent != NULL &&
ns.curr->parent->type != TREE_NODE_ROOT) {
@@ -4575,8 +4648,9 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
ma.y = y;
ma.current_y = search_height;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_mouse_action_cb, &ma);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_mouse_action_cb, &ma);
}
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=f142b3684cd98ace5271c0a72600761585cdfa58
commit f142b3684cd98ace5271c0a72600761585cdfa58
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Track height of display in search view.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index a6e3e60..029fd9d 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -218,6 +218,7 @@ struct treeview_search {
struct textarea *textarea; /**< Search box. */
bool active; /**< Whether the search box has focus. */
bool search; /**< Whether we have a search term. */
+ int height; /**< Current search display height. */
};
@@ -327,6 +328,20 @@ static struct treeview_resource
treeview_res[TREE_RES_LAST] = {
/**
+ * Get the display height of the treeview data component of the display.
+ *
+ * \param[in] tree Treeview to get the height of.
+ * \return the display height in pixels.
+ */
+static inline int treeview__get_display_height(treeview *tree)
+{
+ return (tree->search.search == false) ?
+ tree->root->height :
+ tree->search.height;
+}
+
+
+/**
* Corewindow callback wrapper: Request a redraw of the window
*
* \param[in] tree The treeview to request redraw on.
@@ -1645,7 +1660,7 @@ static nserror treeview__search_walk_cb(
if (matched) {
n->flags |= TV_NFLAGS_MATCHED;
- sw->window_height += tree_g.line_height;
+ sw->window_height += n->height;
} else {
n->flags &= ~TV_NFLAGS_MATCHED;
}
@@ -1670,12 +1685,20 @@ static nserror treeview__search(
{
nserror err;
uint32_t height;
+ uint32_t prev_height = treeview__get_display_height(tree);
+ int search_height = (tree->flags & TREEVIEW_SEARCHABLE) ?
+ tree_g.line_height : 0;
struct treeview_search_walk_data sw = {
.len = len,
.text = text,
.tree = tree,
.window_height = 0,
};
+ struct rect r = {
+ .x0 = 0,
+ .y0 = search_height,
+ .x1 = REDRAW_MAX,
+ };
assert(text[len] == '\0');
@@ -1686,6 +1709,7 @@ static nserror treeview__search(
}
if (len > 0) {
+ tree->search.height = sw.window_height;
tree->search.search = true;
height = sw.window_height;
} else {
@@ -1693,7 +1717,9 @@ static nserror treeview__search(
height = tree->root->height;
}
- treeview__cw_update_size(tree, -1, height);
+ r.y1 = ((height > prev_height) ? height : prev_height) + search_height;
+ treeview__cw_invalidate_area(tree, &r);
+ treeview__cw_update_size(tree, -1, height + search_height);
treeview__cw_scroll_top(tree);
return NSERROR_OK;
@@ -2565,7 +2591,7 @@ static void treeview_redraw_search(
count++;
inset = x + tree_g.window_padding;
- height = tree_g.line_height;
+ height = node->height;
if ((render_y + height) < r->y0) {
/* This node's line is above clip region */
@@ -4469,7 +4495,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
}
}
- if (y > tree->root->height + search_height) {
+ if (y > treeview__get_display_height(tree) + search_height) {
/* Below tree */
r.x0 = 0;
@@ -4560,13 +4586,14 @@ int treeview_get_height(treeview *tree)
{
int search_height = (tree->flags & TREEVIEW_SEARCHABLE) ?
tree_g.line_height : 0;
+ int height = treeview__get_display_height(tree);
assert(tree != NULL);
assert(tree->root != NULL);
- treeview__cw_update_size(tree, -1, tree->root->height);
+ treeview__cw_update_size(tree, -1, height);
- return tree->root->height + search_height;
+ return height + search_height;
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=45a7e6269b2328de9178af76ff4aed41c2e69129
commit 45a7e6269b2328de9178af76ff4aed41c2e69129
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Slight simplification of treeview_walk_internal().
diff --git a/desktop/treeview.c b/desktop/treeview.c
index e6dcbc0..a6e3e60 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -566,13 +566,12 @@ treeview_walk_internal(treeview_node *root,
node = root;
parent = node->parent;
next_sibling = node->next_sib;
- child = (!skip_children &&
- (full || (node->flags & TV_NFLAGS_EXPANDED))) ?
+ child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
node->children : NULL;
while (node != NULL) {
- if (child != NULL) {
+ if (child != NULL && !skip_children) {
/* Down to children */
node = child;
} else {
@@ -639,7 +638,6 @@ treeview_walk_internal(treeview_node *root,
return NSERROR_OK;
}
}
- child = skip_children ? NULL : child;
}
return NSERROR_OK;
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=0a0ad71bdb181bb309ba86d283704ba7b0e89dc1
commit 0a0ad71bdb181bb309ba86d283704ba7b0e89dc1
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Fix function namespace.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 3bbc839..e6dcbc0 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -332,9 +332,9 @@ static struct treeview_resource treeview_res[TREE_RES_LAST]
= {
* \param[in] tree The treeview to request redraw on.
* \param[in] r rectangle to redraw
*/
-static inline
-void cw_invalidate_area(const struct treeview *tree,
- const struct rect *r)
+static inline void treeview__cw_invalidate_area(
+ const struct treeview *tree,
+ const struct rect *r)
{
if (tree->cw_t != NULL) {
tree->cw_t->invalidate(tree->cw_h, r);
@@ -833,7 +833,7 @@ treeview_create_node_folder(treeview *tree,
r.y0 = treeview_node_y(tree, n);
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
@@ -884,7 +884,7 @@ treeview_update_node_folder(treeview *tree,
r.y0 = treeview_node_y(tree, folder);
r.x1 = REDRAW_MAX;
r.y1 = r.y0 + tree_g.line_height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return NSERROR_OK;
@@ -956,7 +956,7 @@ treeview_update_node_entry(treeview *tree,
r.y0 = treeview_node_y(tree, entry);
r.x1 = REDRAW_MAX;
r.y1 = r.y0 + entry->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return NSERROR_OK;
@@ -1043,7 +1043,7 @@ treeview_create_node_entry(treeview *tree,
r.y0 = treeview_node_y(tree, n);
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
@@ -1195,7 +1195,7 @@ static void treeview_edit_cancel(treeview *tree, bool
redraw)
r.y0 = tree->edit.y;
r.x1 = tree->edit.x + tree->edit.w;
r.y1 = tree->edit.y + tree->edit.h;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
@@ -1537,7 +1537,7 @@ treeview_delete_node(treeview *tree,
if (visible && !(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
r.x0 = 0;
r.x1 = REDRAW_MAX;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return NSERROR_OK;
@@ -1738,7 +1738,7 @@ static void treeview_textarea_search_callback(void *data,
r->y1 += tree_g.line_height;
/* Redraw the textarea */
- cw_invalidate_area(tree, r);
+ treeview__cw_invalidate_area(tree, r);
break;
case TEXTAREA_MSG_TEXT_MODIFIED:
@@ -2028,7 +2028,7 @@ nserror treeview_node_expand(treeview *tree,
treeview_node *node)
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return res;
@@ -2137,7 +2137,7 @@ nserror treeview_node_contract(treeview *tree,
treeview_node *node)
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return res;
@@ -2184,7 +2184,7 @@ nserror treeview_contract(treeview *tree, bool all)
treeview__cw_update_size(tree, -1, tree->root->height);
/* Redraw */
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
return NSERROR_OK;
}
@@ -2258,7 +2258,7 @@ nserror treeview_expand(treeview *tree, bool only_folders)
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return res;
}
@@ -3712,7 +3712,7 @@ bool treeview_keypress(treeview *tree, uint32_t key)
r.x1 = 600;
r.y0 = 0;
r.y1 = tree_g.line_height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
return true;
case NS_KEY_NL:
case NS_KEY_CR:
@@ -3766,7 +3766,7 @@ bool treeview_keypress(treeview *tree, uint32_t key)
}
if (redraw) {
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return true;
@@ -3942,7 +3942,7 @@ static void treeview_textarea_callback(void *data, struct
textarea_msg *msg)
r->y1 += tree->edit.y;
/* Redraw the textarea */
- cw_invalidate_area(tree, r);
+ treeview__cw_invalidate_area(tree, r);
break;
default:
@@ -4102,7 +4102,7 @@ void treeview_edit_selection(treeview *tree)
rect.y0 = y;
rect.x1 = REDRAW_MAX;
rect.y1 = y + tree_g.line_height;
- cw_invalidate_area(tree, &rect);
+ treeview__cw_invalidate_area(tree, &rect);
}
@@ -4382,7 +4382,7 @@ treeview_node_mouse_action_cb(treeview_node *node,
}
if (redraw) {
- cw_invalidate_area(ma->tree, &r);
+ treeview__cw_invalidate_area(ma->tree, &r);
}
*end = true; /* Reached line with click; stop walking tree */
@@ -4411,7 +4411,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
if (tree->search.active == false) {
tree->search.active = true;
if (treeview_clear_selection(tree, &r)) {
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
textarea_mouse_action(tree->search.textarea, mouse,
@@ -4463,7 +4463,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
tree->move.target_pos = TV_TARGET_NONE;
treeview__cw_drag_status(tree, CORE_WINDOW_DRAG_NONE);
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
return;
default:
/* No drag to end */
@@ -4538,7 +4538,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
}
if (redraw) {
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
} else {
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=db6b3441c412cdc2e6eb197f9601056c2c85dcf8
commit db6b3441c412cdc2e6eb197f9601056c2c85dcf8
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treeview: Scroll to top when treeview search bar is modified.
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 85bc61d..3bbc839 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -364,6 +364,27 @@ static inline void treeview__cw_update_size(
/**
+ * Corewindow callback_wrapper: Scroll to top of window.
+ *
+ * \param[in] tree The treeview to scroll.
+ */
+static inline void treeview__cw_scroll_top(
+ const struct treeview *tree)
+{
+ struct rect r = {
+ .x0 = 0,
+ .y0 = 0,
+ .x1 = tree_g.window_padding,
+ .y1 = tree_g.line_height,
+ };
+
+ if (tree->cw_t != NULL) {
+ tree->cw_t->scroll_visible(tree->cw_h, &r);
+ }
+}
+
+
+/**
* Corewindow callback wrapper: Get window viewport dimensions
*
* \param[in] tree The treeview to get dimensions for.
@@ -1609,7 +1630,6 @@ static nserror treeview__search_walk_cb(
(struct treeview_node_entry *)n;
bool matched = false;
-
for (int i = 0; i < sw->tree->n_fields; i++) {
struct treeview_field *ef = &(sw->tree->fields[i + 1]);
if (ef->flags & TREE_FLAG_SEARCHABLE) {
@@ -1676,6 +1696,7 @@ static nserror treeview__search(
}
treeview__cw_update_size(tree, -1, height);
+ treeview__cw_scroll_top(tree);
return NSERROR_OK;
}
-----------------------------------------------------------------------
Summary of changes:
desktop/cookie_manager.c | 8 +-
desktop/global_history.c | 7 +-
desktop/hotlist.c | 8 +-
desktop/textarea.c | 11 +
desktop/textarea.h | 10 +
desktop/treeview.c | 732 ++++++++++++++++++++++++++++------------------
6 files changed, 491 insertions(+), 285 deletions(-)
diff --git a/desktop/cookie_manager.c b/desktop/cookie_manager.c
index 987a85c..a2aab8e 100644
--- a/desktop/cookie_manager.c
+++ b/desktop/cookie_manager.c
@@ -576,7 +576,9 @@ static nserror cookie_manager_init_entry_fields(void)
goto error;
}
- cm_ctx.fields[COOKIE_M_DOMAIN].flags = TREE_FLAG_SHOW_NAME;
+ cm_ctx.fields[COOKIE_M_DOMAIN].flags =
+ TREE_FLAG_SHOW_NAME |
+ TREE_FLAG_SEARCHABLE;
label = "TreeviewLabelDomain";
label = messages_get(label);
if (lwc_intern_string(label, strlen(label),
@@ -809,7 +811,9 @@ nserror cookie_manager_init(struct
core_window_callback_table *cw_t,
err = treeview_create(&cm_ctx.tree, &cm_tree_cb_t,
COOKIE_M_N_FIELDS, cm_ctx.fields,
cw_t, core_window_handle,
- TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS);
+ TREEVIEW_NO_MOVES |
+ TREEVIEW_DEL_EMPTY_DIRS |
+ TREEVIEW_SEARCHABLE);
if (err != NSERROR_OK) {
cm_ctx.tree = NULL;
return err;
diff --git a/desktop/global_history.c b/desktop/global_history.c
index e699321..ad39a3e 100644
--- a/desktop/global_history.c
+++ b/desktop/global_history.c
@@ -536,7 +536,9 @@ static nserror global_history_initialise_entry_fields(void)
goto error;
}
- gh_ctx.fields[GH_URL].flags = TREE_FLAG_COPY_TEXT;
+ gh_ctx.fields[GH_URL].flags =
+ TREE_FLAG_COPY_TEXT |
+ TREE_FLAG_SEARCHABLE;
label = "TreeviewLabelURL";
label = messages_get(label);
if (lwc_intern_string(label, strlen(label),
@@ -752,7 +754,8 @@ nserror global_history_init(struct
core_window_callback_table *cw_t,
err = treeview_create(&gh_ctx.tree, &gh_tree_cb_t,
N_FIELDS, gh_ctx.fields,
cw_t, core_window_handle,
- TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS);
+ TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS |
+ TREEVIEW_SEARCHABLE);
if (err != NSERROR_OK) {
gh_ctx.tree = NULL;
return err;
diff --git a/desktop/hotlist.c b/desktop/hotlist.c
index 13a52d0..4bdd7c8 100644
--- a/desktop/hotlist.c
+++ b/desktop/hotlist.c
@@ -1198,8 +1198,10 @@ static nserror hotlist_initialise_entry_fields(void)
goto error;
}
- hl_ctx.fields[HL_URL].flags = TREE_FLAG_ALLOW_EDIT |
- TREE_FLAG_COPY_TEXT;
+ hl_ctx.fields[HL_URL].flags =
+ TREE_FLAG_ALLOW_EDIT |
+ TREE_FLAG_COPY_TEXT |
+ TREE_FLAG_SEARCHABLE;
label = "TreeviewLabelURL";
label = messages_get(label);
if (lwc_intern_string(label, strlen(label),
@@ -1313,7 +1315,7 @@ nserror hotlist_init(
/* Create the hotlist treeview */
err = treeview_create(&hl_ctx.tree, &hl_tree_cb_t,
HL_N_FIELDS, hl_ctx.fields, NULL, NULL,
- TREEVIEW_NO_FLAGS);
+ TREEVIEW_SEARCHABLE);
if (err != NSERROR_OK) {
free(hl_ctx.save_path);
hl_ctx.tree = NULL;
diff --git a/desktop/textarea.c b/desktop/textarea.c
index 1cbb767..3fb18e1 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -2074,6 +2074,17 @@ int textarea_get_text(struct textarea *ta, char *buf,
unsigned int len)
/* exported interface, documented in textarea.h */
+const char * textarea_data(struct textarea *ta, unsigned int *len)
+{
+ if (len != NULL) {
+ *len = ta->text.len;
+ }
+
+ return ta->text.data;
+}
+
+
+/* exported interface, documented in textarea.h */
bool textarea_set_caret(struct textarea *ta, int caret)
{
int b_off;
diff --git a/desktop/textarea.h b/desktop/textarea.h
index 8986097..b386e50 100644
--- a/desktop/textarea.h
+++ b/desktop/textarea.h
@@ -213,6 +213,16 @@ int textarea_get_text(struct textarea *ta, char *buf,
unsigned int len);
/**
+ * Access text data in a text area
+ *
+ * \param[in] ta Text area
+ * \param[out] len Returns byte length of returned text, if passed non-NULL.
+ * \return textarea string data.
+ */
+const char * textarea_data(struct textarea *ta, unsigned int *len);
+
+
+/**
* Set the caret's position
*
* \param ta Text area
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 85bc61d..4841db9 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -218,6 +218,7 @@ struct treeview_search {
struct textarea *textarea; /**< Search box. */
bool active; /**< Whether the search box has focus. */
bool search; /**< Whether we have a search term. */
+ int height; /**< Current search display height. */
};
@@ -327,14 +328,28 @@ static struct treeview_resource
treeview_res[TREE_RES_LAST] = {
/**
+ * Get the display height of the treeview data component of the display.
+ *
+ * \param[in] tree Treeview to get the height of.
+ * \return the display height in pixels.
+ */
+static inline int treeview__get_display_height(treeview *tree)
+{
+ return (tree->search.search == false) ?
+ tree->root->height :
+ tree->search.height;
+}
+
+
+/**
* Corewindow callback wrapper: Request a redraw of the window
*
* \param[in] tree The treeview to request redraw on.
* \param[in] r rectangle to redraw
*/
-static inline
-void cw_invalidate_area(const struct treeview *tree,
- const struct rect *r)
+static inline void treeview__cw_invalidate_area(
+ const struct treeview *tree,
+ const struct rect *r)
{
if (tree->cw_t != NULL) {
tree->cw_t->invalidate(tree->cw_h, r);
@@ -364,6 +379,27 @@ static inline void treeview__cw_update_size(
/**
+ * Corewindow callback_wrapper: Scroll to top of window.
+ *
+ * \param[in] tree The treeview to scroll.
+ */
+static inline void treeview__cw_scroll_top(
+ const struct treeview *tree)
+{
+ struct rect r = {
+ .x0 = 0,
+ .y0 = 0,
+ .x1 = tree_g.window_padding,
+ .y1 = tree_g.line_height,
+ };
+
+ if (tree->cw_t != NULL) {
+ tree->cw_t->scroll_visible(tree->cw_h, &r);
+ }
+}
+
+
+/**
* Corewindow callback wrapper: Get window viewport dimensions
*
* \param[in] tree The treeview to get dimensions for.
@@ -517,10 +553,35 @@ static int treeview_node_y(treeview *tree, treeview_node
*node)
/**
+ * The treeview walk mode. Controls which nodes are visited in a walk.
+ */
+enum treeview_walk_mode {
+ /**
+ * Walk to all nodes in the (sub)tree.
+ */
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+
+ /**
+ * Walk to expanded nodes in the (sub)tree only. Children of
+ * collapsed nodes are not visited.
+ */
+ TREEVIEW_WALK_MODE_LOGICAL_EXPANDED,
+
+ /**
+ * Walk displayed nodes. This differs from the
+ * `TREEVIEW_WALK_MODE_LOGICAL_EXPANDED` mode when there is
+ * an active search filter display.
+ */
+ TREEVIEW_WALK_MODE_DISPLAY,
+};
+
+
+/**
* Walk a treeview subtree, calling a callback at each node (depth first)
*
+ * \param tree Treeview being walked.
* \param root Root to walk tree from (doesn't get a callback call)
- * \param full Iff true, visit children of collapsed nodes
+ * \param mode The treeview walk mode to use.
* \param callback_bwd Function to call on each node in backwards order
* \param callback_fwd Function to call on each node in forwards order
* \param ctx Context to pass to callback
@@ -528,30 +589,46 @@ static int treeview_node_y(treeview *tree, treeview_node
*node)
*
* \note Any node deletion must happen in callback_bwd.
*/
-static nserror
-treeview_walk_internal(treeview_node *root,
- bool full,
- 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)
+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)
{
treeview_node *node, *child, *parent, *next_sibling;
- bool abort = false;
+ bool walking_search = (mode == TREEVIEW_WALK_MODE_DISPLAY &&
+ tree->search.search == true);
bool skip_children = false;
+ bool abort = false;
+ bool full = false;
nserror err;
+ bool entry;
assert(root != NULL);
+ if (mode == TREEVIEW_WALK_MODE_LOGICAL_COMPLETE || walking_search) {
+ /* We need to visit children of collapsed folders. */
+ full = true;
+ }
+
node = root;
parent = node->parent;
next_sibling = node->next_sib;
- child = (!skip_children &&
- (full || (node->flags & TV_NFLAGS_EXPANDED))) ?
+ child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
node->children : NULL;
while (node != NULL) {
- if (child != NULL) {
+ if (child != NULL && !skip_children) {
/* Down to children */
node = child;
} else {
@@ -559,9 +636,10 @@ treeview_walk_internal(treeview_node *root,
* go to next sibling if present, or nearest ancestor
* with a next sibling. */
- while (node != root &&
- next_sibling == NULL) {
- if (callback_bwd != NULL) {
+ while (node != root && next_sibling == NULL) {
+ entry = (node->type == TREE_NODE_ENTRY);
+ if (callback_bwd != NULL &&
+ (entry || !walking_search)) {
/* Backwards callback */
err = callback_bwd(node, ctx, &abort);
@@ -601,11 +679,18 @@ treeview_walk_internal(treeview_node *root,
assert(node != NULL);
assert(node != root);
+ entry = (node->type == TREE_NODE_ENTRY);
+
parent = node->parent;
next_sibling = node->next_sib;
child = (full || (node->flags & TV_NFLAGS_EXPANDED)) ?
node->children : NULL;
+ if (walking_search && (!entry ||
+ !(node->flags & TV_NFLAGS_MATCHED))) {
+ continue;
+ }
+
if (callback_fwd != NULL) {
/* Forwards callback */
err = callback_fwd(node, ctx, &skip_children, &abort);
@@ -618,13 +703,216 @@ treeview_walk_internal(treeview_node *root,
return NSERROR_OK;
}
}
- child = skip_children ? NULL : child;
}
return NSERROR_OK;
}
/**
+ * Data used when doing a treeview walk for search.
+ */
+struct treeview_search_walk_data {
+ treeview *tree; /**< The treeview to search. */
+ const char *text; /**< The string being searched for. */
+ const unsigned int len; /**< Length of string being searched for. */
+ int window_height; /**< Accumulate height for matching entries. */
+};
+
+
+/**
+ * Treewalk node callback for handling search.
+ *
+ * \param[in] n Current node.
+ * \param[in] ctx Treeview search context.
+ * \param[in,out] skip_children Flag to allow children to be skipped.
+ * \param[in,out] end Flag to allow iteration to be finished early.
+ * \return NSERROR_OK on success else error code.
+ */
+static nserror treeview__search_walk_cb(
+ treeview_node *n,
+ void *ctx,
+ bool *skip_children,
+ bool *end)
+{
+ struct treeview_search_walk_data *sw = ctx;
+
+ if (n->type != TREE_NODE_ENTRY) {
+ return NSERROR_OK;
+ }
+
+ if (sw->len == 0) {
+ n->flags &= ~TV_NFLAGS_MATCHED;
+ } else {
+ struct treeview_node_entry *entry =
+ (struct treeview_node_entry *)n;
+ bool matched = false;
+
+ for (int i = 0; i < sw->tree->n_fields; i++) {
+ struct treeview_field *ef = &(sw->tree->fields[i + 1]);
+ if (ef->flags & TREE_FLAG_SEARCHABLE) {
+ if (strcasestr(entry->fields[i].value.data,
+ sw->text) != NULL) {
+ matched = true;
+ break;
+ }
+ }
+ }
+
+ if (!matched && strcasestr(n->text.data, sw->text) != NULL) {
+ matched = true;
+ }
+
+ if (matched) {
+ n->flags |= TV_NFLAGS_MATCHED;
+ sw->window_height += n->height;
+ } else {
+ n->flags &= ~TV_NFLAGS_MATCHED;
+ }
+ }
+
+ return NSERROR_OK;
+}
+
+
+/**
+ * Search treeview for text.
+ *
+ * \param[in] tree Treeview to search.
+ * \param[in] text UTF-8 string to search for. (NULL-terminated.)
+ * \param[in] len Byte length of UTF-8 string.
+ * \return NSERROR_OK on success, appropriate error otherwise.
+ */
+static nserror treeview__search(
+ treeview *tree,
+ const char *text,
+ unsigned int len)
+{
+ nserror err;
+ uint32_t height;
+ uint32_t prev_height = treeview__get_display_height(tree);
+ int search_height = (tree->flags & TREEVIEW_SEARCHABLE) ?
+ tree_g.line_height : 0;
+ struct treeview_search_walk_data sw = {
+ .len = len,
+ .text = text,
+ .tree = tree,
+ .window_height = 0,
+ };
+ struct rect r = {
+ .x0 = 0,
+ .y0 = search_height,
+ .x1 = REDRAW_MAX,
+ };
+
+ assert(text[len] == '\0');
+
+ if (tree->root == NULL) {
+ return NSERROR_OK;
+ }
+
+ err = treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE, NULL,
+ treeview__search_walk_cb, &sw);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ if (len > 0) {
+ tree->search.height = sw.window_height;
+ tree->search.search = true;
+ height = sw.window_height;
+ } else {
+ tree->search.search = false;
+ height = tree->root->height;
+ }
+
+ r.y1 = ((height > prev_height) ? height : prev_height) + search_height;
+ treeview__cw_invalidate_area(tree, &r);
+ treeview__cw_update_size(tree, -1, height);
+ treeview__cw_scroll_top(tree);
+
+ return NSERROR_OK;
+}
+
+
+/**
+ * Callback for textarea_create, in desktop/treeview.h
+ *
+ * \param data treeview context
+ * \param msg textarea message
+ */
+static void treeview_textarea_search_callback(void *data,
+ struct textarea_msg *msg)
+{
+ treeview *tree = data;
+ struct rect *r;
+
+ if (tree->search.active == false || tree->root == NULL) {
+ return;
+ }
+
+ switch (msg->type) {
+ case TEXTAREA_MSG_DRAG_REPORT:
+ if (msg->data.drag == TEXTAREA_DRAG_NONE) {
+ /* Textarea drag finished */
+ tree->drag.type = TV_DRAG_NONE;
+ } else {
+ /* Textarea drag started */
+ tree->drag.type = TV_DRAG_SEARCH;
+ }
+ treeview__cw_drag_status(tree, tree->drag.type);
+ break;
+
+ case TEXTAREA_MSG_REDRAW_REQUEST:
+ r = &msg->data.redraw;
+ r->x0 += tree_g.window_padding + tree_g.icon_size;
+ r->y0 += 0;
+ r->x1 += 600;
+ r->y1 += tree_g.line_height;
+
+ /* Redraw the textarea */
+ treeview__cw_invalidate_area(tree, r);
+ break;
+
+ case TEXTAREA_MSG_TEXT_MODIFIED:
+ /* Textarea length includes trailing NULL, so subtract it. */
+ treeview__search(tree,
+ msg->data.modified.text,
+ msg->data.modified.len - 1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/**
+ * Update the layout for any active search.
+ *
+ * \param[in] tree The tree to update.
+ */
+static void treeview__search_update_display(
+ treeview *tree)
+{
+ const char *string;
+ unsigned int len;
+
+ if (tree->search.search == false) {
+ /* No active search to update view for. */
+ return;
+ }
+
+ string = textarea_data(tree->search.textarea, &len);
+ if (string == NULL || len == 0) {
+ return;
+ }
+
+ treeview__search(tree, string, len - 1);
+}
+
+
+/**
* Create treeview's root node
*
* \param[out] root Returns root node
@@ -689,14 +977,17 @@ treeview_set_inset_from_parent(treeview_node *n,
/**
* Insert a treeview node into a treeview
*
- * \param a parentless node to insert
- * \param b tree node to insert a as a relation of
+ * \param tree the treeview to insert node into.
+ * \param a parentless node to insert
+ * \param b tree node to insert a as a relation of
* \param rel The relationship between \a a and \a b
*/
static inline void
-treeview_insert_node(treeview_node *a,
- treeview_node *b,
- enum treeview_relationship rel)
+treeview_insert_node(
+ treeview *tree,
+ treeview_node *a,
+ treeview_node *b,
+ enum treeview_relationship rel)
{
assert(a != NULL);
assert(a->parent == NULL);
@@ -731,8 +1022,9 @@ treeview_insert_node(treeview_node *a,
a->inset = a->parent->inset + tree_g.step_width;
if (a->children != NULL) {
- treeview_walk_internal(a, true, NULL,
- treeview_set_inset_from_parent, NULL);
+ treeview_walk_internal(tree, a,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE, NULL,
+ treeview_set_inset_from_parent, NULL);
}
if (a->parent->flags & TV_NFLAGS_EXPANDED) {
@@ -797,7 +1089,7 @@ treeview_create_node_folder(treeview *tree,
n->client_data = data;
- treeview_insert_node(n, relation, rel);
+ treeview_insert_node(tree, n, relation, rel);
if (n->parent->flags & TV_NFLAGS_EXPANDED) {
/* Inform front end of change in dimensions */
@@ -812,7 +1104,7 @@ treeview_create_node_folder(treeview *tree,
r.y0 = treeview_node_y(tree, n);
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
@@ -863,7 +1155,7 @@ treeview_update_node_folder(treeview *tree,
r.y0 = treeview_node_y(tree, folder);
r.x1 = REDRAW_MAX;
r.y1 = r.y0 + tree_g.line_height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return NSERROR_OK;
@@ -928,6 +1220,8 @@ treeview_update_node_entry(treeview *tree,
}
}
+ treeview__search_update_display(tree);
+
/* Redraw */
if (entry->parent->flags & TV_NFLAGS_EXPANDED) {
struct rect r;
@@ -935,7 +1229,7 @@ treeview_update_node_entry(treeview *tree,
r.y0 = treeview_node_y(tree, entry);
r.x1 = REDRAW_MAX;
r.y1 = r.y0 + entry->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return NSERROR_OK;
@@ -1007,7 +1301,7 @@ treeview_create_node_entry(treeview *tree,
e->fields[i - 1].value.width = 0;
}
- treeview_insert_node(n, relation, rel);
+ treeview_insert_node(tree, n, relation, rel);
if (n->parent->flags & TV_NFLAGS_EXPANDED) {
/* Inform front end of change in dimensions */
@@ -1022,10 +1316,12 @@ treeview_create_node_entry(treeview *tree,
r.y0 = treeview_node_y(tree, n);
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
+ treeview__search_update_display(tree);
+
*entry = n;
return NSERROR_OK;
@@ -1108,7 +1404,8 @@ treeview_walk(treeview *tree,
if (root == NULL)
root = tree->root;
- return treeview_walk_internal(root, true,
+ return treeview_walk_internal(tree, root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
(leave_cb != NULL) ? treeview_walk_bwd_cb : NULL,
(enter_cb != NULL) ? treeview_walk_fwd_cb : NULL,
&tw);
@@ -1174,7 +1471,7 @@ static void treeview_edit_cancel(treeview *tree, bool
redraw)
r.y0 = tree->edit.y;
r.x1 = tree->edit.x + tree->edit.w;
r.y1 = tree->edit.y + tree->edit.h;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
@@ -1336,8 +1633,9 @@ treeview_delete_node_internal(treeview *tree,
}
/* Delete any children first */
- err = treeview_walk_internal(n, true, treeview_delete_node_walk_cb,
- NULL, &nd);
+ err = treeview_walk_internal(tree, n,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+ treeview_delete_node_walk_cb, NULL, &nd);
if (err != NSERROR_OK) {
return err;
}
@@ -1365,6 +1663,8 @@ treeview_delete_node_internal(treeview *tree,
tree->root->height);
}
+ treeview__search_update_display(tree);
+
return NSERROR_OK;
}
@@ -1516,7 +1816,7 @@ treeview_delete_node(treeview *tree,
if (visible && !(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
r.x0 = 0;
r.x1 = REDRAW_MAX;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return NSERROR_OK;
@@ -1570,169 +1870,6 @@ static struct textarea *treeview__create_textarea(
}
-/**
- * Data used when doing a treeview walk for search.
- */
-struct treeview_search_walk_data {
- treeview *tree; /**< The treeview to search. */
- const char *text; /**< The string being searched for. */
- const unsigned int len; /**< Length of string being searched for. */
- int window_height; /**< Accumulate height for matching entries. */
-};
-
-
-/**
- * Treewalk node callback for handling search.
- *
- * \param[in] n Current node.
- * \param[in] ctx Treeview search context.
- * \param[in,out] skip_children Flag to allow children to be skipped.
- * \param[in,out] end Flag to allow iteration to be finished early.
- * \return NSERROR_OK on success else error code.
- */
-static nserror treeview__search_walk_cb(
- treeview_node *n,
- void *ctx,
- bool *skip_children,
- bool *end)
-{
- struct treeview_search_walk_data *sw = ctx;
-
- if (n->type != TREE_NODE_ENTRY) {
- return NSERROR_OK;
- }
-
- if (sw->len == 0) {
- n->flags &= ~TV_NFLAGS_MATCHED;
- } else {
- struct treeview_node_entry *entry =
- (struct treeview_node_entry *)n;
- bool matched = false;
-
-
- for (int i = 0; i < sw->tree->n_fields; i++) {
- struct treeview_field *ef = &(sw->tree->fields[i + 1]);
- if (ef->flags & TREE_FLAG_SEARCHABLE) {
- if (strcasestr(entry->fields[i].value.data,
- sw->text) != NULL) {
- matched = true;
- break;
- }
- }
- }
-
- if (!matched && strcasestr(n->text.data, sw->text) != NULL) {
- matched = true;
- }
-
- if (matched) {
- n->flags |= TV_NFLAGS_MATCHED;
- sw->window_height += tree_g.line_height;
- } else {
- n->flags &= ~TV_NFLAGS_MATCHED;
- }
- }
-
- return NSERROR_OK;
-}
-
-
-/**
- * Search treeview for text.
- *
- * \param[in] tree Treeview to search.
- * \param[in] text UTF-8 string to search for. (NULL-terminated.)
- * \param[in] len Byte length of UTF-8 string.
- * \return NSERROR_OK on success, appropriate error otherwise.
- */
-static nserror treeview__search(
- treeview *tree,
- const char *text,
- unsigned int len)
-{
- nserror err;
- uint32_t height;
- struct treeview_search_walk_data sw = {
- .len = len,
- .text = text,
- .tree = tree,
- .window_height = 0,
- };
-
- assert(text[len] == '\0');
-
- err = treeview_walk_internal(tree->root, true, NULL,
- treeview__search_walk_cb, &sw);
- if (err != NSERROR_OK) {
- return err;
- }
-
- if (len > 0) {
- tree->search.search = true;
- height = sw.window_height;
- } else {
- tree->search.search = false;
- height = tree->root->height;
- }
-
- treeview__cw_update_size(tree, -1, height);
-
- return NSERROR_OK;
-}
-
-
-/**
- * Callback for textarea_create, in desktop/treeview.h
- *
- * \param data treeview context
- * \param msg textarea message
- */
-static void treeview_textarea_search_callback(void *data,
- struct textarea_msg *msg)
-{
- treeview *tree = data;
- struct rect *r;
-
- if (tree->search.active == false) {
- return;
- }
-
- switch (msg->type) {
- case TEXTAREA_MSG_DRAG_REPORT:
- if (msg->data.drag == TEXTAREA_DRAG_NONE) {
- /* Textarea drag finished */
- tree->drag.type = TV_DRAG_NONE;
- } else {
- /* Textarea drag started */
- tree->drag.type = TV_DRAG_SEARCH;
- }
- treeview__cw_drag_status(tree, tree->drag.type);
- break;
-
- case TEXTAREA_MSG_REDRAW_REQUEST:
- r = &msg->data.redraw;
- r->x0 += tree_g.window_padding + tree_g.icon_size;
- r->y0 += 0;
- r->x1 += 600;
- r->y1 += tree_g.line_height;
-
- /* Redraw the textarea */
- cw_invalidate_area(tree, r);
- break;
-
- case TEXTAREA_MSG_TEXT_MODIFIED:
- /* Textarea length includes trailing NULL, so subtract it. */
- treeview__search(tree,
- msg->data.modified.text,
- msg->data.modified.len - 1);
- break;
-
- default:
- break;
- }
-}
-
-
/* Exported interface, documented in treeview.h */
nserror
treeview_create(treeview **tree,
@@ -1931,7 +2068,6 @@ treeview_node_expand_internal(treeview *tree,
treeview_node *node)
}
do {
- assert((child->flags & TV_NFLAGS_EXPANDED) == false);
if (child->text.width == 0) {
guit->layout->width(&plot_style_odd.text,
child->text.data,
@@ -1976,17 +2112,21 @@ treeview_node_expand_internal(treeview *tree,
treeview_node *node)
/* Update the node */
node->flags |= TV_NFLAGS_EXPANDED;
- /* And parent's heights */
- do {
- node->height += additional_height;
- node = node->parent;
- } while (node->parent != NULL);
+ /* And node heights */
+ for (struct treeview_node *n = node;
+ (n != NULL) && (n->flags & TV_NFLAGS_EXPANDED);
+ n = n->parent) {
+ n->height += additional_height;
+ }
- node->height += additional_height;
+ if (tree->search.search) {
+ tree->search.height += additional_height;
+ }
/* Inform front end of change in dimensions */
if (additional_height != 0) {
- treeview__cw_update_size(tree, -1, tree->root->height);
+ treeview__cw_update_size(tree, -1,
+ treeview__get_display_height(tree));
}
return NSERROR_OK;
@@ -2005,9 +2145,9 @@ nserror treeview_node_expand(treeview *tree,
treeview_node *node)
r.x0 = 0;
r.y0 = treeview_node_y(tree, node);
r.x1 = REDRAW_MAX;
- r.y1 = tree->root->height;
+ r.y1 = treeview__get_display_height(tree);
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return res;
@@ -2018,6 +2158,7 @@ nserror treeview_node_expand(treeview *tree,
treeview_node *node)
* context for treeview contraction callback
*/
struct treeview_contract_data {
+ treeview *tree;
bool only_entries;
};
@@ -2046,15 +2187,20 @@ static nserror treeview_node_contract_cb(treeview_node
*n, void *ctx, bool *end)
return NSERROR_OK;
}
- n->flags ^= TV_NFLAGS_EXPANDED;
h_reduction = n->height - tree_g.line_height;
assert(h_reduction >= 0);
+ for (struct treeview_node *node = n;
+ (node != NULL) && (node->flags & TV_NFLAGS_EXPANDED);
+ node = node->parent) {
+ node->height -= h_reduction;
+ }
- do {
- n->height -= h_reduction;
- n = n->parent;
- } while (n != NULL);
+ if (data->tree->search.search) {
+ data->tree->search.height -= h_reduction;
+ }
+
+ n->flags ^= TV_NFLAGS_EXPANDED;
return NSERROR_OK;
}
@@ -2080,12 +2226,13 @@ treeview_node_contract_internal(treeview *tree,
treeview_node *node)
return NSERROR_OK;
}
+ data.tree = tree;
data.only_entries = false;
selected = node->flags & TV_NFLAGS_SELECTED;
/* Contract children. */
- treeview_walk_internal(node, false, treeview_node_contract_cb,
- NULL, &data);
+ treeview_walk_internal(tree, node, TREEVIEW_WALK_MODE_LOGICAL_EXPANDED,
+ treeview_node_contract_cb, NULL, &data);
/* Contract node */
treeview_node_contract_cb(node, &data, false);
@@ -2094,7 +2241,7 @@ treeview_node_contract_internal(treeview *tree,
treeview_node *node)
node->flags |= TV_NFLAGS_SELECTED;
/* Inform front end of change in dimensions */
- treeview__cw_update_size(tree, -1, tree->root->height);
+ treeview__cw_update_size(tree, -1, treeview__get_display_height(tree));
return NSERROR_OK;
}
@@ -2116,7 +2263,7 @@ nserror treeview_node_contract(treeview *tree,
treeview_node *node)
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return res;
@@ -2149,8 +2296,9 @@ nserror treeview_contract(treeview *tree, bool all)
selected = n->flags & TV_NFLAGS_SELECTED;
/* Contract children. */
- treeview_walk_internal(n, false,
- treeview_node_contract_cb, NULL, &data);
+ treeview_walk_internal(tree, n,
+ TREEVIEW_WALK_MODE_LOGICAL_EXPANDED,
+ treeview_node_contract_cb, NULL, &data);
/* Contract node */
treeview_node_contract_cb(n, &data, false);
@@ -2163,7 +2311,7 @@ nserror treeview_contract(treeview *tree, bool all)
treeview__cw_update_size(tree, -1, tree->root->height);
/* Redraw */
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
return NSERROR_OK;
}
@@ -2224,11 +2372,9 @@ nserror treeview_expand(treeview *tree, bool
only_folders)
data.tree = tree;
data.only_folders = only_folders;
- res = treeview_walk_internal(tree->root,
- true,
- NULL,
- treeview_expand_cb,
- &data);
+ res = treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+ NULL, treeview_expand_cb, &data);
if (res == NSERROR_OK) {
/* expansion succeeded, schedule redraw */
@@ -2237,7 +2383,7 @@ nserror treeview_expand(treeview *tree, bool only_folders)
r.x1 = REDRAW_MAX;
r.y1 = tree->root->height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return res;
}
@@ -2546,7 +2692,7 @@ static void treeview_redraw_search(
count++;
inset = x + tree_g.window_padding;
- height = tree_g.line_height;
+ height = node->height;
if ((render_y + height) < r->y0) {
/* This node's line is above clip region */
@@ -3017,8 +3163,9 @@ bool treeview_has_selection(treeview *tree)
sw.purpose = TREEVIEW_WALK_HAS_SELECTION;
sw.data.has_selection = false;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.has_selection;
}
@@ -3037,8 +3184,9 @@ static treeview_node *
treeview_get_first_selected(treeview *tree)
sw.purpose = TREEVIEW_WALK_GET_FIRST_SELECTED;
sw.data.first.n = NULL;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.first.n;
}
@@ -3086,8 +3234,9 @@ static bool treeview_clear_selection(treeview *tree,
struct rect *rect)
sw.current_y = (tree->flags & TREEVIEW_SEARCHABLE) ?
tree_g.line_height : 0;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3115,8 +3264,9 @@ static bool treeview_select_all(treeview *tree, struct
rect *rect)
sw.current_y = (tree->flags & TREEVIEW_SEARCHABLE) ?
tree_g.line_height : 0;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3143,8 +3293,9 @@ static void treeview_commit_selection_drag(treeview *tree)
sw.data.drag.sel_max = tree->drag.prev.y;
}
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
}
@@ -3161,8 +3312,9 @@ static void treeview_move_yank_selection(treeview *tree)
sw.data.yank.prev = NULL;
sw.tree = tree;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
}
@@ -3181,8 +3333,9 @@ static void treeview_copy_selection(treeview *tree)
sw.data.copy.len = 0;
sw.tree = tree;
- err = treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ err = treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
if (err != NSERROR_OK) {
return;
}
@@ -3220,8 +3373,9 @@ static bool treeview_delete_selection(treeview *tree,
struct rect *rect)
sw.current_y = 0;
sw.tree = tree;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3252,8 +3406,9 @@ static bool treeview_propagate_selection(treeview *tree,
struct rect *rect)
sw.current_y = 0;
sw.tree = tree;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_selection_walk_cb, &sw);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_selection_walk_cb, &sw);
return sw.data.redraw.required;
}
@@ -3343,7 +3498,7 @@ static nserror treeview_move_selection(treeview *tree,
struct rect *rect)
node->flags &= ~TV_NFLAGS_SELECTED;
}
- treeview_insert_node(node, relation, relationship);
+ treeview_insert_node(tree, node, relation, relationship);
relation = node;
relationship = TREE_REL_NEXT_SIBLING;
@@ -3442,9 +3597,10 @@ static nserror treeview_launch_selection(treeview *tree)
lw.selected_depth = 0;
lw.tree = tree;
- return treeview_walk_internal(tree->root, true,
- treeview_node_launch_walk_bwd_cb,
- treeview_node_launch_walk_fwd_cb, &lw);
+ return treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_LOGICAL_COMPLETE,
+ treeview_node_launch_walk_bwd_cb,
+ treeview_node_launch_walk_fwd_cb, &lw);
}
@@ -3579,18 +3735,25 @@ treeview_keyboard_navigation(treeview *tree, uint32_t
key, struct rect *rect)
/* Fill out the nav. state struct, by examining the current selection
* state */
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_nav_cb, &ns);
- if (ns.next == NULL)
- ns.next = tree->root->children;
- if (ns.prev == NULL)
- ns.prev = ns.last;
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_nav_cb, &ns);
+
+ if (tree->search.search == false) {
+ if (ns.next == NULL)
+ ns.next = tree->root->children;
+ if (ns.prev == NULL)
+ ns.prev = ns.last;
+ }
/* Clear any existing selection */
redraw = treeview_clear_selection(tree, rect);
switch (key) {
case NS_KEY_LEFT:
+ if (tree->search.search == true) {
+ break;
+ }
if (ns.curr != NULL &&
ns.curr->parent != NULL &&
ns.curr->parent->type != TREE_NODE_ROOT) {
@@ -3691,7 +3854,7 @@ bool treeview_keypress(treeview *tree, uint32_t key)
r.x1 = 600;
r.y0 = 0;
r.y1 = tree_g.line_height;
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
return true;
case NS_KEY_NL:
case NS_KEY_CR:
@@ -3745,7 +3908,7 @@ bool treeview_keypress(treeview *tree, uint32_t key)
}
if (redraw) {
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
return true;
@@ -3921,7 +4084,7 @@ static void treeview_textarea_callback(void *data, struct
textarea_msg *msg)
r->y1 += tree->edit.y;
/* Redraw the textarea */
- cw_invalidate_area(tree, r);
+ treeview__cw_invalidate_area(tree, r);
break;
default:
@@ -4081,7 +4244,7 @@ void treeview_edit_selection(treeview *tree)
rect.y0 = y;
rect.x1 = REDRAW_MAX;
rect.y1 = y + tree_g.line_height;
- cw_invalidate_area(tree, &rect);
+ treeview__cw_invalidate_area(tree, &rect);
}
@@ -4138,14 +4301,18 @@ treeview_node_mouse_action_cb(treeview_node *node,
/* Find where the mouse is */
if (ma->y <= ma->current_y + tree_g.line_height) {
- if (ma->x >= node->inset - 1 &&
- ma->x < node->inset + tree_g.step_width) {
+ int inset = node->inset;
+ if (ma->tree->search.search == true) {
+ inset = tree_g.window_padding;
+ }
+ if (ma->x >= inset - 1 &&
+ ma->x < inset + tree_g.step_width) {
/* Over expansion toggle */
part = TV_NODE_PART_TOGGLE;
- } else if (ma->x >= node->inset + tree_g.step_width &&
- ma->x < node->inset + tree_g.step_width +
- tree_g.icon_step + node->text.width) {
+ } else if (ma->x >= inset + tree_g.step_width &&
+ ma->x < inset + tree_g.step_width +
+ tree_g.icon_step + node->text.width) {
/* On node */
part = TV_NODE_PART_ON_NODE;
}
@@ -4219,7 +4386,8 @@ treeview_node_mouse_action_cb(treeview_node *node,
treeview__cw_drag_status(ma->tree,
CORE_WINDOW_DRAG_SELECTION);
- } else if (!(ma->tree->flags & TREEVIEW_NO_MOVES) &&
+ } else if (ma->tree->search.search == false &&
+ !(ma->tree->flags & TREEVIEW_NO_MOVES) &&
ma->mouse & BROWSER_MOUSE_DRAG_1 &&
(ma->tree->drag.selected == true ||
ma->tree->drag.part == TV_NODE_PART_ON_NODE)) {
@@ -4259,7 +4427,7 @@ treeview_node_mouse_action_cb(treeview_node *node,
ma->tree->drag.prev.node_y = ma->current_y;
ma->tree->drag.prev.node_h = height;
}
- break;
+ break;
case TV_DRAG_MOVE:
redraw |= treeview_set_move_indicator(ma->tree, redraw,
@@ -4361,7 +4529,7 @@ treeview_node_mouse_action_cb(treeview_node *node,
}
if (redraw) {
- cw_invalidate_area(ma->tree, &r);
+ treeview__cw_invalidate_area(ma->tree, &r);
}
*end = true; /* Reached line with click; stop walking tree */
@@ -4386,11 +4554,13 @@ treeview_mouse_action(treeview *tree,
browser_mouse_state mouse, int x, int y)
textarea_mouse_action(tree->edit.textarea, mouse,
x - tree->edit.x, y - tree->edit.y);
return;
- } else if (tree->drag.type == TV_DRAG_SEARCH || y < search_height) {
+ } else if (tree->drag.type == TV_DRAG_SEARCH ||
+ (y < search_height &&
+ tree->drag.type == TV_DRAG_NONE)) {
if (tree->search.active == false) {
tree->search.active = true;
if (treeview_clear_selection(tree, &r)) {
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
}
textarea_mouse_action(tree->search.textarea, mouse,
@@ -4402,7 +4572,11 @@ treeview_mouse_action(treeview *tree,
browser_mouse_state mouse, int x, int y)
tree->search.active = false;
textarea_set_caret(tree->search.textarea, -1);
- return;
+ r.x0 = 0;
+ r.y0 = 0;
+ r.x1 = REDRAW_MAX;
+ r.y1 = tree_g.line_height;
+ treeview__cw_invalidate_area(tree, &r);
}
/* Handle textarea related mouse action */
@@ -4442,7 +4616,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
tree->move.target_pos = TV_TARGET_NONE;
treeview__cw_drag_status(tree, CORE_WINDOW_DRAG_NONE);
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
return;
default:
/* No drag to end */
@@ -4450,7 +4624,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
}
}
- if (y > tree->root->height + search_height) {
+ if (y > treeview__get_display_height(tree) + search_height) {
/* Below tree */
r.x0 = 0;
@@ -4517,7 +4691,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
}
if (redraw) {
- cw_invalidate_area(tree, &r);
+ treeview__cw_invalidate_area(tree, &r);
}
} else {
@@ -4530,8 +4704,9 @@ treeview_mouse_action(treeview *tree, browser_mouse_state
mouse, int x, int y)
ma.y = y;
ma.current_y = search_height;
- treeview_walk_internal(tree->root, false, NULL,
- treeview_node_mouse_action_cb, &ma);
+ treeview_walk_internal(tree, tree->root,
+ TREEVIEW_WALK_MODE_DISPLAY, NULL,
+ treeview_node_mouse_action_cb, &ma);
}
}
@@ -4541,13 +4716,14 @@ int treeview_get_height(treeview *tree)
{
int search_height = (tree->flags & TREEVIEW_SEARCHABLE) ?
tree_g.line_height : 0;
+ int height = treeview__get_display_height(tree);
assert(tree != NULL);
assert(tree->root != NULL);
- treeview__cw_update_size(tree, -1, tree->root->height);
+ treeview__cw_update_size(tree, -1, height);
- return tree->root->height + search_height;
+ return height + search_height;
}
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org