Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2015-02-03 15:48:22 +0000
committerLeo Ufimtsev2015-02-04 16:41:39 +0000
commite88d85701eb3f196b632b0da3b6a6a6f8376e5b2 (patch)
treea943a1a47310bc424b6fea878fd9ac9c9165cfc2
parentd227a506118c2de93a448ba9902bdded788588dd (diff)
downloadeclipse.platform.swt-e88d85701eb3f196b632b0da3b6a6a6f8376e5b2.tar.gz
eclipse.platform.swt-e88d85701eb3f196b632b0da3b6a6a6f8376e5b2.tar.xz
eclipse.platform.swt-e88d85701eb3f196b632b0da3b6a6a6f8376e5b2.zip
Bug 458844 - [GTK3] TabItem hierarchy change breaks shared control
Fix for correct re-parenting for the case where the tab-control is migrated between tabs via setControl. Test with Junit Gtk2/3 and with own array of tests also. Change-Id: I57b70f32ce86569c7ff9697909df0f83bfcb6167 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java83
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java15
3 files changed, 48 insertions, 52 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
index c599913e2c..8e0a4deac9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
@@ -510,7 +510,7 @@ public void setControl (Control control) {
//As ExpandItem's child can be created before the ExpandItem, our only
//option is to reparent the child upon the setControl(..) call.
//This is simmilar to TabFolder.
- gtk_widget_reparent (control, clientHandle ());
+ gtk_widget_reparent (control.topHandle (), clientHandle ());
}
}
parent.layoutItems (0, true);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
index 6fb8801961..efd1d7e691 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
@@ -287,46 +287,45 @@ public void setControl (Control control) {
if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
}
- if (control != null && OS.GTK3) {
- /*
- * Bug 454936 (see also other 454936 references in TabFolder)
- * Architecture Fix:
- * We reparent the child to be a child of the 'tab' rather than tabfolder's parent swtFixed container.
- * Note, this reparenting is only on the GTK side, not on the SWT side.
- *
- * Note, GTK2 and GTK3 child nesting behaviour is different now.
- * GTK2:
- * swtFixed
- * |-- GtkNoteBook
- * | |-- tabLabel1
- * | |-- tabLabel2
- * |-- swtFixed (child1) //child is sibling of Notebook
- * |-- swtFixed (child2)
- *
- * GTK3+:
- * swtFixed
- * |-- GtkNoteBook
- * |-- tabLabel1
- * |-- tabLabel2
- * |-- swtFixed (child1) //child now child of Notebook.
- * |-- swtFixed (child2)
- *
- * This corrects the hierarchy so that children are beneath gtkNotebook (as oppose to
- * being siblings) and thus fixes DND and background color issues.
- * In gtk2, reparenting doesn't function properly (tab content appear blank),
- * so this is a gtk3-specific behavior.
- *
- * Note about the reason for reparenting:
- * Reparenting (as oppose to adding widget to a tab in the first place) is neccessary
- * because you can have a situation where you create a widget before you create a tab. e.g
- * TabFolder tabFolder = new TabFolder(shell, 0);
- * Composite composite = new Composite(tabFolder, 0);
- * TabItem tabItem = new TabItem(tabFolder, 0);
- * tabitem.setControl(composite);
- */
- gtk_widget_reparent (control, pageHandle);
- }
-
+ if (control != null && OS.GTK3) {
+ /*
+ * Bug 454936 (see also other 454936 references in TabFolder)
+ * Architecture Fix:
+ * We reparent the child to be a child of the 'tab' rather than tabfolder's parent swtFixed container.
+ * Note, this reparenting is only on the GTK side, not on the SWT side.
+ *
+ * Note, GTK2 and GTK3 child nesting behaviour is different now.
+ * GTK2:
+ * swtFixed
+ * |-- GtkNoteBook
+ * | |-- tabLabel1
+ * | |-- tabLabel2
+ * |-- swtFixed (child1) //child is sibling of Notebook
+ * |-- swtFixed (child2)
+ *
+ * GTK3+:
+ * swtFixed
+ * |-- GtkNoteBook
+ * |-- tabLabel1
+ * |-- tabLabel2
+ * |-- swtFixed (child1) //child now child of Notebook.
+ * |-- swtFixed (child2)
+ *
+ * This corrects the hierarchy so that children are beneath gtkNotebook (as oppose to
+ * being siblings) and thus fixes DND and background color issues.
+ * In gtk2, reparenting doesn't function properly (tab content appear blank),
+ * so this is a gtk3-specific behavior.
+ *
+ * Note about the reason for reparenting:
+ * Reparenting (as oppose to adding widget to a tab in the first place) is neccessary
+ * because you can have a situation where you create a widget before you create a tab. e.g
+ * TabFolder tabFolder = new TabFolder(shell, 0);
+ * Composite composite = new Composite(tabFolder, 0);
+ * TabItem tabItem = new TabItem(tabFolder, 0);
+ * tabitem.setControl(composite);
+ */
+ OS.gtk_widget_reparent (control.topHandle (), pageHandle);
+ }
Control oldControl = this.control, newControl = control;
this.control = control;
@@ -345,7 +344,9 @@ public void setControl (Control control) {
newControl.setBounds (parent.getClientArea ());
newControl.setVisible (true);
}
- if (oldControl != null) oldControl.setVisible (false);
+
+ if (oldControl != null && newControl != null && oldControl != newControl)
+ oldControl.setVisible (false);
}
void setFontDescription (long /*int*/ font) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
index 10a310646e..d3713f9fc3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
@@ -979,22 +979,17 @@ long /*int*/ gtk_visibility_notify_event (long /*int*/ widget, long /*int*/ even
return 0;
}
-void gtk_widget_reparent (Control control, long /*int*/ newParent) {
- long /*int*/ widget = control.topHandle ();
- long /*int*/ oldParent = control.parent.topHandle ();
- gtk_widget_reparent(widget, oldParent, newParent);
-}
-
/**
* Reparent on gtk side.
* Note: Composites with a setControl() function should probably use this function
* to correct hierarchy on gtk side.
- * @param control
+ * @param widget the handle to the widget. (usually topHandle())
+ * @param newParent handle to the new widget.
*/
-//Note, we do not actually call * 'gtk_widget_reparent(...) as it's deprecated as of gtk 3.14
-void gtk_widget_reparent (long /*int*/ widget, long /*int*/ oldParent, long /*int*/ newParent) {
+void gtk_widget_reparent (long /*int*/ widget, long /*int*/ newParent) {
+ //Note, we do not actually call * 'gtk_widget_reparent(...) as it's deprecated as of gtk 3.14
OS.g_object_ref (widget); //so that it won't get destroyed due to lack of references.
- OS.gtk_container_remove (oldParent, widget);
+ OS.gtk_container_remove (OS.gtk_widget_get_parent (widget), widget);
OS.gtk_container_add (newParent, widget);
OS.g_object_unref (widget);
}

Back to the top