]> Pileus Git - ~andy/gtk/blob - gtk/gtkseparator.c
Make orientable base classes instantiable
[~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 #include "gtkalias.h"
34
35
36 /**
37  * SECTION:gtkseparator
38  * @Short_description: Base class for #GtkHSeparator and #GtkVSeparator
39  * @Title: GtkSeparator
40  *
41  * The #GtkSeparator widget is an abstract class, used only for deriving the
42  * subclasses #GtkHSeparator and #GtkVSeparator.
43  */
44
45
46 enum {
47   PROP_0,
48   PROP_ORIENTATION
49 };
50
51
52 typedef struct _GtkSeparatorPrivate GtkSeparatorPrivate;
53
54 struct _GtkSeparatorPrivate
55 {
56   GtkOrientation orientation;
57 };
58
59 #define GTK_SEPARATOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR, GtkSeparatorPrivate))
60
61
62 static void       gtk_separator_set_property (GObject        *object,
63                                               guint           prop_id,
64                                               const GValue   *value,
65                                               GParamSpec     *pspec);
66 static void       gtk_separator_get_property (GObject        *object,
67                                               guint           prop_id,
68                                               GValue         *value,
69                                               GParamSpec     *pspec);
70
71 static void       gtk_separator_size_request (GtkWidget      *widget,
72                                               GtkRequisition *requisition);
73 static gboolean   gtk_separator_expose       (GtkWidget      *widget,
74                                               GdkEventExpose *event);
75
76
77 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
78                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
79                                                 NULL))
80
81
82 static void
83 gtk_separator_class_init (GtkSeparatorClass *class)
84 {
85   GObjectClass *object_class = G_OBJECT_CLASS (class);
86   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
87
88   object_class->set_property = gtk_separator_set_property;
89   object_class->get_property = gtk_separator_get_property;
90
91   widget_class->size_request = gtk_separator_size_request;
92   widget_class->expose_event = gtk_separator_expose;
93
94   g_object_class_override_property (object_class,
95                                     PROP_ORIENTATION,
96                                     "orientation");
97
98   g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
99 }
100
101 static void
102 gtk_separator_init (GtkSeparator *separator)
103 {
104   GtkWidget *widget = GTK_WIDGET (separator);
105   GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (separator);
106
107   gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
108
109   private->orientation = GTK_ORIENTATION_HORIZONTAL;
110
111   widget->requisition.width  = 1;
112   widget->requisition.height = widget->style->ythickness;
113 }
114
115 static void
116 gtk_separator_set_property (GObject      *object,
117                             guint         prop_id,
118                             const GValue *value,
119                             GParamSpec   *pspec)
120 {
121   GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
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   GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
142
143   switch (prop_id)
144     {
145     case PROP_ORIENTATION:
146       g_value_set_enum (value, private->orientation);
147       break;
148     default:
149       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
150       break;
151     }
152 }
153
154 static void
155 gtk_separator_size_request (GtkWidget      *widget,
156                             GtkRequisition *requisition)
157 {
158   GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
159   gboolean wide_separators;
160   gint     separator_width;
161   gint     separator_height;
162
163   gtk_widget_style_get (widget,
164                         "wide-separators",  &wide_separators,
165                         "separator-width",  &separator_width,
166                         "separator-height", &separator_height,
167                         NULL);
168
169   requisition->width  = 1;
170   requisition->height = 1;
171
172   if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
173     {
174       if (wide_separators)
175         requisition->height = separator_height;
176       else
177         requisition->height = widget->style->ythickness;
178     }
179   else
180     {
181       if (wide_separators)
182         requisition->width = separator_width;
183       else
184         requisition->width = widget->style->xthickness;
185     }
186 }
187
188 static gboolean
189 gtk_separator_expose (GtkWidget      *widget,
190                       GdkEventExpose *event)
191 {
192   GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
193   gboolean wide_separators;
194   gint     separator_width;
195   gint     separator_height;
196
197   if (!gtk_widget_is_drawable (widget))
198     return FALSE;
199
200   gtk_widget_style_get (widget,
201                         "wide-separators",  &wide_separators,
202                         "separator-width",  &separator_width,
203                         "separator-height", &separator_height,
204                         NULL);
205
206   if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
207     {
208       if (wide_separators)
209         gtk_paint_box (widget->style, widget->window,
210                        gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
211                        &event->area, widget, "hseparator",
212                        widget->allocation.x,
213                        widget->allocation.y + (widget->allocation.height -
214                                                separator_height) / 2,
215                        widget->allocation.width,
216                        separator_height);
217       else
218         gtk_paint_hline (widget->style, widget->window,
219                          gtk_widget_get_state (widget),
220                          &event->area, widget, "hseparator",
221                          widget->allocation.x,
222                          widget->allocation.x + widget->allocation.width - 1,
223                          widget->allocation.y + (widget->allocation.height -
224                                                  widget->style->ythickness) / 2);
225     }
226   else
227     {
228       if (wide_separators)
229         gtk_paint_box (widget->style, widget->window,
230                        gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
231                        &event->area, widget, "vseparator",
232                        widget->allocation.x + (widget->allocation.width -
233                                                separator_width) / 2,
234                        widget->allocation.y,
235                        separator_width,
236                        widget->allocation.height);
237       else
238         gtk_paint_vline (widget->style, widget->window,
239                          gtk_widget_get_state (widget),
240                          &event->area, widget, "vseparator",
241                          widget->allocation.y,
242                          widget->allocation.y + widget->allocation.height - 1,
243                          widget->allocation.x + (widget->allocation.width -
244                                                  widget->style->xthickness) / 2);
245     }
246
247   return FALSE;
248 }
249
250 /**
251  * gtk_separator_new:
252  * @orientation: the separator's orientation.
253  *
254  * Creates a new #GtkSeparator with the given orientation.
255  *
256  * Return value: a new #GtkSeparator.
257  *
258  * Since: 3.0
259  **/
260 GtkWidget *
261 gtk_separator_new (GtkOrientation orientation)
262 {
263   return g_object_new (GTK_TYPE_SEPARATOR,
264                        "orientation", orientation,
265                        NULL);
266 }
267
268
269 #define __GTK_SEPARATOR_C__
270 #include "gtkaliasdef.c"