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