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"
33 struct _GtkFixedPrivate
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 (GtkFixedPrivate));
117 gtk_fixed_child_type (GtkContainer *container)
119 return GTK_TYPE_WIDGET;
123 gtk_fixed_init (GtkFixed *fixed)
125 GtkFixedPrivate *priv;
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 GtkFixedPrivate *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 GtkFixedPrivate *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 (gtk_widget_get_parent (widget) == 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 GtkAllocation allocation;
292 GdkWindowAttr attributes;
293 gint attributes_mask;
295 if (!gtk_widget_get_has_window (widget))
296 GTK_WIDGET_CLASS (gtk_fixed_parent_class)->realize (widget);
299 gtk_widget_set_realized (widget, TRUE);
301 gtk_widget_get_allocation (widget, &allocation);
303 attributes.window_type = GDK_WINDOW_CHILD;
304 attributes.x = allocation.x;
305 attributes.y = allocation.y;
306 attributes.width = allocation.width;
307 attributes.height = allocation.height;
308 attributes.wclass = GDK_INPUT_OUTPUT;
309 attributes.visual = gtk_widget_get_visual (widget);
310 attributes.colormap = gtk_widget_get_colormap (widget);
311 attributes.event_mask = gtk_widget_get_events (widget);
312 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
314 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
316 window = gdk_window_new (gtk_widget_get_parent_window (widget),
317 &attributes, attributes_mask);
318 gtk_widget_set_window (widget, window);
319 gdk_window_set_user_data (window, widget);
321 gtk_widget_style_attach (widget);
322 gtk_style_set_background (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL);
327 gtk_fixed_size_request (GtkWidget *widget,
328 GtkRequisition *requisition)
330 GtkFixedPrivate *priv;
332 GtkFixedChild *child;
334 GtkRequisition child_requisition;
337 fixed = GTK_FIXED (widget);
340 requisition->width = 0;
341 requisition->height = 0;
343 children = priv->children;
346 child = children->data;
347 children = children->next;
349 if (gtk_widget_get_visible (child->widget))
351 gtk_widget_size_request (child->widget, &child_requisition);
353 requisition->height = MAX (requisition->height,
355 child_requisition.height);
356 requisition->width = MAX (requisition->width,
358 child_requisition.width);
362 border_width = gtk_container_get_border_width (GTK_CONTAINER (fixed));
363 requisition->height += border_width * 2;
364 requisition->width += border_width * 2;
368 gtk_fixed_size_allocate (GtkWidget *widget,
369 GtkAllocation *allocation)
371 GtkFixed *fixed = GTK_FIXED (widget);
372 GtkFixedPrivate *priv = fixed->priv;
373 GtkFixedChild *child;
374 GtkAllocation child_allocation;
375 GtkRequisition child_requisition;
379 gtk_widget_set_allocation (widget, allocation);
381 if (gtk_widget_get_has_window (widget))
383 if (gtk_widget_get_realized (widget))
384 gdk_window_move_resize (gtk_widget_get_window (widget),
391 border_width = gtk_container_get_border_width (GTK_CONTAINER (fixed));
393 children = priv->children;
396 child = children->data;
397 children = children->next;
399 if (gtk_widget_get_visible (child->widget))
401 gtk_widget_get_child_requisition (child->widget, &child_requisition);
402 child_allocation.x = child->x + border_width;
403 child_allocation.y = child->y + border_width;
405 if (!gtk_widget_get_has_window (widget))
407 child_allocation.x += allocation->x;
408 child_allocation.y += allocation->y;
411 child_allocation.width = child_requisition.width;
412 child_allocation.height = child_requisition.height;
413 gtk_widget_size_allocate (child->widget, &child_allocation);
419 gtk_fixed_add (GtkContainer *container,
422 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
426 gtk_fixed_remove (GtkContainer *container,
429 GtkFixed *fixed = GTK_FIXED (container);
430 GtkFixedPrivate *priv = fixed->priv;
431 GtkFixedChild *child;
432 GtkWidget *widget_container = GTK_WIDGET (container);
435 children = priv->children;
438 child = children->data;
440 if (child->widget == widget)
442 gboolean was_visible = gtk_widget_get_visible (widget);
444 gtk_widget_unparent (widget);
446 priv->children = g_list_remove_link (priv->children, children);
447 g_list_free (children);
450 if (was_visible && gtk_widget_get_visible (widget_container))
451 gtk_widget_queue_resize (widget_container);
456 children = children->next;
461 gtk_fixed_forall (GtkContainer *container,
462 gboolean include_internals,
463 GtkCallback callback,
464 gpointer callback_data)
466 GtkFixed *fixed = GTK_FIXED (container);
467 GtkFixedPrivate *priv = fixed->priv;
468 GtkFixedChild *child;
471 children = priv->children;
474 child = children->data;
475 children = children->next;
477 (* callback) (child->widget, callback_data);