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