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