]> Pileus Git - ~andy/gtk/blob - gtk/gtkseparator.c
Remove a workaround for old toolbar api
[~andy/gtk] / gtk / gtkseparator.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #include "config.h"
28
29 #include "gtkorientable.h"
30 #include "gtkseparator.h"
31 #include "gtkprivate.h"
32 #include "gtkintl.h"
33
34 /**
35  * SECTION:gtkseparator
36  * @Short_description: Base class for GtkHSeparator and GtkVSeparator
37  * @Title: GtkSeparator
38  *
39  * The GtkSeparator widget is the base class for #GtkHSeparator and
40  * #GtkVSeparator. It can be used in the same way as these, by setting
41  * the "orientation" property suitably.
42  */
43
44
45 struct _GtkSeparatorPrivate
46 {
47   GtkOrientation orientation;
48 };
49
50
51 enum {
52   PROP_0,
53   PROP_ORIENTATION
54 };
55
56 static void       gtk_separator_set_property (GObject        *object,
57                                               guint           prop_id,
58                                               const GValue   *value,
59                                               GParamSpec     *pspec);
60 static void       gtk_separator_get_property (GObject        *object,
61                                               guint           prop_id,
62                                               GValue         *value,
63                                               GParamSpec     *pspec);
64
65 static void       gtk_separator_size_request (GtkWidget      *widget,
66                                               GtkRequisition *requisition);
67 static gboolean   gtk_separator_expose       (GtkWidget      *widget,
68                                               GdkEventExpose *event);
69
70
71 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
72                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
73                                                 NULL))
74
75
76 static void
77 gtk_separator_class_init (GtkSeparatorClass *class)
78 {
79   GObjectClass *object_class = G_OBJECT_CLASS (class);
80   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
81
82   object_class->set_property = gtk_separator_set_property;
83   object_class->get_property = gtk_separator_get_property;
84
85   widget_class->size_request = gtk_separator_size_request;
86   widget_class->expose_event = gtk_separator_expose;
87
88   g_object_class_override_property (object_class,
89                                     PROP_ORIENTATION,
90                                     "orientation");
91
92   g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
93 }
94
95 static void
96 gtk_separator_init (GtkSeparator *separator)
97 {
98   GtkWidget *widget = GTK_WIDGET (separator);
99   GtkSeparatorPrivate *private;
100
101   separator->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator,
102                                                  GTK_TYPE_SEPARATOR,
103                                                  GtkSeparatorPrivate);
104   private = separator->priv;
105
106   gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
107
108   private->orientation = GTK_ORIENTATION_HORIZONTAL;
109
110   widget->requisition.width  = 1;
111   widget->requisition.height = widget->style->ythickness;
112 }
113
114 static void
115 gtk_separator_set_property (GObject      *object,
116                             guint         prop_id,
117                             const GValue *value,
118                             GParamSpec   *pspec)
119 {
120   GtkSeparator *separator = GTK_SEPARATOR (object);
121   GtkSeparatorPrivate *private = separator->priv;
122
123   switch (prop_id)
124     {
125     case PROP_ORIENTATION:
126       private->orientation = g_value_get_enum (value);
127       gtk_widget_queue_resize (GTK_WIDGET (object));
128       break;
129     default:
130       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
131       break;
132     }
133 }
134
135 static void
136 gtk_separator_get_property (GObject    *object,
137                             guint       prop_id,
138                             GValue     *value,
139                             GParamSpec *pspec)
140 {
141   GtkSeparator *separator = GTK_SEPARATOR (object);
142   GtkSeparatorPrivate *private = separator->priv;
143
144   switch (prop_id)
145     {
146     case PROP_ORIENTATION:
147       g_value_set_enum (value, private->orientation);
148       break;
149     default:
150       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
151       break;
152     }
153 }
154
155 static void
156 gtk_separator_size_request (GtkWidget      *widget,
157                             GtkRequisition *requisition)
158 {
159   GtkSeparator *separator = GTK_SEPARATOR (widget);
160   GtkSeparatorPrivate *private = separator->priv;
161   gboolean wide_separators;
162   gint     separator_width;
163   gint     separator_height;
164
165   gtk_widget_style_get (widget,
166                         "wide-separators",  &wide_separators,
167                         "separator-width",  &separator_width,
168                         "separator-height", &separator_height,
169                         NULL);
170
171   requisition->width  = 1;
172   requisition->height = 1;
173
174   if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
175     {
176       if (wide_separators)
177         requisition->height = separator_height;
178       else
179         requisition->height = widget->style->ythickness;
180     }
181   else
182     {
183       if (wide_separators)
184         requisition->width = separator_width;
185       else
186         requisition->width = widget->style->xthickness;
187     }
188 }
189
190 static gboolean
191 gtk_separator_expose (GtkWidget      *widget,
192                       GdkEventExpose *event)
193 {
194   GtkSeparator *separator = GTK_SEPARATOR (widget);
195   GtkSeparatorPrivate *private = separator->priv;
196   gboolean wide_separators;
197   gint     separator_width;
198   gint     separator_height;
199
200   if (!gtk_widget_is_drawable (widget))
201     return FALSE;
202
203   gtk_widget_style_get (widget,
204                         "wide-separators",  &wide_separators,
205                         "separator-width",  &separator_width,
206                         "separator-height", &separator_height,
207                         NULL);
208
209   if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
210     {
211       if (wide_separators)
212         gtk_paint_box (widget->style, widget->window,
213                        gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
214                        &event->area, widget, "hseparator",
215                        widget->allocation.x,
216                        widget->allocation.y + (widget->allocation.height -
217                                                separator_height) / 2,
218                        widget->allocation.width,
219                        separator_height);
220       else
221         gtk_paint_hline (widget->style, widget->window,
222                          gtk_widget_get_state (widget),
223                          &event->area, widget, "hseparator",
224                          widget->allocation.x,
225                          widget->allocation.x + widget->allocation.width - 1,
226                          widget->allocation.y + (widget->allocation.height -
227                                                  widget->style->ythickness) / 2);
228     }
229   else
230     {
231       if (wide_separators)
232         gtk_paint_box (widget->style, widget->window,
233                        gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
234                        &event->area, widget, "vseparator",
235                        widget->allocation.x + (widget->allocation.width -
236                                                separator_width) / 2,
237                        widget->allocation.y,
238                        separator_width,
239                        widget->allocation.height);
240       else
241         gtk_paint_vline (widget->style, widget->window,
242                          gtk_widget_get_state (widget),
243                          &event->area, widget, "vseparator",
244                          widget->allocation.y,
245                          widget->allocation.y + widget->allocation.height - 1,
246                          widget->allocation.x + (widget->allocation.width -
247                                                  widget->style->xthickness) / 2);
248     }
249
250   return FALSE;
251 }
252
253 /**
254  * gtk_separator_new:
255  * @orientation: the separator's orientation.
256  *
257  * Creates a new #GtkSeparator with the given orientation.
258  *
259  * Return value: a new #GtkSeparator.
260  *
261  * Since: 3.0
262  **/
263 GtkWidget *
264 gtk_separator_new (GtkOrientation orientation)
265 {
266   return g_object_new (GTK_TYPE_SEPARATOR,
267                        "orientation", orientation,
268                        NULL);
269 }