]> Pileus Git - ~andy/gtk/blob - gtk/gtkseparatortoolitem.c
remove correction on x when detail is "menuitem". With the new menu look
[~andy/gtk] / gtk / gtkseparatortoolitem.c
1 /* gtkseparatortoolitem.c
2  *
3  * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
4  * Copyright (C) 2002 James Henstridge <james@daa.com.au>
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #undef GTK_DISABLE_DEPRECATED
23
24 #include "gtkseparatormenuitem.h"
25 #include "gtkseparatortoolitem.h"
26 #include "gtkintl.h"
27 #include "gtktoolbar.h"
28
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
32
33 #define SPACE_LINE_DIVISION 10
34 #define SPACE_LINE_START    3
35 #define SPACE_LINE_END      7
36
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,
43                                                                 GtkWidget                 *child);
44 static GtkToolbarSpaceStyle get_space_style                    (GtkToolItem               *tool_item);
45 static gint                 get_space_size                     (GtkToolItem               *tool_item);
46
47 static GObjectClass *parent_class = NULL;
48
49
50 GType
51 gtk_separator_tool_item_get_type (void)
52 {
53   static GType type = 0;
54
55   if (!type)
56     {
57       static const GTypeInfo type_info =
58         {
59           sizeof (GtkSeparatorToolItemClass),
60           (GBaseInitFunc) 0,
61           (GBaseFinalizeFunc) 0,
62           (GClassInitFunc) gtk_separator_tool_item_class_init,
63           (GClassFinalizeFunc) 0,
64           NULL,
65           sizeof (GtkSeparatorToolItem),
66           0, /* n_preallocs */
67           (GInstanceInitFunc) NULL,
68         };
69
70       type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
71                                      "GtkSeparatorToolItem", &type_info, 0);
72     }
73   return type;
74 }
75
76 static GtkToolbarSpaceStyle
77 get_space_style (GtkToolItem *tool_item)
78 {
79   GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
80   GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
81
82   if (GTK_IS_TOOLBAR (parent))
83     {
84       gtk_widget_style_get (parent,
85                             "space_style", &space_style,
86                             NULL);
87     }
88
89   return space_style;  
90 }
91
92 static gint
93 get_space_size (GtkToolItem *tool_item)
94 {
95   gint space_size = DEFAULT_SPACE_SIZE;
96   GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
97   
98   if (GTK_IS_TOOLBAR (parent))
99     {
100       gtk_widget_style_get (parent,
101                             "space_size", &space_size,
102                             NULL);
103     }
104
105   return space_size;
106 }
107
108 static void
109 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
110 {
111   GtkContainerClass *container_class;
112   GtkToolItemClass *toolitem_class;
113   GtkWidgetClass *widget_class;
114
115   parent_class = g_type_class_peek_parent (class);
116   container_class = (GtkContainerClass *)class;
117   toolitem_class = (GtkToolItemClass *)class;
118   widget_class = (GtkWidgetClass *)class;
119
120   widget_class->size_request = gtk_separator_tool_item_size_request;
121   widget_class->expose_event = gtk_separator_tool_item_expose;
122   
123   container_class->add = gtk_separator_tool_item_add;
124 }
125
126 static void
127 gtk_separator_tool_item_add (GtkContainer *container,
128                              GtkWidget    *child)
129 {
130   g_warning("attempt to add a child to an GtkSeparatorToolItem");
131 }
132
133 static void
134 gtk_separator_tool_item_size_request (GtkWidget      *widget,
135                                       GtkRequisition *requisition)
136 {
137   GtkToolItem *item = GTK_TOOL_ITEM (widget);
138   GtkOrientation orientation = gtk_tool_item_get_orientation (item);
139
140   if (orientation == GTK_ORIENTATION_HORIZONTAL)
141     {
142       requisition->width = get_space_size (item);
143       requisition->height = 1;
144     }
145   else
146     {
147       requisition->height = get_space_size (item);
148       requisition->width = 1;
149     }
150 }
151
152 static gboolean
153 gtk_separator_tool_item_expose (GtkWidget      *widget,
154                                 GdkEventExpose *event)
155 {
156   GtkToolItem *tool_item = GTK_TOOL_ITEM (widget);
157   gint space_size;
158   GtkAllocation *allocation;
159   GtkOrientation orientation;
160   GdkRectangle *area;
161
162   if (get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
163     {
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);
168
169       if (orientation == GTK_ORIENTATION_HORIZONTAL)
170         {
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);
179         }
180       else if (orientation == GTK_ORIENTATION_VERTICAL)
181         {
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);
190         }
191     }
192   
193   return TRUE;
194 }
195
196 GtkToolItem *
197 gtk_separator_tool_item_new (void)
198 {
199   GtkToolItem *self;
200
201   self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
202                        NULL);
203   
204   return self;
205 }