[glade] GladeEditorProperty: Added GladeEpropCheck type
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] GladeEditorProperty: Added GladeEpropCheck type
- Date: Sun, 14 Apr 2013 09:40:03 +0000 (UTC)
commit 4d55f3bd489376ff78c71df266b4371a1f482cad
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Sun Apr 14 17:54:45 2013 +0900
GladeEditorProperty: Added GladeEpropCheck type
This is a custom boolean editor for embedding in custom editors which
uses a check button... the normal switch based editor is used by default
for cases where we might use a check button in the case the property
is optional.
gladeui/glade-editor-property.c | 93 +++++++++++++++++++++++++++++++++++++++++
gladeui/glade-editor-property.h | 2 +
2 files changed, 95 insertions(+)
---
diff --git a/gladeui/glade-editor-property.c b/gladeui/glade-editor-property.c
index 019039c..a47c1bb 100644
--- a/gladeui/glade-editor-property.c
+++ b/gladeui/glade-editor-property.c
@@ -2366,6 +2366,99 @@ glade_eprop_bool_create_input (GladeEditorProperty *eprop)
return eprop_bool->button;
}
+/*******************************************************************************
+ GladeEditorPropertyCheckClass
+ *******************************************************************************/
+typedef struct
+{
+ GladeEditorProperty parent_instance;
+
+ GtkWidget *button;
+ GtkWidget *label;
+} GladeEPropCheck;
+
+GLADE_MAKE_EPROP (GladeEPropCheck, glade_eprop_check)
+#define GLADE_EPROP_CHECK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_CHECK,
GladeEPropCheck))
+#define GLADE_EPROP_CHECK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_CHECK,
GladeEPropCheckClass))
+#define GLADE_IS_EPROP_CHECK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_CHECK))
+#define GLADE_IS_EPROP_CHECK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_CHECK))
+#define GLADE_EPROP_CHECK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_CHECK,
GladeEPropCheckClass))
+
+static void
+glade_eprop_check_finalize (GObject *object)
+{
+ /* Chain up */
+ G_OBJECT_CLASS (editor_property_class)->finalize (object);
+}
+
+static void
+glade_eprop_check_load (GladeEditorProperty *eprop, GladeProperty *property)
+{
+ GladeEPropCheck *eprop_check = GLADE_EPROP_CHECK (eprop);
+ GladeWidget *widget;
+
+ /* Chain up first */
+ editor_property_class->load (eprop, property);
+
+ /* Load the inner label */
+ widget = glade_property_get_widget (property);
+ if (widget)
+ glade_editable_load (GLADE_EDITABLE (eprop_check->label), widget);
+
+ if (property)
+ {
+ GladeEPropCheck *eprop_check = GLADE_EPROP_CHECK (eprop);
+ gboolean state = g_value_get_boolean (glade_property_inline_value (property));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eprop_check->button), state);
+ }
+}
+
+static void
+glade_eprop_check_active_notify (GObject *gobject,
+ GParamSpec *pspec,
+ GladeEditorProperty *eprop)
+{
+ GValue val = { 0, };
+
+ if (eprop->priv->loading)
+ return;
+
+ g_value_init (&val, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&val, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gobject)));
+
+ glade_editor_property_commit_no_callback (eprop, &val);
+
+ g_value_unset (&val);
+}
+
+static GtkWidget *
+glade_eprop_check_create_input (GladeEditorProperty *eprop)
+{
+ GladeEPropCheck *eprop_check = GLADE_EPROP_CHECK (eprop);
+ GladePropertyClass *pclass;
+
+ pclass = eprop->priv->klass;
+
+ /* Add the property label as the check button's child */
+ eprop_check->label = glade_property_label_new ();
+ glade_property_label_set_property_name (GLADE_PROPERTY_LABEL (eprop_check->label),
+ glade_property_class_id (pclass));
+ glade_property_label_set_packing (GLADE_PROPERTY_LABEL (eprop_check->label),
+ glade_property_class_get_is_packing (pclass));
+ glade_property_label_set_append_colon (GLADE_PROPERTY_LABEL (eprop_check->label), FALSE);
+ gtk_widget_show (eprop_check->label);
+
+ eprop_check->button = gtk_check_button_new ();
+ gtk_container_add (GTK_CONTAINER (eprop_check->button), eprop_check->label);
+
+ gtk_widget_set_halign (eprop_check->button, GTK_ALIGN_START);
+ gtk_widget_set_valign (eprop_check->button, GTK_ALIGN_CENTER);
+
+ g_signal_connect (eprop_check->button, "notify::active",
+ G_CALLBACK (glade_eprop_check_active_notify), eprop);
+
+ return eprop_check->button;
+}
/*******************************************************************************
GladeEditorPropertyUnicharClass
diff --git a/gladeui/glade-editor-property.h b/gladeui/glade-editor-property.h
index 566a71b..e8155bb 100644
--- a/gladeui/glade-editor-property.h
+++ b/gladeui/glade-editor-property.h
@@ -140,6 +140,7 @@ gboolean glade_editor_property_show_object_dialog (GladeProject
#define GLADE_TYPE_EPROP_NAMED_ICON (glade_eprop_named_icon_get_type())
#define GLADE_TYPE_EPROP_TEXT (glade_eprop_text_get_type())
#define GLADE_TYPE_EPROP_BOOL (glade_eprop_bool_get_type())
+#define GLADE_TYPE_EPROP_CHECK (glade_eprop_check_get_type())
#define GLADE_TYPE_EPROP_UNICHAR (glade_eprop_unichar_get_type())
#define GLADE_TYPE_EPROP_OBJECT (glade_eprop_object_get_type())
#define GLADE_TYPE_EPROP_OBJECTS (glade_eprop_objects_get_type())
@@ -150,6 +151,7 @@ GType glade_eprop_color_get_type (void) G_GNUC_CONST;
GType glade_eprop_named_icon_get_type (void) G_GNUC_CONST;
GType glade_eprop_text_get_type (void) G_GNUC_CONST;
GType glade_eprop_bool_get_type (void) G_GNUC_CONST;
+GType glade_eprop_check_get_type (void) G_GNUC_CONST;
GType glade_eprop_unichar_get_type (void) G_GNUC_CONST;
GType glade_eprop_object_get_type (void) G_GNUC_CONST;
GType glade_eprop_objects_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]