[libgda] Added the ability to use GtkSizeGroups in GdauiBasicForm



commit 4690c1eaa29ea18a2f3f4fed6344d2c25e154062
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Apr 27 19:36:09 2010 +0200

    Added the ability to use GtkSizeGroups in GdauiBasicForm
    
    
    new APIs:
    gdaui_basic_form_add_to_size_group()
    gdaui_basic_form_remove_from_size_group

 doc/C/libgda-ui-sections.txt     |    4 +
 doc/C/tmpl/gdaui-basic-form.sgml |   28 +++++++++
 libgda-ui/gdaui-basic-form.c     |  123 ++++++++++++++++++++++++++++++++++++++
 libgda-ui/gdaui-basic-form.h     |    9 +++
 libgda-ui/libgda-ui.symbols      |    2 +
 5 files changed, 166 insertions(+), 0 deletions(-)
---
diff --git a/doc/C/libgda-ui-sections.txt b/doc/C/libgda-ui-sections.txt
index bf43792..62266b5 100644
--- a/doc/C/libgda-ui-sections.txt
+++ b/doc/C/libgda-ui-sections.txt
@@ -40,6 +40,10 @@ gdaui_basic_form_get_label_widget
 <SUBSECTION>
 gdaui_basic_form_set_layout_from_file
 gdaui_basic_form_get_place_holder
+<SUBSECTION>
+GdauiBasicFormPart
+gdaui_basic_form_add_to_size_group
+gdaui_basic_form_remove_from_size_group
 <SUBSECTION Standard>
 GDAUI_BASIC_FORM
 GDAUI_BASIC_FORM_CLASS
diff --git a/doc/C/tmpl/gdaui-basic-form.sgml b/doc/C/tmpl/gdaui-basic-form.sgml
index 04c0a8d..97338fb 100644
--- a/doc/C/tmpl/gdaui-basic-form.sgml
+++ b/doc/C/tmpl/gdaui-basic-form.sgml
@@ -304,3 +304,31 @@ which can be described by the following DTD.
 @Returns: 
 
 
+<!-- ##### ENUM GdauiBasicFormPart ##### -->
+<para>
+
+</para>
+
+ GDAUI_BASIC_FORM_LABELS: 
+ GDAUI_BASIC_FORM_ENTRIES: 
+
+<!-- ##### FUNCTION gdaui_basic_form_add_to_size_group ##### -->
+<para>
+
+</para>
+
+ form: 
+ size_group: 
+ part: 
+
+
+<!-- ##### FUNCTION gdaui_basic_form_remove_from_size_group ##### -->
+<para>
+
+</para>
+
+ form: 
+ size_group: 
+ part: 
+
+
diff --git a/libgda-ui/gdaui-basic-form.c b/libgda-ui/gdaui-basic-form.c
index 81c65d6..f5a08f4 100644
--- a/libgda-ui/gdaui-basic-form.c
+++ b/libgda-ui/gdaui-basic-form.c
@@ -130,6 +130,17 @@ enum {
 	PROP_CAN_EXPAND
 };
 
+typedef struct {
+	GtkSizeGroup *size_group; /* ref held here */
+	GdauiBasicFormPart part;
+} SizeGroup;
+static void
+size_group_free (SizeGroup *sg)
+{
+	g_object_unref (sg->size_group);
+	g_free (sg);
+}
+
 struct _GdauiBasicFormPriv
 {
 	GdaSet                 *set;
@@ -143,6 +154,8 @@ struct _GdauiBasicFormPriv
 	gboolean                forward_param_updates; /* forward them to the GdauiDataEntry widgets ? */
 	gboolean                show_actions;
 	gboolean                entries_auto_default;
+
+	GSList                 *size_groups; /* list of SizeGroup pointers */
 };
 
 
@@ -430,6 +443,11 @@ gdaui_basic_form_dispose (GObject *object)
 
 		destroy_entries (form);
 
+		if (form->priv->size_groups) {
+			g_slist_foreach (form->priv->size_groups, (GFunc) size_group_free, NULL);
+			g_slist_free (form->priv->size_groups);
+		}
+
 		/* the private area itself */
 		g_free (form->priv);
 		form->priv = NULL;
@@ -826,6 +844,23 @@ create_entry_widget (SingleEntry *sentry)
 	g_object_ref_sink (sentry->entry);
 	gdaui_data_entry_set_editable (sentry->entry, editable);
 
