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.
23 #include "gtkseparatormenuitem.h"
24 #include "gtkseparatortoolitem.h"
26 #include "gtktoolbar.h"
27 #include "gtkprivate.h"
30 #define MENU_ID "gtk-separator-tool-item-menu-id"
37 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
38 static void gtk_separator_tool_item_set_property (GObject *object,
42 static void gtk_separator_tool_item_get_property (GObject *object,
46 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
47 GtkRequisition *requisition);
48 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
49 GdkEventExpose *event);
50 static void gtk_separator_tool_item_add (GtkContainer *container,
52 static gint get_space_size (GtkToolItem *tool_item);
56 #define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
58 struct _GtkSeparatorToolItemPrivate
63 G_DEFINE_TYPE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM)
66 get_space_size (GtkToolItem *tool_item)
68 gint space_size = _gtk_toolbar_get_default_space_size();
69 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
71 if (GTK_IS_TOOLBAR (parent))
73 gtk_widget_style_get (parent,
74 "space-size", &space_size,
82 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
84 GObjectClass *object_class;
85 GtkContainerClass *container_class;
86 GtkToolItemClass *toolitem_class;
87 GtkWidgetClass *widget_class;
89 object_class = (GObjectClass *)class;
90 container_class = (GtkContainerClass *)class;
91 toolitem_class = (GtkToolItemClass *)class;
92 widget_class = (GtkWidgetClass *)class;
94 object_class->set_property = gtk_separator_tool_item_set_property;
95 object_class->get_property = gtk_separator_tool_item_get_property;
96 widget_class->size_request = gtk_separator_tool_item_size_request;
97 widget_class->expose_event = gtk_separator_tool_item_expose;
98 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
100 container_class->add = gtk_separator_tool_item_add;
102 g_object_class_install_property (object_class,
104 g_param_spec_boolean ("draw",
106 P_("Whether the separator is drawn, or just blank"),
108 GTK_PARAM_READWRITE));
110 g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
114 gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item)
116 separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
117 separator_item->priv->draw = TRUE;
121 gtk_separator_tool_item_add (GtkContainer *container,
124 g_warning ("attempt to add a child to an GtkSeparatorToolItem");
128 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
130 GtkWidget *menu_item = NULL;
132 menu_item = gtk_separator_menu_item_new();
134 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
140 gtk_separator_tool_item_set_property (GObject *object,
145 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
150 gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
159 gtk_separator_tool_item_get_property (GObject *object,
164 GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
169 g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
172 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
178 gtk_separator_tool_item_size_request (GtkWidget *widget,
179 GtkRequisition *requisition)
181 GtkToolItem *item = GTK_TOOL_ITEM (widget);
182 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
184 if (orientation == GTK_ORIENTATION_HORIZONTAL)
186 requisition->width = get_space_size (item);
187 requisition->height = 1;
191 requisition->height = get_space_size (item);
192 requisition->width = 1;
197 gtk_separator_tool_item_expose (GtkWidget *widget,
198 GdkEventExpose *event)
200 GtkToolbar *toolbar = NULL;
201 GtkSeparatorToolItemPrivate *priv =
202 GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (widget);
206 if (GTK_IS_TOOLBAR (widget->parent))
207 toolbar = GTK_TOOLBAR (widget->parent);
209 _gtk_toolbar_paint_space_line (widget, toolbar,
210 &(event->area), &widget->allocation);
217 * gtk_separator_tool_item_new:
219 * Create a new #GtkSeparatorToolItem
221 * Return value: the new #GtkSeparatorToolItem
226 gtk_separator_tool_item_new (void)
230 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
237 * gtk_separator_tool_item_get_draw:
238 * @item: a #GtkSeparatorToolItem
240 * Returns whether @item is drawn as a line, or just blank.
241 * See gtk_separator_tool_item_set_draw().
243 * Return value: %TRUE if @item is drawn as a line, or just blank.
248 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
250 g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
252 return item->priv->draw;
256 * gtk_separator_tool_item_set_draw:
257 * @item: a #GtkSeparatorToolItem
258 * @draw: whether @item is drawn as a vertical line
260 * Whether @item is drawn as a vertical line, or just blank.
261 * Setting this to %FALSE along with gtk_tool_item_set_expand() is useful
262 * to create an item that forces following items to the end of the toolbar.
267 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
270 g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
272 draw = draw != FALSE;
274 if (draw != item->priv->draw)
276 item->priv->draw = draw;
278 gtk_widget_queue_draw (GTK_WIDGET (item));
280 g_object_notify (G_OBJECT (item), "draw");
284 #define __GTK_SEPARATOR_TOOL_ITEM_C__
285 #include "gtkaliasdef.c"