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"
38 static void gtk_fixed_realize (GtkWidget *widget);
39 static void gtk_fixed_size_request (GtkWidget *widget,
40 GtkRequisition *requisition);
41 static void gtk_fixed_size_allocate (GtkWidget *widget,
42 GtkAllocation *allocation);
43 static void gtk_fixed_add (GtkContainer *container,
45 static void gtk_fixed_remove (GtkContainer *container,
47 static void gtk_fixed_forall (GtkContainer *container,
48 gboolean include_internals,
50 gpointer callback_data);
51 static GType gtk_fixed_child_type (GtkContainer *container);
53 static void gtk_fixed_set_child_property (GtkContainer *container,
58 static void gtk_fixed_get_child_property (GtkContainer *container,
64 G_DEFINE_TYPE (GtkFixed, gtk_fixed, GTK_TYPE_CONTAINER)
67 gtk_fixed_class_init (GtkFixedClass *class)
69 GtkWidgetClass *widget_class;
70 GtkContainerClass *container_class;
72 widget_class = (GtkWidgetClass*) class;
73 container_class = (GtkContainerClass*) class;
75 widget_class->realize = gtk_fixed_realize;
76 widget_class->size_request = gtk_fixed_size_request;
77 widget_class->size_allocate = gtk_fixed_size_allocate;
79 container_class->add = gtk_fixed_add;
80 container_class->remove = gtk_fixed_remove;
81 container_class->forall = gtk_fixed_forall;
82 container_class->child_type = gtk_fixed_child_type;
84 container_class->set_child_property = gtk_fixed_set_child_property;
85 container_class->get_child_property = gtk_fixed_get_child_property;
87 gtk_container_class_install_child_property (container_class,
89 g_param_spec_int ("x",
91 P_("X position of child widget"),
95 GTK_PARAM_READWRITE));
97 gtk_container_class_install_child_property (container_class,
99 g_param_spec_int ("y",
101 P_("Y position of child widget"),
105 GTK_PARAM_READWRITE));
109 gtk_fixed_child_type (GtkContainer *container)
111 return GTK_TYPE_WIDGET;
115 gtk_fixed_init (GtkFixed *fixed)
117 gtk_widget_set_has_window (GTK_WIDGET (fixed), FALSE);
119 fixed->children = NULL;
125 return g_object_new (GTK_TYPE_FIXED, NULL);
128 static GtkFixedChild*
129 get_child (GtkFixed *fixed,
134 children = fixed->children;
137 GtkFixedChild *child;
139 child = children->data;
140 children = children->next;
142 if (child->widget == widget)
150 gtk_fixed_put (GtkFixed *fixed,
155 GtkFixedChild *child_info;
157 g_return_if_fail (GTK_IS_FIXED (fixed));
158 g_return_if_fail (GTK_IS_WIDGET (widget));
160 child_info = g_new (GtkFixedChild, 1);
161 child_info->widget = widget;
165 gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
167 fixed->children = g_list_append (fixed->children, child_info);
171 gtk_fixed_move_internal (GtkFixed *fixed,
178 GtkFixedChild *child;
180 g_return_if_fail (GTK_IS_FIXED (fixed));
181 g_return_if_fail (GTK_IS_WIDGET (widget));
182 g_return_if_fail (widget->parent == GTK_WIDGET (fixed));
184 child = get_child (fixed, widget);
188 gtk_widget_freeze_child_notify (widget);
193 gtk_widget_child_notify (widget, "x");
199 gtk_widget_child_notify (widget, "y");
202 gtk_widget_thaw_child_notify (widget);
204 if (gtk_widget_get_visible (widget) &&
205 gtk_widget_get_visible (GTK_WIDGET (fixed)))
206 gtk_widget_queue_resize (GTK_WIDGET (fixed));
210 gtk_fixed_move (GtkFixed *fixed,
215 gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
219 gtk_fixed_set_child_property (GtkContainer *container,
228 gtk_fixed_move_internal (GTK_FIXED (container),
230 TRUE, g_value_get_int (value),
234 gtk_fixed_move_internal (GTK_FIXED (container),
237 TRUE, g_value_get_int (value));
240 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
246 gtk_fixed_get_child_property (GtkContainer *container,
252 GtkFixedChild *fixed_child;
254 fixed_child = get_child (GTK_FIXED (container), child);
259 g_value_set_int (value, fixed_child->x);
262 g_value_set_int (value, fixed_child->y);
265 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
271 gtk_fixed_realize (GtkWidget *widget)
273 GdkWindowAttr attributes;
274 gint attributes_mask;
276 if (!gtk_widget_get_has_window (widget))
277 GTK_WIDGET_CLASS (gtk_fixed_parent_class)->realize (widget);
280 gtk_widget_set_realized (widget, TRUE);
282 attributes.window_type = GDK_WINDOW_CHILD;
283 attributes.x = widget->allocation.x;
284 attributes.y = widget->allocation.y;
285 attributes.width = widget->allocation.width;
286 attributes.height = widget->allocation.height;
287 attributes.wclass = GDK_INPUT_OUTPUT;
288 attributes.visual = gtk_widget_get_visual (widget);
289 attributes.colormap = gtk_widget_get_colormap (widget);
290 attributes.event_mask = gtk_widget_get_events (widget);
291 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
293 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
295 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
297 gdk_window_set_user_data (widget->window, widget);
299 widget->style = gtk_style_attach (widget->style, widget->window);
300 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
305 gtk_fixed_size_request (GtkWidget *widget,
306 GtkRequisition *requisition)
309 GtkFixedChild *child;
311 GtkRequisition child_requisition;
313 fixed = GTK_FIXED (widget);
314 requisition->width = 0;
315 requisition->height = 0;
317 children = fixed->children;
320 child = children->data;
321 children = children->next;
323 if (gtk_widget_get_visible (child->widget))
325 gtk_widget_size_request (child->widget, &child_requisition);
327 requisition->height = MAX (requisition->height,
329 child_requisition.height);
330 requisition->width = MAX (requisition->width,
332 child_requisition.width);
336 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
337 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
341 gtk_fixed_size_allocate (GtkWidget *widget,
342 GtkAllocation *allocation)
345 GtkFixedChild *child;
346 GtkAllocation child_allocation;
347 GtkRequisition child_requisition;
349 guint16 border_width;
351 fixed = GTK_FIXED (widget);
353 widget->allocation = *allocation;
355 if (gtk_widget_get_has_window (widget))
357 if (gtk_widget_get_realized (widget))
358 gdk_window_move_resize (widget->window,
365 border_width = GTK_CONTAINER (fixed)->border_width;
367 children = fixed->children;
370 child = children->data;
371 children = children->next;
373 if (gtk_widget_get_visible (child->widget))
375 gtk_widget_get_child_requisition (child->widget, &child_requisition);
376 child_allocation.x = child->x + border_width;
377 child_allocation.y = child->y + border_width;
379 if (!gtk_widget_get_has_window (widget))
381 child_allocation.x += widget->allocation.x;
382 child_allocation.y += widget->allocation.y;
385 child_allocation.width = child_requisition.width;
386 child_allocation.height = child_requisition.height;
387 gtk_widget_size_allocate (child->widget, &child_allocation);
393 gtk_fixed_add (GtkContainer *container,
396 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
400 gtk_fixed_remove (GtkContainer *container,
404 GtkFixedChild *child;
405 GtkWidget *widget_container;
408 fixed = GTK_FIXED (container);
409 widget_container = GTK_WIDGET (container);
411 children = fixed->children;
414 child = children->data;
416 if (child->widget == widget)
418 gboolean was_visible = gtk_widget_get_visible (widget);
420 gtk_widget_unparent (widget);
422 fixed->children = g_list_remove_link (fixed->children, children);
423 g_list_free (children);
426 if (was_visible && gtk_widget_get_visible (widget_container))
427 gtk_widget_queue_resize (widget_container);
432 children = children->next;
437 gtk_fixed_forall (GtkContainer *container,
438 gboolean include_internals,
439 GtkCallback callback,
440 gpointer callback_data)
442 GtkFixed *fixed = GTK_FIXED (container);
443 GtkFixedChild *child;
446 children = fixed->children;
449 child = children->data;
450 children = children->next;
452 (* callback) (child->widget, callback_data);
457 * gtk_fixed_set_has_window:
458 * @fixed: a #GtkFixed
459 * @has_window: %TRUE if a separate window should be created
461 * Sets whether a #GtkFixed widget is created with a separate
462 * #GdkWindow for @widget->window or not. (By default, it will be
463 * created with no separate #GdkWindow). This function must be called
464 * while the #GtkFixed is not realized, for instance, immediately after the
467 * This function was added to provide an easy migration path for
468 * older applications which may expect #GtkFixed to have a separate window.
470 * Deprecated: 2.20: Use gtk_widget_set_has_window() instead.
473 gtk_fixed_set_has_window (GtkFixed *fixed,
476 g_return_if_fail (GTK_IS_FIXED (fixed));
477 g_return_if_fail (!gtk_widget_get_realized (GTK_WIDGET (fixed)));
479 if (has_window != gtk_widget_get_has_window (GTK_WIDGET (fixed)))
481 gtk_widget_set_has_window (GTK_WIDGET (fixed), has_window);
486 * gtk_fixed_get_has_window:
487 * @fixed: a #GtkWidget
489 * Gets whether the #GtkFixed has its own #GdkWindow.
490 * See gtk_fixed_set_has_window().
492 * Return value: %TRUE if @fixed has its own window.
494 * Deprecated: 2.20: Use gtk_widget_get_has_window() instead.
497 gtk_fixed_get_has_window (GtkFixed *fixed)
499 g_return_val_if_fail (GTK_IS_FIXED (fixed), FALSE);
501 return gtk_widget_get_has_window (GTK_WIDGET (fixed));
504 #define __GTK_FIXED_C__
505 #include "gtkaliasdef.c"