155
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwt.custom.CCombo;
|
|
14
|
|
15
|
|
16
|
|
17 import dwt.DWT;
|
|
18 import dwt.DWTException;
|
|
19 import dwt.accessibility.ACC;
|
|
20 import dwt.accessibility.AccessibleAdapter;
|
|
21 import dwt.accessibility.AccessibleControlAdapter;
|
|
22 import dwt.accessibility.AccessibleControlEvent;
|
|
23 import dwt.accessibility.AccessibleEvent;
|
|
24 import dwt.accessibility.AccessibleTextAdapter;
|
|
25 import dwt.accessibility.AccessibleTextEvent;
|
|
26 import dwt.events.ModifyListener;
|
|
27 import dwt.events.SelectionEvent;
|
|
28 import dwt.events.SelectionListener;
|
|
29 import dwt.events.VerifyListener;
|
|
30 import dwt.graphics.Color;
|
|
31 import dwt.graphics.Font;
|
|
32 import dwt.graphics.GC;
|
|
33 import dwt.graphics.Point;
|
|
34 import dwt.graphics.Rectangle;
|
|
35 import dwt.widgets.Button;
|
|
36 import dwt.widgets.Composite;
|
|
37 import dwt.widgets.Control;
|
|
38 import dwt.widgets.Display;
|
|
39 import dwt.widgets.Event;
|
|
40 import dwt.widgets.Label;
|
|
41 import dwt.widgets.Layout;
|
|
42 import dwt.widgets.List;
|
|
43 import dwt.widgets.Listener;
|
|
44 import dwt.widgets.Menu;
|
|
45 import dwt.widgets.Shell;
|
|
46 import dwt.widgets.Text;
|
|
47 import dwt.widgets.TypedListener;
|
|
48 import dwt.widgets.Widget;
|
|
49
|
|
50 static import tango.text.convert.Utf;
|
|
51 static import tango.text.Unicode;
|
|
52 static import tango.text.convert.Format;
|
|
53 import dwt.dwthelper.utils;
|
|
54
|
|
55 /**
|
|
56 * The CCombo class represents a selectable user interface object
|
|
57 * that combines a text field and a list and issues notification
|
|
58 * when an item is selected from the list.
|
|
59 * <p>
|
|
60 * CCombo was written to work around certain limitations in the native
|
|
61 * combo box. Specifically, on win32, the height of a CCombo can be set;
|
|
62 * attempts to set the height of a Combo are ignored. CCombo can be used
|
|
63 * anywhere that having the increased flexibility is more important than
|
|
64 * getting native L&F, but the decision should not be taken lightly.
|
|
65 * There is no is no strict requirement that CCombo look or behave
|
|
66 * the same as the native combo box.
|
|
67 * </p>
|
|
68 * <p>
|
|
69 * Note that although this class is a subclass of <code>Composite</code>,
|
|
70 * it does not make sense to add children to it, or set a layout on it.
|
|
71 * </p>
|
|
72 * <dl>
|
|
73 * <dt><b>Styles:</b>
|
|
74 * <dd>BORDER, READ_ONLY, FLAT</dd>
|
|
75 * <dt><b>Events:</b>
|
|
76 * <dd>DefaultSelection, Modify, Selection, Verify</dd>
|
|
77 * </dl>
|
|
78 */
|
|
79 public final class CCombo : Composite {
|
|
80
|
|
81 alias Composite.computeSize computeSize;
|
|
82
|
|
83 Text text;
|
|
84 List list;
|
|
85 int visibleItemCount = 5;
|
|
86 Shell popup;
|
|
87 Button arrow;
|
|
88 bool hasFocus;
|
|
89 Listener listener, filter;
|
|
90 Color foreground, background;
|
|
91 Font font;
|
|
92
|
|
93 /**
|
|
94 * Constructs a new instance of this class given its parent
|
|
95 * and a style value describing its behavior and appearance.
|
|
96 * <p>
|
|
97 * The style value is either one of the style constants defined in
|
|
98 * class <code>DWT</code> which is applicable to instances of this
|
|
99 * class, or must be built by <em>bitwise OR</em>'ing together
|
|
100 * (that is, using the <code>int</code> "|" operator) two or more
|
|
101 * of those <code>DWT</code> style constants. The class description
|
|
102 * lists the style constants that are applicable to the class.
|
|
103 * Style bits are also inherited from superclasses.
|
|
104 * </p>
|
|
105 *
|
|
106 * @param parent a widget which will be the parent of the new instance (cannot be null)
|
|
107 * @param style the style of widget to construct
|
|
108 *
|
|
109 * @exception IllegalArgumentException <ul>
|
|
110 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
|
|
111 * </ul>
|
|
112 * @exception DWTException <ul>
|
|
113 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
|
|
114 * </ul>
|
|
115 *
|
|
116 * @see DWT#BORDER
|
|
117 * @see DWT#READ_ONLY
|
|
118 * @see DWT#FLAT
|
|
119 * @see Widget#getStyle()
|
|
120 */
|
|
121 public this (Composite parent, int style) {
|
|
122 super (parent, style = checkStyle (style));
|
|
123
|
|
124 int textStyle = DWT.SINGLE;
|
|
125 if ((style & DWT.READ_ONLY) !is 0) textStyle |= DWT.READ_ONLY;
|
|
126 if ((style & DWT.FLAT) !is 0) textStyle |= DWT.FLAT;
|
|
127 text = new Text (this, textStyle);
|
|
128 int arrowStyle = DWT.ARROW | DWT.DOWN;
|
|
129 if ((style & DWT.FLAT) !is 0) arrowStyle |= DWT.FLAT;
|
|
130 arrow = new Button (this, arrowStyle);
|
|
131
|
|
132 listener = new class() Listener {
|
|
133 public void handleEvent (Event event) {
|
|
134 if (popup is event.widget) {
|
|
135 popupEvent (event);
|
|
136 return;
|
|
137 }
|
|
138 if (text is event.widget) {
|
|
139 textEvent (event);
|
|
140 return;
|
|
141 }
|
|
142 if (list is event.widget) {
|
|
143 listEvent (event);
|
|
144 return;
|
|
145 }
|
|
146 if (arrow is event.widget) {
|
|
147 arrowEvent (event);
|
|
148 return;
|
|
149 }
|
|
150 if (this.outer is event.widget) {
|
|
151 comboEvent (event);
|
|
152 return;
|
|
153 }
|
|
154 if (getShell () is event.widget) {
|
|
155 handleFocus (DWT.FocusOut);
|
|
156 }
|
|
157 }
|
|
158 };
|
|
159 filter = new class() Listener {
|
|
160 public void handleEvent(Event event) {
|
|
161 Shell shell = (cast(Control)event.widget).getShell ();
|
|
162 if (shell is this.outer.getShell ()) {
|
|
163 handleFocus (DWT.FocusOut);
|
|
164 }
|
|
165 }
|
|
166 };
|
|
167
|
|
168 int [] comboEvents = [DWT.Dispose, DWT.Move, DWT.Resize];
|
|
169 for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
|
|
170
|
|
171 int [] textEvents = [DWT.KeyDown, DWT.KeyUp, DWT.MenuDetect, DWT.Modify, DWT.MouseDown, DWT.MouseUp, DWT.Traverse, DWT.FocusIn, DWT.Verify];
|
|
172 for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
|
|
173
|
|
174 int [] arrowEvents = [DWT.Selection, DWT.FocusIn];
|
|
175 for (int i=0; i<arrowEvents.length; i++) arrow.addListener (arrowEvents [i], listener);
|
|
176
|
|
177 createPopup(null, -1);
|
|
178 initAccessible();
|
|
179 }
|
|
180 static int checkStyle (int style) {
|
|
181 int mask = DWT.BORDER | DWT.READ_ONLY | DWT.FLAT | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
|
|
182 return style & mask;
|
|
183 }
|
|
184 /**
|
|
185 * Adds the argument to the end of the receiver's list.
|
|
186 *
|
|
187 * @param string the new item
|
|
188 *
|
|
189 * @exception IllegalArgumentException <ul>
|
|
190 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
|
|
191 * </ul>
|
|
192 * @exception DWTException <ul>
|
|
193 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
194 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
195 * </ul>
|
|
196 *
|
|
197 * @see #add(String,int)
|
|
198 */
|
|
199 public void add (char[] string) {
|
|
200 checkWidget();
|
|
201 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
202 list.add (string);
|
|
203 }
|
|
204 /**
|
|
205 * Adds the argument to the receiver's list at the given
|
|
206 * zero-relative index.
|
|
207 * <p>
|
|
208 * Note: To add an item at the end of the list, use the
|
|
209 * result of calling <code>getItemCount()</code> as the
|
|
210 * index or use <code>add(String)</code>.
|
|
211 * </p>
|
|
212 *
|
|
213 * @param string the new item
|
|
214 * @param index the index for the item
|
|
215 *
|
|
216 * @exception IllegalArgumentException <ul>
|
|
217 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
|
|
218 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
|
|
219 * </ul>
|
|
220 * @exception DWTException <ul>
|
|
221 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
222 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
223 * </ul>
|
|
224 *
|
|
225 * @see #add(String)
|
|
226 */
|
|
227 public void add (char[] string, int index) {
|
|
228 checkWidget();
|
|
229 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
230 list.add (string, index);
|
|
231 }
|
|
232 /**
|
|
233 * Adds the listener to the collection of listeners who will
|
|
234 * be notified when the receiver's text is modified, by sending
|
|
235 * it one of the messages defined in the <code>ModifyListener</code>
|
|
236 * interface.
|
|
237 *
|
|
238 * @param listener the listener which should be notified
|
|
239 *
|
|
240 * @exception IllegalArgumentException <ul>
|
|
241 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
242 * </ul>
|
|
243 * @exception DWTException <ul>
|
|
244 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
245 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
246 * </ul>
|
|
247 *
|
|
248 * @see ModifyListener
|
|
249 * @see #removeModifyListener
|
|
250 */
|
|
251 public void addModifyListener (ModifyListener listener) {
|
|
252 checkWidget();
|
|
253 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
254 TypedListener typedListener = new TypedListener (listener);
|
|
255 addListener (DWT.Modify, typedListener);
|
|
256 }
|
|
257 /**
|
|
258 * Adds the listener to the collection of listeners who will
|
|
259 * be notified when the user changes the receiver's selection, by sending
|
|
260 * it one of the messages defined in the <code>SelectionListener</code>
|
|
261 * interface.
|
|
262 * <p>
|
|
263 * <code>widgetSelected</code> is called when the combo's list selection changes.
|
|
264 * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
|
|
265 * </p>
|
|
266 *
|
|
267 * @param listener the listener which should be notified when the user changes the receiver's selection
|
|
268 *
|
|
269 * @exception IllegalArgumentException <ul>
|
|
270 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
271 * </ul>
|
|
272 * @exception DWTException <ul>
|
|
273 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
274 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
275 * </ul>
|
|
276 *
|
|
277 * @see SelectionListener
|
|
278 * @see #removeSelectionListener
|
|
279 * @see SelectionEvent
|
|
280 */
|
|
281 public void addSelectionListener(SelectionListener listener) {
|
|
282 checkWidget();
|
|
283 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
284 TypedListener typedListener = new TypedListener (listener);
|
|
285 addListener (DWT.Selection,typedListener);
|
|
286 addListener (DWT.DefaultSelection,typedListener);
|
|
287 }
|
|
288 /**
|
|
289 * Adds the listener to the collection of listeners who will
|
|
290 * be notified when the receiver's text is verified, by sending
|
|
291 * it one of the messages defined in the <code>VerifyListener</code>
|
|
292 * interface.
|
|
293 *
|
|
294 * @param listener the listener which should be notified
|
|
295 *
|
|
296 * @exception IllegalArgumentException <ul>
|
|
297 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
298 * </ul>
|
|
299 * @exception DWTException <ul>
|
|
300 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
301 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
302 * </ul>
|
|
303 *
|
|
304 * @see VerifyListener
|
|
305 * @see #removeVerifyListener
|
|
306 *
|
|
307 * @since 3.3
|
|
308 */
|
|
309 public void addVerifyListener (VerifyListener listener) {
|
|
310 checkWidget();
|
|
311 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
312 TypedListener typedListener = new TypedListener (listener);
|
|
313 addListener (DWT.Verify,typedListener);
|
|
314 }
|
|
315 void arrowEvent (Event event) {
|
|
316 switch (event.type) {
|
|
317 case DWT.FocusIn: {
|
|
318 handleFocus (DWT.FocusIn);
|
|
319 break;
|
|
320 }
|
|
321 case DWT.Selection: {
|
|
322 dropDown (!isDropped ());
|
|
323 break;
|
|
324 }
|
|
325 default:
|
|
326 }
|
|
327 }
|
|
328 /**
|
|
329 * Sets the selection in the receiver's text field to an empty
|
|
330 * selection starting just before the first character. If the
|
|
331 * text field is editable, this has the effect of placing the
|
|
332 * i-beam at the start of the text.
|
|
333 * <p>
|
|
334 * Note: To clear the selected items in the receiver's list,
|
|
335 * use <code>deselectAll()</code>.
|
|
336 * </p>
|
|
337 *
|
|
338 * @exception DWTException <ul>
|
|
339 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
340 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
341 * </ul>
|
|
342 *
|
|
343 * @see #deselectAll
|
|
344 */
|
|
345 public void clearSelection () {
|
|
346 checkWidget ();
|
|
347 text.clearSelection ();
|
|
348 list.deselectAll ();
|
|
349 }
|
|
350 void comboEvent (Event event) {
|
|
351 switch (event.type) {
|
|
352 case DWT.Dispose:
|
|
353 if (popup !is null && !popup.isDisposed ()) {
|
|
354 list.removeListener (DWT.Dispose, listener);
|
|
355 popup.dispose ();
|
|
356 }
|
|
357 Shell shell = getShell ();
|
|
358 shell.removeListener (DWT.Deactivate, listener);
|
|
359 Display display = getDisplay ();
|
|
360 display.removeFilter (DWT.FocusIn, filter);
|
|
361 popup = null;
|
|
362 text = null;
|
|
363 list = null;
|
|
364 arrow = null;
|
|
365 break;
|
|
366 case DWT.Move:
|
|
367 dropDown (false);
|
|
368 break;
|
|
369 case DWT.Resize:
|
|
370 internalLayout (false);
|
|
371 break;
|
|
372 default:
|
|
373 }
|
|
374 }
|
|
375
|
|
376 public override Point computeSize (int wHint, int hHint, bool changed) {
|
|
377 checkWidget ();
|
|
378 int width = 0, height = 0;
|
|
379 char[][] items = list.getItems ();
|
|
380 GC gc = new GC (text);
|
|
381 int spacer = gc.stringExtent (" ").x; //$NON-NLS-1$
|
|
382 int textWidth = gc.stringExtent (text.getText ()).x;
|
|
383 for (int i = 0; i < items.length; i++) {
|
|
384 textWidth = Math.max (gc.stringExtent (items[i]).x, textWidth);
|
|
385 }
|
|
386 gc.dispose ();
|
|
387 Point textSize = text.computeSize (DWT.DEFAULT, DWT.DEFAULT, changed);
|
|
388 Point arrowSize = arrow.computeSize (DWT.DEFAULT, DWT.DEFAULT, changed);
|
|
389 Point listSize = list.computeSize (DWT.DEFAULT, DWT.DEFAULT, changed);
|
|
390 int borderWidth = getBorderWidth ();
|
|
391
|
|
392 height = Math.max (textSize.y, arrowSize.y);
|
|
393 width = Math.max (textWidth + 2*spacer + arrowSize.x + 2*borderWidth, listSize.x);
|
|
394 if (wHint !is DWT.DEFAULT) width = wHint;
|
|
395 if (hHint !is DWT.DEFAULT) height = hHint;
|
|
396 return new Point (width + 2*borderWidth, height + 2*borderWidth);
|
|
397 }
|
|
398 /**
|
|
399 * Copies the selected text.
|
|
400 * <p>
|
|
401 * The current selection is copied to the clipboard.
|
|
402 * </p>
|
|
403 *
|
|
404 * @exception DWTException <ul>
|
|
405 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
406 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
407 * </ul>
|
|
408 *
|
|
409 * @since 3.3
|
|
410 */
|
|
411 public void copy () {
|
|
412 checkWidget ();
|
|
413 text.copy ();
|
|
414 }
|
|
415 void createPopup(char[][] items, int selectionIndex) {
|
|
416 // create shell and list
|
|
417 popup = new Shell (getShell (), DWT.NO_TRIM | DWT.ON_TOP);
|
|
418 int style = getStyle ();
|
|
419 int listStyle = DWT.SINGLE | DWT.V_SCROLL;
|
|
420 if ((style & DWT.FLAT) !is 0) listStyle |= DWT.FLAT;
|
|
421 if ((style & DWT.RIGHT_TO_LEFT) !is 0) listStyle |= DWT.RIGHT_TO_LEFT;
|
|
422 if ((style & DWT.LEFT_TO_RIGHT) !is 0) listStyle |= DWT.LEFT_TO_RIGHT;
|
|
423 list = new List (popup, listStyle);
|
|
424 if (font !is null) list.setFont (font);
|
|
425 if (foreground !is null) list.setForeground (foreground);
|
|
426 if (background !is null) list.setBackground (background);
|
|
427
|
|
428 int [] popupEvents = [DWT.Close, DWT.Paint, DWT.Deactivate];
|
|
429 for (int i=0; i<popupEvents.length; i++) popup.addListener (popupEvents [i], listener);
|
|
430 int [] listEvents = [DWT.MouseUp, DWT.Selection, DWT.Traverse, DWT.KeyDown, DWT.KeyUp, DWT.FocusIn, DWT.Dispose];
|
|
431 for (int i=0; i<listEvents.length; i++) list.addListener (listEvents [i], listener);
|
|
432
|
|
433 if (items !is null) list.setItems (items);
|
|
434 if (selectionIndex !is -1) list.setSelection (selectionIndex);
|
|
435 }
|
|
436 /**
|
|
437 * Cuts the selected text.
|
|
438 * <p>
|
|
439 * The current selection is first copied to the
|
|
440 * clipboard and then deleted from the widget.
|
|
441 * </p>
|
|
442 *
|
|
443 * @exception DWTException <ul>
|
|
444 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
445 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
446 * </ul>
|
|
447 *
|
|
448 * @since 3.3
|
|
449 */
|
|
450 public void cut () {
|
|
451 checkWidget ();
|
|
452 text.cut ();
|
|
453 }
|
|
454 /**
|
|
455 * Deselects the item at the given zero-relative index in the receiver's
|
|
456 * list. If the item at the index was already deselected, it remains
|
|
457 * deselected. Indices that are out of range are ignored.
|
|
458 *
|
|
459 * @param index the index of the item to deselect
|
|
460 *
|
|
461 * @exception DWTException <ul>
|
|
462 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
463 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
464 * </ul>
|
|
465 */
|
|
466 public void deselect (int index) {
|
|
467 checkWidget ();
|
|
468 list.deselect (index);
|
|
469 }
|
|
470 /**
|
|
471 * Deselects all selected items in the receiver's list.
|
|
472 * <p>
|
|
473 * Note: To clear the selection in the receiver's text field,
|
|
474 * use <code>clearSelection()</code>.
|
|
475 * </p>
|
|
476 *
|
|
477 * @exception DWTException <ul>
|
|
478 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
479 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
480 * </ul>
|
|
481 *
|
|
482 * @see #clearSelection
|
|
483 */
|
|
484 public void deselectAll () {
|
|
485 checkWidget ();
|
|
486 list.deselectAll ();
|
|
487 }
|
|
488 void dropDown (bool drop) {
|
|
489 if (drop is isDropped ()) return;
|
|
490 if (!drop) {
|
|
491 popup.setVisible (false);
|
|
492 if (!isDisposed ()&& arrow.isFocusControl()) {
|
|
493 text.setFocus();
|
|
494 }
|
|
495 return;
|
|
496 }
|
|
497
|
|
498 if (getShell() !is popup.getParent ()) {
|
|
499 char[][] items = list.getItems ();
|
|
500 int selectionIndex = list.getSelectionIndex ();
|
|
501 list.removeListener (DWT.Dispose, listener);
|
|
502 popup.dispose();
|
|
503 popup = null;
|
|
504 list = null;
|
|
505 createPopup (items, selectionIndex);
|
|
506 }
|
|
507
|
|
508 Point size = getSize ();
|
|
509 int itemCount = list.getItemCount ();
|
|
510 itemCount = (itemCount is 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
|
|
511 int itemHeight = list.getItemHeight () * itemCount;
|
|
512 Point listSize = list.computeSize (DWT.DEFAULT, itemHeight, false);
|
|
513 list.setBounds (1, 1, Math.max (size.x - 2, listSize.x), listSize.y);
|
|
514
|
|
515 int index = list.getSelectionIndex ();
|
|
516 if (index !is -1) list.setTopIndex (index);
|
|
517 Display display = getDisplay ();
|
|
518 Rectangle listRect = list.getBounds ();
|
|
519 Rectangle parentRect = display.map (getParent (), null, getBounds ());
|
|
520 Point comboSize = getSize ();
|
|
521 Rectangle displayRect = getMonitor ().getClientArea ();
|
|
522 int width = Math.max (comboSize.x, listRect.width + 2);
|
|
523 int height = listRect.height + 2;
|
|
524 int x = parentRect.x;
|
|
525 int y = parentRect.y + comboSize.y;
|
|
526 if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height;
|
|
527 if (x + width > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - listRect.width;
|
|
528 popup.setBounds (x, y, width, height);
|
|
529 popup.setVisible (true);
|
|
530 list.setFocus ();
|
|
531 }
|
|
532 /*
|
|
533 * Return the lowercase of the first non-'&' character following
|
|
534 * an '&' character in the given string. If there are no '&'
|
|
535 * characters in the given string, return '\0'.
|
|
536 */
|
|
537 dchar _findMnemonic (char[] string) {
|
|
538 if (string is null) return '\0';
|
|
539 int index = 0;
|
|
540 int length = string.length;
|
|
541 do {
|
|
542 while (index < length && string[index] !is '&') index++;
|
|
543 if (++index >= length) return '\0';
|
|
544 if (string[index] !is '&') {
|
|
545 dchar[1] d; uint ate;
|
|
546 auto d2 = tango.text.convert.Utf.toString32( string[ index .. Math.min( index +4, string.length )], d, &ate );
|
|
547 auto d3 = tango.text.Unicode.toLower( d2, d2 );
|
|
548 return d3[0];
|
|
549 }
|
|
550 index++;
|
|
551 } while (index < length);
|
|
552 return '\0';
|
|
553 }
|
|
554 /*
|
|
555 * Return the Label immediately preceding the receiver in the z-order,
|
|
556 * or null if none.
|
|
557 */
|
|
558 Label getAssociatedLabel () {
|
|
559 Control[] siblings = getParent ().getChildren ();
|
|
560 for (int i = 0; i < siblings.length; i++) {
|
|
561 if (siblings [i] is this) {
|
|
562 if (i > 0 && ( null !is cast(Label)siblings [i-1] )) {
|
|
563 return cast(Label) siblings [i-1];
|
|
564 }
|
|
565 }
|
|
566 }
|
|
567 return null;
|
|
568 }
|
|
569 public override Control [] getChildren () {
|
|
570 checkWidget();
|
|
571 return new Control [0];
|
|
572 }
|
|
573 /**
|
|
574 * Gets the editable state.
|
|
575 *
|
|
576 * @return whether or not the receiver is editable
|
|
577 *
|
|
578 * @exception DWTException <ul>
|
|
579 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
580 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
581 * </ul>
|
|
582 *
|
|
583 * @since 3.0
|
|
584 */
|
|
585 public bool getEditable () {
|
|
586 checkWidget ();
|
|
587 return text.getEditable();
|
|
588 }
|
|
589 /**
|
|
590 * Returns the item at the given, zero-relative index in the
|
|
591 * receiver's list. Throws an exception if the index is out
|
|
592 * of range.
|
|
593 *
|
|
594 * @param index the index of the item to return
|
|
595 * @return the item at the given index
|
|
596 *
|
|
597 * @exception IllegalArgumentException <ul>
|
|
598 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
|
|
599 * </ul>
|
|
600 * @exception DWTException <ul>
|
|
601 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
602 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
603 * </ul>
|
|
604 */
|
|
605 public char[] getItem (int index) {
|
|
606 checkWidget();
|
|
607 return list.getItem (index);
|
|
608 }
|
|
609 /**
|
|
610 * Returns the number of items contained in the receiver's list.
|
|
611 *
|
|
612 * @return the number of items
|
|
613 *
|
|
614 * @exception DWTException <ul>
|
|
615 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
616 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
617 * </ul>
|
|
618 */
|
|
619 public int getItemCount () {
|
|
620 checkWidget ();
|
|
621 return list.getItemCount ();
|
|
622 }
|
|
623 /**
|
|
624 * Returns the height of the area which would be used to
|
|
625 * display <em>one</em> of the items in the receiver's list.
|
|
626 *
|
|
627 * @return the height of one item
|
|
628 *
|
|
629 * @exception DWTException <ul>
|
|
630 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
631 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
632 * </ul>
|
|
633 */
|
|
634 public int getItemHeight () {
|
|
635 checkWidget ();
|
|
636 return list.getItemHeight ();
|
|
637 }
|
|
638 /**
|
|
639 * Returns an array of <code>String</code>s which are the items
|
|
640 * in the receiver's list.
|
|
641 * <p>
|
|
642 * Note: This is not the actual structure used by the receiver
|
|
643 * to maintain its list of items, so modifying the array will
|
|
644 * not affect the receiver.
|
|
645 * </p>
|
|
646 *
|
|
647 * @return the items in the receiver's list
|
|
648 *
|
|
649 * @exception DWTException <ul>
|
|
650 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
651 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
652 * </ul>
|
|
653 */
|
|
654 public char[] [] getItems () {
|
|
655 checkWidget ();
|
|
656 return list.getItems ();
|
|
657 }
|
|
658 public override Menu getMenu() {
|
|
659 return text.getMenu();
|
|
660 }
|
|
661 /**
|
|
662 * Returns a <code>Point</code> whose x coordinate is the start
|
|
663 * of the selection in the receiver's text field, and whose y
|
|
664 * coordinate is the end of the selection. The returned values
|
|
665 * are zero-relative. An "empty" selection as indicated by
|
|
666 * the the x and y coordinates having the same value.
|
|
667 *
|
|
668 * @return a point representing the selection start and end
|
|
669 *
|
|
670 * @exception DWTException <ul>
|
|
671 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
672 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
673 * </ul>
|
|
674 */
|
|
675 public Point getSelection () {
|
|
676 checkWidget ();
|
|
677 return text.getSelection ();
|
|
678 }
|
|
679 /**
|
|
680 * Returns the zero-relative index of the item which is currently
|
|
681 * selected in the receiver's list, or -1 if no item is selected.
|
|
682 *
|
|
683 * @return the index of the selected item
|
|
684 *
|
|
685 * @exception DWTException <ul>
|
|
686 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
687 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
688 * </ul>
|
|
689 */
|
|
690 public int getSelectionIndex () {
|
|
691 checkWidget ();
|
|
692 return list.getSelectionIndex ();
|
|
693 }
|
|
694 public override int getStyle () {
|
|
695 int style = super.getStyle ();
|
|
696 style &= ~DWT.READ_ONLY;
|
|
697 if (!text.getEditable()) style |= DWT.READ_ONLY;
|
|
698 return style;
|
|
699 }
|
|
700 /**
|
|
701 * Returns a string containing a copy of the contents of the
|
|
702 * receiver's text field.
|
|
703 *
|
|
704 * @return the receiver's text
|
|
705 *
|
|
706 * @exception DWTException <ul>
|
|
707 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
708 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
709 * </ul>
|
|
710 */
|
|
711 public char[] getText () {
|
|
712 checkWidget ();
|
|
713 return text.getText ();
|
|
714 }
|
|
715 /**
|
|
716 * Returns the height of the receivers's text field.
|
|
717 *
|
|
718 * @return the text height
|
|
719 *
|
|
720 * @exception DWTException <ul>
|
|
721 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
722 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
723 * </ul>
|
|
724 */
|
|
725 public int getTextHeight () {
|
|
726 checkWidget ();
|
|
727 return text.getLineHeight ();
|
|
728 }
|
|
729 /**
|
|
730 * Returns the maximum number of characters that the receiver's
|
|
731 * text field is capable of holding. If this has not been changed
|
|
732 * by <code>setTextLimit()</code>, it will be the constant
|
|
733 * <code>Combo.LIMIT</code>.
|
|
734 *
|
|
735 * @return the text limit
|
|
736 *
|
|
737 * @exception DWTException <ul>
|
|
738 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
739 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
740 * </ul>
|
|
741 */
|
|
742 public int getTextLimit () {
|
|
743 checkWidget ();
|
|
744 return text.getTextLimit ();
|
|
745 }
|
|
746 /**
|
|
747 * Gets the number of items that are visible in the drop
|
|
748 * down portion of the receiver's list.
|
|
749 *
|
|
750 * @return the number of items that are visible
|
|
751 *
|
|
752 * @exception DWTException <ul>
|
|
753 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
754 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
755 * </ul>
|
|
756 *
|
|
757 * @since 3.0
|
|
758 */
|
|
759 public int getVisibleItemCount () {
|
|
760 checkWidget ();
|
|
761 return visibleItemCount;
|
|
762 }
|
|
763 void handleFocus (int type) {
|
|
764 if (isDisposed ()) return;
|
|
765 switch (type) {
|
|
766 case DWT.FocusIn: {
|
|
767 if (hasFocus) return;
|
|
768 if (getEditable ()) text.selectAll ();
|
|
769 hasFocus = true;
|
|
770 Shell shell = getShell ();
|
|
771 shell.removeListener (DWT.Deactivate, listener);
|
|
772 shell.addListener (DWT.Deactivate, listener);
|
|
773 Display display = getDisplay ();
|
|
774 display.removeFilter (DWT.FocusIn, filter);
|
|
775 display.addFilter (DWT.FocusIn, filter);
|
|
776 Event e = new Event ();
|
|
777 notifyListeners (DWT.FocusIn, e);
|
|
778 break;
|
|
779 }
|
|
780 case DWT.FocusOut: {
|
|
781 if (!hasFocus) return;
|
|
782 Control focusControl = getDisplay ().getFocusControl ();
|
|
783 if (focusControl is arrow || focusControl is list || focusControl is text) return;
|
|
784 hasFocus = false;
|
|
785 Shell shell = getShell ();
|
|
786 shell.removeListener(DWT.Deactivate, listener);
|
|
787 Display display = getDisplay ();
|
|
788 display.removeFilter (DWT.FocusIn, filter);
|
|
789 Event e = new Event ();
|
|
790 notifyListeners (DWT.FocusOut, e);
|
|
791 break;
|
|
792 }
|
|
793 default:
|
|
794 }
|
|
795 }
|
|
796 /**
|
|
797 * Searches the receiver's list starting at the first item
|
|
798 * (index 0) until an item is found that is equal to the
|
|
799 * argument, and returns the index of that item. If no item
|
|
800 * is found, returns -1.
|
|
801 *
|
|
802 * @param string the search item
|
|
803 * @return the index of the item
|
|
804 *
|
|
805 * @exception IllegalArgumentException <ul>
|
|
806 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
|
|
807 * </ul>
|
|
808 * @exception DWTException <ul>
|
|
809 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
810 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
811 * </ul>
|
|
812 */
|
|
813 public int indexOf (char[] string) {
|
|
814 checkWidget ();
|
|
815 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
816 return list.indexOf (string);
|
|
817 }
|
|
818 /**
|
|
819 * Searches the receiver's list starting at the given,
|
|
820 * zero-relative index until an item is found that is equal
|
|
821 * to the argument, and returns the index of that item. If
|
|
822 * no item is found or the starting index is out of range,
|
|
823 * returns -1.
|
|
824 *
|
|
825 * @param string the search item
|
|
826 * @param start the zero-relative index at which to begin the search
|
|
827 * @return the index of the item
|
|
828 *
|
|
829 * @exception IllegalArgumentException <ul>
|
|
830 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
|
|
831 * </ul>
|
|
832 * @exception DWTException <ul>
|
|
833 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
834 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
835 * </ul>
|
|
836 */
|
|
837 public int indexOf (char[] string, int start) {
|
|
838 checkWidget ();
|
|
839 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
840 return list.indexOf (string, start);
|
|
841 }
|
|
842
|
|
843 void initAccessible() {
|
|
844 AccessibleAdapter accessibleAdapter = new class() AccessibleAdapter {
|
|
845 public void getName (AccessibleEvent e) {
|
|
846 char[] name = null;
|
|
847 Label label = getAssociatedLabel ();
|
|
848 if (label !is null) {
|
|
849 name = stripMnemonic (label.getText());
|
|
850 }
|
|
851 e.result = name;
|
|
852 }
|
|
853 public void getKeyboardShortcut(AccessibleEvent e) {
|
|
854 char[] shortcut = null;
|
|
855 Label label = getAssociatedLabel ();
|
|
856 if (label !is null) {
|
|
857 char[] text = label.getText ();
|
|
858 if (text !is null) {
|
|
859 dchar mnemonic = _findMnemonic (text);
|
|
860 if (mnemonic !is '\0') {
|
|
861 shortcut = tango.text.convert.Format.Format( "Alt+{}", mnemonic ); //$NON-NLS-1$
|
|
862 }
|
|
863 }
|
|
864 }
|
|
865 e.result = shortcut;
|
|
866 }
|
|
867 public void getHelp (AccessibleEvent e) {
|
|
868 e.result = getToolTipText ();
|
|
869 }
|
|
870 };
|
|
871 getAccessible ().addAccessibleListener (accessibleAdapter);
|
|
872 text.getAccessible ().addAccessibleListener (accessibleAdapter);
|
|
873 list.getAccessible ().addAccessibleListener (accessibleAdapter);
|
|
874
|
|
875 arrow.getAccessible ().addAccessibleListener (new class() AccessibleAdapter {
|
|
876 public void getName (AccessibleEvent e) {
|
|
877 e.result = isDropped () ? DWT.getMessage ("SWT_Close") : DWT.getMessage ("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
878 }
|
|
879 public void getKeyboardShortcut (AccessibleEvent e) {
|
|
880 e.result = "Alt+Down Arrow"; //$NON-NLS-1$
|
|
881 }
|
|
882 public void getHelp (AccessibleEvent e) {
|
|
883 e.result = getToolTipText ();
|
|
884 }
|
|
885 });
|
|
886
|
|
887 getAccessible().addAccessibleTextListener (new class() AccessibleTextAdapter {
|
|
888 public void getCaretOffset (AccessibleTextEvent e) {
|
|
889 e.offset = text.getCaretPosition ();
|
|
890 }
|
|
891 public void getSelectionRange(AccessibleTextEvent e) {
|
|
892 Point sel = text.getSelection();
|
|
893 e.offset = sel.x;
|
|
894 e.length = sel.y - sel.x;
|
|
895 }
|
|
896 });
|
|
897
|
|
898 getAccessible().addAccessibleControlListener (new class() AccessibleControlAdapter {
|
|
899 public void getChildAtPoint (AccessibleControlEvent e) {
|
|
900 Point testPoint = toControl (e.x, e.y);
|
|
901 if (getBounds ().contains (testPoint)) {
|
|
902 e.childID = ACC.CHILDID_SELF;
|
|
903 }
|
|
904 }
|
|
905
|
|
906 public void getLocation (AccessibleControlEvent e) {
|
|
907 Rectangle location = getBounds ();
|
|
908 Point pt = toDisplay (location.x, location.y);
|
|
909 e.x = pt.x;
|
|
910 e.y = pt.y;
|
|
911 e.width = location.width;
|
|
912 e.height = location.height;
|
|
913 }
|
|
914
|
|
915 public void getChildCount (AccessibleControlEvent e) {
|
|
916 e.detail = 0;
|
|
917 }
|
|
918
|
|
919 public void getRole (AccessibleControlEvent e) {
|
|
920 e.detail = ACC.ROLE_COMBOBOX;
|
|
921 }
|
|
922
|
|
923 public void getState (AccessibleControlEvent e) {
|
|
924 e.detail = ACC.STATE_NORMAL;
|
|
925 }
|
|
926
|
|
927 public void getValue (AccessibleControlEvent e) {
|
|
928 e.result = getText ();
|
|
929 }
|
|
930 });
|
|
931
|
|
932 text.getAccessible ().addAccessibleControlListener (new class() AccessibleControlAdapter {
|
|
933 public void getRole (AccessibleControlEvent e) {
|
|
934 e.detail = text.getEditable () ? ACC.ROLE_TEXT : ACC.ROLE_LABEL;
|
|
935 }
|
|
936 });
|
|
937
|
|
938 arrow.getAccessible ().addAccessibleControlListener (new class() AccessibleControlAdapter {
|
|
939 public void getDefaultAction (AccessibleControlEvent e) {
|
|
940 e.result = isDropped () ? DWT.getMessage ("SWT_Close") : DWT.getMessage ("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
941 }
|
|
942 });
|
|
943 }
|
|
944 bool isDropped () {
|
|
945 return popup.getVisible ();
|
|
946 }
|
|
947 public override bool isFocusControl () {
|
|
948 checkWidget();
|
|
949 if (text.isFocusControl () || arrow.isFocusControl () || list.isFocusControl () || popup.isFocusControl ()) {
|
|
950 return true;
|
|
951 }
|
|
952 return super.isFocusControl ();
|
|
953 }
|
|
954 void internalLayout (bool changed) {
|
|
955 if (isDropped ()) dropDown (false);
|
|
956 Rectangle rect = getClientArea ();
|
|
957 int width = rect.width;
|
|
958 int height = rect.height;
|
|
959 Point arrowSize = arrow.computeSize (DWT.DEFAULT, height, changed);
|
|
960 text.setBounds (0, 0, width - arrowSize.x, height);
|
|
961 arrow.setBounds (width - arrowSize.x, 0, arrowSize.x, arrowSize.y);
|
|
962 }
|
|
963 void listEvent (Event event) {
|
|
964 switch (event.type) {
|
|
965 case DWT.Dispose:
|
|
966 if (getShell () !is popup.getParent ()) {
|
|
967 char[][] items = list.getItems ();
|
|
968 int selectionIndex = list.getSelectionIndex ();
|
|
969 popup = null;
|
|
970 list = null;
|
|
971 createPopup (items, selectionIndex);
|
|
972 }
|
|
973 break;
|
|
974 case DWT.FocusIn: {
|
|
975 handleFocus (DWT.FocusIn);
|
|
976 break;
|
|
977 }
|
|
978 case DWT.MouseUp: {
|
|
979 if (event.button !is 1) return;
|
|
980 dropDown (false);
|
|
981 break;
|
|
982 }
|
|
983 case DWT.Selection: {
|
|
984 int index = list.getSelectionIndex ();
|
|
985 if (index is -1) return;
|
|
986 text.setText (list.getItem (index));
|
|
987 text.selectAll ();
|
|
988 list.setSelection (index);
|
|
989 Event e = new Event ();
|
|
990 e.time = event.time;
|
|
991 e.stateMask = event.stateMask;
|
|
992 e.doit = event.doit;
|
|
993 notifyListeners (DWT.Selection, e);
|
|
994 event.doit = e.doit;
|
|
995 break;
|
|
996 }
|
|
997 case DWT.Traverse: {
|
|
998 switch (event.detail) {
|
|
999 case DWT.TRAVERSE_RETURN:
|
|
1000 case DWT.TRAVERSE_ESCAPE:
|
|
1001 case DWT.TRAVERSE_ARROW_PREVIOUS:
|
|
1002 case DWT.TRAVERSE_ARROW_NEXT:
|
|
1003 event.doit = false;
|
|
1004 break;
|
|
1005 default:
|
|
1006 }
|
|
1007 Event e = new Event ();
|
|
1008 e.time = event.time;
|
|
1009 e.detail = event.detail;
|
|
1010 e.doit = event.doit;
|
|
1011 e.character = event.character;
|
|
1012 e.keyCode = event.keyCode;
|
|
1013 notifyListeners (DWT.Traverse, e);
|
|
1014 event.doit = e.doit;
|
|
1015 event.detail = e.detail;
|
|
1016 break;
|
|
1017 }
|
|
1018 case DWT.KeyUp: {
|
|
1019 Event e = new Event ();
|
|
1020 e.time = event.time;
|
|
1021 e.character = event.character;
|
|
1022 e.keyCode = event.keyCode;
|
|
1023 e.stateMask = event.stateMask;
|
|
1024 notifyListeners (DWT.KeyUp, e);
|
|
1025 break;
|
|
1026 }
|
|
1027 case DWT.KeyDown: {
|
|
1028 if (event.character is DWT.ESC) {
|
|
1029 // Escape key cancels popup list
|
|
1030 dropDown (false);
|
|
1031 }
|
|
1032 if ((event.stateMask & DWT.ALT) !is 0 && (event.keyCode is DWT.ARROW_UP || event.keyCode is DWT.ARROW_DOWN)) {
|
|
1033 dropDown (false);
|
|
1034 }
|
|
1035 if (event.character is DWT.CR) {
|
|
1036 // Enter causes default selection
|
|
1037 dropDown (false);
|
|
1038 Event e = new Event ();
|
|
1039 e.time = event.time;
|
|
1040 e.stateMask = event.stateMask;
|
|
1041 notifyListeners (DWT.DefaultSelection, e);
|
|
1042 }
|
|
1043 // At this point the widget may have been disposed.
|
|
1044 // If so, do not continue.
|
|
1045 if (isDisposed ()) break;
|
|
1046 Event e = new Event();
|
|
1047 e.time = event.time;
|
|
1048 e.character = event.character;
|
|
1049 e.keyCode = event.keyCode;
|
|
1050 e.stateMask = event.stateMask;
|
|
1051 notifyListeners(DWT.KeyDown, e);
|
|
1052 break;
|
|
1053
|
|
1054 }
|
|
1055 default:
|
|
1056 }
|
|
1057 }
|
|
1058 /**
|
|
1059 * Pastes text from clipboard.
|
|
1060 * <p>
|
|
1061 * The selected text is deleted from the widget
|
|
1062 * and new text inserted from the clipboard.
|
|
1063 * </p>
|
|
1064 *
|
|
1065 * @exception DWTException <ul>
|
|
1066 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1067 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1068 * </ul>
|
|
1069 *
|
|
1070 * @since 3.3
|
|
1071 */
|
|
1072 public void paste () {
|
|
1073 checkWidget ();
|
|
1074 text.paste ();
|
|
1075 }
|
|
1076 void popupEvent(Event event) {
|
|
1077 switch (event.type) {
|
|
1078 case DWT.Paint:
|
|
1079 // draw black rectangle around list
|
|
1080 Rectangle listRect = list.getBounds();
|
|
1081 Color black = getDisplay().getSystemColor(DWT.COLOR_BLACK);
|
|
1082 event.gc.setForeground(black);
|
|
1083 event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1);
|
|
1084 break;
|
|
1085 case DWT.Close:
|
|
1086 event.doit = false;
|
|
1087 dropDown (false);
|
|
1088 break;
|
|
1089 case DWT.Deactivate:
|
|
1090 dropDown (false);
|
|
1091 break;
|
|
1092 default:
|
|
1093 }
|
|
1094 }
|
|
1095 public override void redraw () {
|
|
1096 super.redraw();
|
|
1097 text.redraw();
|
|
1098 arrow.redraw();
|
|
1099 if (popup.isVisible()) list.redraw();
|
|
1100 }
|
|
1101 public override void redraw (int x, int y, int width, int height, bool all) {
|
|
1102 super.redraw(x, y, width, height, true);
|
|
1103 }
|
|
1104
|
|
1105 /**
|
|
1106 * Removes the item from the receiver's list at the given
|
|
1107 * zero-relative index.
|
|
1108 *
|
|
1109 * @param index the index for the item
|
|
1110 *
|
|
1111 * @exception IllegalArgumentException <ul>
|
|
1112 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
|
|
1113 * </ul>
|
|
1114 * @exception DWTException <ul>
|
|
1115 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1116 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1117 * </ul>
|
|
1118 */
|
|
1119 public void remove (int index) {
|
|
1120 checkWidget();
|
|
1121 list.remove (index);
|
|
1122 }
|
|
1123 /**
|
|
1124 * Removes the items from the receiver's list which are
|
|
1125 * between the given zero-relative start and end
|
|
1126 * indices (inclusive).
|
|
1127 *
|
|
1128 * @param start the start of the range
|
|
1129 * @param end the end of the range
|
|
1130 *
|
|
1131 * @exception IllegalArgumentException <ul>
|
|
1132 * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
|
|
1133 * </ul>
|
|
1134 * @exception DWTException <ul>
|
|
1135 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1136 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1137 * </ul>
|
|
1138 */
|
|
1139 public void remove (int start, int end) {
|
|
1140 checkWidget();
|
|
1141 list.remove (start, end);
|
|
1142 }
|
|
1143 /**
|
|
1144 * Searches the receiver's list starting at the first item
|
|
1145 * until an item is found that is equal to the argument,
|
|
1146 * and removes that item from the list.
|
|
1147 *
|
|
1148 * @param string the item to remove
|
|
1149 *
|
|
1150 * @exception IllegalArgumentException <ul>
|
|
1151 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
|
|
1152 * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
|
|
1153 * </ul>
|
|
1154 * @exception DWTException <ul>
|
|
1155 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1156 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1157 * </ul>
|
|
1158 */
|
|
1159 public void remove (char[] string) {
|
|
1160 checkWidget();
|
|
1161 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
1162 list.remove (string);
|
|
1163 }
|
|
1164 /**
|
|
1165 * Removes all of the items from the receiver's list and clear the
|
|
1166 * contents of receiver's text field.
|
|
1167 * <p>
|
|
1168 * @exception DWTException <ul>
|
|
1169 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1170 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1171 * </ul>
|
|
1172 */
|
|
1173 public void removeAll () {
|
|
1174 checkWidget();
|
|
1175 text.setText (""); //$NON-NLS-1$
|
|
1176 list.removeAll ();
|
|
1177 }
|
|
1178 /**
|
|
1179 * Removes the listener from the collection of listeners who will
|
|
1180 * be notified when the receiver's text is modified.
|
|
1181 *
|
|
1182 * @param listener the listener which should no longer be notified
|
|
1183 *
|
|
1184 * @exception IllegalArgumentException <ul>
|
|
1185 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1186 * </ul>
|
|
1187 * @exception DWTException <ul>
|
|
1188 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1189 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1190 * </ul>
|
|
1191 *
|
|
1192 * @see ModifyListener
|
|
1193 * @see #addModifyListener
|
|
1194 */
|
|
1195 public void removeModifyListener (ModifyListener listener) {
|
|
1196 checkWidget();
|
|
1197 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
1198 removeListener(DWT.Modify, listener);
|
|
1199 }
|
|
1200 /**
|
|
1201 * Removes the listener from the collection of listeners who will
|
|
1202 * be notified when the user changes the receiver's selection.
|
|
1203 *
|
|
1204 * @param listener the listener which should no longer be notified
|
|
1205 *
|
|
1206 * @exception IllegalArgumentException <ul>
|
|
1207 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1208 * </ul>
|
|
1209 * @exception DWTException <ul>
|
|
1210 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1211 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1212 * </ul>
|
|
1213 *
|
|
1214 * @see SelectionListener
|
|
1215 * @see #addSelectionListener
|
|
1216 */
|
|
1217 public void removeSelectionListener (SelectionListener listener) {
|
|
1218 checkWidget();
|
|
1219 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
1220 removeListener(DWT.Selection, listener);
|
|
1221 removeListener(DWT.DefaultSelection,listener);
|
|
1222 }
|
|
1223 /**
|
|
1224 * Removes the listener from the collection of listeners who will
|
|
1225 * be notified when the control is verified.
|
|
1226 *
|
|
1227 * @param listener the listener which should no longer be notified
|
|
1228 *
|
|
1229 * @exception IllegalArgumentException <ul>
|
|
1230 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1231 * </ul>
|
|
1232 * @exception DWTException <ul>
|
|
1233 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1234 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1235 * </ul>
|
|
1236 *
|
|
1237 * @see VerifyListener
|
|
1238 * @see #addVerifyListener
|
|
1239 *
|
|
1240 * @since 3.3
|
|
1241 */
|
|
1242 public void removeVerifyListener (VerifyListener listener) {
|
|
1243 checkWidget();
|
|
1244 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
1245 removeListener(DWT.Verify, listener);
|
|
1246 }
|
|
1247 /**
|
|
1248 * Selects the item at the given zero-relative index in the receiver's
|
|
1249 * list. If the item at the index was already selected, it remains
|
|
1250 * selected. Indices that are out of range are ignored.
|
|
1251 *
|
|
1252 * @param index the index of the item to select
|
|
1253 *
|
|
1254 * @exception DWTException <ul>
|
|
1255 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1256 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1257 * </ul>
|
|
1258 */
|
|
1259 public void select (int index) {
|
|
1260 checkWidget();
|
|
1261 if (index is -1) {
|
|
1262 list.deselectAll ();
|
|
1263 text.setText (""); //$NON-NLS-1$
|
|
1264 return;
|
|
1265 }
|
|
1266 if (0 <= index && index < list.getItemCount()) {
|
|
1267 if (index !is getSelectionIndex()) {
|
|
1268 text.setText (list.getItem (index));
|
|
1269 text.selectAll ();
|
|
1270 list.select (index);
|
|
1271 list.showSelection ();
|
|
1272 }
|
|
1273 }
|
|
1274 }
|
|
1275 public override void setBackground (Color color) {
|
|
1276 super.setBackground(color);
|
|
1277 background = color;
|
|
1278 if (text !is null) text.setBackground(color);
|
|
1279 if (list !is null) list.setBackground(color);
|
|
1280 if (arrow !is null) arrow.setBackground(color);
|
|
1281 }
|
|
1282 /**
|
|
1283 * Sets the editable state.
|
|
1284 *
|
|
1285 * @param editable the new editable state
|
|
1286 *
|
|
1287 * @exception DWTException <ul>
|
|
1288 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1289 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1290 * </ul>
|
|
1291 *
|
|
1292 * @since 3.0
|
|
1293 */
|
|
1294 public void setEditable (bool editable) {
|
|
1295 checkWidget ();
|
|
1296 text.setEditable(editable);
|
|
1297 }
|
|
1298 public override void setEnabled (bool enabled) {
|
|
1299 super.setEnabled(enabled);
|
|
1300 if (popup !is null) popup.setVisible (false);
|
|
1301 if (text !is null) text.setEnabled(enabled);
|
|
1302 if (arrow !is null) arrow.setEnabled(enabled);
|
|
1303 }
|
|
1304 public override bool setFocus () {
|
|
1305 checkWidget();
|
|
1306 if (isFocusControl ()) return true;
|
|
1307 return text.setFocus ();
|
|
1308 }
|
|
1309 public override void setFont (Font font) {
|
|
1310 super.setFont (font);
|
|
1311 this.font = font;
|
|
1312 text.setFont (font);
|
|
1313 list.setFont (font);
|
|
1314 internalLayout (true);
|
|
1315 }
|
|
1316 public override void setForeground (Color color) {
|
|
1317 super.setForeground(color);
|
|
1318 foreground = color;
|
|
1319 if (text !is null) text.setForeground(color);
|
|
1320 if (list !is null) list.setForeground(color);
|
|
1321 if (arrow !is null) arrow.setForeground(color);
|
|
1322 }
|
|
1323 /**
|
|
1324 * Sets the text of the item in the receiver's list at the given
|
|
1325 * zero-relative index to the string argument. This is equivalent
|
|
1326 * to <code>remove</code>'ing the old item at the index, and then
|
|
1327 * <code>add</code>'ing the new item at that index.
|
|
1328 *
|
|
1329 * @param index the index for the item
|
|
1330 * @param string the new text for the item
|
|
1331 *
|
|
1332 * @exception IllegalArgumentException <ul>
|
|
1333 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
|
|
1334 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
|
|
1335 * </ul>
|
|
1336 * @exception DWTException <ul>
|
|
1337 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1338 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1339 * </ul>
|
|
1340 */
|
|
1341 public void setItem (int index, char[] string) {
|
|
1342 checkWidget();
|
|
1343 list.setItem (index, string);
|
|
1344 }
|
|
1345 /**
|
|
1346 * Sets the receiver's list to be the given array of items.
|
|
1347 *
|
|
1348 * @param items the array of items
|
|
1349 *
|
|
1350 * @exception IllegalArgumentException <ul>
|
|
1351 * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
|
|
1352 * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
|
|
1353 * </ul>
|
|
1354 * @exception DWTException <ul>
|
|
1355 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1356 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1357 * </ul>
|
|
1358 */
|
|
1359 public void setItems (char[] [] items) {
|
|
1360 checkWidget ();
|
|
1361 list.setItems (items);
|
|
1362 if (!text.getEditable ()) text.setText (""); //$NON-NLS-1$
|
|
1363 }
|
|
1364 /**
|
|
1365 * Sets the layout which is associated with the receiver to be
|
|
1366 * the argument which may be null.
|
|
1367 * <p>
|
|
1368 * Note: No Layout can be set on this Control because it already
|
|
1369 * manages the size and position of its children.
|
|
1370 * </p>
|
|
1371 *
|
|
1372 * @param layout the receiver's new layout or null
|
|
1373 *
|
|
1374 * @exception DWTException <ul>
|
|
1375 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1376 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1377 * </ul>
|
|
1378 */
|
|
1379 public override void setLayout (Layout layout) {
|
|
1380 checkWidget ();
|
|
1381 return;
|
|
1382 }
|
|
1383 public override void setMenu(Menu menu) {
|
|
1384 text.setMenu(menu);
|
|
1385 }
|
|
1386 /**
|
|
1387 * Sets the selection in the receiver's text field to the
|
|
1388 * range specified by the argument whose x coordinate is the
|
|
1389 * start of the selection and whose y coordinate is the end
|
|
1390 * of the selection.
|
|
1391 *
|
|
1392 * @param selection a point representing the new selection start and end
|
|
1393 *
|
|
1394 * @exception IllegalArgumentException <ul>
|
|
1395 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
1396 * </ul>
|
|
1397 * @exception DWTException <ul>
|
|
1398 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1399 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1400 * </ul>
|
|
1401 */
|
|
1402 public void setSelection (Point selection) {
|
|
1403 checkWidget();
|
|
1404 if (selection is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
1405 text.setSelection (selection.x, selection.y);
|
|
1406 }
|
|
1407
|
|
1408 /**
|
|
1409 * Sets the contents of the receiver's text field to the
|
|
1410 * given string.
|
|
1411 * <p>
|
|
1412 * Note: The text field in a <code>Combo</code> is typically
|
|
1413 * only capable of displaying a single line of text. Thus,
|
|
1414 * setting the text to a string containing line breaks or
|
|
1415 * other special characters will probably cause it to
|
|
1416 * display incorrectly.
|
|
1417 * </p>
|
|
1418 *
|
|
1419 * @param string the new text
|
|
1420 *
|
|
1421 * @exception IllegalArgumentException <ul>
|
|
1422 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
|
|
1423 * </ul>
|
|
1424 * @exception DWTException <ul>
|
|
1425 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1426 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1427 * </ul>
|
|
1428 */
|
|
1429 public void setText (char[] string) {
|
|
1430 checkWidget();
|
|
1431 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
1432 int index = list.indexOf (string);
|
|
1433 if (index is -1) {
|
|
1434 list.deselectAll ();
|
|
1435 text.setText (string);
|
|
1436 return;
|
|
1437 }
|
|
1438 text.setText (string);
|
|
1439 text.selectAll ();
|
|
1440 list.setSelection (index);
|
|
1441 list.showSelection ();
|
|
1442 }
|
|
1443 /**
|
|
1444 * Sets the maximum number of characters that the receiver's
|
|
1445 * text field is capable of holding to be the argument.
|
|
1446 *
|
|
1447 * @param limit new text limit
|
|
1448 *
|
|
1449 * @exception IllegalArgumentException <ul>
|
|
1450 * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
|
|
1451 * </ul>
|
|
1452 * @exception DWTException <ul>
|
|
1453 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1454 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1455 * </ul>
|
|
1456 */
|
|
1457 public void setTextLimit (int limit) {
|
|
1458 checkWidget();
|
|
1459 text.setTextLimit (limit);
|
|
1460 }
|
|
1461
|
|
1462 public override void setToolTipText (char[] string) {
|
|
1463 checkWidget();
|
|
1464 super.setToolTipText(string);
|
|
1465 arrow.setToolTipText (string);
|
|
1466 text.setToolTipText (string);
|
|
1467 }
|
|
1468
|
|
1469 public override void setVisible (bool visible) {
|
|
1470 super.setVisible(visible);
|
|
1471 /*
|
|
1472 * At this point the widget may have been disposed in a FocusOut event.
|
|
1473 * If so then do not continue.
|
|
1474 */
|
|
1475 if (isDisposed ()) return;
|
|
1476 if (!visible) popup.setVisible(false);
|
|
1477 }
|
|
1478 /**
|
|
1479 * Sets the number of items that are visible in the drop
|
|
1480 * down portion of the receiver's list.
|
|
1481 *
|
|
1482 * @param count the new number of items to be visible
|
|
1483 *
|
|
1484 * @exception DWTException <ul>
|
|
1485 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1486 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1487 * </ul>
|
|
1488 *
|
|
1489 * @since 3.0
|
|
1490 */
|
|
1491 public void setVisibleItemCount (int count) {
|
|
1492 checkWidget ();
|
|
1493 if (count < 0) return;
|
|
1494 visibleItemCount = count;
|
|
1495 }
|
|
1496 char[] stripMnemonic (char[] string) {
|
|
1497 int index = 0;
|
|
1498 int length_ = string.length;
|
|
1499 do {
|
|
1500 while ((index < length_) && (string[index] !is '&')) index++;
|
|
1501 if (++index >= length_) return string;
|
|
1502 if (string[index] !is '&') {
|
|
1503 return string[0 .. index-1] ~ string[index .. length_];
|
|
1504 }
|
|
1505 index++;
|
|
1506 } while (index < length_);
|
|
1507 return string;
|
|
1508 }
|
|
1509 void textEvent (Event event) {
|
|
1510 switch (event.type) {
|
|
1511 case DWT.FocusIn: {
|
|
1512 handleFocus (DWT.FocusIn);
|
|
1513 break;
|
|
1514 }
|
|
1515 case DWT.KeyDown: {
|
|
1516 Event keyEvent = new Event ();
|
|
1517 keyEvent.time = event.time;
|
|
1518 keyEvent.character = event.character;
|
|
1519 keyEvent.keyCode = event.keyCode;
|
|
1520 keyEvent.stateMask = event.stateMask;
|
|
1521 notifyListeners (DWT.KeyDown, keyEvent);
|
|
1522 if (isDisposed ()) break;
|
|
1523 event.doit = keyEvent.doit;
|
|
1524 if (!event.doit) break;
|
|
1525
|
|
1526 if (event.character is DWT.CR) {
|
|
1527 dropDown (false);
|
|
1528 Event selectionEvent = new Event ();
|
|
1529 selectionEvent.time = event.time;
|
|
1530 selectionEvent.stateMask = event.stateMask;
|
|
1531 notifyListeners (DWT.DefaultSelection, selectionEvent);
|
|
1532 if (isDisposed ()) break;
|
|
1533 }
|
|
1534
|
|
1535 if (event.keyCode is DWT.ARROW_UP || event.keyCode is DWT.ARROW_DOWN) {
|
|
1536 event.doit = false;
|
|
1537 if ((event.stateMask & DWT.ALT) !is 0) {
|
|
1538 bool dropped = isDropped ();
|
|
1539 text.selectAll ();
|
|
1540 if (!dropped) setFocus ();
|
|
1541 dropDown (!dropped);
|
|
1542 break;
|
|
1543 }
|
|
1544
|
|
1545 int oldIndex = getSelectionIndex ();
|
|
1546 if (event.keyCode is DWT.ARROW_UP) {
|
|
1547 select (Math.max (oldIndex - 1, 0));
|
|
1548 } else {
|
|
1549 select (Math.min (oldIndex + 1, getItemCount () - 1));
|
|
1550 }
|
|
1551 if (oldIndex !is getSelectionIndex ()) {
|
|
1552 Event e = new Event();
|
|
1553 e.time = event.time;
|
|
1554 e.stateMask = event.stateMask;
|
|
1555 notifyListeners (DWT.Selection, e);
|
|
1556 }
|
|
1557 if (isDisposed ()) break;
|
|
1558 }
|
|
1559
|
|
1560 // Further work : Need to add support for incremental search in
|
|
1561 // pop up list as characters typed in text widget
|
|
1562 break;
|
|
1563 }
|
|
1564 case DWT.KeyUp: {
|
|
1565 Event e = new Event ();
|
|
1566 e.time = event.time;
|
|
1567 e.character = event.character;
|
|
1568 e.keyCode = event.keyCode;
|
|
1569 e.stateMask = event.stateMask;
|
|
1570 notifyListeners (DWT.KeyUp, e);
|
|
1571 event.doit = e.doit;
|
|
1572 break;
|
|
1573 }
|
|
1574 case DWT.MenuDetect: {
|
|
1575 Event e = new Event ();
|
|
1576 e.time = event.time;
|
|
1577 notifyListeners (DWT.MenuDetect, e);
|
|
1578 break;
|
|
1579 }
|
|
1580 case DWT.Modify: {
|
|
1581 list.deselectAll ();
|
|
1582 Event e = new Event ();
|
|
1583 e.time = event.time;
|
|
1584 notifyListeners (DWT.Modify, e);
|
|
1585 break;
|
|
1586 }
|
|
1587 case DWT.MouseDown: {
|
|
1588 if (event.button !is 1) return;
|
|
1589 if (text.getEditable ()) return;
|
|
1590 bool dropped = isDropped ();
|
|
1591 text.selectAll ();
|
|
1592 if (!dropped) setFocus ();
|
|
1593 dropDown (!dropped);
|
|
1594 break;
|
|
1595 }
|
|
1596 case DWT.MouseUp: {
|
|
1597 if (event.button !is 1) return;
|
|
1598 if (text.getEditable ()) return;
|
|
1599 text.selectAll ();
|
|
1600 break;
|
|
1601 }
|
|
1602 case DWT.Traverse: {
|
|
1603 switch (event.detail) {
|
|
1604 case DWT.TRAVERSE_RETURN:
|
|
1605 case DWT.TRAVERSE_ARROW_PREVIOUS:
|
|
1606 case DWT.TRAVERSE_ARROW_NEXT:
|
|
1607 // The enter causes default selection and
|
|
1608 // the arrow keys are used to manipulate the list contents so
|
|
1609 // do not use them for traversal.
|
|
1610 event.doit = false;
|
|
1611 break;
|
|
1612 default:
|
|
1613 }
|
|
1614
|
|
1615 Event e = new Event ();
|
|
1616 e.time = event.time;
|
|
1617 e.detail = event.detail;
|
|
1618 e.doit = event.doit;
|
|
1619 e.character = event.character;
|
|
1620 e.keyCode = event.keyCode;
|
|
1621 notifyListeners (DWT.Traverse, e);
|
|
1622 event.doit = e.doit;
|
|
1623 event.detail = e.detail;
|
|
1624 break;
|
|
1625 }
|
|
1626 case DWT.Verify: {
|
|
1627 Event e = new Event ();
|
|
1628 e.text = event.text;
|
|
1629 e.start = event.start;
|
|
1630 e.end = event.end;
|
|
1631 e.character = event.character;
|
|
1632 e.keyCode = event.keyCode;
|
|
1633 e.stateMask = event.stateMask;
|
|
1634 notifyListeners (DWT.Verify, e);
|
|
1635 event.doit = e.doit;
|
|
1636 break;
|
|
1637 }
|
|
1638 default:
|
|
1639 }
|
|
1640 }
|
|
1641 }
|