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