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"
30 #define DRAG_HANDLE_SIZE 10
31 #define CHILDLESS_SIZE 25
32 #define GHOST_HEIGHT 3
36 SIGNAL_CHILD_ATTACHED,
37 SIGNAL_CHILD_DETACHED,
41 typedef void (*SignalChildAttached) (GtkObject *object,
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_destroy (GtkObject *object);
48 static void gtk_handle_box_map (GtkWidget *widget);
49 static void gtk_handle_box_unmap (GtkWidget *widget);
50 static void gtk_handle_box_realize (GtkWidget *widget);
51 static void gtk_handle_box_unrealize (GtkWidget *widget);
52 static void gtk_handle_box_style_set (GtkWidget *widget,
53 GtkStyle *previous_style);
54 static void gtk_handle_box_size_request (GtkWidget *widget,
55 GtkRequisition *requisition);
56 static void gtk_handle_box_size_allocate (GtkWidget *widget,
57 GtkAllocation *real_allocation);
58 static void gtk_handle_box_add (GtkContainer *container,
60 static void gtk_handle_box_remove (GtkContainer *container,
62 static void gtk_handle_box_draw_ghost (GtkHandleBox *hb);
63 static void gtk_handle_box_paint (GtkWidget *widget,
64 GdkEventExpose *event,
66 static void gtk_handle_box_draw (GtkWidget *widget,
68 static gint gtk_handle_box_expose (GtkWidget *widget,
69 GdkEventExpose *event);
70 static gint gtk_handle_box_button_changed (GtkWidget *widget,
71 GdkEventButton *event);
72 static gint gtk_handle_box_motion (GtkWidget *widget,
73 GdkEventMotion *event);
74 static gint gtk_handle_box_delete_event (GtkWidget *widget,
78 static GtkBinClass *parent_class;
79 static guint handle_box_signals[SIGNAL_LAST] = { 0 };
83 gtk_handle_box_get_type (void)
85 static guint handle_box_type = 0;
89 GtkTypeInfo handle_box_info =
92 sizeof (GtkHandleBox),
93 sizeof (GtkHandleBoxClass),
94 (GtkClassInitFunc) gtk_handle_box_class_init,
95 (GtkObjectInitFunc) gtk_handle_box_init,
100 handle_box_type = gtk_type_unique (gtk_bin_get_type (), &handle_box_info);
103 return handle_box_type;
107 gtk_handle_box_marshal_child_attached (GtkObject *object,
112 SignalChildAttached sfunc = (SignalChildAttached) func;
115 (GtkWidget*) GTK_VALUE_OBJECT (args[0]),
120 gtk_handle_box_class_init (GtkHandleBoxClass *class)
122 GtkObjectClass *object_class;
123 GtkWidgetClass *widget_class;
124 GtkContainerClass *container_class;
126 object_class = (GtkObjectClass *) class;
127 widget_class = (GtkWidgetClass *) class;
128 container_class = (GtkContainerClass *) class;
130 parent_class = gtk_type_class (gtk_bin_get_type ());
132 handle_box_signals[SIGNAL_CHILD_ATTACHED] =
133 gtk_signal_new ("child_attached",
136 GTK_SIGNAL_OFFSET (GtkHandleBoxClass, child_attached),
137 gtk_handle_box_marshal_child_attached,
140 handle_box_signals[SIGNAL_CHILD_DETACHED] =
141 gtk_signal_new ("child_detached",
144 GTK_SIGNAL_OFFSET (GtkHandleBoxClass, child_detached),
145 gtk_handle_box_marshal_child_attached,
148 gtk_object_class_add_signals (object_class, handle_box_signals, SIGNAL_LAST);
150 object_class->destroy = gtk_handle_box_destroy;
152 widget_class->map = gtk_handle_box_map;
153 widget_class->unmap = gtk_handle_box_unmap;
154 widget_class->realize = gtk_handle_box_realize;
155 widget_class->unrealize = gtk_handle_box_unrealize;
156 widget_class->style_set = gtk_handle_box_style_set;
157 widget_class->size_request = gtk_handle_box_size_request;
158 widget_class->size_allocate = gtk_handle_box_size_allocate;
159 widget_class->draw = gtk_handle_box_draw;
160 widget_class->expose_event = gtk_handle_box_expose;
161 widget_class->button_press_event = gtk_handle_box_button_changed;
162 widget_class->button_release_event = gtk_handle_box_button_changed;
163 widget_class->motion_notify_event = gtk_handle_box_motion;
164 widget_class->delete_event = gtk_handle_box_delete_event;
166 container_class->add = gtk_handle_box_add;
167 container_class->remove = gtk_handle_box_remove;
169 class->child_attached = NULL;
170 class->child_detached = NULL;
174 gtk_handle_box_init (GtkHandleBox *handle_box)
176 GTK_WIDGET_UNSET_FLAGS (handle_box, GTK_NO_WINDOW);
177 GTK_WIDGET_SET_FLAGS (handle_box, GTK_BASIC); /* FIXME: are we really a basic widget? */
179 handle_box->bin_window = NULL;
180 handle_box->float_window = NULL;
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_new (void)
193 return GTK_WIDGET (gtk_type_new (gtk_handle_box_get_type ()));
197 gtk_handle_box_destroy (GtkObject *object)
201 g_return_if_fail (object != NULL);
202 g_return_if_fail (GTK_IS_HANDLE_BOX (object));
204 hb = GTK_HANDLE_BOX (object);
206 if (GTK_OBJECT_CLASS (parent_class)->destroy)
207 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
211 gtk_handle_box_map (GtkWidget *widget)
216 g_return_if_fail (widget != NULL);
217 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
219 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
221 bin = GTK_BIN (widget);
222 hb = GTK_HANDLE_BOX (widget);
224 gdk_window_show (hb->bin_window);
225 gdk_window_show (widget->window);
227 if (hb->child_detached && !hb->float_window_mapped)
229 gdk_window_show (hb->float_window);
230 hb->float_window_mapped = TRUE;
234 GTK_WIDGET_VISIBLE (bin->child) &&
235 !GTK_WIDGET_MAPPED (bin->child))
236 gtk_widget_map (bin->child);
240 gtk_handle_box_unmap (GtkWidget *widget)
244 g_return_if_fail (widget != NULL);
245 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
247 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
249 hb = GTK_HANDLE_BOX (widget);
251 gdk_window_hide (widget->window);
252 if (hb->float_window_mapped)
254 gdk_window_hide (hb->float_window);
255 hb->float_window_mapped = FALSE;
260 gtk_handle_box_realize (GtkWidget *widget)
262 GdkWindowAttr attributes;
263 gint attributes_mask;
266 g_return_if_fail (widget != NULL);
267 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
269 hb = GTK_HANDLE_BOX (widget);
271 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
273 attributes.x = widget->allocation.x;
274 attributes.y = widget->allocation.y;
275 attributes.width = widget->allocation.width;
276 attributes.height = widget->allocation.height;
277 attributes.window_type = GDK_WINDOW_CHILD;
278 attributes.wclass = GDK_INPUT_OUTPUT;
279 attributes.visual = gtk_widget_get_visual (widget);
280 attributes.colormap = gtk_widget_get_colormap (widget);
281 attributes.event_mask = (gtk_widget_get_events (widget)
282 | GDK_EXPOSURE_MASK);
283 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
284 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
285 gdk_window_set_user_data (widget->window, widget);
289 attributes.width = widget->allocation.width;
290 attributes.height = widget->allocation.height;
291 attributes.window_type = GDK_WINDOW_CHILD;
292 attributes.event_mask |= (gtk_widget_get_events (widget) |
294 GDK_BUTTON1_MOTION_MASK |
295 GDK_POINTER_MOTION_HINT_MASK |
296 GDK_BUTTON_PRESS_MASK |
297 GDK_BUTTON_RELEASE_MASK);
298 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
299 hb->bin_window = gdk_window_new (widget->window, &attributes, attributes_mask);
300 gdk_window_set_user_data (hb->bin_window, widget);
301 if (GTK_BIN (hb)->child)
302 gtk_widget_set_parent_window (GTK_BIN (hb)->child, hb->bin_window);
306 attributes.width = widget->requisition.width;
307 attributes.height = widget->requisition.height;
308 attributes.window_type = GDK_WINDOW_TOPLEVEL;
309 attributes.wclass = GDK_INPUT_OUTPUT;
310 attributes.visual = gtk_widget_get_visual (widget);
311 attributes.colormap = gtk_widget_get_colormap (widget);
312 attributes.event_mask = (gtk_widget_get_events (widget) |
314 GDK_ENTER_NOTIFY_MASK |
315 GDK_LEAVE_NOTIFY_MASK |
316 GDK_FOCUS_CHANGE_MASK |
318 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
319 hb->float_window = gdk_window_new (NULL, &attributes, attributes_mask);
320 gdk_window_set_user_data (hb->float_window, widget);
321 gdk_window_set_decorations (hb->float_window, 0);
323 widget->style = gtk_style_attach (widget->style, widget->window);
324 gtk_style_set_background (widget->style, widget->window, GTK_WIDGET_STATE (hb));
325 gtk_style_set_background (widget->style, hb->bin_window, GTK_WIDGET_STATE (hb));
326 gtk_style_set_background (widget->style, hb->float_window, GTK_WIDGET_STATE (hb));
330 gtk_handle_box_unrealize (GtkWidget *widget)
334 g_return_if_fail (widget != NULL);
335 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
337 hb = GTK_HANDLE_BOX (widget);
339 gdk_window_set_user_data (hb->bin_window, NULL);
340 gdk_window_destroy (hb->bin_window);
341 hb->bin_window = NULL;
342 gdk_window_set_user_data (hb->float_window, NULL);
343 gdk_window_destroy (hb->float_window);
344 hb->float_window = NULL;
346 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
347 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
351 gtk_handle_box_style_set (GtkWidget *widget,
352 GtkStyle *previous_style)
356 g_return_if_fail (widget != NULL);
357 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
359 hb = GTK_HANDLE_BOX (widget);
361 if (GTK_WIDGET_REALIZED (widget) &&
362 !GTK_WIDGET_NO_WINDOW (widget))
364 gtk_style_set_background (widget->style, widget->window,
366 gtk_style_set_background (widget->style, hb->bin_window, widget->state);
367 gtk_style_set_background (widget->style, hb->float_window, widget->state);
368 if (GTK_WIDGET_DRAWABLE (widget))
369 gdk_window_clear (widget->window);
374 gtk_handle_box_size_request (GtkWidget *widget,
375 GtkRequisition *requisition)
380 g_return_if_fail (widget != NULL);
381 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
382 g_return_if_fail (requisition != NULL);
384 bin = GTK_BIN (widget);
385 hb = GTK_HANDLE_BOX (widget);
387 if (hb->handle_position == GTK_POS_LEFT ||
388 hb->handle_position == GTK_POS_RIGHT)
390 requisition->width = DRAG_HANDLE_SIZE;
391 requisition->height = 0;
395 requisition->width = 0;
396 requisition->height = DRAG_HANDLE_SIZE;
399 /* if our child is not visible, we still request its size, since we
400 * won't have any usefull hint for our size otherwise.
403 gtk_widget_size_request (bin->child, &bin->child->requisition);
405 if (hb->child_detached)
407 if (!hb->shrink_on_detach)
409 if (hb->handle_position == GTK_POS_LEFT ||
410 hb->handle_position == GTK_POS_RIGHT)
411 requisition->height += bin->child->requisition.height;
413 requisition->width += bin->child->requisition.width;
417 if (hb->handle_position == GTK_POS_LEFT ||
418 hb->handle_position == GTK_POS_RIGHT)
419 requisition->height += widget->style->klass->ythickness;
421 requisition->width += widget->style->klass->xthickness;
426 requisition->width += GTK_CONTAINER (widget)->border_width * 2;
427 requisition->height += GTK_CONTAINER (widget)->border_width * 2;
431 requisition->width += bin->child->requisition.width;
432 requisition->height += bin->child->requisition.height;
436 requisition->width += CHILDLESS_SIZE;
437 requisition->height += CHILDLESS_SIZE;
443 gtk_handle_box_size_allocate (GtkWidget *widget,
444 GtkAllocation *allocation)
449 g_return_if_fail (widget != NULL);
450 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
451 g_return_if_fail (allocation != NULL);
453 bin = GTK_BIN (widget);
454 hb = GTK_HANDLE_BOX (widget);
456 widget->allocation.x = allocation->x;
458 if (hb->child_detached)
460 guint max_req_height;
463 max_req_height = MAX (widget->requisition.height,
464 bin->child->requisition.height +
465 2 * widget->style->klass->ythickness);
466 max_req_width = MAX (widget->requisition.width,
467 bin->child->requisition.width +
468 2 * widget->style->klass->xthickness);
470 if (allocation->height > max_req_height)
471 widget->allocation.y = allocation->y +
472 (allocation->height - max_req_height) / 2;
474 widget->allocation.y = allocation->y;
476 widget->allocation.height = MIN (allocation->height, max_req_height);
477 widget->allocation.width = MIN (allocation->width, max_req_width);
481 widget->allocation = *allocation;
484 if (GTK_WIDGET_REALIZED (hb))
485 gdk_window_move_resize (widget->window,
486 widget->allocation.x,
487 widget->allocation.y,
488 widget->allocation.width,
489 widget->allocation.height);
492 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
495 GtkAllocation child_allocation;
499 border_width = GTK_CONTAINER (widget)->border_width;
501 child_allocation.x = border_width;
502 child_allocation.y = border_width;
503 if (hb->handle_position == GTK_POS_LEFT)
504 child_allocation.x += DRAG_HANDLE_SIZE;
505 else if (hb->handle_position == GTK_POS_TOP)
506 child_allocation.y += DRAG_HANDLE_SIZE;
508 if (hb->child_detached)
513 child_allocation.width = child->requisition.width;
514 child_allocation.height = child->requisition.height;
516 float_width = child_allocation.width + 2 * border_width;
517 float_height = child_allocation.height + 2 * border_width;
519 if (hb->handle_position == GTK_POS_LEFT ||
520 hb->handle_position == GTK_POS_RIGHT)
521 float_width += DRAG_HANDLE_SIZE;
523 float_height += DRAG_HANDLE_SIZE;
525 if (GTK_WIDGET_REALIZED (hb))
527 gdk_window_resize (hb->float_window,
530 gdk_window_move_resize (hb->bin_window,
539 child_allocation.width = MAX (1, widget->allocation.width - 2 * border_width);
540 child_allocation.height = MAX (1, widget->allocation.height - 2 * border_width);
542 if (hb->handle_position == GTK_POS_LEFT ||
543 hb->handle_position == GTK_POS_RIGHT)
544 child_allocation.width -= DRAG_HANDLE_SIZE;
546 child_allocation.height -= DRAG_HANDLE_SIZE;
548 if (GTK_WIDGET_REALIZED (hb))
549 gdk_window_move_resize (hb->bin_window,
552 widget->allocation.width,
553 widget->allocation.height);
556 gtk_widget_size_allocate (bin->child, &child_allocation);
561 gtk_handle_box_draw_ghost (GtkHandleBox *hb)
569 widget = GTK_WIDGET (hb);
571 if (hb->handle_position == GTK_POS_LEFT ||
572 hb->handle_position == GTK_POS_RIGHT)
574 x = hb->handle_position == GTK_POS_LEFT ? 0 : widget->allocation.width;
576 width = DRAG_HANDLE_SIZE;
577 height = widget->allocation.height;
582 y = hb->handle_position == GTK_POS_TOP ? 0 : widget->allocation.height;
583 width = widget->allocation.width;
584 height = DRAG_HANDLE_SIZE;
586 gtk_draw_shadow (widget->style,
588 GTK_WIDGET_STATE (widget),
589 GTK_SHADOW_ETCHED_IN,
595 if (hb->handle_position == GTK_POS_LEFT ||
596 hb->handle_position == GTK_POS_RIGHT)
597 gtk_draw_hline (widget->style,
599 GTK_WIDGET_STATE (widget),
600 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : widget->allocation.width - DRAG_HANDLE_SIZE,
601 widget->allocation.width - DRAG_HANDLE_SIZE,
602 widget->allocation.height / 2);
604 gtk_draw_vline (widget->style,
606 GTK_WIDGET_STATE (widget),
607 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : widget->allocation.height - DRAG_HANDLE_SIZE,
608 widget->allocation.height - DRAG_HANDLE_SIZE,
609 widget->allocation.width / 2);
614 draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow,
619 GdkGC *light_gc, *dark_gc;
622 if (gdk_rectangle_intersect (rect, clip, &dest))
624 gdk_draw_rectangle (window,
625 widget->style->bg_gc[GTK_STATE_NORMAL],
628 dest.width, dest.height);
630 light_gc = widget->style->light_gc[GTK_STATE_NORMAL];
631 dark_gc = widget->style->dark_gc[GTK_STATE_NORMAL];
633 xthick = widget->style->klass->xthickness;
634 ythick = widget->style->klass->ythickness;
636 gdk_gc_set_clip_rectangle (light_gc, &dest);
637 gdk_gc_set_clip_rectangle (dark_gc, &dest);
639 for (y = rect->y + ythick; y < (rect->y + rect->height - ythick); y += 3)
640 for (x = rect->x + xthick; x < (rect->x + rect->width - xthick); x += 6)
642 gdk_draw_point (window, light_gc, x, y);
643 gdk_draw_point (window, dark_gc, x + 1, y + 1);
645 gdk_draw_point (window, light_gc, x + 3, y + 1);
646 gdk_draw_point (window, dark_gc, x + 4, y + 2);
649 gdk_gc_set_clip_rectangle (light_gc, NULL);
650 gdk_gc_set_clip_rectangle (dark_gc, NULL);
652 gtk_draw_shadow (widget->style, window,
653 GTK_STATE_NORMAL, shadow,
655 rect->width, rect->height);
660 gtk_handle_box_paint (GtkWidget *widget,
661 GdkEventExpose *event,
671 bin = GTK_BIN (widget);
672 hb = GTK_HANDLE_BOX (widget);
674 border_width = GTK_CONTAINER (hb)->border_width;
676 if (hb->child_detached)
678 width = bin->child->allocation.width + 2 * border_width;
679 height = bin->child->allocation.height + 2 * border_width;
681 else if (hb->handle_position == GTK_POS_LEFT ||
682 hb->handle_position == GTK_POS_RIGHT)
684 width = widget->allocation.width - DRAG_HANDLE_SIZE;
685 height = widget->allocation.height;
689 width = widget->allocation.width;
690 height = widget->allocation.height - DRAG_HANDLE_SIZE;
694 gdk_window_clear_area (hb->bin_window,
700 gtk_draw_shadow (widget->style,
702 GTK_WIDGET_STATE (widget),
704 hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
705 hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
711 rect.width = (hb->handle_position == GTK_POS_LEFT) ? DRAG_HANDLE_SIZE : width;
712 rect.height = (hb->handle_position == GTK_POS_TOP) ? DRAG_HANDLE_SIZE : height;
714 draw_textured_frame (widget, hb->bin_window, &rect, GTK_SHADOW_OUT, event ? &event->area : area);
716 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
718 GdkRectangle child_area;
719 GdkEventExpose child_event;
721 if (!event) /* we were called from draw() */
723 if (gtk_widget_intersect (bin->child, area, &child_area))
724 gtk_widget_draw (bin->child, &child_area);
726 else /* we were called from expose() */
728 child_event = *event;
730 if (GTK_WIDGET_NO_WINDOW (bin->child) &&
731 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
732 gtk_widget_event (bin->child, (GdkEvent *) &child_event);
738 gtk_handle_box_draw (GtkWidget *widget,
743 g_return_if_fail (widget != NULL);
744 g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
745 g_return_if_fail (area != NULL);
747 hb = GTK_HANDLE_BOX (widget);
749 if (GTK_WIDGET_DRAWABLE (widget))
751 if (hb->child_detached)
753 /* The area parameter does not make sense in this case, so we
754 * repaint everything.
757 gtk_handle_box_draw_ghost (hb);
761 area->width = 2 * GTK_CONTAINER (hb)->border_width + DRAG_HANDLE_SIZE;
762 area->height = area->width + GTK_BIN (hb)->child->allocation.height;
763 area->width += GTK_BIN (hb)->child->allocation.width;
765 gtk_handle_box_paint (widget, NULL, area);
768 gtk_handle_box_paint (widget, NULL, area);
773 gtk_handle_box_expose (GtkWidget *widget,
774 GdkEventExpose *event)
778 g_return_val_if_fail (widget != NULL, FALSE);
779 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
780 g_return_val_if_fail (event != NULL, FALSE);
782 if (GTK_WIDGET_DRAWABLE (widget))
784 hb = GTK_HANDLE_BOX (widget);
786 if (event->window == widget->window)
788 if (hb->child_detached)
789 gtk_handle_box_draw_ghost (hb);
792 gtk_handle_box_paint (widget, event, NULL);
799 gtk_handle_box_button_changed (GtkWidget *widget,
800 GdkEventButton *event)
803 gboolean event_handled;
806 g_return_val_if_fail (widget != NULL, FALSE);
807 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
808 g_return_val_if_fail (event != NULL, FALSE);
810 hb = GTK_HANDLE_BOX (widget);
812 event_handled = FALSE;
813 if (event->button == 1 &&
814 event->type == GDK_BUTTON_PRESS)
819 child = GTK_BIN (hb)->child;
821 switch (hb->handle_position)
824 in_handle = event->x < DRAG_HANDLE_SIZE;
827 in_handle = event->y < DRAG_HANDLE_SIZE;
830 in_handle = event->x > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.width;
833 in_handle = event->y > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.height;
843 event_handled = TRUE;
848 hb->dragoff_x = event->x;
849 hb->dragoff_y = event->y;
851 gtk_grab_add (widget);
853 fleur = gdk_cursor_new (GDK_FLEUR);
854 while (gdk_pointer_grab (hb->bin_window,
856 (GDK_BUTTON1_MOTION_MASK |
857 GDK_POINTER_MOTION_HINT_MASK |
858 GDK_BUTTON_RELEASE_MASK),
861 GDK_CURRENT_TIME) != 0); /* wait for success */
862 gdk_cursor_destroy (fleur);
863 event_handled = TRUE;
866 else if (event->type == GDK_BUTTON_RELEASE &&
869 gdk_pointer_ungrab (GDK_CURRENT_TIME);
870 gtk_grab_remove (widget);
872 event_handled = TRUE;
875 return event_handled;
879 gtk_handle_box_motion (GtkWidget *widget,
880 GdkEventMotion *event)
889 g_return_val_if_fail (widget != NULL, FALSE);
890 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
891 g_return_val_if_fail (event != NULL, FALSE);
893 hb = GTK_HANDLE_BOX (widget);
899 gdk_window_get_origin (hb->float_window, &ox, &oy);
902 gdk_window_get_pointer (hb->float_window, &new_x, &new_y, NULL);
905 new_x -= hb->dragoff_x;
906 new_y -= hb->dragoff_y;
909 gdk_window_get_pointer (widget->window, &snap_x, &snap_y, NULL);
911 switch (hb->handle_position)
914 in_handle = (snap_x >= 0 && snap_x <= DRAG_HANDLE_SIZE &&
915 snap_y >= 0 && snap_y <= widget->allocation.height);
918 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
919 snap_y >= 0 && snap_y <= DRAG_HANDLE_SIZE);
922 in_handle = (snap_x >= widget->allocation.width - DRAG_HANDLE_SIZE && snap_x <= widget->allocation.width &&
923 snap_y >= 0 && snap_y <= widget->allocation.height);
926 in_handle = (snap_x >= 0 && snap_x <= widget->allocation.width &&
927 snap_y >= widget->allocation.height - DRAG_HANDLE_SIZE && snap_y <= widget->allocation.height);
936 if (hb->child_detached)
938 gdk_pointer_ungrab (GDK_CURRENT_TIME);
940 hb->child_detached = FALSE;
941 gdk_window_hide (hb->float_window);
942 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
943 hb->float_window_mapped = FALSE;
944 gtk_signal_emit (GTK_OBJECT (hb),
945 handle_box_signals[SIGNAL_CHILD_ATTACHED],
946 GTK_BIN (hb)->child);
948 fleur = gdk_cursor_new (GDK_FLEUR);
949 while (gdk_pointer_grab (hb->bin_window,
951 (GDK_BUTTON1_MOTION_MASK |
952 GDK_POINTER_MOTION_HINT_MASK |
953 GDK_BUTTON_RELEASE_MASK),
956 GDK_CURRENT_TIME) != 0); /* wait for success */
957 gdk_cursor_destroy (fleur);
959 gtk_widget_queue_resize (widget);
964 if (hb->child_detached)
966 gdk_window_move (hb->float_window, new_x, new_y);
967 gdk_window_raise (hb->float_window);
974 gdk_pointer_ungrab (GDK_CURRENT_TIME);
976 hb->child_detached = TRUE;
979 gdk_window_get_size (hb->bin_window, &width, &height);
980 gdk_window_move_resize (hb->float_window, new_x, new_y, width, height);
981 gdk_window_reparent (hb->bin_window, hb->float_window, 0, 0);
982 gdk_window_set_hints (hb->float_window, new_x, new_y, 0, 0, 0, 0, GDK_HINT_POS);
983 gdk_window_show (hb->float_window);
984 hb->float_window_mapped = TRUE;
986 /* this extra move is neccessary if we use decorations, or our
987 * window manager insists on decorations.
990 gdk_window_move (hb->float_window, new_x, new_y);
993 gtk_signal_emit (GTK_OBJECT (hb),
994 handle_box_signals[SIGNAL_CHILD_DETACHED],
995 GTK_BIN (hb)->child);
996 gtk_handle_box_draw_ghost (hb);
998 fleur = gdk_cursor_new (GDK_FLEUR);
999 while (gdk_pointer_grab (hb->bin_window,
1001 (GDK_BUTTON1_MOTION_MASK |
1002 GDK_POINTER_MOTION_HINT_MASK |
1003 GDK_BUTTON_RELEASE_MASK),
1006 GDK_CURRENT_TIME) != 0); /* wait for success */
1007 gdk_cursor_destroy (fleur);
1009 gtk_widget_queue_resize (widget);
1017 gtk_handle_box_add (GtkContainer *container,
1020 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1021 g_return_if_fail (GTK_BIN (container)->child == NULL);
1022 g_return_if_fail (widget->parent == NULL);
1024 gtk_widget_set_parent_window (widget, GTK_HANDLE_BOX (container)->bin_window);
1025 GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
1029 gtk_handle_box_remove (GtkContainer *container,
1034 g_return_if_fail (GTK_IS_HANDLE_BOX (container));
1035 g_return_if_fail (GTK_BIN (container)->child == widget);
1037 hb = GTK_HANDLE_BOX (container);
1039 if (hb->child_detached)
1041 hb->child_detached = FALSE;
1042 if (GTK_WIDGET_REALIZED (hb))
1044 gdk_window_hide (hb->float_window);
1045 gdk_window_reparent (hb->bin_window, GTK_WIDGET (hb)->window, 0, 0);
1047 hb->float_window_mapped = FALSE;
1051 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1052 gtk_grab_remove (GTK_WIDGET (container));
1053 hb->in_drag = FALSE;
1056 GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
1060 gtk_handle_box_delete_event (GtkWidget *widget,
1065 g_return_val_if_fail (widget != NULL, FALSE);
1066 g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
1067 g_return_val_if_fail (event != NULL, FALSE);
1069 hb = GTK_HANDLE_BOX (widget);
1070 g_return_val_if_fail (event->window == hb->float_window, FALSE);
1072 hb->child_detached = FALSE;
1073 gdk_window_hide (hb->float_window);
1074 gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
1075 hb->float_window_mapped = FALSE;
1076 gtk_signal_emit (GTK_OBJECT (hb),
1077 handle_box_signals[SIGNAL_CHILD_ATTACHED],
1078 GTK_BIN (hb)->child);
1081 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1082 gtk_grab_remove (widget);
1083 hb->in_drag = FALSE;
1086 gtk_widget_queue_resize (GTK_WIDGET (hb));