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.
22 static void gtk_fixed_class_init (GtkFixedClass *klass);
23 static void gtk_fixed_init (GtkFixed *fixed);
24 static void gtk_fixed_map (GtkWidget *widget);
25 static void gtk_fixed_unmap (GtkWidget *widget);
26 static void gtk_fixed_realize (GtkWidget *widget);
27 static void gtk_fixed_size_request (GtkWidget *widget,
28 GtkRequisition *requisition);
29 static void gtk_fixed_size_allocate (GtkWidget *widget,
30 GtkAllocation *allocation);
31 static void gtk_fixed_paint (GtkWidget *widget,
33 static void gtk_fixed_draw (GtkWidget *widget,
35 static gint gtk_fixed_expose (GtkWidget *widget,
36 GdkEventExpose *event);
37 static void gtk_fixed_add (GtkContainer *container,
39 static void gtk_fixed_remove (GtkContainer *container,
41 static void gtk_fixed_forall (GtkContainer *container,
42 gboolean include_internals,
44 gpointer callback_data);
45 static GtkType gtk_fixed_child_type (GtkContainer *container);
48 static GtkContainerClass *parent_class = NULL;
52 gtk_fixed_get_type (void)
54 static GtkType fixed_type = 0;
58 GtkTypeInfo fixed_info =
62 sizeof (GtkFixedClass),
63 (GtkClassInitFunc) gtk_fixed_class_init,
64 (GtkObjectInitFunc) gtk_fixed_init,
65 /* reserved_1 */ NULL,
66 /* reserved_2 */ NULL,
67 (GtkClassInitFunc) NULL,
70 fixed_type = gtk_type_unique (GTK_TYPE_CONTAINER, &fixed_info);
77 gtk_fixed_class_init (GtkFixedClass *class)
79 GtkObjectClass *object_class;
80 GtkWidgetClass *widget_class;
81 GtkContainerClass *container_class;
83 object_class = (GtkObjectClass*) class;
84 widget_class = (GtkWidgetClass*) class;
85 container_class = (GtkContainerClass*) class;
87 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
89 widget_class->map = gtk_fixed_map;
90 widget_class->unmap = gtk_fixed_unmap;
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;
94 widget_class->draw = gtk_fixed_draw;
95 widget_class->expose_event = gtk_fixed_expose;
97 container_class->add = gtk_fixed_add;
98 container_class->remove = gtk_fixed_remove;
99 container_class->forall = gtk_fixed_forall;
100 container_class->child_type = gtk_fixed_child_type;
104 gtk_fixed_child_type (GtkContainer *container)
106 return GTK_TYPE_WIDGET;
110 gtk_fixed_init (GtkFixed *fixed)
112 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
113 GTK_WIDGET_SET_FLAGS (fixed, GTK_BASIC);
115 fixed->children = NULL;
123 fixed = gtk_type_new (GTK_TYPE_FIXED);
124 return GTK_WIDGET (fixed);
128 gtk_fixed_put (GtkFixed *fixed,
133 GtkFixedChild *child_info;
135 g_return_if_fail (fixed != NULL);
136 g_return_if_fail (GTK_IS_FIXED (fixed));
137 g_return_if_fail (widget != NULL);
139 child_info = g_new (GtkFixedChild, 1);
140 child_info->widget = widget;
144 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
146 fixed->children = g_list_append (fixed->children, child_info);
148 if (GTK_WIDGET_REALIZED (fixed) && !GTK_WIDGET_REALIZED (widget))
149 gtk_widget_realize (widget);
151 if (GTK_WIDGET_MAPPED (fixed) && !GTK_WIDGET_MAPPED (widget))
152 gtk_widget_map (widget);
154 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
155 gtk_widget_queue_resize (GTK_WIDGET (fixed));
159 gtk_fixed_move (GtkFixed *fixed,
164 GtkFixedChild *child;
167 g_return_if_fail (fixed != NULL);
168 g_return_if_fail (GTK_IS_FIXED (fixed));
169 g_return_if_fail (widget != NULL);
171 children = fixed->children;
174 child = children->data;
175 children = children->next;
177 if (child->widget == widget)
182 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
183 gtk_widget_queue_resize (GTK_WIDGET (fixed));
191 gtk_fixed_map (GtkWidget *widget)
194 GtkFixedChild *child;
197 g_return_if_fail (widget != NULL);
198 g_return_if_fail (GTK_IS_FIXED (widget));
200 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
201 fixed = GTK_FIXED (widget);
203 gdk_window_show (widget->window);
205 children = fixed->children;
208 child = children->data;
209 children = children->next;
211 if (GTK_WIDGET_VISIBLE (child->widget) &&
212 !GTK_WIDGET_MAPPED (child->widget))
213 gtk_widget_map (child->widget);
218 gtk_fixed_unmap (GtkWidget *widget)
220 g_return_if_fail (widget != NULL);
221 g_return_if_fail (GTK_IS_FIXED (widget));
223 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
227 gtk_fixed_realize (GtkWidget *widget)
229 GdkWindowAttr attributes;
230 gint attributes_mask;
232 g_return_if_fail (widget != NULL);
233 g_return_if_fail (GTK_IS_FIXED (widget));
235 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
237 attributes.window_type = GDK_WINDOW_CHILD;
238 attributes.x = widget->allocation.x;
239 attributes.y = widget->allocation.y;
240 attributes.width = widget->allocation.width;
241 attributes.height = widget->allocation.height;
242 attributes.wclass = GDK_INPUT_OUTPUT;
243 attributes.visual = gtk_widget_get_visual (widget);
244 attributes.colormap = gtk_widget_get_colormap (widget);
245 attributes.event_mask = gtk_widget_get_events (widget);
246 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
248 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
250 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
252 gdk_window_set_user_data (widget->window, widget);
254 widget->style = gtk_style_attach (widget->style, widget->window);
255 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
259 gtk_fixed_size_request (GtkWidget *widget,
260 GtkRequisition *requisition)
263 GtkFixedChild *child;
266 g_return_if_fail (widget != NULL);
267 g_return_if_fail (GTK_IS_FIXED (widget));
268 g_return_if_fail (requisition != NULL);
270 fixed = GTK_FIXED (widget);
271 requisition->width = 0;
272 requisition->height = 0;
274 children = fixed->children;
277 child = children->data;
278 children = children->next;
280 if (GTK_WIDGET_VISIBLE (child->widget))
282 gtk_widget_size_request (child->widget, &child->widget->requisition);
284 requisition->height = MAX (requisition->height,
286 child->widget->requisition.height);
287 requisition->width = MAX (requisition->width,
289 child->widget->requisition.width);
293 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
294 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
298 gtk_fixed_size_allocate (GtkWidget *widget,
299 GtkAllocation *allocation)
302 GtkFixedChild *child;
303 GtkAllocation child_allocation;
305 guint16 border_width;
307 g_return_if_fail (widget != NULL);
308 g_return_if_fail (GTK_IS_FIXED(widget));
309 g_return_if_fail (allocation != NULL);
311 fixed = GTK_FIXED (widget);
313 widget->allocation = *allocation;
314 if (GTK_WIDGET_REALIZED (widget))
315 gdk_window_move_resize (widget->window,
321 border_width = GTK_CONTAINER (fixed)->border_width;
323 children = fixed->children;
326 child = children->data;
327 children = children->next;
329 if (GTK_WIDGET_VISIBLE (child->widget))
331 child_allocation.x = child->x + border_width;
332 child_allocation.y = child->y + border_width;
333 child_allocation.width = child->widget->requisition.width;
334 child_allocation.height = child->widget->requisition.height;
335 gtk_widget_size_allocate (child->widget, &child_allocation);
341 gtk_fixed_paint (GtkWidget *widget,
344 g_return_if_fail (widget != NULL);
345 g_return_if_fail (GTK_IS_FIXED (widget));
346 g_return_if_fail (area != NULL);
348 if (GTK_WIDGET_DRAWABLE (widget))
349 gdk_window_clear_area (widget->window,
351 area->width, area->height);
355 gtk_fixed_draw (GtkWidget *widget,
359 GtkFixedChild *child;
360 GdkRectangle child_area;
363 g_return_if_fail (widget != NULL);
364 g_return_if_fail (GTK_IS_FIXED (widget));
366 if (GTK_WIDGET_DRAWABLE (widget))
368 fixed = GTK_FIXED (widget);
369 gtk_fixed_paint (widget, area);
371 children = fixed->children;
374 child = children->data;
375 children = children->next;
377 if (gtk_widget_intersect (child->widget, area, &child_area))
378 gtk_widget_draw (child->widget, &child_area);
384 gtk_fixed_expose (GtkWidget *widget,
385 GdkEventExpose *event)
388 GtkFixedChild *child;
389 GdkEventExpose child_event;
392 g_return_val_if_fail (widget != NULL, FALSE);
393 g_return_val_if_fail (GTK_IS_FIXED (widget), FALSE);
394 g_return_val_if_fail (event != NULL, FALSE);
396 if (GTK_WIDGET_DRAWABLE (widget))
398 fixed = GTK_FIXED (widget);
400 child_event = *event;
402 children = fixed->children;
405 child = children->data;
406 children = children->next;
408 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
409 gtk_widget_intersect (child->widget, &event->area,
411 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
419 gtk_fixed_add (GtkContainer *container,
422 g_return_if_fail (container != NULL);
423 g_return_if_fail (GTK_IS_FIXED (container));
424 g_return_if_fail (widget != NULL);
426 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
430 gtk_fixed_remove (GtkContainer *container,
434 GtkFixedChild *child;
437 g_return_if_fail (container != NULL);
438 g_return_if_fail (GTK_IS_FIXED (container));
439 g_return_if_fail (widget != NULL);
441 fixed = GTK_FIXED (container);
443 children = fixed->children;
446 child = children->data;
448 if (child->widget == widget)
450 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
452 gtk_widget_unparent (widget);
454 fixed->children = g_list_remove_link (fixed->children, children);
455 g_list_free (children);
458 if (was_visible && GTK_WIDGET_VISIBLE (container))
459 gtk_widget_queue_resize (GTK_WIDGET (container));
464 children = children->next;
469 gtk_fixed_forall (GtkContainer *container,
470 gboolean include_internals,
471 GtkCallback callback,
472 gpointer callback_data)
475 GtkFixedChild *child;
478 g_return_if_fail (container != NULL);
479 g_return_if_fail (GTK_IS_FIXED (container));
480 g_return_if_fail (callback != NULL);
482 fixed = GTK_FIXED (container);
484 children = fixed->children;
487 child = children->data;
488 children = children->next;
490 (* callback) (child->widget, callback_data);