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.
22 #undef GTK_DISABLE_DEPRECATED
24 #include "gtkseparatormenuitem.h"
25 #include "gtkseparatortoolitem.h"
27 #include "gtktoolbar.h"
29 #define MENU_ID "gtk-separator-tool-item-menu-id"
36 static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
37 static void gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
38 GtkSeparatorToolItemClass *class);
39 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
40 static void gtk_separator_tool_item_set_property (GObject *object,
44 static void gtk_separator_tool_item_get_property (GObject *object,
48 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
49 GtkRequisition *requisition);
50 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
51 GdkEventExpose *event);
52 static void gtk_separator_tool_item_add (GtkContainer *container,
54 static gint get_space_size (GtkToolItem *tool_item);
58 static GObjectClass *parent_class = NULL;
60 #define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
62 struct _GtkSeparatorToolItemPrivate
68 gtk_separator_tool_item_get_type (void)
70 static GType type = 0;
74 static const GTypeInfo type_info =
76 sizeof (GtkSeparatorToolItemClass),
78 (GBaseFinalizeFunc) 0,
79 (GClassInitFunc) gtk_separator_tool_item_class_init,
80 (GClassFinalizeFunc) 0,
82 sizeof (GtkSeparatorToolItem),
84 (GInstanceInitFunc) gtk_separator_tool_item_init,
87 type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
88 "GtkSeparatorToolItem", &type_info, 0);
94 get_space_size (GtkToolItem *tool_item)
96 gint space_size = _gtk_toolbar_get_default_space_size();
97 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
99 if (GTK_IS_TOOLBAR (parent))
101 gtk_widget_style_get (parent,
102 "space_size", &space_size,
110 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
112 GObjectClass *object_class;
113 GtkContainerClass *container_class;
114 GtkToolItemClass *toolitem_class;
115 GtkWidgetClass *widget_class;
117 parent_class = g_type_class_peek_parent (class);
118 object_class = (GObjectClass *)class;
119 container_class = (GtkContainerClass *)class;
120 toolitem_class = (GtkToolItemClass *)class;
121 widget_class = (GtkWidgetClass *)class;
123 object_class->set_property = gtk_separator_tool_item_set_property;
124 object_class->get_property = gtk_separator_tool_item_get_property;
125 widget_class->size_request = gtk_separator_tool_item_size_request;
126 widget_class->expose_event = gtk_separator_tool_item_expose;
127 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
129 container_class->add = gtk_separator_tool_item_add;
131 g_object_class_install_property (object_class,
133 g_param_spec_boolean ("draw",
135 P_("Whether the separator is drawn, or just blank"),
139 g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
143 gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
144 GtkSeparatorToolItemClass *class)
146 separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
147 separator_item->priv->draw = TRUE;
151 gtk_separator_tool_item_add (GtkContainer *container,
154 g_warning ("attempt to add a child to an GtkSeparatorToolItem");
158 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
160 GtkWidget *menu_item = NULL;
162 menu_item = gtk_separator_menu_item_new();
164 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
170 gtk_separator_tool_item_set_property (GObject *object,
175 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
180 gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
183 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
189 gtk_separator_tool_item_get_property (GObject *object,
194 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
199 g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
202 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
208 gtk_separator_tool_item_size_request (GtkWidget *widget,
209 GtkRequisition *requisition)
211 GtkToolItem *item = GTK_TOOL_ITEM (widget);
212 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
214 if (orientation == GTK_ORIENTATION_HORIZONTAL)
216 requisition->width = get_space_size (item);
217 requisition->height = 1;
221 requisition->height = get_space_size (item);
222 requisition->width = 1;
227 gtk_separator_tool_item_expose (GtkWidget *widget,
228 GdkEventExpose *event)
230 GtkToolbar *toolbar = NULL;
232 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
233 toolbar = GTK_TOOLBAR (widget->parent);
235 _gtk_toolbar_paint_space_line (widget, toolbar,
236 &(event->area), &widget->allocation);
242 * gtk_separator_tool_item_new:
244 * Create a new #GtkSeparatorToolItem
246 * Return value: the new #GtkSeparatorToolItem
251 gtk_separator_tool_item_new (void)
255 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
262 * gtk_separator_tool_item_get_draw:
263 * @item: a #GtkSeparatorToolItem
265 * Returns whether @separator_tool_item is drawn as a
266 * line, or just blank. See gtk_separator_tool_item_set_draw().
268 * Return value: #TRUE if @separator_tool_item is drawn as a line, or just blank.
273 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
275 g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
277 return item->priv->draw;
281 * gtk_separator_tool_item_set_draw:
282 * @item: a #GtkSeparatorToolItem
283 * @draw: whether @separator_tool_item is drawn as a vertical iln
285 * When @separator_tool_items is drawn as a vertical line, or just blank.
286 * Setting this #FALSE along with gtk_tool_item_set_expand() is useful
287 * to create an item that forces following items to the end of the toolbar.
292 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
295 g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
297 draw = draw != FALSE;
299 if (draw != item->priv->draw)
301 item->priv->draw = draw;
303 gtk_widget_queue_draw (GTK_WIDGET (item));
305 g_object_notify (G_OBJECT (item), "draw");