[gtk/wip/baedert/for-master: 11/12] textchild: Return an array from get_widgets
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 11/12] textchild: Return an array from get_widgets
- Date: Sat, 25 Apr 2020 14:44:59 +0000 (UTC)
commit ca3ab3731270af24c0f24d7e9b9dfe23d8a54da7
Author: Timm Bäder <mail baedert org>
Date: Sat Apr 25 15:42:24 2020 +0200
textchild: Return an array from get_widgets
Yay, one GList less.
gtk/gtktextchild.c | 23 +++++++++++++++++------
gtk/gtktextchild.h | 4 +++-
gtk/gtktextlayout.c | 15 ++++++++-------
3 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtktextchild.c b/gtk/gtktextchild.c
index 0a2e6163dd..fb2b0f14c8 100644
--- a/gtk/gtktextchild.c
+++ b/gtk/gtktextchild.c
@@ -437,21 +437,31 @@ gtk_text_child_anchor_finalize (GObject *obj)
*
* Returns: (element-type GtkWidget) (transfer container): list of widgets anchored at @anchor
**/
-GList*
-gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor)
+GtkWidget **
+gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor,
+ guint *out_len)
{
GtkTextLineSegment *seg = anchor->segment;
- GList *list = NULL;
+ GPtrArray *arr;
GSList *iter;
CHECK_IN_BUFFER_RETURN (anchor, NULL);
-
+
+ g_return_val_if_fail (out_len != NULL, NULL);
g_return_val_if_fail (seg->type == >k_text_child_type, NULL);
iter = seg->body.child.widgets;
+
+ if (!iter)
+ {
+ *out_len = 0;
+ return NULL;
+ }
+
+ arr = g_ptr_array_new ();
while (iter != NULL)
{
- list = g_list_prepend (list, iter->data);
+ g_ptr_array_add (arr, iter->data);
iter = iter->next;
}
@@ -459,7 +469,8 @@ gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor)
/* Order is not relevant, so we don't need to reverse the list
* again.
*/
- return list;
+ *out_len = arr->len;
+ return (GtkWidget **)g_ptr_array_free (arr, FALSE);
}
/**
diff --git a/gtk/gtktextchild.h b/gtk/gtktextchild.h
index 7437577897..2f9cad3fd3 100644
--- a/gtk/gtktextchild.h
+++ b/gtk/gtktextchild.h
@@ -31,6 +31,7 @@
#include <gdk/gdk.h>
#include <glib-object.h>
+#include <gtkwidget.h>
G_BEGIN_DECLS
@@ -78,7 +79,8 @@ GDK_AVAILABLE_IN_ALL
GtkTextChildAnchor* gtk_text_child_anchor_new (void);
GDK_AVAILABLE_IN_ALL
-GList* gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor);
+GtkWidget ** gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor,
+ guint *out_len);
GDK_AVAILABLE_IN_ALL
gboolean gtk_text_child_anchor_get_deleted (GtkTextChildAnchor *anchor);
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index 0719dcb222..d07413d16a 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -2010,8 +2010,9 @@ allocate_child_widgets (GtkTextLayout *text_layout,
gint byte_index;
GtkTextIter text_iter;
GtkTextChildAnchor *anchor = NULL;
- GList *widgets = NULL;
- GList *l;
+ GtkWidget **widgets = NULL;
+ guint n_widgets = 0;
+ guint i;
/* The pango iterator iterates in visual order.
* We use the byte index to find the child widget.
@@ -2019,13 +2020,13 @@ allocate_child_widgets (GtkTextLayout *text_layout,
byte_index = pango_layout_iter_get_index (run_iter);
line_display_index_to_iter (text_layout, display, &text_iter, byte_index, 0);
anchor = gtk_text_iter_get_child_anchor (&text_iter);
- if (anchor)
- widgets = gtk_text_child_anchor_get_widgets (anchor);
+ if (anchor)
+ widgets = gtk_text_child_anchor_get_widgets (anchor, &n_widgets);
- for (l = widgets; l; l = l->next)
+ for (i = 0; i < n_widgets; i++)
{
+ GtkWidget *child = widgets[i];
PangoRectangle extents;
- GtkWidget *child = l->data;
if (_gtk_anchored_child_get_layout (child) == text_layout)
{
@@ -2047,7 +2048,7 @@ allocate_child_widgets (GtkTextLayout *text_layout,
}
}
- g_list_free (widgets);
+ g_free (widgets);
}
}
while (pango_layout_iter_next_run (run_iter));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]