1 /* gtkseparatortoolitem.c
3 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
4 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include "gtkseparatormenuitem.h"
24 #include "gtkseparatortoolitem.h"
26 #include "gtktoolbar.h"
27 #include "gtkprivate.h"
30 * SECTION:gtkseparatortoolitem
31 * @Short_description: A toolbar item that separates groups of other
33 * @Title: GtkSeparatorToolItem
34 * @See_also: #GtkToolbar, #GtkRadioToolButton
36 * A #GtkSeparatorItem is a #GtkToolItem that separates groups of other
37 * #GtkToolItems. Depending on the theme, a #GtkSeparatorToolItem will
38 * often look like a vertical line on horizontally docked toolbars.
40 * If the #GtkToolbar child property "expand" is %TRUE and the property
41 * #GtkSeparatorToolItem:draw is %FALSE, a #GtkSeparatorToolItem will act as
42 * a "spring" that forces other items to the ends of the toolbar.
44 * Use gtk_separator_tool_item_new() to create a new #GtkSeparatorToolItem.
48 #define MENU_ID "gtk-separator-tool-item-menu-id"
50 struct _GtkSeparatorToolItemPrivate
60 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
61 static void gtk_separator_tool_item_set_property (GObject *object,
65 static void gtk_separator_tool_item_get_property (GObject *object,
69 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
70 GtkRequisition *requisition);
71 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
72 GdkEventExpose *event);
73 static void gtk_separator_tool_item_add (GtkContainer *container,
75 static gint get_space_size (GtkToolItem *tool_item);
78 G_DEFINE_TYPE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM)
81 get_space_size (GtkToolItem *tool_item)
83 gint space_size = _gtk_toolbar_get_default_space_size();
84 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
86 if (GTK_IS_TOOLBAR (parent))
88 gtk_widget_style_get (parent,
89 "space-size", &space_size,
97 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
99 GObjectClass *object_class;
100 GtkContainerClass *container_class;
101 GtkToolItemClass *toolitem_class;
102 GtkWidgetClass *widget_class;
104 object_class = (GObjectClass *)class;
105 container_class = (GtkContainerClass *)class;
106 toolitem_class = (GtkToolItemClass *)class;
107 widget_class = (GtkWidgetClass *)class;
109 object_class->set_property = gtk_separator_tool_item_set_property;
110 object_class->get_property = gtk_separator_tool_item_get_property;
111 widget_class->size_request = gtk_separator_tool_item_size_request;
112 widget_class->expose_event = gtk_separator_tool_item_expose;
113 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
115 container_class->add = gtk_separator_tool_item_add;
117 g_object_class_install_property (object_class,
119 g_param_spec_boolean ("draw",
121 P_("Whether the separator is drawn, or just blank"),
123 GTK_PARAM_READWRITE));
125 g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
129 gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item)
131 separator_item->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator_item,
132 GTK_TYPE_SEPARATOR_TOOL_ITEM,
133 GtkSeparatorToolItemPrivate);
134 separator_item->priv->draw = TRUE;
138 gtk_separator_tool_item_add (GtkContainer *container,
141 g_warning ("attempt to add a child to an GtkSeparatorToolItem");
145 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
147 GtkWidget *menu_item = NULL;
149 menu_item = gtk_separator_menu_item_new();
151 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
157 gtk_separator_tool_item_set_property (GObject *object,
162 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
167 gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
170 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
176 gtk_separator_tool_item_get_property (GObject *object,
181 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
186 g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
195 gtk_separator_tool_item_size_request (GtkWidget *widget,
196 GtkRequisition *requisition)
198 GtkToolItem *item = GTK_TOOL_ITEM (widget);
199 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
201 if (orientation == GTK_ORIENTATION_HORIZONTAL)
203 requisition->width = get_space_size (item);
204 requisition->height = 1;
208 requisition->height = get_space_size (item);
209 requisition->width = 1;
214 gtk_separator_tool_item_expose (GtkWidget *widget,
215 GdkEventExpose *event)
217 GtkToolbar *toolbar = NULL;
218 GtkSeparatorToolItem *separator = GTK_SEPARATOR_TOOL_ITEM (widget);
219 GtkSeparatorToolItemPrivate *priv = separator->priv;
223 if (GTK_IS_TOOLBAR (widget->parent))
224 toolbar = GTK_TOOLBAR (widget->parent);
226 _gtk_toolbar_paint_space_line (widget, toolbar,
227 &(event->area), &widget->allocation);
234 * gtk_separator_tool_item_new:
236 * Create a new #GtkSeparatorToolItem
238 * Return value: the new #GtkSeparatorToolItem
243 gtk_separator_tool_item_new (void)
247 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
254 * gtk_separator_tool_item_get_draw:
255 * @item: a #GtkSeparatorToolItem
257 * Returns whether @item is drawn as a line, or just blank.
258 * See gtk_separator_tool_item_set_draw().
260 * Return value: %TRUE if @item is drawn as a line, or just blank.
265 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
267 g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
269 return item->priv->draw;
273 * gtk_separator_tool_item_set_draw:
274 * @item: a #GtkSeparatorToolItem
275 * @draw: whether @item is drawn as a vertical line
277 * Whether @item is drawn as a vertical line, or just blank.
278 * Setting this to %FALSE along with gtk_tool_item_set_expand() is useful
279 * to create an item that forces following items to the end of the toolbar.
284 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
287 g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
289 draw = draw != FALSE;
291 if (draw != item->priv->draw)
293 item->priv->draw = draw;
295 gtk_widget_queue_draw (GTK_WIDGET (item));
297 g_object_notify (G_OBJECT (item), "draw");