Mercurial > projects > dwt-win
comparison dwt/custom/PopupList.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | a5afe31f5cdd |
children | a59d51c12b42 |
comparison
equal
deleted
inserted
replaced
211:ff59aeb96cac | 212:ab60f3309436 |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2007 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
27 import dwt.widgets.Display; | 27 import dwt.widgets.Display; |
28 import dwt.widgets.Event; | 28 import dwt.widgets.Event; |
29 import dwt.widgets.List; | 29 import dwt.widgets.List; |
30 import dwt.widgets.Listener; | 30 import dwt.widgets.Listener; |
31 import dwt.widgets.Shell; | 31 import dwt.widgets.Shell; |
32 import dwt.dwthelper.utils; | |
33 | |
32 /** | 34 /** |
33 * A PopupList is a list of selectable items that appears in its own shell positioned above | 35 * A PopupList is a list of selectable items that appears in its own shell positioned above |
34 * its parent shell. It is used for selecting items when editing a Table cell (similar to the | 36 * its parent shell. It is used for selecting items when editing a Table cell (similar to the |
35 * list that appears when you open a Combo box). | 37 * list that appears when you open a Combo box). |
36 * | 38 * |
125 * @exception DWTException <ul> | 127 * @exception DWTException <ul> |
126 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 128 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
127 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 129 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
128 * </ul> | 130 * </ul> |
129 */ | 131 */ |
130 public char[][] getItems () { | 132 public String[] getItems () { |
131 return list.getItems(); | 133 return list.getItems(); |
132 } | 134 } |
133 /** | 135 /** |
134 * Gets the minimum width of the list. | 136 * Gets the minimum width of the list. |
135 * | 137 * |
144 * @param rect the initial size and location of the PopupList; the dialog will be | 146 * @param rect the initial size and location of the PopupList; the dialog will be |
145 * positioned so that it does not run off the screen and the largest number of items are visible | 147 * positioned so that it does not run off the screen and the largest number of items are visible |
146 * | 148 * |
147 * @return the text of the selected item or null if no item is selected | 149 * @return the text of the selected item or null if no item is selected |
148 */ | 150 */ |
149 public char[] open (Rectangle rect) { | 151 public String open (Rectangle rect) { |
150 | 152 |
151 Point listSize = list.computeSize (rect.width, DWT.DEFAULT, false); | 153 Point listSize = list.computeSize (rect.width, DWT.DEFAULT, false); |
152 Rectangle screenSize = shell.getDisplay().getBounds(); | 154 Rectangle screenSize = shell.getDisplay().getBounds(); |
153 | 155 |
154 // Position the dialog so that it does not run off the screen and the largest number of items are visible | 156 // Position the dialog so that it does not run off the screen and the largest number of items are visible |
192 Display display = shell.getDisplay(); | 194 Display display = shell.getDisplay(); |
193 while (!shell.isDisposed () && shell.isVisible ()) { | 195 while (!shell.isDisposed () && shell.isVisible ()) { |
194 if (!display.readAndDispatch()) display.sleep(); | 196 if (!display.readAndDispatch()) display.sleep(); |
195 } | 197 } |
196 | 198 |
197 char[] result = null; | 199 String result = null; |
198 if (!shell.isDisposed ()) { | 200 if (!shell.isDisposed ()) { |
199 char[] [] strings = list.getSelection (); | 201 String [] strings = list.getSelection (); |
200 shell.dispose(); | 202 shell.dispose(); |
201 if (strings.length !is 0) result = strings [0]; | 203 if (strings.length !is 0) result = strings [0]; |
202 } | 204 } |
203 return result; | 205 return result; |
204 } | 206 } |
205 /** | 207 /** |
206 * Selects an item with text that starts with specified char[]. | 208 * Selects an item with text that starts with specified String. |
207 * <p> | 209 * <p> |
208 * If the item is not currently selected, it is selected. | 210 * If the item is not currently selected, it is selected. |
209 * If the item at an index is selected, it remains selected. | 211 * If the item at an index is selected, it remains selected. |
210 * If the string is not matched, it is ignored. | 212 * If the string is not matched, it is ignored. |
211 * | 213 * |
214 * @exception DWTException <ul> | 216 * @exception DWTException <ul> |
215 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 217 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
216 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 218 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
217 * </ul> | 219 * </ul> |
218 */ | 220 */ |
219 public void select(char[] string) { | 221 public void select(String string) { |
220 char[][] items = list.getItems(); | 222 String[] items = list.getItems(); |
221 | 223 |
222 // find the first entry in the list that starts with the | 224 // find the first entry in the list that starts with the |
223 // specified string | 225 // specified string |
224 if (string !is null){ | 226 if (string !is null){ |
225 for (int i = 0; i < items.length; i++) { | 227 for (int i = 0; i < items.length; i++) { |
267 * @exception DWTException <ul> | 269 * @exception DWTException <ul> |
268 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 270 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
269 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 271 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
270 * </ul> | 272 * </ul> |
271 */ | 273 */ |
272 public void setItems (char[][] strings) { | 274 public void setItems (String[] strings) { |
273 list.setItems(strings); | 275 list.setItems(strings); |
274 } | 276 } |
275 /** | 277 /** |
276 * Sets the minimum width of the list. | 278 * Sets the minimum width of the list. |
277 * | 279 * |