[glade] Added GtkOverlay support
- From: Juan Pablo Ugarte <jpu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] Added GtkOverlay support
- Date: Mon, 19 Aug 2013 18:54:41 +0000 (UTC)
commit c456aba9ec07dbcdebdd85b4a7756b3563e5ab14
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date: Thu Jul 11 17:26:09 2013 -0300
Added GtkOverlay support
plugins/gtk+/Makefile.am | 1 +
plugins/gtk+/glade-gtk-overlay.c | 192 ++++++++++++++++++++++++++++++++++++++
plugins/gtk+/gtk+.xml.in | 11 ++-
3 files changed, 203 insertions(+), 1 deletions(-)
---
diff --git a/plugins/gtk+/Makefile.am b/plugins/gtk+/Makefile.am
index 1ccf40a..6f17c31 100644
--- a/plugins/gtk+/Makefile.am
+++ b/plugins/gtk+/Makefile.am
@@ -89,6 +89,7 @@ libgladegtk_la_SOURCES = \
glade-gtk-menu-tool-button.c \
glade-gtk-message-dialog.c \
glade-gtk-notebook.c \
+ glade-gtk-overlay.c \
glade-gtk-paned.c \
glade-gtk-progress-bar.c \
glade-gtk-radio-button.c \
diff --git a/plugins/gtk+/glade-gtk-overlay.c b/plugins/gtk+/glade-gtk-overlay.c
new file mode 100644
index 0000000..c509135
--- /dev/null
+++ b/plugins/gtk+/glade-gtk-overlay.c
@@ -0,0 +1,192 @@
+/*
+ * glade-gtk-overlay.c - GladeWidgetAdaptor for GtkOverlay widget
+ *
+ * Copyright (C) 2013 Juan Pablo Ugarte
+ *
+ * Authors:
+ * Juan Pablo Ugarte <juanpablougarte 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 "glade-gtk.h"
+#include <gladeui/glade.h>
+#include <glib/gi18n-lib.h>
+#include <string.h>
+
+typedef struct
+{
+ GtkWidget *bin_child;
+ GtkWidget *overlay_child;
+} VisibilityData;
+
+static void
+set_children_visibility (GtkWidget *widget, gpointer user_data)
+{
+ VisibilityData *data = user_data;
+
+ /* We never hide the main child */
+ if (widget == data->bin_child)
+ return;
+
+ /* We only hide overlay children when one of them is selected */
+ if (data->overlay_child)
+ gtk_widget_set_visible (widget, widget == data->overlay_child);
+ else
+ /* otherwhise we show them so we can interact with the container */
+ gtk_widget_set_visible (widget, TRUE);
+}
+
+static inline GtkWidget *
+get_overlay_children (GtkWidget *deep_child, GtkWidget *overlay)
+{
+ GtkWidget *parent = deep_child;
+
+ while (parent)
+ {
+ if (parent == overlay)
+ return deep_child;
+
+ deep_child = parent;
+ parent = gtk_widget_get_parent (parent);
+ }
+
+ return NULL;
+}
+
+static void
+on_project_selection_changed (GladeProject *project, GtkWidget *overlay)
+{
+ VisibilityData data = { gtk_bin_get_child (GTK_BIN (overlay)), NULL };
+ GList *l;
+
+ for (l = glade_project_selection_get (project); l; l = g_list_next (l))
+ {
+ GtkWidget *selection;
+
+ if (GTK_IS_WIDGET (l->data) && (selection = GTK_WIDGET (l->data)) &&
+ overlay != selection)
+ data.overlay_child = get_overlay_children (selection, overlay);
+
+ if (data.overlay_child)
+ break;
+ }
+
+ gtk_container_foreach (GTK_CONTAINER (overlay), set_children_visibility, &data);
+}
+
+static void
+on_widget_project_notify (GObject *gobject,
+ GParamSpec *pspec,
+ GladeProject *old_project)
+{
+ GladeWidget *gwidget = GLADE_WIDGET (gobject);
+ GladeProject *project = glade_widget_get_project (gwidget);
+ GObject *object = glade_widget_get_object (gwidget);
+
+ if (old_project)
+ g_signal_handlers_disconnect_by_func (old_project, on_project_selection_changed, object);
+
+ g_signal_handlers_disconnect_by_func (gwidget, on_widget_project_notify, old_project);
+
+ g_signal_connect_object (gwidget, "notify::project",
+ G_CALLBACK (on_widget_project_notify),
+ project, 0);
+
+ if (project)
+ g_signal_connect_object (project, "selection-changed",
+ G_CALLBACK (on_project_selection_changed),
+ object, 0);
+}
+
+void
+glade_gtk_overlay_post_create (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GladeCreateReason reason)
+{
+ if (reason == GLADE_CREATE_USER)
+ gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ());
+
+ on_widget_project_notify (G_OBJECT (glade_widget_get_from_gobject (object)),
+ NULL, NULL);
+}
+
+gboolean
+glade_gtk_overlay_add_verify (GladeWidgetAdaptor *adaptor,
+ GtkWidget *container,
+ GtkWidget *child,
+ gboolean user_feedback)
+{
+ if (!GTK_IS_WIDGET (child))
+ {
+ if (user_feedback)
+ {
+ GladeWidgetAdaptor *widget_adaptor =
+ glade_widget_adaptor_get_by_type (GTK_TYPE_WIDGET);
+
+ glade_util_ui_message (glade_app_get_window (),
+ GLADE_UI_INFO, NULL,
+ ONLY_THIS_GOES_IN_THAT_MSG,
+ glade_widget_adaptor_get_title (widget_adaptor),
+ glade_widget_adaptor_get_title (adaptor));
+ }
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void
+glade_gtk_overlay_add_child (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GObject *child)
+{
+ gchar *special_type = g_object_get_data (child, "special-child-type");
+ GtkWidget *bin_child;
+
+ if ((special_type && !strcmp (special_type, "overlay")) ||
+ ((bin_child = gtk_bin_get_child (GTK_BIN (object))) &&
+ !GLADE_IS_PLACEHOLDER (bin_child)))
+ {
+ g_object_set_data (child, "special-child-type", "overlay");
+ gtk_overlay_add_overlay (GTK_OVERLAY (object), GTK_WIDGET (child));
+ }
+ else
+ /* Chain Up */
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->add (adaptor, object, child);
+}
+
+void
+glade_gtk_overlay_remove_child (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GObject *child)
+{
+ gchar *special_type = g_object_get_data (child, "special-child-type");
+
+ if (special_type && !strcmp (special_type, "overlay"))
+ {
+ g_object_set_data (child, "special-child-type", NULL);
+ gtk_widget_show (GTK_WIDGET (child));
+ }
+
+ gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
+
+ if (gtk_bin_get_child (GTK_BIN (object)) == NULL)
+ gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ());
+}
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index f3f7851..63ad273 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -544,7 +544,16 @@ embedded in another object</_tooltip>
</properties>
</glade-widget-class>
- <glade-widget-class name="GtkOverlay" generic-name="overlay" _title="Overlay" since="3.2"
icon-name="widget-gtk-frame"/>
+ <glade-widget-class name="GtkOverlay" generic-name="overlay" _title="Overlay" since="3.2"
+ icon-name="widget-gtk-frame"
+ use-placeholders="False">
+ <post-create-function>glade_gtk_overlay_post_create</post-create-function>
+ <add-child-verify-function>glade_gtk_overlay_add_verify</add-child-verify-function>
+ <add-child-function>glade_gtk_overlay_add_child</add-child-function>
+ <remove-child-function>glade_gtk_overlay_remove_child</remove-child-function>
+
<get-child-at-position-function>glade_gtk_overlay_get_child_at_position</get-child-at-position-function>
+ <special-child-type>overlay</special-child-type>
+ </glade-widget-class>
<glade-widget-class name="GtkMenuShell" _title="Menu Shell" use-placeholders="False" since="2.16">
<post-create-function>empty</post-create-function>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]