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
25 #include "gtkseparatormenuitem.h"
26 #include "gtkseparatortoolitem.h"
28 #include "gtktoolbar.h"
30 #define MENU_ID "gtk-separator-tool-item-menu-id"
37 static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
38 static void gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
39 GtkSeparatorToolItemClass *class);
40 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
41 static void gtk_separator_tool_item_set_property (GObject *object,
45 static void gtk_separator_tool_item_get_property (GObject *object,
49 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
50 GtkRequisition *requisition);
51 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
52 GdkEventExpose *event);
53 static void gtk_separator_tool_item_add (GtkContainer *container,
55 static gint get_space_size (GtkToolItem *tool_item);
59 static GObjectClass *parent_class = NULL;
61 #define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
63 struct _GtkSeparatorToolItemPrivate
69 gtk_separator_tool_item_get_type (void)
71 static GType type = 0;
75 static const GTypeInfo type_info =
77 sizeof (GtkSeparatorToolItemClass),
79 (GBaseFinalizeFunc) 0,
80 (GClassInitFunc) gtk_separator_tool_item_class_init,
81 (GClassFinalizeFunc) 0,
83 sizeof (GtkSeparatorToolItem),
85 (GInstanceInitFunc) gtk_separator_tool_item_init,
88 type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
89 "GtkSeparatorToolItem", &type_info, 0);
95 get_space_size (GtkToolItem *tool_item)
97 gint space_size = _gtk_toolbar_get_default_space_size();
98 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
100 if (GTK_IS_TOOLBAR (parent))
102 gtk_widget_style_get (parent,
103 "space_size", &space_size,
111 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
113 GObjectClass *object_class;
114 GtkContainerClass *container_class;
115 GtkToolItemClass *toolitem_class;
116 GtkWidgetClass *widget_class;
118 parent_class = g_type_class_peek_parent (class);
119 object_class = (GObjectClass *)class;
120 container_class = (GtkContainerClass *)class;
121 toolitem_class = (GtkToolItemClass *)class;
122 widget_class = (GtkWidgetClass *)class;
124 object_class->set_property = gtk_separator_tool_item_set_property;
125 object_class->get_property = gtk_separator_tool_item_get_property;
126 widget_class->size_request = gtk_separator_tool_item_size_request;
127 widget_class->expose_event = gtk_separator_tool_item_expose;
128 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
130 container_class->add = gtk_separator_tool_item_add;
132 g_object_class_install_property (object_class,
134 g_param_spec_boolean ("draw",
136 P_("Whether the separator is drawn, or just blank"),
140 g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
144 gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
145 GtkSeparatorToolItemClass *class)
147 separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
148 separator_item->priv->draw = TRUE;
152 gtk_separator_tool_item_add (GtkContainer *container,
155 g_warning ("attempt to add a child to an GtkSeparatorToolItem");
159 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
161 GtkWidget *menu_item = NULL;
163 menu_item = gtk_separator_menu_item_new();
165 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
171 gtk_separator_tool_item_set_property (GObject *object,
176 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
181 gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
184 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190 gtk_separator_tool_item_get_property (GObject *object,
195 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
200 g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
203 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
209 gtk_separator_tool_item_size_request (GtkWidget *widget,
210 GtkRequisition *requisition)
212 GtkToolItem *item = GTK_TOOL_ITEM (widget);
213 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
215 if (orientation == GTK_ORIENTATION_HORIZONTAL)
217 requisition->width = get_space_size (item);
218 requisition->height = 1;
222 requisition->height = get_space_size (item);
223 requisition->width = 1;
228 gtk_separator_tool_item_expose (GtkWidget *widget,
229 GdkEventExpose *event)
231 GtkToolbar *toolbar = NULL;
233 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
234 toolbar = GTK_TOOLBAR (widget->parent);
236 _gtk_toolbar_paint_space_line (widget, toolbar,
237 &(event->area), &widget->allocation);
243 * gtk_separator_tool_item_new:
245 * Create a new #GtkSeparatorToolItem
247 * Return value: the new #GtkSeparatorToolItem
252 gtk_separator_tool_item_new (void)
256 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
263 * gtk_separator_tool_item_get_draw:
264 * @item: a #GtkSeparatorToolItem
266 * Returns whether @separator_tool_item is drawn as a
267 * line, or just blank. See gtk_separator_tool_item_set_draw().
269 * Return value: #TRUE if @separator_tool_item is drawn as a line, or just blank.
274 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
276 g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
278 return item->priv->draw;
282 * gtk_separator_tool_item_set_draw:
283 * @item: a #GtkSeparatorToolItem
284 * @draw: whether @separator_tool_item is drawn as a vertical iln
286 * When @separator_tool_items is drawn as a vertical line, or just blank.
287 * Setting this #FALSE along with gtk_tool_item_set_expand() is useful
288 * to create an item that forces following items to the end of the toolbar.
293 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
296 g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
298 draw = draw != FALSE;
300 if (draw != item->priv->draw)
302 item->priv->draw = draw;
304 gtk_widget_queue_draw (GTK_WIDGET (item));
306 g_object_notify (G_OBJECT (item), "draw");