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 5
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 static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
38 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
39 GdkEventExpose *event);
40 static void gtk_separator_tool_item_add (GtkContainer *container,
42 static GtkToolbarSpaceStyle get_space_style (GtkToolItem *tool_item);
43 static gint get_space_size (GtkToolItem *tool_item);
45 static GObjectClass *parent_class = NULL;
49 gtk_separator_tool_item_get_type (void)
51 static GType type = 0;
55 static const GTypeInfo type_info =
57 sizeof (GtkSeparatorToolItemClass),
59 (GBaseFinalizeFunc) 0,
60 (GClassInitFunc) gtk_separator_tool_item_class_init,
61 (GClassFinalizeFunc) 0,
63 sizeof (GtkSeparatorToolItem),
65 (GInstanceInitFunc) NULL,
68 type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
69 "GtkSeparatorToolItem", &type_info, 0);
74 static GtkToolbarSpaceStyle
75 get_space_style (GtkToolItem *tool_item)
77 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
78 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
80 if (GTK_IS_TOOLBAR (parent))
82 gtk_widget_style_get (parent,
83 "space_style", &space_style,
91 get_space_size (GtkToolItem *tool_item)
93 gint space_size = DEFAULT_SPACE_SIZE;
94 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
96 if (GTK_IS_TOOLBAR (parent))
98 gtk_widget_style_get (parent,
99 "space_size", &space_size,
107 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
109 GtkContainerClass *container_class;
110 GtkToolItemClass *toolitem_class;
111 GtkWidgetClass *widget_class;
113 parent_class = g_type_class_peek_parent (class);
114 container_class = (GtkContainerClass *)class;
115 toolitem_class = (GtkToolItemClass *)class;
116 widget_class = (GtkWidgetClass *)class;
118 widget_class->expose_event = gtk_separator_tool_item_expose;
120 container_class->add = gtk_separator_tool_item_add;
124 gtk_separator_tool_item_add (GtkContainer *container,
127 g_warning("attempt to add a child to an GtkSeparatorToolItem");
131 gtk_separator_tool_item_expose (GtkWidget *widget,
132 GdkEventExpose *event)
134 GtkToolItem *tool_item = GTK_TOOL_ITEM (widget);
136 GtkAllocation *allocation;
137 GtkOrientation orientation;
140 if (get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
142 space_size = get_space_size (tool_item);
143 allocation = &(widget->allocation);
144 orientation = gtk_tool_item_get_orientation (tool_item);
145 area = &(event->area);
147 if (orientation == GTK_ORIENTATION_HORIZONTAL)
149 gtk_paint_vline (widget->style, widget->window,
150 GTK_WIDGET_STATE (widget), area, widget,
151 "separator_tool_item",
152 allocation->y + allocation->height *
153 SPACE_LINE_START / SPACE_LINE_DIVISION,
154 allocation->y + allocation->height *
155 SPACE_LINE_END / SPACE_LINE_DIVISION,
156 allocation->x + (space_size - widget->style->xthickness) / 2);
158 else if (orientation == GTK_ORIENTATION_VERTICAL)
160 gtk_paint_hline (widget->style, widget->window,
161 GTK_WIDGET_STATE (widget), area, widget,
162 "separator_tool_item",
163 allocation->x + allocation->width *
164 SPACE_LINE_START / SPACE_LINE_DIVISION,
165 allocation->x + allocation->width *
166 SPACE_LINE_END / SPACE_LINE_DIVISION,
167 allocation->y + (space_size - widget->style->ythickness) / 2);
175 gtk_separator_tool_item_new (void)
179 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,