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