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"
31 #define MENU_ID "gtk-separator-tool-item-menu-id"
38 static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
39 static void gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
40 GtkSeparatorToolItemClass *class);
41 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
42 static void gtk_separator_tool_item_set_property (GObject *object,
46 static void gtk_separator_tool_item_get_property (GObject *object,
50 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
51 GtkRequisition *requisition);
52 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
53 GdkEventExpose *event);
54 static void gtk_separator_tool_item_add (GtkContainer *container,
56 static gint get_space_size (GtkToolItem *tool_item);
60 static GObjectClass *parent_class = NULL;
62 #define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
64 struct _GtkSeparatorToolItemPrivate
70 gtk_separator_tool_item_get_type (void)
72 static GType type = 0;
76 static const GTypeInfo type_info =
78 sizeof (GtkSeparatorToolItemClass),
80 (GBaseFinalizeFunc) 0,
81 (GClassInitFunc) gtk_separator_tool_item_class_init,
82 (GClassFinalizeFunc) 0,
84 sizeof (GtkSeparatorToolItem),
86 (GInstanceInitFunc) gtk_separator_tool_item_init,
89 type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
90 "GtkSeparatorToolItem", &type_info, 0);
96 get_space_size (GtkToolItem *tool_item)
98 gint space_size = _gtk_toolbar_get_default_space_size();
99 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
101 if (GTK_IS_TOOLBAR (parent))
103 gtk_widget_style_get (parent,
104 "space_size", &space_size,
112 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
114 GObjectClass *object_class;
115 GtkContainerClass *container_class;
116 GtkToolItemClass *toolitem_class;
117 GtkWidgetClass *widget_class;
119 parent_class = g_type_class_peek_parent (class);
120 object_class = (GObjectClass *)class;
121 container_class = (GtkContainerClass *)class;
122 toolitem_class = (GtkToolItemClass *)class;
123 widget_class = (GtkWidgetClass *)class;
125 object_class->set_property = gtk_separator_tool_item_set_property;
126 object_class->get_property = gtk_separator_tool_item_get_property;
127 widget_class->size_request = gtk_separator_tool_item_size_request;
128 widget_class->expose_event = gtk_separator_tool_item_expose;
129 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
131 container_class->add = gtk_separator_tool_item_add;
133 g_object_class_install_property (object_class,
135 g_param_spec_boolean ("draw",
137 P_("Whether the separator is drawn, or just blank"),
141 g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
145 gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
146 GtkSeparatorToolItemClass *class)
148 separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
149 separator_item->priv->draw = TRUE;
153 gtk_separator_tool_item_add (GtkContainer *container,
156 g_warning ("attempt to add a child to an GtkSeparatorToolItem");
160 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
162 GtkWidget *menu_item = NULL;
164 menu_item = gtk_separator_menu_item_new();
166 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
172 gtk_separator_tool_item_set_property (GObject *object,
177 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
182 gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
191 gtk_separator_tool_item_get_property (GObject *object,
196 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
201 g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
204 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
210 gtk_separator_tool_item_size_request (GtkWidget *widget,
211 GtkRequisition *requisition)
213 GtkToolItem *item = GTK_TOOL_ITEM (widget);
214 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
216 if (orientation == GTK_ORIENTATION_HORIZONTAL)
218 requisition->width = get_space_size (item);
219 requisition->height = 1;
223 requisition->height = get_space_size (item);
224 requisition->width = 1;
229 gtk_separator_tool_item_expose (GtkWidget *widget,
230 GdkEventExpose *event)
232 GtkToolbar *toolbar = NULL;
233 GtkSeparatorToolItemPrivate *priv =
234 GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (widget);
238 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
239 toolbar = GTK_TOOLBAR (widget->parent);
241 _gtk_toolbar_paint_space_line (widget, toolbar,
242 &(event->area), &widget->allocation);
249 * gtk_separator_tool_item_new:
251 * Create a new #GtkSeparatorToolItem
253 * Return value: the new #GtkSeparatorToolItem
258 gtk_separator_tool_item_new (void)
262 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
269 * gtk_separator_tool_item_get_draw:
270 * @item: a #GtkSeparatorToolItem
272 * Returns whether @separator_tool_item is drawn as a
273 * line, or just blank. See gtk_separator_tool_item_set_draw().
275 * Return value: #TRUE if @separator_tool_item is drawn as a line, or just blank.
280 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
282 g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
284 return item->priv->draw;
288 * gtk_separator_tool_item_set_draw:
289 * @item: a #GtkSeparatorToolItem
290 * @draw: whether @separator_tool_item is drawn as a vertical line
292 * When @separator_tool_items is drawn as a vertical line, or just blank.
293 * Setting this #FALSE along with gtk_tool_item_set_expand() is useful
294 * to create an item that forces following items to the end of the toolbar.
299 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
302 g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
304 draw = draw != FALSE;
306 if (draw != item->priv->draw)
308 item->priv->draw = draw;
310 gtk_widget_queue_draw (GTK_WIDGET (item));
312 g_object_notify (G_OBJECT (item), "draw");
316 #define __GTK_SEPARATOR_TOOL_ITEM_C__
317 #include "gtkaliasdef.c"