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/.
28 #include "gtkcontainer.h"
31 #include "gtkprivate.h"
43 static void gtk_misc_realize (GtkWidget *widget);
44 static void gtk_misc_set_property (GObject *object,
48 static void gtk_misc_get_property (GObject *object,
54 G_DEFINE_ABSTRACT_TYPE (GtkMisc, gtk_misc, GTK_TYPE_WIDGET)
57 gtk_misc_class_init (GtkMiscClass *class)
59 GObjectClass *gobject_class;
60 GtkWidgetClass *widget_class;
62 gobject_class = G_OBJECT_CLASS (class);
63 widget_class = (GtkWidgetClass*) class;
65 gobject_class->set_property = gtk_misc_set_property;
66 gobject_class->get_property = gtk_misc_get_property;
68 widget_class->realize = gtk_misc_realize;
70 g_object_class_install_property (gobject_class,
72 g_param_spec_float ("xalign",
74 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
78 GTK_PARAM_READWRITE));
80 g_object_class_install_property (gobject_class,
82 g_param_spec_float ("yalign",
84 P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
88 GTK_PARAM_READWRITE));
90 g_object_class_install_property (gobject_class,
92 g_param_spec_int ("xpad",
94 P_("The amount of space to add on the left and right of the widget, in pixels"),
98 GTK_PARAM_READWRITE));
100 g_object_class_install_property (gobject_class,
102 g_param_spec_int ("ypad",
104 P_("The amount of space to add on the top and bottom of the widget, in pixels"),
108 GTK_PARAM_READWRITE));
112 gtk_misc_init (GtkMisc *misc)
121 gtk_misc_set_property (GObject *object,
128 misc = GTK_MISC (object);
133 gtk_misc_set_alignment (misc, g_value_get_float (value), misc->yalign);
136 gtk_misc_set_alignment (misc, misc->xalign, g_value_get_float (value));
139 gtk_misc_set_padding (misc, g_value_get_int (value), misc->ypad);
142 gtk_misc_set_padding (misc, misc->xpad, g_value_get_int (value));
145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
151 gtk_misc_get_property (GObject *object,
158 misc = GTK_MISC (object);
163 g_value_set_float (value, misc->xalign);
166 g_value_set_float (value, misc->yalign);
169 g_value_set_int (value, misc->xpad);
172 g_value_set_int (value, misc->ypad);
175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
181 gtk_misc_set_alignment (GtkMisc *misc,
185 g_return_if_fail (GTK_IS_MISC (misc));
189 else if (xalign > 1.0)
194 else if (yalign > 1.0)
197 if ((xalign != misc->xalign) || (yalign != misc->yalign))
199 g_object_freeze_notify (G_OBJECT (misc));
200 if (xalign != misc->xalign)
201 g_object_notify (G_OBJECT (misc), "xalign");
203 if (yalign != misc->yalign)
204 g_object_notify (G_OBJECT (misc), "yalign");
206 misc->xalign = xalign;
207 misc->yalign = yalign;
209 /* clear the area that was allocated before the change
211 if (GTK_WIDGET_DRAWABLE (misc))
215 widget = GTK_WIDGET (misc);
216 gtk_widget_queue_draw (widget);
219 g_object_thaw_notify (G_OBJECT (misc));
224 * gtk_misc_get_alignment:
226 * @xalign: location to store X alignment of @misc, or %NULL
227 * @yalign: location to store Y alignment of @misc, or %NULL
229 * Gets the X and Y alignment of the widget within its allocation.
230 * See gtk_misc_set_alignment().
233 gtk_misc_get_alignment (GtkMisc *misc,
237 g_return_if_fail (GTK_IS_MISC (misc));
240 *xalign = misc->xalign;
242 *yalign = misc->yalign;
246 gtk_misc_set_padding (GtkMisc *misc,
250 GtkRequisition *requisition;
252 g_return_if_fail (GTK_IS_MISC (misc));
259 if ((xpad != misc->xpad) || (ypad != misc->ypad))
261 g_object_freeze_notify (G_OBJECT (misc));
262 if (xpad != misc->xpad)
263 g_object_notify (G_OBJECT (misc), "xpad");
265 if (ypad != misc->ypad)
266 g_object_notify (G_OBJECT (misc), "ypad");
268 requisition = &(GTK_WIDGET (misc)->requisition);
269 requisition->width -= misc->xpad * 2;
270 requisition->height -= misc->ypad * 2;
275 requisition->width += misc->xpad * 2;
276 requisition->height += misc->ypad * 2;
278 if (GTK_WIDGET_DRAWABLE (misc))
279 gtk_widget_queue_resize (GTK_WIDGET (misc));
281 g_object_thaw_notify (G_OBJECT (misc));
286 * gtk_misc_get_padding:
288 * @xpad: location to store padding in the X direction, or %NULL
289 * @ypad: location to store padding in the Y direction, or %NULL
291 * Gets the padding in the X and Y directions of the widget.
292 * See gtk_misc_set_padding().
295 gtk_misc_get_padding (GtkMisc *misc,
299 g_return_if_fail (GTK_IS_MISC (misc));
308 gtk_misc_realize (GtkWidget *widget)
310 GdkWindowAttr attributes;
311 gint attributes_mask;
313 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
315 if (GTK_WIDGET_NO_WINDOW (widget))
317 widget->window = gtk_widget_get_parent_window (widget);
318 g_object_ref (widget->window);
319 widget->style = gtk_style_attach (widget->style, widget->window);
323 attributes.window_type = GDK_WINDOW_CHILD;
324 attributes.x = widget->allocation.x;
325 attributes.y = widget->allocation.y;
326 attributes.width = widget->allocation.width;
327 attributes.height = widget->allocation.height;
328 attributes.wclass = GDK_INPUT_OUTPUT;
329 attributes.visual = gtk_widget_get_visual (widget);
330 attributes.colormap = gtk_widget_get_colormap (widget);
331 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
332 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
334 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
335 gdk_window_set_user_data (widget->window, widget);
337 widget->style = gtk_style_attach (widget->style, widget->window);
338 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
342 #define __GTK_MISC_C__
343 #include "gtkaliasdef.c"