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/.
31 #include "gtkprivate.h"
35 struct _GtkFixedPrivate
46 static void gtk_fixed_realize (GtkWidget *widget);
47 static void gtk_fixed_size_request (GtkWidget *widget,
48 GtkRequisition *requisition);
49 static void gtk_fixed_size_allocate (GtkWidget *widget,
50 GtkAllocation *allocation);
51 static void gtk_fixed_add (GtkContainer *container,
53 static void gtk_fixed_remove (GtkContainer *container,
55 static void gtk_fixed_forall (GtkContainer *container,
56 gboolean include_internals,
58 gpointer callback_data);
59 static GType gtk_fixed_child_type (GtkContainer *container);
61 static void gtk_fixed_set_child_property (GtkContainer *container,
66 static void gtk_fixed_get_child_property (GtkContainer *container,
72 G_DEFINE_TYPE (GtkFixed, gtk_fixed, GTK_TYPE_CONTAINER)
75 gtk_fixed_class_init (GtkFixedClass *class)
77 GtkWidgetClass *widget_class;
78 GtkContainerClass *container_class;
80 widget_class = (GtkWidgetClass*) class;
81 container_class = (GtkContainerClass*) class;
83 widget_class->realize = gtk_fixed_realize;
84 widget_class->size_request = gtk_fixed_size_request;
85 widget_class->size_allocate = gtk_fixed_size_allocate;
87 container_class->add = gtk_fixed_add;
88 container_class->remove = gtk_fixed_remove;
89 container_class->forall = gtk_fixed_forall;
90 container_class->child_type = gtk_fixed_child_type;
92 container_class->set_child_property = gtk_fixed_set_child_property;
93 container_class->get_child_property = gtk_fixed_get_child_property;
95 gtk_container_class_install_child_property (container_class,
97 g_param_spec_int ("x",
99 P_("X position of child widget"),
103 GTK_PARAM_READWRITE));
105 gtk_container_class_install_child_property (container_class,
107 g_param_spec_int ("y",
109 P_("Y position of child widget"),
113 GTK_PARAM_READWRITE));
115 g_type_class_add_private (class, sizeof (GtkFixedPrivate));
119 gtk_fixed_child_type (GtkContainer *container)
121 return GTK_TYPE_WIDGET;
125 gtk_fixed_init (GtkFixed *fixed)
127 GtkFixedPrivate *priv;
129 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed,
134 gtk_widget_set_has_window (GTK_WIDGET (fixed), FALSE);
136 priv->children = NULL;
142 return g_object_new (GTK_TYPE_FIXED, NULL);
145 static GtkFixedChild*
146 get_child (GtkFixed *fixed,
149 GtkFixedPrivate *priv = fixed->priv;
152 children = priv->children;
155 GtkFixedChild *child;
157 child = children->data;
158 children = children->next;
160 if (child->widget == widget)
168 gtk_fixed_put (GtkFixed *fixed,
173 GtkFixedPrivate *priv = fixed->priv;
174 GtkFixedChild *child_info;
176 g_return_if_fail (GTK_IS_FIXED (fixed));
177 g_return_if_fail (GTK_IS_WIDGET (widget));
179 child_info = g_new (GtkFixedChild, 1);
180 child_info->widget = widget;
184 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
186 priv->children = g_list_append (priv->children, child_info);
190 gtk_fixed_move_internal (GtkFixed *fixed,
197 GtkFixedChild *child;
199 g_return_if_fail (GTK_IS_FIXED (fixed));
200 g_return_if_fail (GTK_IS_WIDGET (widget));
201 g_return_if_fail (gtk_widget_get_parent (widget) == GTK_WIDGET (fixed));
203 child = get_child (fixed, widget);
207 gtk_widget_freeze_child_notify (widget);
212 gtk_widget_child_notify (widget, "x");
218 gtk_widget_child_notify (widget, "y");
221 gtk_widget_thaw_child_notify (widget);
223 if (gtk_widget_get_visible (widget) &&
224 gtk_widget_get_visible (GTK_WIDGET (fixed)))
225 gtk_widget_queue_resize (GTK_WIDGET (fixed));
229 gtk_fixed_move (GtkFixed *fixed,
234 gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
238 gtk_fixed_set_child_property (GtkContainer *container,
247 gtk_fixed_move_internal (GTK_FIXED (container),
249 TRUE, g_value_get_int (value),
253 gtk_fixed_move_internal (GTK_FIXED (container),
256 TRUE, g_value_get_int (value));
259 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
265 gtk_fixed_get_child_property (GtkContainer *container,
271 GtkFixedChild *fixed_child;
273 fixed_child = get_child (GTK_FIXED (container), child);
278 g_value_set_int (value, fixed_child->x);
281 g_value_set_int (value, fixed_child->y);
284 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
290 gtk_fixed_realize (GtkWidget *widget)
292 GtkAllocation allocation;
294 GdkWindowAttr attributes;
295 gint attributes_mask;
297 if (!gtk_widget_get_has_window (widget))
298 GTK_WIDGET_CLASS (gtk_fixed_parent_class)->realize (widget);
301 gtk_widget_set_realized (widget, TRUE);
303 gtk_widget_get_allocation (widget, &allocation);
305 attributes.window_type = GDK_WINDOW_CHILD;
306 attributes.x = allocation.x;
307 attributes.y = allocation.y;
308 attributes.width = allocation.width;
309 attributes.height = allocation.height;
310 attributes.wclass = GDK_INPUT_OUTPUT;
311 attributes.visual = gtk_widget_get_visual (widget);
312 attributes.event_mask = gtk_widget_get_events (widget);
313 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
315 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
317 window = gdk_window_new (gtk_widget_get_parent_window (widget),
318 &attributes, attributes_mask);
319 gtk_widget_set_window (widget, window);
320 gdk_window_set_user_data (window, widget);
322 gtk_widget_style_attach (widget);
323 gtk_style_set_background (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL);
328 gtk_fixed_size_request (GtkWidget *widget,
329 GtkRequisition *requisition)
331 GtkFixedPrivate *priv;
333 GtkFixedChild *child;
335 GtkRequisition child_requisition;
338 fixed = GTK_FIXED (widget);
341 requisition->width = 0;
342 requisition->height = 0;
344 children = priv->children;
347 child = children->data;
348 children = children->next;
350 if (gtk_widget_get_visible (child->widget))
352 gtk_widget_get_preferred_size (child->widget,
356 requisition->height = MAX (requisition->height,
358 child_requisition.height);
359 requisition->width = MAX (requisition->width,
361 child_requisition.width);
365 border_width = gtk_container_get_border_width (GTK_CONTAINER (fixed));
366 requisition->height += border_width * 2;
367 requisition->width += border_width * 2;
371 gtk_fixed_size_allocate (GtkWidget *widget,
372 GtkAllocation *allocation)
374 GtkFixed *fixed = GTK_FIXED (widget);
375 GtkFixedPrivate *priv = fixed->priv;
376 GtkFixedChild *child;
377 GtkAllocation child_allocation;
378 GtkRequisition child_requisition;
382 gtk_widget_set_allocation (widget, allocation);
384 if (gtk_widget_get_has_window (widget))
386 if (gtk_widget_get_realized (widget))
387 gdk_window_move_resize (gtk_widget_get_window (widget),
394 border_width = gtk_container_get_border_width (GTK_CONTAINER (fixed));
396 children = priv->children;
399 child = children->data;
400 children = children->next;
402 if (gtk_widget_get_visible (child->widget))
404 gtk_widget_get_preferred_size (child->widget,
405 &child_requisition, NULL);
406 child_allocation.x = child->x + border_width;
407 child_allocation.y = child->y + border_width;
409 if (!gtk_widget_get_has_window (widget))
411 child_allocation.x += allocation->x;
412 child_allocation.y += allocation->y;
415 child_allocation.width = child_requisition.width;
416 child_allocation.height = child_requisition.height;
417 gtk_widget_size_allocate (child->widget, &child_allocation);
423 gtk_fixed_add (GtkContainer *container,
426 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
430 gtk_fixed_remove (GtkContainer *container,
433 GtkFixed *fixed = GTK_FIXED (container);
434 GtkFixedPrivate *priv = fixed->priv;
435 GtkFixedChild *child;
436 GtkWidget *widget_container = GTK_WIDGET (container);
439 children = priv->children;
442 child = children->data;
444 if (child->widget == widget)
446 gboolean was_visible = gtk_widget_get_visible (widget);
448 gtk_widget_unparent (widget);
450 priv->children = g_list_remove_link (priv->children, children);
451 g_list_free (children);
454 if (was_visible && gtk_widget_get_visible (widget_container))
455 gtk_widget_queue_resize (widget_container);
460 children = children->next;
465 gtk_fixed_forall (GtkContainer *container,
466 gboolean include_internals,
467 GtkCallback callback,
468 gpointer callback_data)
470 GtkFixed *fixed = GTK_FIXED (container);
471 GtkFixedPrivate *priv = fixed->priv;
472 GtkFixedChild *child;
475 children = priv->children;
478 child = children->data;
479 children = children->next;
481 (* callback) (child->widget, callback_data);