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"
42 static void gtk_misc_class_init (GtkMiscClass *klass);
43 static void gtk_misc_init (GtkMisc *misc);
44 static void gtk_misc_realize (GtkWidget *widget);
45 static void gtk_misc_set_property (GObject *object,
49 static void gtk_misc_get_property (GObject *object,
56 gtk_misc_get_type (void)
58 static GType misc_type = 0;
62 static const GTypeInfo misc_info =
64 sizeof (GtkMiscClass),
66 NULL, /* base_finalize */
67 (GClassInitFunc) gtk_misc_class_init,
68 NULL, /* class_finalize */
69 NULL, /* class_data */
72 (GInstanceInitFunc) gtk_misc_init,
73 NULL, /* value_table */
76 misc_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkMisc",
77 &misc_info, G_TYPE_FLAG_ABSTRACT);
84 gtk_misc_class_init (GtkMiscClass *class)
86 GObjectClass *gobject_class;
87 GtkWidgetClass *widget_class;
89 gobject_class = G_OBJECT_CLASS (class);
90 widget_class = (GtkWidgetClass*) class;
92 gobject_class->set_property = gtk_misc_set_property;
93 gobject_class->get_property = gtk_misc_get_property;
95 widget_class->realize = gtk_misc_realize;
97 g_object_class_install_property (gobject_class,
99 g_param_spec_float ("xalign",
101 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
107 g_object_class_install_property (gobject_class,
109 g_param_spec_float ("yalign",
111 P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
117 g_object_class_install_property (gobject_class,
119 g_param_spec_int ("xpad",
121 P_("The amount of space to add on the left and right of the widget, in pixels"),
127 g_object_class_install_property (gobject_class,
129 g_param_spec_int ("ypad",
131 P_("The amount of space to add on the top and bottom of the widget, in pixels"),
139 gtk_misc_init (GtkMisc *misc)
148 gtk_misc_set_property (GObject *object,
155 misc = GTK_MISC (object);
160 gtk_misc_set_alignment (misc, g_value_get_float (value), misc->yalign);
163 gtk_misc_set_alignment (misc, misc->xalign, g_value_get_float (value));
166 gtk_misc_set_padding (misc, g_value_get_int (value), misc->ypad);
169 gtk_misc_set_padding (misc, misc->xpad, g_value_get_int (value));
172 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
178 gtk_misc_get_property (GObject *object,
185 misc = GTK_MISC (object);
190 g_value_set_float (value, misc->xalign);
193 g_value_set_float (value, misc->yalign);
196 g_value_set_int (value, misc->xpad);
199 g_value_set_int (value, misc->ypad);
202 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
208 gtk_misc_set_alignment (GtkMisc *misc,
212 g_return_if_fail (GTK_IS_MISC (misc));
216 else if (xalign > 1.0)
221 else if (yalign > 1.0)
224 if ((xalign != misc->xalign) || (yalign != misc->yalign))
226 misc->xalign = xalign;
227 misc->yalign = yalign;
229 /* clear the area that was allocated before the change
231 if (GTK_WIDGET_DRAWABLE (misc))
235 widget = GTK_WIDGET (misc);
236 gtk_widget_queue_draw (widget);
239 g_object_freeze_notify (G_OBJECT (misc));
240 if (xalign != misc->xalign)
241 g_object_notify (G_OBJECT (misc), "xalign");
243 if (yalign != misc->yalign)
244 g_object_notify (G_OBJECT (misc), "yalign");
245 g_object_thaw_notify (G_OBJECT (misc));
250 * gtk_misc_get_alignment:
252 * @xalign: location to store X alignment of @misc, or %NULL
253 * @yalign: location to store Y alignment of @misc, or %NULL
255 * Gets the X and Y alignment of the widget within its allocation. See
256 * gtk_misc_set_alignment().
259 gtk_misc_get_alignment (GtkMisc *misc,
263 g_return_if_fail (GTK_IS_MISC (misc));
266 *xalign = misc->xalign;
268 *yalign = misc->yalign;
272 gtk_misc_set_padding (GtkMisc *misc,
276 GtkRequisition *requisition;
278 g_return_if_fail (GTK_IS_MISC (misc));
285 if ((xpad != misc->xpad) || (ypad != misc->ypad))
287 requisition = &(GTK_WIDGET (misc)->requisition);
288 requisition->width -= misc->xpad * 2;
289 requisition->height -= misc->ypad * 2;
294 requisition->width += misc->xpad * 2;
295 requisition->height += misc->ypad * 2;
297 if (GTK_WIDGET_DRAWABLE (misc))
298 gtk_widget_queue_resize (GTK_WIDGET (misc));
300 g_object_freeze_notify (G_OBJECT (misc));
301 if (xpad != misc->xpad)
302 g_object_notify (G_OBJECT (misc), "xpad");
304 if (ypad != misc->ypad)
305 g_object_notify (G_OBJECT (misc), "ypad");
306 g_object_thaw_notify (G_OBJECT (misc));
311 * gtk_misc_get_padding:
313 * @xpad: location to store padding in the X direction, or %NULL
314 * @ypad: location to store padding in the Y direction, or %NULL
316 * Gets the padding in the X and Y directions of the widget. See gtk_misc_set_padding().
319 gtk_misc_get_padding (GtkMisc *misc,
323 g_return_if_fail (GTK_IS_MISC (misc));
332 gtk_misc_realize (GtkWidget *widget)
335 GdkWindowAttr attributes;
336 gint attributes_mask;
338 g_return_if_fail (GTK_IS_MISC (widget));
340 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
341 misc = GTK_MISC (widget);
343 if (GTK_WIDGET_NO_WINDOW (widget))
345 widget->window = gtk_widget_get_parent_window (widget);
346 g_object_ref (widget->window);
347 widget->style = gtk_style_attach (widget->style, widget->window);
351 attributes.window_type = GDK_WINDOW_CHILD;
352 attributes.x = widget->allocation.x;
353 attributes.y = widget->allocation.y;
354 attributes.width = widget->allocation.width;
355 attributes.height = widget->allocation.height;
356 attributes.wclass = GDK_INPUT_OUTPUT;
357 attributes.visual = gtk_widget_get_visual (widget);
358 attributes.colormap = gtk_widget_get_colormap (widget);
359 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
360 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
362 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
363 gdk_window_set_user_data (widget->window, widget);
365 widget->style = gtk_style_attach (widget->style, widget->window);
366 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
370 #define __GTK_MISC_C__
371 #include "gtkaliasdef.c"