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 Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include "gtkcontainer.h"
22 static void gtk_misc_class_init (GtkMiscClass *klass);
23 static void gtk_misc_init (GtkMisc *misc);
24 static void gtk_misc_realize (GtkWidget *widget);
30 static guint misc_type = 0;
34 GtkTypeInfo misc_info =
38 sizeof (GtkMiscClass),
39 (GtkClassInitFunc) gtk_misc_class_init,
40 (GtkObjectInitFunc) gtk_misc_init,
45 misc_type = gtk_type_unique (gtk_widget_get_type (), &misc_info);
52 gtk_misc_class_init (GtkMiscClass *class)
54 GtkWidgetClass *widget_class;
56 widget_class = (GtkWidgetClass*) class;
58 widget_class->realize = gtk_misc_realize;
62 gtk_misc_init (GtkMisc *misc)
64 GTK_WIDGET_SET_FLAGS (misc, GTK_BASIC);
73 gtk_misc_set_alignment (GtkMisc *misc,
77 g_return_if_fail (misc != NULL);
78 g_return_if_fail (GTK_IS_MISC (misc));
82 else if (xalign > 1.0)
87 else if (yalign > 1.0)
90 if ((xalign != misc->xalign) || (yalign != misc->yalign))
92 misc->xalign = xalign;
93 misc->yalign = yalign;
95 /* clear the area that was allocated before the change
97 if (GTK_WIDGET_VISIBLE (misc))
101 widget = GTK_WIDGET (misc);
102 gdk_window_clear_area (widget->window,
103 widget->allocation.x,
104 widget->allocation.y,
105 widget->allocation.width,
106 widget->allocation.height);
109 gtk_widget_queue_draw (GTK_WIDGET (misc));
114 gtk_misc_set_padding (GtkMisc *misc,
118 GtkRequisition *requisition;
120 g_return_if_fail (misc != NULL);
121 g_return_if_fail (GTK_IS_MISC (misc));
128 if ((xpad != misc->xpad) || (ypad != misc->ypad))
130 requisition = &(GTK_WIDGET (misc)->requisition);
131 requisition->width -= misc->xpad * 2;
132 requisition->height -= misc->ypad * 2;
137 requisition->width += misc->xpad * 2;
138 requisition->height += misc->ypad * 2;
140 if (GTK_WIDGET (misc)->parent && GTK_WIDGET_VISIBLE (misc))
141 gtk_widget_queue_resize (GTK_WIDGET (misc));
146 gtk_misc_realize (GtkWidget *widget)
149 GdkWindowAttr attributes;
150 gint attributes_mask;
152 g_return_if_fail (widget != NULL);
153 g_return_if_fail (GTK_IS_MISC (widget));
155 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
156 misc = GTK_MISC (widget);
158 if (GTK_WIDGET_NO_WINDOW (widget))
160 widget->window = widget->parent->window;
161 widget->style = gtk_style_attach (widget->style, widget->window);
165 attributes.window_type = GDK_WINDOW_CHILD;
166 attributes.x = widget->allocation.x;
167 attributes.y = widget->allocation.y;
168 attributes.width = widget->allocation.width;
169 attributes.height = widget->allocation.height;
170 attributes.wclass = GDK_INPUT_OUTPUT;
171 attributes.visual = gtk_widget_get_visual (widget);
172 attributes.colormap = gtk_widget_get_colormap (widget);
173 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
174 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
176 widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
177 gdk_window_set_user_data (widget->window, widget);
179 widget->style = gtk_style_attach (widget->style, widget->window);
180 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);