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