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 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);
176 GTK_WIDGET_SET_FLAGS (handle_box, GTK_BASIC); /* FIXME: are we really a basic widget? */
178 handle_box->bin_window = NULL;
179 handle_box->float_window = NULL;
180 handle_box->shadow_type = GTK_SHADOW_OUT;
181 handle_box->handle_position = GTK_POS_LEFT;
182 handle_box->float_window_mapped = FALSE;
183 handle_box->child_detached = FALSE;
184 handle_box->in_drag = FALSE;
185 handle_box->shrink_on_detach = TRUE;
186 handle_box->dragoff_x = 0;
187 handle_box->dragoff_y = 0;
191 gtk_handle_box_set_arg (GtkObject *object,
195 GtkHandleBox *handle_box;
197 handle_box = GTK_HANDLE_BOX (object);
202 gtk_handle_box_set_shadow_type (handle_box, GTK_VALUE_ENUM (*arg));
210 gtk_handle_box_get_arg (GtkObject *object,
214 GtkHandleBox *handle_box;
216 handle_box = GTK_HANDLE_BOX (object);
221 GTK_VALUE_ENUM (*arg) = handle_box->shadow_type;
224 arg->type = GTK_TYPE_INVALID;
230 gtk_handle_box_new (void)
232 return GTK_WIDGET (gtk_type_new (gtk_handle_box_get_type ()));
236 gtk_handle_box_destroy (GtkObject *object)
240 g_return_if_fail (object != NULL);
241 g_return_if_fail (GTK_IS_HANDLE_BOX (object));
243 hb = GTK_HANDLE_BOX (object);
245 if (GTK_OBJECT_CLASS (parent_class)->destroy)
246 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
250 gtk_handle_box_map (GtkWidget *widget)
255 g_return_if_fail (widget != NULL);
256 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
258 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
260 bin = GTK_BIN (widget);
261 hb = GTK_HANDLE_BOX (widget);
263 gdk_window_show (hb->bin_window);
264 gdk_window_show (widget->window);
266 if (hb->child_detached && !hb->float_window_mapped)
268 gdk_window_show (hb->float_window);
269 hb->float_window_mapped = TRUE;
273 GTK_WIDGET_VISIBLE (bin->child) &&
274 !GTK_WIDGET_MAPPED (bin->child))
275 gtk_widget_map (bin->child);
279 gtk_handle_box_unmap (GtkWidget *widget)
283 g_return_if_fail (widget != NULL);
284 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
286 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
288 hb = GTK_HANDLE_BOX (widget);
290 gdk_window_hide (widget->window);
291 if (hb->float_window_mapped)
293 gdk_window_hide (hb->float_window);
294 hb->float_window_mapped = FALSE;
299 gtk_handle_box_realize (GtkWidget *widget)
301 GdkWindowAttr attributes;
302 gint attributes_mask;
305 g_return_if_fail (widget != NULL);
306 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
308 hb = GTK_HANDLE_BOX (widget);
310 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
312 attributes.x = widget->allocation.x;
313 attributes.y = widget->allocation.y;
314 attributes.width = widget->allocation.width;
315 attributes.height = widget->allocation.height;
316 attributes.window_type = GDK_WINDOW_CHILD;
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 | GDK_EXPOSURE_MASK);
322 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
323 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
324 gdk_window_set_user_data (widget->window, widget);
328 attributes.width = widget->allocation.width;
329 attributes.height = widget->allocation.height;
330 attributes.window_type = GDK_WINDOW_CHILD;
331 attributes.event_mask |= (gtk_widget_get_events (widget) |
333 GDK_BUTTON1_MOTION_MASK |
334 GDK_POINTER_MOTION_HINT_MASK |
335 GDK_BUTTON_PRESS_MASK |
336 GDK_BUTTON_RELEASE_MASK);
337 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
338 hb->bin_window = gdk_window_new (widget->window, &attributes, attributes_mask);
339 gdk_window_set_user_data (hb->bin_window, widget);
340 if (GTK_BIN (hb)->child)
341 gtk_widget_set_parent_window (GTK_BIN (hb)->child, hb->bin_window);
345 attributes.width = widget->requisition.width;
346 attributes.height = widget->requisition.height;
347 attributes.window_type = GDK_WINDOW_TOPLEVEL;
348 attributes.wclass = GDK_INPUT_OUTPUT;
349 attributes.visual = gtk_widget_get_visual (widget);
350 attributes.colormap = gtk_widget_get_colormap (widget);
351 attributes.event_mask = (gtk_widget_get_events (widget) |
353 GDK_ENTER_NOTIFY_MASK |
354 GDK_LEAVE_NOTIFY_MASK |
355 GDK_FOCUS_CHANGE_MASK |
357 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
358 hb->float_window = gdk_window_new (NULL, &attributes, attributes_mask);
359 gdk_window_set_user_data (hb->float_window, widget);
360 gdk_window_set_decorations (hb->float_window, 0);
362 widget->style = gtk_style_attach (widget->style, widget->window);
363 gtk_style_set_background (widget->style, widget->window, GTK_WIDGET_STATE (hb));
364 gtk_style_set_background (widget->style, hb->bin_window, GTK_WIDGET_STATE (hb));
365 gtk_style_set_background (widget->style, hb->float_window, GTK_WIDGET_STATE (hb));
366 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
370 gtk_handle_box_unrealize (GtkWidget *widget)
374 g_return_if_fail (widget != NULL);
375 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
377 hb = GTK_HANDLE_BOX (widget);
379 gdk_window_set_user_data (hb->bin_window, NULL);
380 gdk_window_destroy (hb->bin_window);
381 hb->bin_window = NULL;
382 gdk_window_set_user_data (hb->float_window, NULL);
383 gdk_window_destroy (hb->float_window);
384 hb->float_window = NULL;
386 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
387 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
391 gtk_handle_box_style_set (GtkWidget *widget,
392 GtkStyle *previous_style)
396 g_return_if_fail (widget != NULL);
397 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
399 hb = GTK_HANDLE_BOX (widget);
401 if (GTK_WIDGET_REALIZED (widget) &&
402 !GTK_WIDGET_NO_WINDOW (widget))
404 gtk_style_set_background (widget->style, widget->window,
406 gtk_style_set_background (widget->style, hb->bin_window, widget->state);
407 gtk_style_set_background (widget->style, hb->float_window, widget->state);
408 if (GTK_WIDGET_DRAWABLE (widget))
409 gdk_window_clear (widget->window);
414 gtk_handle_box_size_request (GtkWidget *widget,
415 GtkRequisition *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, &bin->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 += bin->child->requisition.height;
453 requisition->width += bin->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 += bin->child->requisition.width;
472 requisition->height += bin->child->requisition.height;
476 requisition->width += CHILDLESS_SIZE;
477 requisition->height += CHILDLESS_SIZE;
483 gtk_handle_box_size_allocate (GtkWidget *widget,
484 GtkAllocation *allocation)
489 g_return_if_fail (widget != NULL);
490 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
491 g_return_if_fail (allocation != NULL);
493 bin = GTK_BIN (widget);
494 hb = GTK_HANDLE_BOX (widget);
496 widget->allocation.x = allocation->x;
498 if (hb->child_detached)
500 guint max_req_height;
503 max_req_height = MAX (widget->requisition.height,
504 bin->child->requisition.height +
505 2 * widget->style->klass->ythickness);
506 max_req_width = MAX (widget->requisition.width,
507 bin->child->requisition.width +
508 2 * widget->style->klass->xthickness);
510 if (allocation->height > max_req_height)
511 widget->allocation.y = allocation->y +
512 (allocation->height - max_req_height) / 2;
514 widget->allocation.y = allocation->y;
516 widget->allocation.height = MIN (allocation->height, max_req_height);
517 widget->allocation.width = MIN (allocation->width, max_req_width);
521 widget->allocation = *allocation;
524 if (GTK_WIDGET_REALIZED (hb))
525 gdk_window_move_resize (widget->window,
526 widget->allocation.x,
527 widget->allocation.y,
528 widget->allocation.width,
529 widget->allocation.height);
532 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
535 GtkAllocation child_allocation;
539 border_width = GTK_CONTAINER (widget)->border_width;
541 child_allocation.x = border_width;
542 child_allocation.y = border_width;
543 if (hb->handle_position == GTK_POS_LEFT)
544 child_allocation.x += DRAG_HANDLE_SIZE;
545 else if (hb->handle_position == GTK_POS_TOP)
546 child_allocation.y += DRAG_HANDLE_SIZE;
548 if (hb->child_detached)
553 child_allocation.width = child->requisition.width;
554 child_allocation.height = child->requisition.height;
556 float_width = child_allocation.width + 2 * border_width;
557 float_height = child_allocation.height + 2 * border_width;
559 if (hb->handle_position == GTK_POS_LEFT ||
560 hb->handle_position == GTK_POS_RIGHT)
561 float_width += DRAG_HANDLE_SIZE;
563 float_height += DRAG_HANDLE_SIZE;
565 if (GTK_WIDGET_REALIZED (hb))
567 gdk_window_resize (hb->float_window,
570 gdk_window_move_resize (hb->bin_window,
579 child_allocation.width = MAX (1, widget->allocation.width - 2 * border_width);
580 child_allocation.height = MAX (1, widget->allocation.height - 2 * border_width);
582 if (hb->handle_position == GTK_POS_LEFT ||
583 hb->handle_position == GTK_POS_RIGHT)
584 child_allocation.width -= DRAG_HANDLE_SIZE;
586 child_allocation.height -= DRAG_HANDLE_SIZE;
588 if (GTK_WIDGET_REALIZED (hb))
589 gdk_window_move_resize (hb->bin_window,
592 widget->allocation.width,
593 widget->allocation.height);
596 gtk_widget_size_allocate (bin->child, &child_allocation);
601 gtk_handle_box_draw_ghost (GtkHandleBox *hb)
609 widget = GTK_WIDGET (hb);
611 if (hb->handle_position == GTK_POS_LEFT ||
612 hb->handle_position == GTK_POS_RIGHT)
614 x = hb->handle_position == GTK_POS_LEFT ? 0 : widget->allocation.width;
616 width = DRAG_HANDLE_SIZE;
617 height = widget->allocation.height;
622 y = hb->handle_position == GTK_POS_TOP ? 0 : widget->allocation.height;
623 width = widget->allocation.width;
624 height = DRAG_HANDLE_SIZE;
626 gtk_paint_shadow (widget->style,
628 GTK_WIDGET_STATE (widget),
629 GTK_SHADOW_ETCHED_IN,
630 NULL, widget, "handle",
635 if (hb->handle_position == GTK_POS_LEFT ||
636 hb->handle_position == GTK_POS_RIGHT)
637 gtk_paint_hline (widget->style,
639 GTK_WIDGET_STATE (widget),
640 NULL, widget, "handlebox",
641 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : widget->allocation.width - DRAG_HANDLE_SIZE,
642 widget->allocation.width - DRAG_HANDLE_SIZE,
643 widget->allocation.height / 2);
645 gtk_paint_vline (widget->style,
647 GTK_WIDGET_STATE (widget),
648 NULL, widget, "handlebox",
649 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : widget->allocation.height - DRAG_HANDLE_SIZE,
650 widget->allocation.height - DRAG_HANDLE_SIZE,
651 widget->allocation.width / 2);
655 draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow,
658 gtk_paint_handle(widget->style, window, GTK_STATE_NORMAL, shadow,
659 NULL, widget, "handlebox",
660 rect->x, rect->y, rect->width, rect->height,
661 GTK_ORIENTATION_VERTICAL);
665 gtk_handle_box_set_shadow_type (GtkHandleBox *handle_box,
668 g_return_if_fail (handle_box != NULL);
669 g_return_if_fail (GTK_IS_HANDLE_BOX (handle_box));
671 if ((GtkShadowType) handle_box->shadow_type != type)
673 handle_box->shadow_type = type;
675 if (GTK_WIDGET_DRAWABLE (handle_box))
677 gtk_widget_queue_clear (GTK_WIDGET (handle_box));
679 gtk_widget_queue_resize (GTK_WIDGET (handle_box));
684 gtk_handle_box_paint (GtkWidget *widget,
685 GdkEventExpose *event,
695 bin = GTK_BIN (widget);
696 hb = GTK_HANDLE_BOX (widget);
698 border_width = GTK_CONTAINER (hb)->border_width;
700 if (hb->child_detached)
702 width = bin->child->allocation.width + 2 * border_width;
703 height = bin->child->allocation.height + 2 * border_width;
705 else if (hb->handle_position == GTK_POS_LEFT ||
706 hb->handle_position == GTK_POS_RIGHT)
708 width = widget->allocation.width - DRAG_HANDLE_SIZE;
709 height = widget->allocation.height;
713 width = widget->allocation.width;
714 height = widget->allocation.height - DRAG_HANDLE_SIZE;
718 gtk_paint_box(widget->style,
720 GTK_WIDGET_STATE (widget),
722 area, widget, "handlebox_bin",
725 gtk_paint_box(widget->style,
727 GTK_WIDGET_STATE (widget),
729 &event->area, widget, "handlebox_bin",
732 /* We currently draw the handle _above_ the relief of the handlebox.
733 * it could also be drawn on the same level...
735 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
736 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
742 rect.width = (hb->handle_position == GTK_POS_LEFT) ? DRAG_HANDLE_SIZE : width;
743 rect.height = (hb->handle_position == GTK_POS_TOP) ? DRAG_HANDLE_SIZE : height;
745 draw_textured_frame (widget, hb->bin_window, &rect, GTK_SHADOW_OUT, event ? &event->area : area);
747 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
749 GdkRectangle child_area;
750 GdkEventExpose child_event;
752 if (!event) /* we were called from draw() */
754 if (gtk_widget_intersect (bin->child, area, &child_area))
755 gtk_widget_draw (bin->child, &child_area);
757 else /* we were called from expose() */
759 child_event = *event;
761 if (GTK_WIDGET_NO_WINDOW (bin->child) &&
762 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
763 gtk_widget_event (bin->child, (GdkEvent *) &child_event);
769 gtk_handle_box_draw (GtkWidget *widget,
774 g_return_if_fail (widget != NULL);
775 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
776 g_return_if_fail (area != NULL);
778 hb = GTK_HANDLE_BOX (widget);
780 if (GTK_WIDGET_DRAWABLE (widget))
782 if (hb->child_detached)
784 /* The area parameter does not make sense in this case, so we
785 * repaint everything.
788 gtk_handle_box_draw_ghost (hb);
792 area->width = 2 * GTK_CONTAINER (hb)->border_width + DRAG_HANDLE_SIZE;
793 area->height = area->width + GTK_BIN (hb)->child->allocation.height;
794 area->width += GTK_BIN (hb)->child->allocation.width;
796 gtk_handle_box_paint (widget, NULL, area);
799 gtk_handle_box_paint (widget, NULL, area);
804 gtk_handle_box_expose (GtkWidget *widget,
805 GdkEventExpose *event)
809 g_return_val_if_fail (widget != NULL, FALSE);
810 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
811 g_return_val_if_fail (event != NULL, FALSE);
813 if (GTK_WIDGET_DRAWABLE (widget))
815 hb = GTK_HANDLE_BOX (widget);
817 if (event->window == widget->window)
819 if (hb->child_detached)
820 gtk_handle_box_draw_ghost (hb);
823 gtk_handle_box_paint (widget, event, NULL);
830 gtk_handle_box_button_changed (GtkWidget *widget,
831 GdkEventButton *event)
834 gboolean event_handled;
837 g_return_val_if_fail (widget != NULL, FALSE);
838 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
839 g_return_val_if_fail (event != NULL, FALSE);
841 hb = GTK_HANDLE_BOX (widget);
843 if (event->window != hb->bin_window)
846 event_handled = FALSE;
847 if (event->button == 1 &&
848 event->type == GDK_BUTTON_PRESS)
853 child = GTK_BIN (hb)->child;
855 switch (hb->handle_position)
858 in_handle = event->x < DRAG_HANDLE_SIZE;
861 in_handle = event->y < DRAG_HANDLE_SIZE;
864 in_handle = event->x > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.width;
867 in_handle = event->y > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.height;
877 event_handled = TRUE;
882 hb->dragoff_x = event->x;
883 hb->dragoff_y = event->y;
885 gtk_grab_add (widget);
887 fleur = gdk_cursor_new (GDK_FLEUR);
888 while (gdk_pointer_grab (hb->bin_window,
890 (GDK_BUTTON1_MOTION_MASK |
891 GDK_POINTER_MOTION_HINT_MASK |
892 GDK_BUTTON_RELEASE_MASK),
895 GDK_CURRENT_TIME) != 0); /* wait for success */
896 gdk_cursor_destroy (fleur);
897 event_handled = TRUE;
900 else if (event->type == GDK_BUTTON_RELEASE &&
903 gdk_pointer_ungrab (GDK_CURRENT_TIME);
904 gtk_grab_remove (widget);
906 event_handled = TRUE;
909 return event_handled;
913 gtk_handle_box_motion (GtkWidget *widget,
914 GdkEventMotion *event)
923 g_return_val_if_fail (widget != NULL, FALSE);
924 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
925 g_return_val_if_fail (event != NULL, FALSE);
927 hb = GTK_HANDLE_BOX (widget);
931 if (event->window != hb->bin_window)
936 gdk_window_get_deskrelative_origin (hb->float_window, &ox, &oy);
939 gdk_window_get_pointer (hb->float_window, &new_x, &new_y, NULL);
942 new_x -= hb->dragoff_x;
943 new_y -= hb->dragoff_y;
946 gdk_window_get_pointer (widget->window, &snap_x, &snap_y, NULL);
948 switch (hb->handle_position)
951 in_handle = (snap_x >= 0 && snap_x <= DRAG_HANDLE_SIZE &&
952 snap_y >= 0 && snap_y <= widget->allocation.height);
955 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
956 snap_y >= 0 && snap_y <= DRAG_HANDLE_SIZE);
959 in_handle = (snap_x >= widget->allocation.width - DRAG_HANDLE_SIZE && snap_x <= widget->allocation.width &&
960 snap_y >= 0 && snap_y <= widget->allocation.height);
963 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
964 snap_y >= widget->allocation.height - DRAG_HANDLE_SIZE && snap_y <= widget->allocation.height);
973 if (hb->child_detached)
975 gdk_pointer_ungrab (GDK_CURRENT_TIME);
977 hb->child_detached = FALSE;
978 gdk_window_hide (hb->float_window);
979 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
980 hb->float_window_mapped = FALSE;
981 gtk_signal_emit (GTK_OBJECT (hb),
982 handle_box_signals[SIGNAL_CHILD_ATTACHED],
983 GTK_BIN (hb)->child);
985 fleur = gdk_cursor_new (GDK_FLEUR);
986 while (gdk_pointer_grab (hb->bin_window,
988 (GDK_BUTTON1_MOTION_MASK |
989 GDK_POINTER_MOTION_HINT_MASK |
990 GDK_BUTTON_RELEASE_MASK),
993 GDK_CURRENT_TIME) != 0); /* wait for success */
994 gdk_cursor_destroy (fleur);
996 gtk_widget_queue_resize (widget);
1001 if (hb->child_detached)
1003 gdk_window_move (hb->float_window, new_x, new_y);
1004 gdk_window_raise (hb->float_window);
1011 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1013 hb->child_detached = TRUE;
1016 gdk_window_get_size (hb->bin_window, &width, &height);
1017 gdk_window_move_resize (hb->float_window, new_x, new_y, width, height);
1018 gdk_window_reparent (hb->bin_window, hb->float_window, 0, 0);
1019 gdk_window_set_hints (hb->float_window, new_x, new_y, 0, 0, 0, 0, GDK_HINT_POS);
1020 gdk_window_show (hb->float_window);
1021 hb->float_window_mapped = TRUE;
1023 /* this extra move is neccessary if we use decorations, or our
1024 * window manager insists on decorations.
1027 gdk_window_move (hb->float_window, new_x, new_y);
1030 gtk_signal_emit (GTK_OBJECT (hb),
1031 handle_box_signals[SIGNAL_CHILD_DETACHED],
1032 GTK_BIN (hb)->child);
1033 gtk_handle_box_draw_ghost (hb);
1035 fleur = gdk_cursor_new (GDK_FLEUR);
1036 while (gdk_pointer_grab (hb->bin_window,
1038 (GDK_BUTTON1_MOTION_MASK |
1039 GDK_POINTER_MOTION_HINT_MASK |
1040 GDK_BUTTON_RELEASE_MASK),
1043 GDK_CURRENT_TIME) != 0); /* wait for success */
1044 gdk_cursor_destroy (fleur);
1046 gtk_widget_queue_resize (widget);
1054 gtk_handle_box_add (GtkContainer *container,
1057 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1058 g_return_if_fail (GTK_BIN (container)->child == NULL);
1059 g_return_if_fail (widget->parent == NULL);
1061 gtk_widget_set_parent_window (widget, GTK_HANDLE_BOX (container)->bin_window);
1062 GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
1066 gtk_handle_box_remove (GtkContainer *container,
1071 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1072 g_return_if_fail (GTK_BIN (container)->child == widget);
1074 hb = GTK_HANDLE_BOX (container);
1076 if (hb->child_detached)
1078 hb->child_detached = FALSE;
1079 if (GTK_WIDGET_REALIZED (hb))
1081 gdk_window_hide (hb->float_window);
1082 gdk_window_reparent (hb->bin_window, GTK_WIDGET (hb)->window, 0, 0);
1084 hb->float_window_mapped = FALSE;
1088 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1089 gtk_grab_remove (GTK_WIDGET (container));
1090 hb->in_drag = FALSE;
1093 GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
1097 gtk_handle_box_delete_event (GtkWidget *widget,
1102 g_return_val_if_fail (widget != NULL, FALSE);
1103 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
1104 g_return_val_if_fail (event != NULL, FALSE);
1106 hb = GTK_HANDLE_BOX (widget);
1107 g_return_val_if_fail (event->window == hb->float_window, FALSE);
1109 hb->child_detached = FALSE;
1110 gdk_window_hide (hb->float_window);
1111 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
1112 hb->float_window_mapped = FALSE;
1113 gtk_signal_emit (GTK_OBJECT (hb),
1114 handle_box_signals[SIGNAL_CHILD_ATTACHED],
1115 GTK_BIN (hb)->child);
1118 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1119 gtk_grab_remove (widget);
1120 hb->in_drag = FALSE;
1123 gtk_widget_queue_resize (GTK_WIDGET (hb));