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_realize (GtkWidget *widget);
26 static void gtk_fixed_size_request (GtkWidget *widget,
27 GtkRequisition *requisition);
28 static void gtk_fixed_size_allocate (GtkWidget *widget,
29 GtkAllocation *allocation);
30 static void gtk_fixed_paint (GtkWidget *widget,
32 static void gtk_fixed_draw (GtkWidget *widget,
34 static gint gtk_fixed_expose (GtkWidget *widget,
35 GdkEventExpose *event);
36 static void gtk_fixed_add (GtkContainer *container,
38 static void gtk_fixed_remove (GtkContainer *container,
40 static void gtk_fixed_forall (GtkContainer *container,
41 gboolean include_internals,
43 gpointer callback_data);
44 static GtkType gtk_fixed_child_type (GtkContainer *container);
47 static GtkContainerClass *parent_class = NULL;
51 gtk_fixed_get_type (void)
53 static GtkType fixed_type = 0;
57 static const GtkTypeInfo fixed_info =
61 sizeof (GtkFixedClass),
62 (GtkClassInitFunc) gtk_fixed_class_init,
63 (GtkObjectInitFunc) gtk_fixed_init,
64 /* reserved_1 */ NULL,
65 /* reserved_2 */ NULL,
66 (GtkClassInitFunc) NULL,
69 fixed_type = gtk_type_unique (GTK_TYPE_CONTAINER, &fixed_info);
76 gtk_fixed_class_init (GtkFixedClass *class)
78 GtkObjectClass *object_class;
79 GtkWidgetClass *widget_class;
80 GtkContainerClass *container_class;
82 object_class = (GtkObjectClass*) class;
83 widget_class = (GtkWidgetClass*) class;
84 container_class = (GtkContainerClass*) class;
86 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
88 widget_class->map = gtk_fixed_map;
89 widget_class->realize = gtk_fixed_realize;
90 widget_class->size_request = gtk_fixed_size_request;
91 widget_class->size_allocate = gtk_fixed_size_allocate;
92 widget_class->draw = gtk_fixed_draw;
93 widget_class->expose_event = gtk_fixed_expose;
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 (fixed != NULL);
133 g_return_if_fail (GTK_IS_FIXED (fixed));
134 g_return_if_fail (widget != NULL);
136 child_info = g_new (GtkFixedChild, 1);
137 child_info->widget = widget;
141 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
143 fixed->children = g_list_append (fixed->children, child_info);
145 if (GTK_WIDGET_REALIZED (fixed) && !GTK_WIDGET_REALIZED (widget))
146 gtk_widget_realize (widget);
148 if (GTK_WIDGET_MAPPED (fixed) && !GTK_WIDGET_MAPPED (widget))
149 gtk_widget_map (widget);
151 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
152 gtk_widget_queue_resize (GTK_WIDGET (fixed));
156 gtk_fixed_move (GtkFixed *fixed,
161 GtkFixedChild *child;
164 g_return_if_fail (fixed != NULL);
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 (widget != NULL);
195 g_return_if_fail (GTK_IS_FIXED (widget));
197 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
198 fixed = GTK_FIXED (widget);
200 children = fixed->children;
203 child = children->data;
204 children = children->next;
206 if (GTK_WIDGET_VISIBLE (child->widget) &&
207 !GTK_WIDGET_MAPPED (child->widget))
208 gtk_widget_map (child->widget);
211 gdk_window_show (widget->window);
215 gtk_fixed_realize (GtkWidget *widget)
217 GdkWindowAttr attributes;
218 gint attributes_mask;
220 g_return_if_fail (widget != NULL);
221 g_return_if_fail (GTK_IS_FIXED (widget));
223 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
225 attributes.window_type = GDK_WINDOW_CHILD;
226 attributes.x = widget->allocation.x;
227 attributes.y = widget->allocation.y;
228 attributes.width = widget->allocation.width;
229 attributes.height = widget->allocation.height;
230 attributes.wclass = GDK_INPUT_OUTPUT;
231 attributes.visual = gtk_widget_get_visual (widget);
232 attributes.colormap = gtk_widget_get_colormap (widget);
233 attributes.event_mask = gtk_widget_get_events (widget);
234 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
236 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
238 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
240 gdk_window_set_user_data (widget->window, widget);
242 widget->style = gtk_style_attach (widget->style, widget->window);
243 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
247 gtk_fixed_size_request (GtkWidget *widget,
248 GtkRequisition *requisition)
251 GtkFixedChild *child;
254 g_return_if_fail (widget != NULL);
255 g_return_if_fail (GTK_IS_FIXED (widget));
256 g_return_if_fail (requisition != NULL);
258 fixed = GTK_FIXED (widget);
259 requisition->width = 0;
260 requisition->height = 0;
262 children = fixed->children;
265 child = children->data;
266 children = children->next;
268 if (GTK_WIDGET_VISIBLE (child->widget))
270 gtk_widget_size_request (child->widget, &child->widget->requisition);
272 requisition->height = MAX (requisition->height,
274 child->widget->requisition.height);
275 requisition->width = MAX (requisition->width,
277 child->widget->requisition.width);
281 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
282 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
286 gtk_fixed_size_allocate (GtkWidget *widget,
287 GtkAllocation *allocation)
290 GtkFixedChild *child;
291 GtkAllocation child_allocation;
293 guint16 border_width;
295 g_return_if_fail (widget != NULL);
296 g_return_if_fail (GTK_IS_FIXED(widget));
297 g_return_if_fail (allocation != NULL);
299 fixed = GTK_FIXED (widget);
301 widget->allocation = *allocation;
302 if (GTK_WIDGET_REALIZED (widget))
303 gdk_window_move_resize (widget->window,
309 border_width = GTK_CONTAINER (fixed)->border_width;
311 children = fixed->children;
314 child = children->data;
315 children = children->next;
317 if (GTK_WIDGET_VISIBLE (child->widget))
319 child_allocation.x = child->x + border_width;
320 child_allocation.y = child->y + border_width;
321 child_allocation.width = child->widget->requisition.width;
322 child_allocation.height = child->widget->requisition.height;
323 gtk_widget_size_allocate (child->widget, &child_allocation);
329 gtk_fixed_paint (GtkWidget *widget,
332 g_return_if_fail (widget != NULL);
333 g_return_if_fail (GTK_IS_FIXED (widget));
334 g_return_if_fail (area != NULL);
336 if (GTK_WIDGET_DRAWABLE (widget))
337 gdk_window_clear_area (widget->window,
339 area->width, area->height);
343 gtk_fixed_draw (GtkWidget *widget,
347 GtkFixedChild *child;
348 GdkRectangle child_area;
351 g_return_if_fail (widget != NULL);
352 g_return_if_fail (GTK_IS_FIXED (widget));
354 if (GTK_WIDGET_DRAWABLE (widget))
356 fixed = GTK_FIXED (widget);
357 gtk_fixed_paint (widget, area);
359 children = fixed->children;
362 child = children->data;
363 children = children->next;
365 if (gtk_widget_intersect (child->widget, area, &child_area))
366 gtk_widget_draw (child->widget, &child_area);
372 gtk_fixed_expose (GtkWidget *widget,
373 GdkEventExpose *event)
376 GtkFixedChild *child;
377 GdkEventExpose child_event;
380 g_return_val_if_fail (widget != NULL, FALSE);
381 g_return_val_if_fail (GTK_IS_FIXED (widget), FALSE);
382 g_return_val_if_fail (event != NULL, FALSE);
384 if (GTK_WIDGET_DRAWABLE (widget))
386 fixed = GTK_FIXED (widget);
388 child_event = *event;
390 children = fixed->children;
393 child = children->data;
394 children = children->next;
396 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
397 gtk_widget_intersect (child->widget, &event->area,
399 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
407 gtk_fixed_add (GtkContainer *container,
410 g_return_if_fail (container != NULL);
411 g_return_if_fail (GTK_IS_FIXED (container));
412 g_return_if_fail (widget != NULL);
414 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
418 gtk_fixed_remove (GtkContainer *container,
422 GtkFixedChild *child;
425 g_return_if_fail (container != NULL);
426 g_return_if_fail (GTK_IS_FIXED (container));
427 g_return_if_fail (widget != NULL);
429 fixed = GTK_FIXED (container);
431 children = fixed->children;
434 child = children->data;
436 if (child->widget == widget)
438 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
440 gtk_widget_unparent (widget);
442 fixed->children = g_list_remove_link (fixed->children, children);
443 g_list_free (children);
446 if (was_visible && GTK_WIDGET_VISIBLE (container))
447 gtk_widget_queue_resize (GTK_WIDGET (container));
452 children = children->next;
457 gtk_fixed_forall (GtkContainer *container,
458 gboolean include_internals,
459 GtkCallback callback,
460 gpointer callback_data)
463 GtkFixedChild *child;
466 g_return_if_fail (container != NULL);
467 g_return_if_fail (GTK_IS_FIXED (container));
468 g_return_if_fail (callback != NULL);
470 fixed = GTK_FIXED (container);
472 children = fixed->children;
475 child = children->data;
476 children = children->next;
478 (* callback) (child->widget, callback_data);