Commit e6d2660b authored by Tristan Van Berkom's avatar Tristan Van Berkom

Simplified code with convenience functions


	* src/glade-gtk.c: Simplified code with convenience functions

	* src/glade-editor.[ch]: Fixed visual state of labels in insensitive state.

	* src/glade-property.[ch]: Added glade_property_get/set_va_list

	* src/glade-widget.[ch]:
	   Added convenienve functions:
	    - glade_widget_property_get/set
	    - glade_widget_pack_property_get/set
	    - glade_widget_property_set_sensitive
	    - glade_widget_pack_property_set_sensitive
parent 57f41a7e
2005-07-29 Tristan Van Berkom <tvb@gnome.org>
* src/glade-gtk.c: Simplified code with convenience functions
* src/glade-editor.[ch]: Fixed visual state of labels in insensitive state.
* src/glade-property.[ch]: Added glade_property_get/set_va_list
* src/glade-widget.[ch]:
Added convenienve functions:
- glade_widget_property_get/set
- glade_widget_pack_property_get/set
- glade_widget_property_set_sensitive
- glade_widget_pack_property_set_sensitive
2005-07-29 Tristan Van Berkom <tvb@gnome.org>
* src/glade-property.[ch]:
......
......@@ -1065,31 +1065,32 @@ GtkWidget *
glade_editor_create_item_label (GladeEditorProperty *property)
{
GtkWidget *eventbox;
GtkWidget *label;
gchar *text;
g_return_val_if_fail (GLADE_IS_EDITOR_PROPERTY (property), NULL);
g_return_val_if_fail (property->class != NULL, NULL);
text = g_strdup_printf ("%s :", property->class->name);
label = gtk_label_new (text);
property->item_label = gtk_label_new (text);
g_free (text);
gtk_misc_set_alignment (GTK_MISC (property->item_label), 1.0, 0.0);
/* we need to wrap the label in an event box to add tooltips */
eventbox = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (eventbox), property->item_label);
if (insensitive_colour == NULL)
insensitive_colour =
&(GTK_WIDGET
(label)->style->text[GTK_STATE_INSENSITIVE]);
gdk_color_copy
(&(GTK_WIDGET (property->item_label)->
style->fg[GTK_STATE_INSENSITIVE]));
if (normal_colour == NULL)
normal_colour =
&(GTK_WIDGET
(label)->style->text[GTK_STATE_NORMAL]);
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.0);
/* we need to wrap the label in an event box to add tooltips */
eventbox = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (eventbox), label);
gdk_color_copy
(&(GTK_WIDGET (property->item_label)->
style->fg[GTK_STATE_NORMAL]));
return eventbox;
}
......@@ -1146,9 +1147,9 @@ glade_editor_append_item_real (GladeEditorTable *table,
return gtk_label_new ("Implement me !");
}
property->item_label = glade_editor_create_item_label (property);
property->eventbox = glade_editor_create_item_label (property);
glade_editor_table_attach (table->table_widget, property->item_label, 0, table->rows);
glade_editor_table_attach (table->table_widget, property->eventbox, 0, table->rows);
glade_editor_table_attach (table->table_widget, input, 1, table->rows);
table->rows++;
......@@ -1464,7 +1465,7 @@ glade_editor_tooltip_cb (GladeProperty *property,
GladeEditorProperty *editor_prop)
{
glade_util_widget_set_tooltip (editor_prop->input, tooltip);
glade_util_widget_set_tooltip (editor_prop->item_label, tooltip);
glade_util_widget_set_tooltip (editor_prop->eventbox, tooltip);
}
static void
......@@ -1488,7 +1489,7 @@ glade_editor_property_set_tooltips (GladeEditorProperty *property)
tooltip = (gchar *)glade_property_get_tooltip (property->property);
glade_util_widget_set_tooltip (property->input, tooltip);
glade_util_widget_set_tooltip (property->item_label, tooltip);
glade_util_widget_set_tooltip (property->eventbox, tooltip);
return;
}
......@@ -1725,6 +1726,7 @@ glade_editor_sensitivity_cb (GladeProperty *property,
GladeEditorProperty *editor_prop)
{
gboolean sensitive = glade_property_get_sensitive (editor_prop->property);
gtk_widget_modify_fg
(GTK_WIDGET (editor_prop->item_label),
GTK_STATE_NORMAL,
......@@ -1791,10 +1793,11 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
property);
sensitive = glade_property_get_sensitive (property->property);
gtk_widget_modify_fg
gtk_widget_modify_fg
(GTK_WIDGET (property->item_label),
GTK_STATE_NORMAL,
sensitive ? normal_colour : insensitive_colour);
gtk_widget_set_sensitive (property->input, sensitive);
glade_editor_property_set_tooltips (property);
......
......@@ -184,7 +184,9 @@ struct _GladeEditorProperty
gulong sensitive_id; /* signal connection id for sensitivity changes */
GladeProperty *sensitive_prop; /* the last object this was connected to */
GtkWidget *item_label; /* Keep a hold of this for tooltips */
GtkWidget *eventbox; /* Keep a hold of this for tooltips */
GtkWidget *item_label; /* control visual label state manually */
};
LIBGLADEUI_API GType glade_editor_get_type (void);
......
......@@ -842,23 +842,23 @@ glade_gtk_table_verify_n_columns (GObject *object, GValue *value)
void GLADEGTK_API
glade_gtk_button_set_stock (GObject *object, GValue *value)
{
GladeWidget *glade_widget;
GladeWidget *gwidget;
GladeProperty *property;
GEnumClass *eclass;
guint i;
gint val;
glade_widget = glade_widget_get_from_gobject (object);
gwidget = glade_widget_get_from_gobject (object);
g_return_if_fail (GTK_IS_BUTTON (object));
g_return_if_fail (glade_widget != NULL);
g_return_if_fail (gwidget != NULL);
val = g_value_get_enum (value);
if (val == GPOINTER_TO_INT (g_object_get_data (object, "stock")))
return;
g_return_if_fail (glade_widget != NULL);
g_return_if_fail (gwidget != NULL);
property = glade_widget_get_property (glade_widget, "stock");
property = glade_widget_get_property (gwidget, "stock");
eclass = g_type_class_ref (property->class->pspec->value_type);
for (i = 0; i < eclass->n_values; i++)
......@@ -869,13 +869,10 @@ glade_gtk_button_set_stock (GObject *object, GValue *value)
return;
}
property = glade_widget_get_property (glade_widget, "use-stock");
glade_property_set (property, TRUE);
property = glade_widget_get_property (glade_widget, "label");
glade_property_set (property, eclass->values[i].value_nick);
glade_property_set_sensitive (property, FALSE, "Jolly rancher");
glade_widget_property_set (gwidget, "use-stock", TRUE);
glade_widget_property_set (gwidget, "label", eclass->values[i].value_nick);
glade_widget_property_set_sensitive
(gwidget, "label", FALSE, _("Jolly rancher"));
g_type_class_unref (eclass);
g_object_set_data (object, "stock", GINT_TO_POINTER (val));
......@@ -1232,7 +1229,6 @@ glade_gtk_frame_create_idle (gpointer data)
GladeWidget *gframe, *glabel;
GtkWidget *label, *frame;
GladeWidgetClass *wclass;
GladeProperty *property;
g_return_val_if_fail (GLADE_IS_WIDGET (data), FALSE);
g_return_val_if_fail (GTK_IS_FRAME (GLADE_WIDGET (data)->object), FALSE);
......@@ -1247,11 +1243,7 @@ glade_gtk_frame_create_idle (gpointer data)
glabel = glade_widget_new (gframe, wclass,
glade_widget_get_project (gframe));
if ((property =
glade_widget_get_property (glabel, "label")) != NULL)
glade_property_set (property, "Frame");
else
g_critical ("Unable to get \"label\" property\n");
glade_widget_property_set (glabel, "label", "Frame");
g_object_set_data (glabel->object, "special-child-type", "label_item");
gtk_frame_set_label_widget (GTK_FRAME (frame), GTK_WIDGET (glabel->object));
......@@ -1285,7 +1277,6 @@ glade_gtk_button_create_idle (gpointer data)
GladeWidget *gbutton, *glabel;
GtkWidget *widget, *button;
GladeWidgetClass *wclass;
GladeProperty *property;
g_return_val_if_fail (GLADE_IS_WIDGET (data), FALSE);
g_return_val_if_fail (GTK_IS_BUTTON (GLADE_WIDGET (data)->object), FALSE);
......@@ -1299,12 +1290,9 @@ glade_gtk_button_create_idle (gpointer data)
wclass = glade_widget_class_get_by_type (GTK_TYPE_LABEL);
glabel = glade_widget_new (gbutton, wclass,
glade_widget_get_project (gbutton));
if ((property =
glade_widget_get_property (glabel, "label")) != NULL)
glade_property_set (property, gbutton->widget_class->generic_name);
else
g_critical ("Unable to get \"label\" property\n");
glade_widget_property_set
(glabel, "label", gbutton->widget_class->generic_name);
if (widget)
gtk_container_remove (GTK_CONTAINER (button), widget);
......
......@@ -599,40 +599,21 @@ glade_property_set_value (GladeProperty *property, const GValue *value)
}
/**
* glade_property_set_value:
* @property: a #GladeProperty
* @value: a #GValue
*
* TODO: write me
*/
void
glade_property_get_value (GladeProperty *property, GValue *value)
{
g_return_if_fail (GLADE_IS_PROPERTY (property));
g_return_if_fail (value != NULL);
GLADE_PROPERTY_GET_CINFO (property)->get_value (property, value);
}
/**
* glade_property_set:
* glade_property_set_va_list:
* @property: a #GladeProperty
* @value: a #GValue
* @va_list: a va_list with value to set
*
* TODO: write me
*/
void
glade_property_set (GladeProperty *property, ...)
glade_property_set_va_list (GladeProperty *property, va_list vl)
{
va_list vl;
GValue *value;
g_return_if_fail (GLADE_IS_PROPERTY (property));
g_return_if_fail (value != NULL);
value = g_new0 (GValue, 1);
g_value_init (value, property->class->pspec->value_type);
va_start (vl, property);
if (G_IS_PARAM_SPEC_ENUM(property->class->pspec))
g_value_set_enum (value, va_arg (vl, gint));
......@@ -668,8 +649,6 @@ glade_property_set (GladeProperty *property, ...)
g_critical ("Unsupported pspec type %s",
g_type_name(property->class->pspec->value_type));
va_end (vl);
GLADE_PROPERTY_GET_CINFO (property)->set_value (property, value);
g_value_unset (value);
......@@ -679,24 +658,54 @@ glade_property_set (GladeProperty *property, ...)
/**
* glade_property_set:
* @property: a #GladeProperty
* @value: a #GValue
* @...: the value to set
*
* TODO: write me
*/
void
glade_property_get (GladeProperty *property, ...)
glade_property_set (GladeProperty *property, ...)
{
va_list vl;
GValue *value;
g_return_if_fail (GLADE_IS_PROPERTY (property));
va_start (vl, property);
glade_property_set_va_list (property, vl);
va_end (vl);
}
/**
* glade_property_get_value:
* @property: a #GladeProperty
* @value: a #GValue
*
* TODO: write me
*/
void
glade_property_get_value (GladeProperty *property, GValue *value)
{
g_return_if_fail (GLADE_IS_PROPERTY (property));
g_return_if_fail (value != NULL);
GLADE_PROPERTY_GET_CINFO (property)->get_value (property, value);
}
/**
* glade_property_get_va_list:
* @property: a #GladeProperty
* @value: a #GValue
*
* TODO: write me
*/
void
glade_property_get_va_list (GladeProperty *property, va_list vl)
{
GValue *value;
g_return_if_fail (GLADE_IS_PROPERTY (property));
value = g_new0 (GValue, 1);
GLADE_PROPERTY_GET_CINFO (property)->get_value (property, value);
va_start (vl, property);
/* The argument is a pointer of the specified type, cast the pointer and assign
* the value using the proper g_value_get_ variation.
*/
......@@ -733,13 +742,30 @@ glade_property_get (GladeProperty *property, ...)
else
g_critical ("Unsupported pspec type %s",
g_type_name(property->class->pspec->value_type));
va_end (vl);
g_value_unset (value);
g_free (value);
}
/**
* glade_property_get:
* @property: a #GladeProperty
* @value: a #GValue
*
* TODO: write me
*/
void
glade_property_get (GladeProperty *property, ...)
{
va_list vl;
g_return_if_fail (GLADE_IS_PROPERTY (property));
va_start (vl, property);
glade_property_get_va_list (property, vl);
va_end (vl);
}
/**
* glade_property_sync:
* @property: a #GladeProperty
......
......@@ -84,10 +84,14 @@ LIBGLADEUI_API GladeProperty *glade_property_dup (Gla
GladeWidget *widget);
LIBGLADEUI_API void glade_property_set_value (GladeProperty *property,
const GValue *value);
LIBGLADEUI_API void glade_property_set_va_list (GladeProperty *property,
va_list vl);
LIBGLADEUI_API void glade_property_set (GladeProperty *property,
...);
LIBGLADEUI_API void glade_property_get_value (GladeProperty *property,
GValue *value);
LIBGLADEUI_API void glade_property_set (GladeProperty *property,
...);
LIBGLADEUI_API void glade_property_get_va_list (GladeProperty *property,
va_list vl);
LIBGLADEUI_API void glade_property_get (GladeProperty *property,
...);
LIBGLADEUI_API void glade_property_sync (GladeProperty *property);
......
......@@ -1118,7 +1118,7 @@ glade_widget_get_project (GladeWidget *widget)
/**
* glade_widget_get_property:
* @widget: a #GladeWidget
* @id_property: a string naming a property
* @id_property: a string naming a #GladeProperty
*
* Returns: the #GladeProperty in @widget named @id_property
*/
......@@ -1143,7 +1143,7 @@ glade_widget_get_property (GladeWidget *widget, const gchar *id_property)
/**
* glade_widget_get_pack_property:
* @widget: a #GladeWidget
* @id_property: a string naming a packing property
* @id_property: a string naming a #GladeProperty
*
* Returns: the #GladeProperty in @widget named @id_property
*/
......@@ -1169,6 +1169,186 @@ glade_widget_get_pack_property (GladeWidget *widget, const gchar *id_property)
return NULL;
}
/**
* glade_widget_property_get:
* @widget: a #GladeWidget
* @id_property: a string naming a #GladeProperty
* @...: The return location for the value of the said #GladeProperty
*
* Gets the value of @id_property in @widget
*
* Returns: whether @id_property was found or not.
*/
gboolean
glade_widget_property_get (GladeWidget *widget,
const char *id_property,
...)
{
GladeProperty *property;
va_list vl;
g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
if ((property = glade_widget_get_property (widget, id_property)) != NULL)
{
va_start (vl, id_property);
glade_property_get_va_list (property, vl);
va_end (vl);
return TRUE;
}
return FALSE;
}
/**
* glade_widget_property_set:
* @widget: a #GladeWidget
* @id_property: a string naming a #GladeProperty
* @...: A value of the correct type for the said #GladeProperty
*
* Sets the value of @id_property in @widget
*
* Returns: whether @id_property was found or not.
*/
gboolean
glade_widget_property_set (GladeWidget *widget,
const char *id_property,
...)
{
GladeProperty *property;
va_list vl;
g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
if ((property = glade_widget_get_property (widget, id_property)) != NULL)
{
va_start (vl, id_property);
glade_property_set_va_list (property, vl);
va_end (vl);
return TRUE;
}
return FALSE;
}
/**
* glade_widget_pack_property_get:
* @widget: a #GladeWidget
* @id_property: a string naming a #GladeProperty
* @...: The return location for the value of the said #GladeProperty
*
* Gets the value of @id_property in @widget packing properties
*
* Returns: whether @id_property was found or not.
*/
gboolean
glade_widget_pack_property_get (GladeWidget *widget,
const char *id_property,
...)
{
GladeProperty *property;
va_list vl;
g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL)
{
va_start (vl, id_property);
glade_property_get_va_list (property, vl);
va_end (vl);
return TRUE;
}
return FALSE;
}
/**
* glade_widget_pack_property_set:
* @widget: a #GladeWidget
* @id_property: a string naming a #GladeProperty
* @...: The return location for the value of the said #GladeProperty
*
* Sets the value of @id_property in @widget packing properties
*
* Returns: whether @id_property was found or not.
*/
gboolean
glade_widget_pack_property_set (GladeWidget *widget,
const char *id_property,
...)
{
GladeProperty *property;
va_list vl;
g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL)
{
va_start (vl, id_property);
glade_property_set_va_list (property, vl);
va_end (vl);
return TRUE;
}
return FALSE;
}
/**
* glade_widget_property_set_sensitive:
* @widget: a #GladeWidget
* @id_property: a string naming a #GladeProperty
* @...: The return location for the value of the said #GladeProperty
*
* Sets the value of @id_property in @widget
*
* Returns: whether @id_property was found or not.
*/
gboolean
glade_widget_property_set_sensitive (GladeWidget *widget,
const char *id_property,
gboolean sensitive,
const gchar *reason)
{
GladeProperty *property;
g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
if ((property = glade_widget_get_property (widget, id_property)) != NULL)
{
glade_property_set_sensitive (property, sensitive, reason);
return TRUE;
}
return FALSE;
}
/**
* glade_widget_pack_property_set_sensitive:
* @widget: a #GladeWidget
* @id_property: a string naming a #GladeProperty
* @...: The return location for the value of the said #GladeProperty
*
* Sets the value if @id_property in @widget packing properties
*
* Returns: whether @id_property was found or not.
*/
gboolean
glade_widget_pack_property_set_sensitive (GladeWidget *widget,
const char *id_property,
gboolean sensitive,
const gchar *reason)
{
GladeProperty *property;
g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL)
{
glade_property_set_sensitive (property, sensitive, reason);
return TRUE;
}
return FALSE;
}
static gboolean
glade_widget_popup_menu (GtkWidget *widget, gpointer unused_data)
{
......
......@@ -103,15 +103,39 @@ LIBGLADEUI_API const gchar *glade_widget_get_internal (Glad
LIBGLADEUI_API GladeWidgetClass *glade_widget_get_class (GladeWidget *widget);
LIBGLADEUI_API GladeProject *glade_widget_get_project (GladeWidget *widget);
LIBGLADEUI_API GObject *glade_widget_get_object (GladeWidget *widget);
LIBGLADEUI_API GladeProperty *glade_widget_get_property (GladeWidget *widget,
const char *id_property);
LIBGLADEUI_API GladeProperty *glade_widget_get_pack_property (GladeWidget *widget,
const char *id_property);
/* Convenience functions for plugin & application use */
LIBGLADEUI_API gboolean glade_widget_property_get (GladeWidget *widget,
const char *id_property,
...);
LIBGLADEUI_API gboolean glade_widget_property_set (GladeWidget *widget,
const char *id_property,
...);
LIBGLADEUI_API gboolean glade_widget_pack_property_get (GladeWidget *widget,
const char *id_property,
...);
LIBGLADEUI_API gboolean glade_widget_pack_property_set (GladeWidget *widget,
const char *id_property,
...);
LIBGLADEUI_API gboolean glade_widget_property_set_sensitive (GladeWidget *widget,
const char *id_property,
gboolean sensitive,
const gchar *reason);
LIBGLADEUI_API gboolean glade_widget_pack_property_set_sensitive (GladeWidget *widget,
const char *id_property,
gboolean sensitive,
const gchar *reason);
LIBGLADEUI_API void glade_widget_replace (GladeWidget *parent,
GObject *old_object,
GObject *new_object);
LIBGLADEUI_API void glade_widget_rebuild (GladeWidget *widget);
LIBGLADEUI_API GladeWidget *glade_widget_dup (GladeWidget *widget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment