1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998 Elliot Lee
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
24 #include "gtkhandlebox.h"
26 #include "gtksignal.h"
27 #include "gtkwindow.h"
34 #define DRAG_HANDLE_SIZE 10
35 #define CHILDLESS_SIZE 25
36 #define GHOST_HEIGHT 3
40 SIGNAL_CHILD_ATTACHED,
41 SIGNAL_CHILD_DETACHED,
45 static void gtk_handle_box_class_init (GtkHandleBoxClass *klass);
46 static void gtk_handle_box_init (GtkHandleBox *handle_box);
47 static void gtk_handle_box_set_arg (GtkObject *object,
50 static void gtk_handle_box_get_arg (GtkObject *object,
53 static void gtk_handle_box_destroy (GtkObject *object);
54 static void gtk_handle_box_map (GtkWidget *widget);
55 static void gtk_handle_box_unmap (GtkWidget *widget);
56 static void gtk_handle_box_realize (GtkWidget *widget);
57 static void gtk_handle_box_unrealize (GtkWidget *widget);
58 static void gtk_handle_box_style_set (GtkWidget *widget,
59 GtkStyle *previous_style);
60 static void gtk_handle_box_size_request (GtkWidget *widget,
61 GtkRequisition *requisition);
62 static void gtk_handle_box_size_allocate (GtkWidget *widget,
63 GtkAllocation *real_allocation);
64 static void gtk_handle_box_add (GtkContainer *container,
66 static void gtk_handle_box_remove (GtkContainer *container,
68 static void gtk_handle_box_draw_ghost (GtkHandleBox *hb);
69 static void gtk_handle_box_paint (GtkWidget *widget,
70 GdkEventExpose *event,
72 static void gtk_handle_box_draw (GtkWidget *widget,
74 static gint gtk_handle_box_expose (GtkWidget *widget,
75 GdkEventExpose *event);
76 static gint gtk_handle_box_button_changed (GtkWidget *widget,
77 GdkEventButton *event);
78 static gint gtk_handle_box_motion (GtkWidget *widget,
79 GdkEventMotion *event);
80 static gint gtk_handle_box_delete_event (GtkWidget *widget,
84 static GtkBinClass *parent_class;
85 static guint handle_box_signals[SIGNAL_LAST] = { 0 };
89 gtk_handle_box_get_type (void)
91 static guint handle_box_type = 0;
95 static const GtkTypeInfo handle_box_info =
98 sizeof (GtkHandleBox),
99 sizeof (GtkHandleBoxClass),
100 (GtkClassInitFunc) gtk_handle_box_class_init,
101 (GtkObjectInitFunc) gtk_handle_box_init,
102 /* reserved_1 */ NULL,
103 /* reserved_2 */ NULL,
104 (GtkClassInitFunc) NULL,
107 handle_box_type = gtk_type_unique (gtk_bin_get_type (), &handle_box_info);
110 return handle_box_type;
114 gtk_handle_box_class_init (GtkHandleBoxClass *class)
116 GtkObjectClass *object_class;
117 GtkWidgetClass *widget_class;
118 GtkContainerClass *container_class;
120 object_class = (GtkObjectClass *) class;
121 widget_class = (GtkWidgetClass *) class;
122 container_class = (GtkContainerClass *) class;
124 parent_class = gtk_type_class (gtk_bin_get_type ());
126 gtk_object_add_arg_type ("GtkHandleBox::shadow", GTK_TYPE_SHADOW_TYPE, GTK_ARG_READWRITE, ARG_SHADOW);
128 object_class->set_arg = gtk_handle_box_set_arg;
129 object_class->get_arg = gtk_handle_box_get_arg;
131 handle_box_signals[SIGNAL_CHILD_ATTACHED] =
132 gtk_signal_new ("child_attached",
135 GTK_SIGNAL_OFFSET (GtkHandleBoxClass, child_attached),
136 gtk_marshal_NONE__POINTER,
139 handle_box_signals[SIGNAL_CHILD_DETACHED] =
140 gtk_signal_new ("child_detached",
143 GTK_SIGNAL_OFFSET (GtkHandleBoxClass, child_detached),
144 gtk_marshal_NONE__POINTER,
147 gtk_object_class_add_signals (object_class, handle_box_signals, SIGNAL_LAST);
149 object_class->destroy = gtk_handle_box_destroy;
151 widget_class->map = gtk_handle_box_map;
152 widget_class->unmap = gtk_handle_box_unmap;
153 widget_class->realize = gtk_handle_box_realize;
154 widget_class->unrealize = gtk_handle_box_unrealize;
155 widget_class->style_set = gtk_handle_box_style_set;
156 widget_class->size_request = gtk_handle_box_size_request;
157 widget_class->size_allocate = gtk_handle_box_size_allocate;
158 widget_class->draw = gtk_handle_box_draw;
159 widget_class->expose_event = gtk_handle_box_expose;
160 widget_class->button_press_event = gtk_handle_box_button_changed;
161 widget_class->button_release_event = gtk_handle_box_button_changed;
162 widget_class->motion_notify_event = gtk_handle_box_motion;
163 widget_class->delete_event = gtk_handle_box_delete_event;
165 container_class->add = gtk_handle_box_add;
166 container_class->remove = gtk_handle_box_remove;
168 class->child_attached = NULL;
169 class->child_detached = NULL;
173 gtk_handle_box_init (GtkHandleBox *handle_box)
175 GTK_WIDGET_UNSET_FLAGS (handle_box, GTK_NO_WINDOW);
177 handle_box->bin_window = NULL;
178 handle_box->float_window = NULL;
179 handle_box->shadow_type = GTK_SHADOW_OUT;
180 handle_box->handle_position = GTK_POS_LEFT;
181 handle_box->float_window_mapped = FALSE;
182 handle_box->child_detached = FALSE;
183 handle_box->in_drag = FALSE;
184 handle_box->shrink_on_detach = TRUE;
185 handle_box->dragoff_x = 0;
186 handle_box->dragoff_y = 0;
190 gtk_handle_box_set_arg (GtkObject *object,
194 GtkHandleBox *handle_box;
196 handle_box = GTK_HANDLE_BOX (object);
201 gtk_handle_box_set_shadow_type (handle_box, GTK_VALUE_ENUM (*arg));
209 gtk_handle_box_get_arg (GtkObject *object,
213 GtkHandleBox *handle_box;
215 handle_box = GTK_HANDLE_BOX (object);
220 GTK_VALUE_ENUM (*arg) = handle_box->shadow_type;
223 arg->type = GTK_TYPE_INVALID;
229 gtk_handle_box_new (void)
231 return GTK_WIDGET (gtk_type_new (gtk_handle_box_get_type ()));
235 gtk_handle_box_destroy (GtkObject *object)
239 g_return_if_fail (object != NULL);
240 g_return_if_fail (GTK_IS_HANDLE_BOX (object));
242 hb = GTK_HANDLE_BOX (object);
244 if (GTK_OBJECT_CLASS (parent_class)->destroy)
245 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
249 gtk_handle_box_map (GtkWidget *widget)
254 g_return_if_fail (widget != NULL);
255 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
257 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
259 bin = GTK_BIN (widget);
260 hb = GTK_HANDLE_BOX (widget);
263 GTK_WIDGET_VISIBLE (bin->child) &&
264 !GTK_WIDGET_MAPPED (bin->child))
265 gtk_widget_map (bin->child);
267 if (hb->child_detached && !hb->float_window_mapped)
269 gdk_window_show (hb->float_window);
270 hb->float_window_mapped = TRUE;
273 gdk_window_show (hb->bin_window);
274 gdk_window_show (widget->window);
278 gtk_handle_box_unmap (GtkWidget *widget)
282 g_return_if_fail (widget != NULL);
283 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
285 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
287 hb = GTK_HANDLE_BOX (widget);
289 gdk_window_hide (widget->window);
290 if (hb->float_window_mapped)
292 gdk_window_hide (hb->float_window);
293 hb->float_window_mapped = FALSE;
298 gtk_handle_box_realize (GtkWidget *widget)
300 GdkWindowAttr attributes;
301 gint attributes_mask;
304 g_return_if_fail (widget != NULL);
305 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
307 hb = GTK_HANDLE_BOX (widget);
309 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
311 attributes.x = widget->allocation.x;
312 attributes.y = widget->allocation.y;
313 attributes.width = widget->allocation.width;
314 attributes.height = widget->allocation.height;
315 attributes.window_type = GDK_WINDOW_CHILD;
316 attributes.wclass = GDK_INPUT_OUTPUT;
317 attributes.visual = gtk_widget_get_visual (widget);
318 attributes.colormap = gtk_widget_get_colormap (widget);
319 attributes.event_mask = (gtk_widget_get_events (widget)
320 | GDK_EXPOSURE_MASK);
321 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
322 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
323 gdk_window_set_user_data (widget->window, widget);
327 attributes.width = widget->allocation.width;
328 attributes.height = widget->allocation.height;
329 attributes.window_type = GDK_WINDOW_CHILD;
330 attributes.event_mask |= (gtk_widget_get_events (widget) |
332 GDK_BUTTON1_MOTION_MASK |
333 GDK_POINTER_MOTION_HINT_MASK |
334 GDK_BUTTON_PRESS_MASK |
335 GDK_BUTTON_RELEASE_MASK);
336 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
337 hb->bin_window = gdk_window_new (widget->window, &attributes, attributes_mask);
338 gdk_window_set_user_data (hb->bin_window, widget);
339 if (GTK_BIN (hb)->child)
340 gtk_widget_set_parent_window (GTK_BIN (hb)->child, hb->bin_window);
344 attributes.width = widget->requisition.width;
345 attributes.height = widget->requisition.height;
346 attributes.window_type = GDK_WINDOW_TOPLEVEL;
347 attributes.wclass = GDK_INPUT_OUTPUT;
348 attributes.visual = gtk_widget_get_visual (widget);
349 attributes.colormap = gtk_widget_get_colormap (widget);
350 attributes.event_mask = (gtk_widget_get_events (widget) |
352 GDK_ENTER_NOTIFY_MASK |
353 GDK_LEAVE_NOTIFY_MASK |
354 GDK_FOCUS_CHANGE_MASK |
356 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
357 hb->float_window = gdk_window_new (NULL, &attributes, attributes_mask);
358 gdk_window_set_user_data (hb->float_window, widget);
359 gdk_window_set_decorations (hb->float_window, 0);
361 widget->style = gtk_style_attach (widget->style, widget->window);
362 gtk_style_set_background (widget->style, widget->window, GTK_WIDGET_STATE (hb));
363 gtk_style_set_background (widget->style, hb->bin_window, GTK_WIDGET_STATE (hb));
364 gtk_style_set_background (widget->style, hb->float_window, GTK_WIDGET_STATE (hb));
365 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
369 gtk_handle_box_unrealize (GtkWidget *widget)
373 g_return_if_fail (widget != NULL);
374 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
376 hb = GTK_HANDLE_BOX (widget);
378 gdk_window_set_user_data (hb->bin_window, NULL);
379 gdk_window_destroy (hb->bin_window);
380 hb->bin_window = NULL;
381 gdk_window_set_user_data (hb->float_window, NULL);
382 gdk_window_destroy (hb->float_window);
383 hb->float_window = NULL;
385 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
386 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
390 gtk_handle_box_style_set (GtkWidget *widget,
391 GtkStyle *previous_style)
395 g_return_if_fail (widget != NULL);
396 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
398 hb = GTK_HANDLE_BOX (widget);
400 if (GTK_WIDGET_REALIZED (widget) &&
401 !GTK_WIDGET_NO_WINDOW (widget))
403 gtk_style_set_background (widget->style, widget->window,
405 gtk_style_set_background (widget->style, hb->bin_window, widget->state);
406 gtk_style_set_background (widget->style, hb->float_window, widget->state);
407 if (GTK_WIDGET_DRAWABLE (widget))
408 gdk_window_clear (widget->window);
413 gtk_handle_box_size_request (GtkWidget *widget,
414 GtkRequisition *requisition)
418 GtkRequisition child_requisition;
420 g_return_if_fail (widget != NULL);
421 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
422 g_return_if_fail (requisition != NULL);
424 bin = GTK_BIN (widget);
425 hb = GTK_HANDLE_BOX (widget);
427 if (hb->handle_position == GTK_POS_LEFT ||
428 hb->handle_position == GTK_POS_RIGHT)
430 requisition->width = DRAG_HANDLE_SIZE;
431 requisition->height = 0;
435 requisition->width = 0;
436 requisition->height = DRAG_HANDLE_SIZE;
439 /* if our child is not visible, we still request its size, since we
440 * won't have any usefull hint for our size otherwise.
443 gtk_widget_size_request (bin->child, &child_requisition);
445 if (hb->child_detached)
447 if (!hb->shrink_on_detach)
449 if (hb->handle_position == GTK_POS_LEFT ||
450 hb->handle_position == GTK_POS_RIGHT)
451 requisition->height += child_requisition.height;
453 requisition->width += child_requisition.width;
457 if (hb->handle_position == GTK_POS_LEFT ||
458 hb->handle_position == GTK_POS_RIGHT)
459 requisition->height += widget->style->klass->ythickness;
461 requisition->width += widget->style->klass->xthickness;
466 requisition->width += GTK_CONTAINER (widget)->border_width * 2;
467 requisition->height += GTK_CONTAINER (widget)->border_width * 2;
471 requisition->width += child_requisition.width;
472 requisition->height += child_requisition.height;
476 requisition->width += CHILDLESS_SIZE;
477 requisition->height += CHILDLESS_SIZE;
483 gtk_handle_box_size_allocate (GtkWidget *widget,
484 GtkAllocation *allocation)
488 GtkRequisition child_requisition;
490 g_return_if_fail (widget != NULL);
491 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
492 g_return_if_fail (allocation != NULL);
494 bin = GTK_BIN (widget);
495 hb = GTK_HANDLE_BOX (widget);
497 widget->allocation.x = allocation->x;
500 gtk_widget_get_child_requisition (bin->child, &child_requisition);
503 child_requisition.width = 0;
504 child_requisition.height = 0;
507 if (hb->child_detached)
509 guint max_req_height;
512 max_req_height = MAX (widget->requisition.height,
513 child_requisition.height +
514 2 * widget->style->klass->ythickness);
515 max_req_width = MAX (widget->requisition.width,
516 child_requisition.width +
517 2 * widget->style->klass->xthickness);
519 if (allocation->height > max_req_height)
520 widget->allocation.y = allocation->y +
521 (allocation->height - max_req_height) / 2;
523 widget->allocation.y = allocation->y;
525 widget->allocation.height = MIN (allocation->height, max_req_height);
526 widget->allocation.width = MIN (allocation->width, max_req_width);
530 widget->allocation = *allocation;
533 if (GTK_WIDGET_REALIZED (hb))
534 gdk_window_move_resize (widget->window,
535 widget->allocation.x,
536 widget->allocation.y,
537 widget->allocation.width,
538 widget->allocation.height);
541 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
544 GtkAllocation child_allocation;
548 border_width = GTK_CONTAINER (widget)->border_width;
550 child_allocation.x = border_width;
551 child_allocation.y = border_width;
552 if (hb->handle_position == GTK_POS_LEFT)
553 child_allocation.x += DRAG_HANDLE_SIZE;
554 else if (hb->handle_position == GTK_POS_TOP)
555 child_allocation.y += DRAG_HANDLE_SIZE;
557 if (hb->child_detached)
562 child_allocation.width = child_requisition.width;
563 child_allocation.height = child_requisition.height;
565 float_width = child_allocation.width + 2 * border_width;
566 float_height = child_allocation.height + 2 * border_width;
568 if (hb->handle_position == GTK_POS_LEFT ||
569 hb->handle_position == GTK_POS_RIGHT)
570 float_width += DRAG_HANDLE_SIZE;
572 float_height += DRAG_HANDLE_SIZE;
574 if (GTK_WIDGET_REALIZED (hb))
576 gdk_window_resize (hb->float_window,
579 gdk_window_move_resize (hb->bin_window,
588 child_allocation.width = MAX (1, (gint)widget->allocation.width - 2 * border_width);
589 child_allocation.height = MAX (1, (gint)widget->allocation.height - 2 * border_width);
591 if (hb->handle_position == GTK_POS_LEFT ||
592 hb->handle_position == GTK_POS_RIGHT)
593 child_allocation.width -= DRAG_HANDLE_SIZE;
595 child_allocation.height -= DRAG_HANDLE_SIZE;
597 if (GTK_WIDGET_REALIZED (hb))
598 gdk_window_move_resize (hb->bin_window,
601 widget->allocation.width,
602 widget->allocation.height);
605 gtk_widget_size_allocate (bin->child, &child_allocation);
610 gtk_handle_box_draw_ghost (GtkHandleBox *hb)
618 widget = GTK_WIDGET (hb);
620 if (hb->handle_position == GTK_POS_LEFT ||
621 hb->handle_position == GTK_POS_RIGHT)
623 x = hb->handle_position == GTK_POS_LEFT ? 0 : widget->allocation.width;
625 width = DRAG_HANDLE_SIZE;
626 height = widget->allocation.height;
631 y = hb->handle_position == GTK_POS_TOP ? 0 : widget->allocation.height;
632 width = widget->allocation.width;
633 height = DRAG_HANDLE_SIZE;
635 gtk_paint_shadow (widget->style,
637 GTK_WIDGET_STATE (widget),
638 GTK_SHADOW_ETCHED_IN,
639 NULL, widget, "handle",
644 if (hb->handle_position == GTK_POS_LEFT ||
645 hb->handle_position == GTK_POS_RIGHT)
646 gtk_paint_hline (widget->style,
648 GTK_WIDGET_STATE (widget),
649 NULL, widget, "handlebox",
650 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : widget->allocation.width - DRAG_HANDLE_SIZE,
651 widget->allocation.width - DRAG_HANDLE_SIZE,
652 widget->allocation.height / 2);
654 gtk_paint_vline (widget->style,
656 GTK_WIDGET_STATE (widget),
657 NULL, widget, "handlebox",
658 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : widget->allocation.height - DRAG_HANDLE_SIZE,
659 widget->allocation.height - DRAG_HANDLE_SIZE,
660 widget->allocation.width / 2);
664 draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow,
667 gtk_paint_handle(widget->style, window, GTK_STATE_NORMAL, shadow,
668 NULL, widget, "handlebox",
669 rect->x, rect->y, rect->width, rect->height,
670 GTK_ORIENTATION_VERTICAL);
674 gtk_handle_box_set_shadow_type (GtkHandleBox *handle_box,
677 g_return_if_fail (handle_box != NULL);
678 g_return_if_fail (GTK_IS_HANDLE_BOX (handle_box));
680 if ((GtkShadowType) handle_box->shadow_type != type)
682 handle_box->shadow_type = type;
684 if (GTK_WIDGET_DRAWABLE (handle_box))
686 gtk_widget_queue_clear (GTK_WIDGET (handle_box));
688 gtk_widget_queue_resize (GTK_WIDGET (handle_box));
693 gtk_handle_box_paint (GtkWidget *widget,
694 GdkEventExpose *event,
704 bin = GTK_BIN (widget);
705 hb = GTK_HANDLE_BOX (widget);
707 border_width = GTK_CONTAINER (hb)->border_width;
709 if (hb->child_detached)
711 width = bin->child->allocation.width + 2 * border_width;
712 height = bin->child->allocation.height + 2 * border_width;
714 else if (hb->handle_position == GTK_POS_LEFT ||
715 hb->handle_position == GTK_POS_RIGHT)
717 width = widget->allocation.width - DRAG_HANDLE_SIZE;
718 height = widget->allocation.height;
722 width = widget->allocation.width;
723 height = widget->allocation.height - DRAG_HANDLE_SIZE;
727 gtk_paint_box(widget->style,
729 GTK_WIDGET_STATE (widget),
731 area, widget, "handlebox_bin",
734 gtk_paint_box(widget->style,
736 GTK_WIDGET_STATE (widget),
738 &event->area, widget, "handlebox_bin",
741 /* We currently draw the handle _above_ the relief of the handlebox.
742 * it could also be drawn on the same level...
744 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
745 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
751 rect.width = (hb->handle_position == GTK_POS_LEFT) ? DRAG_HANDLE_SIZE : width;
752 rect.height = (hb->handle_position == GTK_POS_TOP) ? DRAG_HANDLE_SIZE : height;
754 draw_textured_frame (widget, hb->bin_window, &rect, GTK_SHADOW_OUT, event ? &event->area : area);
756 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
758 GdkRectangle child_area;
759 GdkEventExpose child_event;
761 if (!event) /* we were called from draw() */
763 if (gtk_widget_intersect (bin->child, area, &child_area))
764 gtk_widget_draw (bin->child, &child_area);
766 else /* we were called from expose() */
768 child_event = *event;
770 if (GTK_WIDGET_NO_WINDOW (bin->child) &&
771 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
772 gtk_widget_event (bin->child, (GdkEvent *) &child_event);
778 gtk_handle_box_draw (GtkWidget *widget,
783 g_return_if_fail (widget != NULL);
784 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
785 g_return_if_fail (area != NULL);
787 hb = GTK_HANDLE_BOX (widget);
789 if (GTK_WIDGET_DRAWABLE (widget))
791 if (hb->child_detached)
793 /* The area parameter does not make sense in this case, so we
794 * repaint everything.
797 gtk_handle_box_draw_ghost (hb);
801 area->width = 2 * GTK_CONTAINER (hb)->border_width + DRAG_HANDLE_SIZE;
802 area->height = area->width + GTK_BIN (hb)->child->allocation.height;
803 area->width += GTK_BIN (hb)->child->allocation.width;
805 gtk_handle_box_paint (widget, NULL, area);
808 gtk_handle_box_paint (widget, NULL, area);
813 gtk_handle_box_expose (GtkWidget *widget,
814 GdkEventExpose *event)
818 g_return_val_if_fail (widget != NULL, FALSE);
819 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
820 g_return_val_if_fail (event != NULL, FALSE);
822 if (GTK_WIDGET_DRAWABLE (widget))
824 hb = GTK_HANDLE_BOX (widget);
826 if (event->window == widget->window)
828 if (hb->child_detached)
829 gtk_handle_box_draw_ghost (hb);
832 gtk_handle_box_paint (widget, event, NULL);
839 gtk_handle_box_button_changed (GtkWidget *widget,
840 GdkEventButton *event)
843 gboolean event_handled;
846 g_return_val_if_fail (widget != NULL, FALSE);
847 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
848 g_return_val_if_fail (event != NULL, FALSE);
850 hb = GTK_HANDLE_BOX (widget);
852 if (event->window != hb->bin_window)
855 event_handled = FALSE;
856 if (event->button == 1 &&
857 event->type == GDK_BUTTON_PRESS)
862 child = GTK_BIN (hb)->child;
864 switch (hb->handle_position)
867 in_handle = event->x < DRAG_HANDLE_SIZE;
870 in_handle = event->y < DRAG_HANDLE_SIZE;
873 in_handle = event->x > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.width;
876 in_handle = event->y > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.height;
886 event_handled = TRUE;
891 hb->dragoff_x = event->x;
892 hb->dragoff_y = event->y;
894 gtk_grab_add (widget);
896 fleur = gdk_cursor_new (GDK_FLEUR);
897 while (gdk_pointer_grab (hb->bin_window,
899 (GDK_BUTTON1_MOTION_MASK |
900 GDK_POINTER_MOTION_HINT_MASK |
901 GDK_BUTTON_RELEASE_MASK),
904 GDK_CURRENT_TIME) != 0); /* wait for success */
905 gdk_cursor_destroy (fleur);
906 event_handled = TRUE;
909 else if (event->type == GDK_BUTTON_RELEASE &&
912 gdk_pointer_ungrab (GDK_CURRENT_TIME);
913 gtk_grab_remove (widget);
915 event_handled = TRUE;
918 return event_handled;
922 gtk_handle_box_motion (GtkWidget *widget,
923 GdkEventMotion *event)
932 g_return_val_if_fail (widget != NULL, FALSE);
933 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
934 g_return_val_if_fail (event != NULL, FALSE);
936 hb = GTK_HANDLE_BOX (widget);
940 if (event->window != hb->bin_window)
945 gdk_window_get_deskrelative_origin (hb->float_window, &ox, &oy);
948 gdk_window_get_pointer (hb->float_window, &new_x, &new_y, NULL);
951 new_x -= hb->dragoff_x;
952 new_y -= hb->dragoff_y;
955 gdk_window_get_pointer (widget->window, &snap_x, &snap_y, NULL);
957 switch (hb->handle_position)
960 in_handle = (snap_x >= 0 && snap_x <= DRAG_HANDLE_SIZE &&
961 snap_y >= 0 && snap_y <= widget->allocation.height);
964 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
965 snap_y >= 0 && snap_y <= DRAG_HANDLE_SIZE);
968 in_handle = (snap_x >= widget->allocation.width - DRAG_HANDLE_SIZE && snap_x <= widget->allocation.width &&
969 snap_y >= 0 && snap_y <= widget->allocation.height);
972 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
973 snap_y >= widget->allocation.height - DRAG_HANDLE_SIZE && snap_y <= widget->allocation.height);
982 if (hb->child_detached)
984 gdk_pointer_ungrab (GDK_CURRENT_TIME);
986 hb->child_detached = FALSE;
987 gdk_window_hide (hb->float_window);
988 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
989 hb->float_window_mapped = FALSE;
990 gtk_signal_emit (GTK_OBJECT (hb),
991 handle_box_signals[SIGNAL_CHILD_ATTACHED],
992 GTK_BIN (hb)->child);
994 fleur = gdk_cursor_new (GDK_FLEUR);
995 while (gdk_pointer_grab (hb->bin_window,
997 (GDK_BUTTON1_MOTION_MASK |
998 GDK_POINTER_MOTION_HINT_MASK |
999 GDK_BUTTON_RELEASE_MASK),
1002 GDK_CURRENT_TIME) != 0); /* wait for success */
1003 gdk_cursor_destroy (fleur);
1005 gtk_widget_queue_resize (widget);
1010 if (hb->child_detached)
1012 gdk_window_move (hb->float_window, new_x, new_y);
1013 gdk_window_raise (hb->float_window);
1020 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1022 hb->child_detached = TRUE;
1025 gdk_window_get_size (hb->bin_window, &width, &height);
1026 gdk_window_move_resize (hb->float_window, new_x, new_y, width, height);
1027 gdk_window_reparent (hb->bin_window, hb->float_window, 0, 0);
1028 gdk_window_set_hints (hb->float_window, new_x, new_y, 0, 0, 0, 0, GDK_HINT_POS);
1029 gdk_window_show (hb->float_window);
1030 hb->float_window_mapped = TRUE;
1032 /* this extra move is neccessary if we use decorations, or our
1033 * window manager insists on decorations.
1036 gdk_window_move (hb->float_window, new_x, new_y);
1039 gtk_signal_emit (GTK_OBJECT (hb),
1040 handle_box_signals[SIGNAL_CHILD_DETACHED],
1041 GTK_BIN (hb)->child);
1042 gtk_handle_box_draw_ghost (hb);
1044 fleur = gdk_cursor_new (GDK_FLEUR);
1045 while (gdk_pointer_grab (hb->bin_window,
1047 (GDK_BUTTON1_MOTION_MASK |
1048 GDK_POINTER_MOTION_HINT_MASK |
1049 GDK_BUTTON_RELEASE_MASK),
1052 GDK_CURRENT_TIME) != 0); /* wait for success */
1053 gdk_cursor_destroy (fleur);
1055 gtk_widget_queue_resize (widget);
1063 gtk_handle_box_add (GtkContainer *container,
1066 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1067 g_return_if_fail (GTK_BIN (container)->child == NULL);
1068 g_return_if_fail (widget->parent == NULL);
1070 gtk_widget_set_parent_window (widget, GTK_HANDLE_BOX (container)->bin_window);
1071 GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
1075 gtk_handle_box_remove (GtkContainer *container,
1080 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1081 g_return_if_fail (GTK_BIN (container)->child == widget);
1083 hb = GTK_HANDLE_BOX (container);
1085 if (hb->child_detached)
1087 hb->child_detached = FALSE;
1088 if (GTK_WIDGET_REALIZED (hb))
1090 gdk_window_hide (hb->float_window);
1091 gdk_window_reparent (hb->bin_window, GTK_WIDGET (hb)->window, 0, 0);
1093 hb->float_window_mapped = FALSE;
1097 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1098 gtk_grab_remove (GTK_WIDGET (container));
1099 hb->in_drag = FALSE;
1102 GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
1106 gtk_handle_box_delete_event (GtkWidget *widget,
1111 g_return_val_if_fail (widget != NULL, FALSE);
1112 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
1113 g_return_val_if_fail (event != NULL, FALSE);
1115 hb = GTK_HANDLE_BOX (widget);
1116 g_return_val_if_fail (event->window == hb->float_window, FALSE);
1118 hb->child_detached = FALSE;
1119 gdk_window_hide (hb->float_window);
1120 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
1121 hb->float_window_mapped = FALSE;
1122 gtk_signal_emit (GTK_OBJECT (hb),
1123 handle_box_signals[SIGNAL_CHILD_ATTACHED],
1124 GTK_BIN (hb)->child);
1127 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1128 gtk_grab_remove (widget);
1129 hb->in_drag = FALSE;
1132 gtk_widget_queue_resize (GTK_WIDGET (hb));