textchild: Return an array from get_widgets
Yay, one GList less.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user