libegg r840 - in trunk: . libegg/toolpalette



Author: hasselmm
Date: Sat Jan 12 00:44:05 2008
New Revision: 840
URL: http://svn.gnome.org/viewvc/libegg?rev=840&view=rev

Log:
Provide combo boxes for toggling palette properties in test program.

* libegg/toolpalette/eggenumaction.h: Declare EggEnumAction.
* libegg/toolpalette/eggenumaction.c: Implement EggEnumAction.
* libegg/toolpalette/eggtoolitemgroup.c: I18N cleanup.
* libegg/toolpalette/eggtoolpalette.c: Install object properties.
* libegg/toolpalette/Makefile.am: Add eggenumaction.c.
* libegg/toolpalette/testtoolpalette.c: Add new actions.


Added:
   trunk/libegg/toolpalette/eggenumaction.c
   trunk/libegg/toolpalette/eggenumaction.h
Modified:
   trunk/ChangeLog
   trunk/libegg/toolpalette/Makefile.am
   trunk/libegg/toolpalette/eggtoolitemgroup.c
   trunk/libegg/toolpalette/eggtoolpalette.c
   trunk/libegg/toolpalette/testtoolpalette.c

Modified: trunk/libegg/toolpalette/Makefile.am
==============================================================================
--- trunk/libegg/toolpalette/Makefile.am	(original)
+++ trunk/libegg/toolpalette/Makefile.am	Sat Jan 12 00:44:05 2008
@@ -9,7 +9,7 @@
 noinst_LTLIBRARIES = libeggtoolpalette.la
 noinst_PROGRAMS = testtoolpalette
 
-libeggtoolpalette_la_SOURCES = eggtoolpalette.c eggtoolitemgroup.c
+libeggtoolpalette_la_SOURCES = eggenumaction.c eggtoolpalette.c eggtoolitemgroup.c
 
 testtoolpalette_SOURCES = testtoolpalette.c
 testtoolpalette_LDFLAGS = libeggtoolpalette.la ../util/libeggutil.la $(EGG_LIBS)

