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