[glade] Move GladeWidgetAdaptor code for GtkFrame into it's own C file
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] Move GladeWidgetAdaptor code for GtkFrame into it's own C file
- Date: Fri, 3 May 2013 17:06:27 +0000 (UTC)
commit 0d48de27ec6ffc7be5ca2fc20cde0e0652fa0a55
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Fri May 3 22:07:47 2013 +0900
Move GladeWidgetAdaptor code for GtkFrame into it's own C file
plugins/gtk+/Makefile.am | 2 +
plugins/gtk+/glade-gtk-frame.c | 207 ++++++++++++++++++++++++++++++++++++++++
plugins/gtk+/glade-gtk-frame.h | 39 ++++++++
plugins/gtk+/glade-gtk.c | 190 +------------------------------------
po/POTFILES.in | 1 +
5 files changed, 253 insertions(+), 186 deletions(-)
---
diff --git a/plugins/gtk+/Makefile.am b/plugins/gtk+/Makefile.am
index f93ab70..73b8652 100644
--- a/plugins/gtk+/Makefile.am
+++ b/plugins/gtk+/Makefile.am
@@ -36,6 +36,7 @@ libgladegtk_la_SOURCES = \
glade-gtk-action-widgets.c \
glade-gtk-box.c \
glade-gtk-container.c \
+ glade-gtk-frame.c \
glade-gtk-grid.c \
glade-gtk-info-bar.c \
glade-gtk-switch.c \
@@ -70,6 +71,7 @@ noinst_HEADERS = \
glade-fixed.h \
glade-gtk.h \
glade-gtk-action-widgets.h \
+ glade-gtk-frame.h \
glade-icon-factory-editor.h \
glade-icon-sources.h \
glade-image-editor.h \
diff --git a/plugins/gtk+/glade-gtk-frame.c b/plugins/gtk+/glade-gtk-frame.c
new file mode 100644
index 0000000..47bab99
--- /dev/null
+++ b/plugins/gtk+/glade-gtk-frame.c
@@ -0,0 +1,207 @@
+/*
+ * glade-gtk-frame.c - GladeWidgetAdaptor for GtkFrame
+ *
+ * Copyright (C) 2013 Tristan Van Berkom
+ *
+ * Authors:
+ * Tristan Van Berkom <tristan van berkom gmail com>
+ *
+ * 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.
+ */
+#include <config.h>
+#include <glib/gi18n-lib.h>
+#include <gladeui/glade.h>
+
+#include "glade-gtk-frame.h"
+
+void
+glade_gtk_frame_post_create (GladeWidgetAdaptor * adaptor,
+ GObject * frame, GladeCreateReason reason)
+{
+ static GladeWidgetAdaptor *label_adaptor = NULL, *alignment_adaptor = NULL;
+ GladeWidget *gframe, *glabel, *galignment;
+ GtkWidget *label;
+ gchar *label_text;
+
+ if (reason != GLADE_CREATE_USER)
+ return;
+
+ g_return_if_fail (GTK_IS_FRAME (frame));
+ gframe = glade_widget_get_from_gobject (frame);
+ g_return_if_fail (GLADE_IS_WIDGET (gframe));
+
+ /* If we didnt put this object here or if frame is an aspect frame... */
+ if (((label = gtk_frame_get_label_widget (GTK_FRAME (frame))) == NULL ||
+ (glade_widget_get_from_gobject (label) == NULL)) &&
+ (GTK_IS_ASPECT_FRAME (frame) == FALSE))
+ {
+
+ if (label_adaptor == NULL)
+ label_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL);
+ if (alignment_adaptor == NULL)
+ alignment_adaptor =
+ glade_widget_adaptor_get_by_type (GTK_TYPE_ALIGNMENT);
+
+ /* add label (as an internal child) */
+ glabel = glade_widget_adaptor_create_widget (label_adaptor, FALSE,
+ "parent", gframe,
+ "project",
+ glade_widget_get_project
+ (gframe), NULL);
+
+ label_text =
+ g_strdup_printf ("<b>%s</b>", glade_widget_get_name (gframe));
+ glade_widget_property_set (glabel, "label", label_text);
+ glade_widget_property_set (glabel, "use-markup", "TRUE");
+ g_free (label_text);
+
+ g_object_set_data (glade_widget_get_object (glabel),
+ "special-child-type", "label_item");
+ glade_widget_add_child (gframe, glabel, FALSE);
+
+ /* add alignment */
+ galignment = glade_widget_adaptor_create_widget (alignment_adaptor, FALSE,
+ "parent", gframe,
+ "project",
+ glade_widget_get_project
+ (gframe), NULL);
+
+ glade_widget_property_set (galignment, "left-padding", 12);
+ glade_widget_add_child (gframe, galignment, FALSE);
+ }
+
+ /* Chain Up */
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->post_create (adaptor, frame, reason);
+}
+
+void
+glade_gtk_frame_replace_child (GladeWidgetAdaptor * adaptor,
+ GtkWidget * container,
+ GtkWidget * current, GtkWidget * new_widget)
+{
+ gchar *special_child_type;
+
+ special_child_type =
+ g_object_get_data (G_OBJECT (current), "special-child-type");
+
+ if (special_child_type && !strcmp (special_child_type, "label_item"))
+ {
+ g_object_set_data (G_OBJECT (new_widget), "special-child-type",
+ "label_item");
+ gtk_frame_set_label_widget (GTK_FRAME (container), new_widget);
+ return;
+ }
+
+ /* Chain Up */
+ GWA_GET_CLASS
+ (GTK_TYPE_CONTAINER)->replace_child (adaptor,
+ G_OBJECT (container),
+ G_OBJECT (current),
+ G_OBJECT (new_widget));
+}
+
+void
+glade_gtk_frame_add_child (GladeWidgetAdaptor * adaptor,
+ GObject * object, GObject * child)
+{
+ GtkWidget *bin_child;
+ gchar *special_child_type;
+
+ special_child_type = g_object_get_data (child, "special-child-type");
+
+ if (special_child_type && !strcmp (special_child_type, "label"))
+ {
+ g_object_set_data (child, "special-child-type", "label_item");
+ gtk_frame_set_label_widget (GTK_FRAME (object), GTK_WIDGET (child));
+ }
+ else if (special_child_type && !strcmp (special_child_type, "label_item"))
+ {
+ gtk_frame_set_label_widget (GTK_FRAME (object), GTK_WIDGET (child));
+ }
+ else
+ {
+ /* Get a placeholder out of the way before adding the child
+ */
+ bin_child = gtk_bin_get_child (GTK_BIN (object));
+ if (bin_child)
+ {
+ if (GLADE_IS_PLACEHOLDER (bin_child))
+ gtk_container_remove (GTK_CONTAINER (object), bin_child);
+ else
+ {
+ g_critical ("Cant add more than one widget to a GtkFrame");
+ return;
+ }
+ }
+ gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
+ }
+}
+
+void
+glade_gtk_frame_remove_child (GladeWidgetAdaptor * adaptor,
+ GObject * object, GObject * child)
+{
+ gchar *special_child_type;
+
+ special_child_type = g_object_get_data (child, "special-child-type");
+ if (special_child_type && !strcmp (special_child_type, "label_item"))
+ {
+ gtk_frame_set_label_widget (GTK_FRAME (object), glade_placeholder_new ());
+ }
+ else
+ {
+ gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
+ gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ());
+ }
+}
+
+void
+glade_gtk_frame_write_child (GladeWidgetAdaptor * adaptor,
+ GladeWidget * widget,
+ GladeXmlContext * context, GladeXmlNode * node)
+{
+
+ if (!glade_gtk_write_special_child_label_item (adaptor, widget, context, node,
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->write_child))
+ /* Chain Up */
+ GWA_GET_CLASS
+ (GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, node);
+}
+
+/* Shared with GtkExpander code */
+gboolean
+glade_gtk_write_special_child_label_item (GladeWidgetAdaptor * adaptor,
+ GladeWidget * widget,
+ GladeXmlContext * context,
+ GladeXmlNode * node,
+ GladeWriteWidgetFunc write_func)
+{
+ gchar *special_child_type = NULL;
+ GObject *child;
+
+ child = glade_widget_get_object (widget);
+ if (child)
+ special_child_type = g_object_get_data (child, "special-child-type");
+
+ if (special_child_type && !strcmp (special_child_type, "label_item"))
+ {
+ g_object_set_data (child, "special-child-type", "label");
+ write_func (adaptor, widget, context, node);
+ g_object_set_data (child, "special-child-type", "label_item");
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
diff --git a/plugins/gtk+/glade-gtk-frame.h b/plugins/gtk+/glade-gtk-frame.h
new file mode 100644
index 0000000..076ac64
--- /dev/null
+++ b/plugins/gtk+/glade-gtk-frame.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 Tristan Van Berkom.
+ *
+ * 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.
+ *
+ * Authors:
+ * Tristan Van Berkom <tvb gnome org>
+ */
+#ifndef _GLADE_GTK_FRAME_H_
+#define _GLADE_GTK_FRAME_H_
+
+#include <gtk/gtk.h>
+#include <gladeui/glade.h>
+
+G_BEGIN_DECLS
+
+gboolean
+glade_gtk_write_special_child_label_item (GladeWidgetAdaptor * adaptor,
+ GladeWidget * widget,
+ GladeXmlContext * context,
+ GladeXmlNode * node,
+ GladeWriteWidgetFunc write_func);
+
+
+G_END_DECLS
+
+#endif /* _GLADE_GTK_FRAME_H_ */
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 16e240e..fbca6a8 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -25,6 +25,7 @@
#include <config.h>
#include "glade-gtk.h"
+#include "glade-gtk-frame.h"
#include "glade-about-dialog-editor.h"
#include "glade-accels.h"
#include "glade-activatable-editor.h"
@@ -84,189 +85,6 @@ glade_gtk_init (const gchar * name)
{
}
-/* ----------------- Generic GladeFixed constructor ------------------ */
-
-/* ----------------------------- GtkFrame ------------------------------ */
-void
-glade_gtk_frame_post_create (GladeWidgetAdaptor * adaptor,
- GObject * frame, GladeCreateReason reason)
-{
- static GladeWidgetAdaptor *label_adaptor = NULL, *alignment_adaptor = NULL;
- GladeWidget *gframe, *glabel, *galignment;
- GtkWidget *label;
- gchar *label_text;
-
- if (reason != GLADE_CREATE_USER)
- return;
-
- g_return_if_fail (GTK_IS_FRAME (frame));
- gframe = glade_widget_get_from_gobject (frame);
- g_return_if_fail (GLADE_IS_WIDGET (gframe));
-
- /* If we didnt put this object here or if frame is an aspect frame... */
- if (((label = gtk_frame_get_label_widget (GTK_FRAME (frame))) == NULL ||
- (glade_widget_get_from_gobject (label) == NULL)) &&
- (GTK_IS_ASPECT_FRAME (frame) == FALSE))
- {
-
- if (label_adaptor == NULL)
- label_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL);
- if (alignment_adaptor == NULL)
- alignment_adaptor =
- glade_widget_adaptor_get_by_type (GTK_TYPE_ALIGNMENT);
-
- /* add label (as an internal child) */
- glabel = glade_widget_adaptor_create_widget (label_adaptor, FALSE,
- "parent", gframe,
- "project",
- glade_widget_get_project
- (gframe), NULL);
-
- label_text =
- g_strdup_printf ("<b>%s</b>", glade_widget_get_name (gframe));
- glade_widget_property_set (glabel, "label", label_text);
- glade_widget_property_set (glabel, "use-markup", "TRUE");
- g_free (label_text);
-
- g_object_set_data (glade_widget_get_object (glabel),
- "special-child-type", "label_item");
- glade_widget_add_child (gframe, glabel, FALSE);
-
- /* add alignment */
- galignment = glade_widget_adaptor_create_widget (alignment_adaptor, FALSE,
- "parent", gframe,
- "project",
- glade_widget_get_project
- (gframe), NULL);
-
- glade_widget_property_set (galignment, "left-padding", 12);
- glade_widget_add_child (gframe, galignment, FALSE);
- }
-
- /* Chain Up */
- GWA_GET_CLASS (GTK_TYPE_CONTAINER)->post_create (adaptor, frame, reason);
-}
-
-void
-glade_gtk_frame_replace_child (GladeWidgetAdaptor * adaptor,
- GtkWidget * container,
- GtkWidget * current, GtkWidget * new_widget)
-{
- gchar *special_child_type;
-
- special_child_type =
- g_object_get_data (G_OBJECT (current), "special-child-type");
-
- if (special_child_type && !strcmp (special_child_type, "label_item"))
- {
- g_object_set_data (G_OBJECT (new_widget), "special-child-type",
- "label_item");
- gtk_frame_set_label_widget (GTK_FRAME (container), new_widget);
- return;
- }
-
- /* Chain Up */
- GWA_GET_CLASS
- (GTK_TYPE_CONTAINER)->replace_child (adaptor,
- G_OBJECT (container),
- G_OBJECT (current),
- G_OBJECT (new_widget));
-}
-
-void
-glade_gtk_frame_add_child (GladeWidgetAdaptor * adaptor,
- GObject * object, GObject * child)
-{
- GtkWidget *bin_child;
- gchar *special_child_type;
-
- special_child_type = g_object_get_data (child, "special-child-type");
-
- if (special_child_type && !strcmp (special_child_type, "label"))
- {
- g_object_set_data (child, "special-child-type", "label_item");
- gtk_frame_set_label_widget (GTK_FRAME (object), GTK_WIDGET (child));
- }
- else if (special_child_type && !strcmp (special_child_type, "label_item"))
- {
- gtk_frame_set_label_widget (GTK_FRAME (object), GTK_WIDGET (child));
- }
- else
- {
- /* Get a placeholder out of the way before adding the child
- */
- bin_child = gtk_bin_get_child (GTK_BIN (object));
- if (bin_child)
- {
- if (GLADE_IS_PLACEHOLDER (bin_child))
- gtk_container_remove (GTK_CONTAINER (object), bin_child);
- else
- {
- g_critical ("Cant add more than one widget to a GtkFrame");
- return;
- }
- }
- gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
- }
-}
-
-void
-glade_gtk_frame_remove_child (GladeWidgetAdaptor * adaptor,
- GObject * object, GObject * child)
-{
- gchar *special_child_type;
-
- special_child_type = g_object_get_data (child, "special-child-type");
- if (special_child_type && !strcmp (special_child_type, "label_item"))
- {
- gtk_frame_set_label_widget (GTK_FRAME (object), glade_placeholder_new ());
- }
- else
- {
- gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
- gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ());
- }
-}
-
-static gboolean
-write_special_child_label_item (GladeWidgetAdaptor * adaptor,
- GladeWidget * widget,
- GladeXmlContext * context,
- GladeXmlNode * node,
- GladeWriteWidgetFunc write_func)
-{
- gchar *special_child_type = NULL;
- GObject *child;
-
- child = glade_widget_get_object (widget);
- if (child)
- special_child_type = g_object_get_data (child, "special-child-type");
-
- if (special_child_type && !strcmp (special_child_type, "label_item"))
- {
- g_object_set_data (child, "special-child-type", "label");
- write_func (adaptor, widget, context, node);
- g_object_set_data (child, "special-child-type", "label_item");
- return TRUE;
- }
- else
- return FALSE;
-}
-
-void
-glade_gtk_frame_write_child (GladeWidgetAdaptor * adaptor,
- GladeWidget * widget,
- GladeXmlContext * context, GladeXmlNode * node)
-{
-
- if (!write_special_child_label_item (adaptor, widget, context, node,
- GWA_GET_CLASS (GTK_TYPE_CONTAINER)->
- write_child))
- /* Chain Up */
- GWA_GET_CLASS
- (GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, node);
-}
-
/* ----------------------------- GtkNotebook ------------------------------ */
typedef struct
{
@@ -1453,9 +1271,9 @@ glade_gtk_expander_write_child (GladeWidgetAdaptor * adaptor,
GladeXmlContext * context, GladeXmlNode * node)
{
- if (!write_special_child_label_item (adaptor, widget, context, node,
- GWA_GET_CLASS (GTK_TYPE_CONTAINER)->
- write_child))
+ if (!glade_gtk_write_special_child_label_item (adaptor, widget, context, node,
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->
+ write_child))
/* Chain Up */
GWA_GET_CLASS
(GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, node);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c16bcad..7ae7e28 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -64,6 +64,7 @@ plugins/gtk+/glade-fixed.c
plugins/gtk+/glade-gtk.c
plugins/gtk+/glade-gtk-box.c
plugins/gtk+/glade-gtk-container.c
+plugins/gtk+/glade-gtk-frame.c
plugins/gtk+/glade-gtk-grid.c
plugins/gtk+/glade-gtk-table.c
plugins/gtk+/glade-gtk-widget.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]