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