Added: trunk/libegg/toolpalette/eggenumaction.c
==============================================================================
--- (empty file)
+++ trunk/libegg/toolpalette/eggenumaction.c	Sat Jan 12 00:44:05 2008
@@ -0,0 +1,491 @@
+/* EggEnumAction -- An action that creates combo boxes for enums
+ * Copyright (C) 2008  Openismus GmbH
+ *
+ * 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *      Mathias Hasselmann
+ */
+
+#include "eggenumaction.h"
+#include <gtk/gtk.h>
+
+#define P_(msgid) (msgid)
+
+enum
+{
+  PROP_NONE,
+  PROP_ENUM_TYPE,
+};
+
+struct _EggEnumActionPrivate
+{
+  GType         enum_type;
+  GEnumClass   *enum_class;
+  GSList       *bindings;
+  GtkListStore *model;
+};
+
+static GQuark egg_enum_action_child_quark;
+static GQuark egg_enum_action_value_quark;
+
+G_DEFINE_TYPE (EggEnumAction, egg_enum_action, GTK_TYPE_ACTION);
+
+static void
+egg_enum_action_init (EggEnumAction *action)
+{
+  action->priv = G_TYPE_INSTANCE_GET_PRIVATE (action,
+                                              EGG_TYPE_ENUM_ACTION,
+                                              EggEnumActionPrivate);
+}
+
+static void
+egg_enum_action_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  EggEnumAction *action = EGG_ENUM_ACTION (object);
+  GType enum_type;
+
+  switch (prop_id)
+    {
+      case PROP_ENUM_TYPE:
+        enum_type = g_value_get_gtype (value);
+
+        if (enum_type == action->priv->enum_type)
+          break;
+
+        if (action->priv->enum_class)
+          {
+            g_type_class_unref (action->priv->enum_class);
+            action->priv->enum_class = NULL;
+          }
+
+        action->priv->enum_type = enum_type;
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+egg_enum_action_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  EggEnumAction *action = EGG_ENUM_ACTION (object);
+
+  switch (prop_id)
+    {
+      case PROP_ENUM_TYPE:
+        g_value_set_gtype (value, action->priv->enum_type);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+egg_enum_action_dispose (GObject *object)
+{
+  EggEnumAction *action = EGG_ENUM_ACTION (object);
+
+  if (action->priv->enum_class)
+    {
+      g_type_class_unref (action->priv->enum_class);
+      action->priv->enum_class = NULL;
+    }
+
+  if (action->priv->model)
+    {
+      g_type_class_unref (action->priv->model);
+      action->priv->model = NULL;
+    }
+
+  while (action->priv->bindings)
+    {
+      g_param_spec_unref (action->priv->bindings->data);
+      g_object_unref (action->priv->bindings->next->data);
+
+      action->priv->bindings->data = g_slist_delete_link (action->priv->bindings->data,
+                                                          action->priv->bindings->data);
+      action->priv->bindings->data = g_slist_delete_link (action->priv->bindings->data,
+                                                          action->priv->bindings->data);
+    }
+
+  G_OBJECT_CLASS (egg_enum_action_parent_class)->dispose (object);
+}
+
+static GtkTreeModel*
+egg_enum_action_get_model (EggEnumAction *action)
+{
+  if (!action->priv->enum_class)
+    action->priv->enum_class = g_type_class_ref (action->priv->enum_type);
+
+  if (!action->priv->model)
+    {
+      GtkTreeIter iter;
+      guint i;
+
+      action->priv->model = gtk_list_store_new (2, G_TYPE_STRING, action->priv->enum_type);
+
+      for (i = 0; i < action->priv->enum_class->n_values; ++i)
+        {
+          GEnumValue *v = &action->priv->enum_class->values[i];
+
+          gtk_list_store_append (action->priv->model, &iter);
+          gtk_list_store_set (action->priv->model, &iter, 
+                              0, v->value_nick, 1, v->value, -1);
+        }
+    }
+
+  return GTK_TREE_MODEL (action->priv->model);
+}
+
+static gboolean
+egg_enum_action_get_iter (EggEnumAction *action,
+                          GtkTreeIter   *iter,
+                          GObject       *object,
+                          GParamSpec    *property)
+{
+  GtkTreeModel *model = egg_enum_action_get_model (action);
+  gint object_value, model_value;
+
+  if (!gtk_tree_model_get_iter_first (model, iter))
+    return FALSE;
+
+  if (!G_IS_OBJECT (object) || !G_IS_PARAM_SPEC_ENUM (property))
+    return TRUE;
+
+  g_object_get (object, property->name, &object_value, NULL);
+
+  do
+    {
+      gtk_tree_model_get (model, iter, 1, &model_value, -1);
+
+      if (model_value == object_value)
+        return TRUE;
+    }
+  while (gtk_tree_model_iter_next (model, iter));
+
+  return FALSE;
+}
+
+static gboolean
+egg_enum_action_get_active_iter (EggEnumAction *action,
+                                 GtkTreeIter   *iter)
+{
+  GParamSpec *property = NULL;
+  GObject *object = NULL;
+
+  if (action->priv->bindings)
+    {
+      property = action->priv->bindings->data;
+      object = action->priv->bindings->next->data;
+    }
+
+  return egg_enum_action_get_iter (action, iter, object, property);
+}
+
+static void
+egg_enum_action_set_value (EggEnumAction *action,
+                           gint           value)
+{
+  GSList *binding = action->priv->bindings;
+
+  while (binding)
+    {
+      GParamSpec *property = binding->data;
+      GObject *object = binding->next->data;
+
+      g_object_set (object, property->name, value, NULL);
+
+      binding = binding->next->next;
+    }
+}
+
+static void
+egg_enum_action_combo_changed (GtkComboBox *combo,
+                               gpointer     data)
+{
+  EggEnumAction *action = EGG_ENUM_ACTION (data);
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gint value;
+
+  if (gtk_combo_box_get_active_iter (combo, &iter))
+    {
+      model = egg_enum_action_get_model (action);
+      gtk_tree_model_get (model, &iter, 1, &value, -1);
+      egg_enum_action_set_value (action, value);
+    }
+}
+
+static void
+egg_enum_action_toolbar_reconfigured (GtkToolItem *item,
+                                      gpointer     data)
+{
+  gboolean important = gtk_tool_item_get_is_important (item);
+  GtkToolbarStyle style = gtk_tool_item_get_toolbar_style (item);
+  EggEnumAction *action = EGG_ENUM_ACTION (data);
+  gchar *text, *tmp;
+
+  GtkWidget *align, *box = NULL;
+  GtkWidget *combo, *label;
+  GtkCellRenderer *cell;
+  GtkTreeIter iter;
+
+  align = gtk_bin_get_child (GTK_BIN (item));
+  box = gtk_bin_get_child (GTK_BIN (align));
+
+  if (box)
+    gtk_container_remove (GTK_CONTAINER (align), box);
+
+  g_object_get (action, "label", &text, NULL);
+  box = NULL;
+
+  combo = gtk_combo_box_new_with_model (egg_enum_action_get_model (action));
+  g_signal_connect (combo, "changed", G_CALLBACK (egg_enum_action_combo_changed), action);
+
+  cell = gtk_cell_renderer_text_new ();
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
+  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell, "text", 0, NULL);
+  g_object_set_qdata (G_OBJECT (item), egg_enum_action_child_quark, combo);
+
+  if (egg_enum_action_get_active_iter (action, &iter))
+    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
+
+  if (GTK_TOOLBAR_BOTH == style)
+    {
+      label = gtk_label_new (text);
+
+      box = gtk_vbox_new (FALSE, 0);
+      gtk_box_pack_end (GTK_BOX (box), label, FALSE, TRUE, 0);
+    }
+  else if (GTK_TOOLBAR_ICONS != style || important)
+    {
+      tmp = g_strconcat (text, ":", NULL);
+      label = gtk_label_new (tmp);
+      g_free (tmp);
+
+      gtk_misc_set_padding (GTK_MISC (label), 3, 0);
+
+      box = gtk_hbox_new (FALSE, 0);
+      gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0);
+    }
+
+  if (box)
+    {
+      gtk_box_pack_start (GTK_BOX (box), combo, TRUE, TRUE, 0);
+      gtk_container_add (GTK_CONTAINER (align), box);
+    }
+  else
+    gtk_container_add (GTK_CONTAINER (align), combo);
+
+  gtk_widget_show_all (align);
+
+  g_free (text);
+}
+
+static void
+egg_enum_action_select_menu_item (EggEnumAction *action,
+                                  GtkTreeIter   *iter,
+                                  GtkWidget     *menu)
+{
+  GList *items = gtk_container_get_children (GTK_CONTAINER (menu));
+  GtkTreeModel *model = egg_enum_action_get_model (action);
+  GtkTreePath *path = gtk_tree_model_get_path (model, iter);
+  gint item_index = gtk_tree_path_get_indices (path)[0];
+  GtkWidget *child = g_list_nth_data (items, item_index);
+
+  if (child)
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (child), TRUE);
+
+  gtk_tree_path_free (path);
+  g_list_free (items);
+}
+
+static void
+egg_enum_action_menu_item_toggled (GtkCheckMenuItem *item,
+                                   gpointer          data)
+{
+  gpointer value = g_object_get_qdata (G_OBJECT (item), egg_enum_action_value_quark);
+  egg_enum_action_set_value (EGG_ENUM_ACTION (data), GPOINTER_TO_INT (value));
+}
+
+static GtkWidget*
+egg_enum_action_create_menu_item (GtkAction *action)
+{
+  GtkTreeModel *model = egg_enum_action_get_model (EGG_ENUM_ACTION (action));
+  GtkTreeIter iter;
+  gchar *label;
+  gint value;
+
+  GtkWidget *item;
+  GtkWidget *menu = gtk_menu_new ();
+  GSList *group = NULL;
+
+  if (gtk_tree_model_get_iter_first (model, &iter))
+    do
+      {
+        gtk_tree_model_get (model, &iter, 0, &label, 1, &value, -1);
+
+        item = gtk_radio_menu_item_new_with_label (group, label);
+        group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+        g_object_set_qdata (G_OBJECT (item),
+                            egg_enum_action_value_quark,
+                            GINT_TO_POINTER (value));
+
+        g_signal_connect (item, "toggled",
+                          G_CALLBACK (egg_enum_action_menu_item_toggled),
+                          action);
+      }
+    while (gtk_tree_model_iter_next (model, &iter));
+
+  gtk_widget_show_all (menu);
+
+  if (egg_enum_action_get_active_iter (EGG_ENUM_ACTION (action), &iter))
+    egg_enum_action_select_menu_item (EGG_ENUM_ACTION (action), &iter, menu);
+
+  item = GTK_ACTION_CLASS (egg_enum_action_parent_class)->create_menu_item (action);
+  g_object_set_qdata (G_OBJECT (item), egg_enum_action_child_quark, menu);
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
+
+  return item;
+}
+
+static GtkWidget*
+egg_enum_action_create_tool_item (GtkAction *action)
+{
+  GtkToolItem *item = gtk_tool_item_new ();
+  GtkWidget *align = gtk_alignment_new (0.5, 0.5, 1, 0);
+
+  gtk_container_add (GTK_CONTAINER (item), align);
+
+  g_signal_connect (item, "toolbar-reconfigured",
+                    G_CALLBACK (egg_enum_action_toolbar_reconfigured),
+                    action);
+
+  return GTK_WIDGET (item);
+}
+
+static void
+egg_enum_action_class_init (EggEnumActionClass *cls)
+{
+  GObjectClass *oclass = G_OBJECT_CLASS (cls);
+  GtkActionClass *aclass = GTK_ACTION_CLASS (cls);
+
+  oclass->set_property     = egg_enum_action_set_property;
+  oclass->get_property     = egg_enum_action_get_property;
+  oclass->dispose          = egg_enum_action_dispose;
+
+  aclass->create_menu_item = egg_enum_action_create_menu_item;
+  aclass->create_tool_item = egg_enum_action_create_tool_item;
+
+  g_object_class_install_property (oclass, PROP_ENUM_TYPE,
+                                   g_param_spec_gtype ("enum-type",
+                                                       P_("Enum Type"),
+                                                       P_("Type of the enumeration"),
+                                                       G_TYPE_ENUM,
+                                                       G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
+                                                       G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+  g_type_class_add_private (cls, sizeof (EggEnumActionPrivate));
+
+  egg_enum_action_child_quark = g_quark_from_static_string ("egg-enum-action-child-quark");
+  egg_enum_action_value_quark = g_quark_from_static_string ("egg-enum-action-value-quark");
+}
+
+GtkAction*
+egg_enum_action_new (const gchar *name,
+                     const gchar *label,
+                     const gchar *tooltip,
+                     GType        enum_type)
+{
+  g_return_val_if_fail (NULL != name, NULL);
+  g_return_val_if_fail (g_type_is_a (enum_type, G_TYPE_ENUM), NULL);
+
+  return g_object_new (EGG_TYPE_ENUM_ACTION, "name", name, "label", label,
+                       "tooltip", tooltip, "enum-type", enum_type, NULL);
+}
+
+static void
+egg_enum_action_notify (GObject    *object,
+                        GParamSpec *property,
+                        gpointer    data)
+{
+  EggEnumAction *action = EGG_ENUM_ACTION (data);
+  GtkTreeIter active_iter;
+  GtkWidget *child;
+  GSList *proxies;
+
+  if (egg_enum_action_get_iter (action, &active_iter, object, property))
+    {
+      proxies = gtk_action_get_proxies (GTK_ACTION (action));
+
+      while (proxies)
+        {
+          child = g_object_get_qdata (proxies->data, egg_enum_action_child_quark);
+
+          if (GTK_IS_COMBO_BOX (child))
+            gtk_combo_box_set_active_iter (GTK_COMBO_BOX (child), &active_iter);
+          else if (GTK_IS_MENU (child))
+            egg_enum_action_select_menu_item (action, &active_iter, child);
+
+          proxies = proxies->next;
+        }
+    }
+}
+
+void
+egg_enum_action_bind (EggEnumAction *action,
+                      GObject       *object,
+                      const gchar   *property_name)
+{
+  gchar *signal_name;
+  GParamSpec *property;
+
+  g_return_if_fail (EGG_IS_ENUM_ACTION (action));
+  g_return_if_fail (GTK_IS_OBJECT (object));
+  g_return_if_fail (NULL != property_name);
+
+  property = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
+                                           property_name);
+
+  g_return_if_fail (NULL != property);
+  g_return_if_fail (g_type_is_a (property->value_type, action->priv->enum_type));
+
+  signal_name = g_strconcat ("notify::", property_name, NULL);
+
+  g_signal_connect (object, signal_name,
+                    G_CALLBACK (egg_enum_action_notify),
+                    action);
+
+  g_free (signal_name);
+
+  action->priv->bindings = g_slist_prepend (action->priv->bindings, g_object_ref (object));
+  action->priv->bindings = g_slist_prepend (action->priv->bindings, g_param_spec_ref (property));
+
+  egg_enum_action_notify (object, property, action);
+}
+

Added: trunk/libegg/toolpalette/eggenumaction.h
==============================================================================
--- (empty file)
+++ trunk/libegg/toolpalette/eggenumaction.h	Sat Jan 12 00:44:05 2008
@@ -0,0 +1,62 @@
+/* EggEnumAction -- An action that creates combo boxes for enums
+ * Copyright (C) 2008  Openismus GmbH
+ *
+ * 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *      Mathias Hasselmann
+ */
+
+#ifndef __EGG_ENUM_ACTION_H__
+#define __EGG_ENUM_ACTION_H__
+
+#include <gtk/gtkaction.h>
+
+G_BEGIN_DECLS
+
+#define EGG_TYPE_ENUM_ACTION           (egg_enum_action_get_type())
+#define EGG_ENUM_ACTION(obj)           (G_TYPE_CHECK_INSTANCE_CAST(obj, EGG_TYPE_ENUM_ACTION, EggEnumAction))
+#define EGG_ENUM_ACTION_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST(cls, EGG_TYPE_ENUM_ACTION, EggEnumActionClass))
+#define EGG_IS_ENUM_ACTION(obj)        (G_TYPE_CHECK_INSTANCE_TYPE(obj, EGG_TYPE_ENUM_ACTION))
+#define EGG_IS_ENUM_ACTION_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE(obj, EGG_TYPE_ENUM_ACTION))
+#define EGG_ENUM_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EGG_TYPE_ENUM_ACTION, EggEnumActionClass))
+
+typedef struct _EggEnumAction        EggEnumAction;
+typedef struct _EggEnumActionClass   EggEnumActionClass;
+typedef struct _EggEnumActionPrivate EggEnumActionPrivate;
+
+struct _EggEnumAction
+{
+  GtkAction parent_instance;
+  EggEnumActionPrivate *priv;
+};
+
+struct _EggEnumActionClass
+{
+  GtkActionClass parent_class;
+};
+
+GType      egg_enum_action_get_type (void) G_GNUC_CONST;
+GtkAction* egg_enum_action_new      (const gchar   *name,
+                                     const gchar   *label,
+                                     const gchar   *tooltip,
+                                     GType          enum_type);
+void       egg_enum_action_bind     (EggEnumAction *action,
+                                     GObject       *object,
+                                     const gchar   *property_name);
+
+G_END_DECLS
+
+#endif /* __EGG_ENUM_ACTION_H__ */ 

Modified: trunk/libegg/toolpalette/eggtoolitemgroup.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolitemgroup.c	(original)
+++ trunk/libegg/toolpalette/eggtoolitemgroup.c	Sat Jan 12 00:44:05 2008
@@ -22,8 +22,6 @@
 #include "eggtoolitemgroup.h"
 #include "eggtoolpaletteprivate.h"
 
-#include <glib/gi18n.h>
-
 #include <gtk/gtkalignment.h>
 #include <gtk/gtkbutton.h>
 #include <gtk/gtklabel.h>
@@ -35,7 +33,7 @@
 #define DEFAULT_EXPANDER_SIZE    16
 #define DEFAULT_HEADER_SPACING   2
 
-#define P_(msgid) _(msgid)
+#define P_(msgid) (msgid)
 
 enum
 {

Modified: trunk/libegg/toolpalette/eggtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpalette.c	(original)
+++ trunk/libegg/toolpalette/eggtoolpalette.c	Sat Jan 12 00:44:05 2008
@@ -29,7 +29,9 @@
 
 #define DEFAULT_ICON_SIZE       GTK_ICON_SIZE_SMALL_TOOLBAR
 #define DEFAULT_ORIENTATION     GTK_ORIENTATION_VERTICAL
-#define DEFAULT_STYLE           GTK_TOOLBAR_ICONS
+#define DEFAULT_TOOLBAR_STYLE   GTK_TOOLBAR_ICONS
+
+#define P_(msgid) (msgid)
 
 typedef struct _EggToolPaletteDragData EggToolPaletteDragData;
 
@@ -38,7 +40,7 @@
   PROP_NONE,
   PROP_ICON_SIZE,
   PROP_ORIENTATION,
-  PROP_STYLE,
+  PROP_TOOLBAR_STYLE,
 };
 
 struct _EggToolPalettePrivate
@@ -88,7 +90,7 @@
 
   palette->priv->icon_size = DEFAULT_ICON_SIZE;
   palette->priv->orientation = DEFAULT_ORIENTATION;
-  palette->priv->style = DEFAULT_STYLE;
+  palette->priv->style = DEFAULT_TOOLBAR_STYLE;
 }
 
 static void
