diff options
author | rhlabs <rhlabs> | 1998-02-23 20:48:46 +0000 |
---|---|---|
committer | rhlabs <rhlabs> | 1998-02-23 20:48:46 +0000 |
commit | 7add75fba5eacf78decbba100158b333d66b0c92 (patch) | |
tree | 668cb30f4d94568c88e01dc4a08a2c5c59f24f51 /gtk/gtktoolbar.c | |
parent | 86a97f7835cffabf1d2ce44c89fa3f2dff626c3c (diff) | |
download | gdk-pixbuf-7add75fba5eacf78decbba100158b333d66b0c92.tar.gz |
Added gtk_toolbar_*_element() functions. Rewrote others
to simply call gtk_toolbar_insert_element() to do the work.
Added two new GtkToolbarChildType options: TOGGLEBUTTON and
RADIOBUTTON, available through the gtk_toolbar_*_element() functions.
-Marc
Diffstat (limited to 'gtk/gtktoolbar.c')
-rw-r--r-- | gtk/gtktoolbar.c | 313 |
1 files changed, 181 insertions, 132 deletions
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 067ef8a32..e850af2ad 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -18,6 +18,8 @@ */ #include "gtkbutton.h" +#include "gtktogglebutton.h" +#include "gtkradiobutton.h" #include "gtklabel.h" #include "gtkvbox.h" #include "gtktoolbar.h" @@ -361,6 +363,8 @@ gtk_toolbar_size_request (GtkWidget *widget, break; case GTK_TOOLBAR_CHILD_BUTTON: + case GTK_TOOLBAR_CHILD_RADIOBUTTON: + case GTK_TOOLBAR_CHILD_TOGGLEBUTTON: if (GTK_WIDGET_VISIBLE (child->widget)) { gtk_widget_size_request (child->widget, &child->widget->requisition); @@ -447,6 +451,8 @@ gtk_toolbar_size_allocate (GtkWidget *widget, break; case GTK_TOOLBAR_CHILD_BUTTON: + case GTK_TOOLBAR_CHILD_RADIOBUTTON: + case GTK_TOOLBAR_CHILD_TOGGLEBUTTON: alloc.width = toolbar->button_maxw; alloc.height = toolbar->button_maxh; @@ -570,8 +576,11 @@ gtk_toolbar_append_item (GtkToolbar *toolbar, GtkSignalFunc callback, gpointer user_data) { - return gtk_toolbar_insert_item (toolbar, text, tooltip_text, tooltip_private_text, icon, - callback, user_data, toolbar->num_children); + return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, + NULL, text, + tooltip_text, tooltip_private_text, + icon, callback, user_data, + toolbar->num_children); } GtkWidget * @@ -583,8 +592,11 @@ gtk_toolbar_prepend_item (GtkToolbar *toolbar, GtkSignalFunc callback, gpointer user_data) { - return gtk_toolbar_insert_item (toolbar, text, tooltip_text, tooltip_private_text, icon, - callback, user_data, 0); + return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, + NULL, text, + tooltip_text, tooltip_private_text, + icon, callback, user_data, + 0); } GtkWidget * @@ -597,124 +609,42 @@ gtk_toolbar_insert_item (GtkToolbar *toolbar, gpointer user_data, gint position) { - GtkToolbarChild *child; - GtkWidget *vbox; - - g_return_val_if_fail (toolbar != NULL, NULL); - g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL); - - child = g_new (GtkToolbarChild, 1); - - child->type = GTK_TOOLBAR_CHILD_BUTTON; - child->widget = gtk_button_new (); - - if (callback) - gtk_signal_connect (GTK_OBJECT (child->widget), "clicked", - callback, user_data); - - if (tooltip_text) - gtk_tooltips_set_tip (toolbar->tooltips, child->widget, tooltip_text, tooltip_private_text); - - if (text) - child->label = gtk_label_new (text); - else - child->label = NULL; - - if (icon) - child->icon = GTK_WIDGET (icon); - else - child->icon = NULL; - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (child->widget), vbox); - gtk_widget_show (vbox); - - if (child->icon) - gtk_box_pack_start (GTK_BOX (vbox), child->icon, FALSE, FALSE, 0); - - if (child->label) - gtk_box_pack_start (GTK_BOX (vbox), child->label, FALSE, FALSE, 0); - - switch (toolbar->style) - { - case GTK_TOOLBAR_ICONS: - if (child->icon) - gtk_widget_show (child->icon); - break; - - case GTK_TOOLBAR_TEXT: - if (child->label) - gtk_widget_show (child->label); - break; - - case GTK_TOOLBAR_BOTH: - if (child->icon) - gtk_widget_show (child->icon); - - if (child->label) - gtk_widget_show (child->label); - break; - - default: - g_assert_not_reached (); - } - - gtk_widget_show (child->widget); - - toolbar->children = g_list_insert (toolbar->children, child, position); - toolbar->num_children++; - - gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar)); - - if (GTK_WIDGET_VISIBLE (toolbar)) - { - if (GTK_WIDGET_REALIZED (toolbar) - && !GTK_WIDGET_REALIZED (child->widget)) - gtk_widget_realize (child->widget); - - if (GTK_WIDGET_MAPPED (toolbar) - && !GTK_WIDGET_MAPPED (child->widget)) - gtk_widget_map (child->widget); - } - - if (GTK_WIDGET_VISIBLE (child->widget) && GTK_WIDGET_VISIBLE (toolbar)) - gtk_widget_queue_resize (child->widget); - - return child->widget; + return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, + NULL, text, + tooltip_text, tooltip_private_text, + icon, callback, user_data, + position); } void gtk_toolbar_append_space (GtkToolbar *toolbar) { - gtk_toolbar_insert_space (toolbar, toolbar->num_children); + gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE, + NULL, NULL, + NULL, NULL, + NULL, NULL, NULL, + toolbar->num_children); } void gtk_toolbar_prepend_space (GtkToolbar *toolbar) { - gtk_toolbar_insert_space (toolbar, 0); + gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE, + NULL, NULL, + NULL, NULL, + NULL, NULL, NULL, + 0); } void gtk_toolbar_insert_space (GtkToolbar *toolbar, gint position) { - GtkToolbarChild *child; - - g_return_if_fail (toolbar != NULL); - g_return_if_fail (GTK_IS_TOOLBAR (toolbar)); - - child = g_new (GtkToolbarChild, 1); - child->type = GTK_TOOLBAR_CHILD_SPACE; - child->widget = NULL; - child->icon = NULL; - child->label = NULL; - - toolbar->children = g_list_insert (toolbar->children, child, position); - toolbar->num_children++; - - if (GTK_WIDGET_VISIBLE (toolbar)) - gtk_widget_queue_resize (GTK_WIDGET (toolbar)); + gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE, + NULL, NULL, + NULL, NULL, + NULL, NULL, NULL, + position); } void @@ -723,7 +653,11 @@ gtk_toolbar_append_widget (GtkToolbar *toolbar, const gchar *tooltip_text, const gchar *tooltip_private_text) { - gtk_toolbar_insert_widget (toolbar, widget, tooltip_text, tooltip_private_text, toolbar->num_children); + gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET, + widget, NULL, + tooltip_text, tooltip_private_text, + NULL, NULL, NULL, + toolbar->num_children); } void @@ -732,7 +666,11 @@ gtk_toolbar_prepend_widget (GtkToolbar *toolbar, const gchar *tooltip_text, const gchar *tooltip_private_text) { - gtk_toolbar_insert_widget (toolbar, widget, tooltip_text, tooltip_private_text, 0); + gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET, + widget, NULL, + tooltip_text, tooltip_private_text, + NULL, NULL, NULL, + toolbar->num_children); } void @@ -742,38 +680,147 @@ gtk_toolbar_insert_widget (GtkToolbar *toolbar, const char *tooltip_private_text, gint position) { - GtkToolbarChild *child; + gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET, + widget, NULL, + tooltip_text, tooltip_private_text, + NULL, NULL, NULL, + position); +} - g_return_if_fail (toolbar != NULL); - g_return_if_fail (widget != NULL); +GtkWidget *gtk_toolbar_append_element (GtkToolbar *toolbar, + GtkToolbarChildType type, + GtkWidget *widget, + const char *text, + const char *tooltip_text, + const char *tooltip_private_text, + GtkWidget *icon, + GtkSignalFunc callback, + gpointer user_data) +{ + return gtk_toolbar_insert_element(toolbar, type, widget, text, + tooltip_text, tooltip_private_text, + icon, callback, user_data, + toolbar->num_children); +} - child = g_new (GtkToolbarChild, 1); - child->type = GTK_TOOLBAR_CHILD_WIDGET; - child->widget = widget; - child->icon = NULL; - child->label = NULL; +GtkWidget *gtk_toolbar_prepend_element (GtkToolbar *toolbar, + GtkToolbarChildType type, + GtkWidget *widget, + const char *text, + const char *tooltip_text, + const char *tooltip_private_text, + GtkWidget *icon, + GtkSignalFunc callback, + gpointer user_data) +{ + return gtk_toolbar_insert_element(toolbar, type, widget, text, + tooltip_text, tooltip_private_text, + icon, callback, user_data, 0); +} - if (tooltip_text) - gtk_tooltips_set_tip (toolbar->tooltips, child->widget, tooltip_text, tooltip_private_text); +GtkWidget *gtk_toolbar_insert_element (GtkToolbar *toolbar, + GtkToolbarChildType type, + GtkWidget *widget, + const char *text, + const char *tooltip_text, + const char *tooltip_private_text, + GtkWidget *icon, + GtkSignalFunc callback, + gpointer user_data, + gint position) +{ + GtkToolbarChild *child; + GtkWidget *vbox; - toolbar->children = g_list_insert (toolbar->children, child, position); - toolbar->num_children++; + g_return_val_if_fail (toolbar != NULL, NULL); + g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL); - gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar)); + child = g_new (GtkToolbarChild, 1); + child->type = type; + child->icon = NULL; + child->label = NULL; - if (GTK_WIDGET_VISIBLE (toolbar)) - { - if (GTK_WIDGET_REALIZED (toolbar) - && !GTK_WIDGET_REALIZED (child->widget)) - gtk_widget_realize (child->widget); + switch (type) { + case GTK_TOOLBAR_CHILD_SPACE: + child->widget = NULL; + break; + case GTK_TOOLBAR_CHILD_WIDGET: + child->widget = widget; + break; + case GTK_TOOLBAR_CHILD_BUTTON: + case GTK_TOOLBAR_CHILD_TOGGLEBUTTON: + case GTK_TOOLBAR_CHILD_RADIOBUTTON: + if (type == GTK_TOOLBAR_CHILD_BUTTON) { + child->widget = gtk_button_new (); + } else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON) { + child->widget = gtk_toggle_button_new (); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(child->widget), + FALSE); + } else { + child->widget = + gtk_radio_button_new( + widget + ? gtk_radio_button_group(GTK_RADIO_BUTTON(widget)) + : NULL); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(child->widget), + FALSE); + } + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (child->widget), vbox); + gtk_widget_show (vbox); + + if (icon) { + child->icon = GTK_WIDGET (icon); + gtk_box_pack_start (GTK_BOX (vbox), child->icon, FALSE, FALSE, 0); + if (toolbar->style != GTK_TOOLBAR_TEXT) + gtk_widget_show (child->icon); + } - if (GTK_WIDGET_MAPPED (toolbar) - && !GTK_WIDGET_MAPPED (child->widget)) - gtk_widget_map (child->widget); + if (text) { + child->label = gtk_label_new (text); + gtk_box_pack_start (GTK_BOX (vbox), child->label, FALSE, FALSE, 0); + if (toolbar->style != GTK_TOOLBAR_ICONS) + gtk_widget_show (child->label); + } + + gtk_widget_show (child->widget); + break; + default: + g_assert_not_reached (); + } + + if (callback) + gtk_signal_connect (GTK_OBJECT (child->widget), "clicked", + callback, user_data); + + if (tooltip_text) + gtk_tooltips_set_tip (toolbar->tooltips, child->widget, + tooltip_text, tooltip_private_text); + + toolbar->children = g_list_insert (toolbar->children, child, position); + toolbar->num_children++; + + if (type != GTK_TOOLBAR_CHILD_SPACE) + gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar)); + + if (type != GTK_TOOLBAR_CHILD_SPACE && GTK_WIDGET_VISIBLE (toolbar)) + { + if (GTK_WIDGET_REALIZED (toolbar) + && !GTK_WIDGET_REALIZED (child->widget)) + gtk_widget_realize (child->widget); + + if (GTK_WIDGET_MAPPED (toolbar) + && !GTK_WIDGET_MAPPED (child->widget)) + gtk_widget_map (child->widget); } - if (GTK_WIDGET_VISIBLE (child->widget) && GTK_WIDGET_VISIBLE (toolbar)) - gtk_widget_queue_resize (child->widget); + if (GTK_WIDGET_VISIBLE (toolbar) && + (type == GTK_TOOLBAR_CHILD_SPACE || + GTK_WIDGET_VISIBLE (child->widget))) + gtk_widget_queue_resize (GTK_WIDGET (toolbar)); + + return child->widget; } void @@ -862,7 +909,9 @@ gtk_real_toolbar_style_changed (GtkToolbar *toolbar, { child = children->data; - if (child->type == GTK_TOOLBAR_CHILD_BUTTON) + if (child->type == GTK_TOOLBAR_CHILD_BUTTON || + child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON || + child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON) switch (style) { case GTK_TOOLBAR_ICONS: |