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