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.
21 * Modified by the GTK+ Team and others 1997-1999. 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 void gtk_fixed_draw (GtkWidget *widget,
42 static gint gtk_fixed_expose (GtkWidget *widget,
43 GdkEventExpose *event);
44 static void gtk_fixed_add (GtkContainer *container,
46 static void gtk_fixed_remove (GtkContainer *container,
48 static void gtk_fixed_forall (GtkContainer *container,
49 gboolean include_internals,
51 gpointer callback_data);
52 static GtkType gtk_fixed_child_type (GtkContainer *container);
55 static GtkContainerClass *parent_class = NULL;
59 gtk_fixed_get_type (void)
61 static GtkType fixed_type = 0;
65 static const GtkTypeInfo fixed_info =
69 sizeof (GtkFixedClass),
70 (GtkClassInitFunc) gtk_fixed_class_init,
71 (GtkObjectInitFunc) gtk_fixed_init,
72 /* reserved_1 */ NULL,
73 /* reserved_2 */ NULL,
74 (GtkClassInitFunc) NULL,
77 fixed_type = gtk_type_unique (GTK_TYPE_CONTAINER, &fixed_info);
84 gtk_fixed_class_init (GtkFixedClass *class)
86 GtkObjectClass *object_class;
87 GtkWidgetClass *widget_class;
88 GtkContainerClass *container_class;
90 object_class = (GtkObjectClass*) class;
91 widget_class = (GtkWidgetClass*) class;
92 container_class = (GtkContainerClass*) class;
94 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
96 widget_class->map = gtk_fixed_map;
97 widget_class->realize = gtk_fixed_realize;
98 widget_class->size_request = gtk_fixed_size_request;
99 widget_class->size_allocate = gtk_fixed_size_allocate;
100 widget_class->draw = gtk_fixed_draw;
101 widget_class->expose_event = gtk_fixed_expose;
103 container_class->add = gtk_fixed_add;
104 container_class->remove = gtk_fixed_remove;
105 container_class->forall = gtk_fixed_forall;
106 container_class->child_type = gtk_fixed_child_type;
110 gtk_fixed_child_type (GtkContainer *container)
112 return GTK_TYPE_WIDGET;
116 gtk_fixed_init (GtkFixed *fixed)
118 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
120 fixed->children = NULL;
128 fixed = gtk_type_new (GTK_TYPE_FIXED);
129 return GTK_WIDGET (fixed);
133 gtk_fixed_put (GtkFixed *fixed,
138 GtkFixedChild *child_info;
140 g_return_if_fail (fixed != NULL);
141 g_return_if_fail (GTK_IS_FIXED (fixed));
142 g_return_if_fail (widget != NULL);
144 child_info = g_new (GtkFixedChild, 1);
145 child_info->widget = widget;
149 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
151 fixed->children = g_list_append (fixed->children, child_info);
153 if (GTK_WIDGET_REALIZED (fixed) && !GTK_WIDGET_REALIZED (widget))
154 gtk_widget_realize (widget);
156 if (GTK_WIDGET_MAPPED (fixed) && !GTK_WIDGET_MAPPED (widget))
157 gtk_widget_map (widget);
159 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
160 gtk_widget_queue_resize (GTK_WIDGET (fixed));
164 gtk_fixed_move (GtkFixed *fixed,
169 GtkFixedChild *child;
172 g_return_if_fail (fixed != NULL);
173 g_return_if_fail (GTK_IS_FIXED (fixed));
174 g_return_if_fail (widget != NULL);
176 children = fixed->children;
179 child = children->data;
180 children = children->next;
182 if (child->widget == widget)
187 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
188 gtk_widget_queue_resize (GTK_WIDGET (fixed));
196 gtk_fixed_map (GtkWidget *widget)
199 GtkFixedChild *child;
202 g_return_if_fail (widget != NULL);
203 g_return_if_fail (GTK_IS_FIXED (widget));
205 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
206 fixed = GTK_FIXED (widget);
208 children = fixed->children;
211 child = children->data;
212 children = children->next;
214 if (GTK_WIDGET_VISIBLE (child->widget) &&
215 !GTK_WIDGET_MAPPED (child->widget))
216 gtk_widget_map (child->widget);
219 gdk_window_show (widget->window);
223 gtk_fixed_realize (GtkWidget *widget)
225 GdkWindowAttr attributes;
226 gint attributes_mask;
228 g_return_if_fail (widget != NULL);
229 g_return_if_fail (GTK_IS_FIXED (widget));
231 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
233 attributes.window_type = GDK_WINDOW_CHILD;
234 attributes.x = widget->allocation.x;
235 attributes.y = widget->allocation.y;
236 attributes.width = widget->allocation.width;
237 attributes.height = widget->allocation.height;
238 attributes.wclass = GDK_INPUT_OUTPUT;
239 attributes.visual = gtk_widget_get_visual (widget);
240 attributes.colormap = gtk_widget_get_colormap (widget);
241 attributes.event_mask = gtk_widget_get_events (widget);
242 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
244 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
246 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
248 gdk_window_set_user_data (widget->window, widget);
250 widget->style = gtk_style_attach (widget->style, widget->window);
251 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
255 gtk_fixed_size_request (GtkWidget *widget,
256 GtkRequisition *requisition)
259 GtkFixedChild *child;
261 GtkRequisition child_requisition;
263 g_return_if_fail (widget != NULL);
264 g_return_if_fail (GTK_IS_FIXED (widget));
265 g_return_if_fail (requisition != NULL);
267 fixed = GTK_FIXED (widget);
268 requisition->width = 0;
269 requisition->height = 0;
271 children = fixed->children;
274 child = children->data;
275 children = children->next;
277 if (GTK_WIDGET_VISIBLE (child->widget))
279 gtk_widget_size_request (child->widget, &child_requisition);
281 requisition->height = MAX (requisition->height,
283 child_requisition.height);
284 requisition->width = MAX (requisition->width,
286 child_requisition.width);
290 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
291 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
295 gtk_fixed_size_allocate (GtkWidget *widget,
296 GtkAllocation *allocation)
299 GtkFixedChild *child;
300 GtkAllocation child_allocation;
301 GtkRequisition child_requisition;
303 guint16 border_width;
305 g_return_if_fail (widget != NULL);
306 g_return_if_fail (GTK_IS_FIXED(widget));
307 g_return_if_fail (allocation != NULL);
309 fixed = GTK_FIXED (widget);
311 widget->allocation = *allocation;
312 if (GTK_WIDGET_REALIZED (widget))
313 gdk_window_move_resize (widget->window,
319 border_width = GTK_CONTAINER (fixed)->border_width;
321 children = fixed->children;
324 child = children->data;
325 children = children->next;
327 if (GTK_WIDGET_VISIBLE (child->widget))
329 gtk_widget_get_child_requisition (child->widget, &child_requisition);
330 child_allocation.x = child->x + border_width;
331 child_allocation.y = child->y + border_width;
332 child_allocation.width = child_requisition.width;
333 child_allocation.height = child_requisition.height;
334 gtk_widget_size_allocate (child->widget, &child_allocation);
340 gtk_fixed_paint (GtkWidget *widget,
343 g_return_if_fail (widget != NULL);
344 g_return_if_fail (GTK_IS_FIXED (widget));
345 g_return_if_fail (area != NULL);
347 if (GTK_WIDGET_DRAWABLE (widget))
348 gdk_window_clear_area (widget->window,
350 area->width, area->height);
354 gtk_fixed_draw (GtkWidget *widget,
358 GtkFixedChild *child;
359 GdkRectangle child_area;
362 g_return_if_fail (widget != NULL);
363 g_return_if_fail (GTK_IS_FIXED (widget));
365 if (GTK_WIDGET_DRAWABLE (widget))
367 fixed = GTK_FIXED (widget);
368 gtk_fixed_paint (widget, area);
370 children = fixed->children;
373 child = children->data;
374 children = children->next;
376 if (gtk_widget_intersect (child->widget, area, &child_area))
377 gtk_widget_draw (child->widget, &child_area);
383 gtk_fixed_expose (GtkWidget *widget,
384 GdkEventExpose *event)
387 GtkFixedChild *child;
388 GdkEventExpose child_event;
391 g_return_val_if_fail (widget != NULL, FALSE);
392 g_return_val_if_fail (GTK_IS_FIXED (widget), FALSE);
393 g_return_val_if_fail (event != NULL, FALSE);
395 if (GTK_WIDGET_DRAWABLE (widget))
397 fixed = GTK_FIXED (widget);
399 child_event = *event;
401 children = fixed->children;
404 child = children->data;
405 children = children->next;
407 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
408 gtk_widget_intersect (child->widget, &event->area,
410 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
418 gtk_fixed_add (GtkContainer *container,
421 g_return_if_fail (container != NULL);
422 g_return_if_fail (GTK_IS_FIXED (container));
423 g_return_if_fail (widget != NULL);
425 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
429 gtk_fixed_remove (GtkContainer *container,
433 GtkFixedChild *child;
436 g_return_if_fail (container != NULL);
437 g_return_if_fail (GTK_IS_FIXED (container));
438 g_return_if_fail (widget != NULL);
440 fixed = GTK_FIXED (container);
442 children = fixed->children;
445 child = children->data;
447 if (child->widget == widget)
449 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
451 gtk_widget_unparent (widget);
453 fixed->children = g_list_remove_link (fixed->children, children);
454 g_list_free (children);
457 if (was_visible && GTK_WIDGET_VISIBLE (container))
458 gtk_widget_queue_resize (GTK_WIDGET (container));
463 children = children->next;
468 gtk_fixed_forall (GtkContainer *container,
469 gboolean include_internals,
470 GtkCallback callback,
471 gpointer callback_data)
474 GtkFixedChild *child;
477 g_return_if_fail (container != NULL);
478 g_return_if_fail (GTK_IS_FIXED (container));
479 g_return_if_fail (callback != NULL);
481 fixed = GTK_FIXED (container);
483 children = fixed->children;
486 child = children->data;
487 children = children->next;
489 (* callback) (child->widget, callback_data);