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