1997-12-16 21:39:55 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
1998-01-08 16:25:31 +00:00
|
|
|
* Copyright (C) 1998 Elliot Lee
|
1997-12-16 21:39:55 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
1998-01-05 19:41:03 +00:00
|
|
|
|
|
|
|
|
1998-01-03 05:46:58 +00:00
|
|
|
#include <stdlib.h>
|
1998-01-16 19:01:56 +00:00
|
|
|
#include "gdk/gdkx.h"
|
1997-12-16 21:39:55 +00:00
|
|
|
#include "gtkhandlebox.h"
|
1998-01-16 19:01:56 +00:00
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtksignal.h"
|
1998-01-16 23:43:10 +00:00
|
|
|
#include "gtkwindow.h"
|
1997-12-16 21:39:55 +00:00
|
|
|
|
1998-01-05 19:41:03 +00:00
|
|
|
|
1997-12-19 19:17:45 +00:00
|
|
|
#define DRAG_HANDLE_SIZE 10
|
1997-12-28 00:34:22 +00:00
|
|
|
#define BORDER_SIZE 5
|
1998-01-16 19:01:56 +00:00
|
|
|
#define GHOST_HEIGHT 3
|
|
|
|
#define SNAP_TOLERANCE 10
|
|
|
|
|
|
|
|
|
|
|
|
static void gtk_handle_box_class_init (GtkHandleBoxClass *klass);
|
|
|
|
static void gtk_handle_box_init (GtkHandleBox *handle_box);
|
|
|
|
static void gtk_handle_box_destroy (GtkObject *object);
|
|
|
|
static void gtk_handle_box_map (GtkWidget *widget);
|
|
|
|
static void gtk_handle_box_unmap (GtkWidget *widget);
|
|
|
|
static void gtk_handle_box_realize (GtkWidget *widget);
|
|
|
|
static void gtk_handle_box_unrealize (GtkWidget *widget);
|
|
|
|
static void gtk_handle_box_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition);
|
|
|
|
static void gtk_handle_box_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static void gtk_handle_box_draw_ghost (GtkWidget *widget);
|
|
|
|
static void gtk_handle_box_paint (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event,
|
|
|
|
GdkRectangle *area);
|
|
|
|
static void gtk_handle_box_draw (GtkWidget *widget,
|
|
|
|
GdkRectangle *area);
|
|
|
|
static gint gtk_handle_box_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
static gint gtk_handle_box_button_changed (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gint gtk_handle_box_motion (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event);
|
1998-01-16 23:43:10 +00:00
|
|
|
static gint gtk_handle_box_delete_float (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data);
|
1998-01-16 19:01:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GtkBinClass *parent_class;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
guint
|
1998-01-16 19:01:56 +00:00
|
|
|
gtk_handle_box_get_type (void)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
1997-12-17 14:36:57 +00:00
|
|
|
static guint handle_box_type = 0;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
1997-12-19 19:17:45 +00:00
|
|
|
if (!handle_box_type)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
|
|
|
GtkTypeInfo handle_box_info =
|
|
|
|
{
|
|
|
|
"GtkHandleBox",
|
|
|
|
sizeof (GtkHandleBox),
|
|
|
|
sizeof (GtkHandleBoxClass),
|
|
|
|
(GtkClassInitFunc) gtk_handle_box_class_init,
|
|
|
|
(GtkObjectInitFunc) gtk_handle_box_init,
|
1998-01-16 00:49:51 +00:00
|
|
|
(GtkArgSetFunc) NULL,
|
|
|
|
(GtkArgGetFunc) NULL,
|
1997-12-16 21:39:55 +00:00
|
|
|
};
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
handle_box_type = gtk_type_unique (gtk_bin_get_type (), &handle_box_info);
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
1997-12-17 14:36:57 +00:00
|
|
|
return handle_box_type;
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_handle_box_class_init (GtkHandleBoxClass *class)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class;
|
1998-01-16 19:01:56 +00:00
|
|
|
GtkObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = (GtkObjectClass *) class;
|
|
|
|
widget_class = (GtkWidgetClass *) class;
|
|
|
|
|
|
|
|
parent_class = gtk_type_class (gtk_bin_get_type ());
|
1997-12-16 21:39:55 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
object_class->destroy = gtk_handle_box_destroy;
|
|
|
|
|
|
|
|
widget_class->map = gtk_handle_box_map;
|
|
|
|
widget_class->unmap = gtk_handle_box_unmap;
|
1997-12-16 21:39:55 +00:00
|
|
|
widget_class->realize = gtk_handle_box_realize;
|
1998-01-16 19:01:56 +00:00
|
|
|
widget_class->unrealize = gtk_handle_box_unrealize;
|
1997-12-16 21:39:55 +00:00
|
|
|
widget_class->size_request = gtk_handle_box_size_request;
|
|
|
|
widget_class->size_allocate = gtk_handle_box_size_allocate;
|
|
|
|
widget_class->draw = gtk_handle_box_draw;
|
|
|
|
widget_class->expose_event = gtk_handle_box_expose;
|
1997-12-19 19:17:45 +00:00
|
|
|
widget_class->button_press_event = gtk_handle_box_button_changed;
|
|
|
|
widget_class->button_release_event = gtk_handle_box_button_changed;
|
1997-12-17 14:36:57 +00:00
|
|
|
widget_class->motion_notify_event = gtk_handle_box_motion;
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-12-17 14:36:57 +00:00
|
|
|
gtk_handle_box_init (GtkHandleBox *handle_box)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
1997-12-17 14:36:57 +00:00
|
|
|
GTK_WIDGET_UNSET_FLAGS (handle_box, GTK_NO_WINDOW);
|
1998-01-16 19:01:56 +00:00
|
|
|
GTK_WIDGET_SET_FLAGS (handle_box, GTK_BASIC); /* FIXME: are we really a basic widget? */
|
|
|
|
|
|
|
|
handle_box->steady_window = NULL;
|
1998-01-16 23:43:10 +00:00
|
|
|
handle_box->float_window = NULL;
|
1997-12-17 14:36:57 +00:00
|
|
|
handle_box->is_being_dragged = FALSE;
|
1997-12-22 21:37:43 +00:00
|
|
|
handle_box->is_onroot = FALSE;
|
1998-01-16 19:01:56 +00:00
|
|
|
handle_box->fleur_cursor = gdk_cursor_new (GDK_FLEUR);
|
|
|
|
handle_box->dragoff_x = 0;
|
|
|
|
handle_box->dragoff_y = 0;
|
|
|
|
handle_box->steady_x = 0;
|
|
|
|
handle_box->steady_x = 0;
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
1998-01-16 19:01:56 +00:00
|
|
|
gtk_handle_box_new (void)
|
|
|
|
{
|
|
|
|
return GTK_WIDGET (gtk_type_new (gtk_handle_box_get_type ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_handle_box_destroy (GtkObject *object)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
GtkHandleBox *hb;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (object));
|
|
|
|
|
|
|
|
hb = GTK_HANDLE_BOX (object);
|
|
|
|
|
|
|
|
gdk_cursor_destroy (hb->fleur_cursor);
|
|
|
|
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_handle_box_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkBin *bin;
|
|
|
|
GtkHandleBox *hb;
|
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
|
|
|
|
|
|
|
|
GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
|
|
|
|
|
|
|
|
bin = GTK_BIN (widget);
|
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
|
|
|
|
|
|
|
gdk_window_show (hb->steady_window);
|
|
|
|
gdk_window_show (widget->window);
|
|
|
|
|
|
|
|
if (bin->child
|
|
|
|
&& GTK_WIDGET_VISIBLE (bin->child)
|
|
|
|
&& !GTK_WIDGET_MAPPED (bin->child))
|
|
|
|
gtk_widget_map (bin->child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_handle_box_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkHandleBox *hb;
|
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
|
|
|
|
|
|
|
|
GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
|
|
|
|
|
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
|
|
|
|
|
|
|
gdk_window_hide (widget->window);
|
|
|
|
gdk_window_hide (hb->steady_window);
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_handle_box_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
1998-01-16 19:01:56 +00:00
|
|
|
GtkHandleBox *hb;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
|
|
|
|
1997-12-16 21:39:55 +00:00
|
|
|
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
|
|
|
|
|
1998-01-16 23:43:10 +00:00
|
|
|
/* FIXME: we need a property that would tell the window manager not
|
|
|
|
* to put decoration on this window. This is not part of the ICCCM,
|
|
|
|
* so we'll have to define our own (a la KWM) and hack some window
|
|
|
|
* managers to support it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
hb->float_window = gtk_window_new (GTK_WINDOW_DIALOG);
|
1998-01-28 03:41:55 +00:00
|
|
|
gtk_window_set_policy (GTK_WINDOW (hb->float_window), FALSE, FALSE, TRUE);
|
1998-01-16 23:43:10 +00:00
|
|
|
gtk_container_border_width (GTK_CONTAINER (hb->float_window), 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (hb->float_window), "delete_event",
|
|
|
|
(GtkSignalFunc) gtk_handle_box_delete_float,
|
|
|
|
hb);
|
|
|
|
|
1997-12-16 21:39:55 +00:00
|
|
|
attributes.x = widget->allocation.x;
|
|
|
|
attributes.y = widget->allocation.y;
|
|
|
|
attributes.width = widget->allocation.width;
|
|
|
|
attributes.height = widget->allocation.height;
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
1998-01-16 19:01:56 +00:00
|
|
|
attributes.event_mask = (gtk_widget_get_events (widget)
|
|
|
|
| GDK_EXPOSURE_MASK);
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
|
|
|
1998-01-18 15:09:10 +00:00
|
|
|
hb->steady_window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
|
1998-01-16 19:01:56 +00:00
|
|
|
gdk_window_set_user_data (hb->steady_window, widget);
|
|
|
|
|
|
|
|
attributes.x = 0;
|
|
|
|
attributes.y = 0;
|
|
|
|
attributes.event_mask |= (GDK_BUTTON1_MOTION_MASK
|
1998-01-28 03:41:55 +00:00
|
|
|
| GDK_POINTER_MOTION_HINT_MASK
|
1998-01-16 19:01:56 +00:00
|
|
|
| GDK_BUTTON_PRESS_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK);
|
|
|
|
|
|
|
|
widget->window = gdk_window_new (hb->steady_window, &attributes, attributes_mask);
|
1997-12-16 21:39:55 +00:00
|
|
|
gdk_window_set_user_data (widget->window, widget);
|
|
|
|
|
|
|
|
widget->style = gtk_style_attach (widget->style, widget->window);
|
1998-01-16 19:01:56 +00:00
|
|
|
gtk_style_set_background (widget->style, hb->steady_window, GTK_STATE_NORMAL);
|
1997-12-16 21:39:55 +00:00
|
|
|
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
|
|
|
|
}
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
static void
|
|
|
|
gtk_handle_box_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkHandleBox *hb;
|
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
|
|
|
|
|
|
|
|
GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
|
|
|
|
|
|
|
|
gtk_style_detach (widget->style);
|
|
|
|
|
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
|
|
|
|
|
|
|
if (widget->window)
|
|
|
|
gdk_window_destroy (widget->window);
|
|
|
|
|
|
|
|
if (hb->steady_window)
|
|
|
|
gdk_window_destroy (hb->steady_window);
|
|
|
|
|
|
|
|
hb->steady_window = NULL;
|
|
|
|
widget->window = NULL;
|
1998-01-16 23:43:10 +00:00
|
|
|
|
|
|
|
/* FIXME: do we have to unref the float_window before destroying it? */
|
|
|
|
|
|
|
|
gtk_widget_destroy (hb->float_window);
|
|
|
|
hb->float_window = NULL;
|
1998-01-16 19:01:56 +00:00
|
|
|
}
|
|
|
|
|
1997-12-16 21:39:55 +00:00
|
|
|
static void
|
|
|
|
gtk_handle_box_size_request (GtkWidget *widget,
|
1997-12-19 19:17:45 +00:00
|
|
|
GtkRequisition *requisition)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
|
|
|
GtkBin *bin;
|
1997-12-22 21:37:43 +00:00
|
|
|
GtkHandleBox *hb;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
|
|
|
|
g_return_if_fail (requisition != NULL);
|
|
|
|
|
|
|
|
bin = GTK_BIN (widget);
|
1998-01-16 19:01:56 +00:00
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
1997-12-16 21:39:55 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
requisition->width = DRAG_HANDLE_SIZE + GTK_CONTAINER (widget)->border_width * 2;
|
|
|
|
requisition->height = GTK_CONTAINER (widget)->border_width * 2;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
|
|
|
|
{
|
|
|
|
gtk_widget_size_request (bin->child, &bin->child->requisition);
|
|
|
|
|
|
|
|
requisition->width += bin->child->requisition.width;
|
1997-12-28 00:34:22 +00:00
|
|
|
requisition->height += bin->child->requisition.height;
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
1997-12-22 21:37:43 +00:00
|
|
|
|
|
|
|
hb->real_requisition = *requisition;
|
1998-01-05 19:41:03 +00:00
|
|
|
if (hb->is_onroot)
|
1998-01-16 19:01:56 +00:00
|
|
|
requisition->height = GHOST_HEIGHT;
|
1998-01-16 23:43:10 +00:00
|
|
|
/* FIXME: Should also set requisition->width to a small value? */
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_handle_box_size_allocate (GtkWidget *widget,
|
1997-12-22 21:37:43 +00:00
|
|
|
GtkAllocation *allocation)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
|
|
|
GtkBin *bin;
|
|
|
|
GtkAllocation child_allocation;
|
1997-12-28 00:34:22 +00:00
|
|
|
GtkHandleBox *hb;
|
1998-01-16 19:01:56 +00:00
|
|
|
gint border_width;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
|
|
|
|
g_return_if_fail (allocation != NULL);
|
|
|
|
|
|
|
|
widget->allocation = *allocation;
|
|
|
|
bin = GTK_BIN (widget);
|
1998-01-16 19:01:56 +00:00
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
1997-12-16 21:39:55 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
border_width = GTK_CONTAINER (widget)->border_width;
|
1997-12-28 01:28:27 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
1997-12-28 01:28:27 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
if (!hb->is_onroot)
|
|
|
|
{
|
|
|
|
gdk_window_move_resize (hb->steady_window,
|
|
|
|
allocation->x + border_width,
|
|
|
|
allocation->y + border_width,
|
|
|
|
allocation->width - border_width * 2,
|
|
|
|
allocation->height - border_width * 2);
|
|
|
|
gdk_window_move_resize (widget->window,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
allocation->width - border_width * 2,
|
|
|
|
allocation->height - border_width * 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-01-16 23:43:10 +00:00
|
|
|
gtk_widget_set_usize (hb->float_window,
|
|
|
|
hb->real_requisition.width,
|
|
|
|
hb->real_requisition.height);
|
1998-01-16 19:01:56 +00:00
|
|
|
gdk_window_resize (widget->window,
|
|
|
|
hb->real_requisition.width,
|
|
|
|
hb->real_requisition.height);
|
|
|
|
gdk_window_move_resize (hb->steady_window,
|
|
|
|
allocation->x + border_width,
|
|
|
|
allocation->y + border_width,
|
|
|
|
allocation->width - border_width * 2,
|
|
|
|
GHOST_HEIGHT);
|
|
|
|
}
|
1997-12-28 01:28:27 +00:00
|
|
|
}
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
|
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
child_allocation.x = DRAG_HANDLE_SIZE;
|
|
|
|
child_allocation.y = 0;
|
|
|
|
|
|
|
|
if (hb->is_onroot)
|
|
|
|
{
|
|
|
|
child_allocation.width = hb->real_requisition.width - DRAG_HANDLE_SIZE;
|
|
|
|
child_allocation.height = hb->real_requisition.height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child_allocation.width = allocation->width - DRAG_HANDLE_SIZE - border_width * 2;
|
|
|
|
child_allocation.height = allocation->height - border_width * 2;
|
|
|
|
}
|
|
|
|
|
1997-12-16 21:39:55 +00:00
|
|
|
gtk_widget_size_allocate (bin->child, &child_allocation);
|
1998-01-05 19:41:03 +00:00
|
|
|
}
|
1998-01-16 19:01:56 +00:00
|
|
|
}
|
1997-12-28 00:34:22 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
static void
|
|
|
|
gtk_handle_box_draw_ghost (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_draw_hline (widget->style,
|
|
|
|
GTK_HANDLE_BOX (widget)->steady_window,
|
|
|
|
GTK_WIDGET_STATE (widget),
|
|
|
|
0,
|
|
|
|
widget->allocation.width - GTK_CONTAINER (widget)->border_width * 2,
|
|
|
|
0);
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
1998-01-05 19:41:03 +00:00
|
|
|
static void
|
1998-01-16 19:01:56 +00:00
|
|
|
gtk_handle_box_paint (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event,
|
|
|
|
GdkRectangle *area)
|
1997-12-19 19:17:45 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
GtkBin *bin;
|
1997-12-22 21:37:43 +00:00
|
|
|
GtkHandleBox *hb;
|
1998-01-16 19:01:56 +00:00
|
|
|
GdkRectangle child_area;
|
|
|
|
GdkEventExpose child_event;
|
|
|
|
gint x;
|
1997-12-19 20:19:28 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
bin = GTK_BIN (widget);
|
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
1997-12-19 21:06:39 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
if (event != NULL)
|
|
|
|
area = &event->area;
|
1997-12-19 21:06:39 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
for (x = 1; x < DRAG_HANDLE_SIZE; x += 3)
|
|
|
|
gtk_draw_vline (widget->style,
|
1997-12-28 01:28:27 +00:00
|
|
|
widget->window,
|
1998-01-16 19:01:56 +00:00
|
|
|
GTK_WIDGET_STATE (widget),
|
|
|
|
0, hb->is_onroot ? hb->real_requisition.height : widget->allocation.height,
|
|
|
|
x);
|
1997-12-28 01:28:27 +00:00
|
|
|
|
1998-01-05 19:41:03 +00:00
|
|
|
if (hb->is_onroot)
|
1998-01-16 19:01:56 +00:00
|
|
|
gtk_draw_shadow (widget->style,
|
|
|
|
widget->window,
|
|
|
|
GTK_WIDGET_STATE (widget),
|
|
|
|
GTK_SHADOW_OUT,
|
|
|
|
0, 0,
|
|
|
|
hb->real_requisition.width,
|
|
|
|
hb->real_requisition.height);
|
|
|
|
else
|
|
|
|
gtk_draw_shadow (widget->style,
|
|
|
|
widget->window,
|
|
|
|
GTK_WIDGET_STATE (widget),
|
|
|
|
GTK_SHADOW_OUT,
|
|
|
|
0, 0,
|
|
|
|
widget->allocation.width,
|
|
|
|
widget->allocation.height);
|
|
|
|
|
|
|
|
if (bin->child)
|
|
|
|
{
|
|
|
|
if (event == NULL) /* we were called from draw() */
|
|
|
|
{
|
|
|
|
if (gtk_widget_intersect (bin->child, area, &child_area))
|
|
|
|
gtk_widget_draw (bin->child, &child_area);
|
|
|
|
}
|
|
|
|
else /* we were called from expose() */
|
|
|
|
{
|
|
|
|
child_event = *event;
|
|
|
|
|
|
|
|
if (GTK_WIDGET_NO_WINDOW (bin->child)
|
|
|
|
&& gtk_widget_intersect (bin->child, &event->area, &child_event.area))
|
|
|
|
gtk_widget_event (bin->child, (GdkEvent *) &child_event);
|
|
|
|
}
|
|
|
|
}
|
1997-12-19 19:17:45 +00:00
|
|
|
}
|
|
|
|
|
1997-12-16 21:39:55 +00:00
|
|
|
static void
|
|
|
|
gtk_handle_box_draw (GtkWidget *widget,
|
1998-01-05 19:41:03 +00:00
|
|
|
GdkRectangle *area)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
|
|
|
GdkRectangle child_area;
|
1998-01-16 19:01:56 +00:00
|
|
|
GtkHandleBox *hb;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_HANDLE_BOX (widget));
|
|
|
|
g_return_if_fail (area != NULL);
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
|
|
|
|
1997-12-16 21:39:55 +00:00
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
if (hb->is_onroot)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
/* The area parameter does not make sense in this case, so we
|
|
|
|
* repaint everything.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gtk_handle_box_draw_ghost (widget);
|
|
|
|
|
|
|
|
child_area.x = 0;
|
|
|
|
child_area.y = 0;
|
|
|
|
child_area.width = hb->real_requisition.width;
|
|
|
|
child_area.height = hb->real_requisition.height;
|
|
|
|
|
|
|
|
gtk_handle_box_paint (widget, NULL, &child_area);
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
1998-01-16 19:01:56 +00:00
|
|
|
else
|
|
|
|
gtk_handle_box_paint (widget, NULL, area);
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_handle_box_expose (GtkWidget *widget,
|
1997-12-19 19:17:45 +00:00
|
|
|
GdkEventExpose *event)
|
1997-12-16 21:39:55 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
GtkHandleBox *hb;
|
1997-12-16 21:39:55 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
|
|
|
|
|
|
|
if (event->window == hb->steady_window)
|
|
|
|
gtk_handle_box_draw_ghost (widget);
|
|
|
|
else if (event->window == widget->window)
|
|
|
|
gtk_handle_box_paint (widget, event, NULL);
|
1997-12-16 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-12-22 21:37:43 +00:00
|
|
|
static gint
|
1998-01-16 19:01:56 +00:00
|
|
|
gtk_handle_box_button_changed (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
1997-12-17 14:36:57 +00:00
|
|
|
{
|
|
|
|
GtkHandleBox *hb;
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
|
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
|
|
|
|
1998-01-05 19:41:03 +00:00
|
|
|
if (event->button == 1)
|
1997-12-17 14:36:57 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
if ((event->type == GDK_BUTTON_PRESS) && (event->x < DRAG_HANDLE_SIZE))
|
1997-12-17 14:36:57 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
hb->dragoff_x = event->x;
|
|
|
|
hb->dragoff_y = event->y;
|
|
|
|
|
|
|
|
gdk_window_get_origin (hb->steady_window, &hb->steady_x, &hb->steady_y);
|
|
|
|
|
1997-12-22 21:37:43 +00:00
|
|
|
hb->is_being_dragged = TRUE;
|
1998-01-16 19:01:56 +00:00
|
|
|
|
|
|
|
gdk_flush();
|
|
|
|
gtk_grab_add (widget);
|
|
|
|
while (gdk_pointer_grab (widget->window,
|
|
|
|
FALSE,
|
1998-01-28 03:41:55 +00:00
|
|
|
(GDK_BUTTON1_MOTION_MASK
|
|
|
|
| GDK_POINTER_MOTION_HINT_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK),
|
1998-01-16 19:01:56 +00:00
|
|
|
NULL,
|
|
|
|
hb->fleur_cursor,
|
|
|
|
GDK_CURRENT_TIME) != 0); /* wait for success */
|
1997-12-17 14:36:57 +00:00
|
|
|
}
|
1998-01-16 19:01:56 +00:00
|
|
|
else if ((event->type == GDK_BUTTON_RELEASE) && hb->is_being_dragged)
|
1997-12-17 14:36:57 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
gtk_grab_remove (widget);
|
1997-12-17 14:36:57 +00:00
|
|
|
hb->is_being_dragged = FALSE;
|
|
|
|
}
|
|
|
|
}
|
1997-12-19 19:17:45 +00:00
|
|
|
return TRUE;
|
1997-12-17 14:36:57 +00:00
|
|
|
}
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
static gint
|
|
|
|
gtk_handle_box_motion (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event)
|
1997-12-22 21:37:43 +00:00
|
|
|
{
|
|
|
|
GtkHandleBox *hb;
|
1998-01-16 19:01:56 +00:00
|
|
|
gint newx, newy;
|
1998-01-28 03:41:55 +00:00
|
|
|
gint ox, oy;
|
1998-01-16 19:01:56 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_HANDLE_BOX (widget), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1997-12-22 21:37:43 +00:00
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
hb = GTK_HANDLE_BOX (widget);
|
1997-12-22 21:37:43 +00:00
|
|
|
|
1998-01-28 03:41:55 +00:00
|
|
|
if (event->is_hint)
|
|
|
|
{
|
|
|
|
gdk_window_get_origin (widget->window, &ox, &oy);
|
|
|
|
gdk_window_get_pointer (widget->window, &newx, &newy, NULL);
|
|
|
|
newx += ox;
|
|
|
|
newy += oy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newx = event->x_root;
|
|
|
|
newy = event->y_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
newx -= hb->dragoff_x;
|
|
|
|
newy -= hb->dragoff_y;
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
if (hb->is_being_dragged)
|
1997-12-22 21:37:43 +00:00
|
|
|
{
|
1998-01-16 19:01:56 +00:00
|
|
|
if ((abs (hb->steady_x - newx) < SNAP_TOLERANCE)
|
|
|
|
&& (abs (hb->steady_y - newy) < SNAP_TOLERANCE))
|
|
|
|
{
|
|
|
|
if (hb->is_onroot)
|
|
|
|
{
|
|
|
|
hb->is_onroot = FALSE;
|
|
|
|
|
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
|
|
|
|
gdk_window_reparent (widget->window, hb->steady_window, 0, 0);
|
|
|
|
|
1998-01-16 23:43:10 +00:00
|
|
|
gtk_widget_hide (hb->float_window);
|
|
|
|
|
1998-01-16 19:01:56 +00:00
|
|
|
while (gdk_pointer_grab (widget->window,
|
|
|
|
FALSE,
|
1998-01-28 03:41:55 +00:00
|
|
|
(GDK_BUTTON1_MOTION_MASK
|
|
|
|
| GDK_POINTER_MOTION_HINT_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK),
|
1998-01-16 19:01:56 +00:00
|
|
|
NULL,
|
|
|
|
hb->fleur_cursor,
|
|
|
|
GDK_CURRENT_TIME) != 0); /* wait for success */
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (hb->is_onroot)
|
1998-01-16 23:43:10 +00:00
|
|
|
{
|
|
|
|
gtk_widget_set_uposition (hb->float_window, newx, newy);
|
|
|
|
gdk_window_raise (hb->float_window->window);
|
|
|
|
}
|
1998-01-16 19:01:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
hb->is_onroot = TRUE;
|
|
|
|
|
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
1998-01-18 15:09:10 +00:00
|
|
|
|
|
|
|
if (!GTK_WIDGET_REALIZED (hb->float_window))
|
|
|
|
gtk_widget_realize (hb->float_window);
|
|
|
|
|
1998-01-16 23:43:10 +00:00
|
|
|
gtk_widget_set_uposition (hb->float_window, newx, newy);
|
|
|
|
gdk_window_reparent (widget->window, hb->float_window->window, 0, 0);
|
1998-01-18 15:09:10 +00:00
|
|
|
gtk_widget_show (hb->float_window);
|
1998-01-16 19:01:56 +00:00
|
|
|
|
|
|
|
while (gdk_pointer_grab (widget->window,
|
|
|
|
FALSE,
|
1998-01-28 03:41:55 +00:00
|
|
|
(GDK_BUTTON1_MOTION_MASK
|
|
|
|
| GDK_POINTER_MOTION_HINT_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK),
|
1998-01-16 19:01:56 +00:00
|
|
|
NULL,
|
|
|
|
hb->fleur_cursor,
|
|
|
|
GDK_CURRENT_TIME) != 0); /* wait for success */
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-12-19 19:17:45 +00:00
|
|
|
|
|
|
|
return TRUE;
|
1997-12-17 14:36:57 +00:00
|
|
|
}
|
1998-01-16 23:43:10 +00:00
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_handle_box_delete_float (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkHandleBox *hb;
|
|
|
|
|
1998-01-18 15:09:10 +00:00
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (data != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_HANDLE_BOX (data), FALSE);
|
1998-01-16 23:43:10 +00:00
|
|
|
|
|
|
|
hb = GTK_HANDLE_BOX (data);
|
|
|
|
|
|
|
|
hb->is_onroot = FALSE;
|
|
|
|
|
|
|
|
gdk_window_reparent (GTK_WIDGET (hb)->window, hb->steady_window, 0, 0);
|
|
|
|
gtk_widget_hide (hb->float_window);
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (hb));
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|