[glade] Added GladePropertyEditor interface.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] Added GladePropertyEditor interface.
- Date: Sat, 13 Apr 2013 17:50:32 +0000 (UTC)
commit 7afab79bf89356d248fa6b9ce50a1082e70a186a
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Sat Apr 13 17:55:05 2013 +0900
Added GladePropertyEditor interface.
This interface captures the common load_by_widget() semantics used by
GladePropertyLabel, GladePropertyShell and GladeEditorProperty.
gladeui/Makefile.am | 2 ++
gladeui/glade-editor-property.c | 23 +++++++++++++-
gladeui/glade-property-editor.c | 66 +++++++++++++++++++++++++++++++++++++++
gladeui/glade-property-editor.h | 34 +++++++++++++++++++++
gladeui/glade-property-label.c | 68 +++++++++++++++++++++++++----------------
gladeui/glade-property-label.h | 2 --
gladeui/glade-property-shell.c | 48 ++++++++++++++++++-----------
gladeui/glade-property-shell.h | 2 --
8 files changed, 196 insertions(+), 49 deletions(-)
---
diff --git a/gladeui/Makefile.am b/gladeui/Makefile.am
index a68c600..5beb6ae 100644
--- a/gladeui/Makefile.am
+++ b/gladeui/Makefile.am
@@ -102,6 +102,7 @@ libgladeui_2_la_SOURCES = \
glade-project.c \
glade-property.c \
glade-property-class.c \
+ glade-property-editor.c \
glade-property-label.c \
glade-property-shell.c \
glade-signal.c \
@@ -155,6 +156,7 @@ libgladeuiinclude_HEADERS = \
glade-project.h \
glade-property.h \
glade-property-class.h \
+ glade-property-editor.h \
glade-property-label.h \
glade-property-shell.h \
glade-signal.h \
diff --git a/gladeui/glade-editor-property.c b/gladeui/glade-editor-property.c
index ada43bd..4b7ad3b 100644
--- a/gladeui/glade-editor-property.c
+++ b/gladeui/glade-editor-property.c
@@ -40,6 +40,7 @@
#include "glade.h"
#include "glade-widget.h"
+#include "glade-property-editor.h"
#include "glade-editor-property.h"
#include "glade-property-label.h"
#include "glade-property.h"
@@ -105,7 +106,27 @@ struct _GladeEditorPropertyPrivate
guint disable_check : 1; /* Whether to explicitly disable the optional check button */
};
-G_DEFINE_TYPE (GladeEditorProperty, glade_editor_property, GTK_TYPE_BOX);
+static void glade_editor_property_property_editor_init (GladePropertyEditorInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GladeEditorProperty, glade_editor_property, GTK_TYPE_BOX,
+ G_IMPLEMENT_INTERFACE (GLADE_TYPE_PROPERTY_EDITOR,
+ glade_editor_property_property_editor_init));
+
+/*******************************************************************************
+ * GladePropertyEditorInterface *
+ *******************************************************************************/
+static void
+glade_editor_property_property_editor_load (GladePropertyEditor *editor,
+ GladeWidget *widget)
+{
+ glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (editor), widget);
+}
+
+static void
+glade_editor_property_property_editor_init (GladePropertyEditorInterface *iface)
+{
+ iface->load = glade_editor_property_property_editor_load;
+}
/*******************************************************************************
GladeEditorPropertyClass
diff --git a/gladeui/glade-property-editor.c b/gladeui/glade-property-editor.c
new file mode 100644
index 0000000..e4407ce
--- /dev/null
+++ b/gladeui/glade-property-editor.c
@@ -0,0 +1,66 @@
+/*
+ * glade-property-editor.c
+ *
+ * Copyright (C) 2013 Tristan Van Berkom.
+ *
+ * Authors:
+ * Tristan Van Berkom <tvb gnome org>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "glade-widget.h"
+#include "glade-property-editor.h"
+
+G_DEFINE_INTERFACE (GladePropertyEditor, glade_property_editor, GTK_TYPE_WIDGET);
+
+static void
+glade_property_editor_default_init (GladePropertyEditorInterface *iface)
+{
+}
+
+/**
+ * glade_property_editor_load:
+ * @editor: A #GladePropertyEditor
+ * @widget: the #GladeWidget to load
+ *
+ * Loads @editor from @widget
+ */
+void
+glade_property_editor_load (GladePropertyEditor *editor,
+ GladeWidget *widget)
+{
+ GladePropertyEditorInterface *iface;
+
+ g_return_if_fail (GLADE_IS_PROPERTY_EDITOR (editor));
+ g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget));
+
+ iface = GLADE_PROPERTY_EDITOR_GET_IFACE (editor);
+
+ if (iface->load)
+ iface->load (editor, widget);
+ else
+ g_critical ("No GladePropertyEditor::load_by_widget() support on type %s",
+ G_OBJECT_TYPE_NAME (editor));
+}
diff --git a/gladeui/glade-property-editor.h b/gladeui/glade-property-editor.h
new file mode 100644
index 0000000..3b27fcb
--- /dev/null
+++ b/gladeui/glade-property-editor.h
@@ -0,0 +1,34 @@
+#ifndef __GLADE_PROPERTY_EDITOR_H__
+#define __GLADE_PROPERTY_EDITOR_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gladeui/glade-xml-utils.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_PROPERTY_EDITOR (glade_property_editor_get_type ())
+#define GLADE_PROPERTY_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GLADE_TYPE_PROPERTY_EDITOR, GladePropertyEditor))
+#define GLADE_PROPERTY_EDITOR_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GLADE_TYPE_PROPERTY_EDITOR,
GladePropertyEditorInterface))
+#define GLADE_IS_PROPERTY_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GLADE_TYPE_PROPERTY_EDITOR))
+#define GLADE_PROPERTY_EDITOR_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj),
GLADE_TYPE_PROPERTY_EDITOR, GladePropertyEditorInterface))
+
+typedef struct _GladePropertyEditor GladePropertyEditor;
+typedef struct _GladePropertyEditorIface GladePropertyEditorInterface;
+
+struct _GladePropertyEditorIface
+{
+ GTypeInterface g_iface;
+
+ /* virtual table */
+ void (* load) (GladePropertyEditor *editor,
+ GladeWidget *widget);
+};
+
+GType glade_property_editor_get_type (void) G_GNUC_CONST;
+void glade_property_editor_load (GladePropertyEditor *editor,
+ GladeWidget *widget);
+
+G_END_DECLS
+
+#endif /* __GLADE_PROPERTY_EDITOR_H__ */
diff --git a/gladeui/glade-property-label.c b/gladeui/glade-property-label.c
index 34c9795..0b57557 100644
--- a/gladeui/glade-property-label.c
+++ b/gladeui/glade-property-label.c
@@ -28,6 +28,7 @@
#include "glade.h"
#include "glade-widget.h"
#include "glade-popup.h"
+#include "glade-property-editor.h"
#include "glade-property-label.h"
/* GObjectClass */
@@ -46,6 +47,9 @@ static void glade_property_label_get_real_property (GObject *object
static gint glade_property_label_button_press (GtkWidget *widget,
GdkEventButton *event);
+/* GladePropertyEditorInterface */
+static void glade_property_label_property_editor_init (GladePropertyEditorInterface *iface);
+
struct _GladePropertyLabelPrivate
{
GladeProperty *property;
@@ -75,7 +79,9 @@ enum {
PROP_CUSTOM_TOOLTIP,
};
-G_DEFINE_TYPE (GladePropertyLabel, glade_property_label, GTK_TYPE_EVENT_BOX);
+G_DEFINE_TYPE_WITH_CODE (GladePropertyLabel, glade_property_label, GTK_TYPE_EVENT_BOX,
+ G_IMPLEMENT_INTERFACE (GLADE_TYPE_PROPERTY_EDITOR,
+ glade_property_label_property_editor_init));
static void
glade_property_label_init (GladePropertyLabel *label)
@@ -229,6 +235,40 @@ glade_property_label_get_real_property (GObject *object,
}
}
+/*******************************************************************************
+ * GladePropertyEditorInterface *
+ *******************************************************************************/
+static void
+glade_property_label_property_editor_load (GladePropertyEditor *editor,
+ GladeWidget *widget)
+{
+ GladePropertyLabel *label = GLADE_PROPERTY_LABEL (editor);
+ GladePropertyLabelPrivate *priv;
+ GladeProperty *property;
+
+ g_return_if_fail (label->priv->property_name != NULL);
+
+ priv = label->priv;
+
+ if (widget)
+ {
+ if (priv->packing)
+ property = glade_widget_get_pack_property (widget, priv->property_name);
+ else
+ property = glade_widget_get_property (widget, priv->property_name);
+
+ glade_property_label_set_property (label, property);
+ }
+ else
+ glade_property_label_set_property (label, NULL);
+}
+
+static void
+glade_property_label_property_editor_init (GladePropertyEditorInterface *iface)
+{
+ iface->load = glade_property_label_property_editor_load;
+}
+
/***********************************************************
* GtkWidgetClass *
***********************************************************/
@@ -341,32 +381,6 @@ glade_property_label_new (void)
}
void
-glade_property_label_load_by_widget (GladePropertyLabel *label,
- GladeWidget *widget)
-{
- GladePropertyLabelPrivate *priv;
- GladeProperty *property;
-
- g_return_if_fail (GLADE_IS_PROPERTY_LABEL (label));
- g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget));
- g_return_if_fail (label->priv->property_name != NULL);
-
- priv = label->priv;
-
- if (widget)
- {
- if (priv->packing)
- property = glade_widget_get_pack_property (widget, priv->property_name);
- else
- property = glade_widget_get_property (widget, priv->property_name);
-
- glade_property_label_set_property (label, property);
- }
- else
- glade_property_label_set_property (label, NULL);
-}
-
-void
glade_property_label_set_property_name (GladePropertyLabel *label,
const gchar *property_name)
{
diff --git a/gladeui/glade-property-label.h b/gladeui/glade-property-label.h
index b621390..04ab2f2 100644
--- a/gladeui/glade-property-label.h
+++ b/gladeui/glade-property-label.h
@@ -56,8 +56,6 @@ GType glade_property_label_get_type (void) G_GNUC_CONST;
GtkWidget *glade_property_label_new (void);
-void glade_property_label_load_by_widget (GladePropertyLabel *label,
- GladeWidget *widget);
void glade_property_label_set_property_name (GladePropertyLabel *label,
const gchar *property_name);
const gchar *glade_property_label_get_property_name (GladePropertyLabel *label);
diff --git a/gladeui/glade-property-shell.c b/gladeui/glade-property-shell.c
index b491fa2..5a73de4 100644
--- a/gladeui/glade-property-shell.c
+++ b/gladeui/glade-property-shell.c
@@ -28,6 +28,7 @@
#include "glade.h"
#include "glade-widget.h"
#include "glade-popup.h"
+#include "glade-property-editor.h"
#include "glade-property-shell.h"
/* GObjectClass */
@@ -41,6 +42,9 @@ static void glade_property_shell_get_real_property (GObject *object
GValue *value,
GParamSpec *pspec);
+/* GladePropertyEditorInterface */
+static void glade_property_shell_property_editor_init (GladePropertyEditorInterface *iface);
+
struct _GladePropertyShellPrivate
{
/* Current State */
@@ -60,7 +64,9 @@ enum {
PROP_USE_COMMAND,
};
-G_DEFINE_TYPE (GladePropertyShell, glade_property_shell, GTK_TYPE_BOX);
+G_DEFINE_TYPE_WITH_CODE (GladePropertyShell, glade_property_shell, GTK_TYPE_BOX,
+ G_IMPLEMENT_INTERFACE (GLADE_TYPE_PROPERTY_EDITOR,
+ glade_property_shell_property_editor_init));
static void
glade_property_shell_init (GladePropertyShell *shell)
@@ -168,23 +174,16 @@ glade_property_shell_get_real_property (GObject *object,
}
}
-/***********************************************************
- * API *
- ***********************************************************/
-GtkWidget *
-glade_property_shell_new (void)
-{
- return g_object_new (GLADE_TYPE_PROPERTY_SHELL, NULL);
-}
-
-void
-glade_property_shell_load_by_widget (GladePropertyShell *shell,
- GladeWidget *widget)
+/*******************************************************************************
+ * GladePropertyEditorInterface *
+ *******************************************************************************/
+static void
+glade_property_shell_property_editor_load (GladePropertyEditor *editor,
+ GladeWidget *widget)
{
+ GladePropertyShell *shell = GLADE_PROPERTY_SHELL (editor);
GladePropertyShellPrivate *priv;
- g_return_if_fail (GLADE_IS_PROPERTY_SHELL (shell));
- g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget));
g_return_if_fail (shell->priv->property_name != NULL);
priv = shell->priv;
@@ -213,10 +212,25 @@ glade_property_shell_load_by_widget (GladePropertyShell *shell,
/* If we have an editor for the right adaptor, load it */
if (priv->property_editor)
- glade_editor_property_load_by_widget (priv->property_editor, widget);
+ glade_property_editor_load (GLADE_PROPERTY_EDITOR (priv->property_editor), widget);
}
else if (priv->property_editor)
- glade_editor_property_load_by_widget (priv->property_editor, NULL);
+ glade_property_editor_load (GLADE_PROPERTY_EDITOR (priv->property_editor), NULL);
+}
+
+static void
+glade_property_shell_property_editor_init (GladePropertyEditorInterface *iface)
+{
+ iface->load = glade_property_shell_property_editor_load;
+}
+
+/***********************************************************
+ * API *
+ ***********************************************************/
+GtkWidget *
+glade_property_shell_new (void)
+{
+ return g_object_new (GLADE_TYPE_PROPERTY_SHELL, NULL);
}
void
diff --git a/gladeui/glade-property-shell.h b/gladeui/glade-property-shell.h
index 75b168d..2c4c8fe 100644
--- a/gladeui/glade-property-shell.h
+++ b/gladeui/glade-property-shell.h
@@ -56,8 +56,6 @@ GType glade_property_shell_get_type (void) G_GNUC_CONST;
GtkWidget *glade_property_shell_new (void);
-void glade_property_shell_load_by_widget (GladePropertyShell *shell,
- GladeWidget *widget);
void glade_property_shell_set_property_name (GladePropertyShell *shell,
const gchar *property_name);
const gchar *glade_property_shell_get_property_name (GladePropertyShell *shell);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]