Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java124
1 files changed, 75 insertions, 49 deletions
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 f263e2b2fd..ca80b50924 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
@@ -1,8 +1,8 @@
package org.eclipse.swt.custom;
/*
- * Licensed Materials - Property of IBM,
- * (c) Copyright IBM Corp. 1998, 2001 All Rights Reserved
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
*/
import org.eclipse.swt.*;
@@ -15,6 +15,9 @@ import org.eclipse.swt.widgets.*;
* that combines a text field and a list and issues notificiation
* when an item is selected from the list.
* <p>
+ * Note that although this class is a subclass of <code>Composite</code>,
+ * it does not make sense to add children to it, or set a layout on it.
+ * </p>
* <dl>
* <dt><b>Styles:</b>
* <dd>BORDER, READ_ONLY</dd>
@@ -30,6 +33,7 @@ public final class CCombo extends Composite {
List list;
Shell popup;
Button arrow;
+ boolean hasFocus;
public CCombo (Composite parent, int style) {
super (parent, checkStyle (style));
@@ -41,7 +45,7 @@ public CCombo (Composite parent, int style) {
if ((style & SWT.FLAT) != 0) textStyle |= SWT.FLAT;
text = new Text (this, textStyle);
- popup = new Shell (getShell (), SWT.ON_TOP | SWT.NO_TRIM);
+ popup = new Shell (getShell (), SWT.NO_TRIM);
int listStyle = SWT.SINGLE | SWT.V_SCROLL;
if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT;
@@ -77,16 +81,16 @@ public CCombo (Composite parent, int style) {
}
};
- int [] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate};
+ int [] popupEvents = {SWT.Close, SWT.Paint, SWT.Activate, SWT.Deactivate};
for (int i=0; i<popupEvents.length; i++) popup.addListener (popupEvents [i], listener);
- int [] textEvents = {SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.FocusIn, SWT.FocusOut, SWT.Traverse};
+ int [] textEvents = {SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse};
for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
- int [] listEvents = {SWT.MouseUp, SWT.FocusIn, SWT.FocusOut, SWT.Selection};
+ int [] listEvents = {SWT.MouseUp, SWT.Selection};
for (int i=0; i<listEvents.length; i++) list.addListener (listEvents [i], listener);
- int [] comboEvents = {SWT.Dispose, SWT.Move, SWT.Resize};
+ int [] comboEvents = {SWT.Dispose, SWT.Move, SWT.Resize, SWT.Activate, SWT.Deactivate};
for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
int [] arrowEvents = {SWT.MouseDown};
@@ -214,6 +218,24 @@ void comboEvent (Event event) {
case SWT.Resize:
internalLayout();
break;
+ case SWT.Activate: {
+ if (hasFocus) return;
+ hasFocus = true;
+ if (getEditable ()) text.selectAll ();
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusIn, e);
+ break;
+ }
+ case SWT.Deactivate: {
+ Control focusControl = getDisplay ().getFocusControl();
+ if (focusControl == list) return;
+ hasFocus = false;
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusOut, e);
+ break;
+ }
}
}
@@ -267,6 +289,7 @@ void dropDown (boolean drop) {
if (drop == isDropped ()) return;
if (!drop) {
popup.setVisible (false);
+ text.setFocus();
return;
}
int index = list.getSelectionIndex ();
@@ -484,12 +507,19 @@ public int indexOf (String string, int start) {
boolean isDropped () {
return popup.getVisible ();
}
+public boolean isFocusControl () {
+ if (text.isFocusControl() || arrow.isFocusControl() || list.isFocusControl() || popup.isFocusControl()) {
+ return true;
+ } else {
+ return super.isFocusControl();
+ }
+}
void internalLayout () {
+ if (isDropped ()) dropDown (false);
+
Rectangle rect = getClientArea();
int width = rect.width;
int height = rect.height;
-
- if (isDropped ()) dropDown (false);
Point arrowSize = arrow.computeSize(SWT.DEFAULT, height);
text.setBounds (0, 0, width - arrowSize.x, height);
arrow.setBounds (width - arrowSize.x, 0, arrowSize.x, arrowSize.y);
@@ -524,22 +554,6 @@ void listEvent (Event event) {
event.doit = e.doit;
break;
}
- case SWT.FocusOut: {
- Control control = getDisplay ().getFocusControl ();
- if (control == text) return;
- Event e = new Event();
- e.time = event.time;
- notifyListeners(SWT.FocusOut, e);
- break;
- }
- case SWT.FocusIn: {
- Control control = getDisplay ().getFocusControl ();
- if (control == text) return;
- Event e = new Event();
- e.time = event.time;
- notifyListeners(SWT.FocusIn, e);
- break;
- }
}
}
void popupEvent(Event event) {
@@ -555,6 +569,14 @@ void popupEvent(Event event) {
event.doit = false;
dropDown (false);
break;
+ case SWT.Activate:
+ if (hasFocus) return;
+ hasFocus = true;
+ if (getEditable ()) text.selectAll ();
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusIn, e);
+ break;
case SWT.Deactivate:
dropDown (false);
break;
@@ -847,6 +869,16 @@ public void setText (String string) {
public void setTextLimit (int limit) {
text.setTextLimit (limit);
}
+public void setVisible (boolean visible) {
+ super.setVisible(visible);
+ if (!getVisible()) {
+ Composite parent = getParent();
+ while (parent != null && !parent.isVisible()) {
+ parent = parent.getParent();
+ }
+ if (parent != null) parent.setFocus();
+ }
+}
void textEvent (Event event) {
switch (event.type) {
case SWT.KeyDown: {
@@ -911,31 +943,25 @@ void textEvent (Event event) {
text.selectAll ();
break;
}
- case SWT.FocusIn: {
- if (getEditable ()) text.selectAll ();
- Event e = new Event();
- e.time = event.time;
- notifyListeners(SWT.FocusIn, e);
- break;
- }
- case SWT.FocusOut: {
- Display display = getDisplay ();
- Control focusControl = display.getFocusControl ();
- if (isDropped ()) {
- Control cursorControl = display.getCursorControl ();
- if (cursorControl != list) dropDown (false);
- if (focusControl != text) dropDown (false);
- }
- if (focusControl == list) return;
- Event e = new Event();
- e.time = event.time;
- notifyListeners(SWT.FocusOut, e);
- break;
- }
case SWT.Traverse: {
- if (event.detail == SWT.TRAVERSE_ARROW_PREVIOUS || event.detail == SWT.TRAVERSE_ARROW_NEXT) {
- event.doit = false;
+ switch (event.detail) {
+ case SWT.TRAVERSE_RETURN:
+ case SWT.TRAVERSE_TAB_NEXT:
+ // allow "return" and "tab" to have their usual effect
+ break;
+ case SWT.TRAVERSE_ESCAPE:
+ // escape key is used to close the list so
+ // do not use it for traversal
+ event.doit = false;
+ break;
+ case SWT.TRAVERSE_ARROW_PREVIOUS:
+ case SWT.TRAVERSE_ARROW_NEXT:
+ // arrow keys are used to manipulate the list contents so
+ // do not use them for traversal.
+ event.doit = false;
+ break;
}
+
Event e = new Event();
e.time = event.time;
e.detail = event.detail;
@@ -947,4 +973,4 @@ void textEvent (Event event) {
}
}
}
-} \ No newline at end of file
+}

Back to the top