Commit 58d5cd29 authored by Michael Natterer's avatar Michael Natterer 😴

app: remove most of our own dockable DND code

and use GtkNotebook's implementation instead. This is mostly moving
dockable adding and removing code to GtkNotebook::page_added() and
::page_removed() and removing lots of code.
parent 4d03c166
......@@ -599,7 +599,7 @@ static const GimpDndDataDef dnd_data_defs[] =
},
{
GIMP_TARGET_DIALOG,
GIMP_TARGET_NOTEBOOK_TAB,
NULL,
NULL,
......
......@@ -91,8 +91,8 @@
#define GIMP_TARGET_TOOL_INFO \
{ "application/x-gimp-tool-info-name", GTK_TARGET_SAME_APP, GIMP_DND_TYPE_TOOL_INFO }
#define GIMP_TARGET_DIALOG \
{ "application/x-gimp-dialog", GTK_TARGET_SAME_APP, GIMP_DND_TYPE_DIALOG }
#define GIMP_TARGET_NOTEBOOK_TAB \
{ "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, GIMP_DND_TYPE_NOTEBOOK_TAB }
/* dnd initialization */
......
......@@ -77,7 +77,8 @@ static void gimp_dock_real_book_added (GimpDock *dock,
static void gimp_dock_real_book_removed (GimpDock *dock,
GimpDockbook *dockbook);
static void gimp_dock_invalidate_description (GimpDock *dock);
static gboolean gimp_dock_dropped_cb (GtkWidget *source,
static gboolean gimp_dock_dropped_cb (GtkWidget *notebook,
GtkWidget *child,
gint insert_index,
gpointer data);
......@@ -290,22 +291,21 @@ gimp_dock_invalidate_description (GimpDock *dock)
}
static gboolean
gimp_dock_dropped_cb (GtkWidget *source,
gimp_dock_dropped_cb (GtkWidget *notebook,
GtkWidget *child,
gint insert_index,
gpointer data)
{
GimpDock *dock = GIMP_DOCK (data);
GimpDockable *dockable = gimp_dockbook_drag_source_to_dockable (source);
GimpDockbook *dockbook = GIMP_DOCKBOOK (notebook);
GimpDockable *dockable = GIMP_DOCKABLE (child);
GimpDialogFactory *factory;
GtkWidget *dockbook = NULL;
if (!dockable )
return FALSE;
GtkWidget *new_dockbook;
/* if dropping to the same dock, take care that we don't try
* to reorder the *only* dockable in the dock
*/
if (gimp_dockbook_get_dock (gimp_dockable_get_dockbook (dockable)) == dock)
if (gimp_dockbook_get_dock (dockbook) == dock)
{
GList *children;
gint n_books;
......@@ -323,15 +323,15 @@ gimp_dock_dropped_cb (GtkWidget *source,
/* Detach the dockable from the old dockbook */
g_object_ref (dockable);
gimp_dockbook_remove (gimp_dockable_get_dockbook (dockable), dockable);
gtk_notebook_detach_tab (GTK_NOTEBOOK (notebook), child);
/* Create a new dockbook */
factory = gimp_dock_get_dialog_factory (dock);
dockbook = gimp_dockbook_new (gimp_dialog_factory_get_menu_factory (factory));
gimp_dock_add_book (dock, GIMP_DOCKBOOK (dockbook), insert_index);
new_dockbook = gimp_dockbook_new (gimp_dialog_factory_get_menu_factory (factory));
gimp_dock_add_book (dock, GIMP_DOCKBOOK (new_dockbook), insert_index);
/* Add the dockable to new new dockbook */
gimp_dockbook_add (GIMP_DOCKBOOK (dockbook), dockable, -1);
gimp_dockbook_add (GIMP_DOCKBOOK (new_dockbook), dockable, -1);
g_object_unref (dockable);
return TRUE;
......
......@@ -67,12 +67,6 @@ struct _GimpDockablePrivate
GimpDockbook *dockbook;
GimpContext *context;
GimpPanedBox *drag_handler;
/* drag icon hotspot */
gint drag_x;
gint drag_y;
};
......@@ -89,20 +83,6 @@ static void gimp_dockable_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void gimp_dockable_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time);
static gboolean gimp_dockable_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static gboolean gimp_dockable_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static void gimp_dockable_style_updated (GtkWidget *widget);
static void gimp_dockable_add (GtkContainer *container,
......@@ -124,7 +104,7 @@ G_DEFINE_TYPE_WITH_CODE (GimpDockable, gimp_dockable, GTK_TYPE_BIN,
#define parent_class gimp_dockable_parent_class
static const GtkTargetEntry dialog_target_table[] = { GIMP_TARGET_DIALOG };
static const GtkTargetEntry dialog_target_table[] = { GIMP_TARGET_NOTEBOOK_TAB };
static void
......@@ -139,9 +119,6 @@ gimp_dockable_class_init (GimpDockableClass *klass)
object_class->get_property = gimp_dockable_get_property;
widget_class->style_updated = gimp_dockable_style_updated;
widget_class->drag_leave = gimp_dockable_drag_leave;
widget_class->drag_motion = gimp_dockable_drag_motion;
widget_class->drag_drop = gimp_dockable_drag_drop;
container_class->add = gimp_dockable_add;
container_class->child_type = gimp_dockable_child_type;
......@@ -172,8 +149,6 @@ gimp_dockable_init (GimpDockable *dockable)
GimpDockablePrivate);
dockable->p->tab_style = GIMP_TAB_STYLE_PREVIEW;
dockable->p->drag_x = GIMP_DOCKABLE_DRAG_OFFSET;
dockable->p->drag_y = GIMP_DOCKABLE_DRAG_OFFSET;
gtk_drag_dest_set (GTK_WIDGET (dockable),
0,
......@@ -263,69 +238,6 @@ gimp_dockable_get_property (GObject *object,
}
}
static void
gimp_dockable_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time)
{
gimp_highlight_widget (widget, FALSE);
}
static gboolean
gimp_dockable_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GimpDockable *dockable = GIMP_DOCKABLE (widget);
if (gimp_paned_box_will_handle_drag (dockable->p->drag_handler,
widget,
context,
x, y,
time))
{
gdk_drag_status (context, 0, time);
gimp_highlight_widget (widget, FALSE);
return FALSE;
}
gdk_drag_status (context, GDK_ACTION_MOVE, time);
gimp_highlight_widget (widget, TRUE);
/* Return TRUE so drag_leave() is called */
return TRUE;
}
static gboolean
gimp_dockable_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GimpDockable *dockable = GIMP_DOCKABLE (widget);
gboolean dropped;
if (gimp_paned_box_will_handle_drag (dockable->p->drag_handler,
widget,
context,
x, y,
time))
{
return FALSE;
}
dropped = gimp_dockbook_drop_dockable (GIMP_DOCKABLE (widget)->p->dockbook,
gtk_drag_get_source_widget (context));
gtk_drag_finish (context, dropped, TRUE, time);
return TRUE;
}
static void
gimp_dockable_style_updated (GtkWidget *widget)
{
......@@ -561,38 +473,6 @@ gimp_dockable_get_locked (GimpDockable *dockable)
return dockable->p->locked;
}
void
gimp_dockable_set_drag_pos (GimpDockable *dockable,
gint drag_x,
gint drag_y)
{
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
dockable->p->drag_x = drag_x;
dockable->p->drag_y = drag_y;
}
void
gimp_dockable_get_drag_pos (GimpDockable *dockable,
gint *drag_x,
gint *drag_y)
{
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
if (drag_x != NULL)
*drag_x = dockable->p->drag_x;
if (drag_y != NULL)
*drag_y = dockable->p->drag_y;
}
GimpPanedBox *
gimp_dockable_get_drag_handler (GimpDockable *dockable)
{
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), NULL);
return dockable->p->drag_handler;
}
void
gimp_dockable_set_locked (GimpDockable *dockable,
gboolean lock)
......@@ -638,29 +518,6 @@ gimp_dockable_create_tab_widget (GimpDockable *dockable,
tab_style, size, FALSE);
}
GtkWidget *
gimp_dockable_create_drag_widget (GimpDockable *dockable)
{
GtkWidget *frame;
GtkWidget *widget;
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), NULL);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
widget = gimp_dockable_new_tab_widget_internal (dockable,
dockable->p->context,
GIMP_TAB_STYLE_ICON_BLURB,
GTK_ICON_SIZE_DND,
TRUE);
gtk_container_set_border_width (GTK_CONTAINER (widget), 6);
gtk_container_add (GTK_CONTAINER (frame), widget);
gtk_widget_show (widget);
return frame;
}
void
gimp_dockable_set_context (GimpDockable *dockable,
GimpContext *context)
......@@ -698,23 +555,6 @@ gimp_dockable_get_menu (GimpDockable *dockable,
return NULL;
}
/**
* gimp_dockable_set_drag_handler:
* @dockable:
* @handler:
*
* Set a drag handler that will be asked if it will handle drag events
* before the dockable handles the event itself.
**/
void
gimp_dockable_set_drag_handler (GimpDockable *dockable,
GimpPanedBox *handler)
{
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
dockable->p->drag_handler = handler;
}
void
gimp_dockable_detach (GimpDockable *dockable)
{
......
......@@ -74,14 +74,6 @@ GtkWidget * gimp_dockable_get_icon (GimpDockable *dockable,
GtkIconSize size);
gboolean gimp_dockable_get_locked (GimpDockable *dockable);
void gimp_dockable_set_drag_pos (GimpDockable *dockable,
gint drag_x,
gint drag_y);
void gimp_dockable_get_drag_pos (GimpDockable *dockable,
gint *drag_x,
gint *drag_y);
GimpPanedBox * gimp_dockable_get_drag_handler (GimpDockable *dockable);
void gimp_dockable_set_locked (GimpDockable *dockable,
gboolean lock);
gboolean gimp_dockable_is_locked (GimpDockable *dockable);
......@@ -92,14 +84,11 @@ GtkWidget * gimp_dockable_create_tab_widget (GimpDockable *dockable,
GimpContext *context,
GimpTabStyle tab_style,
GtkIconSize size);
GtkWidget * gimp_dockable_create_drag_widget (GimpDockable *dockable);
void gimp_dockable_set_context (GimpDockable *dockable,
GimpContext *context);
GimpUIManager * gimp_dockable_get_menu (GimpDockable *dockable,
const gchar **ui_path,
gpointer *popup_data);
void gimp_dockable_set_drag_handler (GimpDockable *dockable,
GimpPanedBox *drag_handler);
void gimp_dockable_detach (GimpDockable *dockable);
......
This diff is collapsed.
......@@ -77,11 +77,8 @@ void gimp_dockbook_update_with_context (GimpDockbook *dockbo
GimpContext *context);
GtkWidget * gimp_dockbook_create_tab_widget (GimpDockbook *dockbook,
GimpDockable *dockable);
gboolean gimp_dockbook_drop_dockable (GimpDockbook *dockbook,
GtkWidget *drag_source);
void gimp_dockbook_set_drag_handler (GimpDockbook *dockbook,
GimpPanedBox *drag_handler);
GimpDockable * gimp_dockbook_drag_source_to_dockable (GtkWidget *drag_source);
#endif /* __GIMP_DOCKBOOK_H__ */
......@@ -79,7 +79,8 @@ static void gimp_dock_columns_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gboolean gimp_dock_columns_dropped_cb (GtkWidget *source,
static gboolean gimp_dock_columns_dropped_cb (GtkWidget *notebook,
GtkWidget *child,
gint insert_index,
gpointer data);
static void gimp_dock_columns_real_dock_added (GimpDockColumns *dock_columns,
......@@ -286,29 +287,27 @@ gimp_dock_columns_get_property (GObject *object,
}
static gboolean
gimp_dock_columns_dropped_cb (GtkWidget *source,
gimp_dock_columns_dropped_cb (GtkWidget *notebook,
GtkWidget *child,
gint insert_index,
gpointer data)
{
GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (data);
GimpDockable *dockable = gimp_dockbook_drag_source_to_dockable (source);
GtkWidget *dockbook = NULL;
if (! dockable)
return FALSE;
GimpDockable *dockable = GIMP_DOCKABLE (child);
GtkWidget *new_dockbook = NULL;
/* Create a new dock (including a new dockbook) */
gimp_dock_columns_prepare_dockbook (dock_columns,
insert_index,
&dockbook);
&new_dockbook);
/* Move the dockable to the new dockbook */
g_object_ref (dockbook);
g_object_ref (new_dockbook);
g_object_ref (dockable);
gimp_dockbook_remove (gimp_dockable_get_dockbook (dockable), dockable);
gimp_dockbook_add (GIMP_DOCKBOOK (dockbook), dockable, -1);
gtk_notebook_detach_tab (GTK_NOTEBOOK (notebook), child);
gimp_dockbook_add (GIMP_DOCKBOOK (new_dockbook), dockable, -1);
g_object_unref (dockable);
g_object_unref (dockbook);
g_object_unref (new_dockbook);
return TRUE;
}
......
......@@ -51,7 +51,7 @@
* order to be inserted and get space on their own (rather than
* inserted among others and sharing space)
*/
#define DROP_AREA_SIZE 6
#define DROP_AREA_SIZE 12
#define INSERT_INDEX_UNUSED G_MININT
......@@ -98,6 +98,13 @@ static gboolean gimp_paned_box_drag_drop (GtkWidget *widget,
gint x,
gint y,
guint time);
static void gimp_paned_box_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint info,
guint time);
static void gimp_paned_box_set_widget_drag_handler (GtkWidget *widget,
GimpPanedBox *handler);
static gint gimp_paned_box_get_drop_area_size (GimpPanedBox *paned_box);
......@@ -108,7 +115,7 @@ G_DEFINE_TYPE (GimpPanedBox, gimp_paned_box, GTK_TYPE_BOX)
#define parent_class gimp_paned_box_parent_class
static const GtkTargetEntry dialog_target_table[] = { GIMP_TARGET_DIALOG };
static const GtkTargetEntry dialog_target_table[] = { GIMP_TARGET_NOTEBOOK_TAB };
static void
......@@ -117,11 +124,12 @@ gimp_paned_box_class_init (GimpPanedBoxClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = gimp_paned_box_dispose;
object_class->dispose = gimp_paned_box_dispose;
widget_class->drag_leave = gimp_paned_box_drag_leave;
widget_class->drag_motion = gimp_paned_box_drag_motion;
widget_class->drag_drop = gimp_paned_box_drag_drop;
widget_class->drag_leave = gimp_paned_box_drag_leave;
widget_class->drag_motion = gimp_paned_box_drag_motion;
widget_class->drag_drop = gimp_paned_box_drag_drop;
widget_class->drag_data_received = gimp_paned_box_drag_data_received;
g_type_class_add_private (klass, sizeof (GimpPanedBoxPrivate));
}
......@@ -310,7 +318,6 @@ gimp_paned_box_drag_leave (GtkWidget *widget,
guint time)
{
gimp_paned_box_hide_drop_indicator (GIMP_PANED_BOX (widget));
gimp_highlight_widget (widget, FALSE);
}
static gboolean
......@@ -320,16 +327,16 @@ gimp_paned_box_drag_motion (GtkWidget *widget,
gint y,
guint time)
{
GimpPanedBox *paned_box = GIMP_PANED_BOX (widget);
gint insert_index = INSERT_INDEX_UNUSED;
gint dnd_window_x = 0;
gint dnd_window_y = 0;
gint dnd_window_w = 0;
gint dnd_window_h = 0;
GtkAllocation allocation = { 0, };
GtkOrientation orientation = 0;
gboolean handle = FALSE;
gint drop_area_size = gimp_paned_box_get_drop_area_size (paned_box);
GimpPanedBox *paned_box = GIMP_PANED_BOX (widget);
gint insert_index = INSERT_INDEX_UNUSED;
gint dnd_window_x;
gint dnd_window_y;
gint dnd_window_w;
gint dnd_window_h;
GtkAllocation allocation;
GtkOrientation orientation;
gboolean handle;
gint drop_area_size;
if (gimp_paned_box_will_handle_drag (paned_box->p->drag_handler,
widget,
......@@ -338,17 +345,19 @@ gimp_paned_box_drag_motion (GtkWidget *widget,
time))
{
gdk_drag_status (context, 0, time);
gimp_highlight_widget (widget, FALSE);
return FALSE;
}
drop_area_size = gimp_paned_box_get_drop_area_size (paned_box);
gtk_widget_get_allocation (widget, &allocation);
/* See if we're at the edge of the dock If there are no dockables,
* the entire paned box is a drop area
*/
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (paned_box));
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
dnd_window_y = 0;
......@@ -367,6 +376,7 @@ gimp_paned_box_drag_motion (GtkWidget *widget,
insert_index = 0;
dnd_window_x = 0;
}
if (x > allocation.width - drop_area_size)
{
insert_index = -1;
......@@ -391,6 +401,7 @@ gimp_paned_box_drag_motion (GtkWidget *widget,
insert_index = 0;
dnd_window_y = 0;
}
if (y > allocation.height - drop_area_size)
{
insert_index = -1;
......@@ -402,11 +413,12 @@ gimp_paned_box_drag_motion (GtkWidget *widget,
* drop will create a new dock column
*/
handle = (insert_index != INSERT_INDEX_UNUSED);
if (handle)
{
gimp_paned_box_position_drop_indicator (paned_box,
allocation.x + dnd_window_x,
allocation.y + dnd_window_y,
dnd_window_x,
dnd_window_y,
dnd_window_w,
dnd_window_h);
}
......@@ -419,7 +431,6 @@ gimp_paned_box_drag_motion (GtkWidget *widget,
paned_box->p->insert_index = insert_index;
gdk_drag_status (context, handle ? GDK_ACTION_MOVE : 0, time);
gimp_highlight_widget (widget, handle);
/* Return TRUE so drag_leave() is called */
return TRUE;
......@@ -433,7 +444,7 @@ gimp_paned_box_drag_drop (GtkWidget *widget,
guint time)
{
GimpPanedBox *paned_box = GIMP_PANED_BOX (widget);
gboolean dropped = FALSE;
GdkAtom target;
if (gimp_paned_box_will_handle_drag (paned_box->p->drag_handler,
widget,
......@@ -444,22 +455,38 @@ gimp_paned_box_drag_drop (GtkWidget *widget,
return FALSE;
}
target = gtk_drag_dest_find_target (widget, context, NULL);
gtk_drag_get_data (widget, context, target, time);
return TRUE;
}
static void
gimp_paned_box_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint info,
guint time)
{
GimpPanedBox *paned_box = GIMP_PANED_BOX (widget);
GtkWidget *notebook = gtk_drag_get_source_widget (context);
GtkWidget **child = (gpointer) gtk_selection_data_get_data (data);
gboolean dropped = FALSE;
if (paned_box->p->dropped_cb)
{
GtkWidget *source = gtk_drag_get_source_widget (context);
if (source)
dropped = paned_box->p->dropped_cb (source,
paned_box->p->insert_index,
paned_box->p->dropped_cb_data);
dropped = paned_box->p->dropped_cb (notebook,
*child,
paned_box->p->insert_index,
paned_box->p->dropped_cb_data);
}
gtk_drag_finish (context, dropped, TRUE, time);
return TRUE;
}
GtkWidget *
gimp_paned_box_new (gboolean homogeneous,
gint spacing,
......
......@@ -181,9 +181,9 @@ typedef enum /*< skip >*/
GIMP_DND_TYPE_IMAGEFILE = 21,
GIMP_DND_TYPE_TEMPLATE = 22,
GIMP_DND_TYPE_TOOL_INFO = 23,
GIMP_DND_TYPE_DIALOG = 24,
GIMP_DND_TYPE_NOTEBOOK_TAB = 24,
GIMP_DND_TYPE_LAST = GIMP_DND_TYPE_DIALOG
GIMP_DND_TYPE_LAST = GIMP_DND_TYPE_NOTEBOOK_TAB
} GimpDndType;
typedef enum /*< skip >*/
......
......@@ -303,7 +303,8 @@ typedef void (* GimpMenuPositionFunc) (GtkMenu *menu,
gint *x,
gint *y,
gpointer data);
typedef gboolean (* GimpPanedBoxDroppedFunc) (GtkWidget *source,
typedef gboolean (* GimpPanedBoxDroppedFunc) (GtkWidget *notebook,
GtkWidget *child,
gint insert_index,
gpointer data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment