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