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 GtkType misc_type = 0;
60 static const GtkTypeInfo misc_info =
64 sizeof (GtkMiscClass),
65 (GtkClassInitFunc) gtk_misc_class_init,
66 (GtkObjectInitFunc) gtk_misc_init,
67 /* reserved_1 */ NULL,
68 /* reserved_2 */ NULL,
69 (GtkClassInitFunc) NULL,
72 misc_type = gtk_type_unique (GTK_TYPE_WIDGET, &misc_info);
79 gtk_misc_class_init (GtkMiscClass *class)
81 GObjectClass *gobject_class;
82 GtkObjectClass *object_class;
83 GtkWidgetClass *widget_class;
85 gobject_class = G_OBJECT_CLASS (class);
86 object_class = (GtkObjectClass*) class;
87 widget_class = (GtkWidgetClass*) class;
89 gobject_class->set_property = gtk_misc_set_property;
90 gobject_class->get_property = gtk_misc_get_property;
92 widget_class->realize = gtk_misc_realize;
94 g_object_class_install_property (gobject_class,
96 g_param_spec_float ("xalign",
98 _("The horizontal alignment, from 0 (left) to 1 (right)"),
104 g_object_class_install_property (gobject_class,
106 g_param_spec_float ("yalign",
108 _("The vertical alignment, from 0 (top) to 1 (bottom)"),
114 g_object_class_install_property (gobject_class,
116 g_param_spec_int ("xpad",
118 _("The amount of space to add on the left and right of the widget, in pixels"),
124 g_object_class_install_property (gobject_class,
126 g_param_spec_int ("ypad",
128 _("The amount of space to add on the top and bottom of the widget, in pixels"),
136 gtk_misc_init (GtkMisc *misc)
145 gtk_misc_set_property (GObject *object,
152 misc = GTK_MISC (object);
157 gtk_misc_set_alignment (misc, g_value_get_float (value), misc->yalign);
160 gtk_misc_set_alignment (misc, misc->xalign, g_value_get_float (value));
163 gtk_misc_set_padding (misc, g_value_get_int (value), misc->ypad);
166 gtk_misc_set_padding (misc, misc->xpad, g_value_get_int (value));
169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
175 gtk_misc_get_property (GObject *object,
182 misc = GTK_MISC (object);
187 g_value_set_float (value, misc->xalign);
190 g_value_set_float (value, misc->yalign);
193 g_value_set_int (value, misc->xpad);
196 g_value_set_int (value, misc->ypad);
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205 gtk_misc_set_alignment (GtkMisc *misc,
209 g_return_if_fail (misc != NULL);
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_clear (widget);
237 if (xalign != misc->xalign)
238 g_object_notify (G_OBJECT (misc), "xalign");
240 if (yalign != misc->yalign)
241 g_object_notify (G_OBJECT (misc), "yalign");
246 * gtk_misc_get_alignment:
248 * @xalign: location to store X alignment of @misc, or %NULL
249 * @yalign: location to store Y alignment of @misc, or %NULL
251 * Gets the X and Y alignment of the widget within its allocation. See
252 * gtk_misc_set_alignment().
255 gtk_misc_get_alignment (GtkMisc *misc,
259 g_return_if_fail (GTK_IS_MISC (misc));
262 *xalign = misc->xalign;
264 *yalign = misc->yalign;
268 gtk_misc_set_padding (GtkMisc *misc,
272 GtkRequisition *requisition;
274 g_return_if_fail (misc != NULL);
275 g_return_if_fail (GTK_IS_MISC (misc));
282 if ((xpad != misc->xpad) || (ypad != misc->ypad))
284 requisition = &(GTK_WIDGET (misc)->requisition);
285 requisition->width -= misc->xpad * 2;
286 requisition->height -= misc->ypad * 2;
291 requisition->width += misc->xpad * 2;
292 requisition->height += misc->ypad * 2;
294 if (GTK_WIDGET_DRAWABLE (misc))
295 gtk_widget_queue_resize (GTK_WIDGET (misc));
297 if (xpad != misc->xpad)
298 g_object_notify (G_OBJECT (misc), "xpad");
300 if (ypad != misc->ypad)
301 g_object_notify (G_OBJECT (misc), "ypad");
306 * gtk_misc_get_padding:
308 * @xpad: location to store padding in the X direction, or %NULL
309 * @ypad: location to store padding in the Y direction, or %NULL
311 * Gets the padding in the X and Y directions of the widget. See gtk_misc_set_padding().
314 gtk_misc_get_padding (GtkMisc *misc,
318 g_return_if_fail (GTK_IS_MISC (misc));
327 gtk_misc_realize (GtkWidget *widget)
330 GdkWindowAttr attributes;
331 gint attributes_mask;
333 g_return_if_fail (widget != NULL);
334 g_return_if_fail (GTK_IS_MISC (widget));
336 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
337 misc = GTK_MISC (widget);
339 if (GTK_WIDGET_NO_WINDOW (widget))
341 widget->window = gtk_widget_get_parent_window (widget);
342 gdk_window_ref (widget->window);
343 widget->style = gtk_style_attach (widget->style, widget->window);
347 attributes.window_type = GDK_WINDOW_CHILD;
348 attributes.x = widget->allocation.x;
349 attributes.y = widget->allocation.y;
350 attributes.width = widget->allocation.width;
351 attributes.height = widget->allocation.height;
352 attributes.wclass = GDK_INPUT_OUTPUT;
353 attributes.visual = gtk_widget_get_visual (widget);
354 attributes.colormap = gtk_widget_get_colormap (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 | GDK_WA_COLORMAP;
358 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
359 gdk_window_set_user_data (widget->window, widget);
361 widget->style = gtk_style_attach (widget->style, widget->window);
362 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);