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