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"
43 static void gtk_misc_class_init (GtkMiscClass *klass);
44 static void gtk_misc_init (GtkMisc *misc);
45 static void gtk_misc_realize (GtkWidget *widget);
46 static void gtk_misc_set_property (GObject *object,
50 static void gtk_misc_get_property (GObject *object,
57 gtk_misc_get_type (void)
59 static GType misc_type = 0;
63 static const GTypeInfo misc_info =
65 sizeof (GtkMiscClass),
67 NULL, /* base_finalize */
68 (GClassInitFunc) gtk_misc_class_init,
69 NULL, /* class_finalize */
70 NULL, /* class_data */
73 (GInstanceInitFunc) gtk_misc_init,
74 NULL, /* value_table */
77 misc_type = g_type_register_static (GTK_TYPE_WIDGET, I_("GtkMisc"),
78 &misc_info, G_TYPE_FLAG_ABSTRACT);
85 gtk_misc_class_init (GtkMiscClass *class)
87 GObjectClass *gobject_class;
88 GtkWidgetClass *widget_class;
90 gobject_class = G_OBJECT_CLASS (class);
91 widget_class = (GtkWidgetClass*) class;
93 gobject_class->set_property = gtk_misc_set_property;
94 gobject_class->get_property = gtk_misc_get_property;
96 widget_class->realize = gtk_misc_realize;
98 g_object_class_install_property (gobject_class,
100 g_param_spec_float ("xalign",
102 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
106 GTK_PARAM_READWRITE));
108 g_object_class_install_property (gobject_class,
110 g_param_spec_float ("yalign",
112 P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
116 GTK_PARAM_READWRITE));
118 g_object_class_install_property (gobject_class,
120 g_param_spec_int ("xpad",
122 P_("The amount of space to add on the left and right of the widget, in pixels"),
126 GTK_PARAM_READWRITE));
128 g_object_class_install_property (gobject_class,
130 g_param_spec_int ("ypad",
132 P_("The amount of space to add on the top and bottom of the widget, in pixels"),
136 GTK_PARAM_READWRITE));
140 gtk_misc_init (GtkMisc *misc)
149 gtk_misc_set_property (GObject *object,
156 misc = GTK_MISC (object);
161 gtk_misc_set_alignment (misc, g_value_get_float (value), misc->yalign);
164 gtk_misc_set_alignment (misc, misc->xalign, g_value_get_float (value));
167 gtk_misc_set_padding (misc, g_value_get_int (value), misc->ypad);
170 gtk_misc_set_padding (misc, misc->xpad, g_value_get_int (value));
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
179 gtk_misc_get_property (GObject *object,
186 misc = GTK_MISC (object);
191 g_value_set_float (value, misc->xalign);
194 g_value_set_float (value, misc->yalign);
197 g_value_set_int (value, misc->xpad);
200 g_value_set_int (value, misc->ypad);
203 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
209 gtk_misc_set_alignment (GtkMisc *misc,
213 g_return_if_fail (GTK_IS_MISC (misc));
217 else if (xalign > 1.0)
222 else if (yalign > 1.0)
225 if ((xalign != misc->xalign) || (yalign != misc->yalign))
227 misc->xalign = xalign;
228 misc->yalign = yalign;
230 /* clear the area that was allocated before the change
232 if (GTK_WIDGET_DRAWABLE (misc))
236 widget = GTK_WIDGET (misc);
237 gtk_widget_queue_draw (widget);
240 g_object_freeze_notify (G_OBJECT (misc));
241 if (xalign != misc->xalign)
242 g_object_notify (G_OBJECT (misc), "xalign");
244 if (yalign != misc->yalign)
245 g_object_notify (G_OBJECT (misc), "yalign");
246 g_object_thaw_notify (G_OBJECT (misc));
251 * gtk_misc_get_alignment:
253 * @xalign: location to store X alignment of @misc, or %NULL
254 * @yalign: location to store Y alignment of @misc, or %NULL
256 * Gets the X and Y alignment of the widget within its allocation. See
257 * gtk_misc_set_alignment().
260 gtk_misc_get_alignment (GtkMisc *misc,
264 g_return_if_fail (GTK_IS_MISC (misc));
267 *xalign = misc->xalign;
269 *yalign = misc->yalign;
273 gtk_misc_set_padding (GtkMisc *misc,
277 GtkRequisition *requisition;
279 g_return_if_fail (GTK_IS_MISC (misc));
286 if ((xpad != misc->xpad) || (ypad != misc->ypad))
288 requisition = &(GTK_WIDGET (misc)->requisition);
289 requisition->width -= misc->xpad * 2;
290 requisition->height -= misc->ypad * 2;
295 requisition->width += misc->xpad * 2;
296 requisition->height += misc->ypad * 2;
298 if (GTK_WIDGET_DRAWABLE (misc))
299 gtk_widget_queue_resize (GTK_WIDGET (misc));
301 g_object_freeze_notify (G_OBJECT (misc));
302 if (xpad != misc->xpad)
303 g_object_notify (G_OBJECT (misc), "xpad");
305 if (ypad != misc->ypad)
306 g_object_notify (G_OBJECT (misc), "ypad");
307 g_object_thaw_notify (G_OBJECT (misc));
312 * gtk_misc_get_padding:
314 * @xpad: location to store padding in the X direction, or %NULL
315 * @ypad: location to store padding in the Y direction, or %NULL
317 * Gets the padding in the X and Y directions of the widget. See gtk_misc_set_padding().
320 gtk_misc_get_padding (GtkMisc *misc,
324 g_return_if_fail (GTK_IS_MISC (misc));
333 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);
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);
369 #define __GTK_MISC_C__
370 #include "gtkaliasdef.c"