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 static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
38 static void gtk_separator_tool_item_size_request (GtkWidget *widget,
39 GtkRequisition *requisition);
40 static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
41 GdkEventExpose *event);
42 static void gtk_separator_tool_item_add (GtkContainer *container,
44 static GtkToolbarSpaceStyle get_space_style (GtkToolItem *tool_item);
45 static gint get_space_size (GtkToolItem *tool_item);
47 static GObjectClass *parent_class = NULL;
51 gtk_separator_tool_item_get_type (void)
53 static GType type = 0;
57 static const GTypeInfo type_info =
59 sizeof (GtkSeparatorToolItemClass),
61 (GBaseFinalizeFunc) 0,
62 (GClassInitFunc) gtk_separator_tool_item_class_init,
63 (GClassFinalizeFunc) 0,
65 sizeof (GtkSeparatorToolItem),
67 (GInstanceInitFunc) NULL,
70 type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
71 "GtkSeparatorToolItem", &type_info, 0);
76 static GtkToolbarSpaceStyle
77 get_space_style (GtkToolItem *tool_item)
79 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
80 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
82 if (GTK_IS_TOOLBAR (parent))
84 gtk_widget_style_get (parent,
85 "space_style", &space_style,
93 get_space_size (GtkToolItem *tool_item)
95 gint space_size = DEFAULT_SPACE_SIZE;
96 GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
98 if (GTK_IS_TOOLBAR (parent))
100 gtk_widget_style_get (parent,
101 "space_size", &space_size,
109 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
111 GtkContainerClass *container_class;
112 GtkToolItemClass *toolitem_class;
113 GtkWidgetClass *widget_class;
115 parent_class = g_type_class_peek_parent (class);
116 container_class = (GtkContainerClass *)class;
117 toolitem_class = (GtkToolItemClass *)class;
118 widget_class = (GtkWidgetClass *)class;
120 widget_class->size_request = gtk_separator_tool_item_size_request;
121 widget_class->expose_event = gtk_separator_tool_item_expose;
123 container_class->add = gtk_separator_tool_item_add;
127 gtk_separator_tool_item_add (GtkContainer *container,
130 g_warning("attempt to add a child to an GtkSeparatorToolItem");
134 gtk_separator_tool_item_size_request (GtkWidget *widget,
135 GtkRequisition *requisition)
137 GtkToolItem *item = GTK_TOOL_ITEM (widget);
138 GtkOrientation orientation = gtk_tool_item_get_orientation (item);
140 if (orientation == GTK_ORIENTATION_HORIZONTAL)
142 requisition->width = get_space_size (item);
143 requisition->height = 1;
147 requisition->height = get_space_size (item);
148 requisition->width = 1;
153 gtk_separator_tool_item_expose (GtkWidget *widget,
154 GdkEventExpose *event)
156 GtkToolItem *tool_item = GTK_TOOL_ITEM (widget);
158 GtkAllocation *allocation;
159 GtkOrientation orientation;
162 if (get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
164 space_size = get_space_size (tool_item);
165 allocation = &(widget->allocation);
166 orientation = gtk_tool_item_get_orientation (tool_item);
167 area = &(event->area);
169 if (orientation == GTK_ORIENTATION_HORIZONTAL)
171 gtk_paint_vline (widget->style, widget->window,
172 GTK_WIDGET_STATE (widget), area, widget,
173 "separator_tool_item",
174 allocation->y + allocation->height *
175 SPACE_LINE_START / SPACE_LINE_DIVISION,
176 allocation->y + allocation->height *
177 SPACE_LINE_END / SPACE_LINE_DIVISION,
178 allocation->x + (space_size - widget->style->xthickness) / 2);
180 else if (orientation == GTK_ORIENTATION_VERTICAL)
182 gtk_paint_hline (widget->style, widget->window,
183 GTK_WIDGET_STATE (widget), area, widget,
184 "separator_tool_item",
185 allocation->x + allocation->width *
186 SPACE_LINE_START / SPACE_LINE_DIVISION,
187 allocation->x + allocation->width *
188 SPACE_LINE_END / SPACE_LINE_DIVISION,
189 allocation->y + (space_size - widget->style->ythickness) / 2);
197 gtk_separator_tool_item_new (void)
201 self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,