119057 - [CCombo] Drop down CCombo list programmatically
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
index d0cedcc..c599c34 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
@@ -447,8 +447,51 @@
list.deselectAll ();
}
void dropDown (boolean drop) {
- setListVisible(drop);
- if (isDropped()) list.setFocus ();
+ dropDown(drop, true);
+}
+void dropDown (boolean drop, boolean focus) {
+ if (drop == isDropped ()) return;
+ if (!drop) {
+ popup.setVisible (false);
+ if (!isDisposed ()&& arrow.isFocusControl() && focus) {
+ text.setFocus();
+ }
+ return;
+ }
+
+ if (getShell() != popup.getParent ()) {
+ String[] items = list.getItems ();
+ int selectionIndex = list.getSelectionIndex ();
+ list.removeListener (SWT.Dispose, listener);
+ popup.dispose();
+ popup = null;
+ list = null;
+ createPopup (items, selectionIndex);
+ }
+
+ Point size = getSize ();
+ int itemCount = list.getItemCount ();
+ itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
+ int itemHeight = list.getItemHeight () * itemCount;
+ Point listSize = list.computeSize (SWT.DEFAULT, itemHeight, false);
+ list.setBounds (1, 1, Math.max (size.x - 2, listSize.x), listSize.y);
+
+ int index = list.getSelectionIndex ();
+ if (index != -1) list.setTopIndex (index);
+ Display display = getDisplay ();
+ Rectangle listRect = list.getBounds ();
+ Rectangle parentRect = display.map (getParent (), null, getBounds ());
+ Point comboSize = getSize ();
+ Rectangle displayRect = getMonitor ().getClientArea ();
+ int width = Math.max (comboSize.x, listRect.width + 2);
+ int height = listRect.height + 2;
+ int x = parentRect.x;
+ int y = parentRect.y + comboSize.y;
+ if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height;
+ if (x + width > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - listRect.width;
+ popup.setBounds (x, y, width, height);
+ popup.setVisible (true);
+ if (focus) list.setFocus ();
}
/*
* Return the lowercase of the first non-'&' character following
@@ -1352,47 +1395,7 @@
*/
public void setListVisible (boolean visible) {
checkWidget ();
- if (visible == isDropped ()) return;
- if (!visible) {
- popup.setVisible (false);
- if (!isDisposed ()&& arrow.isFocusControl()) {
- text.setFocus();
- }
- return;
- }
-
- if (getShell() != popup.getParent ()) {
- String[] items = list.getItems ();
- int selectionIndex = list.getSelectionIndex ();
- list.removeListener (SWT.Dispose, listener);
- popup.dispose();
- popup = null;
- list = null;
- createPopup (items, selectionIndex);
- }
-
- Point size = getSize ();
- int itemCount = list.getItemCount ();
- itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
- int itemHeight = list.getItemHeight () * itemCount;
- Point listSize = list.computeSize (SWT.DEFAULT, itemHeight, false);
- list.setBounds (1, 1, Math.max (size.x - 2, listSize.x), listSize.y);
-
- int index = list.getSelectionIndex ();
- if (index != -1) list.setTopIndex (index);
- Display display = getDisplay ();
- Rectangle listRect = list.getBounds ();
- Rectangle parentRect = display.map (getParent (), null, getBounds ());
- Point comboSize = getSize ();
- Rectangle displayRect = getMonitor ().getClientArea ();
- int width = Math.max (comboSize.x, listRect.width + 2);
- int height = listRect.height + 2;
- int x = parentRect.x;
- int y = parentRect.y + comboSize.y;
- if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height;
- if (x + width > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - listRect.width;
- popup.setBounds (x, y, width, height);
- popup.setVisible (true);
+ dropDown(visible, false);
}
public void setMenu(Menu menu) {
text.setMenu(menu);