[glade/flowbox] Support GtkFlowBox
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade/flowbox] Support GtkFlowBox
- Date: Sat, 18 Oct 2014 03:05:06 +0000 (UTC)
commit 08603542c1f2a8fa26ed119a76813617751cffab
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Oct 17 23:03:30 2014 -0400
Support GtkFlowBox
plugins/gtk+/Makefile.am | 1 +
plugins/gtk+/glade-gtk-flow-box.c | 265 ++++++++++++++++++++
plugins/gtk+/gtk+.xml.in | 54 ++++
plugins/gtk+/icons/16x16/Makefile.am | 2 +
plugins/gtk+/icons/16x16/widget-gtk-flowbox.png | Bin 0 -> 381 bytes
.../gtk+/icons/16x16/widget-gtk-flowboxchild.png | Bin 0 -> 365 bytes
plugins/gtk+/icons/22x22/Makefile.am | 2 +
plugins/gtk+/icons/22x22/widget-gtk-flowbox.png | Bin 0 -> 230 bytes
.../gtk+/icons/22x22/widget-gtk-flowboxchild.png | Bin 0 -> 226 bytes
9 files changed, 324 insertions(+), 0 deletions(-)
---
diff --git a/plugins/gtk+/Makefile.am b/plugins/gtk+/Makefile.am
index 6f17c31..7585086 100644
--- a/plugins/gtk+/Makefile.am
+++ b/plugins/gtk+/Makefile.am
@@ -70,6 +70,7 @@ libgladegtk_la_SOURCES = \
glade-gtk-expander.c \
glade-gtk-file-chooser-widget.c \
glade-gtk-fixed-layout.c \
+ glade-gtk-flow-box.c \
glade-gtk-font-chooser-widget.c \
glade-gtk-frame.c \
glade-gtk-grid.c \
diff --git a/plugins/gtk+/glade-gtk-flow-box.c b/plugins/gtk+/glade-gtk-flow-box.c
new file mode 100644
index 0000000..297b97b
--- /dev/null
+++ b/plugins/gtk+/glade-gtk-flow-box.c
@@ -0,0 +1,265 @@
+/*
+ * glade-gtk-flow-box.c - GladeWidgetAdaptor for GtkFlowBox widget
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * Authors:
+ * Matthias Clasen <mclasen redhat 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 <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
+#include <string.h>
+
+#include <gladeui/glade.h>
+#include "glade-gtk.h"
+
+static void
+sync_child_positions (GtkFlowBox *flowbox)
+{
+ GList *l, *children;
+ int position;
+ static gboolean recursion = FALSE;
+
+ /* Avoid feedback loop */
+ if (recursion)
+ return;
+
+ children = gtk_container_get_children (GTK_CONTAINER (flowbox));
+
+ position = 0;
+ for (l = children; l; l = g_list_next (l))
+ {
+ gint old_position;
+
+ glade_widget_pack_property_get (glade_widget_get_from_gobject (l->data),
+ "position", &old_position);
+ if (position != old_position)
+ {
+ /* Update glade with the new value */
+ recursion = TRUE;
+ glade_widget_pack_property_set (glade_widget_get_from_gobject (l->data),
+ "position", position);
+ recursion = FALSE;
+ }
+
+ position++;
+ }
+
+ g_list_free (children);
+}
+
+static void
+glade_gtk_flowbox_insert (GtkFlowBox *flowbox,
+ GtkFlowBoxChild *child,
+ gint position)
+{
+ gtk_flow_box_insert (flowbox, GTK_WIDGET (child), position);
+ sync_child_positions (flowbox);
+}
+
+static void
+glade_gtk_flowbox_reorder (GtkFlowBox *flowbox,
+ GtkFlowBoxChild *child,
+ gint position)
+{
+ gtk_container_remove (GTK_CONTAINER (flowbox), GTK_WIDGET (child));
+ gtk_flow_box_insert (flowbox, GTK_WIDGET (child), position);
+ sync_child_positions (flowbox);
+}
+
+void
+glade_gtk_flowbox_get_child_property (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *child,
+ const gchar *property_name,
+ GValue *value)
+{
+ g_return_if_fail (GTK_IS_FLOW_BOX (container));
+ g_return_if_fail (GTK_IS_FLOW_BOX_CHILD (child));
+
+ if (strcmp (property_name, "position") == 0)
+ {
+ gint position = gtk_flow_box_child_get_index (GTK_FLOW_BOX_CHILD (child));
+ g_value_set_int (value, position);
+ }
+ else
+ {
+ /* Chain Up */
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_get_property (adaptor,
+ container,
+ child,
+ property_name,
+ value);
+ }
+}
+
+void
+glade_gtk_flowbox_set_child_property (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *child,
+ const gchar *property_name,
+ GValue *value)
+{
+ g_return_if_fail (GTK_IS_FLOW_BOX (container));
+ g_return_if_fail (GTK_IS_FLOW_BOX_CHILD (child));
+
+ g_return_if_fail (property_name != NULL || value != NULL);
+
+ if (strcmp (property_name, "position") == 0)
+ {
+ gint position;
+
+ position = g_value_get_int (value);
+ glade_gtk_flowbox_reorder (GTK_FLOW_BOX (container),
+ GTK_FLOW_BOX_CHILD (child),
+ position);
+ }
+ else
+ {
+ /* Chain Up */
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
+ container,
+ child,
+ property_name,
+ value);
+ }
+}
+
+gboolean
+glade_gtk_flowbox_add_verify (GladeWidgetAdaptor *adaptor,
+ GtkWidget *container,
+ GtkWidget *child,
+ gboolean user_feedback)
+{
+ if (!GTK_IS_FLOW_BOX_CHILD (child))
+ {
+ if (user_feedback)
+ {
+ GladeWidgetAdaptor *tool_item_adaptor =
+ glade_widget_adaptor_get_by_type (GTK_TYPE_FLOW_BOX_CHILD);
+
+ glade_util_ui_message (glade_app_get_window (),
+ GLADE_UI_INFO, NULL,
+ ONLY_THIS_GOES_IN_THAT_MSG,
+ glade_widget_adaptor_get_title (tool_item_adaptor),
+ glade_widget_adaptor_get_title (adaptor));
+ }
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void
+glade_gtk_flowbox_add_child (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GObject *child)
+{
+ g_return_if_fail (GTK_IS_FLOW_BOX (object));
+ g_return_if_fail (GTK_IS_FLOW_BOX_CHILD (child));
+
+ /* Insert to the end of the list */
+ glade_gtk_flowbox_insert (GTK_FLOW_BOX (object),
+ GTK_FLOW_BOX_CHILD (child),
+ -1);
+}
+
+void
+glade_gtk_flowbox_remove_child (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GObject *child)
+{
+ gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
+ sync_child_positions (GTK_FLOW_BOX (object));
+}
+
+static void
+glade_gtk_flowbox_child_insert_action (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *object,
+ const gchar *group_format,
+ gboolean after)
+{
+ GladeWidget *parent;
+ GladeWidget *gchild;
+ gint position;
+
+ parent = glade_widget_get_from_gobject (container);
+ glade_command_push_group (group_format, glade_widget_get_name (parent));
+
+ position = gtk_flow_box_child_get_index (GTK_FLOW_BOX_CHILD (object));
+ if (after)
+ position++;
+
+ gchild = glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_FLOW_BOX_CHILD),
+ parent,
+ NULL,
+ glade_widget_get_project (parent));
+ glade_widget_pack_property_set (gchild, "position", position);
+
+ glade_command_pop_group ();
+}
+
+void
+glade_gtk_flowbox_action_activate (GladeWidgetAdaptor * adaptor,
+ GObject * object,
+ const gchar * action_path)
+{
+ if (strcmp (action_path, "add_child") == 0)
+ {
+ GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_FLOW_BOX_CHILD);
+ GladeWidget *gparent = glade_widget_get_from_gobject (object);
+ GladeProject *project = glade_widget_get_project (gparent);
+
+ glade_command_create (adaptor, gparent, NULL, project);
+
+ glade_project_selection_set (project, object, TRUE);
+ }
+ else
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor,
+ object, action_path);
+}
+
+void
+glade_gtk_flowbox_child_action_activate (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *object,
+ const gchar *action_path)
+{
+ if (strcmp (action_path, "insert_after") == 0)
+ {
+ glade_gtk_flowbox_child_insert_action (adaptor, container, object,
+ _("Insert Child on %s"),
+ TRUE);
+ }
+ else if (strcmp (action_path, "insert_before") == 0)
+ {
+ glade_gtk_flowbox_child_insert_action (adaptor, container, object,
+ _("Insert Child on %s"),
+ FALSE);
+ }
+ else
+ {
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor,
+ container,
+ object,
+ action_path);
+ }
+}
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index bf5b006..b8f01a1 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -2464,6 +2464,59 @@
</glade-widget-class>
<glade-widget-class name="GtkListBoxRow" generic-name="listboxrow" _title="List Box Row" since="3.10"/>
+
+ <glade-widget-class name="GtkFlowBox" generic-name="flowbox" _title="Flow Box"
use-placeholders="False" since="3.12">
+
+ <action-activate-function>glade_gtk_flowbox_action_activate</action-activate-function>
+
<child-action-activate-function>glade_gtk_flowbox_child_action_activate</child-action-activate-function>
+ <create-widget-function>glade_gtk_create_fixed_widget</create-widget-function>
+ <!-- We do not want glade_gtk_container_post_create be executed -->
+ <post-create-function>empty</post-create-function>
+ <add-child-verify-function>glade_gtk_flowbox_add_verify</add-child-verify-function>
+ <add-child-function>glade_gtk_flowbox_add_child</add-child-function>
+ <remove-child-function>glade_gtk_flowbox_remove_child</remove-child-function>
+ <child-set-property-function>glade_gtk_flowbox_set_child_property</child-set-property-function>
+ <child-get-property-function>glade_gtk_flowbox_get_child_property</child-get-property-function>
+
+ <actions>
+ <action id="add_child" _name="Add Child" stock="list-add" important="True"/>
+ </actions>
+
+ <packing-actions>
+ <action id="insert_before" _name="Insert Before" stock="list-add"/>
+ <action id="insert_after" _name="Insert After" stock="list-add"/>
+ </packing-actions>
+
+ <properties>
+ <property id="activate-on-single-click" default="True"/>
+ <property id="selection-mode">
+ <displayable-values>
+ <!-- GtkSelectionMode enumeration value -->
+ <value id="GTK_SELECTION_NONE" _name="None"/>
+ <!-- GtkSelectionMode enumeration value -->
+ <value id="GTK_SELECTION_SINGLE" _name="Single"/>
+ <!-- GtkSelectionMode enumeration value -->
+ <value id="GTK_SELECTION_BROWSE" _name="Browse"/>
+ <!-- GtkSelectionMode enumeration value -->
+ <value id="GTK_SELECTION_MULTIPLE" _name="Multiple"/>
+ </displayable-values>
+ </property>
+ </properties>
+
+ <packing-properties>
+ <property id="position" _name="Position" default="0" save="False">
+ <parameter-spec>
+ <type>GParamInt</type>
+ <min>0</min>
+ </parameter-spec>
+ <_tooltip>The position of the child in the flowbox</_tooltip>
+ </property>
+ </packing-properties>
+
+ </glade-widget-class>
+
+ <glade-widget-class name="GtkFlowBoxChild" generic-name="flowboxchild" _title="Flow Box Child"
since="3.12"/>
+
<glade-widget-class name="GtkRange" _title="Range">
<properties>
@@ -5127,6 +5180,7 @@
<glade-widget-class-ref name="GtkFrame"/>
<glade-widget-class-ref name="GtkAspectFrame"/>
<glade-widget-class-ref name="GtkListBox"/>
+ <glade-widget-class-ref name="GtkFlowBox"/>
<glade-widget-class-ref name="GtkOverlay"/>
<glade-widget-class-ref name="GtkMenuBar"/>
<glade-widget-class-ref name="GtkToolbar"/>
diff --git a/plugins/gtk+/icons/16x16/Makefile.am b/plugins/gtk+/icons/16x16/Makefile.am
index baaeba7..a3d7f61 100644
--- a/plugins/gtk+/icons/16x16/Makefile.am
+++ b/plugins/gtk+/icons/16x16/Makefile.am
@@ -46,6 +46,8 @@ icons_DATA = \
widget-gtk-filechooserwidget.png \
widget-gtk-filefilter.png \
widget-gtk-fixed.png \
+ widget-gtk-flowbox.png \
+ widget-gtk-flowboxchild.png \
widget-gtk-fontbutton.png \
widget-gtk-fontselection.png \
widget-gtk-fontselectiondialog.png \
diff --git a/plugins/gtk+/icons/16x16/widget-gtk-flowbox.png b/plugins/gtk+/icons/16x16/widget-gtk-flowbox.png
new file mode 100644
index 0000000..85f2b78
Binary files /dev/null and b/plugins/gtk+/icons/16x16/widget-gtk-flowbox.png differ
diff --git a/plugins/gtk+/icons/16x16/widget-gtk-flowboxchild.png
b/plugins/gtk+/icons/16x16/widget-gtk-flowboxchild.png
new file mode 100644
index 0000000..fbdf6c7
Binary files /dev/null and b/plugins/gtk+/icons/16x16/widget-gtk-flowboxchild.png differ
diff --git a/plugins/gtk+/icons/22x22/Makefile.am b/plugins/gtk+/icons/22x22/Makefile.am
index ff45e33..0a61721 100644
--- a/plugins/gtk+/icons/22x22/Makefile.am
+++ b/plugins/gtk+/icons/22x22/Makefile.am
@@ -46,6 +46,8 @@ icons_DATA = \
widget-gtk-filechooserwidget.png \
widget-gtk-filefilter.png \
widget-gtk-fixed.png \
+ widget-gtk-flowbox.png \
+ widget-gtk-flowboxchild.png \
widget-gtk-fontbutton.png \
widget-gtk-fontselection.png \
widget-gtk-fontselectiondialog.png \
diff --git a/plugins/gtk+/icons/22x22/widget-gtk-flowbox.png b/plugins/gtk+/icons/22x22/widget-gtk-flowbox.png
new file mode 100644
index 0000000..6f2bdb1
Binary files /dev/null and b/plugins/gtk+/icons/22x22/widget-gtk-flowbox.png differ
diff --git a/plugins/gtk+/icons/22x22/widget-gtk-flowboxchild.png
b/plugins/gtk+/icons/22x22/widget-gtk-flowboxchild.png
new file mode 100644
index 0000000..44930e3
Binary files /dev/null and b/plugins/gtk+/icons/22x22/widget-gtk-flowboxchild.png differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]