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