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