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_paint (GtkWidget *widget,
40 static gint gtk_fixed_expose (GtkWidget *widget,
41 GdkEventExpose *event);
42 static void gtk_fixed_add (GtkContainer *container,
44 static void gtk_fixed_remove (GtkContainer *container,
46 static void gtk_fixed_forall (GtkContainer *container,
47 gboolean include_internals,
49 gpointer callback_data);
50 static GtkType gtk_fixed_child_type (GtkContainer *container);
53 static GtkContainerClass *parent_class = NULL;
57 gtk_fixed_get_type (void)
59 static GtkType fixed_type = 0;
63 static const GtkTypeInfo fixed_info =
67 sizeof (GtkFixedClass),
68 (GtkClassInitFunc) gtk_fixed_class_init,
69 (GtkObjectInitFunc) gtk_fixed_init,
70 /* reserved_1 */ NULL,
71 /* reserved_2 */ NULL,
72 (GtkClassInitFunc) NULL,
75 fixed_type = gtk_type_unique (GTK_TYPE_CONTAINER, &fixed_info);
82 gtk_fixed_class_init (GtkFixedClass *class)
84 GtkObjectClass *object_class;
85 GtkWidgetClass *widget_class;
86 GtkContainerClass *container_class;
88 object_class = (GtkObjectClass*) class;
89 widget_class = (GtkWidgetClass*) class;
90 container_class = (GtkContainerClass*) class;
92 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
94 widget_class->map = gtk_fixed_map;
95 widget_class->realize = gtk_fixed_realize;
96 widget_class->size_request = gtk_fixed_size_request;
97 widget_class->size_allocate = gtk_fixed_size_allocate;
98 widget_class->expose_event = gtk_fixed_expose;
100 container_class->add = gtk_fixed_add;
101 container_class->remove = gtk_fixed_remove;
102 container_class->forall = gtk_fixed_forall;
103 container_class->child_type = gtk_fixed_child_type;
107 gtk_fixed_child_type (GtkContainer *container)
109 return GTK_TYPE_WIDGET;
113 gtk_fixed_init (GtkFixed *fixed)
115 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
117 fixed->children = NULL;
125 fixed = gtk_type_new (GTK_TYPE_FIXED);
126 return GTK_WIDGET (fixed);
130 gtk_fixed_put (GtkFixed *fixed,
135 GtkFixedChild *child_info;
137 g_return_if_fail (fixed != NULL);
138 g_return_if_fail (GTK_IS_FIXED (fixed));
139 g_return_if_fail (widget != NULL);
141 child_info = g_new (GtkFixedChild, 1);
142 child_info->widget = widget;
146 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
148 fixed->children = g_list_append (fixed->children, child_info);
150 if (GTK_WIDGET_REALIZED (fixed))
151 gtk_widget_realize (widget);
153 if (GTK_WIDGET_VISIBLE (fixed) && GTK_WIDGET_VISIBLE (widget))
155 if (GTK_WIDGET_MAPPED (fixed))
156 gtk_widget_map (widget);
158 gtk_widget_queue_resize (GTK_WIDGET (fixed));
163 gtk_fixed_move (GtkFixed *fixed,
168 GtkFixedChild *child;
171 g_return_if_fail (fixed != NULL);
172 g_return_if_fail (GTK_IS_FIXED (fixed));
173 g_return_if_fail (widget != NULL);
175 children = fixed->children;
178 child = children->data;
179 children = children->next;
181 if (child->widget == widget)
186 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
187 gtk_widget_queue_resize (GTK_WIDGET (fixed));
195 gtk_fixed_map (GtkWidget *widget)
198 GtkFixedChild *child;
201 g_return_if_fail (widget != NULL);
202 g_return_if_fail (GTK_IS_FIXED (widget));
204 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
205 fixed = GTK_FIXED (widget);
207 children = fixed->children;
210 child = children->data;
211 children = children->next;
213 if (GTK_WIDGET_VISIBLE (child->widget) &&
214 !GTK_WIDGET_MAPPED (child->widget))
215 gtk_widget_map (child->widget);
218 gdk_window_show (widget->window);
222 gtk_fixed_realize (GtkWidget *widget)
224 GdkWindowAttr attributes;
225 gint attributes_mask;
227 g_return_if_fail (widget != NULL);
228 g_return_if_fail (GTK_IS_FIXED (widget));
230 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
232 attributes.window_type = GDK_WINDOW_CHILD;
233 attributes.x = widget->allocation.x;
234 attributes.y = widget->allocation.y;
235 attributes.width = widget->allocation.width;
236 attributes.height = widget->allocation.height;
237 attributes.wclass = GDK_INPUT_OUTPUT;
238 attributes.visual = gtk_widget_get_visual (widget);
239 attributes.colormap = gtk_widget_get_colormap (widget);
240 attributes.event_mask = gtk_widget_get_events (widget);
241 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_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,
247 gdk_window_set_user_data (widget->window, widget);
249 widget->style = gtk_style_attach (widget->style, widget->window);
250 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
254 gtk_fixed_size_request (GtkWidget *widget,
255 GtkRequisition *requisition)
258 GtkFixedChild *child;
260 GtkRequisition child_requisition;
262 g_return_if_fail (widget != NULL);
263 g_return_if_fail (GTK_IS_FIXED (widget));
264 g_return_if_fail (requisition != NULL);
266 fixed = GTK_FIXED (widget);
267 requisition->width = 0;
268 requisition->height = 0;
270 children = fixed->children;
273 child = children->data;
274 children = children->next;
276 if (GTK_WIDGET_VISIBLE (child->widget))
278 gtk_widget_size_request (child->widget, &child_requisition);
280 requisition->height = MAX (requisition->height,
282 child_requisition.height);
283 requisition->width = MAX (requisition->width,
285 child_requisition.width);
289 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
290 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
294 gtk_fixed_size_allocate (GtkWidget *widget,
295 GtkAllocation *allocation)
298 GtkFixedChild *child;
299 GtkAllocation child_allocation;
300 GtkRequisition child_requisition;
302 guint16 border_width;
304 g_return_if_fail (widget != NULL);
305 g_return_if_fail (GTK_IS_FIXED(widget));
306 g_return_if_fail (allocation != NULL);
308 fixed = GTK_FIXED (widget);
310 widget->allocation = *allocation;
311 if (GTK_WIDGET_REALIZED (widget))
312 gdk_window_move_resize (widget->window,
318 border_width = GTK_CONTAINER (fixed)->border_width;
320 children = fixed->children;
323 child = children->data;
324 children = children->next;
326 if (GTK_WIDGET_VISIBLE (child->widget))
328 gtk_widget_get_child_requisition (child->widget, &child_requisition);
329 child_allocation.x = child->x + border_width;
330 child_allocation.y = child->y + border_width;
331 child_allocation.width = child_requisition.width;
332 child_allocation.height = child_requisition.height;
333 gtk_widget_size_allocate (child->widget, &child_allocation);
339 gtk_fixed_paint (GtkWidget *widget,
342 g_return_if_fail (widget != NULL);
343 g_return_if_fail (GTK_IS_FIXED (widget));
344 g_return_if_fail (area != NULL);
346 if (GTK_WIDGET_DRAWABLE (widget))
347 gdk_window_clear_area (widget->window,
349 area->width, area->height);
353 gtk_fixed_expose (GtkWidget *widget,
354 GdkEventExpose *event)
357 GtkFixedChild *child;
358 GdkEventExpose child_event;
361 g_return_val_if_fail (widget != NULL, FALSE);
362 g_return_val_if_fail (GTK_IS_FIXED (widget), FALSE);
363 g_return_val_if_fail (event != NULL, FALSE);
365 if (GTK_WIDGET_DRAWABLE (widget))
367 fixed = GTK_FIXED (widget);
369 child_event = *event;
371 children = fixed->children;
374 child = children->data;
375 children = children->next;
377 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
378 gtk_widget_intersect (child->widget, &event->area,
380 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
388 gtk_fixed_add (GtkContainer *container,
391 g_return_if_fail (container != NULL);
392 g_return_if_fail (GTK_IS_FIXED (container));
393 g_return_if_fail (widget != NULL);
395 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
399 gtk_fixed_remove (GtkContainer *container,
403 GtkFixedChild *child;
406 g_return_if_fail (container != NULL);
407 g_return_if_fail (GTK_IS_FIXED (container));
408 g_return_if_fail (widget != NULL);
410 fixed = GTK_FIXED (container);
412 children = fixed->children;
415 child = children->data;
417 if (child->widget == widget)
419 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
421 gtk_widget_unparent (widget);
423 fixed->children = g_list_remove_link (fixed->children, children);
424 g_list_free (children);
427 if (was_visible && GTK_WIDGET_VISIBLE (container))
428 gtk_widget_queue_resize (GTK_WIDGET (container));
433 children = children->next;
438 gtk_fixed_forall (GtkContainer *container,
439 gboolean include_internals,
440 GtkCallback callback,
441 gpointer callback_data)
444 GtkFixedChild *child;
447 g_return_if_fail (container != NULL);
448 g_return_if_fail (GTK_IS_FIXED (container));
449 g_return_if_fail (callback != NULL);
451 fixed = GTK_FIXED (container);
453 children = fixed->children;
456 child = children->data;
457 children = children->next;
459 (* callback) (child->widget, callback_data);