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