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);
262 gdk_window_show (hb->bin_window);
263 gdk_window_show (widget->window);
265 if (hb->child_detached && !hb->float_window_mapped)
267 gdk_window_show (hb->float_window);
268 hb->float_window_mapped = TRUE;
272 GTK_WIDGET_VISIBLE (bin->child) &&
273 !GTK_WIDGET_MAPPED (bin->child))
274 gtk_widget_map (bin->child);
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)
419 g_return_if_fail (widget != NULL);
420 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
421 g_return_if_fail (requisition != NULL);
423 bin = GTK_BIN (widget);
424 hb = GTK_HANDLE_BOX (widget);
426 if (hb->handle_position == GTK_POS_LEFT ||
427 hb->handle_position == GTK_POS_RIGHT)
429 requisition->width = DRAG_HANDLE_SIZE;
430 requisition->height = 0;
434 requisition->width = 0;
435 requisition->height = DRAG_HANDLE_SIZE;
438 /* if our child is not visible, we still request its size, since we
439 * won't have any usefull hint for our size otherwise.
442 gtk_widget_size_request (bin->child, &bin->child->requisition);
444 if (hb->child_detached)
446 if (!hb->shrink_on_detach)
448 if (hb->handle_position == GTK_POS_LEFT ||
449 hb->handle_position == GTK_POS_RIGHT)
450 requisition->height += bin->child->requisition.height;
452 requisition->width += bin->child->requisition.width;
456 if (hb->handle_position == GTK_POS_LEFT ||
457 hb->handle_position == GTK_POS_RIGHT)
458 requisition->height += widget->style->klass->ythickness;
460 requisition->width += widget->style->klass->xthickness;
465 requisition->width += GTK_CONTAINER (widget)->border_width * 2;
466 requisition->height += GTK_CONTAINER (widget)->border_width * 2;
470 requisition->width += bin->child->requisition.width;
471 requisition->height += bin->child->requisition.height;
475 requisition->width += CHILDLESS_SIZE;
476 requisition->height += CHILDLESS_SIZE;
482 gtk_handle_box_size_allocate (GtkWidget *widget,
483 GtkAllocation *allocation)
488 g_return_if_fail (widget != NULL);
489 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
490 g_return_if_fail (allocation != NULL);
492 bin = GTK_BIN (widget);
493 hb = GTK_HANDLE_BOX (widget);
495 widget->allocation.x = allocation->x;
497 if (hb->child_detached)
499 guint max_req_height;
502 max_req_height = MAX (widget->requisition.height,
503 bin->child->requisition.height +
504 2 * widget->style->klass->ythickness);
505 max_req_width = MAX (widget->requisition.width,
506 bin->child->requisition.width +
507 2 * widget->style->klass->xthickness);
509 if (allocation->height > max_req_height)
510 widget->allocation.y = allocation->y +
511 (allocation->height - max_req_height) / 2;
513 widget->allocation.y = allocation->y;
515 widget->allocation.height = MIN (allocation->height, max_req_height);
516 widget->allocation.width = MIN (allocation->width, max_req_width);
520 widget->allocation = *allocation;
523 if (GTK_WIDGET_REALIZED (hb))
524 gdk_window_move_resize (widget->window,
525 widget->allocation.x,
526 widget->allocation.y,
527 widget->allocation.width,
528 widget->allocation.height);
531 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
534 GtkAllocation child_allocation;
538 border_width = GTK_CONTAINER (widget)->border_width;
540 child_allocation.x = border_width;
541 child_allocation.y = border_width;
542 if (hb->handle_position == GTK_POS_LEFT)
543 child_allocation.x += DRAG_HANDLE_SIZE;
544 else if (hb->handle_position == GTK_POS_TOP)
545 child_allocation.y += DRAG_HANDLE_SIZE;
547 if (hb->child_detached)
552 child_allocation.width = child->requisition.width;
553 child_allocation.height = child->requisition.height;
555 float_width = child_allocation.width + 2 * border_width;
556 float_height = child_allocation.height + 2 * border_width;
558 if (hb->handle_position == GTK_POS_LEFT ||
559 hb->handle_position == GTK_POS_RIGHT)
560 float_width += DRAG_HANDLE_SIZE;
562 float_height += DRAG_HANDLE_SIZE;
564 if (GTK_WIDGET_REALIZED (hb))
566 gdk_window_resize (hb->float_window,
569 gdk_window_move_resize (hb->bin_window,
578 child_allocation.width = MAX (1, widget->allocation.width - 2 * border_width);
579 child_allocation.height = MAX (1, widget->allocation.height - 2 * border_width);
581 if (hb->handle_position == GTK_POS_LEFT ||
582 hb->handle_position == GTK_POS_RIGHT)
583 child_allocation.width -= DRAG_HANDLE_SIZE;
585 child_allocation.height -= DRAG_HANDLE_SIZE;
587 if (GTK_WIDGET_REALIZED (hb))
588 gdk_window_move_resize (hb->bin_window,
591 widget->allocation.width,
592 widget->allocation.height);
595 gtk_widget_size_allocate (bin->child, &child_allocation);
600 gtk_handle_box_draw_ghost (GtkHandleBox *hb)
608 widget = GTK_WIDGET (hb);
610 if (hb->handle_position == GTK_POS_LEFT ||
611 hb->handle_position == GTK_POS_RIGHT)
613 x = hb->handle_position == GTK_POS_LEFT ? 0 : widget->allocation.width;
615 width = DRAG_HANDLE_SIZE;
616 height = widget->allocation.height;
621 y = hb->handle_position == GTK_POS_TOP ? 0 : widget->allocation.height;
622 width = widget->allocation.width;
623 height = DRAG_HANDLE_SIZE;
625 gtk_paint_shadow (widget->style,
627 GTK_WIDGET_STATE (widget),
628 GTK_SHADOW_ETCHED_IN,
629 NULL, widget, "handle",
634 if (hb->handle_position == GTK_POS_LEFT ||
635 hb->handle_position == GTK_POS_RIGHT)
636 gtk_paint_hline (widget->style,
638 GTK_WIDGET_STATE (widget),
639 NULL, widget, "handlebox",
640 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : widget->allocation.width - DRAG_HANDLE_SIZE,
641 widget->allocation.width - DRAG_HANDLE_SIZE,
642 widget->allocation.height / 2);
644 gtk_paint_vline (widget->style,
646 GTK_WIDGET_STATE (widget),
647 NULL, widget, "handlebox",
648 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : widget->allocation.height - DRAG_HANDLE_SIZE,
649 widget->allocation.height - DRAG_HANDLE_SIZE,
650 widget->allocation.width / 2);
654 draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow,
657 gtk_paint_handle(widget->style, window, GTK_STATE_NORMAL, shadow,
658 NULL, widget, "handlebox",
659 rect->x, rect->y, rect->width, rect->height,
660 GTK_ORIENTATION_VERTICAL);
664 gtk_handle_box_set_shadow_type (GtkHandleBox *handle_box,
667 g_return_if_fail (handle_box != NULL);
668 g_return_if_fail (GTK_IS_HANDLE_BOX (handle_box));
670 if ((GtkShadowType) handle_box->shadow_type != type)
672 handle_box->shadow_type = type;
674 if (GTK_WIDGET_DRAWABLE (handle_box))
676 gtk_widget_queue_clear (GTK_WIDGET (handle_box));
678 gtk_widget_queue_resize (GTK_WIDGET (handle_box));
683 gtk_handle_box_paint (GtkWidget *widget,
684 GdkEventExpose *event,
694 bin = GTK_BIN (widget);
695 hb = GTK_HANDLE_BOX (widget);
697 border_width = GTK_CONTAINER (hb)->border_width;
699 if (hb->child_detached)
701 width = bin->child->allocation.width + 2 * border_width;
702 height = bin->child->allocation.height + 2 * border_width;
704 else if (hb->handle_position == GTK_POS_LEFT ||
705 hb->handle_position == GTK_POS_RIGHT)
707 width = widget->allocation.width - DRAG_HANDLE_SIZE;
708 height = widget->allocation.height;
712 width = widget->allocation.width;
713 height = widget->allocation.height - DRAG_HANDLE_SIZE;
717 gtk_paint_box(widget->style,
719 GTK_WIDGET_STATE (widget),
721 area, widget, "handlebox_bin",
724 gtk_paint_box(widget->style,
726 GTK_WIDGET_STATE (widget),
728 &event->area, widget, "handlebox_bin",
731 /* We currently draw the handle _above_ the relief of the handlebox.
732 * it could also be drawn on the same level...
734 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
735 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
741 rect.width = (hb->handle_position == GTK_POS_LEFT) ? DRAG_HANDLE_SIZE : width;
742 rect.height = (hb->handle_position == GTK_POS_TOP) ? DRAG_HANDLE_SIZE : height;
744 draw_textured_frame (widget, hb->bin_window, &rect, GTK_SHADOW_OUT, event ? &event->area : area);
746 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
748 GdkRectangle child_area;
749 GdkEventExpose child_event;
751 if (!event) /* we were called from draw() */
753 if (gtk_widget_intersect (bin->child, area, &child_area))
754 gtk_widget_draw (bin->child, &child_area);
756 else /* we were called from expose() */
758 child_event = *event;
760 if (GTK_WIDGET_NO_WINDOW (bin->child) &&
761 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
762 gtk_widget_event (bin->child, (GdkEvent *) &child_event);
768 gtk_handle_box_draw (GtkWidget *widget,
773 g_return_if_fail (widget != NULL);
774 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
775 g_return_if_fail (area != NULL);
777 hb = GTK_HANDLE_BOX (widget);
779 if (GTK_WIDGET_DRAWABLE (widget))
781 if (hb->child_detached)
783 /* The area parameter does not make sense in this case, so we
784 * repaint everything.
787 gtk_handle_box_draw_ghost (hb);
791 area->width = 2 * GTK_CONTAINER (hb)->border_width + DRAG_HANDLE_SIZE;
792 area->height = area->width + GTK_BIN (hb)->child->allocation.height;
793 area->width += GTK_BIN (hb)->child->allocation.width;
795 gtk_handle_box_paint (widget, NULL, area);
798 gtk_handle_box_paint (widget, NULL, area);
803 gtk_handle_box_expose (GtkWidget *widget,
804 GdkEventExpose *event)
808 g_return_val_if_fail (widget != NULL, FALSE);
809 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
810 g_return_val_if_fail (event != NULL, FALSE);
812 if (GTK_WIDGET_DRAWABLE (widget))
814 hb = GTK_HANDLE_BOX (widget);
816 if (event->window == widget->window)
818 if (hb->child_detached)
819 gtk_handle_box_draw_ghost (hb);
822 gtk_handle_box_paint (widget, event, NULL);
829 gtk_handle_box_button_changed (GtkWidget *widget,
830 GdkEventButton *event)
833 gboolean event_handled;
836 g_return_val_if_fail (widget != NULL, FALSE);
837 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
838 g_return_val_if_fail (event != NULL, FALSE);
840 hb = GTK_HANDLE_BOX (widget);
842 if (event->window != hb->bin_window)
845 event_handled = FALSE;
846 if (event->button == 1 &&
847 event->type == GDK_BUTTON_PRESS)
852 child = GTK_BIN (hb)->child;
854 switch (hb->handle_position)
857 in_handle = event->x < DRAG_HANDLE_SIZE;
860 in_handle = event->y < DRAG_HANDLE_SIZE;
863 in_handle = event->x > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.width;
866 in_handle = event->y > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.height;
876 event_handled = TRUE;
881 hb->dragoff_x = event->x;
882 hb->dragoff_y = event->y;
884 gtk_grab_add (widget);
886 fleur = gdk_cursor_new (GDK_FLEUR);
887 while (gdk_pointer_grab (hb->bin_window,
889 (GDK_BUTTON1_MOTION_MASK |
890 GDK_POINTER_MOTION_HINT_MASK |
891 GDK_BUTTON_RELEASE_MASK),
894 GDK_CURRENT_TIME) != 0); /* wait for success */
895 gdk_cursor_destroy (fleur);
896 event_handled = TRUE;
899 else if (event->type == GDK_BUTTON_RELEASE &&
902 gdk_pointer_ungrab (GDK_CURRENT_TIME);
903 gtk_grab_remove (widget);
905 event_handled = TRUE;
908 return event_handled;
912 gtk_handle_box_motion (GtkWidget *widget,
913 GdkEventMotion *event)
922 g_return_val_if_fail (widget != NULL, FALSE);
923 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
924 g_return_val_if_fail (event != NULL, FALSE);
926 hb = GTK_HANDLE_BOX (widget);
930 if (event->window != hb->bin_window)
935 gdk_window_get_deskrelative_origin (hb->float_window, &ox, &oy);
938 gdk_window_get_pointer (hb->float_window, &new_x, &new_y, NULL);
941 new_x -= hb->dragoff_x;
942 new_y -= hb->dragoff_y;
945 gdk_window_get_pointer (widget->window, &snap_x, &snap_y, NULL);
947 switch (hb->handle_position)
950 in_handle = (snap_x >= 0 && snap_x <= DRAG_HANDLE_SIZE &&
951 snap_y >= 0 && snap_y <= widget->allocation.height);
954 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
955 snap_y >= 0 && snap_y <= DRAG_HANDLE_SIZE);
958 in_handle = (snap_x >= widget->allocation.width - DRAG_HANDLE_SIZE && snap_x <= widget->allocation.width &&
959 snap_y >= 0 && snap_y <= widget->allocation.height);
962 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
963 snap_y >= widget->allocation.height - DRAG_HANDLE_SIZE && snap_y <= widget->allocation.height);
972 if (hb->child_detached)
974 gdk_pointer_ungrab (GDK_CURRENT_TIME);
976 hb->child_detached = FALSE;
977 gdk_window_hide (hb->float_window);
978 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
979 hb->float_window_mapped = FALSE;
980 gtk_signal_emit (GTK_OBJECT (hb),
981 handle_box_signals[SIGNAL_CHILD_ATTACHED],
982 GTK_BIN (hb)->child);
984 fleur = gdk_cursor_new (GDK_FLEUR);
985 while (gdk_pointer_grab (hb->bin_window,
987 (GDK_BUTTON1_MOTION_MASK |
988 GDK_POINTER_MOTION_HINT_MASK |
989 GDK_BUTTON_RELEASE_MASK),
992 GDK_CURRENT_TIME) != 0); /* wait for success */
993 gdk_cursor_destroy (fleur);
995 gtk_widget_queue_resize (widget);
1000 if (hb->child_detached)
1002 gdk_window_move (hb->float_window, new_x, new_y);
1003 gdk_window_raise (hb->float_window);
1010 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1012 hb->child_detached = TRUE;
1015 gdk_window_get_size (hb->bin_window, &width, &height);
1016 gdk_window_move_resize (hb->float_window, new_x, new_y, width, height);
1017 gdk_window_reparent (hb->bin_window, hb->float_window, 0, 0);
1018 gdk_window_set_hints (hb->float_window, new_x, new_y, 0, 0, 0, 0, GDK_HINT_POS);
1019 gdk_window_show (hb->float_window);
1020 hb->float_window_mapped = TRUE;
1022 /* this extra move is neccessary if we use decorations, or our
1023 * window manager insists on decorations.
1026 gdk_window_move (hb->float_window, new_x, new_y);
1029 gtk_signal_emit (GTK_OBJECT (hb),
1030 handle_box_signals[SIGNAL_CHILD_DETACHED],
1031 GTK_BIN (hb)->child);
1032 gtk_handle_box_draw_ghost (hb);
1034 fleur = gdk_cursor_new (GDK_FLEUR);
1035 while (gdk_pointer_grab (hb->bin_window,
1037 (GDK_BUTTON1_MOTION_MASK |
1038 GDK_POINTER_MOTION_HINT_MASK |
1039 GDK_BUTTON_RELEASE_MASK),
1042 GDK_CURRENT_TIME) != 0); /* wait for success */
1043 gdk_cursor_destroy (fleur);
1045 gtk_widget_queue_resize (widget);
1053 gtk_handle_box_add (GtkContainer *container,
1056 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1057 g_return_if_fail (GTK_BIN (container)->child == NULL);
1058 g_return_if_fail (widget->parent == NULL);
1060 gtk_widget_set_parent_window (widget, GTK_HANDLE_BOX (container)->bin_window);
1061 GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
1065 gtk_handle_box_remove (GtkContainer *container,
1070 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1071 g_return_if_fail (GTK_BIN (container)->child == widget);
1073 hb = GTK_HANDLE_BOX (container);
1075 if (hb->child_detached)
1077 hb->child_detached = FALSE;
1078 if (GTK_WIDGET_REALIZED (hb))
1080 gdk_window_hide (hb->float_window);
1081 gdk_window_reparent (hb->bin_window, GTK_WIDGET (hb)->window, 0, 0);
1083 hb->float_window_mapped = FALSE;
1087 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1088 gtk_grab_remove (GTK_WIDGET (container));
1089 hb->in_drag = FALSE;
1092 GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
1096 gtk_handle_box_delete_event (GtkWidget *widget,
1101 g_return_val_if_fail (widget != NULL, FALSE);
1102 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
1103 g_return_val_if_fail (event != NULL, FALSE);
1105 hb = GTK_HANDLE_BOX (widget);
1106 g_return_val_if_fail (event->window == hb->float_window, FALSE);
1108 hb->child_detached = FALSE;
1109 gdk_window_hide (hb->float_window);
1110 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
1111 hb->float_window_mapped = FALSE;
1112 gtk_signal_emit (GTK_OBJECT (hb),
1113 handle_box_signals[SIGNAL_CHILD_ATTACHED],
1114 GTK_BIN (hb)->child);
1117 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1118 gtk_grab_remove (widget);
1119 hb->in_drag = FALSE;
1122 gtk_widget_queue_resize (GTK_WIDGET (hb));