]> Pileus Git - ~andy/gtk/blob - gtk/gtkseparatortoolitem.c
Patch from Christian Neumair to make warning string more translator
[~andy/gtk] / gtk / gtkseparatortoolitem.c
1 /* gtkseparatortoolitem.c
2  *
3  * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
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 #define MENU_ID "gtk-separator-tool-item-menu-id"
30
31 enum {
32   PROP_0,
33   PROP_DRAW
34 };
35
36 static void     gtk_separator_tool_item_class_init        (GtkSeparatorToolItemClass *class);
37 static void     gtk_separator_tool_item_init              (GtkSeparatorToolItem      *separator_item,
38                                                            GtkSeparatorToolItemClass *class);
39 static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem               *item);
40 static void     gtk_separator_tool_item_set_property      (GObject                   *object,
41                                                            guint                      prop_id,
42                                                            const GValue              *value,
43                                                            GParamSpec                *pspec);
44 static void     gtk_separator_tool_item_get_property       (GObject                   *object,
45                                                            guint                      prop_id,
46                                                            GValue                    *value,
47                                                            GParamSpec                *pspec);
48 static void     gtk_separator_tool_item_size_request      (GtkWidget                 *widget,
49                                                            GtkRequisition            *requisition);
50 static gboolean gtk_separator_tool_item_expose            (GtkWidget                 *widget,
51                                                            GdkEventExpose            *event);
52 static void     gtk_separator_tool_item_add               (GtkContainer              *container,
53                                                            GtkWidget                 *child);
54 static gint     get_space_size                            (GtkToolItem               *tool_item);
55
56
57
58 static GObjectClass *parent_class = NULL;
59
60 #define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
61
62 struct _GtkSeparatorToolItemPrivate
63 {
64   guint draw : 1;
65 };
66
67 GType
68 gtk_separator_tool_item_get_type (void)
69 {
70   static GType type = 0;
71   
72   if (!type)
73     {
74       static const GTypeInfo type_info =
75         {
76           sizeof (GtkSeparatorToolItemClass),
77           (GBaseInitFunc) 0,
78           (GBaseFinalizeFunc) 0,
79           (GClassInitFunc) gtk_separator_tool_item_class_init,
80           (GClassFinalizeFunc) 0,
81           NULL,
82           sizeof (GtkSeparatorToolItem),
83           0, /* n_preallocs */
84           (GInstanceInitFunc) gtk_separator_tool_item_init,
85         };
86       
87       type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
88                                      "GtkSeparatorToolItem", &type_info, 0);
89     }
90   return type;
91 }
92
93 static gint
94 get_space_size (GtkToolItem *tool_item)
95 {
96   gint space_size = _gtk_toolbar_get_default_space_size();
97   GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
98   
99   if (GTK_IS_TOOLBAR (parent))
100     {
101       gtk_widget_style_get (parent,
102                             "space_size", &space_size,
103                             NULL);
104     }
105   
106   return space_size;
107 }
108
109 static void
110 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
111 {
112   GObjectClass *object_class;
113   GtkContainerClass *container_class;
114   GtkToolItemClass *toolitem_class;
115   GtkWidgetClass *widget_class;
116   
117   parent_class = g_type_class_peek_parent (class);
118   object_class = (GObjectClass *)class;
119   container_class = (GtkContainerClass *)class;
120   toolitem_class = (GtkToolItemClass *)class;
121   widget_class = (GtkWidgetClass *)class;
122
123   object_class->set_property = gtk_separator_tool_item_set_property;
124   object_class->get_property = gtk_separator_tool_item_get_property;
125   widget_class->size_request = gtk_separator_tool_item_size_request;
126   widget_class->expose_event = gtk_separator_tool_item_expose;
127   toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
128   
129   container_class->add = gtk_separator_tool_item_add;
130   
131   g_object_class_install_property (object_class,
132                                    PROP_DRAW,
133                                    g_param_spec_boolean ("draw",
134                                                          P_("Draw"),
135                                                          P_("Whether the separator is drawn, or just blank"),
136                                                          TRUE,
137                                                          G_PARAM_READWRITE));
138   
139   g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
140 }
141
142 static void
143 gtk_separator_tool_item_init (GtkSeparatorToolItem      *separator_item,
144                               GtkSeparatorToolItemClass *class)
145 {
146   separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
147   separator_item->priv->draw = TRUE;
148 }
149
150 static void
151 gtk_separator_tool_item_add (GtkContainer *container,
152                              GtkWidget    *child)
153 {
154   g_warning ("attempt to add a child to an GtkSeparatorToolItem");
155 }
156
157 static gboolean
158 gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
159 {
160   GtkWidget *menu_item = NULL;
161   
162   menu_item = gtk_separator_menu_item_new();
163   
164   gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
165   
166   return TRUE;
167 }
168
169 static void
170 gtk_separator_tool_item_set_property (GObject      *object,
171                                       guint         prop_id,
172                                       const GValue *value,
173                                       GParamSpec   *pspec)
174 {
175   GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
176   
177   switch (prop_id)
178     {
179     case PROP_DRAW:
180       gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
181       break;
182     default:
183       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
184       break;
185     }
186 }
187
188 static void
189 gtk_separator_tool_item_get_property (GObject      *object,
190                                       guint         prop_id,
191                                       GValue       *value,
192                                       GParamSpec   *pspec)
193 {
194   GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
195   
196   switch (prop_id)
197     {
198     case PROP_DRAW:
199       g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
200       break;
201     default:
202       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
203       break;
204     }
205 }
206
207 static void
208 gtk_separator_tool_item_size_request (GtkWidget      *widget,
209                                       GtkRequisition *requisition)
210 {
211   GtkToolItem *item = GTK_TOOL_ITEM (widget);
212   GtkOrientation orientation = gtk_tool_item_get_orientation (item);
213   
214   if (orientation == GTK_ORIENTATION_HORIZONTAL)
215     {
216       requisition->width = get_space_size (item);
217       requisition->height = 1;
218     }
219   else
220     {
221       requisition->height = get_space_size (item);
222       requisition->width = 1;
223     }
224 }
225
226 static gboolean
227 gtk_separator_tool_item_expose (GtkWidget      *widget,
228                                 GdkEventExpose *event)
229 {
230   GtkToolbar *toolbar = NULL;
231
232   if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
233     toolbar = GTK_TOOLBAR (widget->parent);
234
235   _gtk_toolbar_paint_space_line (widget, toolbar,
236                                  &(event->area), &widget->allocation);
237   
238   return FALSE;
239 }
240
241 /**
242  * gtk_separator_tool_item_new:
243  * 
244  * Create a new #GtkSeparatorToolItem
245  * 
246  * Return value: the new #GtkSeparatorToolItem
247  * 
248  * Since: 2.4
249  **/
250 GtkToolItem *
251 gtk_separator_tool_item_new (void)
252 {
253   GtkToolItem *self;
254   
255   self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
256                        NULL);
257   
258   return self;
259 }
260
261 /**
262  * gtk_separator_tool_item_get_draw:
263  * @item: a #GtkSeparatorToolItem 
264  * 
265  * Returns whether @separator_tool_item is drawn as a
266  * line, or just blank. See gtk_separator_tool_item_set_draw().
267  * 
268  * Return value: #TRUE if @separator_tool_item is drawn as a line, or just blank.
269  * 
270  * Since: 2.4
271  **/
272 gboolean
273 gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
274 {
275   g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
276   
277   return item->priv->draw;
278 }
279
280 /**
281  * gtk_separator_tool_item_set_draw:
282  * @item: a #GtkSeparatorToolItem
283  * @draw: whether @separator_tool_item is drawn as a vertical iln
284  * 
285  * When @separator_tool_items is drawn as a vertical line, or just blank.
286  * Setting this #FALSE along with gtk_tool_item_set_expand() is useful
287  * to create an item that forces following items to the end of the toolbar.
288  * 
289  * Since: 2.4
290  **/
291 void
292 gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
293                                   gboolean              draw)
294 {
295   g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
296
297   draw = draw != FALSE;
298
299   if (draw != item->priv->draw)
300     {
301       item->priv->draw = draw;
302
303       gtk_widget_queue_draw (GTK_WIDGET (item));
304
305       g_object_notify (G_OBJECT (item), "draw");
306     }
307 }
308