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_FLAGS (fixed, GTK_NO_WINDOW);
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_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
205 gtk_widget_queue_resize (GTK_WIDGET (fixed));
209 gtk_fixed_move (GtkFixed *fixed,
214 gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
218 gtk_fixed_set_child_property (GtkContainer *container,
227 gtk_fixed_move_internal (GTK_FIXED (container),
229 TRUE, g_value_get_int (value),
233 gtk_fixed_move_internal (GTK_FIXED (container),
236 TRUE, g_value_get_int (value));
239 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
245 gtk_fixed_get_child_property (GtkContainer *container,
251 GtkFixedChild *fixed_child;
253 fixed_child = get_child (GTK_FIXED (container), child);
258 g_value_set_int (value, fixed_child->x);
261 g_value_set_int (value, fixed_child->y);
264 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
270 gtk_fixed_realize (GtkWidget *widget)
272 GdkWindowAttr attributes;
273 gint attributes_mask;
275 if (GTK_WIDGET_NO_WINDOW (widget))
276 GTK_WIDGET_CLASS (gtk_fixed_parent_class)->realize (widget);
279 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
281 attributes.window_type = GDK_WINDOW_CHILD;
282 attributes.x = widget->allocation.x;
283 attributes.y = widget->allocation.y;
284 attributes.width = widget->allocation.width;
285 attributes.height = widget->allocation.height;
286 attributes.wclass = GDK_INPUT_OUTPUT;
287 attributes.visual = gtk_widget_get_visual (widget);
288 attributes.colormap = gtk_widget_get_colormap (widget);
289 attributes.event_mask = gtk_widget_get_events (widget);
290 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
292 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
294 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
296 gdk_window_set_user_data (widget->window, widget);
298 widget->style = gtk_style_attach (widget->style, widget->window);
299 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
304 gtk_fixed_size_request (GtkWidget *widget,
305 GtkRequisition *requisition)
308 GtkFixedChild *child;
310 GtkRequisition child_requisition;
312 fixed = GTK_FIXED (widget);
313 requisition->width = 0;
314 requisition->height = 0;
316 children = fixed->children;
319 child = children->data;
320 children = children->next;
322 if (GTK_WIDGET_VISIBLE (child->widget))
324 gtk_widget_size_request (child->widget, &child_requisition);
326 requisition->height = MAX (requisition->height,
328 child_requisition.height);
329 requisition->width = MAX (requisition->width,
331 child_requisition.width);
335 requisition->height += GTK_CONTAINER (fixed)->border_width * 2;
336 requisition->width += GTK_CONTAINER (fixed)->border_width * 2;
340 gtk_fixed_size_allocate (GtkWidget *widget,
341 GtkAllocation *allocation)
344 GtkFixedChild *child;
345 GtkAllocation child_allocation;
346 GtkRequisition child_requisition;
348 guint16 border_width;
350 fixed = GTK_FIXED (widget);
352 widget->allocation = *allocation;
354 if (!GTK_WIDGET_NO_WINDOW (widget))
356 if (GTK_WIDGET_REALIZED (widget))
357 gdk_window_move_resize (widget->window,
364 border_width = GTK_CONTAINER (fixed)->border_width;
366 children = fixed->children;
369 child = children->data;
370 children = children->next;
372 if (GTK_WIDGET_VISIBLE (child->widget))
374 gtk_widget_get_child_requisition (child->widget, &child_requisition);
375 child_allocation.x = child->x + border_width;
376 child_allocation.y = child->y + border_width;
378 if (GTK_WIDGET_NO_WINDOW (widget))
380 child_allocation.x += widget->allocation.x;
381 child_allocation.y += widget->allocation.y;
384 child_allocation.width = child_requisition.width;
385 child_allocation.height = child_requisition.height;
386 gtk_widget_size_allocate (child->widget, &child_allocation);
392 gtk_fixed_add (GtkContainer *container,
395 gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
399 gtk_fixed_remove (GtkContainer *container,
403 GtkFixedChild *child;
406 fixed = GTK_FIXED (container);
408 children = fixed->children;
411 child = children->data;
413 if (child->widget == widget)
415 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
417 gtk_widget_unparent (widget);
419 fixed->children = g_list_remove_link (fixed->children, children);
420 g_list_free (children);
423 if (was_visible && GTK_WIDGET_VISIBLE (container))
424 gtk_widget_queue_resize (GTK_WIDGET (container));
429 children = children->next;
434 gtk_fixed_forall (GtkContainer *container,
435 gboolean include_internals,
436 GtkCallback callback,
437 gpointer callback_data)
440 GtkFixedChild *child;
443 g_return_if_fail (callback != NULL);
445 fixed = GTK_FIXED (container);
447 children = fixed->children;
450 child = children->data;
451 children = children->next;
453 (* callback) (child->widget, callback_data);
458 * gtk_fixed_set_has_window:
459 * @fixed: a #GtkFixed
460 * @has_window: %TRUE if a separate window should be created
462 * Sets whether a #GtkFixed widget is created with a separate
463 * #GdkWindow for @widget->window or not. (By default, it will be
464 * created with no separate #GdkWindow). This function must be called
465 * while the #GtkFixed is not realized, for instance, immediately after the
468 * This function was added to provide an easy migration path for
469 * older applications which may expect #GtkFixed to have a separate window.
472 gtk_fixed_set_has_window (GtkFixed *fixed,
475 g_return_if_fail (GTK_IS_FIXED (fixed));
476 g_return_if_fail (!GTK_WIDGET_REALIZED (fixed));
478 if (!has_window != GTK_WIDGET_NO_WINDOW (fixed))
481 GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
483 GTK_WIDGET_SET_FLAGS (fixed, GTK_NO_WINDOW);
488 * gtk_fixed_get_has_window:
489 * @fixed: a #GtkWidget
491 * Gets whether the #GtkFixed has its own #GdkWindow.
492 * See gdk_fixed_set_has_window().
494 * Return value: %TRUE if @fixed has its own window.
497 gtk_fixed_get_has_window (GtkFixed *fixed)
499 g_return_val_if_fail (GTK_IS_FIXED (fixed), FALSE);
501 return !GTK_WIDGET_NO_WINDOW (fixed);
504 #define __GTK_FIXED_C__
505 #include "gtkaliasdef.c"