Bug 497812: requestLayout not layout correctly

Minor refactor of previous patch to avoid using instance of.
Tested with attached sample project, functionality is preserved.

Change-Id: Icfa52ef90a41e1fe63f308b490688c22ebc33cd6
Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
index 00f4c23..ca07d36 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
@@ -868,12 +868,9 @@
 		for (int i=0; i<changed.length; i++) {
 			Control child = changed [i];
 			Composite composite = child.parent;
-			if (child instanceof Composite) {
-				Composite compositeChild = ((Composite) child);
-				if (compositeChild.layout != null) {
-					compositeChild.state |= LAYOUT_NEEDED;
-				}
-			}
+			// Update layout when the list of children has changed.
+			// See bug 497812.
+			child.markLayout(false, false);
 			while (child != this) {
 				if (composite.layout != null) {
 					composite.state |= LAYOUT_NEEDED;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
index dcf1f40..f8665bb 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
@@ -1176,12 +1176,9 @@
 		for (int i=0; i<changed.length; i++) {
 			Control child = changed [i];
 			Composite composite = child.parent;
-			if (child instanceof Composite) {
-				Composite compositeChild = ((Composite) child);
-				if (compositeChild.layout != null) {
-					compositeChild.state |= LAYOUT_NEEDED;
-				}
-			}
+			// Update layout when the list of children has changed.
+			// See bug 497812.
+			child.markLayout(false, false);
 			while (child != this) {
 				if (composite.layout != null) {
 					composite.state |= LAYOUT_NEEDED;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
index 2985de8..cf80097 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
@@ -845,12 +845,9 @@
 		for (int i=0; i<changed.length; i++) {
 			Control child = changed [i];
 			Composite composite = child.parent;
-			if (child instanceof Composite) {
-				Composite compositeChild = ((Composite) child);
-				if (compositeChild.layout != null) {
-					compositeChild.state |= LAYOUT_NEEDED;
-				}
-			}
+			// Update layout when the list of children has changed.
+			// See bug 497812.
+			child.markLayout(false, false);
 			while (child != this) {
 				if (composite.layout != null) {
 					composite.state |= LAYOUT_NEEDED;