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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
19 #include "gtkcontainer.h"
31 static void gtk_misc_class_init (GtkMiscClass *klass);
32 static void gtk_misc_init (GtkMisc *misc);
33 static void gtk_misc_realize (GtkWidget *widget);
34 static void gtk_misc_set_arg (GtkMisc *misc,
37 static void gtk_misc_get_arg (GtkMisc *misc,
43 gtk_misc_get_type (void)
45 static guint misc_type = 0;
49 GtkTypeInfo misc_info =
53 sizeof (GtkMiscClass),
54 (GtkClassInitFunc) gtk_misc_class_init,
55 (GtkObjectInitFunc) gtk_misc_init,
56 (GtkArgSetFunc) gtk_misc_set_arg,
57 (GtkArgGetFunc) gtk_misc_get_arg,
60 misc_type = gtk_type_unique (gtk_widget_get_type (), &misc_info);
67 gtk_misc_class_init (GtkMiscClass *class)
69 GtkWidgetClass *widget_class;
71 widget_class = (GtkWidgetClass*) class;
73 gtk_object_add_arg_type ("GtkMisc::xalign", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_XALIGN);
74 gtk_object_add_arg_type ("GtkMisc::yalign", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_YALIGN);
75 gtk_object_add_arg_type ("GtkMisc::xpad", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_XPAD);
76 gtk_object_add_arg_type ("GtkMisc::ypad", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_YPAD);
78 widget_class->realize = gtk_misc_realize;
82 gtk_misc_init (GtkMisc *misc)
84 GTK_WIDGET_SET_FLAGS (misc, GTK_BASIC);
93 gtk_misc_set_arg (GtkMisc *misc,
100 gtk_misc_set_alignment (misc, GTK_VALUE_DOUBLE (*arg), misc->yalign);
103 gtk_misc_set_alignment (misc, misc->xalign, GTK_VALUE_DOUBLE (*arg));
106 gtk_misc_set_alignment (misc, GTK_VALUE_INT (*arg), misc->ypad);
109 gtk_misc_set_alignment (misc, misc->xpad, GTK_VALUE_INT (*arg));
117 gtk_misc_get_arg (GtkMisc *misc,
124 GTK_VALUE_DOUBLE (*arg) = misc->xalign;
127 GTK_VALUE_DOUBLE (*arg) = misc->yalign;
130 GTK_VALUE_INT (*arg) = misc->xpad;
133 GTK_VALUE_INT (*arg) = misc->ypad;
136 arg->type = GTK_TYPE_INVALID;
142 gtk_misc_set_alignment (GtkMisc *misc,
146 g_return_if_fail (misc != NULL);
147 g_return_if_fail (GTK_IS_MISC (misc));
151 else if (xalign > 1.0)
156 else if (yalign > 1.0)
159 if ((xalign != misc->xalign) || (yalign != misc->yalign))
161 misc->xalign = xalign;
162 misc->yalign = yalign;
164 /* clear the area that was allocated before the change
166 if (GTK_WIDGET_DRAWABLE (misc))
170 widget = GTK_WIDGET (misc);
171 gdk_window_clear_area (widget->window,
172 widget->allocation.x,
173 widget->allocation.y,
174 widget->allocation.width,
175 widget->allocation.height);
176 gtk_widget_queue_draw (GTK_WIDGET (misc));
182 gtk_misc_set_padding (GtkMisc *misc,
186 GtkRequisition *requisition;
188 g_return_if_fail (misc != NULL);
189 g_return_if_fail (GTK_IS_MISC (misc));
196 if ((xpad != misc->xpad) || (ypad != misc->ypad))
198 requisition = &(GTK_WIDGET (misc)->requisition);
199 requisition->width -= misc->xpad * 2;
200 requisition->height -= misc->ypad * 2;
205 requisition->width += misc->xpad * 2;
206 requisition->height += misc->ypad * 2;
208 if (GTK_WIDGET_DRAWABLE (misc))
209 gtk_widget_queue_resize (GTK_WIDGET (misc));
214 gtk_misc_realize (GtkWidget *widget)
217 GdkWindowAttr attributes;
218 gint attributes_mask;
220 g_return_if_fail (widget != NULL);
221 g_return_if_fail (GTK_IS_MISC (widget));
223 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
224 misc = GTK_MISC (widget);
226 if (GTK_WIDGET_NO_WINDOW (widget))
228 widget->window = gtk_widget_get_parent_window (widget);
229 gdk_window_ref (widget->window);
230 widget->style = gtk_style_attach (widget->style, widget->window);
234 attributes.window_type = GDK_WINDOW_CHILD;
235 attributes.x = widget->allocation.x;
236 attributes.y = widget->allocation.y;
237 attributes.width = widget->allocation.width;
238 attributes.height = widget->allocation.height;
239 attributes.wclass = GDK_INPUT_OUTPUT;
240 attributes.visual = gtk_widget_get_visual (widget);
241 attributes.colormap = gtk_widget_get_colormap (widget);
242 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
243 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
245 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
246 gdk_window_set_user_data (widget->window, widget);
248 widget->style = gtk_style_attach (widget->style, widget->window);
249 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);