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