From 38b73db178144be6ffe6727ccb166c587d5f6161 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alejandro=20Pi=C3=B1eiro?= Date: Tue, 14 Oct 2008 17:18:27 +0000 Subject: [PATCH] 2008-10-14 Alejandro Pinheiro * src/hildon-touch-selector.h: Set parent_instance and parent_class as GtkVBox and GtkVboxClass, as currently the type definition was using GTK_TYPE_VBOX * src/hildon-touch-selector.c: Added some implementation notes in order to clarify that any other widget added without the column related API will not be included on the selection logic, and how the widget is freed, as some people ask about it. (hildon_touch_selector_remove): Reimplemented in order to free properly the column related data when you remove the private hbox. * doc/hildon.types: Added the type hildon_touch_selector_column, in order to get a proper HildonTouchSelectorColumn documentation --- ChangeLog | 15 +++++++++++ doc/hildon.types | 2 ++ src/hildon-touch-selector.c | 58 +++++++++++++++++++++---------------------- src/hildon-touch-selector.h | 4 +-- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index a568eca..eccc9ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-10-14 Alejandro Pinheiro + + * src/hildon-touch-selector.h: + Set parent_instance and parent_class as GtkVBox and GtkVboxClass, as + currently the type definition was using GTK_TYPE_VBOX + * src/hildon-touch-selector.c: + Added some implementation notes in order to clarify that any other widget + added without the column related API will not be included on the + selection logic, and how the widget is freed, as some people ask about + it. + (hildon_touch_selector_remove): Reimplemented in order to free properly + the column related data when you remove the private hbox. + * doc/hildon.types: Added the type hildon_touch_selector_column, in order + to get a proper HildonTouchSelectorColumn documentation + 2008-10-13 Claudio Saavedra * src/hildon-touch-selector-entry.c: diff --git a/doc/hildon.types b/doc/hildon.types index f71be6f..f169706 100644 --- a/doc/hildon.types +++ b/doc/hildon.types @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,7 @@ hildon_entry_get_type hildon_text_view_get_type hildon_button_get_type hildon_touch_selector_get_type +hildon_touch_selector_column_get_type hildon_touch_selector_entry_get_type hildon_time_selector_get_type hildon_date_selector_get_type diff --git a/src/hildon-touch-selector.c b/src/hildon-touch-selector.c index 7b59ce6..6477379 100644 --- a/src/hildon-touch-selector.c +++ b/src/hildon-touch-selector.c @@ -96,11 +96,13 @@ G_DEFINE_TYPE (HildonTouchSelector, hildon_touch_selector, GTK_TYPE_VBOX) #define CENTER_ON_SELECTED_ITEM_DELAY 50 /* + * IMPLEMENTATION NOTES: * Struct to maintain the data of each column. The columns are the elements - * of the widget that belongs properly to the selection behaviour. As - * the selector contents are arranged in a #GtkHBox, you can add more widgets, - * like buttons etc. between the columns, but this doesn't belongs to the - * selection logic + * of the widget that belongs properly to the selection behaviour. Although + * internally the columns are arranged in a private #GtkHBox, as the selector + * itself is a #GtkVBox, you can add more widgets, like buttons etc., so + * you finally could have a widget with more elements that the columns, but + * this doesn't belongs to the selection logic */ struct _HildonTouchSelectorColumnPrivate { @@ -300,6 +302,21 @@ hildon_touch_selector_init (HildonTouchSelector * selector) gtk_widget_set_size_request (GTK_WIDGET (selector), -1, 320); } +/* + * IMPLEMENTATION NOTES: + * Some people sent questions regarding a missing dispose/finalize function on + * this widget that could lead to leak memory, so we will clarify this topic. + * + * This is not required as #HildonTouchSelector extends #GtkContainer. When the + * widget is freed, the #GtkContainer freeing memory functions are called. This + * process includes remove each widget individually, so all the widgets are + * properly freed. + * + * In the same way, this widget redefines gtk_container->remove function, in + * order to free the column related information if it is required. + * + * Please take a look to hildon_touch_selector_remove for more information. + */ static void hildon_touch_selector_map (GtkWidget * widget) { @@ -318,39 +335,22 @@ static void hildon_touch_selector_remove (GtkContainer * container, GtkWidget * widget) { HildonTouchSelector *selector = NULL; - GSList *iter = NULL; - gint position = 0; - HildonTouchSelectorColumn *current_column = NULL; - gint num_columns = 0; g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (container)); - selector = HILDON_TOUCH_SELECTOR (container); - num_columns = hildon_touch_selector_get_num_columns (selector); - /* Check if the widget is inside a column and remove - it from the list */ - iter = selector->priv->columns; - position = 0; - while (iter) { - current_column = HILDON_TOUCH_SELECTOR_COLUMN (iter->data); - if (widget == current_column->priv->panarea) { - current_column = g_slist_nth_data (selector->priv->columns, position); + /* Remove the extra data related to the columns, if required. */ + if (widget == selector->priv->hbox) { + g_slist_foreach (selector->priv->columns, (GFunc) g_object_unref, NULL); - selector->priv->columns = g_slist_remove (selector->priv->columns, - current_column); - g_free (current_column); + g_slist_free (selector->priv->columns); - break; - } - - position++; - iter = g_slist_next (iter); - } - if (position >= num_columns) { - g_debug ("This widget was not inside the selector column"); + selector->priv->columns = NULL; + } else { + g_debug ("Freeing a widget outside the columns logic"); } + /* Now remove the widget itself from the container */ GTK_CONTAINER_CLASS (hildon_touch_selector_parent_class)->remove (container, widget); } diff --git a/src/hildon-touch-selector.h b/src/hildon-touch-selector.h index b3f84ed..07caf0f 100644 --- a/src/hildon-touch-selector.h +++ b/src/hildon-touch-selector.h @@ -56,7 +56,7 @@ typedef gchar *(*HildonTouchSelectorPrintFunc) (HildonTouchSelector * selector) struct _HildonTouchSelector { - GtkHBox parent_instance; + GtkVBox parent_instance; /*< private > */ HildonTouchSelectorPrivate *priv; @@ -64,7 +64,7 @@ struct _HildonTouchSelector struct _HildonTouchSelectorClass { - GtkHBoxClass parent_class; + GtkVBoxClass parent_class; /* signals */ void (*changed) (HildonTouchSelector *selector, -- 1.7.9.5