@@ -117,7 +119,7 @@
           }
         break;
 
-      case PROP_STYLE:
+      case PROP_TOOLBAR_STYLE:
         if ((guint) g_value_get_enum (value) != palette->priv->style)
           {
             palette->priv->style = g_value_get_enum (value);
@@ -149,7 +151,7 @@
         g_value_set_enum (value, egg_tool_palette_get_orientation (palette));
         break;
 
-      case PROP_STYLE:
+      case PROP_TOOLBAR_STYLE:
         g_value_set_enum (value, egg_tool_palette_get_style (palette));
         break;
 
@@ -524,6 +526,33 @@
                   GTK_TYPE_ADJUSTMENT,
                   GTK_TYPE_ADJUSTMENT);
 
+  g_object_class_install_property (oclass, PROP_ICON_SIZE,
+                                   g_param_spec_enum ("icon-size",
+                                                      P_("Icon Size"),
+                                                      P_("The size of palette icons"),
+                                                      GTK_TYPE_ICON_SIZE,
+                                                      DEFAULT_ICON_SIZE,
+                                                      G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
+                                                      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (oclass, PROP_ORIENTATION,
+                                   g_param_spec_enum ("orientation",
+                                                      P_("Orientation"),
+                                                      P_("Orientation of the tool palette"),
+                                                      GTK_TYPE_ORIENTATION,
+                                                      DEFAULT_ORIENTATION,
+                                                      G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
+                                                      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
+                                   g_param_spec_enum ("toolbar-style",
+                                                      P_("Toolbar Style"),
+                                                      P_("Style of items in the tool palette"),
+                                                      GTK_TYPE_TOOLBAR_STYLE,
+                                                      DEFAULT_TOOLBAR_STYLE,
+                                                      G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
+                                                      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
   g_type_class_add_private (cls, sizeof (EggToolPalettePrivate));
 
   dnd_target_atom = gdk_atom_intern_static_string (dnd_targets[0].target);
@@ -582,7 +611,7 @@
 GtkToolbarStyle
 egg_tool_palette_get_style (EggToolPalette *palette)
 {
-  g_return_val_if_fail (EGG_IS_TOOL_PALETTE (palette), DEFAULT_STYLE);
+  g_return_val_if_fail (EGG_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
   return palette->priv->style;
 }
 

Modified: trunk/libegg/toolpalette/testtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/testtoolpalette.c	(original)
+++ trunk/libegg/toolpalette/testtoolpalette.c	Sat Jan 12 00:44:05 2008
@@ -1,5 +1,6 @@
 #include "eggtoolpalette.h"
 #include "eggtoolitemgroup.h"
+#include "eggenumaction.h"
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
@@ -126,6 +127,12 @@
           <menuitem action='FileQuit' />        \
         </menu>                                 \
                                                 \
+        <menu action='ViewMenu'>                \
+          <menuitem action='ViewIconSize' />    \
+          <menuitem action='ViewOrientation' /> \
+          <menuitem action='ViewStyle' />       \
+        </menu>                                 \
+                                                \
         <menu action='HelpMenu'>                \
           <menuitem action='HelpAbout' />       \
         </menu>                                 \
@@ -136,6 +143,11 @@
         <toolitem action='FileOpen' />          \
         <toolitem action='FileSave' />          \
         <separator />                           \
+        <toolitem action='ViewIconSize' />      \
+        <toolitem action='ViewOrientation' />   \
+        <toolitem action='ViewStyle' />         \
+        <separator />                           \
+        <separator />                           \
         <toolitem action='HelpAbout' />         \
       </toolbar>                                \
     </ui>";
@@ -148,6 +160,7 @@
     { "FileSaveAs", GTK_STOCK_SAVE_AS, NULL, NULL, NULL, G_CALLBACK (not_implemented) },
     { "FileClose",  GTK_STOCK_CLOSE, NULL,   NULL, NULL, G_CALLBACK (not_implemented) },
     { "FileQuit",   GTK_STOCK_QUIT, NULL,    NULL, NULL, G_CALLBACK (gtk_main_quit) },
+    { "ViewMenu",   NULL, N_("_View"),       NULL, NULL, NULL },
     { "HelpMenu",   NULL, N_("_Help"),       NULL, NULL, NULL },
     { "HelpAbout",  GTK_STOCK_ABOUT, NULL,   NULL, NULL, G_CALLBACK (not_implemented) },
   };
@@ -160,14 +173,29 @@
   GtkWidget *menubar, *toolbar, *hpaned;
   GtkWidget *palette, *palette_scroller;
   GtkWidget *contents, *contents_scroller;
+  GtkAction *action;
 
   /* ===== menubar/toolbar ===== */
 
+  palette = egg_tool_palette_new ();
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   group = gtk_action_group_new ("");
   ui = gtk_ui_manager_new ();
 
   gtk_action_group_add_actions (group, actions, G_N_ELEMENTS (actions), window);
+
+  action = egg_enum_action_new ("ViewIconSize", _("Icon Size"), NULL, GTK_TYPE_ICON_SIZE);
+  egg_enum_action_bind (EGG_ENUM_ACTION (action), G_OBJECT (palette), "icon-size");
+  gtk_action_group_add_action (group, action);
+
+  action = egg_enum_action_new ("ViewOrientation", _("Orientation"), NULL, GTK_TYPE_ORIENTATION);
+  egg_enum_action_bind (EGG_ENUM_ACTION (action), G_OBJECT (palette), "orientation");
+  gtk_action_group_add_action (group, action);
+
+  action = egg_enum_action_new ("ViewStyle", _("Style"), NULL, GTK_TYPE_TOOLBAR_STYLE);
+  egg_enum_action_bind (EGG_ENUM_ACTION (action), G_OBJECT (palette), "toolbar-style");
+  gtk_action_group_add_action (group, action);
+
   gtk_ui_manager_insert_action_group (ui, group, -1);
 
   if (!gtk_ui_manager_add_ui_from_string (ui, ui_spec, sizeof ui_spec - 1, &error))
@@ -181,8 +209,6 @@
 
   /* ===== palette ===== */
 
-  palette = egg_tool_palette_new ();
-
   load_stock_items (EGG_TOOL_PALETTE (palette));
 
   palette_scroller = gtk_scrolled_window_new (NULL, NULL);



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