/* bonobo-dock-item.c
*
* Copyright (C) 1998 Ettore Perazzoli
* Copyright (C) 1998 Elliot Lee
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* All rights reserved.
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
@NOTATION@
*/
/*
* NB. this may look like a GtkBin, but it contains
* a BonoboDockItemGrip in addition to it's child,
* stranger things have been done in the name of
* bin-compat.
*/
#include <config.h>
#include "bonobo-dock-item.h"
#include "bonobo-dock-band.h"
#include "bonobo-dock-item-grip.h"
#include "bonobo-ui-marshal.h"
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <gtk/gtktoolbar.h>
#include <gtk/gtkwindow.h>
#include <glib/gi18n.h>
#include <libgnome/gnome-macros.h>
struct _BonoboDockItemPrivate
{
GtkWidget *child;
GtkWidget *grip;
GtkWidget *float_window;
GtkWidget *float_window_box;
gboolean float_window_hidden;
};
GNOME_CLASS_BOILERPLATE (BonoboDockItem, bonobo_dock_item,
GtkBin, GTK_TYPE_BIN)
enum {
PROP_0,
PROP_SHADOW,
PROP_ORIENTATION,
PROP_PREFERRED_WIDTH,
PROP_PREFERRED_HEIGHT
};
#define DRAG_HANDLE_SIZE 10
enum {
DOCK_DRAG_BEGIN,
DOCK_DRAG_END,
DOCK_DRAG_MOTION,
DOCK_DETACH,
ORIENTATION_CHANGED,
LAST_SIGNAL
};
static guint get_preferred_width (BonoboDockItem *item);
static guint get_preferred_height (BonoboDockItem *item);
static void bonobo_dock_item_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void bonobo_dock_item_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void bonobo_dock_item_finalize (GObject *object);
static void bonobo_dock_item_map (GtkWidget *widget);
static void bonobo_dock_item_unmap (GtkWidget *widget);
static void bonobo_dock_item_realize (GtkWidget *widget);
static void bonobo_dock_item_unrealize (GtkWidget *widget);
static void bonobo_dock_item_style_set (GtkWidget *widget,
GtkStyle *previous_style);
static void bonobo_dock_item_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void bonobo_dock_item_size_allocate (GtkWidget *widget,
GtkAllocation *real_allocation);
static void bonobo_dock_item_add (GtkContainer *container,
GtkWidget *widget);
static void bonobo_dock_item_remove (GtkContainer *container,
GtkWidget *widget);
static void bonobo_dock_item_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
static void bonobo_dock_item_paint (GtkWidget *widget,
GdkEventExpose *event);
static gboolean bonobo_dock_item_expose (GtkWidget *widget,
GdkEventExpose *event);
static gboolean bonobo_dock_item_button_changed (GtkWidget *widget,
GdkEventButton *event);
static gboolean bonobo_dock_item_motion (GtkWidget *widget,
GdkEventMotion *event);
static void bonobo_dock_item_float_window_size_request (GtkWidget *widget, GtkRequisition *requisition, gpointer data);
static void bonobo_dock_item_float_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data);
static gboolean bonobo_dock_item_float_window_expose (GtkWidget *widget, GdkEventExpose *event, gpointer data);
static gboolean bonobo_dock_item_float_window_button_changed (GtkWidget *widget, GdkEventButton *event, gpointer data);
static gboolean bonobo_dock_item_float_window_motion (GtkWidget *widget, GdkEventMotion *event, gpointer data);
static guint dock_item_signals[LAST_SIGNAL] = { 0 };
/* Helper functions. */
static gboolean
check_guint_arg (GObject *object,
const gchar *name,
guint *value_return)
{
GParamSpec *pspec;
g_return_val_if_fail (object != NULL, FALSE);
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
if (pspec != NULL) {
GValue value = { 0, };
g_value_init (&value, G_TYPE_UINT);
g_object_get_property (G_OBJECT (object), name, &value);
*value_return = g_value_get_uint (&value);
g_value_unset (&value);
return TRUE;
} else
return FALSE;
}
static guint
get_preferred_width (BonoboDockItem *dock_item)
{
GtkWidget *child;
guint preferred_width;
child = dock_item->_priv->child;
if (!child)
return 0;
if (! check_guint_arg (G_OBJECT (child), "preferred_width", &preferred_width))
{
GtkRequisition child_requisition;
gtk_widget_get_child_requisition (child, &child_requisition);
preferred_width = child_requisition.width;
}
if (dock_item->orientation == GTK_ORIENTATION_HORIZONTAL)
preferred_width += BONOBO_DOCK_ITEM_NOT_LOCKED (dock_item) ? DRAG_HANDLE_SIZE : 0;
preferred_width += GTK_CONTAINER (dock_item)->border_width * 2;
return preferred_width;
}
static guint
get_preferred_height (BonoboDockItem *dock_item)
{
GtkWidget *child;
guint preferred_height;
child = dock_item->_priv->child;
if (!child)
return 0;
if (! check_guint_arg (G_OBJECT (child), "preferred_height", &preferred_height))
{
GtkRequisition child_requisition;
gtk_widget_get_child_requisition (child, &child_requisition);
preferred_height = child_requisition.height;
}
if (dock_item->orientation == GTK_ORIENTATION_VERTICAL)
preferred_height += BONOBO_DOCK_ITEM_NOT_LOCKED (dock_item) ? DRAG_HANDLE_SIZE : 0;
preferred_height += GTK_CONTAINER (dock_item)->border_width * 2;
return preferred_height;
}
static void
bonobo_dock_item_class_init (BonoboDockItemClass *klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
gobject_class = (GObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
container_class = (GtkContainerClass *) klass;
gobject_class->set_property = bonobo_dock_item_set_property;
gobject_class->get_property = bonobo_dock_item_get_property;
g_object_class_install_property (
gobject_class,
PROP_SHADOW,
g_param_spec_enum ("shadow",
_("Shadow type"),
_("Shadow type"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_OUT,
(G_PARAM_READABLE |
G_PARAM_WRITABLE)));
g_object_class_install_property (
gobject_class,
PROP_ORIENTATION,
g_param_spec_enum ("orientation",
_("Orientation"),
_("Orientation"),
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_HORIZONTAL,
(G_PARAM_READABLE |
G_PARAM_WRITABLE)));
g_object_class_install_property (
gobject_class,
PROP_PREFERRED_WIDTH,
g_param_spec_uint ("preferred_width",
_("Preferred width"),
_("Preferred width"),
0, G_MAXINT, 0,
G_PARAM_READABLE));
g_object_class_install_property (
gobject_class,
PROP_PREFERRED_HEIGHT,
g_param_spec_uint ("preferred_height",
_("Preferred height"),
_("Preferred height"),
0, G_MAXINT, 0,
G_PARAM_READABLE));
dock_item_signals[DOCK_DRAG_BEGIN] =
g_signal_new ("dock_drag_begin",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (BonoboDockItemClass,
dock_drag_begin),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
dock_item_signals[DOCK_DRAG_MOTION] =
g_signal_new ("dock_drag_motion",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (BonoboDockItemClass, dock_drag_motion),
NULL, NULL,
bonobo_ui_marshal_VOID__INT_INT,
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
dock_item_signals[DOCK_DRAG_END] =
g_signal_new ("dock_drag_end",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (BonoboDockItemClass, dock_drag_end),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
dock_item_signals[DOCK_DETACH] =
g_signal_new ("dock_detach",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (BonoboDockItemClass, dock_detach),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
dock_item_signals[ORIENTATION_CHANGED] =
g_signal_new ("orientation_changed",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (BonoboDockItemClass, orientation_changed),
NULL, NULL,
g_cclosure_marshal_VOID__ENUM,
G_TYPE_NONE, 1, GTK_TYPE_ORIENTATION);
gobject_class->finalize = bonobo_dock_item_finalize;
widget_class->map = bonobo_dock_item_map;
widget_class->unmap = bonobo_dock_item_unmap;
widget_class->realize = bonobo_dock_item_realize;
widget_class->unrealize = bonobo_dock_item_unrealize;
widget_class->style_set = bonobo_dock_item_style_set;
widget_class->size_request = bonobo_dock_item_size_request;
widget_class->size_allocate = bonobo_dock_item_size_allocate;
widget_class->expose_event = bonobo_dock_item_expose;
widget_class->button_press_event = bonobo_dock_item_button_changed;
widget_class->button_release_event = bonobo_dock_item_button_changed;
widget_class->motion_notify_event = bonobo_dock_item_motion;
container_class->add = bonobo_dock_item_add;
container_class->remove = bonobo_dock_item_remove;
container_class->forall = bonobo_dock_item_forall;
}
static void
bonobo_dock_item_instance_init (BonoboDockItem *dock_item)
{
GTK_WIDGET_UNSET_FLAGS (dock_item, GTK_NO_WINDOW);
dock_item->_priv = g_new0 (BonoboDockItemPrivate, 1);
dock_item->_priv->grip = bonobo_dock_item_grip_new (dock_item);
dock_item->_priv->float_window = NULL;
dock_item->_priv->float_window_hidden = FALSE;
gtk_widget_set_parent (dock_item->_priv->grip, GTK_WIDGET (dock_item));
gtk_widget_show (dock_item->_priv->grip);
dock_item->bin_window = NULL;
dock_item->float_window = NULL;
dock_item->shadow_type = GTK_SHADOW_OUT;
dock_item->orientation = GTK_ORIENTATION_HORIZONTAL;
dock_item->behavior = BONOBO_DOCK_ITEM_BEH_NORMAL;
dock_item->float_window_mapped = FALSE;
dock_item->is_floating = FALSE;
dock_item->in_drag = FALSE;
dock_item->dragoff_x = 0;
dock_item->dragoff_y = 0;
dock_item->float_x = 0;
dock_item->float_y = 0;
}
static void
bonobo_dock_item_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
BonoboDockItem *dock_item;
g_return_if_fail (object !=