[gtk+] notebook: Add api to complete tab dnd from the outside
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] notebook: Add api to complete tab dnd from the outside
- Date: Thu, 12 Feb 2015 22:34:42 +0000 (UTC)
commit 8d7a235a045b667b2efad80a93717572b581307b
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Feb 12 17:33:10 2015 -0500
notebook: Add api to complete tab dnd from the outside
This is necessary to avoid unwanted drag cancel animations,
now that GtkNotebook is careful about cancelling a drag
when the dragged tab disappears unexpectedly.
docs/reference/gtk/gtk3-sections.txt | 1 +
gtk/gtknotebook.c | 39 ++++++++++++++++++++++++++++-----
2 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 88f20c3..7db2ee3 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -2485,6 +2485,7 @@ gtk_notebook_prepend_page_menu
gtk_notebook_insert_page
gtk_notebook_insert_page_menu
gtk_notebook_remove_page
+gtk_notebook_detach_tab
gtk_notebook_page_num
gtk_notebook_next_page
gtk_notebook_prev_page
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 3953eec..3de4692 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -3925,6 +3925,29 @@ gtk_notebook_drag_drop (GtkWidget *widget,
return FALSE;
}
+/**
+ * gtk_notebook_detach_tab:
+ * @notebook: a #GtkNotebook
+ * @child: a child
+ *
+ * Removes the child from the notebook.
+ *
+ * This function is very similar to gtk_container_remove(),
+ * but additionally informs the notebook that the removal
+ * is happening as part of a tab DND operation, which should
+ * not be cancelled.
+ *
+ * Since: 3.16
+ */
+void
+gtk_notebook_detach_tab (GtkNotebook *notebook,
+ GtkWidget *child)
+{
+ notebook->priv->remove_in_detach = TRUE;
+ gtk_container_remove (GTK_CONTAINER (notebook), child);
+ notebook->priv->remove_in_detach = FALSE;
+}
+
static void
do_detach_tab (GtkNotebook *from,
GtkNotebook *to,
@@ -3959,9 +3982,7 @@ do_detach_tab (GtkNotebook *from,
"detachable", &detachable,
NULL);
- from->priv->remove_in_detach = TRUE;
- gtk_container_remove (GTK_CONTAINER (from), child);
- from->priv->remove_in_detach = FALSE;
+ gtk_notebook_detach_tab (from, child);
gtk_widget_get_allocation (GTK_WIDGET (to), &to_allocation);
to_priv->mouse_x = x + to_allocation.x;
@@ -8406,6 +8427,14 @@ gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
* destination and accept the target “GTK_NOTEBOOK_TAB”. The notebook
* will fill the selection with a GtkWidget** pointing to the child
* widget that corresponds to the dropped tab.
+ *
+ * Note that you should use gtk_notebook_detach_tab() instead
+ * of gtk_container_remove() if you want to remove the tab from
+ * the source notebook as part of accepting a drop. Otherwise,
+ * the source notebook will think that the dragged tab was
+ * removed from underneath the ongoing drag operation, and
+ * will initiate a drag cancel animation.
+ *
* |[<!-- language="C" -->
* static void
* on_drag_data_received (GtkWidget *widget,
@@ -8419,14 +8448,12 @@ gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
* {
* GtkWidget *notebook;
* GtkWidget **child;
- * GtkContainer *container;
*
* notebook = gtk_drag_get_source_widget (context);
* child = (void*) gtk_selection_data_get_data (data);
*
* process_widget (*child);
- * container = GTK_CONTAINER (notebook);
- * gtk_container_remove (container, *child);
+ * gtk_notebook_detach_tab (GTK_NOTEBOOK (notebook), *child);
* }
* ]|
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]