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/.
37 static void gtk_fixed_class_init (GtkFixedClass *klass);
38 static void gtk_fixed_init (GtkFixed *fixed);
39 static void gtk_fixed_realize (GtkWidget *widget);
40 static void gtk_fixed_size_request (GtkWidget *widget,
41 GtkRequisition *requisition);
42 static void gtk_fixed_size_allocate (GtkWidget *widget,
43 GtkAllocation *allocation);
44 static void gtk_fixed_add (GtkContainer *container,
46 static void gtk_fixed_remove (GtkContainer *container,
48 static void gtk_fixed_forall (GtkContainer *container,
49 gboolean include_internals,
51 gpointer callback_data);
52 static GType gtk_fixed_child_type (GtkContainer *container);
54 static void gtk_fixed_set_child_property (GtkContainer *container,
59 static void gtk_fixed_get_child_property (GtkContainer *container,
65 static GtkContainerClass *parent_class = NULL;
69 gtk_fixed_get_type (void)
71 static GType fixed_type = 0;
75 static const GTypeInfo fixed_info =
77 sizeof (GtkFixedClass),
79 NULL, /* base_finalize */
80 (GClassInitFunc) gtk_fixed_class_init,
81 NULL, /* class_finalize */
82 NULL, /* class_data */
85 (GInstanceInitFunc) gtk_fixed_init,
88 fixed_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkFixed",
96 gtk_fixed_class_init (GtkFixedClass *class)
98 GtkWidgetClass *widget_class;
99 GtkContainerClass *container_class;
101 widget_class = (GtkWidgetClass*) class;
102 container_class = (GtkContainerClass*) class;
104 parent_class = g_type_class_peek_parent (class);
106 widget_class->realize = gtk_fixed_realize;
107 widget_class->size_request = gtk_fixed_size_request;
108 widget_class->size_allocate = gtk_fixed_size_allocate;
110 container_class->add = gtk_fixed_add;
111 container_class->remove = gtk_fixed_remove;
112 container_class->forall = gtk_fixed_forall;
113 container_class->child_type = gtk_fixed_child_type;
115 container_class->set_child_property = gtk_fixed_set_child_property;
116 container_class->get_child_property = gtk_fixed_get_child_property;
118 gtk_container_class_install_child_property (container_class,
120 g_param_spec_int ("x",
122 P_("X position of child widget"),
128 gtk_container_class_install_child_property (container_class,
130 g_param_spec_int ("y",
132 P_("Y position of child widget"),
140 gtk_fixed_child_type (GtkContainer *container)
142 return GTK_TYPE_WIDGET;
146 gtk_fixed_init (GtkFixed *fixed)
148 GTK_WIDGET_SET_FLAGS (fixed, GTK_NO_WINDOW);
150 fixed->children = NULL;
156 return g_object_new (GTK_TYPE_FIXED, NULL);
159 static GtkFixedChild*
160 get_child (GtkFixed *fixed,
165 children = fixed->children;
168 GtkFixedChild *child;
170 child = children->data;
171 children = children->next;
173 if (child->widget == widget)
181 gtk_fixed_put (GtkFixed *fixed,
186 GtkFixedChild *child_info;
188 g_return_if_fail (GTK_IS_FIXED (fixed));
189 g_return_if_fail (GTK_IS_WIDGET (fixed));
191 child_info = g_new (GtkFixedChild, 1);
192 child_info->widget = widget;
196 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
198 fixed->children = g_list_append (fixed->children, child_info);
202 gtk_fixed_move_internal (GtkFixed *fixed,
209 GtkFixedChild *child;
211 g_return_if_fail (GTK_IS_FIXED (fixed));
212 g_return_if_fail (GTK_IS_WIDGET (widget));
213 g_return_if_fail (widget->parent == GTK_WIDGET (fixed));
215 child = get_child (fixed, widget);
219 gtk_widget_freeze_child_notify (widget);
224 gtk_widget_child_notify (widget, "x");
230 gtk_widget_child_notify (widget, "y");
233 gtk_widget_thaw_child_notify (widget);
235 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
236 gtk_widget_queue_resize (GTK_WIDGET (fixed));
240 gtk_fixed_move (GtkFixed *fixed,
245 gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
249 gtk_fixed_set_child_property (GtkContainer *container,
258 gtk_fixed_move_internal (GTK_FIXED (container),
260 TRUE, g_value_get_int (value),
264 gtk_fixed_move_internal (GTK_FIXED (container),
267 TRUE, g_value_get_int (value));
270 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
276 gtk_fixed_get_child_property (GtkContainer *container,
282 GtkFixedChild *fixed_child;
284 fixed_child = get_child (GTK_FIXED (container), child);
289 g_value_set_int (value, fixed_child->x);
292 g_value_set_int (value, fixed_child->y);
295 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
301 gtk_fixed_realize (GtkWidget *widget)
303 GdkWindowAttr attributes;
304 gint attributes_mask;
306 if (GTK_WIDGET_NO_WINDOW (widget))
307 GTK_WIDGET_CLASS (parent_class)->realize (widget);
310 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
312 attributes.window_type = GDK_WINDOW_CHILD;
313 attributes.x = widget->allocation.x;
314 attributes.y = widget->allocation.y;
315 attributes.width = widget->allocation.width;
316 attributes.height = widget->allocation.height;
317 attributes.wclass = GDK_INPUT_OUTPUT;
318 attributes.visual = gtk_widget_get_visual (widget);
319 attributes.colormap = gtk_widget_get_colormap (widget);
320 attributes.event_mask = gtk_widget_get_events (widget);
321 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
323 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
325 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
327 gdk_window_set_user_data (widget->window, widget);
329 widget->style = gtk_style_attach (widget->style, widget->window);
330 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
335 gtk_fixed_size_request (GtkWidget *widget,
336 GtkRequisition *requisition)
339 GtkFixedChild *child;
341 GtkRequisition child_requisition;
343 fixed = GTK_FIXED (widget);
344 requisition->width = 0;
345 requisition->height = 0;
347 children = fixed->children;
350 child = children->data;
351 children = children->next;
353 if (GTK_WIDGET_VISIBLE (child->widget))
355 gtk_widget_size_request (child->widget, &child_requisition);
357 requisition->height = MAX (requisition->height,
359 child_requisition.height);
360 requisition->width = MAX (requisition->width,
362 child_requisition.width);
366 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
367 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
371 gtk_fixed_size_allocate (GtkWidget *widget,
372 GtkAllocation *allocation)
375 GtkFixedChild *child;
376 GtkAllocation child_allocation;
377 GtkRequisition child_requisition;
379 guint16 border_width;
381 fixed = GTK_FIXED (widget);
383 widget->allocation = *allocation;
385 if (!GTK_WIDGET_NO_WINDOW (widget))
387 if (GTK_WIDGET_REALIZED (widget))
388 gdk_window_move_resize (widget->window,
395 border_width = GTK_CONTAINER (fixed)->border_width;
397 children = fixed->children;
400 child = children->data;
401 children = children->next;
403 if (GTK_WIDGET_VISIBLE (child->widget))
405 gtk_widget_get_child_requisition (child->widget, &child_requisition);
406 child_allocation.x = child->x + border_width;
407 child_allocation.y = child->y + border_width;
409 if (GTK_WIDGET_NO_WINDOW (widget))
411 child_allocation.x += widget->allocation.x;
412 child_allocation.y += widget->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,
434 GtkFixedChild *child;
437 fixed = GTK_FIXED (container);
439 children = fixed->children;
442 child = children->data;
444 if (child->widget == widget)
446 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
448 gtk_widget_unparent (widget);
450 fixed->children = g_list_remove_link (fixed->children, children);
451 g_list_free (children);
454 if (was_visible && GTK_WIDGET_VISIBLE (container))
455 gtk_widget_queue_resize (GTK_WIDGET (container));
460 children = children->next;
465 gtk_fixed_forall (GtkContainer *container,
466 gboolean include_internals,
467 GtkCallback callback,
468 gpointer callback_data)
471 GtkFixedChild *child;
474 g_return_if_fail (callback != NULL);
476 fixed = GTK_FIXED (container);
478 children = fixed->children;
481 child = children->data;
482 children = children->next;
484 (* callback) (child->widget, callback_data);
489 * gtk_fixed_set_has_window:
490 * @fixed: a #GtkFixed
491 * @has_window: %TRUE if a separate window should be created
493 * Sets whether a #GtkFixed widget is created with a separate
494 * #GdkWindow for widget->window or not. (By default, it will be
495 * created with no separate #GdkWindow). This function must be called
496 * while the #GtkFixed is not realized, for instance, immediately after the
500 gtk_fixed_set_has_window (GtkFixed *fixed,
503 g_return_if_fail (GTK_IS_FIXED (fixed));
504 g_return_if_fail (!GTK_WIDGET_REALIZED (fixed));
506 if (!has_window != GTK_WIDGET_NO_WINDOW (fixed))
509 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
511 GTK_WIDGET_SET_FLAGS (fixed, GTK_NO_WINDOW);
516 * gtk_fixed_get_has_window:
517 * @fixed: a #GtkWidget
519 * Gets whether the #GtkFixed has its own #GdkWindow.
520 * See gdk_fixed_set_has_window().
522 * Return value: %TRUE if @fixed has its own window.
525 gtk_fixed_get_has_window (GtkFixed *fixed)
527 g_return_val_if_fail (GTK_IS_FIXED (fixed), FALSE);
529 return !GTK_WIDGET_NO_WINDOW (fixed);