1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
29 #include "gtkorientable.h"
30 #include "gtkseparator.h"
31 #include "gtkprivate.h"
37 * SECTION:gtkseparator
38 * @Short_description: Base class for #GtkHSeparator and #GtkVSeparator
39 * @Title: GtkSeparator
41 * The #GtkSeparator widget is an abstract class, used only for deriving the
42 * subclasses #GtkHSeparator and #GtkVSeparator.
52 typedef struct _GtkSeparatorPrivate GtkSeparatorPrivate;
54 struct _GtkSeparatorPrivate
56 GtkOrientation orientation;
59 #define GTK_SEPARATOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR, GtkSeparatorPrivate))
62 static void gtk_separator_set_property (GObject *object,
66 static void gtk_separator_get_property (GObject *object,
71 static void gtk_separator_size_request (GtkWidget *widget,
72 GtkRequisition *requisition);
73 static gboolean gtk_separator_expose (GtkWidget *widget,
74 GdkEventExpose *event);
77 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
78 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
83 gtk_separator_class_init (GtkSeparatorClass *class)
85 GObjectClass *object_class = G_OBJECT_CLASS (class);
86 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
88 object_class->set_property = gtk_separator_set_property;
89 object_class->get_property = gtk_separator_get_property;
91 widget_class->size_request = gtk_separator_size_request;
92 widget_class->expose_event = gtk_separator_expose;
94 g_object_class_override_property (object_class,
98 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
102 gtk_separator_init (GtkSeparator *separator)
104 GtkWidget *widget = GTK_WIDGET (separator);
105 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (separator);
107 gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
109 private->orientation = GTK_ORIENTATION_HORIZONTAL;
111 widget->requisition.width = 1;
112 widget->requisition.height = widget->style->ythickness;
116 gtk_separator_set_property (GObject *object,
121 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
125 case PROP_ORIENTATION:
126 private->orientation = g_value_get_enum (value);
127 gtk_widget_queue_resize (GTK_WIDGET (object));
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 gtk_separator_get_property (GObject *object,
141 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
145 case PROP_ORIENTATION:
146 g_value_set_enum (value, private->orientation);
149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
155 gtk_separator_size_request (GtkWidget *widget,
156 GtkRequisition *requisition)
158 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
159 gboolean wide_separators;
160 gint separator_width;
161 gint separator_height;
163 gtk_widget_style_get (widget,
164 "wide-separators", &wide_separators,
165 "separator-width", &separator_width,
166 "separator-height", &separator_height,
169 requisition->width = 1;
170 requisition->height = 1;
172 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
175 requisition->height = separator_height;
177 requisition->height = widget->style->ythickness;
182 requisition->width = separator_width;
184 requisition->width = widget->style->xthickness;
189 gtk_separator_expose (GtkWidget *widget,
190 GdkEventExpose *event)
192 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
193 gboolean wide_separators;
194 gint separator_width;
195 gint separator_height;
197 if (!gtk_widget_is_drawable (widget))
200 gtk_widget_style_get (widget,
201 "wide-separators", &wide_separators,
202 "separator-width", &separator_width,
203 "separator-height", &separator_height,
206 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
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,
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);
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,
236 widget->allocation.height);
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);
252 * @orientation: the separator's orientation.
254 * Creates a new #GtkSeparator with the given orientation.
256 * Return value: a new #GtkSeparator.
261 gtk_separator_new (GtkOrientation orientation)
263 return g_object_new (GTK_TYPE_SEPARATOR,
264 "orientation", orientation,
269 #define __GTK_SEPARATOR_C__
270 #include "gtkaliasdef.c"