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"
39 static void gtk_misc_class_init (GtkMiscClass *klass);
40 static void gtk_misc_init (GtkMisc *misc);
41 static void gtk_misc_realize (GtkWidget *widget);
42 static void gtk_misc_set_arg (GtkObject *object,
45 static void gtk_misc_get_arg (GtkObject *object,
51 gtk_misc_get_type (void)
53 static GtkType misc_type = 0;
57 static const GtkTypeInfo misc_info =
61 sizeof (GtkMiscClass),
62 (GtkClassInitFunc) gtk_misc_class_init,
63 (GtkObjectInitFunc) gtk_misc_init,
64 /* reserved_1 */ NULL,
65 /* reserved_2 */ NULL,
66 (GtkClassInitFunc) NULL,
69 misc_type = gtk_type_unique (GTK_TYPE_WIDGET, &misc_info);
76 gtk_misc_class_init (GtkMiscClass *class)
78 GtkObjectClass *object_class;
79 GtkWidgetClass *widget_class;
81 object_class = (GtkObjectClass*) class;
82 widget_class = (GtkWidgetClass*) class;
84 gtk_object_add_arg_type ("GtkMisc::xalign", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_XALIGN);
85 gtk_object_add_arg_type ("GtkMisc::yalign", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_YALIGN);
86 gtk_object_add_arg_type ("GtkMisc::xpad", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_XPAD);
87 gtk_object_add_arg_type ("GtkMisc::ypad", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_YPAD);
89 object_class->set_arg = gtk_misc_set_arg;
90 object_class->get_arg = gtk_misc_get_arg;
92 widget_class->realize = gtk_misc_realize;
96 gtk_misc_init (GtkMisc *misc)
105 gtk_misc_set_arg (GtkObject *object,
111 misc = GTK_MISC (object);
116 gtk_misc_set_alignment (misc, GTK_VALUE_FLOAT (*arg), misc->yalign);
119 gtk_misc_set_alignment (misc, misc->xalign, GTK_VALUE_FLOAT (*arg));
122 gtk_misc_set_padding (misc, GTK_VALUE_INT (*arg), misc->ypad);
125 gtk_misc_set_padding (misc, misc->xpad, GTK_VALUE_INT (*arg));
133 gtk_misc_get_arg (GtkObject *object,
139 misc = GTK_MISC (object);
144 GTK_VALUE_FLOAT (*arg) = misc->xalign;
147 GTK_VALUE_FLOAT (*arg) = misc->yalign;
150 GTK_VALUE_INT (*arg) = misc->xpad;
153 GTK_VALUE_INT (*arg) = misc->ypad;
156 arg->type = GTK_TYPE_INVALID;
162 gtk_misc_set_alignment (GtkMisc *misc,
166 g_return_if_fail (misc != NULL);
167 g_return_if_fail (GTK_IS_MISC (misc));
171 else if (xalign > 1.0)
176 else if (yalign > 1.0)
179 if ((xalign != misc->xalign) || (yalign != misc->yalign))
181 misc->xalign = xalign;
182 misc->yalign = yalign;
184 /* clear the area that was allocated before the change
186 if (GTK_WIDGET_DRAWABLE (misc))
190 widget = GTK_WIDGET (misc);
191 gtk_widget_queue_clear (widget);
197 gtk_misc_set_padding (GtkMisc *misc,
201 GtkRequisition *requisition;
203 g_return_if_fail (misc != NULL);
204 g_return_if_fail (GTK_IS_MISC (misc));
211 if ((xpad != misc->xpad) || (ypad != misc->ypad))
213 requisition = &(GTK_WIDGET (misc)->requisition);
214 requisition->width -= misc->xpad * 2;
215 requisition->height -= misc->ypad * 2;
220 requisition->width += misc->xpad * 2;
221 requisition->height += misc->ypad * 2;
223 if (GTK_WIDGET_DRAWABLE (misc))
224 gtk_widget_queue_resize (GTK_WIDGET (misc));
229 gtk_misc_realize (GtkWidget *widget)
232 GdkWindowAttr attributes;
233 gint attributes_mask;
235 g_return_if_fail (widget != NULL);
236 g_return_if_fail (GTK_IS_MISC (widget));
238 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
239 misc = GTK_MISC (widget);
241 if (GTK_WIDGET_NO_WINDOW (widget))
243 widget->window = gtk_widget_get_parent_window (widget);
244 gdk_window_ref (widget->window);
245 widget->style = gtk_style_attach (widget->style, widget->window);
249 attributes.window_type = GDK_WINDOW_CHILD;
250 attributes.x = widget->allocation.x;
251 attributes.y = widget->allocation.y;
252 attributes.width = widget->allocation.width;
253 attributes.height = widget->allocation.height;
254 attributes.wclass = GDK_INPUT_OUTPUT;
255 attributes.visual = gtk_widget_get_visual (widget);
256 attributes.colormap = gtk_widget_get_colormap (widget);
257 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
258 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
260 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
261 gdk_window_set_user_data (widget->window, widget);
263 widget->style = gtk_style_attach (widget->style, widget->window);
264 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);