[glade] Support GtkActionBar



commit 0c3658f962939fbfa65b637e16acd7706c6a35ad
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Nov 12 20:04:25 2014 -0500

    Support GtkActionBar

 plugins/gtk+/Makefile.am                          |    4 +
 plugins/gtk+/glade-action-bar-editor.c            |  160 +++++++
 plugins/gtk+/glade-action-bar-editor.h            |   57 +++
 plugins/gtk+/glade-action-bar-editor.ui           |  131 ++++++
 plugins/gtk+/glade-gtk-action-bar.c               |  499 +++++++++++++++++++++
 plugins/gtk+/glade-gtk-resources.gresource.xml    |    1 +
 plugins/gtk+/gtk+.xml.in                          |   40 ++
 plugins/gtk+/icons/16x16/Makefile.am              |    1 +
 plugins/gtk+/icons/16x16/widget-gtk-actionbar.png |  Bin 0 -> 340 bytes
 plugins/gtk+/icons/22x22/Makefile.am              |    1 +
 plugins/gtk+/icons/22x22/widget-gtk-actionbar.png |  Bin 0 -> 285 bytes
 11 files changed, 894 insertions(+), 0 deletions(-)
---
diff --git a/plugins/gtk+/Makefile.am b/plugins/gtk+/Makefile.am
index 6139d28..1d628fb 100644
--- a/plugins/gtk+/Makefile.am
+++ b/plugins/gtk+/Makefile.am
@@ -31,6 +31,7 @@ libgladegtk_la_SOURCES =              \
        glade-app-chooser-widget-editor.c \
        glade-arrow-editor.c            \
        glade-attributes.c              \
+       glade-action-bar-editor.c       \
        glade-box-editor.c              \
        glade-button-editor.c           \
        glade-cell-renderer-editor.c    \
@@ -50,6 +51,7 @@ libgladegtk_la_SOURCES =              \
        glade-grid-editor.c             \
        glade-gtk-about-dialog.c        \
        glade-gtk-action.c              \
+       glade-gtk-action-bar.c          \
        glade-gtk-action-group.c        \
        glade-gtk-action-widgets.c      \
        glade-gtk-adjustment.c          \
@@ -178,6 +180,7 @@ noinst_HEADERS =                    \
        glade-app-chooser-widget-editor.h \
        glade-arrow-editor.h            \
        glade-attributes.h              \
+       glade-action-bar-editor.h       \
        glade-box-editor.h              \
        glade-button-editor.h           \
        glade-cell-renderer-editor.h    \
@@ -276,6 +279,7 @@ UI_FILES =                          \
        glade-app-chooser-button-editor.ui \
        glade-app-chooser-widget-editor.ui \
        glade-arrow-editor.ui           \
+       glade-action-bar-editor.ui      \
        glade-box-editor.ui             \
        glade-button-editor.ui          \
        glade-combo-box-editor.ui       \
