libegg r833 - in trunk: . libegg libegg/toolpalette
- From: hasselmm svn gnome org
- To: svn-commits-list gnome org
- Subject: libegg r833 - in trunk: . libegg libegg/toolpalette
- Date: Wed, 9 Jan 2008 21:46:29 +0000 (GMT)
Author: hasselmm
Date: Wed Jan 9 21:46:29 2008
New Revision: 833
URL: http://svn.gnome.org/viewvc/libegg?rev=833&view=rev
Log:
Provide initial implementation of EggToolPalette.
* configure.in: Add libegg/toolpalette/Makefile.
* libegg/Makefile.am: Add toolpalette folder.
* libegg/toolpalette/eggtoolpalette.c,
libegg/toolpalette/eggtoolpalette.h: Initial EggToolPalette code.
* libegg/toolpalette/testtoolpalette.c: Demonstate EggToolPalette.
* libegg/toolpalette/Makefile.am:
Build libeggtoolpalette.la and testtoolpalette.
Added:
trunk/libegg/toolpalette/
trunk/libegg/toolpalette/Makefile.am
trunk/libegg/toolpalette/eggtoolpalette.c
trunk/libegg/toolpalette/eggtoolpalette.h
trunk/libegg/toolpalette/testtoolpalette.c
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/libegg/Makefile.am
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Wed Jan 9 21:46:29 2008
@@ -190,5 +190,6 @@
libegg/recentchooser/xdgmime/Makefile
libegg/smclient/Makefile
libegg/fileformatchooser/Makefile
+libegg/toolpalette/Makefile
doc/Makefile
])
Modified: trunk/libegg/Makefile.am
==============================================================================
--- trunk/libegg/Makefile.am (original)
+++ trunk/libegg/Makefile.am Wed Jan 9 21:46:29 2008
@@ -31,7 +31,7 @@
sidebar druid filesystem $(background_monitor_SUBDIRS) recent-files \
$(tray_SUBDIRS) dock datetime desktopentries $(thumbnail_SUBDIRS) \
$(iconchooser_SUBDIRS) bookmarkfile recentchooser regex sequence smclient \
- fileformatchooser
+ fileformatchooser toolpalette
INCLUDES = \
$(EGG_CFLAGS) \
Added: trunk/libegg/toolpalette/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/libegg/toolpalette/Makefile.am Wed Jan 9 21:46:29 2008
@@ -0,0 +1,18 @@
+INCLUDES = \
+ $(EGG_CFLAGS) \
+ -I$(top_srcdir)/libegg/util \
+ -DEGG_COMPILATION \
+ -DGTK_DISABLE_DEPRECATED \
+ -DGDK_DISABLE_DEPRECATED \
+ -DG_DISABLE_DEPRECATED
+
+noinst_LTLIBRARIES = libeggtoolpalette.la
+noinst_PROGRAMS = testtoolpalette
+
+libeggtoolpalette_la_SOURCES = eggtoolpalette.c
+
+testtoolpalette_SOURCES = testtoolpalette.c
+testtoolpalette_LDFLAGS = libeggtoolpalette.la ../util/libeggutil.la $(EGG_LIBS)
+testtoolpalette_DEPENDENCIES = libeggtoolpalette.la ../util/libeggutil.la
+
+-include Makefile.local
Added: trunk/libegg/toolpalette/eggtoolpalette.c
==============================================================================
--- (empty file)
+++ trunk/libegg/toolpalette/eggtoolpalette.c Wed Jan 9 21:46:29 2008
@@ -0,0 +1,1028 @@
+#include "eggtoolpalette.h"
+#include "eggmarshalers.h"
+
+#include <gtk/gtk.h>
+#include <string.h>
+
+#define DEFAULT_HEADER_SPACING 2
+#define DEFAULT_EXPANDER_SIZE 16
+
+typedef struct _EggToolPaletteCategory EggToolPaletteCategory;
+typedef struct _EggToolPaletteCallbackData EggToolPaletteCallbackData;
+
+enum
+{
+ PROP_NONE
+ /* TODO: fill in properties */
+};
+
+struct _EggToolPaletteCategory
+{
+ gchar *id;
+ GArray *items;
+
+ GtkWidget *header_button;
+ GtkWidget *header_label;
+ GtkExpanderStyle expander_style;
+ guint animation_timeout;
+
+ GdkWindow *window;
+
+ guint expanded : 1;
+};
+
+struct _EggToolPalettePrivate
+{
+ EggToolPaletteCategory *current_category;
+ GArray *categories;
+
+ GtkAdjustment *hadjustment;
+ GtkAdjustment *vadjustment;
+
+ gint header_spacing;
+ gint expander_size;
+
+ guint is_drag_source : 1;
+};
+
+struct _EggToolPaletteCallbackData
+{
+ EggToolPaletteCallback callback;
+ gpointer user_data;
+};
+
+static GtkTargetEntry dnd_targets[] =
+{
+ { "application/x-egg-tool-palette-item", GTK_TARGET_SAME_APP, 0 }
+};
+
+G_DEFINE_TYPE (EggToolPalette, egg_tool_palette, GTK_TYPE_CONTAINER);
+
+static EggToolPaletteCategory*
+egg_tool_palette_get_category (EggToolPalette *self,
+ guint index)
+{
+ g_return_val_if_fail (index < self->priv->categories->len, NULL);
+
+ return g_array_index (self->priv->categories,
+ EggToolPaletteCategory*,
+ index);
+}
+
+static EggToolPaletteCategory*
+egg_tool_palette_find_category (EggToolPalette *self,
+ const gchar *id)
+{
+ guint i;
+
+ if (NULL == id)
+ id = "";
+
+ if (self->priv->current_category &&
+ strcmp (id, self->priv->current_category->id))
+ self->priv->current_category = NULL;
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+
+ if (g_str_equal (id, category->id))
+ {
+ self->priv->current_category = category;
+ break;
+ }
+ }
+
+ return self->priv->current_category;
+}
+
+static gboolean
+egg_tool_palette_header_expose_event (GtkWidget *widget,
+ GdkEventExpose *event G_GNUC_UNUSED,
+ gpointer data)
+{
+ EggToolPaletteCategory *category = data;
+ EggToolPalette *self;
+ GtkWidget *palette;
+ gint x, y;
+
+ palette = gtk_widget_get_parent (category->header_button);
+ self = EGG_TOOL_PALETTE (palette);
+
+ x = widget->allocation.x + self->priv->expander_size / 2;
+ y = widget->allocation.y + widget->allocation.height / 2;
+
+ gtk_paint_expander (widget->style, widget->window,
+ category->header_button->state,
+ &event->area, palette, NULL,
+ x, y, category->expander_style);
+
+ return FALSE;
+}
+
+static gboolean
+egg_tool_palette_expand_animation (gpointer data)
+{
+ EggToolPaletteCategory *category = data;
+ GtkWidget *palette = gtk_widget_get_parent (category->header_button);
+ gboolean finish = TRUE;
+
+ if (GTK_WIDGET_REALIZED (category->header_button))
+ {
+ GtkWidget *alignment = gtk_bin_get_child (GTK_BIN (category->header_button));
+ EggToolPalette *self = EGG_TOOL_PALETTE (palette);
+ GdkRectangle area;
+
+ area.x = alignment->allocation.x;
+ area.y = alignment->allocation.y + (alignment->allocation.height - self->priv->expander_size) / 2;
+ area.height = self->priv->expander_size;
+ area.width = self->priv->expander_size;
+
+ gdk_window_invalidate_rect (category->header_button->window, &area, TRUE);
+ }
+
+ if (category->expanded)
+ {
+ if (category->expander_style == GTK_EXPANDER_COLLAPSED)
+ {
+ category->expander_style = GTK_EXPANDER_SEMI_EXPANDED;
+ finish = FALSE;
+ }
+ else
+ category->expander_style = GTK_EXPANDER_EXPANDED;
+ }
+ else
+ {
+ if (category->expander_style == GTK_EXPANDER_EXPANDED)
+ {
+ category->expander_style = GTK_EXPANDER_SEMI_COLLAPSED;
+ finish = FALSE;
+ }
+ else
+ category->expander_style = GTK_EXPANDER_COLLAPSED;
+ }
+
+ if (finish)
+ {
+ category->animation_timeout = 0;
+ gtk_widget_queue_resize (palette);
+ }
+
+ return !finish;
+}
+
+static void
+egg_tool_palette_category_set_expanded (EggToolPaletteCategory *category,
+ gboolean expanded)
+{
+ if (category->animation_timeout)
+ g_source_remove (category->animation_timeout);
+
+ category->expanded = expanded;
+ category->animation_timeout = g_timeout_add (50, egg_tool_palette_expand_animation, category);
+}
+
+static void
+egg_tool_palette_header_clicked (GtkButton *button G_GNUC_UNUSED,
+ gpointer data)
+{
+ EggToolPaletteCategory *category = data;
+ egg_tool_palette_category_set_expanded (category, !category->expanded);
+}
+
+static EggToolPaletteCategory*
+egg_tool_palette_create_category (EggToolPalette *self,
+ const gchar *id,
+ const gchar *name)
+{
+ EggToolPaletteCategory *category;
+ GtkWidget *alignment;
+
+ g_assert (NULL != id);
+
+ category = g_slice_new0 (EggToolPaletteCategory);
+ category->items = g_array_new (TRUE, TRUE, sizeof (GtkToolItem*));
+ category->id = g_strdup (id);
+
+ category->expanded = TRUE;
+ category->expander_style = GTK_EXPANDER_EXPANDED;
+
+ gtk_widget_push_composite_child ();
+
+ category->header_button = gtk_button_new ();
+ category->header_label = gtk_label_new (name);
+
+ gtk_widget_set_composite_name (category->header_button, "header-button");
+ gtk_widget_set_composite_name (category->header_button, "header-label");
+ gtk_widget_set_composite_name (category->header_button, "header-arrow");
+
+ gtk_widget_pop_composite_child ();
+
+ alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0,
+ self->priv->header_spacing +
+ self->priv->expander_size, 0);
+ gtk_widget_set_size_request (alignment, -1, self->priv->expander_size);
+ gtk_container_add (GTK_CONTAINER (alignment), category->header_label);
+ gtk_widget_show_all (alignment);
+
+ gtk_button_set_focus_on_click (GTK_BUTTON (category->header_button), FALSE);
+ gtk_container_add (GTK_CONTAINER (category->header_button), alignment);
+ gtk_widget_set_parent (category->header_button, GTK_WIDGET (self));
+
+ g_signal_connect_after (alignment, "expose-event",
+ G_CALLBACK (egg_tool_palette_header_expose_event),
+ category);
+
+ g_signal_connect (category->header_button, "clicked",
+ G_CALLBACK (egg_tool_palette_header_clicked),
+ category);
+
+ if (name)
+ gtk_widget_show (category->header_button);
+
+ g_array_append_val (self->priv->categories, category);
+ self->priv->current_category = category;
+ return self->priv->current_category;
+}
+
+static void
+egg_tool_palette_category_free (EggToolPaletteCategory *category)
+{
+ if (category->header_button)
+ gtk_widget_unparent (category->header_button);
+ if (category->window)
+ g_object_unref (category->window);
+ if (category->items)
+ g_array_free (category->items, TRUE);
+
+ g_slice_free (EggToolPaletteCategory, category);
+}
+
+static GtkToolItem*
+egg_tool_palette_category_get_child (EggToolPaletteCategory *category,
+ guint index)
+{
+ g_return_val_if_fail (index < category->items->len, NULL);
+ return g_array_index (category->items, GtkToolItem*, index);
+}
+
+static void
+egg_tool_palette_init (EggToolPalette *self)
+{
+ gtk_widget_set_redraw_on_allocate (GTK_WIDGET (self), FALSE);
+#if 0
+ GTK_WIDGET_SET_FLAGS (self, GTK_NO_WINDOW);
+#endif
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EGG_TYPE_TOOL_PALETTE,
+ EggToolPalettePrivate);
+
+ self->priv->categories = g_array_new (TRUE, TRUE, sizeof (EggToolPaletteCategory*));
+ egg_tool_palette_create_category (self, "", NULL);
+}
+
+#if 0
+static void
+egg_tool_palette_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (object);
+
+ switch (prop_id)
+ {
+ /* TODO: handle properties */
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+egg_tool_palette_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (object);
+
+ switch (prop_id)
+ {
+ /* TODO: handle properties */
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+#endif
+
+static void
+egg_tool_palette_dispose (GObject *object)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (object);
+ guint i;
+
+ gtk_container_forall (GTK_CONTAINER (self), (GtkCallback) g_object_unref, NULL);
+
+ if (self->priv->hadjustment)
+ {
+ g_object_unref (self->priv->hadjustment);
+ self->priv->hadjustment = NULL;
+ }
+
+ if (self->priv->vadjustment)
+ {
+ g_object_unref (self->priv->vadjustment);
+ self->priv->vadjustment = NULL;
+ }
+
+ if (self->priv->categories)
+ {
+ for (i = 0; i < self->priv->categories->len; ++i)
+ egg_tool_palette_category_free (egg_tool_palette_get_category (self, i));
+
+ g_array_free (self->priv->categories, TRUE);
+ self->priv->categories = NULL;
+ }
+
+ G_OBJECT_CLASS (egg_tool_palette_parent_class)->dispose (object);
+}
+
+static void
+egg_tool_palette_realize (GtkWidget *widget)
+{
+ const gint border_width = GTK_CONTAINER (widget)->border_width;
+ gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ GdkWindowAttr attributes;
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.x = widget->allocation.x + border_width;
+ attributes.y = widget->allocation.y + border_width;
+ attributes.width = widget->allocation.width - border_width * 2;
+ attributes.height = widget->allocation.height - border_width * 2;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ | GDK_BUTTON_MOTION_MASK;
+
+ widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+
+ gdk_window_set_user_data (widget->window, widget);
+
+ widget->style = gtk_style_attach (widget->style, widget->window);
+ gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+
+ gtk_container_forall (GTK_CONTAINER (widget),
+ (GtkCallback) gtk_widget_set_parent_window,
+ widget->window);
+
+ gtk_widget_queue_resize_no_redraw (widget);
+}
+
+static void
+egg_tool_palette_unrealize (GtkWidget *widget)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (widget);
+ guint i;
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+
+ if (category->animation_timeout)
+ {
+ g_source_remove (category->animation_timeout);
+ category->animation_timeout = 0;
+ }
+
+ if (category->window)
+ {
+ g_object_unref (category->window);
+ category->window = NULL;
+ }
+ }
+}
+
+static void
+egg_tool_palette_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (widget);
+ guint i;
+
+ requisition->width = requisition->height = 0;
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+ GtkRequisition child_requistion;
+
+ if (GTK_WIDGET_VISIBLE (category->header_button))
+ {
+ gtk_widget_size_request (category->header_button, &child_requistion);
+ requisition->width = MAX (requisition->width, child_requistion.width);
+ requisition->height += child_requistion.height;
+ }
+ }
+
+ requisition->width += GTK_CONTAINER (self)->border_width * 2;
+ requisition->height += GTK_CONTAINER (self)->border_width * 2;
+}
+
+static void
+egg_tool_palette_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ const gint border_width = GTK_CONTAINER (widget)->border_width;
+ EggToolPalette *self = EGG_TOOL_PALETTE (widget);
+ GtkRequisition child_requistion;
+ GtkAllocation child_allocation;
+ gint item_height = 0;
+ gint item_width = 0;
+ gint offset = 0;
+ guint i, j;
+
+ GTK_WIDGET_CLASS (egg_tool_palette_parent_class)->size_allocate (widget, allocation);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ gdk_window_move_resize (widget->window,
+ allocation->x + border_width,
+ allocation->y + border_width,
+ allocation->width - border_width * 2,
+ allocation->height - border_width * 2);
+ }
+
+ if (self->priv->vadjustment)
+ offset = -gtk_adjustment_get_value (self->priv->vadjustment);
+
+ child_allocation.x = border_width;
+ child_allocation.y = border_width + offset;
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+
+ for (j = 0; j < category->items->len; ++j)
+ {
+ GtkToolItem *child = egg_tool_palette_category_get_child (category, j);
+
+ gtk_widget_size_request (GTK_WIDGET (child), &child_requistion);
+
+ item_width = MAX (item_width, child_requistion.width);
+ item_height = MAX (item_height, child_requistion.height);
+ }
+ }
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+
+ if (!category->items->len)
+ continue;
+
+ if (GTK_WIDGET_VISIBLE (category->header_button))
+ {
+ gtk_widget_size_request (category->header_button, &child_requistion);
+
+ child_allocation.width = allocation->width - border_width * 2;
+ child_allocation.height = child_requistion.height;
+
+ gtk_widget_size_allocate (category->header_button, &child_allocation);
+
+ child_allocation.y += child_allocation.height;
+ }
+
+ if (category->expanded)
+ {
+ for (j = 0; j < category->items->len; ++j)
+ {
+ GtkToolItem *child = egg_tool_palette_category_get_child (category, j);
+
+ child_allocation.width = item_width;
+ child_allocation.height = item_height;
+
+ if (child_allocation.x + child_allocation.width > allocation->width)
+ {
+ child_allocation.y += child_allocation.height;
+ child_allocation.x = border_width;
+ }
+
+ gtk_widget_size_allocate (GTK_WIDGET (child), &child_allocation);
+ gtk_widget_show (GTK_WIDGET (child));
+
+ child_allocation.x += child_allocation.width;
+ }
+
+ child_allocation.y += item_height;
+ child_allocation.x = border_width;
+ }
+ else
+ {
+ for (j = 0; j < category->items->len; ++j)
+ {
+ GtkToolItem *child = egg_tool_palette_category_get_child (category, j);
+ gtk_widget_hide (GTK_WIDGET (child));
+ }
+ }
+ }
+
+ child_allocation.y += border_width;
+
+ if (self->priv->vadjustment)
+ {
+ self->priv->vadjustment->page_size = allocation->height;
+ self->priv->vadjustment->page_increment = allocation->height * 0.9;
+ self->priv->vadjustment->step_increment = allocation->height * 0.1;
+ self->priv->vadjustment->upper = MAX (0, child_allocation.y - offset);
+
+ gtk_adjustment_changed (self->priv->vadjustment);
+ gtk_adjustment_clamp_page (self->priv->vadjustment, -offset, allocation->height -offset);
+ }
+
+ if (GTK_WIDGET_MAPPED (widget))
+ gdk_window_invalidate_rect (widget->window, NULL, FALSE);
+}
+
+static gboolean
+egg_tool_palette_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (widget);
+ guint i;
+
+ if (GTK_WIDGET_CLASS (egg_tool_palette_parent_class)->expose_event (widget, event))
+ return TRUE;
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+
+ if (category->window)
+ {
+ /* TODO: draw composited window */
+ }
+ }
+
+ return FALSE;
+}
+
+static void
+egg_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment G_GNUC_UNUSED,
+ gpointer data)
+{
+ GtkWidget *widget = GTK_WIDGET (data);
+ egg_tool_palette_size_allocate (widget, &widget->allocation);
+}
+
+static void
+egg_tool_palette_set_scroll_adjustments (GtkWidget *widget,
+ GtkAdjustment *hadjustment,
+ GtkAdjustment *vadjustment)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (widget);
+
+ if (self->priv->hadjustment)
+ g_object_unref (self->priv->hadjustment);
+ if (self->priv->vadjustment)
+ g_object_unref (self->priv->vadjustment);
+
+ if (hadjustment)
+ g_object_ref_sink (hadjustment);
+ if (vadjustment)
+ g_object_ref_sink (vadjustment);
+
+ self->priv->hadjustment = hadjustment;
+ self->priv->vadjustment = vadjustment;
+
+ if (self->priv->hadjustment)
+ g_signal_connect (self->priv->hadjustment, "value-changed",
+ G_CALLBACK (egg_tool_palette_adjustment_value_changed),
+ self);
+ if (self->priv->vadjustment)
+ g_signal_connect (self->priv->vadjustment, "value-changed",
+ G_CALLBACK (egg_tool_palette_adjustment_value_changed),
+ self);
+}
+
+static void
+egg_tool_palette_style_set (GtkWidget *widget,
+ GtkStyle *previous_style)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (widget);
+ guint i;
+
+ self->priv->header_spacing = DEFAULT_HEADER_SPACING; /* TODO: use real style property */
+ self->priv->expander_size = DEFAULT_EXPANDER_SIZE; /* TODO: use real style property */
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+ GtkWidget *alignment = NULL;
+
+ if (category->header_button)
+ {
+ alignment = gtk_bin_get_child (GTK_BIN (category->header_button));
+
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0,
+ self->priv->header_spacing +
+ self->priv->expander_size, 0);
+ gtk_widget_set_size_request (alignment, -1, self->priv->expander_size);
+ }
+ }
+
+ GTK_WIDGET_CLASS (egg_tool_palette_parent_class)->style_set (widget, previous_style);
+}
+
+static void
+egg_tool_palette_add (GtkContainer *container G_GNUC_UNUSED,
+ GtkWidget *child G_GNUC_UNUSED)
+{
+ g_return_if_reached ();
+}
+
+static void
+egg_tool_palette_remove (GtkContainer *container G_GNUC_UNUSED,
+ GtkWidget *child G_GNUC_UNUSED)
+{
+ g_return_if_reached ();
+}
+
+static void
+egg_tool_palette_forall (GtkContainer *container,
+ gboolean internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ EggToolPalette *self = EGG_TOOL_PALETTE (container);
+ guint i, j;
+
+ if (NULL == self->priv->categories)
+ return;
+
+ for (i = 0; i < self->priv->categories->len; ++i)
+ {
+ EggToolPaletteCategory *category = egg_tool_palette_get_category (self, i);
+
+ if (internals && category->header_button)
+ callback (category->header_button, callback_data);
+
+ for (j = 0; j < category->items->len; ++j)
+ {
+ GtkToolItem *child = egg_tool_palette_category_get_child (category, j);
+ callback (GTK_WIDGET (child), callback_data);
+ }
+ }
+}
+
+static GType
+egg_tool_palette_child_type (GtkContainer *container G_GNUC_UNUSED)
+{
+ return GTK_TYPE_TOOL_ITEM;
+}
+
+static void
+egg_tool_palette_class_init (EggToolPaletteClass *cls)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (cls);
+ GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
+ GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
+
+#if 0
+ oclass->set_property = egg_tool_palette_set_property;
+ oclass->get_property = egg_tool_palette_get_property;
+#endif
+ oclass->dispose = egg_tool_palette_dispose;
+
+ wclass->realize = egg_tool_palette_realize;
+ wclass->unrealize = egg_tool_palette_unrealize;
+ wclass->size_request = egg_tool_palette_size_request;
+ wclass->size_allocate = egg_tool_palette_size_allocate;
+ wclass->expose_event = egg_tool_palette_expose_event;
+ wclass->style_set = egg_tool_palette_style_set;
+
+ cclass->add = egg_tool_palette_add;
+ cclass->remove = egg_tool_palette_remove;
+ cclass->forall = egg_tool_palette_forall;
+ cclass->child_type = egg_tool_palette_child_type;
+
+ cls->set_scroll_adjustments = egg_tool_palette_set_scroll_adjustments;
+
+ wclass->set_scroll_adjustments_signal =
+ g_signal_new ("set-scroll-adjustments",
+ G_TYPE_FROM_CLASS (oclass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EggToolPaletteClass, set_scroll_adjustments),
+ NULL, NULL,
+ _egg_marshal_VOID__OBJECT_OBJECT,
+ G_TYPE_NONE, 2,
+ GTK_TYPE_ADJUSTMENT,
+ GTK_TYPE_ADJUSTMENT);
+
+ g_type_class_add_private (cls, sizeof (EggToolPalettePrivate));
+}
+
+/* ===== instance handling ===== */
+
+GtkWidget*
+egg_tool_palette_new (void)
+{
+ return g_object_new (EGG_TYPE_TOOL_PALETTE, NULL);
+}
+
+/* ===== category settings ===== */
+
+void
+egg_tool_palette_set_category_name (EggToolPalette *self,
+ const gchar *category,
+ const gchar *name G_GNUC_UNUSED)
+{
+ EggToolPaletteCategory *category_info;
+
+ g_return_if_fail (EGG_IS_TOOL_PALETTE (self));
+ g_return_if_fail (NULL != category);
+
+ category_info = egg_tool_palette_find_category (self, category);
+
+ if (category_info)
+ {
+ gtk_label_set_text (GTK_LABEL (category_info->header_label), name);
+ gtk_widget_show (category_info->header_button);
+ }
+}
+
+void
+egg_tool_palette_set_category_position (EggToolPalette *self,
+ const gchar *category,
+ gint position G_GNUC_UNUSED)
+{
+ g_return_if_fail (EGG_IS_TOOL_PALETTE (self));
+ g_return_if_fail (NULL != category);
+ g_return_if_reached ();
+}
+
+void
+egg_tool_palette_set_category_expanded (EggToolPalette *self,
+ const gchar *category,
+ gboolean expanded)
+{
+ EggToolPaletteCategory *category_info;
+
+ g_return_if_fail (EGG_IS_TOOL_PALETTE (self));
+ g_return_if_fail (NULL != category);
+
+ category_info = egg_tool_palette_find_category (self, category);
+ g_return_if_fail (NULL != category_info);
+
+ egg_tool_palette_category_set_expanded (category_info, expanded);
+}
+
+G_CONST_RETURN gchar*
+egg_tool_palette_get_category_name (EggToolPalette *self,
+ const gchar *category)
+{
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), NULL);
+ g_return_val_if_fail (NULL != category, NULL);
+ g_return_val_if_reached (NULL);
+}
+
+gint
+egg_tool_palette_get_category_position (EggToolPalette *self,
+ const gchar *category)
+{
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), 0);
+ g_return_val_if_fail (NULL != category, 0);
+ g_return_val_if_reached (0);
+}
+
+gboolean
+egg_tool_palette_get_category_expanded (EggToolPalette *self,
+ const gchar *category)
+{
+ EggToolPaletteCategory *category_info;
+
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), FALSE);
+ g_return_val_if_fail (NULL != category, FALSE);
+
+ category_info = egg_tool_palette_find_category (self, category);
+ g_return_val_if_fail (NULL != category_info, FALSE);
+
+ return category_info->expanded;
+}
+
+/* ===== item packing ===== */
+
+static void
+egg_tool_palette_item_drag_data_get (GtkWidget *widget,
+ GdkDragContext *context G_GNUC_UNUSED,
+ GtkSelectionData *selection,
+ guint info G_GNUC_UNUSED,
+ guint time G_GNUC_UNUSED,
+ gpointer data G_GNUC_UNUSED)
+{
+ const gchar *target_name = gdk_atom_name (selection->target);
+
+ if (g_str_equal (target_name, dnd_targets[0].target))
+ gtk_selection_data_set (selection, selection->target, 8,
+ (guchar*) &widget, sizeof (&widget));
+}
+
+static void
+egg_tool_palette_item_set_drag_source (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_tool_item_set_use_drag_window (GTK_TOOL_ITEM (widget), TRUE);
+ gtk_drag_source_set (widget, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
+ dnd_targets, G_N_ELEMENTS (dnd_targets),
+ GDK_ACTION_COPY);
+
+ g_signal_connect (widget, "drag-data-get",
+ G_CALLBACK (egg_tool_palette_item_drag_data_get),
+ data);
+}
+
+void
+egg_tool_palette_insert (EggToolPalette *self,
+ const gchar *category,
+ GtkToolItem *item,
+ gint position)
+{
+ EggToolPaletteCategory *category_info;
+
+ g_return_if_fail (EGG_IS_TOOL_PALETTE (self));
+ g_return_if_fail (GTK_IS_TOOL_ITEM (item));
+ g_return_if_fail (position >= -1);
+
+ category_info = egg_tool_palette_find_category (self, category);
+
+ if (NULL == category_info)
+ category_info = egg_tool_palette_create_category (self, category, NULL);
+ if (-1 == position)
+ position = category_info->items->len;
+
+ g_return_if_fail ((guint) position <= category_info->items->len);
+ g_array_insert_val (category_info->items, position, item);
+
+ if (self->priv->is_drag_source)
+ egg_tool_palette_item_set_drag_source (GTK_WIDGET (item), self);
+
+ gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (self));
+ g_object_ref (item);
+}
+
+gint
+egg_tool_palette_get_n_items (EggToolPalette *self,
+ const gchar *category)
+{
+ EggToolPaletteCategory *category_info;
+
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), 0);
+ category_info = egg_tool_palette_find_category (self, category);
+
+ if (NULL != category_info)
+ return category_info->items->len;
+
+ return 0;
+}
+
+GtkToolItem*
+egg_tool_palette_get_nth_item (EggToolPalette *self,
+ const gchar *category,
+ gint index)
+{
+ EggToolPaletteCategory *category_info;
+
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), NULL);
+ category_info = egg_tool_palette_find_category (self, category);
+
+ if (NULL != category_info)
+ return egg_tool_palette_category_get_child (category_info, index);
+
+ return 0;
+}
+
+GtkToolItem*
+egg_tool_palette_get_drop_item (EggToolPalette *self,
+ gint x G_GNUC_UNUSED,
+ gint y G_GNUC_UNUSED)
+{
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), NULL);
+ g_return_val_if_reached (NULL);
+}
+
+/* ===== item settings ===== */
+
+void
+egg_tool_palette_set_item_category (EggToolPalette *self,
+ GtkToolItem *item,
+ const gchar *category G_GNUC_UNUSED)
+{
+ g_return_if_fail (EGG_IS_TOOL_PALETTE (self));
+ g_return_if_fail (GTK_IS_TOOL_ITEM (item));
+ g_return_if_reached ();
+}
+
+void
+egg_tool_palette_set_item_position (EggToolPalette *self,
+ GtkToolItem *item,
+ gint position G_GNUC_UNUSED)
+{
+ g_return_if_fail (EGG_IS_TOOL_PALETTE (self));
+ g_return_if_fail (GTK_IS_TOOL_ITEM (item));
+ g_return_if_reached ();
+}
+
+G_CONST_RETURN gchar*
+egg_tool_palette_get_item_category (EggToolPalette *self,
+ GtkToolItem *item)
+{
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), NULL);
+ g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), NULL);
+ g_return_val_if_reached (NULL);
+}
+
+gint
+egg_tool_palette_get_item_position (EggToolPalette *self,
+ GtkToolItem *item)
+{
+ g_return_val_if_fail (EGG_IS_TOOL_PALETTE (self), 0);
+ g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), 0);
+ g_return_val_if_reached (0);
+}
+
+void
+egg_tool_palette_set_drag_source (EggToolPalette *self)
+{
+ if (self->priv->is_drag_source)
+ return;
+
+ gtk_container_foreach (GTK_CONTAINER (self),
+ egg_tool_palette_item_set_drag_source,
+ self);
+
+ self->priv->is_drag_source = TRUE;
+}
+
+static void
+egg_tool_palette_drag_data_received (GtkWidget *widget G_GNUC_UNUSED,
+ GdkDragContext *context G_GNUC_UNUSED,
+ gint x G_GNUC_UNUSED,
+ gint y G_GNUC_UNUSED,
+ GtkSelectionData *selection G_GNUC_UNUSED,
+ guint info G_GNUC_UNUSED,
+ guint time G_GNUC_UNUSED,
+ gpointer data)
+{
+ GtkWidget *item = *(GtkWidget**) selection->data;
+ EggToolPaletteCallbackData *callback_data = data;
+ EggToolPalette *palette;
+
+ if (GTK_IS_TOOL_ITEM (item))
+ {
+ palette = EGG_TOOL_PALETTE (gtk_widget_get_parent (item));
+ callback_data->callback (palette, GTK_TOOL_ITEM (item), callback_data->user_data);
+ }
+}
+
+static void
+egg_tool_palette_callback_data_free (gpointer data,
+ GClosure *closure G_GNUC_UNUSED)
+{
+ g_slice_free (EggToolPaletteCallbackData, data);
+}
+
+void
+egg_tool_palette_add_drag_dest (EggToolPalette *self,
+ GtkWidget *widget,
+ EggToolPaletteCallback callback,
+ gpointer user_data)
+{
+ EggToolPaletteCallbackData *callback_data;
+
+ g_return_if_fail (EGG_IS_TOOL_PALETTE (self));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (NULL != callback);
+
+ callback_data = g_slice_new (EggToolPaletteCallbackData);
+ callback_data->user_data = user_data;
+ callback_data->callback = callback;
+
+ gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL,
+ dnd_targets, G_N_ELEMENTS (dnd_targets),
+ GDK_ACTION_COPY);
+
+ g_signal_connect_data (widget, "drag-data-received",
+ G_CALLBACK (egg_tool_palette_drag_data_received),
+ callback_data, egg_tool_palette_callback_data_free, 0);
+}
+
Added: trunk/libegg/toolpalette/eggtoolpalette.h
==============================================================================
--- (empty file)
+++ trunk/libegg/toolpalette/eggtoolpalette.h Wed Jan 9 21:46:29 2008
@@ -0,0 +1,103 @@
+#ifndef __EGG_TOOL_PALETTE_H__
+#define __EGG_TOOL_PALETTE_H__
+
+#include <gtk/gtkcontainer.h>
+#include <gtk/gtktoolitem.h>
+
+G_BEGIN_DECLS
+
+#define EGG_TYPE_TOOL_PALETTE (egg_tool_palette_get_type())
+#define EGG_TOOL_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, EGG_TYPE_TOOL_PALETTE, EggToolPalette))
+#define EGG_TOOL_PALETTE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST(cls, EGG_TYPE_TOOL_PALETTE, EggToolPaletteClass))
+#define EGG_IS_TOOL_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, EGG_TYPE_TOOL_PALETTE))
+#define EGG_IS_TOOL_PALETTE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE(obj, EGG_TYPE_TOOL_PALETTE))
+#define EGG_TOOL_PALETTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EGG_TYPE_TOOL_PALETTE, EggToolPaletteClass))
+
+typedef struct _EggToolPalette EggToolPalette;
+typedef struct _EggToolPaletteClass EggToolPaletteClass;
+typedef struct _EggToolPalettePrivate EggToolPalettePrivate;
+
+typedef void (*EggToolPaletteCallback) (EggToolPalette *palette,
+ GtkToolItem *item,
+ gpointer data);
+
+struct _EggToolPalette
+{
+ GtkContainer parent_instance;
+ EggToolPalettePrivate *priv;
+};
+
+struct _EggToolPaletteClass
+{
+ GtkContainerClass parent_class;
+
+ void (*set_scroll_adjustments) (GtkWidget *widget,
+ GtkAdjustment *hadjustment,
+ GtkAdjustment *vadjustment);
+};
+
+/* ===== instance handling ===== */
+
+GType egg_tool_palette_get_type (void) G_GNUC_CONST;
+GtkWidget* egg_tool_palette_new (void);
+
+/* ===== category settings ===== */
+
+void egg_tool_palette_set_category_name (EggToolPalette *palette,
+ const gchar *category,
+ const gchar *name);
+void egg_tool_palette_set_category_position (EggToolPalette *palette,
+ const gchar *category,
+ gint position);
+void egg_tool_palette_set_category_expanded (EggToolPalette *palette,
+ const gchar *category,
+ gboolean expanded);
+
+G_CONST_RETURN gchar* egg_tool_palette_get_category_name (EggToolPalette *palette,
+ const gchar *category);
+gint egg_tool_palette_get_category_position (EggToolPalette *palette,
+ const gchar *category);
+gboolean egg_tool_palette_get_category_expanded (EggToolPalette *palette,
+ const gchar *category);
+
+/* ===== item packing ===== */
+
+void egg_tool_palette_insert (EggToolPalette *palette,
+ const gchar *category,
+ GtkToolItem *item,
+ gint position);
+
+gint egg_tool_palette_get_n_items (EggToolPalette *palette,
+ const gchar *category);
+GtkToolItem* egg_tool_palette_get_nth_item (EggToolPalette *palette,
+ const gchar *category,
+ gint index);
+GtkToolItem* egg_tool_palette_get_drop_item (EggToolPalette *palette,
+ gint x,
+ gint y);
+
+/* ===== item settings ===== */
+
+void egg_tool_palette_set_item_category (EggToolPalette *palette,
+ GtkToolItem *item,
+ const gchar *category);
+void egg_tool_palette_set_item_position (EggToolPalette *palette,
+ GtkToolItem *item,
+ gint position);
+
+G_CONST_RETURN gchar* egg_tool_palette_get_item_category (EggToolPalette *palette,
+ GtkToolItem *item);
+gint egg_tool_palette_get_item_position (EggToolPalette *palette,
+ GtkToolItem *item);
+
+/* ===== drag-and-drop ===== */
+
+void egg_tool_palette_set_drag_source (EggToolPalette *palette);
+void egg_tool_palette_add_drag_dest (EggToolPalette *palette,
+ GtkWidget *widget,
+ EggToolPaletteCallback callback,
+ gpointer user_data);
+
+G_END_DECLS
+
+#endif /* __EGG_TOOL_PALETTE_H__ */
Added: trunk/libegg/toolpalette/testtoolpalette.c
==============================================================================
--- (empty file)
+++ trunk/libegg/toolpalette/testtoolpalette.c Wed Jan 9 21:46:29 2008
@@ -0,0 +1,241 @@
+#include "eggtoolpalette.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <string.h>
+
+static void
+not_implemented (GtkAction *action,
+ GtkWindow *parent)
+{
+ GtkWidget *dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_CLOSE,
+ _("Not implemented yet."));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("Sorry, the '%s' action is not implemented."),
+ gtk_action_get_name (action));
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+static void
+load_stock_items (EggToolPalette *palette)
+{
+ const gchar *group = NULL;
+ GtkToolItem *item;
+ GSList *stock_ids;
+ GSList *iter;
+
+ stock_ids = gtk_stock_list_ids ();
+ stock_ids = g_slist_sort (stock_ids, (GCompareFunc) strcmp);
+
+ for (iter = stock_ids; iter; iter = g_slist_next (iter))
+ {
+ gchar *id = iter->data;
+
+ switch (id[4])
+ {
+ case 'a':
+ group = "stock-icons-af";
+ break;
+
+ case 'g':
+ group = "stock-icons-gn";
+ break;
+
+ case 'o':
+ group = "stock-icons-or";
+ break;
+
+ case 's':
+ group = "stock-icons-sz";
+ break;
+ }
+
+ item = gtk_tool_button_new_from_stock (id);
+ gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item), id);
+ egg_tool_palette_insert (palette, group, item, -1);
+
+ g_free (id);
+ }
+
+ g_slist_free (stock_ids);
+}
+
+static void
+contents_drop_cb (EggToolPalette *palette G_GNUC_UNUSED,
+ GtkToolItem *item,
+ gpointer data)
+{
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (data);
+ const gchar *stock_id = gtk_tool_button_get_stock_id (GTK_TOOL_BUTTON (item));
+ gtk_text_buffer_set_text (buffer, stock_id, -1);
+}
+
+static GtkWidget*
+create_ui (void)
+{
+ static const gchar ui_spec[] = " \
+ <ui> \
+ <menubar> \
+ <menu action='FileMenu'> \
+ <menuitem action='FileNew' /> \
+ <menuitem action='FileOpen' /> \
+ <separator /> \
+ <menuitem action='FileSave' /> \
+ <menuitem action='FileSaveAs' /> \
+ <separator /> \
+ <menuitem action='FileClose' /> \
+ <menuitem action='FileQuit' /> \
+ </menu> \
+ \
+ <menu action='HelpMenu'> \
+ <menuitem action='HelpAbout' /> \
+ </menu> \
+ </menubar> \
+ \
+ <toolbar> \
+ <toolitem action='FileNew' /> \
+ <toolitem action='FileOpen' /> \
+ <toolitem action='FileSave' /> \
+ <separator /> \
+ <toolitem action='HelpAbout' /> \
+ </toolbar> \
+ </ui>";
+
+ static GtkActionEntry actions[] = {
+ { "FileMenu", NULL, N_("_File"), NULL, NULL, NULL },
+ { "FileNew", GTK_STOCK_NEW, NULL, NULL, NULL, G_CALLBACK (not_implemented) },
+ { "FileOpen", GTK_STOCK_OPEN, NULL, NULL, NULL, G_CALLBACK (not_implemented) },
+ { "FileSave", GTK_STOCK_SAVE, NULL, NULL, NULL, G_CALLBACK (not_implemented) },
+ { "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) },
+ { "HelpMenu", NULL, N_("_Help"), NULL, NULL, NULL },
+ { "HelpAbout", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK (not_implemented) },
+ };
+
+ GtkActionGroup *group;
+ GError *error = NULL;
+ GtkUIManager *ui;
+
+ GtkWidget *window, *vbox;
+ GtkWidget *menubar, *toolbar, *hpaned;
+ GtkWidget *palette, *palette_scroller;
+ GtkWidget *contents, *contents_scroller;
+
+ /* ===== menubar/toolbar ===== */
+
+ 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);
+ 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))
+ {
+ g_message ("building ui_spec failed: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ menubar = gtk_ui_manager_get_widget (ui, "/menubar");
+ toolbar = gtk_ui_manager_get_widget (ui, "/toolbar");
+
+ /* ===== palette ===== */
+
+ palette = egg_tool_palette_new ();
+
+ load_stock_items (EGG_TOOL_PALETTE (palette));
+
+ egg_tool_palette_set_category_name (EGG_TOOL_PALETTE (palette),
+ "stock-icons-af", _("Stock Icons (A-F)"));
+ egg_tool_palette_set_category_name (EGG_TOOL_PALETTE (palette),
+ "stock-icons-gn", _("Stock Icons (G-N)"));
+ egg_tool_palette_set_category_name (EGG_TOOL_PALETTE (palette),
+ "stock-icons-or", _("Stock Icons (O-R)"));
+ egg_tool_palette_set_category_name (EGG_TOOL_PALETTE (palette),
+ "stock-icons-sz", _("Stock Icons (S-Z)"));
+
+ egg_tool_palette_set_drag_source (EGG_TOOL_PALETTE (palette));
+
+ palette_scroller = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (palette_scroller),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ gtk_container_set_border_width (GTK_CONTAINER (palette_scroller), 6);
+ gtk_container_add (GTK_CONTAINER (palette_scroller), palette);
+
+ /* ===== contents ===== */
+
+ contents = gtk_text_view_new ();
+ gtk_widget_set_size_request (contents, 100, 400);
+ egg_tool_palette_add_drag_dest (EGG_TOOL_PALETTE (palette),
+ contents, contents_drop_cb,
+ contents);
+
+ contents_scroller = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (contents_scroller),
+ GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (contents_scroller),
+ GTK_SHADOW_IN);
+ gtk_container_add (GTK_CONTAINER (contents_scroller), contents);
+ gtk_container_set_border_width (GTK_CONTAINER (contents_scroller), 6);
+
+ /* ===== hpaned ===== */
+
+ hpaned = gtk_hpaned_new ();
+ gtk_paned_pack1 (GTK_PANED (hpaned), palette_scroller, FALSE, FALSE);
+ gtk_paned_pack2 (GTK_PANED (hpaned), contents_scroller, TRUE, FALSE);
+
+ /* ===== vbox ===== */
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
+ gtk_widget_show_all (vbox);
+
+ /* ===== window ===== */
+
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_window_set_default_size (GTK_WINDOW (window), 600, 500);
+ gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (ui));
+ g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+
+ g_object_unref (ui);
+ return window;
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ GtkWidget *ui;
+
+ gtk_init (&argc, &argv);
+
+ gtk_rc_parse_string (" \
+ style 'egg-tool-palette-header' { \
+ bg[NORMAL] = @selected_bg_color \
+ fg[NORMAL] = @selected_fg_color \
+ bg[PRELIGHT] = shade(1.04, @selected_bg_color) \
+ fg[PRELIGHT] = @selected_fg_color \
+ bg[ACTIVE] = shade(0.9, @selected_bg_color) \
+ fg[ACTIVE] = shade(0.9, @selected_fg_color) \
+ font_name = 'Sans Serif Bold 10.' \
+ } \
+ \
+ widget_class '*<EggToolPalette>.GtkButton*' \
+ style 'egg-tool-palette-header' \
+ ");
+
+ ui = create_ui ();
+ gtk_widget_show (ui);
+ gtk_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]