diff options
author | Christian Hergert <chergert@redhat.com> | 2021-03-29 20:44:58 -0700 |
---|---|---|
committer | Christian Hergert <chergert@redhat.com> | 2021-03-30 13:07:30 -0700 |
commit | 5e3f1ee42acfa30d3e47af8747869ce564ef8993 (patch) | |
tree | 05f725b7f8b04f89ec5609e3a3d4c70306c38a62 | |
parent | 12642456012f7d121d90f71fe0072c33acfa1e44 (diff) | |
download | gtk+-5e3f1ee42acfa30d3e47af8747869ce564ef8993.tar.gz |
textregion: allow breaking foreach early
-rw-r--r-- | gtk/gtktextregion.c | 6 | ||||
-rw-r--r-- | gtk/gtktextregionprivate.h | 16 | ||||
-rw-r--r-- | testsuite/gtk/textregion.c | 15 |
3 files changed, 28 insertions, 9 deletions
diff --git a/gtk/gtktextregion.c b/gtk/gtktextregion.c index af32a5cc5d..100b6ea105 100644 --- a/gtk/gtktextregion.c +++ b/gtk/gtktextregion.c @@ -1234,7 +1234,8 @@ _gtk_text_region_foreach (GtkTextRegion *region, g_assert (leaf->leaf.next == NULL || leaf->leaf.next->leaf.prev == leaf); SORTED_ARRAY_FOREACH (&leaf->leaf.runs, GtkTextRegionRun, run, { - func (offset, run, user_data); + if (func (offset, run, user_data)) + return; offset += run->length; }); } @@ -1279,7 +1280,8 @@ _gtk_text_region_foreach_in_range (GtkTextRegion *region, else { offset_within_node = 0; - func (position, run, user_data); + if (func (position, run, user_data)) + return; } position += run->length; diff --git a/gtk/gtktextregionprivate.h b/gtk/gtktextregionprivate.h index e4868cea66..d8365e4115 100644 --- a/gtk/gtktextregionprivate.h +++ b/gtk/gtktextregionprivate.h @@ -33,9 +33,19 @@ typedef struct _GtkTextRegionRun gpointer data; } GtkTextRegionRun; -typedef void (*GtkTextRegionForeachFunc) (gsize offset, - const GtkTextRegionRun *run, - gpointer user_data); +/* + * GtkTextRegionForeachFunc: + * @offset: the offset in characters within the text region + * @run: the run of text and data pointer + * @user_data: user data supplied + * + * Function callback to iterate through runs within a text region. + * + * Returns: %FALSE to coninue iteration, otherwise %TRUE to stop. + */ +typedef gboolean (*GtkTextRegionForeachFunc) (gsize offset, + const GtkTextRegionRun *run, + gpointer user_data); /* * GtkTextRegionJoinFunc: diff --git a/testsuite/gtk/textregion.c b/testsuite/gtk/textregion.c index ab5f4221ab..f2474b316e 100644 --- a/testsuite/gtk/textregion.c +++ b/testsuite/gtk/textregion.c @@ -98,12 +98,13 @@ assert_empty (GtkTextRegion *region) g_assert_cmpint (1, ==, count_leaves (region)); } -static void +static gboolean non_overlapping_insert_remove_cb (gsize offset, const GtkTextRegionRun *run, gpointer user_data) { g_assert_cmpint (offset, ==, GPOINTER_TO_UINT (run->data)); + return FALSE; } static void @@ -145,7 +146,7 @@ typedef struct { const SplitRunCheck *checks; } SplitRun; -static void +static gboolean split_run_cb (gsize offset, const GtkTextRegionRun *run, gpointer user_data) @@ -155,6 +156,8 @@ split_run_cb (gsize offset, g_assert_cmpint (run->length, ==, state->checks[state->index].length); g_assert_true (run->data == state->checks[state->index].data); state->index++; + + return FALSE; } static void @@ -463,7 +466,7 @@ typedef struct GString *res; } wordstate; -static void +static gboolean word_foreach_cb (gsize offset, const GtkTextRegionRun *run, gpointer data) @@ -485,6 +488,8 @@ word_foreach_cb (gsize offset, #endif g_string_append_len (state->res, src + soff, run->length); + + return FALSE; } static gboolean @@ -564,7 +569,7 @@ test_words_database (void) _gtk_text_region_free (region); } -static void +static gboolean foreach_cb (gsize offset, const GtkTextRegionRun *run, gpointer user_data) @@ -573,6 +578,8 @@ foreach_cb (gsize offset, g_assert_cmpint (GPOINTER_TO_SIZE (run->data), ==, offset); (*count)++; + + return FALSE; } static void |