diff --git a/plugins/gtk+/glade-action-bar-editor.c b/plugins/gtk+/glade-action-bar-editor.c
new file mode 100644
index 0000000..56ae344
--- /dev/null
+++ b/plugins/gtk+/glade-action-bar-editor.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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:
+ *   Matthias Clasen <mclasen redhat com>
+ */
+
+#include <config.h>
+#include <gladeui/glade.h>
+#include <glib/gi18n-lib.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "glade-action-bar-editor.h"
+
+static void glade_action_bar_editor_editable_init (GladeEditableIface * iface);
+static void glade_action_bar_editor_grab_focus (GtkWidget * widget);
+static void use_center_child_toggled (GtkWidget *widget, GladeActionBarEditor * box_editor);
+
+
+struct _GladeActionBarEditorPrivate
+{
+  GtkWidget *embed;
+  GtkWidget *use_center_child;
+};
+
+static GladeEditableIface *parent_editable_iface;
+
+G_DEFINE_TYPE_WITH_CODE (GladeActionBarEditor, glade_action_bar_editor, GLADE_TYPE_EDITOR_SKELETON,
+                         G_ADD_PRIVATE (GladeActionBarEditor)
+                         G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE,
+                                                glade_action_bar_editor_editable_init));
+
+static void
+glade_action_bar_editor_class_init (GladeActionBarEditorClass * klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  widget_class->grab_focus = glade_action_bar_editor_grab_focus;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/gladegtk/glade-action-bar-editor.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, GladeActionBarEditor, embed);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeActionBarEditor, use_center_child);
+
+  gtk_widget_class_bind_template_callback (widget_class, use_center_child_toggled);
+}
+
+static void
+glade_action_bar_editor_init (GladeActionBarEditor * self)
+{
+  self->priv = glade_action_bar_editor_get_instance_private (self);
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+glade_action_bar_editor_grab_focus (GtkWidget * widget)
+{
+  GladeActionBarEditor *box_editor = GLADE_ACTION_BAR_EDITOR (widget);
+  gtk_widget_grab_focus (box_editor->priv->embed);
+}
+
+static void
+glade_action_bar_editor_load (GladeEditable *editable,
+                              GladeWidget   *gwidget)
+{
+  GladeActionBarEditor *box_editor = GLADE_ACTION_BAR_EDITOR (editable);
+  GladeActionBarEditorPrivate *priv = box_editor->priv;
+
+  /* Chain up to default implementation */
+  parent_editable_iface->load (editable, gwidget);
+
+  if (gwidget)
+    {
+      gboolean use_center_child;
+      glade_widget_property_get (gwidget, "use-center-child", &use_center_child);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_center_child), use_center_child);
+    }
+}
+
+static void
+glade_action_bar_editor_editable_init (GladeEditableIface * iface)
+{
+  parent_editable_iface = g_type_interface_peek_parent (iface);
+  iface->load = glade_action_bar_editor_load;
+}
+
+static void
+use_center_child_toggled (GtkWidget            * widget,
+                          GladeActionBarEditor * box_editor)
+{
+  GladeActionBarEditorPrivate *priv = box_editor->priv;
+  GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (box_editor));
+  GladeWidget   *gcenter = NULL;
+  GtkWidget     *box;
+  GtkWidget     *center;
+  GladeProperty *property;
+  gboolean       use_center_child;
+
+  if (glade_editable_loading (GLADE_EDITABLE (box_editor)) || !gwidget)
+    return;
+
+  /* Get new desired property state */
+  use_center_child = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_center_child));
+
+  /* Get any existing center child */
+  box = (GtkWidget *)glade_widget_get_object (gwidget);
+  center = gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box));
+
+  if (center && !GLADE_IS_PLACEHOLDER (center))
+    gcenter = glade_widget_get_from_gobject (center);
+
+  glade_editable_block (GLADE_EDITABLE (box_editor));
+
+  if (use_center_child)
+    glade_command_push_group (_("Setting %s to use a center child"),
+                              glade_widget_get_name (gwidget));
+  else
+    glade_command_push_group (_("Setting %s to not use a center child"),
+                              glade_widget_get_name (gwidget));
+
+  /* If a project widget exists when were disabling center child, it needs
+   * to be removed first as a part of the issuing GladeCommand group
+   */
+  if (gcenter)
+    {
+      GList list;
+      list.prev = list.next = NULL;
+      list.data = gcenter;
+      glade_command_delete (&list);
+    }
+
+  property = glade_widget_get_property (gwidget, "use-center-child");
+  glade_command_set_property (property, use_center_child);
+
+  glade_command_pop_group ();
+
+  glade_editable_unblock (GLADE_EDITABLE (box_editor));
+
+  /* reload buttons and sensitivity and stuff... */
+  glade_editable_load (GLADE_EDITABLE (box_editor), gwidget);
+}
+
+GtkWidget *
+glade_action_bar_editor_new (void)
+{
+  return g_object_new (GLADE_TYPE_ACTION_BAR_EDITOR, NULL);
+}
diff --git a/plugins/gtk+/glade-action-bar-editor.h b/plugins/gtk+/glade-action-bar-editor.h
new file mode 100644
index 0000000..c69e702
--- /dev/null
+++ b/plugins/gtk+/glade-action-bar-editor.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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:
+ *   Matthias Clasen <mclasen redhat com>
+ */
+#ifndef _GLADE_ACTION_BAR_EDITOR_H_
+#define _GLADE_ACTION_BAR_EDITOR_H_
+
+#include <gtk/gtk.h>
+#include <gladeui/glade-editor-skeleton.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_ACTION_BAR_EDITOR             (glade_action_bar_editor_get_type ())
+#define GLADE_ACTION_BAR_EDITOR(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GLADE_TYPE_ACTION_BAR_EDITOR, GladeActionBarEditor))
+#define GLADE_ACTION_BAR_EDITOR_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GLADE_TYPE_ACTION_BAR_EDITOR, GladeActionBarEditorClass))
+#define GLADE_IS_ACTION_BAR_EDITOR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GLADE_TYPE_ACTION_BAR_EDITOR))
+#define GLADE_IS_ACTION_BAR_EDITOR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GLADE_TYPE_ACTION_BAR_EDITOR))
+#define GLADE_ACTION_BAR_EDITOR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GLADE_TYPE_ACTION_BAR_EDITOR, GladeActionBarEditorClass))
+
+typedef struct _GladeActionBarEditor        GladeActionBarEditor;
+typedef struct _GladeActionBarEditorClass   GladeActionBarEditorClass;
+typedef struct _GladeActionBarEditorPrivate GladeActionBarEditorPrivate;
+
+struct _GladeActionBarEditor
+{
+  GladeEditorSkeleton  parent;
+
+  GladeActionBarEditorPrivate *priv;
+};
+
+struct _GladeActionBarEditorClass
+{
+  GladeEditorSkeletonClass parent;
+};
+
+GType            glade_action_bar_editor_get_type (void) G_GNUC_CONST;
+GtkWidget       *glade_action_bar_editor_new      (void);
+
+G_END_DECLS
+
+#endif  /* _GLADE_ACTION_BAR_EDITOR_H_ */
diff --git a/plugins/gtk+/glade-action-bar-editor.ui b/plugins/gtk+/glade-action-bar-editor.ui
new file mode 100644
index 0000000..412cdc9
--- /dev/null
+++ b/plugins/gtk+/glade-action-bar-editor.ui
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 
+
+libgladegtk - Glade UI Designer Gtk+ support plugin
+Copyright (C) 2013 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 library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+Author: Tristan Van Berkom <tvb gnome org>
+
+-->
+<interface domain="glade">
+  <requires lib="gtk+" version="3.12"/>
+  <requires lib="gladeui" version="0.0"/>
+  <template class="GladeActionBarEditor" parent="GladeEditorSkeleton">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="row_spacing">6</property>
+        <property name="column_spacing">6</property>
+        <child>
+          <object class="GladeEditorTable" id="embed">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">6</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="title">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="valign">center</property>
+            <property name="label" translatable="yes">Box Attributes</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">6</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyLabel" id="size_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">size</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyShell" id="size_editor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">size</property>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="use_center_child">
+            <property name="label" translatable="yes">Add center child</property>
+            <property name="tooltip_text" translatable="yes">Whether this action bar should include a 
centered child.</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
+            <signal name="toggled" handler="use_center_child_toggled" swapped="no"/>
+          </object>
+          <packing>
+            <property name="left_attach">3</property>
+            <property name="top_attach">2</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child-editors>
+      <editor id="embed"/>
+      <editor id="size_label"/>
+      <editor id="size_editor"/>
+      <editor id="homogeneous_editor"/>
+    </child-editors>
+  </template>
+</interface>
diff --git a/plugins/gtk+/glade-gtk-action-bar.c b/plugins/gtk+/glade-gtk-action-bar.c
new file mode 100644
index 0000000..7743ad0
--- /dev/null
+++ b/plugins/gtk+/glade-gtk-action-bar.c
@@ -0,0 +1,499 @@
+/*
+ * glade-gtk-action-bar.c - GladeWidgetAdaptor for GtkActionBar 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-widget.h>
+#include <gladeui/glade-utils.h>
+#include "glade-action-bar-editor.h"
+#include "glade-gtk.h"
+
+
+GladeEditable *
+glade_gtk_action_bar_create_editable (GladeWidgetAdaptor * adaptor,
+                                      GladeEditorPageType type)
+{
+  if (type == GLADE_PAGE_GENERAL)
+    return (GladeEditable *) glade_action_bar_editor_new ();
+
+  return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type);
+}
+
+static void
+glade_gtk_action_bar_parse_finished (GladeProject * project,
+                                     GObject * object)
+{
+  GladeWidget *gbox;
+
+  gbox = glade_widget_get_from_gobject (object);
+  glade_widget_property_set (gbox, "use-center-child", gtk_action_bar_get_center_widget (GTK_ACTION_BAR 
(object)) != NULL);
+}
+
+void
+glade_gtk_action_bar_post_create (GladeWidgetAdaptor * adaptor,
+                                  GObject * container,
+                                  GladeCreateReason reason)
+{
+  GladeWidget *gwidget = glade_widget_get_from_gobject (container);
+  GladeProject *project = glade_widget_get_project (gwidget);
+
+  if (reason == GLADE_CREATE_LOAD)
+    g_signal_connect (project, "parse-finished",
+                      G_CALLBACK (glade_gtk_action_bar_parse_finished),
+                      container);
+}
+
+static gint
+sort_children (GtkWidget * widget_a, GtkWidget * widget_b, GtkWidget *box)
+{
+  GladeWidget *gwidget_a, *gwidget_b;
+  gint position_a, position_b;
+
+  gwidget_a = glade_widget_get_from_gobject (widget_a);
+  gwidget_b = glade_widget_get_from_gobject (widget_b);
+
+  /* Sort internal children before any other children */
+  if (box != gtk_widget_get_parent (widget_a))
+    return -1;
+  if (box != gtk_widget_get_parent (widget_b))
+    return 1;
+
+  if (gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)) == widget_a)
+    return -1;
+  if (gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)) == widget_b)
+    return -1;
+
+  if (gwidget_a)
+    glade_widget_pack_property_get (gwidget_a, "position", &position_a);
+  else
+    gtk_container_child_get (GTK_CONTAINER (box),
+                             widget_a, "position", &position_a, NULL);
+
+  if (gwidget_b)
+    glade_widget_pack_property_get (gwidget_b, "position", &position_b);
+  else
+    gtk_container_child_get (GTK_CONTAINER (box),
+                             widget_b, "position", &position_b, NULL);
+
+  return position_a - position_b;
+}
+
+GList *
+glade_gtk_action_bar_get_children (GladeWidgetAdaptor * adaptor,
+                                   GObject * container)
+{
+  GList *children;
+
+  children = GWA_GET_CLASS (GTK_TYPE_CONTAINER)->get_children (adaptor, container);
+
+  return g_list_sort_with_data (children, (GCompareDataFunc) sort_children, container);
+}
+
+static void
+update_position (GtkWidget *widget, gpointer data)
+{
+  GtkContainer *parent = data;
+  GladeWidget *gwidget;
+  gint position;
+
+  gwidget = glade_widget_get_from_gobject (widget);
+  if (gwidget)
+    {
+      gtk_container_child_get (parent, widget, "position", &position, NULL);
+      glade_widget_pack_property_set (gwidget, "position", position);
+    }
+}
+
+static void
+glade_gtk_action_bar_set_child_position (GObject * container,
+                                         GObject * child,
+                                         GValue * value)
+{
+  static gboolean recursion = FALSE;
+  gint new_position, old_position;
+
+  if (recursion)
+    return;
+
+  gtk_container_child_get (GTK_CONTAINER (container), GTK_WIDGET (child), "position", &old_position, NULL);
+  new_position = g_value_get_int (value);
+
+  if (old_position == new_position)
+    return;
+
+  recursion = TRUE;
+  gtk_container_child_set (GTK_CONTAINER (container), GTK_WIDGET (child),
+                           "position", new_position,
+                           NULL);
+  gtk_container_forall (GTK_CONTAINER (container), update_position, container);
+  recursion = FALSE;
+}
+
+static void
+glade_gtk_action_bar_set_child_pack_type (GObject * container,
+                                          GObject * child,
+                                          GValue * value)
+{
+  GtkPackType pack_type;
+
+  pack_type = g_value_get_enum (value);
+
+  gtk_container_child_set (GTK_CONTAINER (container), GTK_WIDGET (child), "pack-type", pack_type, NULL);
+}
+
+void
+glade_gtk_action_bar_set_child_property (GladeWidgetAdaptor * adaptor,
+                                         GObject * container,
+                                         GObject * child,
+                                         const gchar * id,
+                                         GValue * value)
+{
+  if (!strcmp (id, "position"))
+    glade_gtk_action_bar_set_child_position (container, child, value);
+  else if (!strcmp (id, "pack-type"))
+    glade_gtk_action_bar_set_child_pack_type (container, child, value);
+  else
+    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_set_property (adaptor, container,
+                                                            child, id, value);
+
+  gtk_container_check_resize (GTK_CONTAINER (container));
+}
+
+static gint
+glade_gtk_action_bar_get_num_children (GObject *box)
+{
+  GList *children = gtk_container_get_children (GTK_CONTAINER (box));
+  gint retval = g_list_length (children);
+  if (gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)) != NULL)
+    retval -= 1;
+  g_list_free (children);
+  return retval;
+}
+
+void
+glade_gtk_action_bar_get_property (GladeWidgetAdaptor * adaptor,
+                                   GObject * object,
+                                   const gchar * id,
+                                   GValue * value)
+{
+  if (!strcmp (id, "use-center-child"))
+    {
+      g_value_reset (value);
+      g_value_set_boolean (value, gtk_action_bar_get_center_widget (GTK_ACTION_BAR      (object)) != NULL);
+    }
+  else if (!strcmp (id, "size"))
+    {
+      g_value_reset (value);
+      g_value_set_int (value, glade_gtk_action_bar_get_num_children (object));
+    }
+  else
+    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->get_property (adaptor, object, id, value);
+}
+
+static gint
+glade_gtk_action_bar_get_first_blank (GtkActionBar * box)
+{
+  GList *child, *children;
+  GladeWidget *gwidget;
+  gint position;
+
+  children = gtk_container_get_children (GTK_CONTAINER (box));
+
+  for (child = children, position = 0;
+       child && child->data; child = child->next, position++)
+    {
+      GtkWidget *widget = child->data;
+
+      if (widget == gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)))
+        continue;
+
+      if ((gwidget = glade_widget_get_from_gobject (widget)) != NULL)
+        {
+          gint gwidget_position = 0;
+          GladeProperty *property =
+              glade_widget_get_pack_property (gwidget, "position");
+
+         /* property can be NULL here when project is closing */
+         if (property)
+           gwidget_position = g_value_get_int (glade_property_inline_value (property));
+
+          if (gwidget_position > position)
+            break;
+        }
+    }
+
+  g_list_free (children);
+
+  return position;
+}
+
+static void
+glade_gtk_action_bar_set_size (GObject * object, const GValue * value)
+{
+  GtkActionBar *box;
+  GList *child, *children;
+  guint new_size, old_size, i;
+
+  box = GTK_ACTION_BAR (object);
+
+  if (glade_util_object_is_loading (object))
+    return;
+
+  children = gtk_container_get_children (GTK_CONTAINER (box));
+  children = g_list_remove (children, gtk_action_bar_get_center_widget (box));
+
+  old_size = g_list_length (children);
+  new_size = g_value_get_int (value);
+
+  if (old_size == new_size)
+    {
+      g_list_free (children);
+      return;
+    }
+
+  /* Ensure placeholders first...
+   */
+  for (i = 0; i < new_size; i++)
+    {
+      if (g_list_length (children) < (i + 1))
+        {
+          GtkWidget *placeholder = glade_placeholder_new ();
+          gint blank = glade_gtk_action_bar_get_first_blank (box);
+
+          gtk_container_add (GTK_CONTAINER (box), placeholder);
+          gtk_container_child_set (GTK_CONTAINER (box), placeholder, "position", blank, NULL);
+        }
+    }
+
+  /* The box has shrunk. Remove the widgets that are on those slots */
+  for (child = g_list_last (children);
+       child && old_size > new_size; child = g_list_previous (child))
+    {
+      GtkWidget *child_widget = child->data;
+
+      /* Refuse to remove any widgets that are either GladeWidget objects
+       * or internal to the hierarchic entity (may be a composite widget,
+       * not all internal widgets have GladeWidgets).
+       */
+      if (glade_widget_get_from_gobject (child_widget) ||
+          GLADE_IS_PLACEHOLDER (child_widget) == FALSE)
+        continue;
+
+      gtk_container_remove (GTK_CONTAINER (box), child_widget);
+      old_size--;
+    }
+  g_list_free (children);
+}
+
+void
+glade_gtk_action_bar_set_property (GladeWidgetAdaptor * adaptor,
+                                   GObject * object,
+                                   const gchar * id,
+                                   const GValue * value)
+{
+  if (!strcmp (id, "use-center-child"))
+    {
+      GtkWidget *child;
+
+      if (g_value_get_boolean (value))
+        {
+          child = gtk_action_bar_get_center_widget (GTK_ACTION_BAR (object));
+          if (!child)
+            child = glade_placeholder_new ();
+          g_object_set_data (G_OBJECT (child), "special-child-type", "center");
+        }
+      else
+        child = NULL;
+      gtk_action_bar_set_center_widget (GTK_ACTION_BAR (object), child);
+    }
+
+  else if (!strcmp (id, "size"))
+    glade_gtk_action_bar_set_size (object, value);
+  else
+    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value);
+}
+
+static gboolean
+glade_gtk_action_bar_verify_size (GObject *object, const GValue *value)
+{
+  GList *child, *children;
+  gint old_size, count = 0;
+  gint new_size = g_value_get_int (value);
+  
+  children = gtk_container_get_children (GTK_CONTAINER (object));
+  children = g_list_remove (children, gtk_action_bar_get_center_widget (GTK_ACTION_BAR (object)));
+  old_size = g_list_length (children);
+
+  for (child = g_list_last (children);
+       child && old_size > new_size;
+       child = g_list_previous (child))
+    {
+      GtkWidget *widget = child->data;
+      if (glade_widget_get_from_gobject (widget) != NULL)
+        count++;
+      else
+        old_size--;
+    }
+
+  g_list_free (children);
+
+  return count > new_size ? FALSE : new_size >= 0;
+}
+
+gboolean
+glade_gtk_action_bar_verify_property (GladeWidgetAdaptor * adaptor,
+                                      GObject * object,
+                                      const gchar * id,
+                                      const GValue * value)
+{
+  if (!strcmp (id, "size"))
+    return glade_gtk_action_bar_verify_size (object, value);
+  else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property)
+    return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, id, value);
+
+  return TRUE;
+}
+
+void
+glade_gtk_action_bar_add_child (GladeWidgetAdaptor * adaptor,
+                                GObject * object,
+                                GObject * child)
+{
+  GladeWidget *gbox, *gchild;
+  gint num_children;
+  gchar *special_child_type;
+
+  gbox = glade_widget_get_from_gobject (object);
+
+  special_child_type = g_object_get_data (child, "special-child-type");
+  if (special_child_type && !strcmp (special_child_type, "center"))
+    {
+      gtk_action_bar_set_center_widget (GTK_ACTION_BAR (object), GTK_WIDGET (child));
+       return;
+    }
+
+  /*
+     Try to remove the last placeholder if any, this way GtkBox`s size 
+     will not be changed.
+   */
+  if (!glade_widget_superuser () && !GLADE_IS_PLACEHOLDER (child))
+    {
+      GList *l, *children;
+
+      children = gtk_container_get_children (GTK_CONTAINER (object));
+      for (l = g_list_last (children); l; l = g_list_previous (l))
+        {
+          GtkWidget *child_widget = l->data;
+          if (GLADE_IS_PLACEHOLDER (child_widget))
+            {
+              gtk_container_remove (GTK_CONTAINER (object), child_widget);
+              break;
+            }
+        }
+      g_list_free (children);
+    }
+
+  gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
+  num_children = glade_gtk_action_bar_get_num_children (object);
+  glade_widget_property_set (gbox, "size", num_children);
+
+  if (glade_widget_superuser ())
+    return;
+  
+  gchild = glade_widget_get_from_gobject (child);
+
+  /* Packing props arent around when parenting during a glade_widget_dup() */
+  if (gchild && glade_widget_get_packing_properties (gchild))
+    glade_widget_pack_property_set (gchild, "position", num_children - 1);
+}
+
+void
+glade_gtk_action_bar_remove_child (GladeWidgetAdaptor * adaptor,
+                                   GObject * object,
+                                   GObject * child)
+{
+  GladeWidget *gbox;
+  gint size;
+  gchar *special_child_type;
+
+  gbox = glade_widget_get_from_gobject (object);
+
+  special_child_type = g_object_get_data (child, "special-child-type");
+  if (special_child_type && !strcmp (special_child_type, "center"))
+    {
+      GtkWidget *w;
+
+      w = glade_placeholder_new ();
+      g_object_set_data (G_OBJECT (w), "special-child-type", "center");
+      gtk_action_bar_set_center_widget (GTK_ACTION_BAR (object), w);
+      return;
+    }
+
+  gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
+
+  if (!glade_widget_superuser ())
+    {
+      glade_widget_property_get (gbox, "size", &size);
+      glade_widget_property_set (gbox, "size", size);
+    }
+}
+
+void
+glade_gtk_action_bar_replace_child (GladeWidgetAdaptor * adaptor,
+                                    GObject * container,
+                                    GObject * current,
+                                    GObject * new_widget)
+{
+  gint position;
+  GtkPackType pack_type;
+
+  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, "center"))
+    {
+      g_object_set_data (G_OBJECT (new_widget), "special-child-type", "center");
+      gtk_action_bar_set_center_widget (GTK_ACTION_BAR (container), GTK_WIDGET (new_widget));
+      return;
+    }
+
+  gtk_container_child_get (GTK_CONTAINER (container),
+                           GTK_WIDGET (current),
+                           "position", &position,
+                           "pack-type", &pack_type,
+                           NULL); 
+
+  gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (current));
+  gtk_container_add (GTK_CONTAINER (container), GTK_WIDGET (new_widget));
+
+  gtk_container_child_set (GTK_CONTAINER (container),
+                           GTK_WIDGET (new_widget),
+                           "position", position,
+                           "pack-type", pack_type,
+                           NULL);
+}
diff --git a/plugins/gtk+/glade-gtk-resources.gresource.xml b/plugins/gtk+/glade-gtk-resources.gresource.xml
index 75c53b1..1c2b8b9 100644
--- a/plugins/gtk+/glade-gtk-resources.gresource.xml
+++ b/plugins/gtk+/glade-gtk-resources.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/gladegtk">
     <file compressed="true" preprocess="xml-stripblanks">glade-about-dialog-editor.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">glade-action-bar-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-action-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-activatable-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-app-chooser-button-editor.ui</file>
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index c820b9b..04707cf 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -704,6 +704,45 @@
         </properties>
       </glade-widget-class>
       
