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/.
27 #include "gtkcontainer.h"
40 static void gtk_misc_class_init (GtkMiscClass *klass);
41 static void gtk_misc_init (GtkMisc *misc);
42 static void gtk_misc_realize (GtkWidget *widget);
43 static void gtk_misc_set_property (GObject *object,
47 static void gtk_misc_get_property (GObject *object,
54 gtk_misc_get_type (void)
56 static GType misc_type = 0;
60 static const GTypeInfo misc_info =
62 sizeof (GtkMiscClass),
64 NULL, /* base_finalize */
65 (GClassInitFunc) gtk_misc_class_init,
66 NULL, /* class_finalize */
67 NULL, /* class_data */
70 (GInstanceInitFunc) gtk_misc_init,
71 NULL, /* value_table */
74 misc_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkMisc",
75 &misc_info, G_TYPE_FLAG_ABSTRACT);
82 gtk_misc_class_init (GtkMiscClass *class)
84 GObjectClass *gobject_class;
85 GtkWidgetClass *widget_class;
87 gobject_class = G_OBJECT_CLASS (class);
88 widget_class = (GtkWidgetClass*) class;
90 gobject_class->set_property = gtk_misc_set_property;
91 gobject_class->get_property = gtk_misc_get_property;
93 widget_class->realize = gtk_misc_realize;
95 g_object_class_install_property (gobject_class,
97 g_param_spec_float ("xalign",
99 _("The horizontal alignment, from 0 (left) to 1 (right)"),
105 g_object_class_install_property (gobject_class,
107 g_param_spec_float ("yalign",
109 _("The vertical alignment, from 0 (top) to 1 (bottom)"),
115 g_object_class_install_property (gobject_class,
117 g_param_spec_int ("xpad",
119 _("The amount of space to add on the left and right of the widget, in pixels"),
125 g_object_class_install_property (gobject_class,
127 g_param_spec_int ("ypad",
129 _("The amount of space to add on the top and bottom of the widget, in pixels"),
137 gtk_misc_init (GtkMisc *misc)
146 gtk_misc_set_property (GObject *object,
153 misc = GTK_MISC (object);
158 gtk_misc_set_alignment (misc, g_value_get_float (value), misc->yalign);
161 gtk_misc_set_alignment (misc, misc->xalign, g_value_get_float (value));
164 gtk_misc_set_padding (misc, g_value_get_int (value), misc->ypad);
167 gtk_misc_set_padding (misc, misc->xpad, g_value_get_int (value));
170 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
176 gtk_misc_get_property (GObject *object,
183 misc = GTK_MISC (object);
188 g_value_set_float (value, misc->xalign);
191 g_value_set_float (value, misc->yalign);
194 g_value_set_int (value, misc->xpad);
197 g_value_set_int (value, misc->ypad);
200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
206 gtk_misc_set_alignment (GtkMisc *misc,
210 g_return_if_fail (GTK_IS_MISC (misc));
214 else if (xalign > 1.0)
219 else if (yalign > 1.0)
222 if ((xalign != misc->xalign) || (yalign != misc->yalign))
224 misc->xalign = xalign;
225 misc->yalign = yalign;
227 /* clear the area that was allocated before the change
229 if (GTK_WIDGET_DRAWABLE (misc))
233 widget = GTK_WIDGET (misc);
234 gtk_widget_queue_draw (widget);
237 g_object_freeze_notify (G_OBJECT (misc));
238 if (xalign != misc->xalign)
239 g_object_notify (G_OBJECT (misc), "xalign");
241 if (yalign != misc->yalign)
242 g_object_notify (G_OBJECT (misc), "yalign");
243 g_object_thaw_notify (G_OBJECT (misc));
248 * gtk_misc_get_alignment:
250 * @xalign: location to store X alignment of @misc, or %NULL
251 * @yalign: location to store Y alignment of @misc, or %NULL
253 * Gets the X and Y alignment of the widget within its allocation. See
254 * gtk_misc_set_alignment().
257 gtk_misc_get_alignment (GtkMisc *misc,
261 g_return_if_fail (GTK_IS_MISC (misc));
264 *xalign = misc->xalign;
266 *yalign = misc->yalign;
270 gtk_misc_set_padding (GtkMisc *misc,
274 GtkRequisition *requisition;
276 g_return_if_fail (GTK_IS_MISC (misc));
283 if ((xpad != misc->xpad) || (ypad != misc->ypad))
285 requisition = &(GTK_WIDGET (misc)->requisition);
286 requisition->width -= misc->xpad * 2;
287 requisition->height -= misc->ypad * 2;
292 requisition->width += misc->xpad * 2;
293 requisition->height += misc->ypad * 2;
295 if (GTK_WIDGET_DRAWABLE (misc))
296 gtk_widget_queue_resize (GTK_WIDGET (misc));
298 g_object_freeze_notify (G_OBJECT (misc));
299 if (xpad != misc->xpad)
300 g_object_notify (G_OBJECT (misc), "xpad");
302 if (ypad != misc->ypad)
303 g_object_notify (G_OBJECT (misc), "ypad");
304 g_object_thaw_notify (G_OBJECT (misc));
309 * gtk_misc_get_padding:
311 * @xpad: location to store padding in the X direction, or %NULL
312 * @ypad: location to store padding in the Y direction, or %NULL
314 * Gets the padding in the X and Y directions of the widget. See gtk_misc_set_padding().
317 gtk_misc_get_padding (GtkMisc *misc,
321 g_return_if_fail (GTK_IS_MISC (misc));
330 gtk_misc_realize (GtkWidget *widget)
333 GdkWindowAttr attributes;
334 gint attributes_mask;
336 g_return_if_fail (GTK_IS_MISC (widget));
338 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
339 misc = GTK_MISC (widget);
341 if (GTK_WIDGET_NO_WINDOW (widget))
343 widget->window = gtk_widget_get_parent_window (widget);
344 g_object_ref (widget->window);
345 widget->style = gtk_style_attach (widget->style, widget->window);
349 attributes.window_type = GDK_WINDOW_CHILD;
350 attributes.x = widget->allocation.x;
351 attributes.y = widget->allocation.y;
352 attributes.width = widget->allocation.width;
353 attributes.height = widget->allocation.height;
354 attributes.wclass = GDK_INPUT_OUTPUT;
355 attributes.visual = gtk_widget_get_visual (widget);
356 attributes.colormap = gtk_widget_get_colormap (widget);
357 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
358 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
360 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
361 gdk_window_set_user_data (widget->window, widget);
363 widget->style = gtk_style_attach (widget->style, widget->window);
364 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);