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"
29 #include "gtkprivate.h"
32 #define MENU_ID "gtk-separator-tool-item-menu-id"
39 static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
40 static void gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
41 GtkSeparatorToolItemClass *class);
42 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
43 static void gtk_separator_tool_item_set_property (GObject *object,
47 static void gtk_separator_tool_item_get_property (GObject *object,
51 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
52 GtkRequisition *requisition);
53 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
54 GdkEventExpose *event);
55 static void gtk_separator_tool_item_add (GtkContainer *container,
57 static gint get_space_size (GtkToolItem *tool_item);
61 static GObjectClass *parent_class = NULL;
63 #define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
65 struct _GtkSeparatorToolItemPrivate
71 gtk_separator_tool_item_get_type (void)
73 static GType type = 0;
77 static const GTypeInfo type_info =
79 sizeof (GtkSeparatorToolItemClass),
81 (GBaseFinalizeFunc) 0,
82 (GClassInitFunc) gtk_separator_tool_item_class_init,
83 (GClassFinalizeFunc) 0,
85 sizeof (GtkSeparatorToolItem),
87 (GInstanceInitFunc) gtk_separator_tool_item_init,
90 type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
91 "GtkSeparatorToolItem", &type_info, 0);
97 get_space_size (GtkToolItem *tool_item)
99 gint space_size = _gtk_toolbar_get_default_space_size();
100 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
102 if (GTK_IS_TOOLBAR (parent))
104 gtk_widget_style_get (parent,
105 "space-size", &space_size,
113 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
115 GObjectClass *object_class;
116 GtkContainerClass *container_class;
117 GtkToolItemClass *toolitem_class;
118 GtkWidgetClass *widget_class;
120 parent_class = g_type_class_peek_parent (class);
121 object_class = (GObjectClass *)class;
122 container_class = (GtkContainerClass *)class;
123 toolitem_class = (GtkToolItemClass *)class;
124 widget_class = (GtkWidgetClass *)class;
126 object_class->set_property = gtk_separator_tool_item_set_property;
127 object_class->get_property = gtk_separator_tool_item_get_property;
128 widget_class->size_request = gtk_separator_tool_item_size_request;
129 widget_class->expose_event = gtk_separator_tool_item_expose;
130 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
132 container_class->add = gtk_separator_tool_item_add;
134 g_object_class_install_property (object_class,
136 g_param_spec_boolean ("draw",
138 P_("Whether the separator is drawn, or just blank"),
140 GTK_PARAM_READWRITE));
142 g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
146 gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
147 GtkSeparatorToolItemClass *class)
149 separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
150 separator_item->priv->draw = TRUE;
154 gtk_separator_tool_item_add (GtkContainer *container,
157 g_warning ("attempt to add a child to an GtkSeparatorToolItem");
161 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
163 GtkWidget *menu_item = NULL;
165 menu_item = gtk_separator_menu_item_new();
167 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
173 gtk_separator_tool_item_set_property (GObject *object,
178 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
183 gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
186 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
192 gtk_separator_tool_item_get_property (GObject *object,
197 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
202 g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
205 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
211 gtk_separator_tool_item_size_request (GtkWidget *widget,
212 GtkRequisition *requisition)
214 GtkToolItem *item = GTK_TOOL_ITEM (widget);
215 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
217 if (orientation == GTK_ORIENTATION_HORIZONTAL)
219 requisition->width = get_space_size (item);
220 requisition->height = 1;
224 requisition->height = get_space_size (item);
225 requisition->width = 1;
230 gtk_separator_tool_item_expose (GtkWidget *widget,
231 GdkEventExpose *event)
233 GtkToolbar *toolbar = NULL;
234 GtkSeparatorToolItemPrivate *priv =
235 GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (widget);
239 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
240 toolbar = GTK_TOOLBAR (widget->parent);
242 _gtk_toolbar_paint_space_line (widget, toolbar,
243 &(event->area), &widget->allocation);
250 * gtk_separator_tool_item_new:
252 * Create a new #GtkSeparatorToolItem
254 * Return value: the new #GtkSeparatorToolItem
259 gtk_separator_tool_item_new (void)
263 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
270 * gtk_separator_tool_item_get_draw:
271 * @item: a #GtkSeparatorToolItem
273 * Returns whether @separator_tool_item is drawn as a
274 * line, or just blank. See gtk_separator_tool_item_set_draw().
276 * Return value: #TRUE if @separator_tool_item is drawn as a line, or just blank.
281 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
283 g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
285 return item->priv->draw;
289 * gtk_separator_tool_item_set_draw:
290 * @item: a #GtkSeparatorToolItem
291 * @draw: whether @separator_tool_item is drawn as a vertical line
293 * When @separator_tool_items is drawn as a vertical line, or just blank.
294 * Setting this #FALSE along with gtk_tool_item_set_expand() is useful
295 * to create an item that forces following items to the end of the toolbar.
300 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
303 g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
305 draw = draw != FALSE;
307 if (draw != item->priv->draw)
309 item->priv->draw = draw;
311 gtk_widget_queue_draw (GTK_WIDGET (item));
313 g_object_notify (G_OBJECT (item), "draw");
317 #define __GTK_SEPARATOR_TOOL_ITEM_C__
318 #include "gtkaliasdef.c"