summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorArturo Espinosa <unammx@src.gnome.org>1997-12-23 06:11:36 +0000
committerArturo Espinosa <unammx@src.gnome.org>1997-12-23 06:11:36 +0000
commit104f72cf9534c1c4d3f5ac8bb45c2b1d8ec1576d (patch)
treebbac77d0088f9f19b56c1814a46a85fc60fcb78d /gtk
parent7bac5c59eb2c26dc5293125fd66442c7d8898d8f (diff)
downloadgtk+-104f72cf9534c1c4d3f5ac8bb45c2b1d8ec1576d.tar.gz
Added "orientation_changed" and "style_changed" signals to GtkToolbar.
Fixed some nits. - Federico
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtktoolbar.c203
-rw-r--r--gtk/gtktoolbar.h68
-rw-r--r--gtk/testgtk.c193
3 files changed, 408 insertions, 56 deletions
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 55c20480a1..6afa9435d5 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -26,6 +26,13 @@
#define DEFAULT_SPACE_SIZE 5
+enum {
+ ORIENTATION_CHANGED,
+ STYLE_CHANGED,
+ LAST_SIGNAL
+};
+
+
typedef struct {
GtkWidget *button;
GtkWidget *icon;
@@ -33,25 +40,42 @@ typedef struct {
} Child;
-static void gtk_toolbar_class_init (GtkToolbarClass *class);
-static void gtk_toolbar_init (GtkToolbar *toolbar);
-static void gtk_toolbar_destroy (GtkObject *object);
-static void gtk_toolbar_map (GtkWidget *widget);
-static void gtk_toolbar_unmap (GtkWidget *widget);
-static void gtk_toolbar_draw (GtkWidget *widget,
- GdkRectangle *area);
-static void gtk_toolbar_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_toolbar_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static void gtk_toolbar_add (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_toolbar_foreach (GtkContainer *container,
- GtkCallback callback,
- gpointer callback_data);
+typedef void (*GtkToolbarSignal1) (GtkObject *object,
+ gint arg1,
+ gpointer data);
+
+static void gtk_toolbar_marshal_signal_1 (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
+
+
+static void gtk_toolbar_class_init (GtkToolbarClass *class);
+static void gtk_toolbar_init (GtkToolbar *toolbar);
+static void gtk_toolbar_destroy (GtkObject *object);
+static void gtk_toolbar_map (GtkWidget *widget);
+static void gtk_toolbar_unmap (GtkWidget *widget);
+static void gtk_toolbar_draw (GtkWidget *widget,
+ GdkRectangle *area);
+static void gtk_toolbar_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void gtk_toolbar_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static void gtk_toolbar_add (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_toolbar_foreach (GtkContainer *container,
+ GtkCallback callback,
+ gpointer callback_data);
+static void gtk_real_toolbar_orientation_changed (GtkToolbar *toolbar,
+ GtkOrientation orientation);
+static void gtk_real_toolbar_style_changed (GtkToolbar *toolbar,
+ GtkToolbarStyle style);
+
static GtkContainerClass *parent_class;
+static gint toolbar_signals[LAST_SIGNAL] = { 0 };
+
guint
gtk_toolbar_get_type(void)
@@ -87,6 +111,25 @@ gtk_toolbar_class_init(GtkToolbarClass *class)
parent_class = gtk_type_class(gtk_container_get_type());
+ toolbar_signals[ORIENTATION_CHANGED] =
+ gtk_signal_new("orientation_changed",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET(GtkToolbarClass, orientation_changed),
+ gtk_toolbar_marshal_signal_1,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_INT);
+ toolbar_signals[STYLE_CHANGED] =
+ gtk_signal_new("style_changed",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET(GtkToolbarClass, style_changed),
+ gtk_toolbar_marshal_signal_1,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_INT);
+
+ gtk_object_class_add_signals(object_class, toolbar_signals, LAST_SIGNAL);
+
object_class->destroy = gtk_toolbar_destroy;
widget_class->map = gtk_toolbar_map;
@@ -97,6 +140,9 @@ gtk_toolbar_class_init(GtkToolbarClass *class)
container_class->add = gtk_toolbar_add;
container_class->foreach = gtk_toolbar_foreach;
+
+ class->orientation_changed = gtk_real_toolbar_orientation_changed;
+ class->style_changed = gtk_real_toolbar_style_changed;
}
static void
@@ -139,7 +185,7 @@ gtk_toolbar_destroy(GtkObject *object)
toolbar = GTK_TOOLBAR(object);
- gtk_tooltips_unref(toolbar->tooltips); /* XXX: do I have to unref the tooltips? */
+ gtk_tooltips_unref(toolbar->tooltips); /* XXX: do I have to unref the tooltips to destroy them? */
for (children = toolbar->children; children; children = children->next) {
child = children->data;
@@ -390,6 +436,9 @@ gtk_toolbar_insert_item(GtkToolbar *toolbar,
gtk_signal_connect(GTK_OBJECT(child->button), "clicked",
callback, user_data);
+ if (tooltip_text)
+ gtk_tooltips_set_tips(toolbar->tooltips, child->button, tooltip_text);
+
if (text)
child->label = gtk_label_new(text);
else
@@ -479,3 +528,123 @@ gtk_toolbar_insert_space(GtkToolbar *toolbar,
if (GTK_WIDGET_VISIBLE(toolbar))
gtk_widget_queue_resize(GTK_WIDGET(toolbar));
}
+
+void
+gtk_toolbar_set_orientation(GtkToolbar *toolbar,
+ GtkOrientation orientation)
+{
+ gtk_signal_emit(GTK_OBJECT(toolbar), toolbar_signals[ORIENTATION_CHANGED], orientation);
+}
+
+void
+gtk_toolbar_set_style(GtkToolbar *toolbar,
+ GtkToolbarStyle style)
+{
+ gtk_signal_emit(GTK_OBJECT(toolbar), toolbar_signals[STYLE_CHANGED], style);
+}
+
+void
+gtk_toolbar_set_space_size(GtkToolbar *toolbar,
+ gint space_size)
+{
+ g_return_if_fail(toolbar != NULL);
+ g_return_if_fail(GTK_IS_TOOLBAR(toolbar));
+
+ if (toolbar->space_size != space_size) {
+ toolbar->space_size = space_size;
+ gtk_widget_queue_resize(GTK_WIDGET(toolbar));
+ }
+}
+
+void
+gtk_toolbar_set_tooltips(GtkToolbar *toolbar,
+ gint enable)
+{
+ g_return_if_fail(toolbar != NULL);
+ g_return_if_fail(GTK_IS_TOOLBAR(toolbar));
+
+ if (enable)
+ gtk_tooltips_enable(toolbar->tooltips);
+ else
+ gtk_tooltips_disable(toolbar->tooltips);
+}
+
+static void
+gtk_toolbar_marshal_signal_1(GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args)
+{
+ GtkToolbarSignal1 rfunc;
+
+ rfunc = (GtkToolbarSignal1) func;
+
+ (*rfunc) (object, GTK_VALUE_ENUM(args[0]), func_data);
+}
+
+static void
+gtk_real_toolbar_orientation_changed(GtkToolbar *toolbar,
+ GtkOrientation orientation)
+{
+ g_return_if_fail(toolbar != NULL);
+ g_return_if_fail(GTK_IS_TOOLBAR(toolbar));
+
+ if (toolbar->orientation != orientation) {
+ toolbar->orientation = orientation;
+ gtk_widget_queue_resize(GTK_WIDGET(toolbar));
+ }
+}
+
+static void
+gtk_real_toolbar_style_changed(GtkToolbar *toolbar,
+ GtkToolbarStyle style)
+{
+ GList *children;
+ Child *child;
+
+ g_return_if_fail(toolbar != NULL);
+ g_return_if_fail(GTK_IS_TOOLBAR(toolbar));
+
+ if (toolbar->style != style) {
+ toolbar->style = style;
+
+ for (children = toolbar->children; children; children = children->next) {
+ child = children->data;
+
+ if (child)
+ switch (style) {
+ case GTK_TOOLBAR_ICONS:
+ if (!GTK_WIDGET_VISIBLE(child->icon))
+ gtk_widget_show(child->icon);
+
+ if (GTK_WIDGET_VISIBLE(child->label))
+ gtk_widget_hide(child->label);
+
+ break;
+
+ case GTK_TOOLBAR_TEXT:
+ if (GTK_WIDGET_VISIBLE(child->icon))
+ gtk_widget_hide(child->icon);
+
+ if (!GTK_WIDGET_VISIBLE(child->label))
+ gtk_widget_show(child->label);
+
+ break;
+
+ case GTK_TOOLBAR_BOTH:
+ if (!GTK_WIDGET_VISIBLE(child->icon))
+ gtk_widget_show(child->icon);
+
+ if (!GTK_WIDGET_VISIBLE(child->label))
+ gtk_widget_show(child->label);
+
+ break;
+
+ default:
+ g_assert_not_reached();
+ }
+ }
+
+ gtk_widget_queue_resize(GTK_WIDGET(toolbar));
+ }
+}
diff --git a/gtk/gtktoolbar.h b/gtk/gtktoolbar.h
index 5b4bbf34e5..189aeef69a 100644
--- a/gtk/gtktoolbar.h
+++ b/gtk/gtktoolbar.h
@@ -61,36 +61,50 @@ struct _GtkToolbar
struct _GtkToolbarClass
{
GtkContainerClass parent_class;
+
+ void (* orientation_changed) (GtkToolbar *toolbar,
+ GtkOrientation orientation);
+ void (* style_changed) (GtkToolbar *toolbar,
+ GtkToolbarStyle style);
};
-guint gtk_toolbar_get_type (void);
-GtkWidget *gtk_toolbar_new (GtkOrientation orientation,
- GtkToolbarStyle style);
-
-void gtk_toolbar_append_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- GtkPixmap *icon,
- GtkSignalFunc callback,
- gpointer user_data);
-void gtk_toolbar_prepend_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- GtkPixmap *icon,
- GtkSignalFunc callback,
- gpointer user_data);
-void gtk_toolbar_insert_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- GtkPixmap *icon,
- GtkSignalFunc callback,
- gpointer user_data,
- gint position);
-void gtk_toolbar_append_space (GtkToolbar *toolbar);
-void gtk_toolbar_prepend_space (GtkToolbar *toolbar);
-void gtk_toolbar_insert_space (GtkToolbar *toolbar,
- gint position);
+guint gtk_toolbar_get_type (void);
+GtkWidget *gtk_toolbar_new (GtkOrientation orientation,
+ GtkToolbarStyle style);
+
+void gtk_toolbar_append_item (GtkToolbar *toolbar,
+ const char *text,
+ const char *tooltip_text,
+ GtkPixmap *icon,
+ GtkSignalFunc callback,
+ gpointer user_data);
+void gtk_toolbar_prepend_item (GtkToolbar *toolbar,
+ const char *text,
+ const char *tooltip_text,
+ GtkPixmap *icon,
+ GtkSignalFunc callback,
+ gpointer user_data);
+void gtk_toolbar_insert_item (GtkToolbar *toolbar,
+ const char *text,
+ const char *tooltip_text,
+ GtkPixmap *icon,
+ GtkSignalFunc callback,
+ gpointer user_data,
+ gint position);
+void gtk_toolbar_append_space (GtkToolbar *toolbar);
+void gtk_toolbar_prepend_space (GtkToolbar *toolbar);
+void gtk_toolbar_insert_space (GtkToolbar *toolbar,
+ gint position);
+
+void gtk_toolbar_set_orientation (GtkToolbar *toolbar,
+ GtkOrientation orientation);
+void gtk_toolbar_set_style (GtkToolbar *toolbar,
+ GtkToolbarStyle style);
+void gtk_toolbar_set_space_size (GtkToolbar *toolbar,
+ gint space_size);
+void gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
+ gint enable);
#ifdef __cplusplus
diff --git a/gtk/testgtk.c b/gtk/testgtk.c
index 98ae0ad686..15d5d52fdc 100644
--- a/gtk/testgtk.c
+++ b/gtk/testgtk.c
@@ -549,7 +549,9 @@ create_button_box ()
}
GtkWidget *
-new_pixmap (char *filename, GdkWindow *window, GdkColor *background)
+new_pixmap (char *filename,
+ GdkWindow *window,
+ GdkColor *background)
{
GtkWidget *wpixmap;
GdkPixmap *pixmap;
@@ -564,6 +566,69 @@ new_pixmap (char *filename, GdkWindow *window, GdkColor *background)
}
void
+set_toolbar_horizontal (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_HORIZONTAL);
+}
+
+void
+set_toolbar_vertical (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_VERTICAL);
+}
+
+void
+set_toolbar_icons (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_ICONS);
+}
+
+void
+set_toolbar_text (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_TEXT);
+}
+
+void
+set_toolbar_both (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH);
+}
+
+void
+set_toolbar_small_space (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 5);
+}
+
+void
+set_toolbar_big_space (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 10);
+}
+
+void
+set_toolbar_enable (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), TRUE);
+}
+
+void
+set_toolbar_disable (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), FALSE);
+}
+
+void
create_toolbar (void)
{
static GtkWidget *window = NULL;
@@ -573,6 +638,7 @@ create_toolbar (void)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Toolbar test");
+ gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, TRUE);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (destroy_window),
@@ -587,31 +653,59 @@ create_toolbar (void)
toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
- "New", "New document",
+ "Horizontal", "Horizontal toolbar layout",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_horizontal, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Vertical", "Vertical toolbar layout",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
- NULL, NULL);
+ (GtkSignalFunc) set_toolbar_vertical, toolbar);
+
+ gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));
+
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Icons", "Only show toolbar icons",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_icons, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Text", "Only show toolbar text",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_text, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Both", "Show toolbar icons and text",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_both, toolbar);
+
+ gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
+
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
- "Open", "Open existing",
+ "Small", "Use small spaces",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
- NULL, NULL);
+ (GtkSignalFunc) set_toolbar_small_space, toolbar);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
- "Close", "Close current document",
+ "Big", "Use big spaces",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
- NULL, NULL);
+ (GtkSignalFunc) set_toolbar_big_space, toolbar);
+
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
+
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
- "Undo", "Undo screw-up",
+ "Enable", "Enable tooltips",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
- NULL, NULL);
+ (GtkSignalFunc) set_toolbar_enable, toolbar);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
- "Redo", "Redo not-screwup-after-all",
+ "Disable", "Disable tooltips",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
- NULL, NULL);
+ (GtkSignalFunc) set_toolbar_disable, toolbar);
gtk_container_add (GTK_CONTAINER (window), toolbar);
gtk_widget_show (toolbar);
@@ -623,6 +717,74 @@ create_toolbar (void)
gtk_widget_destroy (window);
}
+GtkWidget *
+make_toolbar (GtkWidget *window)
+{
+ GtkWidget *toolbar;
+
+ if (!GTK_WIDGET_REALIZED (window))
+ gtk_widget_realize (window);
+
+ toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
+
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Horizontal", "Horizontal toolbar layout",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_horizontal, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Vertical", "Vertical toolbar layout",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_vertical, toolbar);
+
+ gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));
+
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Icons", "Only show toolbar icons",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_icons, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Text", "Only show toolbar text",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_text, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Both", "Show toolbar icons and text",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_both, toolbar);
+
+ gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
+
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Small", "Use small spaces",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_small_space, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Big", "Use big spaces",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_big_space, toolbar);
+
+ gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
+
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Enable", "Enable tooltips",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_enable, toolbar);
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Disable", "Disable tooltips",
+ GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
+ &window->style->bg[GTK_STATE_NORMAL])),
+ (GtkSignalFunc) set_toolbar_disable, toolbar);
+
+ return toolbar;
+}
+
void
create_handle_box ()
{
@@ -650,7 +812,7 @@ create_handle_box ()
gtk_container_add (GTK_CONTAINER (window), hbox);
gtk_widget_set_usize(hbox, 300, 40);
gtk_widget_show (hbox);
-
+#if 0
#if 0
button = gtk_toggle_button_new_with_label ("Let's try this");
#else
@@ -659,6 +821,13 @@ create_handle_box ()
gtk_container_add (GTK_CONTAINER (hbox), button);
gtk_widget_set_usize(button, 250, 40);
gtk_widget_show (button);
+#else
+ {
+ GtkWidget *toolbar = make_toolbar (window);
+ gtk_container_add (GTK_CONTAINER (hbox), toolbar);
+ gtk_widget_show (toolbar);
+ }
+#endif
}
if (!GTK_WIDGET_VISIBLE (window))