+      <glade-widget-class name="GtkActionBar" generic-name="actionbar" _title="Action Bar" since="3.12">
+        <create-editable-function>glade_gtk_action_bar_create_editable</create-editable-function>
+        <post-create-function>glade_gtk_action_bar_post_create</post-create-function>
+        <get-children-function>glade_gtk_action_bar_get_children</get-children-function>
+        <set-property-function>glade_gtk_action_bar_set_property</set-property-function>
+        <get-property-function>glade_gtk_action_bar_get_property</get-property-function>
+        <verify-function>glade_gtk_action_bar_verify_property</verify-function>
+        <add-child-function>glade_gtk_action_bar_add_child</add-child-function>
+        <remove-child-function>glade_gtk_action_bar_remove_child</remove-child-function>
+        <replace-child-function>glade_gtk_action_bar_replace_child</replace-child-function>
+        <child-set-property-function>glade_gtk_action_bar_set_child_property</child-set-property-function>
+        <special-child-type>type</special-child-type>
+        
+        <properties>
+          <property id="size" _name="Number of items" default="1" save="False" custom-layout="True">
+            <parameter-spec>
+              <type>GParamInt</type>
+              <min>1</min>
+            </parameter-spec>
+            <_tooltip>The number of items in the action bar</_tooltip>
+          </property>
+          <property save="False" id="use-center-child" since="3.12" default="FALSE" _name="Center Child" 
custom-layout="True">
+            <parameter-spec>
+              <type>GParamBoolean</type>
+            </parameter-spec>
+          </property>
+        </properties>
+        
+        <packing-properties>
+          <property id="position" weight="0" save-always="True"/>
+          <property id="pack-type" transfer-on-paste="True">
+            <displayable-values>
+              <value id="GTK_PACK_START" _name="Start"/>
+              <value id="GTK_PACK_END" _name="End"/>
+            </displayable-values>
+          </property>
+        </packing-properties>
+      </glade-widget-class>
+      
       <glade-widget-class name="GtkWindow" generic-name="window" _title="Window" toplevel="True" 
