diff dwt/custom/PopupList.d @ 41:6337764516f1

Sync dwt/custom with dwt-linux (took copy of complete folder)
author Frank Benoit <benoit@tionex.de>
date Tue, 07 Oct 2008 16:29:55 +0200
parents 1a8b3cb347e0
children 3d4579727e0e
line wrap: on
line diff
--- a/dwt/custom/PopupList.d	Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/PopupList.d	Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,72 +7,92 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.custom;
+module dwt.custom.PopupList;
+
+import dwt.dwthelper.utils;
+
 
-import dwt.*;
-import dwt.events.*;
-import dwt.graphics.*;
-import dwt.widgets.*;
+import dwt.DWT;
+import dwt.DWTException;
+import dwt.events.ControlEvent;
+import dwt.events.ControlListener;
+import dwt.events.KeyEvent;
+import dwt.events.KeyListener;
+import dwt.events.MouseEvent;
+import dwt.events.MouseListener;
+import dwt.graphics.Font;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.List;
+import dwt.widgets.Listener;
+import dwt.widgets.Shell;
+
 /**
 * A PopupList is a list of selectable items that appears in its own shell positioned above
 * its parent shell.  It is used for selecting items when editing a Table cell (similar to the
 * list that appears when you open a Combo box).
 *
 * The list will be positioned so that it does not run off the screen and the largest number of items
-* are visible.  It may appear above the current cursor location or below it depending how close you 
+* are visible.  It may appear above the current cursor location or below it depending how close you
 * are to the edge of the screen.
+*
+* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
 */
 public class PopupList {
     Shell  shell;
     List   list;
     int    minimumWidth;
-/** 
+/**
 * Creates a PopupList above the specified shell.
-* 
+*
 * @param parent a Shell control which will be the parent of the new instance (cannot be null)
 */
 public this(Shell parent) {
     this (parent, 0);
 }
-/** 
+/**
 * Creates a PopupList above the specified shell.
-* 
+*
 * @param parent a widget which will be the parent of the new instance (cannot be null)
 * @param style the style of widget to construct
-* 
-* @since 3.0 
+*
+* @since 3.0
 */
 public this(Shell parent, int style) {
     shell = new Shell(parent, checkStyle(style));
-    
-    list = new List(shell, DWT.SINGLE | DWT.V_SCROLL);  
+
+    list = new List(shell, DWT.SINGLE | DWT.V_SCROLL);
 
     // close dialog if user selects outside of the shell
-    shell.addListener(DWT.Deactivate, new Listener() {
-        public void handleEvent(Event e){   
+    shell.addListener(DWT.Deactivate, new class() Listener {
+        public void handleEvent(Event e){
             shell.setVisible (false);
         }
     });
-    
+
     // resize shell when list resizes
-    shell.addControlListener(new ControlListener() {
+    shell.addControlListener(new class() ControlListener {
         public void controlMoved(ControlEvent e){}
         public void controlResized(ControlEvent e){
             Rectangle shellSize = shell.getClientArea();
             list.setSize(shellSize.width, shellSize.height);
         }
     });
-    
+
     // return list selection on Mouse Up or Carriage Return
-    list.addMouseListener(new MouseListener() {
+    list.addMouseListener(new class() MouseListener {
         public void mouseDoubleClick(MouseEvent e){}
         public void mouseDown(MouseEvent e){}
         public void mouseUp(MouseEvent e){
             shell.setVisible (false);
         }
     });
-    list.addKeyListener(new KeyListener() {
+    list.addKeyListener(new class() KeyListener {
         public void keyReleased(KeyEvent e){}
         public void keyPressed(KeyEvent e){
             if (e.character is '\r'){
@@ -80,7 +100,7 @@
             }
         }
     });
-    
+
 }
 private static int checkStyle (int style) {
     int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
@@ -149,7 +169,7 @@
             listSize.y += 2;
         }
         y = rect.y - listSize.y;
-        
+
     } else {
         // place popup list below table cell
         if (listSize.y > spaceBelow){
@@ -159,18 +179,18 @@
         }
         y = rect.y + rect.height;
     }
-    
+
     // Make dialog as wide as the cell
     listSize.x = rect.width;
     // dialog width should not be less than minimumWidth
     if (listSize.x < minimumWidth)
         listSize.x = minimumWidth;
-    
+
     // Align right side of dialog with right side of cell
     int x = rect.x + rect.width - listSize.x;
-    
+
     shell.setBounds(x, y, listSize.x, listSize.y);
-    
+
     shell.open();
     list.setFocus();
 
@@ -178,37 +198,37 @@
     while (!shell.isDisposed () && shell.isVisible ()) {
         if (!display.readAndDispatch()) display.sleep();
     }
-    
+
     String result = null;
     if (!shell.isDisposed ()) {
-        String [] Strings = list.getSelection ();
+        String [] strings = list.getSelection ();
         shell.dispose();
-        if (Strings.length !is 0) result = Strings [0];
+        if (strings.length !is 0) result = strings [0];
     }
     return result;
 }
 /**
 * Selects an item with text that starts with specified String.
 * <p>
-* If the item is not currently selected, it is selected.  
-* If the item at an index is selected, it remains selected.  
-* If the String is not matched, it is ignored.
+* If the item is not currently selected, it is selected.
+* If the item at an index is selected, it remains selected.
+* If the string is not matched, it is ignored.
 *
-* @param String the text of the item
+* @param string the text of the item
 *
 * @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>
 */
-public void select(String String) {
+public void select(String string) {
     String[] items = list.getItems();
 
     // find the first entry in the list that starts with the
-    // specified String
-    if (String !is null){
+    // specified string
+    if (string !is null){
         for (int i = 0; i < items.length; i++) {
-            if (items[i].startsWith(String)){
+            if ( tango.text.Util.locatePattern( items[i], string) is 0 ){
                 int index = list.indexOf(items[i]);
                 list.select(index);
                 break;
@@ -223,7 +243,7 @@
 * to the default system font for the widget.
 *
 * @param font the new font (or null)
-* 
+*
 * @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>
@@ -240,13 +260,12 @@
 * The new items are added.
 * The top index is set to 0.
 *
-* @param Strings the array of items
+* @param strings the array of items
 *
 * This operation will fail when an item is null
 * or could not be added in the OS.
-* 
+*
 * @exception IllegalArgumentException <ul>
-*    <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
 *    <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
 * </ul>
 * @exception DWTException <ul>
@@ -254,8 +273,8 @@
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 *   </ul>
 */
-public void setItems (String[] Strings) {
-    list.setItems(Strings);
+public void setItems (String[] strings) {
+    list.setItems(strings);
 }
 /**
 * Sets the minimum width of the list.
@@ -265,7 +284,7 @@
 public void setMinimumWidth (int width) {
     if (width < 0)
         DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-        
+
     minimumWidth = width;
 }
 }