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"
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,
53 G_DEFINE_ABSTRACT_TYPE (GtkMisc, gtk_misc, GTK_TYPE_WIDGET)
56 gtk_misc_class_init (GtkMiscClass *class)
58 GObjectClass *gobject_class;
59 GtkWidgetClass *widget_class;
61 gobject_class = G_OBJECT_CLASS (class);
62 widget_class = (GtkWidgetClass*) class;
64 gobject_class->set_property = gtk_misc_set_property;
65 gobject_class->get_property = gtk_misc_get_property;
67 widget_class->realize = gtk_misc_realize;
69 g_object_class_install_property (gobject_class,
71 g_param_spec_float ("xalign",
73 P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
77 GTK_PARAM_READWRITE));
79 g_object_class_install_property (gobject_class,
81 g_param_spec_float ("yalign",
83 P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
87 GTK_PARAM_READWRITE));
89 g_object_class_install_property (gobject_class,
91 g_param_spec_int ("xpad",
93 P_("The amount of space to add on the left and right of the widget, in pixels"),
97 GTK_PARAM_READWRITE));
99 g_object_class_install_property (gobject_class,
101 g_param_spec_int ("ypad",
103 P_("The amount of space to add on the top and bottom of the widget, in pixels"),
107 GTK_PARAM_READWRITE));
111 gtk_misc_init (GtkMisc *misc)
120 gtk_misc_set_property (GObject *object,
127 misc = GTK_MISC (object);
132 gtk_misc_set_alignment (misc, g_value_get_float (value), misc->yalign);
135 gtk_misc_set_alignment (misc, misc->xalign, g_value_get_float (value));
138 gtk_misc_set_padding (misc, g_value_get_int (value), misc->ypad);
141 gtk_misc_set_padding (misc, misc->xpad, g_value_get_int (value));
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
150 gtk_misc_get_property (GObject *object,
157 misc = GTK_MISC (object);
162 g_value_set_float (value, misc->xalign);
165 g_value_set_float (value, misc->yalign);
168 g_value_set_int (value, misc->xpad);
171 g_value_set_int (value, misc->ypad);
174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
180 gtk_misc_set_alignment (GtkMisc *misc,
186 g_return_if_fail (GTK_IS_MISC (misc));
190 else if (xalign > 1.0)
195 else if (yalign > 1.0)
198 if ((xalign != misc->xalign) || (yalign != misc->yalign))
200 g_object_freeze_notify (G_OBJECT (misc));
201 if (xalign != misc->xalign)
202 g_object_notify (G_OBJECT (misc), "xalign");
204 if (yalign != misc->yalign)
205 g_object_notify (G_OBJECT (misc), "yalign");
207 misc->xalign = xalign;
208 misc->yalign = yalign;
210 /* clear the area that was allocated before the change
212 widget = GTK_WIDGET (misc);
213 if (gtk_widget_is_drawable (widget))
214 gtk_widget_queue_draw (widget);
216 g_object_thaw_notify (G_OBJECT (misc));
221 * gtk_misc_get_alignment:
223 * @xalign: (allow-none): location to store X alignment of @misc, or %NULL
224 * @yalign: (allow-none): location to store Y alignment of @misc, or %NULL
226 * Gets the X and Y alignment of the widget within its allocation.
227 * See gtk_misc_set_alignment().
230 gtk_misc_get_alignment (GtkMisc *misc,
234 g_return_if_fail (GTK_IS_MISC (misc));
237 *xalign = misc->xalign;
239 *yalign = misc->yalign;
243 gtk_misc_set_padding (GtkMisc *misc,
247 GtkRequisition *requisition;
249 g_return_if_fail (GTK_IS_MISC (misc));
256 if ((xpad != misc->xpad) || (ypad != misc->ypad))
258 g_object_freeze_notify (G_OBJECT (misc));
259 if (xpad != misc->xpad)
260 g_object_notify (G_OBJECT (misc), "xpad");
262 if (ypad != misc->ypad)
263 g_object_notify (G_OBJECT (misc), "ypad");
265 requisition = &(GTK_WIDGET (misc)->requisition);
266 requisition->width -= misc->xpad * 2;
267 requisition->height -= misc->ypad * 2;
272 requisition->width += misc->xpad * 2;
273 requisition->height += misc->ypad * 2;
275 if (gtk_widget_is_drawable (GTK_WIDGET (misc)))
276 gtk_widget_queue_resize (GTK_WIDGET (misc));
278 g_object_thaw_notify (G_OBJECT (misc));
283 * gtk_misc_get_padding:
285 * @xpad: (allow-none): location to store padding in the X direction, or %NULL
286 * @ypad: (allow-none): location to store padding in the Y direction, or %NULL
288 * Gets the padding in the X and Y directions of the widget.
289 * See gtk_misc_set_padding().
292 gtk_misc_get_padding (GtkMisc *misc,
296 g_return_if_fail (GTK_IS_MISC (misc));
305 gtk_misc_realize (GtkWidget *widget)
307 GdkWindowAttr attributes;
308 gint attributes_mask;
310 gtk_widget_set_realized (widget, TRUE);
312 if (!gtk_widget_get_has_window (widget))
314 widget->window = gtk_widget_get_parent_window (widget);
315 g_object_ref (widget->window);
316 widget->style = gtk_style_attach (widget->style, widget->window);
320 attributes.window_type = GDK_WINDOW_CHILD;
321 attributes.x = widget->allocation.x;
322 attributes.y = widget->allocation.y;
323 attributes.width = widget->allocation.width;
324 attributes.height = widget->allocation.height;
325 attributes.wclass = GDK_INPUT_OUTPUT;
326 attributes.visual = gtk_widget_get_visual (widget);
327 attributes.colormap = gtk_widget_get_colormap (widget);
328 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
329 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
331 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
332 gdk_window_set_user_data (widget->window, widget);
334 widget->style = gtk_style_attach (widget->style, widget->window);
335 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);