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/.
30 static void gtk_fixed_class_init (GtkFixedClass *klass);
31 static void gtk_fixed_init (GtkFixed *fixed);
32 static void gtk_fixed_map (GtkWidget *widget);
33 static void gtk_fixed_realize (GtkWidget *widget);
34 static void gtk_fixed_size_request (GtkWidget *widget,
35 GtkRequisition *requisition);
36 static void gtk_fixed_size_allocate (GtkWidget *widget,
37 GtkAllocation *allocation);
38 static void gtk_fixed_add (GtkContainer *container,
40 static void gtk_fixed_remove (GtkContainer *container,
42 static void gtk_fixed_forall (GtkContainer *container,
43 gboolean include_internals,
45 gpointer callback_data);
46 static GtkType gtk_fixed_child_type (GtkContainer *container);
49 static GtkContainerClass *parent_class = NULL;
53 gtk_fixed_get_type (void)
55 static GtkType fixed_type = 0;
59 static const GtkTypeInfo fixed_info =
63 sizeof (GtkFixedClass),
64 (GtkClassInitFunc) gtk_fixed_class_init,
65 (GtkObjectInitFunc) gtk_fixed_init,
66 /* reserved_1 */ NULL,
67 /* reserved_2 */ NULL,
68 (GtkClassInitFunc) NULL,
71 fixed_type = gtk_type_unique (GTK_TYPE_CONTAINER, &fixed_info);
78 gtk_fixed_class_init (GtkFixedClass *class)
80 GtkObjectClass *object_class;
81 GtkWidgetClass *widget_class;
82 GtkContainerClass *container_class;
84 object_class = (GtkObjectClass*) class;
85 widget_class = (GtkWidgetClass*) class;
86 container_class = (GtkContainerClass*) class;
88 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
90 widget_class->map = gtk_fixed_map;
91 widget_class->realize = gtk_fixed_realize;
92 widget_class->size_request = gtk_fixed_size_request;
93 widget_class->size_allocate = gtk_fixed_size_allocate;
95 container_class->add = gtk_fixed_add;
96 container_class->remove = gtk_fixed_remove;
97 container_class->forall = gtk_fixed_forall;
98 container_class->child_type = gtk_fixed_child_type;
102 gtk_fixed_child_type (GtkContainer *container)
104 return GTK_TYPE_WIDGET;
108 gtk_fixed_init (GtkFixed *fixed)
110 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
112 fixed->children = NULL;
120 fixed = gtk_type_new (GTK_TYPE_FIXED);
121 return GTK_WIDGET (fixed);
125 gtk_fixed_put (GtkFixed *fixed,
130 GtkFixedChild *child_info;
132 g_return_if_fail (GTK_IS_FIXED (fixed));
133 g_return_if_fail (widget != NULL);
135 child_info = g_new (GtkFixedChild, 1);
136 child_info->widget = widget;
140 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
142 fixed->children = g_list_append (fixed->children, child_info);
144 if (GTK_WIDGET_REALIZED (fixed))
145 gtk_widget_realize (widget);
147 if (GTK_WIDGET_VISIBLE (fixed) && GTK_WIDGET_VISIBLE (widget))
149 if (GTK_WIDGET_MAPPED (fixed))
150 gtk_widget_map (widget);
152 gtk_widget_queue_resize (GTK_WIDGET (fixed));
157 gtk_fixed_move (GtkFixed *fixed,
162 GtkFixedChild *child;
165 g_return_if_fail (GTK_IS_FIXED (fixed));
166 g_return_if_fail (widget != NULL);
168 children = fixed->children;
171 child = children->data;
172 children = children->next;
174 if (child->widget == widget)
179 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
180 gtk_widget_queue_resize (GTK_WIDGET (fixed));
188 gtk_fixed_map (GtkWidget *widget)
191 GtkFixedChild *child;
194 g_return_if_fail (GTK_IS_FIXED (widget));
196 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
197 fixed = GTK_FIXED (widget);
199 children = fixed->children;
202 child = children->data;
203 children = children->next;
205 if (GTK_WIDGET_VISIBLE (child->widget) &&
206 !GTK_WIDGET_MAPPED (child->widget))
207 gtk_widget_map (child->widget);
210 gdk_window_show (widget->window);
214 gtk_fixed_realize (GtkWidget *widget)
216 GdkWindowAttr attributes;
217 gint attributes_mask;
219 g_return_if_fail (GTK_IS_FIXED (widget));
221 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
223 attributes.window_type = GDK_WINDOW_CHILD;
224 attributes.x = widget->allocation.x;
225 attributes.y = widget->allocation.y;
226 attributes.width = widget->allocation.width;
227 attributes.height = widget->allocation.height;
228 attributes.wclass = GDK_INPUT_OUTPUT;
229 attributes.visual = gtk_widget_get_visual (widget);
230 attributes.colormap = gtk_widget_get_colormap (widget);
231 attributes.event_mask = gtk_widget_get_events (widget);
232 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
234 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
236 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
238 gdk_window_set_user_data (widget->window, widget);
240 widget->style = gtk_style_attach (widget->style, widget->window);
241 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
245 gtk_fixed_size_request (GtkWidget *widget,
246 GtkRequisition *requisition)
249 GtkFixedChild *child;
251 GtkRequisition child_requisition;
253 g_return_if_fail (GTK_IS_FIXED (widget));
254 g_return_if_fail (requisition != NULL);
256 fixed = GTK_FIXED (widget);
257 requisition->width = 0;
258 requisition->height = 0;
260 children = fixed->children;
263 child = children->data;
264 children = children->next;
266 if (GTK_WIDGET_VISIBLE (child->widget))
268 gtk_widget_size_request (child->widget, &child_requisition);
270 requisition->height = MAX (requisition->height,
272 child_requisition.height);
273 requisition->width = MAX (requisition->width,
275 child_requisition.width);
279 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
280 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
284 gtk_fixed_size_allocate (GtkWidget *widget,
285 GtkAllocation *allocation)
288 GtkFixedChild *child;
289 GtkAllocation child_allocation;
290 GtkRequisition child_requisition;
292 guint16 border_width;
294 g_return_if_fail (GTK_IS_FIXED(widget));
295 g_return_if_fail (allocation != NULL);
297 fixed = GTK_FIXED (widget);
299 widget->allocation = *allocation;
300 if (GTK_WIDGET_REALIZED (widget))
301 gdk_window_move_resize (widget->window,
307 border_width = GTK_CONTAINER (fixed)->border_width;
309 children = fixed->children;
312 child = children->data;
313 children = children->next;
315 if (GTK_WIDGET_VISIBLE (child->widget))
317 gtk_widget_get_child_requisition (child->widget, &child_requisition);
318 child_allocation.x = child->x + border_width;
319 child_allocation.y = child->y + border_width;
320 child_allocation.width = child_requisition.width;
321 child_allocation.height = child_requisition.height;
322 gtk_widget_size_allocate (child->widget, &child_allocation);
328 gtk_fixed_add (GtkContainer *container,
331 g_return_if_fail (GTK_IS_FIXED (container));
332 g_return_if_fail (widget != NULL);
334 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
338 gtk_fixed_remove (GtkContainer *container,
342 GtkFixedChild *child;
345 g_return_if_fail (GTK_IS_FIXED (container));
346 g_return_if_fail (widget != NULL);
348 fixed = GTK_FIXED (container);
350 children = fixed->children;
353 child = children->data;
355 if (child->widget == widget)
357 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
359 gtk_widget_unparent (widget);
361 fixed->children = g_list_remove_link (fixed->children, children);
362 g_list_free (children);
365 if (was_visible && GTK_WIDGET_VISIBLE (container))
366 gtk_widget_queue_resize (GTK_WIDGET (container));
371 children = children->next;
376 gtk_fixed_forall (GtkContainer *container,
377 gboolean include_internals,
378 GtkCallback callback,
379 gpointer callback_data)
382 GtkFixedChild *child;
385 g_return_if_fail (GTK_IS_FIXED (container));
386 g_return_if_fail (callback != NULL);
388 fixed = GTK_FIXED (container);
390 children = fixed->children;
393 child = children->data;
394 children = children->next;
396 (* callback) (child->widget, callback_data);