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