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"
34 struct _GtkMiscPrivate
51 static void gtk_misc_realize (GtkWidget *widget);
52 static void gtk_misc_set_property (GObject *object,
56 static void gtk_misc_get_property (GObject *object,
62 G_DEFINE_ABSTRACT_TYPE (GtkMisc, gtk_misc, GTK_TYPE_WIDGET)
65 gtk_misc_class_init (GtkMiscClass *class)
67 GObjectClass *gobject_class;
68 GtkWidgetClass *widget_class;
70 gobject_class = G_OBJECT_CLASS (class);
71 widget_class = (GtkWidgetClass*) class;
73 gobject_class->set_property = gtk_misc_set_property;
74 gobject_class->get_property = gtk_misc_get_property;
76 widget_class->realize = gtk_misc_realize;
78 g_object_class_install_property (gobject_class,
80 g_param_spec_float ("xalign",
82 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
86 GTK_PARAM_READWRITE));
88 g_object_class_install_property (gobject_class,
90 g_param_spec_float ("yalign",
92 P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
96 GTK_PARAM_READWRITE));
98 g_object_class_install_property (gobject_class,
100 g_param_spec_int ("xpad",
102 P_("The amount of space to add on the left and right of the widget, in pixels"),
106 GTK_PARAM_READWRITE));
108 g_object_class_install_property (gobject_class,
110 g_param_spec_int ("ypad",
112 P_("The amount of space to add on the top and bottom of the widget, in pixels"),
116 GTK_PARAM_READWRITE));
118 g_type_class_add_private (class, sizeof (GtkMiscPrivate));
122 gtk_misc_init (GtkMisc *misc)
124 GtkMiscPrivate *priv;
126 misc->priv = G_TYPE_INSTANCE_GET_PRIVATE (misc,
138 gtk_misc_set_property (GObject *object,
143 GtkMisc *misc = GTK_MISC (object);
144 GtkMiscPrivate *priv = misc->priv;
149 gtk_misc_set_alignment (misc, g_value_get_float (value), priv->yalign);
152 gtk_misc_set_alignment (misc, priv->xalign, g_value_get_float (value));
155 gtk_misc_set_padding (misc, g_value_get_int (value), priv->ypad);
158 gtk_misc_set_padding (misc, priv->xpad, g_value_get_int (value));
161 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
167 gtk_misc_get_property (GObject *object,
172 GtkMisc *misc = GTK_MISC (object);
173 GtkMiscPrivate *priv = misc->priv;
178 g_value_set_float (value, priv->xalign);
181 g_value_set_float (value, priv->yalign);
184 g_value_set_int (value, priv->xpad);
187 g_value_set_int (value, priv->ypad);
190 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
196 gtk_misc_set_alignment (GtkMisc *misc,
200 GtkMiscPrivate *priv;
203 g_return_if_fail (GTK_IS_MISC (misc));
209 else if (xalign > 1.0)
214 else if (yalign > 1.0)
217 if ((xalign != priv->xalign) || (yalign != priv->yalign))
219 g_object_freeze_notify (G_OBJECT (misc));
220 if (xalign != priv->xalign)
221 g_object_notify (G_OBJECT (misc), "xalign");
223 if (yalign != priv->yalign)
224 g_object_notify (G_OBJECT (misc), "yalign");
226 priv->xalign = xalign;
227 priv->yalign = yalign;
229 /* clear the area that was allocated before the change
231 widget = GTK_WIDGET (misc);
232 if (gtk_widget_is_drawable (widget))
233 gtk_widget_queue_draw (widget);
235 g_object_thaw_notify (G_OBJECT (misc));
240 * gtk_misc_get_alignment:
242 * @xalign: (allow-none): location to store X alignment of @misc, or %NULL
243 * @yalign: (allow-none): location to store Y alignment of @misc, or %NULL
245 * Gets the X and Y alignment of the widget within its allocation.
246 * See gtk_misc_set_alignment().
249 gtk_misc_get_alignment (GtkMisc *misc,
253 GtkMiscPrivate *priv;
255 g_return_if_fail (GTK_IS_MISC (misc));
260 *xalign = priv->xalign;
262 *yalign = priv->yalign;
266 gtk_misc_set_padding (GtkMisc *misc,
270 GtkMiscPrivate *priv;
272 g_return_if_fail (GTK_IS_MISC (misc));
281 if ((xpad != priv->xpad) || (ypad != priv->ypad))
283 g_object_freeze_notify (G_OBJECT (misc));
284 if (xpad != priv->xpad)
285 g_object_notify (G_OBJECT (misc), "xpad");
287 if (ypad != priv->ypad)
288 g_object_notify (G_OBJECT (misc), "ypad");
293 if (gtk_widget_is_drawable (GTK_WIDGET (misc)))
294 gtk_widget_queue_resize (GTK_WIDGET (misc));
296 g_object_thaw_notify (G_OBJECT (misc));
301 * gtk_misc_get_padding:
303 * @xpad: (allow-none): location to store padding in the X direction, or %NULL
304 * @ypad: (allow-none): location to store padding in the Y direction, or %NULL
306 * Gets the padding in the X and Y directions of the widget.
307 * See gtk_misc_set_padding().
310 gtk_misc_get_padding (GtkMisc *misc,
314 GtkMiscPrivate *priv;
316 g_return_if_fail (GTK_IS_MISC (misc));
327 gtk_misc_realize (GtkWidget *widget)
329 GtkAllocation allocation;
331 GdkWindowAttr attributes;
332 gint attributes_mask;
334 gtk_widget_set_realized (widget, TRUE);
336 if (!gtk_widget_get_has_window (widget))
338 window = gtk_widget_get_parent_window (widget);
339 gtk_widget_set_window (widget, window);
340 g_object_ref (window);
342 gtk_widget_style_attach (widget);
346 gtk_widget_get_allocation (widget, &allocation);
348 attributes.window_type = GDK_WINDOW_CHILD;
349 attributes.x = allocation.x;
350 attributes.y = allocation.y;
351 attributes.width = allocation.width;
352 attributes.height = allocation.height;
353 attributes.wclass = GDK_INPUT_OUTPUT;
354 attributes.visual = gtk_widget_get_visual (widget);
355 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
356 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
358 window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
359 gtk_widget_set_window (widget, window);
360 gdk_window_set_user_data (window, widget);
361 gdk_window_set_background_pattern (window, NULL);
363 gtk_widget_style_attach (widget);