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/.
29 #include "gtkprivate.h"
44 static void gtk_fixed_realize (GtkWidget *widget);
45 static void gtk_fixed_size_request (GtkWidget *widget,
46 GtkRequisition *requisition);
47 static void gtk_fixed_size_allocate (GtkWidget *widget,
48 GtkAllocation *allocation);
49 static void gtk_fixed_add (GtkContainer *container,
51 static void gtk_fixed_remove (GtkContainer *container,
53 static void gtk_fixed_forall (GtkContainer *container,
54 gboolean include_internals,
56 gpointer callback_data);
57 static GType gtk_fixed_child_type (GtkContainer *container);
59 static void gtk_fixed_set_child_property (GtkContainer *container,
64 static void gtk_fixed_get_child_property (GtkContainer *container,
70 G_DEFINE_TYPE (GtkFixed, gtk_fixed, GTK_TYPE_CONTAINER)
73 gtk_fixed_class_init (GtkFixedClass *class)
75 GtkWidgetClass *widget_class;
76 GtkContainerClass *container_class;
78 widget_class = (GtkWidgetClass*) class;
79 container_class = (GtkContainerClass*) class;
81 widget_class->realize = gtk_fixed_realize;
82 widget_class->size_request = gtk_fixed_size_request;
83 widget_class->size_allocate = gtk_fixed_size_allocate;
85 container_class->add = gtk_fixed_add;
86 container_class->remove = gtk_fixed_remove;
87 container_class->forall = gtk_fixed_forall;
88 container_class->child_type = gtk_fixed_child_type;
90 container_class->set_child_property = gtk_fixed_set_child_property;
91 container_class->get_child_property = gtk_fixed_get_child_property;
93 gtk_container_class_install_child_property (container_class,
95 g_param_spec_int ("x",
97 P_("X position of child widget"),
101 GTK_PARAM_READWRITE));
103 gtk_container_class_install_child_property (container_class,
105 g_param_spec_int ("y",
107 P_("Y position of child widget"),
111 GTK_PARAM_READWRITE));
113 g_type_class_add_private (class, sizeof (GtkFixedPriv));
117 gtk_fixed_child_type (GtkContainer *container)
119 return GTK_TYPE_WIDGET;
123 gtk_fixed_init (GtkFixed *fixed)
127 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed,
132 gtk_widget_set_has_window (GTK_WIDGET (fixed), FALSE);
134 priv->children = NULL;
140 return g_object_new (GTK_TYPE_FIXED, NULL);
143 static GtkFixedChild*
144 get_child (GtkFixed *fixed,
147 GtkFixedPriv *priv = fixed->priv;
150 children = priv->children;
153 GtkFixedChild *child;
155 child = children->data;
156 children = children->next;
158 if (child->widget == widget)
166 gtk_fixed_put (GtkFixed *fixed,
171 GtkFixedPriv *priv = fixed->priv;
172 GtkFixedChild *child_info;
174 g_return_if_fail (GTK_IS_FIXED (fixed));
175 g_return_if_fail (GTK_IS_WIDGET (widget));
177 child_info = g_new (GtkFixedChild, 1);
178 child_info->widget = widget;
182 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
184 priv->children = g_list_append (priv->children, child_info);
188 gtk_fixed_move_internal (GtkFixed *fixed,
195 GtkFixedChild *child;
197 g_return_if_fail (GTK_IS_FIXED (fixed));
198 g_return_if_fail (GTK_IS_WIDGET (widget));
199 g_return_if_fail (widget->parent == GTK_WIDGET (fixed));
201 child = get_child (fixed, widget);
205 gtk_widget_freeze_child_notify (widget);
210 gtk_widget_child_notify (widget, "x");
216 gtk_widget_child_notify (widget, "y");
219 gtk_widget_thaw_child_notify (widget);
221 if (gtk_widget_get_visible (widget) &&
222 gtk_widget_get_visible (GTK_WIDGET (fixed)))
223 gtk_widget_queue_resize (GTK_WIDGET (fixed));
227 gtk_fixed_move (GtkFixed *fixed,
232 gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
236 gtk_fixed_set_child_property (GtkContainer *container,
245 gtk_fixed_move_internal (GTK_FIXED (container),
247 TRUE, g_value_get_int (value),
251 gtk_fixed_move_internal (GTK_FIXED (container),
254 TRUE, g_value_get_int (value));
257 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
263 gtk_fixed_get_child_property (GtkContainer *container,
269 GtkFixedChild *fixed_child;
271 fixed_child = get_child (GTK_FIXED (container), child);
276 g_value_set_int (value, fixed_child->x);
279 g_value_set_int (value, fixed_child->y);
282 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
288 gtk_fixed_realize (GtkWidget *widget)
290 GdkWindowAttr attributes;
291 gint attributes_mask;
293 if (!gtk_widget_get_has_window (widget))
294 GTK_WIDGET_CLASS (gtk_fixed_parent_class)->realize (widget);
297 gtk_widget_set_realized (widget, TRUE);
299 attributes.window_type = GDK_WINDOW_CHILD;
300 attributes.x = widget->allocation.x;
301 attributes.y = widget->allocation.y;
302 attributes.width = widget->allocation.width;
303 attributes.height = widget->allocation.height;
304 attributes.wclass = GDK_INPUT_OUTPUT;
305 attributes.visual = gtk_widget_get_visual (widget);
306 attributes.colormap = gtk_widget_get_colormap (widget);
307 attributes.event_mask = gtk_widget_get_events (widget);
308 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
310 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
312 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
314 gdk_window_set_user_data (widget->window, widget);
316 widget->style = gtk_style_attach (widget->style, widget->window);
317 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
322 gtk_fixed_size_request (GtkWidget *widget,
323 GtkRequisition *requisition)
327 GtkFixedChild *child;
329 GtkRequisition child_requisition;
332 fixed = GTK_FIXED (widget);
335 requisition->width = 0;
336 requisition->height = 0;
338 children = priv->children;
341 child = children->data;
342 children = children->next;
344 if (gtk_widget_get_visible (child->widget))
346 gtk_widget_size_request (child->widget, &child_requisition);
348 requisition->height = MAX (requisition->height,
350 child_requisition.height);
351 requisition->width = MAX (requisition->width,
353 child_requisition.width);
357 border_width = gtk_container_get_border_width (GTK_CONTAINER (fixed));
358 requisition->height += border_width * 2;
359 requisition->width += border_width * 2;
363 gtk_fixed_size_allocate (GtkWidget *widget,
364 GtkAllocation *allocation)
366 GtkFixed *fixed = GTK_FIXED (widget);
367 GtkFixedPriv *priv = fixed->priv;
368 GtkFixedChild *child;
369 GtkAllocation child_allocation;
370 GtkRequisition child_requisition;
374 widget->allocation = *allocation;
376 if (gtk_widget_get_has_window (widget))
378 if (gtk_widget_get_realized (widget))
379 gdk_window_move_resize (widget->window,
386 border_width = gtk_container_get_border_width (GTK_CONTAINER (fixed));
388 children = priv->children;
391 child = children->data;
392 children = children->next;
394 if (gtk_widget_get_visible (child->widget))
396 gtk_widget_get_child_requisition (child->widget, &child_requisition);
397 child_allocation.x = child->x + border_width;
398 child_allocation.y = child->y + border_width;
400 if (!gtk_widget_get_has_window (widget))
402 child_allocation.x += widget->allocation.x;
403 child_allocation.y += widget->allocation.y;
406 child_allocation.width = child_requisition.width;
407 child_allocation.height = child_requisition.height;
408 gtk_widget_size_allocate (child->widget, &child_allocation);
414 gtk_fixed_add (GtkContainer *container,
417 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
421 gtk_fixed_remove (GtkContainer *container,
424 GtkFixed *fixed = GTK_FIXED (container);
425 GtkFixedPriv *priv = fixed->priv;
426 GtkFixedChild *child;
427 GtkWidget *widget_container = GTK_WIDGET (container);
430 children = priv->children;
433 child = children->data;
435 if (child->widget == widget)
437 gboolean was_visible = gtk_widget_get_visible (widget);
439 gtk_widget_unparent (widget);
441 priv->children = g_list_remove_link (priv->children, children);
442 g_list_free (children);
445 if (was_visible && gtk_widget_get_visible (widget_container))
446 gtk_widget_queue_resize (widget_container);
451 children = children->next;
456 gtk_fixed_forall (GtkContainer *container,
457 gboolean include_internals,
458 GtkCallback callback,
459 gpointer callback_data)
461 GtkFixed *fixed = GTK_FIXED (container);
462 GtkFixedPriv *priv = fixed->priv;
463 GtkFixedChild *child;
466 children = priv->children;
469 child = children->data;
470 children = children->next;
472 (* callback) (child->widget, callback_data);