default-width="440" default-height="250">
         <post-create-function>glade_gtk_window_post_create</post-create-function>
         <read-widget-function>glade_gtk_window_read_widget</read-widget-function>
@@ -5450,6 +5489,7 @@
       <glade-widget-class-ref name="GtkStack" />
       <glade-widget-class-ref name="GtkPopover"/>
       <glade-widget-class-ref name="GtkPopoverMenu"/>
+      <glade-widget-class-ref name="GtkActionBar" />
     </glade-widget-group>
     
     <glade-widget-group name="gtk-control-display" _title="Control and Display">
diff --git a/plugins/gtk+/icons/16x16/Makefile.am b/plugins/gtk+/icons/16x16/Makefile.am
index d7c0270..e162304 100644
--- a/plugins/gtk+/icons/16x16/Makefile.am
+++ b/plugins/gtk+/icons/16x16/Makefile.am
@@ -6,6 +6,7 @@ icons_DATA = \
        widget-gtk-aboutdialog.png \
        widget-gtk-accelgroup.png \
        widget-gtk-accellabel.png \
+       widget-gtk-actionbar.png \
        widget-gtk-adjustment.png \
        widget-gtk-alignment.png \
        widget-gtk-appchooserbutton.png \
diff --git a/plugins/gtk+/icons/16x16/widget-gtk-actionbar.png 
b/plugins/gtk+/icons/16x16/widget-gtk-actionbar.png
new file mode 100644
index 0000000..ef4f8d5
Binary files /dev/null and b/plugins/gtk+/icons/16x16/widget-gtk-actionbar.png differ
diff --git a/plugins/gtk+/icons/22x22/Makefile.am b/plugins/gtk+/icons/22x22/Makefile.am
index d6c6874..0d58ef6 100644
--- a/plugins/gtk+/icons/22x22/Makefile.am
+++ b/plugins/gtk+/icons/22x22/Makefile.am
@@ -6,6 +6,7 @@ icons_DATA = \
        widget-gtk-aboutdialog.png \
        widget-gtk-accelgroup.png \
        widget-gtk-accellabel.png \
+       widget-gtk-actionbar.png \
        widget-gtk-adjustment.png \
        widget-gtk-alignment.png \
        widget-gtk-appchooserbutton.png \
diff --git a/plugins/gtk+/icons/22x22/widget-gtk-actionbar.png 
b/plugins/gtk+/icons/22x22/widget-gtk-actionbar.png
new file mode 100644
index 0000000..bd01750
Binary files /dev/null and b/plugins/gtk+/icons/22x22/widget-gtk-actionbar.png differ


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]