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"
41 static void gtk_misc_class_init (GtkMiscClass *klass);
42 static void gtk_misc_init (GtkMisc *misc);
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,
55 gtk_misc_get_type (void)
57 static GType misc_type = 0;
61 static const GTypeInfo misc_info =
63 sizeof (GtkMiscClass),
65 NULL, /* base_finalize */
66 (GClassInitFunc) gtk_misc_class_init,
67 NULL, /* class_finalize */
68 NULL, /* class_data */
71 (GInstanceInitFunc) gtk_misc_init,
72 NULL, /* value_table */
75 misc_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkMisc",
76 &misc_info, G_TYPE_FLAG_ABSTRACT);
83 gtk_misc_class_init (GtkMiscClass *class)
85 GObjectClass *gobject_class;
86 GtkWidgetClass *widget_class;
88 gobject_class = G_OBJECT_CLASS (class);
89 widget_class = (GtkWidgetClass*) class;
91 gobject_class->set_property = gtk_misc_set_property;
92 gobject_class->get_property = gtk_misc_get_property;
94 widget_class->realize = gtk_misc_realize;
96 g_object_class_install_property (gobject_class,
98 g_param_spec_float ("xalign",
100 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts"),
106 g_object_class_install_property (gobject_class,
108 g_param_spec_float ("yalign",
110 P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
116 g_object_class_install_property (gobject_class,
118 g_param_spec_int ("xpad",
120 P_("The amount of space to add on the left and right of the widget, in pixels"),
126 g_object_class_install_property (gobject_class,
128 g_param_spec_int ("ypad",
130 P_("The amount of space to add on the top and bottom of the widget, in pixels"),
138 gtk_misc_init (GtkMisc *misc)
147 gtk_misc_set_property (GObject *object,
154 misc = GTK_MISC (object);
159 gtk_misc_set_alignment (misc, g_value_get_float (value), misc->yalign);
162 gtk_misc_set_alignment (misc, misc->xalign, g_value_get_float (value));
165 gtk_misc_set_padding (misc, g_value_get_int (value), misc->ypad);
168 gtk_misc_set_padding (misc, misc->xpad, g_value_get_int (value));
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
177 gtk_misc_get_property (GObject *object,
184 misc = GTK_MISC (object);
189 g_value_set_float (value, misc->xalign);
192 g_value_set_float (value, misc->yalign);
195 g_value_set_int (value, misc->xpad);
198 g_value_set_int (value, misc->ypad);
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
207 gtk_misc_set_alignment (GtkMisc *misc,
211 g_return_if_fail (GTK_IS_MISC (misc));
215 else if (xalign > 1.0)
220 else if (yalign > 1.0)
223 if ((xalign != misc->xalign) || (yalign != misc->yalign))
225 misc->xalign = xalign;
226 misc->yalign = yalign;
228 /* clear the area that was allocated before the change
230 if (GTK_WIDGET_DRAWABLE (misc))
234 widget = GTK_WIDGET (misc);
235 gtk_widget_queue_draw (widget);
238 g_object_freeze_notify (G_OBJECT (misc));
239 if (xalign != misc->xalign)
240 g_object_notify (G_OBJECT (misc), "xalign");
242 if (yalign != misc->yalign)
243 g_object_notify (G_OBJECT (misc), "yalign");
244 g_object_thaw_notify (G_OBJECT (misc));
249 * gtk_misc_get_alignment:
251 * @xalign: location to store X alignment of @misc, or %NULL
252 * @yalign: location to store Y alignment of @misc, or %NULL
254 * Gets the X and Y alignment of the widget within its allocation. See
255 * gtk_misc_set_alignment().
258 gtk_misc_get_alignment (GtkMisc *misc,
262 g_return_if_fail (GTK_IS_MISC (misc));
265 *xalign = misc->xalign;
267 *yalign = misc->yalign;
271 gtk_misc_set_padding (GtkMisc *misc,
275 GtkRequisition *requisition;
277 g_return_if_fail (GTK_IS_MISC (misc));
284 if ((xpad != misc->xpad) || (ypad != misc->ypad))
286 requisition = &(GTK_WIDGET (misc)->requisition);
287 requisition->width -= misc->xpad * 2;
288 requisition->height -= misc->ypad * 2;
293 requisition->width += misc->xpad * 2;
294 requisition->height += misc->ypad * 2;
296 if (GTK_WIDGET_DRAWABLE (misc))
297 gtk_widget_queue_resize (GTK_WIDGET (misc));
299 g_object_freeze_notify (G_OBJECT (misc));
300 if (xpad != misc->xpad)
301 g_object_notify (G_OBJECT (misc), "xpad");
303 if (ypad != misc->ypad)
304 g_object_notify (G_OBJECT (misc), "ypad");
305 g_object_thaw_notify (G_OBJECT (misc));
310 * gtk_misc_get_padding:
312 * @xpad: location to store padding in the X direction, or %NULL
313 * @ypad: location to store padding in the Y direction, or %NULL
315 * Gets the padding in the X and Y directions of the widget. See gtk_misc_set_padding().
318 gtk_misc_get_padding (GtkMisc *misc,
322 g_return_if_fail (GTK_IS_MISC (misc));
331 gtk_misc_realize (GtkWidget *widget)
334 GdkWindowAttr attributes;
335 gint attributes_mask;
337 g_return_if_fail (GTK_IS_MISC (widget));
339 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
340 misc = GTK_MISC (widget);
342 if (GTK_WIDGET_NO_WINDOW (widget))
344 widget->window = gtk_widget_get_parent_window (widget);
345 g_object_ref (widget->window);
346 widget->style = gtk_style_attach (widget->style, widget->window);
350 attributes.window_type = GDK_WINDOW_CHILD;
351 attributes.x = widget->allocation.x;
352 attributes.y = widget->allocation.y;
353 attributes.width = widget->allocation.width;
354 attributes.height = widget->allocation.height;
355 attributes.wclass = GDK_INPUT_OUTPUT;
356 attributes.visual = gtk_widget_get_visual (widget);
357 attributes.colormap = gtk_widget_get_colormap (widget);
358 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
359 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
361 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
362 gdk_window_set_user_data (widget->window, widget);
364 widget->style = gtk_style_attach (widget->style, widget->window);
365 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);