diff dwt/custom/CCombo.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children a59d51c12b42
line wrap: on
line diff
--- a/dwt/custom/CCombo.d	Mon May 05 00:12:38 2008 +0200
+++ b/dwt/custom/CCombo.d	Sat May 17 17:34:28 2008 +0200
@@ -51,6 +51,7 @@
 static import tango.text.Unicode;
 static import tango.text.convert.Format;
 import dwt.dwthelper.utils;
+import dwt.dwthelper.Runnable;
 
 /**
  * The CCombo class represents a selectable user interface object
@@ -152,7 +153,12 @@
                 return;
             }
             if (getShell () is event.widget) {
-                handleFocus (DWT.FocusOut);
+                getDisplay().asyncExec(new class() Runnable {
+                    public void run() {
+                        if (isDisposed()) return;
+                        handleFocus (DWT.FocusOut);
+                    }
+                });
             }
         }
     };
@@ -165,13 +171,13 @@
         }
     };
 
-    int [] comboEvents = [DWT.Dispose, DWT.Move, DWT.Resize];
+    int [] comboEvents = [DWT.Dispose, DWT.FocusIn, DWT.Move, DWT.Resize];
     for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
 
-    int [] textEvents = [DWT.KeyDown, DWT.KeyUp, DWT.MenuDetect, DWT.Modify, DWT.MouseDown, DWT.MouseUp, DWT.Traverse, DWT.FocusIn, DWT.Verify];
+    int [] textEvents = [DWT.DefaultSelection, DWT.KeyDown, DWT.KeyUp, DWT.MenuDetect, DWT.Modify, DWT.MouseDown, DWT.MouseUp, DWT.MouseDoubleClick, DWT.MouseWheel, DWT.Traverse, DWT.FocusIn, DWT.Verify];
     for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
 
-    int [] arrowEvents = [DWT.Selection, DWT.FocusIn];
+    int [] arrowEvents = [DWT.MouseDown, DWT.MouseUp, DWT.Selection, DWT.FocusIn];
     for (int i=0; i<arrowEvents.length; i++) arrow.addListener (arrowEvents [i], listener);
 
     createPopup(null, -1);
@@ -179,7 +185,7 @@
 }
 static int checkStyle (int style) {
     int mask = DWT.BORDER | DWT.READ_ONLY | DWT.FLAT | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
-    return style & mask;
+    return DWT.NO_FOCUS | (style & mask);
 }
 /**
  * Adds the argument to the end of the receiver's list.
@@ -318,7 +324,30 @@
             handleFocus (DWT.FocusIn);
             break;
         }
+        case DWT.MouseDown: {
+            Event mouseEvent = new Event ();
+            mouseEvent.button = event.button;
+            mouseEvent.count = event.count;
+            mouseEvent.stateMask = event.stateMask;
+            mouseEvent.time = event.time;
+            mouseEvent.x = event.x; mouseEvent.y = event.y;
+            notifyListeners (DWT.MouseDown, mouseEvent);
+            event.doit = mouseEvent.doit;
+            break;
+        }
+        case DWT.MouseUp: {
+            Event mouseEvent = new Event ();
+            mouseEvent.button = event.button;
+            mouseEvent.count = event.count;
+            mouseEvent.stateMask = event.stateMask;
+            mouseEvent.time = event.time;
+            mouseEvent.x = event.x; mouseEvent.y = event.y;
+            notifyListeners (DWT.MouseUp, mouseEvent);
+            event.doit = mouseEvent.doit;
+            break;
+        }
         case DWT.Selection: {
+            text.setFocus();
             dropDown (!isDropped ());
             break;
         }
@@ -363,6 +392,15 @@
             list = null;
             arrow = null;
             break;
+        case DWT.FocusIn:
+            Control focusControl = getDisplay ().getFocusControl ();
+            if (focusControl is arrow || focusControl is list) return;
+            if (isDropped()) {
+                list.setFocus();
+            } else {
+                text.setFocus();
+            }
+            break;
         case DWT.Move:
             dropDown (false);
             break;
@@ -465,7 +503,12 @@
  */
 public void deselect (int index) {
     checkWidget ();
-    list.deselect (index);
+    if (0 <= index && index < list.getItemCount () &&
+            index is list.getSelectionIndex() &&
+            text.getText().equals(list.getItem(index))) {
+        text.setText("");  //$NON-NLS-1$
+        list.deselect (index);
+    }
 }
 /**
  * Deselects all selected items in the receiver's list.
@@ -483,13 +526,14 @@
  */
 public void deselectAll () {
     checkWidget ();
+    text.setText("");  //$NON-NLS-1$
     list.deselectAll ();
 }
 void dropDown (bool drop) {
     if (drop is isDropped ()) return;
     if (!drop) {
         popup.setVisible (false);
-        if (!isDisposed ()&& arrow.isFocusControl()) {
+        if (!isDisposed () && isFocusControl()) {
             text.setFocus();
         }
         return;
@@ -527,7 +571,7 @@
     if (x + width > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - listRect.width;
     popup.setBounds (x, y, width, height);
     popup.setVisible (true);
-    list.setFocus ();
+    if (isFocusControl()) list.setFocus ();
 }
 /*
  * Return the lowercase of the first non-'&' character following
@@ -655,6 +699,29 @@
     checkWidget ();
     return list.getItems ();
 }
+/**
+ * Returns <code>true</code> if the receiver's list is visible,
+ * and <code>false</code> otherwise.
+ * <p>
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, this method
+ * may still indicate that it is considered visible even though
+ * it may not actually be showing.
+ * </p>
+ *
+ * @return the receiver's list's visibility state
+ *
+ * @exception DWTException <ul>
+ *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 3.4
+ */
+public bool getListVisible () {
+    checkWidget ();
+    return isDropped();
+}
 public override Menu getMenu() {
     return text.getMenu();
 }
@@ -905,7 +972,7 @@
 
         public void getLocation (AccessibleControlEvent e) {
             Rectangle location = getBounds ();
-            Point pt = toDisplay (location.x, location.y);
+            Point pt = getParent().toDisplay (location.x, location.y);
             e.x = pt.x;
             e.y = pt.y;
             e.width = location.width;
@@ -1002,6 +1069,12 @@
                 case DWT.TRAVERSE_ARROW_NEXT:
                     event.doit = false;
                     break;
+                case DWT.TRAVERSE_TAB_NEXT:
+                case DWT.TRAVERSE_TAB_PREVIOUS:
+                    event.doit = text.traverse(event.detail);
+                    event.detail = DWT.TRAVERSE_NONE;
+                    if (event.doit) dropDown(false);
+                    return;
                 default:
             }
             Event e = new Event ();
@@ -1093,8 +1166,10 @@
              * we hide the popup in the deactivate event, the selection event will show
              * it again. To prevent the popup from showing again, we will let the selection
              * event of the arrow button hide the popup.
+             * In Windows, hiding the popup during the deactivate causes the deactivate
+             * to be called twice and the selection event to be disappear.
              */
-            if ("gtk".equals(DWT.getPlatform())) {
+            if (!"carbon".equals(DWT.getPlatform())) {
                 Point point = arrow.toControl(getDisplay().getCursorLocation());
                 Point size = arrow.getSize();
                 Rectangle rect = new Rectangle(0, 0, size.x, size.y);
@@ -1317,6 +1392,7 @@
 }
 public override bool setFocus () {
     checkWidget();
+    if (!isEnabled () || !isVisible ()) return false;
     if (isFocusControl ()) return true;
     return text.setFocus ();
 }
@@ -1394,6 +1470,28 @@
     checkWidget ();
     return;
 }
+/**
+ * Marks the receiver's list as visible if the argument is <code>true</code>,
+ * and marks it invisible otherwise.
+ * <p>
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, marking
+ * it visible may not actually cause it to be displayed.
+ * </p>
+ *
+ * @param visible the new visibility state
+ *
+ * @exception DWTException <ul>
+ *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 3.4
+ */
+public void setListVisible (bool visible) {
+    checkWidget ();
+    dropDown(visible);
+}
 public override void setMenu(Menu menu) {
     text.setMenu(menu);
 }
@@ -1526,6 +1624,14 @@
             handleFocus (DWT.FocusIn);
             break;
         }
+        case DWT.DefaultSelection: {
+            dropDown (false);
+            Event e = new Event ();
+            e.time = event.time;
+            e.stateMask = event.stateMask;
+            notifyListeners (DWT.DefaultSelection, e);
+            break;
+        }
         case DWT.KeyDown: {
             Event keyEvent = new Event ();
             keyEvent.time = event.time;
@@ -1536,16 +1642,6 @@
             if (isDisposed ()) break;
             event.doit = keyEvent.doit;
             if (!event.doit) break;
-
-            if (event.character is DWT.CR) {
-                dropDown (false);
-                Event selectionEvent = new Event ();
-                selectionEvent.time = event.time;
-                selectionEvent.stateMask = event.stateMask;
-                notifyListeners (DWT.DefaultSelection, selectionEvent);
-                if (isDisposed ()) break;
-            }
-
             if (event.keyCode is DWT.ARROW_UP || event.keyCode is DWT.ARROW_DOWN) {
                 event.doit = false;
                 if ((event.stateMask & DWT.ALT) !is 0) {
@@ -1599,6 +1695,16 @@
             break;
         }
         case DWT.MouseDown: {
+            Event mouseEvent = new Event ();
+            mouseEvent.button = event.button;
+            mouseEvent.count = event.count;
+            mouseEvent.stateMask = event.stateMask;
+            mouseEvent.time = event.time;
+            mouseEvent.x = event.x; mouseEvent.y = event.y;
+            notifyListeners (DWT.MouseDown, mouseEvent);
+            if (isDisposed ()) break;
+            event.doit = mouseEvent.doit;
+            if (!event.doit) break;
             if (event.button !is 1) return;
             if (text.getEditable ()) return;
             bool dropped = isDropped ();
@@ -1608,14 +1714,60 @@
             break;
         }
         case DWT.MouseUp: {
+            Event mouseEvent = new Event ();
+            mouseEvent.button = event.button;
+            mouseEvent.count = event.count;
+            mouseEvent.stateMask = event.stateMask;
+            mouseEvent.time = event.time;
+            mouseEvent.x = event.x; mouseEvent.y = event.y;
+            notifyListeners (DWT.MouseUp, mouseEvent);
+            if (isDisposed ()) break;
+            event.doit = mouseEvent.doit;
+            if (!event.doit) break;
             if (event.button !is 1) return;
             if (text.getEditable ()) return;
             text.selectAll ();
             break;
         }
+        case DWT.MouseDoubleClick: {
+            Event mouseEvent = new Event ();
+            mouseEvent.button = event.button;
+            mouseEvent.count = event.count;
+            mouseEvent.stateMask = event.stateMask;
+            mouseEvent.time = event.time;
+            mouseEvent.x = event.x; mouseEvent.y = event.y;
+            notifyListeners (DWT.MouseDoubleClick, mouseEvent);
+            break;
+        }
+        case DWT.MouseWheel: {
+            Event keyEvent = new Event ();
+            keyEvent.time = event.time;
+            keyEvent.keyCode = event.count > 0 ? DWT.ARROW_UP : DWT.ARROW_DOWN;
+            keyEvent.stateMask = event.stateMask;
+            notifyListeners (DWT.KeyDown, keyEvent);
+            if (isDisposed ()) break;
+            event.doit = keyEvent.doit;
+            if (!event.doit) break;
+            if (event.count !is 0) {
+                event.doit = false;
+                int oldIndex = getSelectionIndex ();
+                if (event.count > 0) {
+                    select (Math.max (oldIndex - 1, 0));
+                } else {
+                    select (Math.min (oldIndex + 1, getItemCount () - 1));
+                }
+                if (oldIndex !is getSelectionIndex ()) {
+                    Event e = new Event();
+                    e.time = event.time;
+                    e.stateMask = event.stateMask;
+                    notifyListeners (DWT.Selection, e);
+                }
+                if (isDisposed ()) break;
+            }
+            break;
+        }
         case DWT.Traverse: {
             switch (event.detail) {
-                case DWT.TRAVERSE_RETURN:
                 case DWT.TRAVERSE_ARROW_PREVIOUS:
                 case DWT.TRAVERSE_ARROW_NEXT:
                     // The enter causes default selection and
@@ -1623,9 +1775,12 @@
                     // do not use them for traversal.
                     event.doit = false;
                     break;
+                case DWT.TRAVERSE_TAB_PREVIOUS:
+                    event.doit = traverse(DWT.TRAVERSE_TAB_PREVIOUS);
+                    event.detail = DWT.TRAVERSE_NONE;
+                    return;
                 default:
             }
-
             Event e = new Event ();
             e.time = event.time;
             e.detail = event.detail;