glade3 r2005 - in trunk: . gladeui plugins/gtk+
- From: tvb svn gnome org
- To: svn-commits-list gnome org
- Subject: glade3 r2005 - in trunk: . gladeui plugins/gtk+
- Date: Mon, 27 Oct 2008 20:00:35 +0000 (UTC)
Author: tvb
Date: Mon Oct 27 20:00:34 2008
New Revision: 2005
URL: http://svn.gnome.org/viewvc/glade3?rev=2005&view=rev
Log:
* plugins/gtk+/glade-image-editor.[ch], plugins/gtk+/gtk+.xml.in, plugins/gtk+/glade-gtk.c,
gladeui/glade-property-class.c: Override type of GtkImage::icon-size to use real
GTK_TYPE_ICON_SIZE for editing purposes (needed to fix the core a bit for this), also
improved image editor to keep sizes contextual to image edit mode.
Modified:
trunk/ChangeLog
trunk/gladeui/glade-property-class.c
trunk/plugins/gtk+/glade-gtk.c
trunk/plugins/gtk+/glade-image-editor.c
trunk/plugins/gtk+/glade-image-editor.h
trunk/plugins/gtk+/gtk+.xml.in
Modified: trunk/gladeui/glade-property-class.c
==============================================================================
--- trunk/gladeui/glade-property-class.c (original)
+++ trunk/gladeui/glade-property-class.c Mon Oct 27 20:00:34 2008
@@ -1301,7 +1301,7 @@
return TRUE;
}
- /* ...the spec... */
+ /* ...the spec... we could be introducing a new one or even overriding an existing spec... */
buf = glade_xml_get_value_string (node, GLADE_TAG_SPEC);
if (buf)
{
@@ -1313,6 +1313,9 @@
*/
klass->pspec->owner_type = object_type;
+ /* We overrode the pspec, now it *is* a virtual property. */
+ klass->virt = TRUE;
+
if (klass->tooltip) g_free (klass->tooltip);
if (klass->name) g_free (klass->name);
@@ -1322,15 +1325,17 @@
if (klass->pspec->flags & G_PARAM_CONSTRUCT_ONLY)
klass->construct_only = TRUE;
+ if (klass->orig_def) {
+ g_value_unset (klass->orig_def);
+ g_free (klass->orig_def);
+ }
+ klass->orig_def = glade_property_class_get_default_from_spec (klass->pspec);
+
if (klass->def) {
g_value_unset (klass->def);
g_free (klass->def);
}
- klass->def = glade_property_class_get_default_from_spec (klass->pspec);
-
- if (klass->orig_def == NULL)
- klass->orig_def =
- glade_property_class_get_default_from_spec (klass->pspec);
+ klass->def = glade_property_class_get_default_from_spec (klass->pspec);
}
Modified: trunk/plugins/gtk+/glade-gtk.c
==============================================================================
--- trunk/plugins/gtk+/glade-gtk.c (original)
+++ trunk/plugins/gtk+/glade-gtk.c Mon Oct 27 20:00:34 2008
@@ -182,31 +182,15 @@
0, G_PARAM_READWRITE);
}
-
-GType
-glade_gtk_image_type_get_type (void)
-{
- static GType etype = 0;
- if (etype == 0) {
- static GEnumValue values[] = {
- { GLADEGTK_IMAGE_FILENAME, "GLADEGTK_IMAGE_FILENAME", "glade-gtk-image-filename" },
- { GLADEGTK_IMAGE_STOCK, "GLADEGTK_IMAGE_STOCK", "glade-gtk-image-stock" },
- { GLADEGTK_IMAGE_ICONTHEME, "GLADEGTK_IMAGE_ICONTHEME", "glade-gtk-image-icontheme" },
- { 0, NULL, NULL }
- };
-
- etype = g_enum_register_static ("GladeGtkImageType", values);
- }
- return etype;
-}
-
+/* Fake GtkImage::icon-size since its an int pspec in the image */
GParamSpec *
-glade_gtk_image_type_spec (void)
+gladegtk_icon_size_spec (void)
{
- return g_param_spec_enum ("type", _("Method"),
- _("The method to use to edit this image"),
- glade_gtk_image_type_get_type (),
- 1, G_PARAM_READWRITE);
+ return g_param_spec_enum ("icon-size", _("Icon Size"),
+ _("Symbolic size to use for stock icon, icon set or named icon"),
+ GTK_TYPE_ICON_SIZE,
+ GTK_ICON_SIZE_BUTTON,
+ G_PARAM_READWRITE);
}
/* This function does absolutely nothing
@@ -5228,117 +5212,95 @@
GladeXmlContext *context,
GladeXmlNode *node)
{
- GladeXmlNode *prop_node;
GladeProperty *label_prop;
- gboolean use_stock;
- gchar *label = NULL;
- gint stock_id = 0;
+ gboolean use_stock;
+ gchar *stock = NULL;
if (!glade_xml_node_verify
(node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
return;
- /* Start out by writing the use-stock prop so it stays at the top... */
- glade_widget_property_get (widget, "use-stock", &use_stock);
- if (use_stock)
- {
- GEnumClass *eclass;
- GEnumValue *eval;
-
- glade_widget_property_get (widget, "stock", &stock_id);
+ /* First chain up and write all the normal properties (including "use-stock")... */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
- eclass = g_type_class_ref (GLADE_TYPE_STOCK);
- if (stock_id > 0 &&
- (eval = g_enum_get_value (eclass, stock_id)) != NULL)
- label = g_strdup (eval->value_nick);
- g_type_class_unref (eclass);
+ label_prop = glade_widget_get_property (widget, "label");
- if (label)
- {
- /* Good thing stock items dont have translatable stock ids ! :D */
- prop_node = glade_xml_node_new (context, GLADE_XML_TAG_PROPERTY);
- glade_xml_node_append_child (node, prop_node);
-
- /* Name and value */
- glade_xml_node_set_property_string (prop_node, GLADE_XML_TAG_NAME, "label");
- glade_xml_set_content (prop_node, label);
-
- g_free (label);
- }
- }
- else
+ /* Make a copy of the GladeProperty, override its value if use-stock is TRUE */
+ label_prop = glade_property_dup (label_prop, widget);
+ glade_widget_property_get (widget, "use-stock", &use_stock);
+ if (use_stock)
{
- label_prop = glade_widget_get_property (widget, "label");
- glade_property_write (label_prop, context, node);
+ glade_widget_property_get (widget, "stock", &stock);
+ glade_property_set (label_prop, stock);
}
+ glade_property_write (label_prop, context, node);
- /* First chain up and read in all the normal properties.. */
- GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
-
+ g_print ("Finalizing property, ref_count %d\n", G_OBJECT (label_prop)->ref_count);
+ g_object_unref (G_OBJECT (label_prop));
}
/* ----------------------------- GtkImage ------------------------------ */
-static void
-glade_gtk_image_pixel_size_changed (GladeProperty *property,
- GValue *old_value,
- GValue *value,
- GladeWidget *gimage)
-{
- gint size = g_value_get_int (value);
- glade_widget_property_set_sensitive
- (gimage, "icon-size", size < 0 ? TRUE : FALSE,
- _("Pixel Size takes precedence over Icon Size; "
- "if you want to use Icon Size, set Pixel size to -1"));
-}
-
-static void
-glade_gtk_image_parse_finished (GladeProject *project, GladeWidget *gimage)
+void
+glade_gtk_image_read_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlNode *node)
{
- GladeProperty *property;
- gint size;
-
- if (glade_widget_property_original_default (gimage, "icon-name") == FALSE)
- glade_widget_property_set (gimage, "glade-type", GLADEGTK_IMAGE_ICONTHEME);
- else if (glade_widget_property_original_default (gimage, "stock") == FALSE)
- glade_widget_property_set (gimage, "glade-type", GLADEGTK_IMAGE_STOCK);
- else if (glade_widget_property_original_default (gimage, "pixbuf") == FALSE)
- glade_widget_property_set (gimage, "glade-type", GLADEGTK_IMAGE_FILENAME);
- else
- glade_widget_property_reset (gimage, "glade-type");
-
- if ((property = glade_widget_get_property (gimage, "pixel-size")) == NULL)
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
return;
- glade_widget_property_get (gimage, "pixel-size", &size);
-
- if (size >= 0)
- glade_widget_property_set_sensitive (gimage, "icon-size", FALSE,
- _("Pixel Size takes precedence over Icon size"));
+ /* First chain up and read in all the normal properties.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
- g_signal_connect (G_OBJECT (property), "value-changed",
- G_CALLBACK (glade_gtk_image_pixel_size_changed),
- gimage);
+ if (glade_widget_property_original_default (widget, "icon-name") == FALSE)
+ glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_ICON);
+ else if (glade_widget_property_original_default (widget, "stock") == FALSE)
+ glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_STOCK);
+ else if (glade_widget_property_original_default (widget, "pixbuf") == FALSE)
+ glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_FILENAME);
+ else
+ glade_widget_property_reset (widget, "image-mode");
}
+
void
-glade_gtk_image_post_create (GladeWidgetAdaptor *adaptor,
- GObject *object,
- GladeCreateReason reason)
+glade_gtk_image_write_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
{
- GladeWidget *gimage;
-
- if (reason == GLADE_CREATE_LOAD)
+ GladeXmlNode *prop_node;
+ GladeProperty *size_prop;
+ GtkIconSize icon_size;
+ gchar *value;
+
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ return;
+
+ /* First chain up and write all the normal properties (including "use-stock")... */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
+
+ /* We have to save icon-size as an integer, the core will take care of
+ * loading the int value though.
+ */
+ size_prop = glade_widget_get_property (widget, "icon-size");
+ if (!glade_property_original_default (size_prop))
{
- gimage = glade_widget_get_from_gobject (object);
+ prop_node = glade_xml_node_new (context, GLADE_TAG_PROPERTY);
+ glade_xml_node_append_child (node, prop_node);
+
+ glade_xml_node_set_property_string (prop_node, GLADE_TAG_NAME, size_prop->klass->id);
- g_signal_connect (glade_widget_get_project (gimage),
- "parse-finished",
- G_CALLBACK (glade_gtk_image_parse_finished),
- gimage);
+ glade_property_get (size_prop, &icon_size);
+ value = g_strdup_printf ("%d", icon_size);
+ glade_xml_set_content (prop_node, value);
+ g_free (value);
}
}
+
static void
glade_gtk_image_set_image_mode (GObject *object, const GValue *value)
{
@@ -5353,15 +5315,21 @@
glade_widget_property_set_sensitive (gwidget, "stock", FALSE, insensitive_msg);
glade_widget_property_set_sensitive (gwidget, "icon-name", FALSE, insensitive_msg);
glade_widget_property_set_sensitive (gwidget, "pixbuf", FALSE, insensitive_msg);
+ glade_widget_property_set_sensitive (gwidget, "icon-size", FALSE,
+ _("This property only applies to stock images"));
+ glade_widget_property_set_sensitive (gwidget, "pixel-size", FALSE,
+ _("This property only applies to named icons"));
switch ((type = g_value_get_int (value)))
{
case GLADE_IMAGE_MODE_STOCK:
glade_widget_property_set_sensitive (gwidget, "stock", TRUE, NULL);
+ glade_widget_property_set_sensitive (gwidget, "icon-size", TRUE, NULL);
break;
case GLADE_IMAGE_MODE_ICON:
glade_widget_property_set_sensitive (gwidget, "icon-name", TRUE, NULL);
+ glade_widget_property_set_sensitive (gwidget, "pixel-size", TRUE, NULL);
break;
case GLADE_IMAGE_MODE_FILENAME:
@@ -5372,6 +5340,26 @@
}
void
+glade_gtk_image_get_property (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *id,
+ GValue *value)
+{
+ if (!strcmp (id, "icon-size"))
+ {
+ /* Make the int an enum... */
+ GValue int_value = { 0, };
+ g_value_init (&int_value, G_TYPE_INT);
+ GWA_GET_CLASS (GTK_TYPE_WIDGET)->get_property (adaptor, object, id, &int_value);
+ g_value_set_enum (value, g_value_get_int (&int_value));
+ g_value_unset (&int_value);
+ }
+ else
+ GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object,
+ id, value);
+}
+
+void
glade_gtk_image_set_property (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *id,
@@ -5379,11 +5367,21 @@
{
if (!strcmp (id, "image-mode"))
glade_gtk_image_set_image_mode (object, value);
+ else if (!strcmp (id, "icon-size"))
+ {
+ /* Make the enum an int... */
+ GValue int_value = { 0, };
+ g_value_init (&int_value, G_TYPE_INT);
+ g_value_set_int (&int_value, g_value_get_enum (value));
+ GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, &int_value);
+ g_value_unset (&int_value);
+ }
else
GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object,
id, value);
}
+
GladeEditable *
glade_gtk_image_create_editable (GladeWidgetAdaptor *adaptor,
GladeEditorPageType type)
Modified: trunk/plugins/gtk+/glade-image-editor.c
==============================================================================
--- trunk/plugins/gtk+/glade-image-editor.c (original)
+++ trunk/plugins/gtk+/glade-image-editor.c Mon Oct 27 20:00:34 2008
@@ -194,24 +194,12 @@
3, 1);
}
-
static void
-stock_toggled (GtkWidget *widget,
- GladeImageEditor *image_editor)
+set_stock_mode (GladeImageEditor *image_editor)
{
GladeProperty *property;
GValue value = { 0, };
- if (image_editor->loading || !image_editor->loaded_widget)
- return;
-
- if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (image_editor->stock_radio)))
- return;
-
- image_editor->modifying = TRUE;
-
- glade_command_push_group (_("Setting %s to use an image from stock"), image_editor->loaded_widget->name);
-
property = glade_widget_get_property (image_editor->loaded_widget, "icon-name");
glade_command_set_property (property, NULL);
property = glade_widget_get_property (image_editor->loaded_widget, "pixbuf");
@@ -224,7 +212,51 @@
property = glade_widget_get_property (image_editor->loaded_widget, "image-mode");
glade_command_set_property (property, GLADE_IMAGE_MODE_STOCK);
+}
+
+static void
+set_icon_mode (GladeImageEditor *image_editor)
+{
+ GladeProperty *property;
+
+ property = glade_widget_get_property (image_editor->loaded_widget, "stock");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (image_editor->loaded_widget, "pixbuf");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (image_editor->loaded_widget, "image-mode");
+ glade_command_set_property (property, GLADE_IMAGE_MODE_ICON);
+}
+
+
+
+static void
+set_file_mode (GladeImageEditor *image_editor)
+{
+ GladeProperty *property;
+
+ property = glade_widget_get_property (image_editor->loaded_widget, "stock");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (image_editor->loaded_widget, "icon-name");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (image_editor->loaded_widget, "image-mode");
+ glade_command_set_property (property, GLADE_IMAGE_MODE_FILENAME);
+}
+
+static void
+stock_toggled (GtkWidget *widget,
+ GladeImageEditor *image_editor)
+{
+
+ if (image_editor->loading || !image_editor->loaded_widget)
+ return;
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (image_editor->stock_radio)))
+ return;
+
+ image_editor->modifying = TRUE;
+
+ glade_command_push_group (_("Setting %s to use an image from stock"), image_editor->loaded_widget->name);
+ set_stock_mode (image_editor);
glade_command_pop_group ();
image_editor->modifying = FALSE;
@@ -239,8 +271,6 @@
icon_toggled (GtkWidget *widget,
GladeImageEditor *image_editor)
{
- GladeProperty *property;
-
if (image_editor->loading || !image_editor->loaded_widget)
return;
@@ -250,14 +280,7 @@
image_editor->modifying = TRUE;
glade_command_push_group (_("Setting %s to use an image from the icon theme"), image_editor->loaded_widget->name);
-
- property = glade_widget_get_property (image_editor->loaded_widget, "stock");
- glade_command_set_property (property, NULL);
- property = glade_widget_get_property (image_editor->loaded_widget, "pixbuf");
- glade_command_set_property (property, NULL);
- property = glade_widget_get_property (image_editor->loaded_widget, "image-mode");
- glade_command_set_property (property, GLADE_IMAGE_MODE_ICON);
-
+ set_icon_mode (image_editor);
glade_command_pop_group ();
image_editor->modifying = FALSE;
@@ -271,8 +294,6 @@
file_toggled (GtkWidget *widget,
GladeImageEditor *image_editor)
{
- GladeProperty *property;
-
if (image_editor->loading || !image_editor->loaded_widget)
return;
@@ -281,15 +302,8 @@
image_editor->modifying = TRUE;
- glade_command_push_group (_("Setting %s to use an image from the icon theme"), image_editor->loaded_widget->name);
-
- property = glade_widget_get_property (image_editor->loaded_widget, "stock");
- glade_command_set_property (property, NULL);
- property = glade_widget_get_property (image_editor->loaded_widget, "icon-name");
- glade_command_set_property (property, NULL);
- property = glade_widget_get_property (image_editor->loaded_widget, "image-mode");
- glade_command_set_property (property, GLADE_IMAGE_MODE_FILENAME);
-
+ glade_command_push_group (_("Setting %s to use an image from filename"), image_editor->loaded_widget->name);
+ set_file_mode (image_editor);
glade_command_pop_group ();
image_editor->modifying = FALSE;
@@ -318,7 +332,7 @@
/* Pack the parent on top... */
gtk_box_pack_start (GTK_BOX (image_editor), GTK_WIDGET (embed), FALSE, FALSE, 0);
- /* Image area frame... */
+ /* Image content frame... */
str = g_strdup_printf ("<b>%s</b>", _("Edit Image"));
label = gtk_label_new (str);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
@@ -361,6 +375,35 @@
table_attach (table, GTK_WIDGET (eprop), 1, 2);
image_editor->properties = g_list_prepend (image_editor->properties, eprop);
+ /* Image size frame... */
+ str = g_strdup_printf ("<b>%s</b>", _("Set Image Size"));
+ label = gtk_label_new (str);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (str);
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+ gtk_box_pack_start (GTK_BOX (image_editor), frame, FALSE, FALSE, 8);
+
+ alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
+ gtk_container_add (GTK_CONTAINER (frame), alignment);
+
+ table = gtk_table_new (0, 0, FALSE);
+ gtk_container_add (GTK_CONTAINER (alignment), table);
+
+ /* Icon Size... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-size", FALSE, TRUE);
+ table_attach (table, eprop->item_label, 0, 0);
+ table_attach (table, GTK_WIDGET (eprop), 1, 0);
+ image_editor->properties = g_list_prepend (image_editor->properties, eprop);
+
+ /* Pixel Size... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "pixel-size", FALSE, TRUE);
+ table_attach (table, eprop->item_label, 0, 1);
+ table_attach (table, GTK_WIDGET (eprop), 1, 1);
+ image_editor->properties = g_list_prepend (image_editor->properties, eprop);
+
/* Connect radio button signals... */
g_signal_connect (G_OBJECT (image_editor->stock_radio), "toggled",
G_CALLBACK (stock_toggled), image_editor);
Modified: trunk/plugins/gtk+/glade-image-editor.h
==============================================================================
--- trunk/plugins/gtk+/glade-image-editor.h (original)
+++ trunk/plugins/gtk+/glade-image-editor.h Mon Oct 27 20:00:34 2008
@@ -54,6 +54,9 @@
GtkWidget *icon_radio; /* Create the image with the icon theme */
GtkWidget *file_radio; /* Create the image from filename (libglade only) */
+ GtkWidget *size_radio; /* Set size with GtkIconSize */
+ GtkWidget *pixels_radio; /* Set size in Pixel value */
+
GList *properties; /* A list of eprops to update at load() time */
gboolean loading; /* Loading flag for loading widgets in the editor */
Modified: trunk/plugins/gtk+/gtk+.xml.in
==============================================================================
--- trunk/plugins/gtk+/gtk+.xml.in (original)
+++ trunk/plugins/gtk+/gtk+.xml.in Mon Oct 27 20:00:34 2008
@@ -892,10 +892,11 @@
</glade-widget-class>
<glade-widget-class name="GtkImage" generic-name="image" _title="Image">
- <post-create-function>glade_gtk_image_post_create</post-create-function>
<set-property-function>glade_gtk_image_set_property</set-property-function>
+ <get-property-function>glade_gtk_image_get_property</get-property-function>
<create-editable-function>glade_gtk_image_create_editable</create-editable-function>
<read-widget-function>glade_gtk_image_read_widget</read-widget-function>
+ <write-widget-function>glade_gtk_image_write_widget</write-widget-function>
<properties>
<property id="image-mode" save="False" visible="False">
<spec>glade_standard_int_spec</spec>
@@ -903,8 +904,14 @@
<property id="stock" stock-icon="True" custom-layout="True" default="gtk-missing-image"/>
<property id="icon-name" _name="Icon Name" themed-icon="True" custom-layout="True" />
<property id="pixbuf" _name="File Name" custom-layout="True"/>
+ <property id="pixel-size" custom-layout="True"/>
+ <!-- We have to save/load icon-size as int, and fake the enum -->
+ <property id="icon-size" custom-layout="True" save="False">
+ <spec>gladegtk_icon_size_spec</spec>
+ </property>
<property id="pixbuf-animation" disabled="True"/>
<property id="file" disabled="True"/>
+ <property id="gicon" disabled="True"/>
<property id="pixmap" disabled="True"/>
<property id="image" disabled="True"/>
<property id="mask" disabled="True"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]