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/.
36 static void gtk_fixed_class_init (GtkFixedClass *klass);
37 static void gtk_fixed_init (GtkFixed *fixed);
38 static void gtk_fixed_realize (GtkWidget *widget);
39 static void gtk_fixed_size_request (GtkWidget *widget,
40 GtkRequisition *requisition);
41 static void gtk_fixed_size_allocate (GtkWidget *widget,
42 GtkAllocation *allocation);
43 static void gtk_fixed_add (GtkContainer *container,
45 static void gtk_fixed_remove (GtkContainer *container,
47 static void gtk_fixed_forall (GtkContainer *container,
48 gboolean include_internals,
50 gpointer callback_data);
51 static GtkType gtk_fixed_child_type (GtkContainer *container);
53 static void gtk_fixed_set_child_property (GtkContainer *container,
58 static void gtk_fixed_get_child_property (GtkContainer *container,
64 static GtkContainerClass *parent_class = NULL;
68 gtk_fixed_get_type (void)
70 static GtkType fixed_type = 0;
74 static const GtkTypeInfo fixed_info =
78 sizeof (GtkFixedClass),
79 (GtkClassInitFunc) gtk_fixed_class_init,
80 (GtkObjectInitFunc) gtk_fixed_init,
81 /* reserved_1 */ NULL,
82 /* reserved_2 */ NULL,
83 (GtkClassInitFunc) NULL,
86 fixed_type = gtk_type_unique (GTK_TYPE_CONTAINER, &fixed_info);
93 gtk_fixed_class_init (GtkFixedClass *class)
95 GtkObjectClass *object_class;
96 GtkWidgetClass *widget_class;
97 GtkContainerClass *container_class;
99 object_class = (GtkObjectClass*) class;
100 widget_class = (GtkWidgetClass*) class;
101 container_class = (GtkContainerClass*) class;
103 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
105 widget_class->realize = gtk_fixed_realize;
106 widget_class->size_request = gtk_fixed_size_request;
107 widget_class->size_allocate = gtk_fixed_size_allocate;
109 container_class->add = gtk_fixed_add;
110 container_class->remove = gtk_fixed_remove;
111 container_class->forall = gtk_fixed_forall;
112 container_class->child_type = gtk_fixed_child_type;
114 container_class->set_child_property = gtk_fixed_set_child_property;
115 container_class->get_child_property = gtk_fixed_get_child_property;
117 gtk_container_class_install_child_property (container_class,
119 g_param_spec_int ("x",
121 _("X position of child widget"),
127 gtk_container_class_install_child_property (container_class,
129 g_param_spec_int ("y",
131 _("Y position of child widget"),
139 gtk_fixed_child_type (GtkContainer *container)
141 return GTK_TYPE_WIDGET;
145 gtk_fixed_init (GtkFixed *fixed)
147 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
149 fixed->children = NULL;
157 fixed = gtk_type_new (GTK_TYPE_FIXED);
158 return GTK_WIDGET (fixed);
161 static GtkFixedChild*
162 get_child (GtkFixed *fixed,
167 children = fixed->children;
170 GtkFixedChild *child;
172 child = children->data;
173 children = children->next;
175 if (child->widget == widget)
183 gtk_fixed_put (GtkFixed *fixed,
188 GtkFixedChild *child_info;
190 g_return_if_fail (GTK_IS_FIXED (fixed));
191 g_return_if_fail (widget != NULL);
193 child_info = g_new (GtkFixedChild, 1);
194 child_info->widget = widget;
198 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
200 fixed->children = g_list_append (fixed->children, child_info);
204 gtk_fixed_move_internal (GtkFixed *fixed,
211 GtkFixedChild *child;
213 g_return_if_fail (GTK_IS_FIXED (fixed));
214 g_return_if_fail (GTK_IS_WIDGET (widget));
215 g_return_if_fail (widget->parent == GTK_WIDGET (fixed));
217 child = get_child (fixed, widget);
221 gtk_widget_freeze_child_notify (widget);
226 gtk_widget_child_notify (widget, "x");
232 gtk_widget_child_notify (widget, "y");
235 gtk_widget_thaw_child_notify (widget);
237 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
238 gtk_widget_queue_resize (GTK_WIDGET (fixed));
242 gtk_fixed_move (GtkFixed *fixed,
247 g_return_if_fail (GTK_IS_FIXED (fixed));
248 g_return_if_fail (GTK_IS_WIDGET (widget));
249 g_return_if_fail (widget->parent == GTK_WIDGET (fixed));
251 gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
255 gtk_fixed_set_child_property (GtkContainer *container,
264 gtk_fixed_move_internal (GTK_FIXED (container),
266 TRUE, g_value_get_int (value),
270 gtk_fixed_move_internal (GTK_FIXED (container),
273 TRUE, g_value_get_int (value));
276 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
282 gtk_fixed_get_child_property (GtkContainer *container,
288 GtkFixedChild *fixed_child;
290 fixed_child = get_child (GTK_FIXED (container), child);
295 g_value_set_int (value, fixed_child->x);
298 g_value_set_int (value, fixed_child->y);
301 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
307 gtk_fixed_map (GtkWidget *widget)
310 GtkFixedChild *child;
313 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
314 fixed = GTK_FIXED (widget);
316 children = fixed->children;
319 child = children->data;
320 children = children->next;
322 if (GTK_WIDGET_VISIBLE (child->widget) &&
323 !GTK_WIDGET_MAPPED (child->widget))
324 gtk_widget_map (child->widget);
327 gdk_window_show (widget->window);
331 gtk_fixed_realize (GtkWidget *widget)
333 GdkWindowAttr attributes;
334 gint attributes_mask;
336 g_return_if_fail (GTK_IS_FIXED (widget));
338 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
340 attributes.window_type = GDK_WINDOW_CHILD;
341 attributes.x = widget->allocation.x;
342 attributes.y = widget->allocation.y;
343 attributes.width = widget->allocation.width;
344 attributes.height = widget->allocation.height;
345 attributes.wclass = GDK_INPUT_OUTPUT;
346 attributes.visual = gtk_widget_get_visual (widget);
347 attributes.colormap = gtk_widget_get_colormap (widget);
348 attributes.event_mask = gtk_widget_get_events (widget);
349 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
351 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
353 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
355 gdk_window_set_user_data (widget->window, widget);
357 widget->style = gtk_style_attach (widget->style, widget->window);
358 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
362 gtk_fixed_size_request (GtkWidget *widget,
363 GtkRequisition *requisition)
366 GtkFixedChild *child;
368 GtkRequisition child_requisition;
370 g_return_if_fail (GTK_IS_FIXED (widget));
371 g_return_if_fail (requisition != NULL);
373 fixed = GTK_FIXED (widget);
374 requisition->width = 0;
375 requisition->height = 0;
377 children = fixed->children;
380 child = children->data;
381 children = children->next;
383 if (GTK_WIDGET_VISIBLE (child->widget))
385 gtk_widget_size_request (child->widget, &child_requisition);
387 requisition->height = MAX (requisition->height,
389 child_requisition.height);
390 requisition->width = MAX (requisition->width,
392 child_requisition.width);
396 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
397 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
401 gtk_fixed_size_allocate (GtkWidget *widget,
402 GtkAllocation *allocation)
405 GtkFixedChild *child;
406 GtkAllocation child_allocation;
407 GtkRequisition child_requisition;
409 guint16 border_width;
411 g_return_if_fail (GTK_IS_FIXED(widget));
412 g_return_if_fail (allocation != NULL);
414 fixed = GTK_FIXED (widget);
416 widget->allocation = *allocation;
417 if (GTK_WIDGET_REALIZED (widget))
418 gdk_window_move_resize (widget->window,
424 border_width = GTK_CONTAINER (fixed)->border_width;
426 children = fixed->children;
429 child = children->data;
430 children = children->next;
432 if (GTK_WIDGET_VISIBLE (child->widget))
434 gtk_widget_get_child_requisition (child->widget, &child_requisition);
435 child_allocation.x = child->x + border_width;
436 child_allocation.y = child->y + border_width;
437 child_allocation.width = child_requisition.width;
438 child_allocation.height = child_requisition.height;
439 gtk_widget_size_allocate (child->widget, &child_allocation);
445 gtk_fixed_add (GtkContainer *container,
448 g_return_if_fail (GTK_IS_FIXED (container));
449 g_return_if_fail (widget != NULL);
451 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
455 gtk_fixed_remove (GtkContainer *container,
459 GtkFixedChild *child;
462 g_return_if_fail (GTK_IS_FIXED (container));
463 g_return_if_fail (widget != NULL);
465 fixed = GTK_FIXED (container);
467 children = fixed->children;
470 child = children->data;
472 if (child->widget == widget)
474 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
476 gtk_widget_unparent (widget);
478 fixed->children = g_list_remove_link (fixed->children, children);
479 g_list_free (children);
482 if (was_visible && GTK_WIDGET_VISIBLE (container))
483 gtk_widget_queue_resize (GTK_WIDGET (container));
488 children = children->next;
493 gtk_fixed_forall (GtkContainer *container,
494 gboolean include_internals,
495 GtkCallback callback,
496 gpointer callback_data)
499 GtkFixedChild *child;
502 g_return_if_fail (GTK_IS_FIXED (container));
503 g_return_if_fail (callback != NULL);
505 fixed = GTK_FIXED (container);
507 children = fixed->children;
510 child = children->data;
511 children = children->next;
513 (* callback) (child->widget, callback_data);