+	GSList *list;
+	for (list = sentry->form->priv->size_groups; list; list = list->next) {
+		SizeGroup *sg = (SizeGroup*) list->data;
+		switch (sg->part) {
+		case GDAUI_BASIC_FORM_LABELS:
+			if (sentry->label)
+				gtk_size_group_add_widget (sg->size_group, sentry->label);
+			break;
+		case GDAUI_BASIC_FORM_ENTRIES:
+			if (sentry->entry)
+				gtk_size_group_add_widget (sg->size_group, sentry->entry);
+			break;
+		default:
+			g_assert_not_reached ();
+		}
+	}
+
 	/* connect the entry's changes */
 	sentry->entry_contents_modified_id = g_signal_connect (G_OBJECT (entry), "contents-modified",
 							       G_CALLBACK (entry_contents_modified),
@@ -2003,3 +2038,91 @@ gdaui_basic_form_get_place_holder (GdauiBasicForm *form, const gchar *placeholde
 		return NULL;
 	return g_hash_table_lookup (form->priv->place_holders, placeholder_id);
 }
+
+/**
+ * gdaui_basic_form_add_to_size_group
+ * @form: a #GdauiBasicForm
+ * @size_group: a #GtkSizeGroup object
+ * @part: specifies which widgets in @form are concerned
+ *
+ * Add @form's widgets specified by @part to @size_group
+ * (the widgets can then be removed using gdaui_basic_form_remove_from_size_group()).
+ */
+void
+gdaui_basic_form_add_to_size_group (GdauiBasicForm *form, GtkSizeGroup *size_group, GdauiBasicFormPart part)
+{
+	GSList *list;
+	g_return_if_fail (GDAUI_IS_BASIC_FORM (form));
+	g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
+
+	SizeGroup *sg;
+	sg = g_new (SizeGroup, 1);
+	sg->size_group = g_object_ref (size_group);
+	sg->part = part;
+	form->priv->size_groups = g_slist_append (form->priv->size_groups, sg);
+
+	for (list = form->priv->s_entries; list; list = list->next) {
+		SingleEntry *se = (SingleEntry*) list->data;
+		switch (part) {
+		case GDAUI_BASIC_FORM_LABELS:
+			if (se->label)
+				gtk_size_group_add_widget (size_group, se->label);
+			break;
+		case GDAUI_BASIC_FORM_ENTRIES:
+			if (se->entry)
+				gtk_size_group_add_widget (size_group, GTK_WIDGET (se->entry));
+			break;
+		default:
+			g_assert_not_reached ();
+		}
+	}
+}
+
+/**
+ * gdaui_basic_form_remove_from_size_group
+ * @form: a #GdauiBasicForm
+ * @size_group: a #GtkSizeGroup object
+ * @part: specifies which widgets in @form are concerned
+ *
+ * Removes @form's widgets specified by @part from @size_group
+ * (the widgets must have been added using gdaui_basic_form_add_to_size_group()).
+ */
+void
+gdaui_basic_form_remove_from_size_group (GdauiBasicForm *form, GtkSizeGroup *size_group, GdauiBasicFormPart part)
+{
+	GSList *list;
+	g_return_if_fail (GDAUI_IS_BASIC_FORM (form));
+	g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
+	
+	SizeGroup *sg;
+	for (list = form->priv->size_groups; list; list = list->next) {
+		sg = (SizeGroup*) list->data;
+		if (sg->size_group == size_group) {
+			form->priv->size_groups = g_slist_remove (form->priv->size_groups, sg);
+			size_group_free (sg);
+			break;
+		}
+		sg = NULL;
+	}
+
+	if (!sg) {
+		g_warning (_("size group was not taken into account using gdaui_basic_form_add_to_size_group()"));
+		return;
+	}
+
+	for (list = form->priv->s_entries; list; list = list->next) {
+		SingleEntry *se = (SingleEntry*) list->data;
+		switch (part) {
+		case GDAUI_BASIC_FORM_LABELS:
+			if (se->label)
+				gtk_size_group_remove_widget (size_group, se->label);
+			break;
+		case GDAUI_BASIC_FORM_ENTRIES:
+			if (se->entry)
+				gtk_size_group_remove_widget (size_group, GTK_WIDGET (se->entry));
+			break;
+		default:
+			g_assert_not_reached ();
+		}
+	}
+}
diff --git a/libgda-ui/gdaui-basic-form.h b/libgda-ui/gdaui-basic-form.h
index 286df2f..c8c17ef 100644
--- a/libgda-ui/gdaui-basic-form.h
+++ b/libgda-ui/gdaui-basic-form.h
@@ -82,6 +82,15 @@ void              gdaui_basic_form_set_layout_from_file     (GdauiBasicForm *for
 							     const gchar *form_name);
 GtkWidget        *gdaui_basic_form_get_place_holder         (GdauiBasicForm *form, const gchar *placeholder_id);
 
+typedef enum {
+	GDAUI_BASIC_FORM_LABELS,
+	GDAUI_BASIC_FORM_ENTRIES
+} GdauiBasicFormPart;
+void              gdaui_basic_form_add_to_size_group        (GdauiBasicForm *form, GtkSizeGroup *size_group,
+							     GdauiBasicFormPart part);
+void              gdaui_basic_form_remove_from_size_group   (GdauiBasicForm *form, GtkSizeGroup *size_group,
+							     GdauiBasicFormPart part);
+
 G_END_DECLS
 
 #endif
diff --git a/libgda-ui/libgda-ui.symbols b/libgda-ui/libgda-ui.symbols
index 9a75da7..8ba402d 100644
--- a/libgda-ui/libgda-ui.symbols
+++ b/libgda-ui/libgda-ui.symbols
@@ -1,5 +1,6 @@
 	gdaui_action_get_type
 	gdaui_action_mode_get_type
+	gdaui_basic_form_add_to_size_group
 	gdaui_basic_form_entry_grab_focus
 	gdaui_basic_form_entry_set_editable
 	gdaui_basic_form_entry_set_visible
@@ -12,6 +13,7 @@
 	gdaui_basic_form_is_valid
 	gdaui_basic_form_new
 	gdaui_basic_form_new_in_dialog
+	gdaui_basic_form_remove_from_size_group
 	gdaui_basic_form_reset
 	gdaui_basic_form_set_as_reference
 	gdaui_basic_form_set_entries_to_default



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]