1 /* gtkseparatortoolitem.c
3 * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
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
24 #include "gtkseparatormenuitem.h"
25 #include "gtkseparatortoolitem.h"
27 #include "gtktoolbar.h"
29 /* note: keep in sync with DEFAULT_SPACE_SIZE and DEFAULT_SPACE_STYLE in gtktoolbar.c */
30 #define DEFAULT_SPACE_SIZE 4
31 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
33 #define SPACE_LINE_DIVISION 10
34 #define SPACE_LINE_START 3
35 #define SPACE_LINE_END 7
37 #define MENU_ID "gtk-separator-tool-item-menu-id"
39 static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
40 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
41 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
43 GtkRequisition *requisition);
44 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
45 GdkEventExpose *event);
46 static void gtk_separator_tool_item_add (GtkContainer *container,
48 static GtkToolbarSpaceStyle get_space_style (GtkToolItem *tool_item);
49 static gint get_space_size (GtkToolItem *tool_item);
51 static GObjectClass *parent_class = NULL;
55 gtk_separator_tool_item_get_type (void)
57 static GType type = 0;
61 static const GTypeInfo type_info =
63 sizeof (GtkSeparatorToolItemClass),
65 (GBaseFinalizeFunc) 0,
66 (GClassInitFunc) gtk_separator_tool_item_class_init,
67 (GClassFinalizeFunc) 0,
69 sizeof (GtkSeparatorToolItem),
71 (GInstanceInitFunc) NULL,
74 type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
75 "GtkSeparatorToolItem", &type_info, 0);
80 static GtkToolbarSpaceStyle
81 get_space_style (GtkToolItem *tool_item)
83 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
84 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
86 if (GTK_IS_TOOLBAR (parent))
88 gtk_widget_style_get (parent,
89 "space_style", &space_style,
97 get_space_size (GtkToolItem *tool_item)
99 gint space_size = 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 GtkContainerClass *container_class;
116 GtkToolItemClass *toolitem_class;
117 GtkWidgetClass *widget_class;
119 parent_class = g_type_class_peek_parent (class);
120 container_class = (GtkContainerClass *)class;
121 toolitem_class = (GtkToolItemClass *)class;
122 widget_class = (GtkWidgetClass *)class;
124 widget_class->size_request = gtk_separator_tool_item_size_request;
125 widget_class->expose_event = gtk_separator_tool_item_expose;
126 toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
128 container_class->add = gtk_separator_tool_item_add;
132 gtk_separator_tool_item_add (GtkContainer *container,
135 g_warning("attempt to add a child to an GtkSeparatorToolItem");
139 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
141 GtkWidget *menu_item = NULL;
143 menu_item = gtk_separator_menu_item_new();
145 gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
151 gtk_separator_tool_item_size_request (GtkWidget *widget,
152 GtkRequisition *requisition)
154 GtkToolItem *item = GTK_TOOL_ITEM (widget);
155 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
157 if (orientation == GTK_ORIENTATION_HORIZONTAL)
159 requisition->width = get_space_size (item);
160 requisition->height = 1;
164 requisition->height = get_space_size (item);
165 requisition->width = 1;
170 gtk_separator_tool_item_expose (GtkWidget *widget,
171 GdkEventExpose *event)
173 GtkToolItem *tool_item = GTK_TOOL_ITEM (widget);
175 GtkAllocation *allocation;
176 GtkOrientation orientation;
179 if (get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
181 space_size = get_space_size (tool_item);
182 allocation = &(widget->allocation);
183 orientation = gtk_tool_item_get_orientation (tool_item);
184 area = &(event->area);
186 if (orientation == GTK_ORIENTATION_HORIZONTAL)
188 gtk_paint_vline (widget->style, widget->window,
189 GTK_WIDGET_STATE (widget), area, widget,
190 "separator_tool_item",
191 allocation->y + allocation->height *
192 SPACE_LINE_START / SPACE_LINE_DIVISION,
193 allocation->y + allocation->height *
194 SPACE_LINE_END / SPACE_LINE_DIVISION,
195 allocation->x + (space_size - widget->style->xthickness) / 2);
197 else if (orientation == GTK_ORIENTATION_VERTICAL)
199 gtk_paint_hline (widget->style, widget->window,
200 GTK_WIDGET_STATE (widget), area, widget,
201 "separator_tool_item",
202 allocation->x + allocation->width *
203 SPACE_LINE_START / SPACE_LINE_DIVISION,
204 allocation->x + allocation->width *
205 SPACE_LINE_END / SPACE_LINE_DIVISION,
206 allocation->y + (space_size - widget->style->ythickness) / 2);
214 * gtk_separator_tool_item_new:
216 * Create a new #GtkSeparatorToolItem
218 * Return value: the new #GtkSeparatorToolItem
223 gtk_separator_tool_item_new (void)
227 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,