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"
39 static void gtk_fixed_class_init (GtkFixedClass *klass);
40 static void gtk_fixed_init (GtkFixed *fixed);
41 static void gtk_fixed_realize (GtkWidget *widget);
42 static void gtk_fixed_size_request (GtkWidget *widget,
43 GtkRequisition *requisition);
44 static void gtk_fixed_size_allocate (GtkWidget *widget,
45 GtkAllocation *allocation);
46 static void gtk_fixed_add (GtkContainer *container,
48 static void gtk_fixed_remove (GtkContainer *container,
50 static void gtk_fixed_forall (GtkContainer *container,
51 gboolean include_internals,
53 gpointer callback_data);
54 static GType gtk_fixed_child_type (GtkContainer *container);
56 static void gtk_fixed_set_child_property (GtkContainer *container,
61 static void gtk_fixed_get_child_property (GtkContainer *container,
67 static GtkContainerClass *parent_class = NULL;
71 gtk_fixed_get_type (void)
73 static GType fixed_type = 0;
77 static const GTypeInfo fixed_info =
79 sizeof (GtkFixedClass),
81 NULL, /* base_finalize */
82 (GClassInitFunc) gtk_fixed_class_init,
83 NULL, /* class_finalize */
84 NULL, /* class_data */
87 (GInstanceInitFunc) gtk_fixed_init,
90 fixed_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkFixed",
98 gtk_fixed_class_init (GtkFixedClass *class)
100 GtkWidgetClass *widget_class;
101 GtkContainerClass *container_class;
103 widget_class = (GtkWidgetClass*) class;
104 container_class = (GtkContainerClass*) class;
106 parent_class = g_type_class_peek_parent (class);
108 widget_class->realize = gtk_fixed_realize;
109 widget_class->size_request = gtk_fixed_size_request;
110 widget_class->size_allocate = gtk_fixed_size_allocate;
112 container_class->add = gtk_fixed_add;
113 container_class->remove = gtk_fixed_remove;
114 container_class->forall = gtk_fixed_forall;
115 container_class->child_type = gtk_fixed_child_type;
117 container_class->set_child_property = gtk_fixed_set_child_property;
118 container_class->get_child_property = gtk_fixed_get_child_property;
120 gtk_container_class_install_child_property (container_class,
122 g_param_spec_int ("x",
124 P_("X position of child widget"),
128 GTK_PARAM_READWRITE));
130 gtk_container_class_install_child_property (container_class,
132 g_param_spec_int ("y",
134 P_("Y position of child widget"),
138 GTK_PARAM_READWRITE));
142 gtk_fixed_child_type (GtkContainer *container)
144 return GTK_TYPE_WIDGET;
148 gtk_fixed_init (GtkFixed *fixed)
150 GTK_WIDGET_SET_FLAGS (fixed, GTK_NO_WINDOW);
152 fixed->children = NULL;
158 return g_object_new (GTK_TYPE_FIXED, NULL);
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 (GTK_IS_WIDGET (widget));
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 gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
251 gtk_fixed_set_child_property (GtkContainer *container,
260 gtk_fixed_move_internal (GTK_FIXED (container),
262 TRUE, g_value_get_int (value),
266 gtk_fixed_move_internal (GTK_FIXED (container),
269 TRUE, g_value_get_int (value));
272 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
278 gtk_fixed_get_child_property (GtkContainer *container,
284 GtkFixedChild *fixed_child;
286 fixed_child = get_child (GTK_FIXED (container), child);
291 g_value_set_int (value, fixed_child->x);
294 g_value_set_int (value, fixed_child->y);
297 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
303 gtk_fixed_realize (GtkWidget *widget)
305 GdkWindowAttr attributes;
306 gint attributes_mask;
308 if (GTK_WIDGET_NO_WINDOW (widget))
309 GTK_WIDGET_CLASS (parent_class)->realize (widget);
312 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
314 attributes.window_type = GDK_WINDOW_CHILD;
315 attributes.x = widget->allocation.x;
316 attributes.y = widget->allocation.y;
317 attributes.width = widget->allocation.width;
318 attributes.height = widget->allocation.height;
319 attributes.wclass = GDK_INPUT_OUTPUT;
320 attributes.visual = gtk_widget_get_visual (widget);
321 attributes.colormap = gtk_widget_get_colormap (widget);
322 attributes.event_mask = gtk_widget_get_events (widget);
323 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
325 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
327 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
329 gdk_window_set_user_data (widget->window, widget);
331 widget->style = gtk_style_attach (widget->style, widget->window);
332 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
337 gtk_fixed_size_request (GtkWidget *widget,
338 GtkRequisition *requisition)
341 GtkFixedChild *child;
343 GtkRequisition child_requisition;
345 fixed = GTK_FIXED (widget);
346 requisition->width = 0;
347 requisition->height = 0;
349 children = fixed->children;
352 child = children->data;
353 children = children->next;
355 if (GTK_WIDGET_VISIBLE (child->widget))
357 gtk_widget_size_request (child->widget, &child_requisition);
359 requisition->height = MAX (requisition->height,
361 child_requisition.height);
362 requisition->width = MAX (requisition->width,
364 child_requisition.width);
368 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
369 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
373 gtk_fixed_size_allocate (GtkWidget *widget,
374 GtkAllocation *allocation)
377 GtkFixedChild *child;
378 GtkAllocation child_allocation;
379 GtkRequisition child_requisition;
381 guint16 border_width;
383 fixed = GTK_FIXED (widget);
385 widget->allocation = *allocation;
387 if (!GTK_WIDGET_NO_WINDOW (widget))
389 if (GTK_WIDGET_REALIZED (widget))
390 gdk_window_move_resize (widget->window,
397 border_width = GTK_CONTAINER (fixed)->border_width;
399 children = fixed->children;
402 child = children->data;
403 children = children->next;
405 if (GTK_WIDGET_VISIBLE (child->widget))
407 gtk_widget_get_child_requisition (child->widget, &child_requisition);
408 child_allocation.x = child->x + border_width;
409 child_allocation.y = child->y + border_width;
411 if (GTK_WIDGET_NO_WINDOW (widget))
413 child_allocation.x += widget->allocation.x;
414 child_allocation.y += widget->allocation.y;
417 child_allocation.width = child_requisition.width;
418 child_allocation.height = child_requisition.height;
419 gtk_widget_size_allocate (child->widget, &child_allocation);
425 gtk_fixed_add (GtkContainer *container,
428 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
432 gtk_fixed_remove (GtkContainer *container,
436 GtkFixedChild *child;
439 fixed = GTK_FIXED (container);
441 children = fixed->children;
444 child = children->data;
446 if (child->widget == widget)
448 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
450 gtk_widget_unparent (widget);
452 fixed->children = g_list_remove_link (fixed->children, children);
453 g_list_free (children);
456 if (was_visible && GTK_WIDGET_VISIBLE (container))
457 gtk_widget_queue_resize (GTK_WIDGET (container));
462 children = children->next;
467 gtk_fixed_forall (GtkContainer *container,
468 gboolean include_internals,
469 GtkCallback callback,
470 gpointer callback_data)
473 GtkFixedChild *child;
476 g_return_if_fail (callback != NULL);
478 fixed = GTK_FIXED (container);
480 children = fixed->children;
483 child = children->data;
484 children = children->next;
486 (* callback) (child->widget, callback_data);
491 * gtk_fixed_set_has_window:
492 * @fixed: a #GtkFixed
493 * @has_window: %TRUE if a separate window should be created
495 * Sets whether a #GtkFixed widget is created with a separate
496 * #GdkWindow for @widget->window or not. (By default, it will be
497 * created with no separate #GdkWindow). This function must be called
498 * while the #GtkFixed is not realized, for instance, immediately after the
501 * This function was added to provide an easy migration path for
502 * older applications which may expect #GtkFixed to have a separate window.
505 gtk_fixed_set_has_window (GtkFixed *fixed,
508 g_return_if_fail (GTK_IS_FIXED (fixed));
509 g_return_if_fail (!GTK_WIDGET_REALIZED (fixed));
511 if (!has_window != GTK_WIDGET_NO_WINDOW (fixed))
514 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
516 GTK_WIDGET_SET_FLAGS (fixed, GTK_NO_WINDOW);
521 * gtk_fixed_get_has_window:
522 * @fixed: a #GtkWidget
524 * Gets whether the #GtkFixed has its own #GdkWindow.
525 * See gdk_fixed_set_has_window().
527 * Return value: %TRUE if @fixed has its own window.
530 gtk_fixed_get_has_window (GtkFixed *fixed)
532 g_return_val_if_fail (GTK_IS_FIXED (fixed), FALSE);
534 return !GTK_WIDGET_NO_WINDOW (fixed);
537 #define __GTK_FIXED_C__
538 #include "gtkaliasdef.c"