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 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 #define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
60 struct _GtkSeparatorToolItemPrivate
65 G_DEFINE_TYPE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM)
68 get_space_size (GtkToolItem *tool_item)
70 gint space_size = _gtk_toolbar_get_default_space_size();
71 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
73 if (GTK_IS_TOOLBAR (parent))
75 gtk_widget_style_get (parent,
76 "space-size", &space_size,
84 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
86 GObjectClass *object_class;
87 GtkContainerClass *container_class;
88 GtkToolItemClass *toolitem_class;
89 GtkWidgetClass *widget_class;
91 object_class = (GObjectClass *)class;
92 container_class = (GtkContainerClass *)class;
93 toolitem_class = (GtkToolItemClass *)class;
94 widget_class = (GtkWidgetClass *)class;
96 object_class->set_property = gtk_separator_tool_item_set_property;
97 object_class->get_property = gtk_separator_tool_item_get_property;
98 widget_class->size_request = gtk_separator_tool_item_size_request;
99 widget_class->expose_event = gtk_separator_tool_item_expose;
100 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
102 container_class->add = gtk_separator_tool_item_add;
104 g_object_class_install_property (object_class,
106 g_param_spec_boolean ("draw",
108 P_("Whether the separator is drawn, or just blank"),
110 GTK_PARAM_READWRITE));
112 g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
116 gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item)
118 separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
119 separator_item->priv->draw = TRUE;
123 gtk_separator_tool_item_add (GtkContainer *container,
126 g_warning ("attempt to add a child to an GtkSeparatorToolItem");
130 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
132 GtkWidget *menu_item = NULL;
134 menu_item = gtk_separator_menu_item_new();
136 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
142 gtk_separator_tool_item_set_property (GObject *object,
147 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
152 gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
155 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
161 gtk_separator_tool_item_get_property (GObject *object,
166 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
171 g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
180 gtk_separator_tool_item_size_request (GtkWidget *widget,
181 GtkRequisition *requisition)
183 GtkToolItem *item = GTK_TOOL_ITEM (widget);
184 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
186 if (orientation == GTK_ORIENTATION_HORIZONTAL)
188 requisition->width = get_space_size (item);
189 requisition->height = 1;
193 requisition->height = get_space_size (item);
194 requisition->width = 1;
199 gtk_separator_tool_item_expose (GtkWidget *widget,
200 GdkEventExpose *event)
202 GtkToolbar *toolbar = NULL;
203 GtkSeparatorToolItemPrivate *priv =
204 GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (widget);
208 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
209 toolbar = GTK_TOOLBAR (widget->parent);
211 _gtk_toolbar_paint_space_line (widget, toolbar,
212 &(event->area), &widget->allocation);
219 * gtk_separator_tool_item_new:
221 * Create a new #GtkSeparatorToolItem
223 * Return value: the new #GtkSeparatorToolItem
228 gtk_separator_tool_item_new (void)
232 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
239 * gtk_separator_tool_item_get_draw:
240 * @item: a #GtkSeparatorToolItem
242 * Returns whether @separator_tool_item is drawn as a
243 * line, or just blank. See gtk_separator_tool_item_set_draw().
245 * Return value: #TRUE if @separator_tool_item is drawn as a line, or just blank.
250 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
252 g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
254 return item->priv->draw;
258 * gtk_separator_tool_item_set_draw:
259 * @item: a #GtkSeparatorToolItem
260 * @draw: whether @separator_tool_item is drawn as a vertical line
262 * When @separator_tool_items is drawn as a vertical line, or just blank.
263 * Setting this #FALSE along with gtk_tool_item_set_expand() is useful
264 * to create an item that forces following items to the end of the toolbar.
269 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
272 g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
274 draw = draw != FALSE;
276 if (draw != item->priv->draw)
278 item->priv->draw = draw;
280 gtk_widget_queue_draw (GTK_WIDGET (item));
282 g_object_notify (G_OBJECT (item), "draw");
286 #define __GTK_SEPARATOR_TOOL_ITEM_C__
287 #include "gtkaliasdef.c"