* GtkToolbar copyright (C) Federico Mena
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 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
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
#include "gtkbutton.h"
#include "gtktogglebutton.h"
#include "gtkradiobutton.h"
#include "gtklabel.h"
#include "gtkvbox.h"
+#include "gtkhbox.h"
#include "gtktoolbar.h"
+#include "gtkstock.h"
+#include "gtkiconfactory.h"
+#include "gtkimage.h"
+
+#define DEFAULT_SPACE_SIZE 5
+#define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_EMPTY
-#define DEFAULT_SPACE_SIZE 5
+#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
+#define SPACE_LINE_DIVISION 10
+#define SPACE_LINE_START 3
+#define SPACE_LINE_END 7
+
+enum {
+ ARG_0,
+ ARG_ORIENTATION,
+ ARG_TOOLBAR_STYLE,
+ ARG_SPACE_SIZE,
+ ARG_SPACE_STYLE,
+ ARG_RELIEF
+};
enum {
ORIENTATION_CHANGED,
LAST_SIGNAL
};
+typedef struct _GtkToolbarChildSpace GtkToolbarChildSpace;
+struct _GtkToolbarChildSpace
+{
+ GtkToolbarChild child;
+
+ gint alloc_x, alloc_y;
+};
+
static void gtk_toolbar_class_init (GtkToolbarClass *class);
static void gtk_toolbar_init (GtkToolbar *toolbar);
+static void gtk_toolbar_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+static void gtk_toolbar_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
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 gint gtk_toolbar_expose (GtkWidget *widget,
GdkEventExpose *event);
static void gtk_toolbar_size_request (GtkWidget *widget,
static void gtk_real_toolbar_style_changed (GtkToolbar *toolbar,
GtkToolbarStyle style);
+static GtkWidget * gtk_toolbar_internal_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,
+ gboolean has_mnemonic);
+
+static GtkWidget * gtk_toolbar_internal_insert_item (GtkToolbar *toolbar,
+ const char *text,
+ const char *tooltip_text,
+ const char *tooltip_private_text,
+ GtkWidget *icon,
+ GtkSignalFunc callback,
+ gpointer user_data,
+ gint position,
+ gboolean has_mnemonic);
static GtkContainerClass *parent_class;
static guint toolbar_signals[LAST_SIGNAL] = { 0 };
-guint
+GtkType
gtk_toolbar_get_type (void)
{
- static guint toolbar_type = 0;
+ static GtkType toolbar_type = 0;
if (!toolbar_type)
{
- GtkTypeInfo toolbar_info =
+ static const GtkTypeInfo toolbar_info =
{
"GtkToolbar",
sizeof (GtkToolbar),
container_class = (GtkContainerClass *) 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_marshal_NONE__INT,
- 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_marshal_NONE__INT,
- GTK_TYPE_NONE, 1,
- GTK_TYPE_INT);
-
- gtk_object_class_add_signals (object_class, toolbar_signals, LAST_SIGNAL);
-
+
object_class->destroy = gtk_toolbar_destroy;
+ object_class->set_arg = gtk_toolbar_set_arg;
+ object_class->get_arg = gtk_toolbar_get_arg;
widget_class->map = gtk_toolbar_map;
widget_class->unmap = gtk_toolbar_unmap;
- widget_class->draw = gtk_toolbar_draw;
widget_class->expose_event = gtk_toolbar_expose;
widget_class->size_request = gtk_toolbar_size_request;
widget_class->size_allocate = gtk_toolbar_size_allocate;
container_class->remove = gtk_toolbar_remove;
container_class->forall = gtk_toolbar_forall;
container_class->focus = NULL;
-
+
class->orientation_changed = gtk_real_toolbar_orientation_changed;
class->style_changed = gtk_real_toolbar_style_changed;
+
+ toolbar_signals[ORIENTATION_CHANGED] =
+ gtk_signal_new ("orientation_changed",
+ GTK_RUN_FIRST,
+ GTK_CLASS_TYPE (object_class),
+ GTK_SIGNAL_OFFSET (GtkToolbarClass, orientation_changed),
+ gtk_marshal_VOID__INT,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_INT);
+ toolbar_signals[STYLE_CHANGED] =
+ gtk_signal_new ("style_changed",
+ GTK_RUN_FIRST,
+ GTK_CLASS_TYPE (object_class),
+ GTK_SIGNAL_OFFSET (GtkToolbarClass, style_changed),
+ gtk_marshal_VOID__INT,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_INT);
+
+ gtk_object_add_arg_type ("GtkToolbar::orientation", GTK_TYPE_ORIENTATION,
+ GTK_ARG_READWRITE, ARG_ORIENTATION);
+ gtk_object_add_arg_type ("GtkToolbar::toolbar_style", GTK_TYPE_TOOLBAR_STYLE,
+ GTK_ARG_READWRITE, ARG_TOOLBAR_STYLE);
+ gtk_object_add_arg_type ("GtkToolbar::space_size", GTK_TYPE_UINT,
+ GTK_ARG_READWRITE, ARG_SPACE_SIZE);
+ gtk_object_add_arg_type ("GtkToolbar::space_style", GTK_TYPE_TOOLBAR_SPACE_STYLE,
+ GTK_ARG_READWRITE, ARG_SPACE_STYLE);
+ gtk_object_add_arg_type ("GtkToolbar::relief", GTK_TYPE_RELIEF_STYLE,
+ GTK_ARG_READWRITE, ARG_RELIEF);
}
static void
toolbar->style = GTK_TOOLBAR_ICONS;
toolbar->relief = GTK_RELIEF_NORMAL;
toolbar->space_size = DEFAULT_SPACE_SIZE;
+ toolbar->space_style = DEFAULT_SPACE_STYLE;
+ toolbar->icon_size = DEFAULT_ICON_SIZE;
toolbar->tooltips = gtk_tooltips_new ();
toolbar->button_maxw = 0;
toolbar->button_maxh = 0;
}
-GtkWidget *
+static void
+gtk_toolbar_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (object);
+
+ switch (arg_id)
+ {
+ case ARG_ORIENTATION:
+ gtk_toolbar_set_orientation (toolbar, GTK_VALUE_ENUM (*arg));
+ break;
+ case ARG_TOOLBAR_STYLE:
+ gtk_toolbar_set_style (toolbar, GTK_VALUE_ENUM (*arg));
+ break;
+ case ARG_SPACE_SIZE:
+ gtk_toolbar_set_space_size (toolbar, GTK_VALUE_UINT (*arg));
+ break;
+ case ARG_SPACE_STYLE:
+ gtk_toolbar_set_space_style (toolbar, GTK_VALUE_ENUM (*arg));
+ break;
+ case ARG_RELIEF:
+ gtk_toolbar_set_button_relief (toolbar, GTK_VALUE_ENUM (*arg));
+ break;
+ }
+}
+
+static void
+gtk_toolbar_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (object);
+
+ switch (arg_id)
+ {
+ case ARG_ORIENTATION:
+ GTK_VALUE_ENUM (*arg) = toolbar->orientation;
+ break;
+ case ARG_TOOLBAR_STYLE:
+ GTK_VALUE_ENUM (*arg) = toolbar->style;
+ break;
+ case ARG_SPACE_SIZE:
+ GTK_VALUE_UINT (*arg) = toolbar->space_size;
+ break;
+ case ARG_SPACE_STYLE:
+ GTK_VALUE_ENUM (*arg) = toolbar->space_style;
+ break;
+ case ARG_RELIEF:
+ GTK_VALUE_ENUM (*arg) = toolbar->relief;
+ break;
+ default:
+ arg->type = GTK_TYPE_INVALID;
+ break;
+ }
+}
+
+GtkWidget*
gtk_toolbar_new (GtkOrientation orientation,
GtkToolbarStyle style)
{
toolbar = GTK_TOOLBAR (object);
- gtk_object_unref (GTK_OBJECT (toolbar->tooltips));
- toolbar->tooltips = NULL;
+ if (toolbar->tooltips)
+ {
+ gtk_object_unref (GTK_OBJECT (toolbar->tooltips));
+ toolbar->tooltips = NULL;
+ }
for (children = toolbar->children; children; children = children->next)
{
g_free (child);
}
-
g_list_free (toolbar->children);
toolbar->children = NULL;
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
}
static void
-gtk_toolbar_draw (GtkWidget *widget,
- GdkRectangle *area)
+gtk_toolbar_paint_space_line (GtkWidget *widget,
+ GdkRectangle *area,
+ GtkToolbarChild *child)
{
GtkToolbar *toolbar;
- GList *children;
- GtkToolbarChild *child;
- GdkRectangle child_area;
+ GtkToolbarChildSpace *child_space;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_TOOLBAR (widget));
+ g_return_if_fail (child != NULL);
+ g_return_if_fail (child->type == GTK_TOOLBAR_CHILD_SPACE);
- if (GTK_WIDGET_DRAWABLE (widget))
- {
- toolbar = GTK_TOOLBAR (widget);
+ toolbar = GTK_TOOLBAR (widget);
- for (children = toolbar->children; children; children = children->next)
- {
- child = children->data;
+ child_space = (GtkToolbarChildSpace *) child;
- if ((child->type != GTK_TOOLBAR_CHILD_SPACE)
- && gtk_widget_intersect (child->widget, area, &child_area))
- gtk_widget_draw (child->widget, &child_area);
- }
- }
+ if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_paint_vline (widget->style, widget->window,
+ GTK_WIDGET_STATE (widget), area, widget,
+ "toolbar",
+ child_space->alloc_y + toolbar->button_maxh *
+ SPACE_LINE_START / SPACE_LINE_DIVISION,
+ child_space->alloc_y + toolbar->button_maxh *
+ SPACE_LINE_END / SPACE_LINE_DIVISION,
+ child_space->alloc_x +
+ (toolbar->space_size -
+ widget->style->xthickness) / 2);
+ else
+ gtk_paint_hline (widget->style, widget->window,
+ GTK_WIDGET_STATE (widget), area, widget,
+ "toolbar",
+ child_space->alloc_x + toolbar->button_maxw *
+ SPACE_LINE_START / SPACE_LINE_DIVISION,
+ child_space->alloc_x + toolbar->button_maxw *
+ SPACE_LINE_END / SPACE_LINE_DIVISION,
+ child_space->alloc_y +
+ (toolbar->space_size -
+ widget->style->ythickness) / 2);
}
static gint
GtkToolbar *toolbar;
GList *children;
GtkToolbarChild *child;
- GdkEventExpose child_event;
-
+
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_TOOLBAR (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
{
toolbar = GTK_TOOLBAR (widget);
- child_event = *event;
-
for (children = toolbar->children; children; children = children->next)
{
child = children->data;
- if ((child->type != GTK_TOOLBAR_CHILD_SPACE)
- && GTK_WIDGET_NO_WINDOW (child->widget)
- && gtk_widget_intersect (child->widget, &event->area, &child_event.area))
- gtk_widget_event (child->widget, (GdkEvent *) &child_event);
+ if (child->type == GTK_TOOLBAR_CHILD_SPACE)
+ {
+ if (toolbar->space_style == GTK_TOOLBAR_SPACE_LINE)
+ gtk_toolbar_paint_space_line (widget, &event->area, child);
+ }
+ else
+ gtk_container_propagate_expose (GTK_CONTAINER (widget),
+ child->widget,
+ event);
}
}
gint nbuttons;
gint button_maxw, button_maxh;
gint widget_maxw, widget_maxh;
+ GtkRequisition child_requisition;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_TOOLBAR (widget));
case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
if (GTK_WIDGET_VISIBLE (child->widget))
{
- gtk_widget_size_request (child->widget, &child->widget->requisition);
+ gtk_widget_size_request (child->widget, &child_requisition);
nbuttons++;
- button_maxw = MAX (button_maxw, child->widget->requisition.width);
- button_maxh = MAX (button_maxh, child->widget->requisition.height);
+ button_maxw = MAX (button_maxw, child_requisition.width);
+ button_maxh = MAX (button_maxh, child_requisition.height);
}
break;
case GTK_TOOLBAR_CHILD_WIDGET:
if (GTK_WIDGET_VISIBLE (child->widget))
{
- gtk_widget_size_request (child->widget, &child->widget->requisition);
+ gtk_widget_size_request (child->widget, &child_requisition);
- widget_maxw = MAX (widget_maxw, child->widget->requisition.width);
- widget_maxh = MAX (widget_maxh, child->widget->requisition.height);
+ widget_maxw = MAX (widget_maxw, child_requisition.width);
+ widget_maxh = MAX (widget_maxh, child_requisition.height);
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
- requisition->width += child->widget->requisition.width;
+ requisition->width += child_requisition.width;
else
- requisition->height += child->widget->requisition.height;
+ requisition->height += child_requisition.height;
}
break;
GtkToolbar *toolbar;
GList *children;
GtkToolbarChild *child;
+ GtkToolbarChildSpace *child_space;
GtkAllocation alloc;
+ GtkRequisition child_requisition;
gint border_width;
g_return_if_fail (widget != NULL);
switch (child->type)
{
case GTK_TOOLBAR_CHILD_SPACE:
+
+ child_space = (GtkToolbarChildSpace *) child;
+
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
- alloc.x += toolbar->space_size;
+ {
+ child_space->alloc_x = alloc.x;
+ child_space->alloc_y = allocation->y + (allocation->height - toolbar->button_maxh) / 2;
+ alloc.x += toolbar->space_size;
+ }
else
- alloc.y += toolbar->space_size;
+ {
+ child_space->alloc_x = allocation->x + (allocation->width - toolbar->button_maxw) / 2;
+ child_space->alloc_y = alloc.y;
+ alloc.y += toolbar->space_size;
+ }
break;
if (!GTK_WIDGET_VISIBLE (child->widget))
break;
- alloc.width = child->widget->requisition.width;
- alloc.height = child->widget->requisition.height;
+ gtk_widget_get_child_requisition (child->widget, &child_requisition);
+
+ alloc.width = child_requisition.width;
+ alloc.height = child_requisition.height;
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
- alloc.y = allocation->y + (allocation->height - child->widget->requisition.height) / 2;
+ alloc.y = allocation->y + (allocation->height - child_requisition.height) / 2;
else
- alloc.x = allocation->x + (allocation->width - child->widget->requisition.width) / 2;
+ alloc.x = allocation->x + (allocation->width - child_requisition.width) / 2;
gtk_widget_size_allocate (child->widget, &alloc);
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
- alloc.x += child->widget->requisition.width;
+ alloc.x += child_requisition.width;
else
- alloc.y += child->widget->requisition.height;
+ alloc.y += child_requisition.height;
break;
0);
}
+static GtkWidget *
+gtk_toolbar_internal_insert_item (GtkToolbar *toolbar,
+ const char *text,
+ const char *tooltip_text,
+ const char *tooltip_private_text,
+ GtkWidget *icon,
+ GtkSignalFunc callback,
+ gpointer user_data,
+ gint position,
+ gboolean has_mnemonic)
+{
+ return gtk_toolbar_internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
+ NULL, text,
+ tooltip_text, tooltip_private_text,
+ icon, callback, user_data,
+ position, has_mnemonic);
+}
+
GtkWidget *
gtk_toolbar_insert_item (GtkToolbar *toolbar,
const char *text,
gpointer user_data,
gint position)
{
- return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data,
- position);
+ return gtk_toolbar_internal_insert_item (toolbar,
+ text, tooltip_text, tooltip_private_text,
+ icon, callback, user_data,
+ position, FALSE);
}
+/**
+ * gtk_toolbar_set_icon_size:
+ * @toolbar: A #GtkToolbar
+ * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
+ *
+ * This function sets the size of stock icons in the toolbar. You
+ * can call it both before you add the icons and after they've been
+ * added.
+ **/
+void
+gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
+ GtkIconSize icon_size)
+{
+ GList *children;
+ GtkToolbarChild *child;
+ GtkImage *image;
+ gchar *stock_id;
+
+ g_return_if_fail (toolbar != NULL);
+ g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
+
+ if (toolbar->icon_size == icon_size)
+ return;
+
+ toolbar->icon_size = icon_size;
+
+ for (children = toolbar->children; children; children = children->next)
+ {
+ child = children->data;
+ if (child->type == GTK_TOOLBAR_CHILD_BUTTON &&
+ GTK_IS_IMAGE (child->icon))
+ {
+ image = GTK_IMAGE (child->icon);
+ if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
+ {
+ gtk_image_get_stock (image, &stock_id, NULL);
+ stock_id = g_strdup (stock_id);
+ gtk_image_set_from_stock (image,
+ stock_id,
+ icon_size);
+ g_free (stock_id);
+ }
+ }
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+}
+
+/**
+ * gtk_toolbar_insert_stock:
+ * @toolbar: A #GtkToolbar
+ * @stock_id: The id of the stock item you want to insert
+ * @tooltip_text: The text in the tooltip of the toolbar button
+ * @tooltip_private_text: The private text of the tooltip
+ * @callback: The callback called when the toolbar button is clicked.
+ * @user_data: user data passed to callback
+ * @position: The position the button shall be inserted at.
+ * -1 means at the end.
+ *
+ * Inserts a stock item at the specified position of the toolbar. If
+ * @stock_id is not a known stock item ID, it's inserted verbatim,
+ * except that underscores are used to mark mnemonics (see
+ * gtk_label_new_with_mnemonic()).
+ *
+ * Returns: the inserted widget
+ */
+GtkWidget*
+gtk_toolbar_insert_stock (GtkToolbar *toolbar,
+ const gchar *stock_id,
+ const char *tooltip_text,
+ const char *tooltip_private_text,
+ GtkSignalFunc callback,
+ gpointer user_data,
+ gint position)
+{
+ GtkStockItem item;
+ GtkWidget *image;
+
+ if (gtk_stock_lookup (stock_id, &item))
+ {
+ image = gtk_image_new_from_stock (stock_id, toolbar->icon_size);
+
+ return gtk_toolbar_internal_insert_item (toolbar,
+ item.label,
+ tooltip_text,
+ tooltip_private_text,
+ image,
+ callback,
+ user_data,
+ position,
+ TRUE);
+ }
+ else
+ return gtk_toolbar_internal_insert_item (toolbar,
+ stock_id,
+ tooltip_text,
+ tooltip_private_text,
+ NULL,
+ callback,
+ user_data,
+ position,
+ TRUE);
+}
+
+
+
void
gtk_toolbar_append_space (GtkToolbar *toolbar)
{
widget, NULL,
tooltip_text, tooltip_private_text,
NULL, NULL, NULL,
- toolbar->num_children);
+ 0);
}
void
position);
}
-GtkWidget *
+GtkWidget*
gtk_toolbar_append_element (GtkToolbar *toolbar,
GtkToolbarChildType type,
GtkWidget *widget,
GtkSignalFunc callback,
gpointer user_data,
gint position)
+{
+ g_return_val_if_fail (toolbar != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
+ if (type == GTK_TOOLBAR_CHILD_WIDGET)
+ {
+ g_return_val_if_fail (widget != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+ }
+ else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
+ g_return_val_if_fail (widget == NULL, NULL);
+
+ return gtk_toolbar_internal_insert_element (toolbar, type, widget, text,
+ tooltip_text, tooltip_private_text,
+ icon, callback, user_data,
+ position, FALSE);
+}
+
+static GtkWidget *
+gtk_toolbar_internal_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,
+ gboolean has_mnemonic)
{
GtkToolbarChild *child;
- GtkWidget *vbox;
+ GtkWidget *box;
g_return_val_if_fail (toolbar != NULL, NULL);
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
g_return_val_if_fail (widget == NULL, NULL);
- child = g_new (GtkToolbarChild, 1);
+ if (type == GTK_TOOLBAR_CHILD_SPACE)
+ child = (GtkToolbarChild *) g_new (GtkToolbarChildSpace, 1);
+ else
+ child = g_new (GtkToolbarChild, 1);
+
child->type = type;
child->icon = NULL;
child->label = NULL;
{
case GTK_TOOLBAR_CHILD_SPACE:
child->widget = NULL;
+ ((GtkToolbarChildSpace *) child)->alloc_x =
+ ((GtkToolbarChildSpace *) child)->alloc_y = 0;
break;
case GTK_TOOLBAR_CHILD_WIDGET:
child->widget = gtk_radio_button_new (widget
? gtk_radio_button_group (GTK_RADIO_BUTTON (widget))
: NULL);
+ gtk_button_set_relief (GTK_BUTTON (child->widget), toolbar->relief);
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child->widget), FALSE);
}
gtk_signal_connect (GTK_OBJECT (child->widget), "clicked",
callback, user_data);
- vbox = gtk_vbox_new (FALSE, 0);
- gtk_container_add (GTK_CONTAINER (child->widget), vbox);
- gtk_widget_show (vbox);
+ if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
+ box = gtk_hbox_new (FALSE, 0);
+ else
+ box = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (child->widget), box);
+ gtk_widget_show (box);
if (text)
{
- child->label = gtk_label_new (text);
- gtk_box_pack_end (GTK_BOX (vbox), child->label, FALSE, FALSE, 0);
+ if (has_mnemonic)
+ child->label = gtk_label_new_with_mnemonic (text);
+ else
+ child->label = gtk_label_new (text);
+ gtk_box_pack_end (GTK_BOX (box), child->label, FALSE, FALSE, 0);
if (toolbar->style != GTK_TOOLBAR_ICONS)
gtk_widget_show (child->label);
}
if (icon)
{
child->icon = GTK_WIDGET (icon);
- gtk_box_pack_end (GTK_BOX (vbox), child->icon, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (box), child->icon, FALSE, FALSE, 0);
if (toolbar->style != GTK_TOOLBAR_TEXT)
gtk_widget_show (child->icon);
}
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_set_parent (child->widget, GTK_WIDGET (toolbar));
+
+ if (GTK_WIDGET_REALIZED (child->widget->parent))
gtk_widget_realize (child->widget);
-
- if (GTK_WIDGET_MAPPED (toolbar)
- && !GTK_WIDGET_MAPPED (child->widget))
- gtk_widget_map (child->widget);
- }
- if (GTK_WIDGET_VISIBLE (toolbar) &&
- ((type == GTK_TOOLBAR_CHILD_SPACE) ||
- GTK_WIDGET_VISIBLE (child->widget)))
+ if (GTK_WIDGET_VISIBLE (child->widget->parent) && GTK_WIDGET_VISIBLE (child->widget))
+ {
+ if (GTK_WIDGET_MAPPED (child->widget->parent))
+ gtk_widget_map (child->widget);
+
+ gtk_widget_queue_resize (child->widget);
+ }
+ }
+ else
gtk_widget_queue_resize (GTK_WIDGET (toolbar));
return child->widget;
}
}
+void
+gtk_toolbar_set_space_style (GtkToolbar *toolbar,
+ GtkToolbarSpaceStyle space_style)
+{
+ g_return_if_fail (toolbar != NULL);
+ g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
+
+ if (toolbar->space_style != space_style)
+ {
+ toolbar->space_style = space_style;
+ gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+ }
+}
+
void
gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
- gint enable)
+ gboolean enable)
{
g_return_if_fail (toolbar != NULL);
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
{
child = children->data;
if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
+ child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
}
{
GList *children;
GtkToolbarChild *child;
+ GtkWidget* box = NULL;
g_return_if_fail (toolbar != NULL);
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
case GTK_TOOLBAR_TEXT:
if (child->icon && GTK_WIDGET_VISIBLE (child->icon))
gtk_widget_hide (child->icon);
-
+
if (child->label && !GTK_WIDGET_VISIBLE (child->label))
gtk_widget_show (child->label);
if (child->label && !GTK_WIDGET_VISIBLE (child->label))
gtk_widget_show (child->label);
+ box = (GtkWidget*)gtk_container_children (GTK_CONTAINER (child->widget))->data;
+
+ if (GTK_IS_HBOX (box))
+ {
+ if (child->icon)
+ {
+ gtk_object_ref (GTK_OBJECT (child->icon));
+ gtk_container_remove (GTK_CONTAINER (box),
+ child->icon);
+ }
+ if (child->label)
+ {
+ gtk_object_ref (GTK_OBJECT (child->label));
+ gtk_container_remove (GTK_CONTAINER (box),
+ child->label);
+ }
+ gtk_container_remove (GTK_CONTAINER (child->widget),
+ box);
+
+ box = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (box);
+
+ if (child->label)
+ {
+ gtk_box_pack_end (GTK_BOX (box), child->label, FALSE, FALSE, 0);
+ gtk_object_unref (GTK_OBJECT (child->label));
+ }
+ if (child->icon)
+ {
+ gtk_box_pack_end (GTK_BOX (box), child->icon, FALSE, FALSE, 0);
+ gtk_object_unref (GTK_OBJECT (child->icon));
+ }
+ gtk_container_add (GTK_CONTAINER (child->widget),
+ box);
+ }
+
+ break;
+
+ case GTK_TOOLBAR_BOTH_HORIZ:
+ if (child->icon && !GTK_WIDGET_VISIBLE (child->icon))
+ gtk_widget_show (child->icon);
+ if (child->label && !GTK_WIDGET_VISIBLE (child->label))
+ gtk_widget_show (child->label);
+
+ box = (GtkWidget*)gtk_container_children (GTK_CONTAINER (child->widget))->data;
+
+ if (GTK_IS_VBOX (box))
+ {
+ if (child->icon)
+ {
+ gtk_object_ref (GTK_OBJECT (child->icon));
+ gtk_container_remove (GTK_CONTAINER (box),
+ child->icon);
+ }
+ if (child->label)
+ {
+ gtk_object_ref (GTK_OBJECT (child->label));
+ gtk_container_remove (GTK_CONTAINER (box),
+ child->label);
+ }
+ gtk_container_remove (GTK_CONTAINER (child->widget),
+ box);
+
+ box = gtk_hbox_new (FALSE, 0);
+ gtk_widget_show (box);
+
+ if (child->label)
+ {
+ gtk_box_pack_end (GTK_BOX (box), child->label, TRUE, TRUE, 0);
+ gtk_object_unref (GTK_OBJECT (child->label));
+ }
+ if (child->icon)
+ {
+ gtk_box_pack_end (GTK_BOX (box), child->icon, FALSE, FALSE, 0);
+ gtk_object_unref (GTK_OBJECT (child->icon));
+ }
+ gtk_container_add (GTK_CONTAINER (child->widget), box);
+
+ }
+
break;
default: