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 */
|
51
|
584 dchar _findMnemonic (String str) {
|
|
585 if (str is null) return '\0';
|
25
|
586 int index = 0;
|
51
|
587 int length = str.length;
|
25
|
588 do {
|
51
|
589 while (index < length && str[index] !is '&') index++;
|
25
|
590 if (++index >= length) return '\0';
|
51
|
591 if (str[index] !is '&') return Character.toLowerCase (str.dcharAt (index));
|
25
|
592 index++;
|
|
593 } while (index < length);
|
|
594 return '\0';
|
|
595 }
|
|
596 /*
|
|
597 * Return the Label immediately preceding the receiver in the z-order,
|
|
598 * or null if none.
|
|
599 */
|
|
600 Label getAssociatedLabel () {
|
|
601 Control[] siblings = getParent ().getChildren ();
|
|
602 for (int i = 0; i < siblings.length; i++) {
|
|
603 if (siblings [i] is this) {
|
|
604 if (i > 0 && ( null !is cast(Label)siblings [i-1] )) {
|
|
605 return cast(Label) siblings [i-1];
|
|
606 }
|
|
607 }
|
|
608 }
|
|
609 return null;
|
|
610 }
|
|
611 public override Control [] getChildren () {
|
|
612 checkWidget();
|
|
613 return new Control [0];
|
|
614 }
|
|
615 /**
|
|
616 * Gets the editable state.
|
|
617 *
|
|
618 * @return whether or not the receiver is editable
|
|
619 *
|
|
620 * @exception SWTException <ul>
|
|
621 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
622 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
623 * </ul>
|
|
624 *
|
|
625 * @since 3.0
|
|
626 */
|
|
627 public bool getEditable () {
|
|
628 checkWidget ();
|
|
629 return text.getEditable();
|
|
630 }
|
|
631 /**
|
|
632 * Returns the item at the given, zero-relative index in the
|
|
633 * receiver's list. Throws an exception if the index is out
|
|
634 * of range.
|
|
635 *
|
|
636 * @param index the index of the item to return
|
|
637 * @return the item at the given index
|
|
638 *
|
|
639 * @exception IllegalArgumentException <ul>
|
|
640 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
|
|
641 * </ul>
|
|
642 * @exception SWTException <ul>
|
|
643 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
644 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
645 * </ul>
|
|
646 */
|
|
647 public String getItem (int index) {
|
|
648 checkWidget();
|
|
649 return list.getItem (index);
|
|
650 }
|
|
651 /**
|
|
652 * Returns the number of items contained in the receiver's list.
|
|
653 *
|
|
654 * @return the number of items
|
|
655 *
|
|
656 * @exception SWTException <ul>
|
|
657 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
658 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
659 * </ul>
|
|
660 */
|
|
661 public int getItemCount () {
|
|
662 checkWidget ();
|
|
663 return list.getItemCount ();
|
|
664 }
|
|
665 /**
|
|
666 * Returns the height of the area which would be used to
|
|
667 * display <em>one</em> of the items in the receiver's list.
|
|
668 *
|
|
669 * @return the height of one item
|
|
670 *
|
|
671 * @exception SWTException <ul>
|
|
672 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
673 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
674 * </ul>
|
|
675 */
|
|
676 public int getItemHeight () {
|
|
677 checkWidget ();
|
|
678 return list.getItemHeight ();
|
|
679 }
|
|
680 /**
|
|
681 * Returns an array of <code>String</code>s which are the items
|
|
682 * in the receiver's list.
|
|
683 * <p>
|
|
684 * Note: This is not the actual structure used by the receiver
|
|
685 * to maintain its list of items, so modifying the array will
|
|
686 * not affect the receiver.
|
|
687 * </p>
|
|
688 *
|
|
689 * @return the items in the receiver's list
|
|
690 *
|
|
691 * @exception SWTException <ul>
|
|
692 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
693 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
694 * </ul>
|
|
695 */
|
|
696 public String [] getItems () {
|
|
697 checkWidget ();
|
|
698 return list.getItems ();
|
|
699 }
|
|
700 /**
|
|
701 * Returns <code>true</code> if the receiver's list is visible,
|
|
702 * and <code>false</code> otherwise.
|
|
703 * <p>
|
|
704 * If one of the receiver's ancestors is not visible or some
|
|
705 * other condition makes the receiver not visible, this method
|
|
706 * may still indicate that it is considered visible even though
|
|
707 * it may not actually be showing.
|
|
708 * </p>
|
|
709 *
|
|
710 * @return the receiver's list's visibility state
|
|
711 *
|
|
712 * @exception SWTException <ul>
|
|
713 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
714 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
715 * </ul>
|
|
716 *
|
|
717 * @since 3.4
|
|
718 */
|
|
719 public bool getListVisible () {
|
|
720 checkWidget ();
|
|
721 return isDropped();
|
|
722 }
|
|
723 public override Menu getMenu() {
|
|
724 return text.getMenu();
|
|
725 }
|
|
726 /**
|
|
727 * Returns a <code>Point</code> whose x coordinate is the start
|
|
728 * of the selection in the receiver's text field, and whose y
|
|
729 * coordinate is the end of the selection. The returned values
|
|
730 * are zero-relative. An "empty" selection as indicated by
|
|
731 * the the x and y coordinates having the same value.
|
|
732 *
|
|
733 * @return a point representing the selection start and end
|
|
734 *
|
|
735 * @exception SWTException <ul>
|
|
736 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
737 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
738 * </ul>
|
|
739 */
|
|
740 public Point getSelection () {
|
|
741 checkWidget ();
|
|
742 return text.getSelection ();
|
|
743 }
|
|
744 /**
|
|
745 * Returns the zero-relative index of the item which is currently
|
|
746 * selected in the receiver's list, or -1 if no item is selected.
|
|
747 *
|
|
748 * @return the index of the selected item
|
|
749 *
|
|
750 * @exception SWTException <ul>
|
|
751 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
752 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
753 * </ul>
|
|
754 */
|
|
755 public int getSelectionIndex () {
|
|
756 checkWidget ();
|
|
757 return list.getSelectionIndex ();
|
|
758 }
|
|
759 public override int getStyle () {
|
|
760 int style = super.getStyle ();
|
|
761 style &= ~SWT.READ_ONLY;
|
|
762 if (!text.getEditable()) style |= SWT.READ_ONLY;
|
|
763 return style;
|
|
764 }
|
|
765 /**
|
|
766 * Returns a string containing a copy of the contents of the
|
|
767 * receiver's text field.
|
|
768 *
|
|
769 * @return the receiver's text
|
|
770 *
|
|
771 * @exception SWTException <ul>
|
|
772 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
773 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
774 * </ul>
|
|
775 */
|
|
776 public String getText () {
|
|
777 checkWidget ();
|
|
778 return text.getText ();
|
|
779 }
|
|
780 /**
|
|
781 * Returns the height of the receivers's text field.
|
|
782 *
|
|
783 * @return the text height
|
|
784 *
|
|
785 * @exception SWTException <ul>
|
|
786 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
787 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
788 * </ul>
|
|
789 */
|
|
790 public int getTextHeight () {
|
|
791 checkWidget ();
|
|
792 return text.getLineHeight ();
|
|
793 }
|
|
794 /**
|
|
795 * Returns the maximum number of characters that the receiver's
|
|
796 * text field is capable of holding. If this has not been changed
|
|
797 * by <code>setTextLimit()</code>, it will be the constant
|
|
798 * <code>Combo.LIMIT</code>.
|
|
799 *
|
|
800 * @return the text limit
|
|
801 *
|
|
802 * @exception SWTException <ul>
|
|
803 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
804 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
805 * </ul>
|
|
806 */
|
|
807 public int getTextLimit () {
|
|
808 checkWidget ();
|
|
809 return text.getTextLimit ();
|
|
810 }
|
|
811 /**
|
|
812 * Gets the number of items that are visible in the drop
|
|
813 * down portion of the receiver's list.
|
|
814 *
|
|
815 * @return the number of items that are visible
|
|
816 *
|
|
817 * @exception SWTException <ul>
|
|
818 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
819 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
820 * </ul>
|
|
821 *
|
|
822 * @since 3.0
|
|
823 */
|
|
824 public int getVisibleItemCount () {
|
|
825 checkWidget ();
|
|
826 return visibleItemCount;
|
|
827 }
|
|
828 void handleFocus (int type) {
|
|
829 if (isDisposed ()) return;
|
|
830 switch (type) {
|
|
831 case SWT.FocusIn: {
|
|
832 if (hasFocus) return;
|
|
833 if (getEditable ()) text.selectAll ();
|
|
834 hasFocus = true;
|
|
835 Shell shell = getShell ();
|
|
836 shell.removeListener (SWT.Deactivate, listener);
|
|
837 shell.addListener (SWT.Deactivate, listener);
|
|
838 Display display = getDisplay ();
|
|
839 display.removeFilter (SWT.FocusIn, filter);
|
|
840 display.addFilter (SWT.FocusIn, filter);
|
|
841 Event e = new Event ();
|
|
842 notifyListeners (SWT.FocusIn, e);
|
|
843 break;
|
|
844 }
|
|
845 case SWT.FocusOut: {
|
|
846 if (!hasFocus) return;
|
|
847 Control focusControl = getDisplay ().getFocusControl ();
|
|
848 if (focusControl is arrow || focusControl is list || focusControl is text) return;
|
|
849 hasFocus = false;
|
|
850 Shell shell = getShell ();
|
|
851 shell.removeListener(SWT.Deactivate, listener);
|
|
852 Display display = getDisplay ();
|
|
853 display.removeFilter (SWT.FocusIn, filter);
|
|
854 Event e = new Event ();
|
|
855 notifyListeners (SWT.FocusOut, e);
|
|
856 break;
|
|
857 }
|
|
858 default:
|
|
859 }
|
|
860 }
|
|
861 /**
|
|
862 * Searches the receiver's list starting at the first item
|
|
863 * (index 0) until an item is found that is equal to the
|
|
864 * argument, and returns the index of that item. If no item
|
|
865 * is found, returns -1.
|
|
866 *
|
|
867 * @param string the search item
|
|
868 * @return the index of the item
|
|
869 *
|
|
870 * @exception SWTException <ul>
|
|
871 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
872 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
873 * </ul>
|
|
874 */
|
|
875 public int indexOf (String string) {
|
|
876 checkWidget ();
|
|
877 // SWT extension: allow null for zero length string
|
|
878 //if (string is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
879 return list.indexOf (string);
|
|
880 }
|
|
881 /**
|
|
882 * Searches the receiver's list starting at the given,
|
|
883 * zero-relative index until an item is found that is equal
|
|
884 * to the argument, and returns the index of that item. If
|
|
885 * no item is found or the starting index is out of range,
|
|
886 * returns -1.
|
|
887 *
|
|
888 * @param string the search item
|
|
889 * @param start the zero-relative index at which to begin the search
|
|
890 * @return the index of the item
|
|
891 *
|
|
892 * @exception SWTException <ul>
|
|
893 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
894 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
895 * </ul>
|
|
896 */
|
|
897 public int indexOf (String string, int start) {
|
|
898 checkWidget ();
|
|
899 // SWT extension: allow null for zero length string
|
|
900 //if (string is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
901 return list.indexOf (string, start);
|
|
902 }
|
|
903
|
|
904 void initAccessible() {
|
|
905 AccessibleAdapter accessibleAdapter = new class() AccessibleAdapter {
|
|
906 public void getName (AccessibleEvent e) {
|
|
907 String name = null;
|
|
908 Label label = getAssociatedLabel ();
|
|
909 if (label !is null) {
|
|
910 name = stripMnemonic (label.getText());
|
|
911 }
|
|
912 e.result = name;
|
|
913 }
|
|
914 public void getKeyboardShortcut(AccessibleEvent e) {
|
|
915 String shortcut = null;
|
|
916 Label label = getAssociatedLabel ();
|
|
917 if (label !is null) {
|
|
918 String text = label.getText ();
|
|
919 if (text !is null) {
|
|
920 dchar mnemonic = _findMnemonic (text);
|
|
921 if (mnemonic !is '\0') {
|
51
|
922 shortcut = Format( "Alt+{}", mnemonic ); //$NON-NLS-1$
|
25
|
923 }
|
|
924 }
|
|
925 }
|
|
926 e.result = shortcut;
|
|
927 }
|
|
928 public void getHelp (AccessibleEvent e) {
|
|
929 e.result = getToolTipText ();
|
|
930 }
|
|
931 };
|
|
932 getAccessible ().addAccessibleListener (accessibleAdapter);
|
|
933 text.getAccessible ().addAccessibleListener (accessibleAdapter);
|
|
934 list.getAccessible ().addAccessibleListener (accessibleAdapter);
|
|
935
|
|
936 arrow.getAccessible ().addAccessibleListener (new class() AccessibleAdapter {
|
|
937 public void getName (AccessibleEvent e) {
|
|
938 e.result = isDropped () ? SWT.getMessage ("SWT_Close") : SWT.getMessage ("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
939 }
|
|
940 public void getKeyboardShortcut (AccessibleEvent e) {
|
|
941 e.result = "Alt+Down Arrow"; //$NON-NLS-1$
|
|
942 }
|
|
943 public void getHelp (AccessibleEvent e) {
|
|
944 e.result = getToolTipText ();
|
|
945 }
|
|
946 });
|
|
947
|
|
948 getAccessible().addAccessibleTextListener (new class() AccessibleTextAdapter {
|
|
949 public void getCaretOffset (AccessibleTextEvent e) {
|
|
950 e.offset = text.getCaretPosition ();
|
|
951 }
|
|
952 public void getSelectionRange(AccessibleTextEvent e) {
|
|
953 Point sel = text.getSelection();
|
|
954 e.offset = sel.x;
|
|
955 e.length = sel.y - sel.x;
|
|
956 }
|
|
957 });
|
|
958
|
|
959 getAccessible().addAccessibleControlListener (new class() AccessibleControlAdapter {
|
|
960 public void getChildAtPoint (AccessibleControlEvent e) {
|
|
961 Point testPoint = toControl (e.x, e.y);
|
|
962 if (getBounds ().contains (testPoint)) {
|
|
963 e.childID = ACC.CHILDID_SELF;
|
|
964 }
|
|
965 }
|
|
966
|
|
967 public void getLocation (AccessibleControlEvent e) {
|
|
968 Rectangle location = getBounds ();
|
|
969 Point pt = getParent().toDisplay (location.x, location.y);
|
|
970 e.x = pt.x;
|
|
971 e.y = pt.y;
|
|
972 e.width = location.width;
|
|
973 e.height = location.height;
|
|
974 }
|
|
975
|
|
976 public void getChildCount (AccessibleControlEvent e) {
|
|
977 e.detail = 0;
|
|
978 }
|
|
979
|
|
980 public void getRole (AccessibleControlEvent e) {
|
|
981 e.detail = ACC.ROLE_COMBOBOX;
|
|
982 }
|
|
983
|
|
984 public void getState (AccessibleControlEvent e) {
|
|
985 e.detail = ACC.STATE_NORMAL;
|
|
986 }
|
|
987
|
|
988 public void getValue (AccessibleControlEvent e) {
|
|
989 e.result = getText ();
|
|
990 }
|
|
991 });
|
|
992
|
|
993 text.getAccessible ().addAccessibleControlListener (new class() AccessibleControlAdapter {
|
|
994 public void getRole (AccessibleControlEvent e) {
|
|
995 e.detail = text.getEditable () ? ACC.ROLE_TEXT : ACC.ROLE_LABEL;
|
|
996 }
|
|
997 });
|
|
998
|
|
999 arrow.getAccessible ().addAccessibleControlListener (new class() AccessibleControlAdapter {
|
|
1000 public void getDefaultAction (AccessibleControlEvent e) {
|
|
1001 e.result = isDropped () ? SWT.getMessage ("SWT_Close") : SWT.getMessage ("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
1002 }
|
|
1003 });
|
|
1004 }
|
|
1005 bool isDropped () {
|
|
1006 return popup.getVisible ();
|
|
1007 }
|
|
1008 public override bool isFocusControl () {
|
|
1009 checkWidget();
|
|
1010 if (text.isFocusControl () || arrow.isFocusControl () || list.isFocusControl () || popup.isFocusControl ()) {
|
|
1011 return true;
|
|
1012 }
|
|
1013 return super.isFocusControl ();
|
|
1014 }
|
|
1015 void internalLayout (bool changed) {
|
|
1016 if (isDropped ()) dropDown (false);
|
|
1017 Rectangle rect = getClientArea ();
|
|
1018 int width = rect.width;
|
|
1019 int height = rect.height;
|
|
1020 Point arrowSize = arrow.computeSize (SWT.DEFAULT, height, changed);
|
|
1021 text.setBounds (0, 0, width - arrowSize.x, height);
|
|
1022 arrow.setBounds (width - arrowSize.x, 0, arrowSize.x, arrowSize.y);
|
|
1023 }
|
|
1024 void listEvent (Event event) {
|
|
1025 switch (event.type) {
|
|
1026 case SWT.Dispose:
|
|
1027 if (getShell () !is popup.getParent ()) {
|
|
1028 String[] items = list.getItems ();
|
|
1029 int selectionIndex = list.getSelectionIndex ();
|
|
1030 popup = null;
|
|
1031 list = null;
|
|
1032 createPopup (items, selectionIndex);
|
|
1033 }
|
|
1034 break;
|
|
1035 case SWT.FocusIn: {
|
|
1036 handleFocus (SWT.FocusIn);
|
|
1037 break;
|
|
1038 }
|
|
1039 case SWT.MouseUp: {
|
|
1040 if (event.button !is 1) return;
|
|
1041 dropDown (false);
|
|
1042 break;
|
|
1043 }
|
|
1044 case SWT.Selection: {
|
|
1045 int index = list.getSelectionIndex ();
|
|
1046 if (index is -1) return;
|
|
1047 text.setText (list.getItem (index));
|
|
1048 text.selectAll ();
|
|
1049 list.setSelection (index);
|
|
1050 Event e = new Event ();
|
|
1051 e.time = event.time;
|
|
1052 e.stateMask = event.stateMask;
|
|
1053 e.doit = event.doit;
|
|
1054 notifyListeners (SWT.Selection, e);
|
|
1055 event.doit = e.doit;
|
|
1056 break;
|
|
1057 }
|
|
1058 case SWT.Traverse: {
|
|
1059 switch (event.detail) {
|
|
1060 case SWT.TRAVERSE_RETURN:
|
|
1061 case SWT.TRAVERSE_ESCAPE:
|
|
1062 case SWT.TRAVERSE_ARROW_PREVIOUS:
|
|
1063 case SWT.TRAVERSE_ARROW_NEXT:
|
|
1064 event.doit = false;
|
|
1065 break;
|
|
1066 case SWT.TRAVERSE_TAB_NEXT:
|
|
1067 case SWT.TRAVERSE_TAB_PREVIOUS:
|
|
1068 event.doit = text.traverse(event.detail);
|
|
1069 event.detail = SWT.TRAVERSE_NONE;
|
|
1070 if (event.doit) dropDown(false);
|
|
1071 return;
|
|
1072 default:
|
|
1073 }
|
|
1074 Event e = new Event ();
|
|
1075 e.time = event.time;
|
|
1076 e.detail = event.detail;
|
|
1077 e.doit = event.doit;
|
|
1078 e.character = event.character;
|
|
1079 e.keyCode = event.keyCode;
|
|
1080 notifyListeners (SWT.Traverse, e);
|
|
1081 event.doit = e.doit;
|
|
1082 event.detail = e.detail;
|
|
1083 break;
|
|
1084 }
|
|
1085 case SWT.KeyUp: {
|
|
1086 Event e = new Event ();
|
|
1087 e.time = event.time;
|
|
1088 e.character = event.character;
|
|
1089 e.keyCode = event.keyCode;
|
|
1090 e.stateMask = event.stateMask;
|
|
1091 notifyListeners (SWT.KeyUp, e);
|
|
1092 break;
|
|
1093 }
|
|
1094 case SWT.KeyDown: {
|
|
1095 if (event.character is SWT.ESC) {
|
|
1096 // Escape key cancels popup list
|
|
1097 dropDown (false);
|
|
1098 }
|
|
1099 if ((event.stateMask & SWT.ALT) !is 0 && (event.keyCode is SWT.ARROW_UP || event.keyCode is SWT.ARROW_DOWN)) {
|
|
1100 dropDown (false);
|
|
1101 }
|
|
1102 if (event.character is SWT.CR) {
|
|
1103 // Enter causes default selection
|
|
1104 dropDown (false);
|
|
1105 Event e = new Event ();
|
|
1106 e.time = event.time;
|
|
1107 e.stateMask = event.stateMask;
|
|
1108 notifyListeners (SWT.DefaultSelection, e);
|
|
1109 }
|
|
1110 // At this point the widget may have been disposed.
|
|
1111 // If so, do not continue.
|
|
1112 if (isDisposed ()) break;
|
|
1113 Event e = new Event();
|
|
1114 e.time = event.time;
|
|
1115 e.character = event.character;
|
|
1116 e.keyCode = event.keyCode;
|
|
1117 e.stateMask = event.stateMask;
|
|
1118 notifyListeners(SWT.KeyDown, e);
|
|
1119 break;
|
|
1120
|
|
1121 }
|
|
1122 default:
|
|
1123 }
|
|
1124 }
|
|
1125 /**
|
|
1126 * Pastes text from clipboard.
|
|
1127 * <p>
|
|
1128 * The selected text is deleted from the widget
|
|
1129 * and new text inserted from the clipboard.
|
|
1130 * </p>
|
|
1131 *
|
|
1132 * @exception SWTException <ul>
|
|
1133 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1134 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1135 * </ul>
|
|
1136 *
|
|
1137 * @since 3.3
|
|
1138 */
|
|
1139 public void paste () {
|
|
1140 checkWidget ();
|
|
1141 text.paste ();
|
|
1142 }
|
|
1143 void popupEvent(Event event) {
|
|
1144 switch (event.type) {
|
|
1145 case SWT.Paint:
|
|
1146 // draw black rectangle around list
|
|
1147 Rectangle listRect = list.getBounds();
|
|
1148 Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
|
|
1149 event.gc.setForeground(black);
|
|
1150 event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1);
|
|
1151 break;
|
|
1152 case SWT.Close:
|
|
1153 event.doit = false;
|
|
1154 dropDown (false);
|
|
1155 break;
|
|
1156 case SWT.Deactivate:
|
|
1157 /*
|
|
1158 * Bug in GTK. When the arrow button is pressed the popup control receives a
|
|
1159 * deactivate event and then the arrow button receives a selection event. If
|
|
1160 * we hide the popup in the deactivate event, the selection event will show
|
|
1161 * it again. To prevent the popup from showing again, we will let the selection
|
|
1162 * event of the arrow button hide the popup.
|
|
1163 * In Windows, hiding the popup during the deactivate causes the deactivate
|
|
1164 * to be called twice and the selection event to be disappear.
|
|
1165 */
|
|
1166 if (!"carbon".equals(SWT.getPlatform())) {
|
|
1167 Point point = arrow.toControl(getDisplay().getCursorLocation());
|
|
1168 Point size = arrow.getSize();
|
|
1169 Rectangle rect = new Rectangle(0, 0, size.x, size.y);
|
|
1170 if (!rect.contains(point)) dropDown (false);
|
|
1171 } else {
|
|
1172 dropDown(false);
|
|
1173 }
|
|
1174 break;
|
|
1175 default:
|
|
1176 }
|
|
1177 }
|
|
1178 public override void redraw () {
|
|
1179 super.redraw();
|
|
1180 text.redraw();
|
|
1181 arrow.redraw();
|
|
1182 if (popup.isVisible()) list.redraw();
|
|
1183 }
|
|
1184 public override void redraw (int x, int y, int width, int height, bool all) {
|
|
1185 super.redraw(x, y, width, height, true);
|
|
1186 }
|
|
1187
|
|
1188 /**
|
|
1189 * Removes the item from the receiver's list at the given
|
|
1190 * zero-relative index.
|
|
1191 *
|
|
1192 * @param index the index for the item
|
|
1193 *
|
|
1194 * @exception IllegalArgumentException <ul>
|
|
1195 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
|
|
1196 * </ul>
|
|
1197 * @exception SWTException <ul>
|
|
1198 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1199 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1200 * </ul>
|
|
1201 */
|
|
1202 public void remove (int index) {
|
|
1203 checkWidget();
|
|
1204 list.remove (index);
|
|
1205 }
|
|
1206 /**
|
|
1207 * Removes the items from the receiver's list which are
|
|
1208 * between the given zero-relative start and end
|
|
1209 * indices (inclusive).
|
|
1210 *
|
|
1211 * @param start the start of the range
|
|
1212 * @param end the end of the range
|
|
1213 *
|
|
1214 * @exception IllegalArgumentException <ul>
|
|
1215 * <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>
|
|
1216 * </ul>
|
|
1217 * @exception SWTException <ul>
|
|
1218 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1219 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1220 * </ul>
|
|
1221 */
|
|
1222 public void remove (int start, int end) {
|
|
1223 checkWidget();
|
|
1224 list.remove (start, end);
|
|
1225 }
|
|
1226 /**
|
|
1227 * Searches the receiver's list starting at the first item
|
|
1228 * until an item is found that is equal to the argument,
|
|
1229 * and removes that item from the list.
|
|
1230 *
|
|
1231 * @param string the item to remove
|
|
1232 *
|
|
1233 * @exception IllegalArgumentException <ul>
|
|
1234 * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
|
|
1235 * </ul>
|
|
1236 * @exception SWTException <ul>
|
|
1237 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1238 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1239 * </ul>
|
|
1240 */
|
|
1241 public void remove (String string) {
|
|
1242 checkWidget();
|
|
1243 // SWT extension: allow null for zero length string
|
|
1244 //if (string is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
1245 list.remove (string);
|
|
1246 }
|
|
1247 /**
|
|
1248 * Removes all of the items from the receiver's list and clear the
|
|
1249 * contents of receiver's text field.
|
|
1250 * <p>
|
|
1251 * @exception SWTException <ul>
|
|
1252 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1253 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1254 * </ul>
|
|
1255 */
|
|
1256 public void removeAll () {
|
|
1257 checkWidget();
|
|
1258 text.setText (""); //$NON-NLS-1$
|
|
1259 list.removeAll ();
|
|
1260 }
|
|
1261 /**
|
|
1262 * Removes the listener from the collection of listeners who will
|
|
1263 * be notified when the receiver's text is modified.
|
|
1264 *
|
|
1265 * @param listener the listener which should no longer be notified
|
|
1266 *
|
|
1267 * @exception IllegalArgumentException <ul>
|
|
1268 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1269 * </ul>
|
|
1270 * @exception SWTException <ul>
|
|
1271 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1272 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1273 * </ul>
|
|
1274 *
|
|
1275 * @see ModifyListener
|
|
1276 * @see #addModifyListener
|
|
1277 */
|
|
1278 public void removeModifyListener (ModifyListener listener) {
|
|
1279 checkWidget();
|
|
1280 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
1281 removeListener(SWT.Modify, listener);
|
|
1282 }
|
|
1283 /**
|
|
1284 * Removes the listener from the collection of listeners who will
|
|
1285 * be notified when the user changes the receiver's selection.
|
|
1286 *
|
|
1287 * @param listener the listener which should no longer be notified
|
|
1288 *
|
|
1289 * @exception IllegalArgumentException <ul>
|
|
1290 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1291 * </ul>
|
|
1292 * @exception SWTException <ul>
|
|
1293 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1294 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1295 * </ul>
|
|
1296 *
|
|
1297 * @see SelectionListener
|
|
1298 * @see #addSelectionListener
|
|
1299 */
|
|
1300 public void removeSelectionListener (SelectionListener listener) {
|
|
1301 checkWidget();
|
|
1302 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
1303 removeListener(SWT.Selection, listener);
|
|
1304 removeListener(SWT.DefaultSelection,listener);
|
|
1305 }
|
|
1306 /**
|
|
1307 * Removes the listener from the collection of listeners who will
|
|
1308 * be notified when the control is verified.
|
|
1309 *
|
|
1310 * @param listener the listener which should no longer be notified
|
|
1311 *
|
|
1312 * @exception IllegalArgumentException <ul>
|
|
1313 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1314 * </ul>
|
|
1315 * @exception SWTException <ul>
|
|
1316 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1317 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1318 * </ul>
|
|
1319 *
|
|
1320 * @see VerifyListener
|
|
1321 * @see #addVerifyListener
|
|
1322 *
|
|
1323 * @since 3.3
|
|
1324 */
|
|
1325 public void removeVerifyListener (VerifyListener listener) {
|
|
1326 checkWidget();
|
|
1327 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
1328 removeListener(SWT.Verify, listener);
|
|
1329 }
|
|
1330 /**
|
|
1331 * Selects the item at the given zero-relative index in the receiver's
|
|
1332 * list. If the item at the index was already selected, it remains
|
|
1333 * selected. Indices that are out of range are ignored.
|
|
1334 *
|
|
1335 * @param index the index of the item to select
|
|
1336 *
|
|
1337 * @exception SWTException <ul>
|
|
1338 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1339 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1340 * </ul>
|
|
1341 */
|
|
1342 public void select (int index) {
|
|
1343 checkWidget();
|
|
1344 if (index is -1) {
|
|
1345 list.deselectAll ();
|
|
1346 text.setText (""); //$NON-NLS-1$
|
|
1347 return;
|
|
1348 }
|
|
1349 if (0 <= index && index < list.getItemCount()) {
|
|
1350 if (index !is getSelectionIndex()) {
|
|
1351 text.setText (list.getItem (index));
|
|
1352 text.selectAll ();
|
|
1353 list.select (index);
|
|
1354 list.showSelection ();
|
|
1355 }
|
|
1356 }
|
|
1357 }
|
|
1358 public override void setBackground (Color color) {
|
|
1359 super.setBackground(color);
|
|
1360 background = color;
|
|
1361 if (text !is null) text.setBackground(color);
|
|
1362 if (list !is null) list.setBackground(color);
|
|
1363 if (arrow !is null) arrow.setBackground(color);
|
|
1364 }
|
|
1365 /**
|
|
1366 * Sets the editable state.
|
|
1367 *
|
|
1368 * @param editable the new editable state
|
|
1369 *
|
|
1370 * @exception SWTException <ul>
|
|
1371 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1372 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1373 * </ul>
|
|
1374 *
|
|
1375 * @since 3.0
|
|
1376 */
|
|
1377 public void setEditable (bool editable) {
|
|
1378 checkWidget ();
|
|
1379 text.setEditable(editable);
|
|
1380 }
|
|
1381 public override void setEnabled (bool enabled) {
|
|
1382 super.setEnabled(enabled);
|
|
1383 if (popup !is null) popup.setVisible (false);
|
|
1384 if (text !is null) text.setEnabled(enabled);
|
|
1385 if (arrow !is null) arrow.setEnabled(enabled);
|
|
1386 }
|
|
1387 public override bool setFocus () {
|
|
1388 checkWidget();
|
|
1389 if (!isEnabled () || !isVisible ()) return false;
|
|
1390 if (isFocusControl ()) return true;
|
|
1391 return text.setFocus ();
|
|
1392 }
|
|
1393 public override void setFont (Font font) {
|
|
1394 super.setFont (font);
|
|
1395 this.font = font;
|
|
1396 text.setFont (font);
|
|
1397 list.setFont (font);
|
|
1398 internalLayout (true);
|
|
1399 }
|
|
1400 public override void setForeground (Color color) {
|
|
1401 super.setForeground(color);
|
|
1402 foreground = color;
|
|
1403 if (text !is null) text.setForeground(color);
|
|
1404 if (list !is null) list.setForeground(color);
|
|
1405 if (arrow !is null) arrow.setForeground(color);
|
|
1406 }
|
|
1407 /**
|
|
1408 * Sets the text of the item in the receiver's list at the given
|
|
1409 * zero-relative index to the string argument. This is equivalent
|
|
1410 * to <code>remove</code>'ing the old item at the index, and then
|
|
1411 * <code>add</code>'ing the new item at that index.
|
|
1412 *
|
|
1413 * @param index the index for the item
|
|
1414 * @param string the new text for the item
|
|
1415 *
|
|
1416 * @exception IllegalArgumentException <ul>
|
|
1417 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
|
|
1418 * </ul>
|
|
1419 * @exception SWTException <ul>
|
|
1420 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1421 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1422 * </ul>
|
|
1423 */
|
|
1424 public void setItem (int index, String string) {
|
|
1425 checkWidget();
|
|
1426 list.setItem (index, string);
|
|
1427 }
|
|
1428 /**
|
|
1429 * Sets the receiver's list to be the given array of items.
|
|
1430 *
|
|
1431 * @param items the array of items
|
|
1432 *
|
|
1433 * @exception IllegalArgumentException <ul>
|
|
1434 * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
|
|
1435 * </ul>
|
|
1436 * @exception SWTException <ul>
|
|
1437 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1438 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1439 * </ul>
|
|
1440 */
|
|
1441 public void setItems (String [] items) {
|
|
1442 checkWidget ();
|
|
1443 list.setItems (items);
|
|
1444 if (!text.getEditable ()) text.setText (""); //$NON-NLS-1$
|
|
1445 }
|
|
1446 /**
|
|
1447 * Sets the layout which is associated with the receiver to be
|
|
1448 * the argument which may be null.
|
|
1449 * <p>
|
|
1450 * Note: No Layout can be set on this Control because it already
|
|
1451 * manages the size and position of its children.
|
|
1452 * </p>
|
|
1453 *
|
|
1454 * @param layout the receiver's new layout or null
|
|
1455 *
|
|
1456 * @exception SWTException <ul>
|
|
1457 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1458 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1459 * </ul>
|
|
1460 */
|
|
1461 public override void setLayout (Layout layout) {
|
|
1462 checkWidget ();
|
|
1463 return;
|
|
1464 }
|
|
1465 /**
|
|
1466 * Marks the receiver's list as visible if the argument is <code>true</code>,
|
|
1467 * and marks it invisible otherwise.
|
|
1468 * <p>
|
|
1469 * If one of the receiver's ancestors is not visible or some
|
|
1470 * other condition makes the receiver not visible, marking
|
|
1471 * it visible may not actually cause it to be displayed.
|
|
1472 * </p>
|
|
1473 *
|
|
1474 * @param visible the new visibility state
|
|
1475 *
|
|
1476 * @exception SWTException <ul>
|
|
1477 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1478 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1479 * </ul>
|
|
1480 *
|
|
1481 * @since 3.4
|
|
1482 */
|
|
1483 public void setListVisible (bool visible) {
|
|
1484 checkWidget ();
|
|
1485 dropDown(visible);
|
|
1486 }
|
|
1487 public override void setMenu(Menu menu) {
|
|
1488 text.setMenu(menu);
|
|
1489 }
|
|
1490 /**
|
|
1491 * Sets the selection in the receiver's text field to the
|
|
1492 * range specified by the argument whose x coordinate is the
|
|
1493 * start of the selection and whose y coordinate is the end
|
|
1494 * of the selection.
|
|
1495 *
|
|
1496 * @param selection a point representing the new selection start and end
|
|
1497 *
|
|
1498 * @exception IllegalArgumentException <ul>
|
|
1499 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
1500 * </ul>
|
|
1501 * @exception SWTException <ul>
|
|
1502 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1503 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1504 * </ul>
|
|
1505 */
|
|
1506 public void setSelection (Point selection) {
|
|
1507 checkWidget();
|
|
1508 if (selection is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
1509 text.setSelection (selection.x, selection.y);
|
|
1510 }
|
|
1511
|
|
1512 /**
|
|
1513 * Sets the contents of the receiver's text field to the
|
|
1514 * given string.
|
|
1515 * <p>
|
|
1516 * Note: The text field in a <code>Combo</code> is typically
|
|
1517 * only capable of displaying a single line of text. Thus,
|
|
1518 * setting the text to a string containing line breaks or
|
|
1519 * other special characters will probably cause it to
|
|
1520 * display incorrectly.
|
|
1521 * </p>
|
|
1522 *
|
|
1523 * @param string the new text
|
|
1524 *
|
|
1525 * @exception SWTException <ul>
|
|
1526 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1527 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1528 * </ul>
|
|
1529 */
|
|
1530 public void setText (String string) {
|
|
1531 checkWidget();
|
|
1532 // SWT extension: allow null for zero length string
|
|
1533 //if (string is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
1534 int index = list.indexOf (string);
|
|
1535 if (index is -1) {
|
|
1536 list.deselectAll ();
|
|
1537 text.setText (string);
|
|
1538 return;
|
|
1539 }
|
|
1540 text.setText (string);
|
|
1541 text.selectAll ();
|
|
1542 list.setSelection (index);
|
|
1543 list.showSelection ();
|
|
1544 }
|
|
1545 /**
|
|
1546 * Sets the maximum number of characters that the receiver's
|
|
1547 * text field is capable of holding to be the argument.
|
|
1548 *
|
|
1549 * @param limit new text limit
|
|
1550 *
|
|
1551 * @exception IllegalArgumentException <ul>
|
|
1552 * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
|
|
1553 * </ul>
|
|
1554 * @exception SWTException <ul>
|
|
1555 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1556 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1557 * </ul>
|
|
1558 */
|
|
1559 public void setTextLimit (int limit) {
|
|
1560 checkWidget();
|
|
1561 text.setTextLimit (limit);
|
|
1562 }
|
|
1563
|
|
1564 public override void setToolTipText (String string) {
|
|
1565 checkWidget();
|
|
1566 super.setToolTipText(string);
|
|
1567 arrow.setToolTipText (string);
|
|
1568 text.setToolTipText (string);
|
|
1569 }
|
|
1570
|
|
1571 public override void setVisible (bool visible) {
|
|
1572 super.setVisible(visible);
|
|
1573 /*
|
|
1574 * At this point the widget may have been disposed in a FocusOut event.
|
|
1575 * If so then do not continue.
|
|
1576 */
|
|
1577 if (isDisposed ()) return;
|
|
1578 // TEMPORARY CODE
|
|
1579 if (popup is null || popup.isDisposed ()) return;
|
|
1580 if (!visible) popup.setVisible (false);
|
|
1581 }
|
|
1582 /**
|
|
1583 * Sets the number of items that are visible in the drop
|
|
1584 * down portion of the receiver's list.
|
|
1585 *
|
|
1586 * @param count the new number of items to be visible
|
|
1587 *
|
|
1588 * @exception SWTException <ul>
|
|
1589 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1590 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1591 * </ul>
|
|
1592 *
|
|
1593 * @since 3.0
|
|
1594 */
|
|
1595 public void setVisibleItemCount (int count) {
|
|
1596 checkWidget ();
|
|
1597 if (count < 0) return;
|
|
1598 visibleItemCount = count;
|
|
1599 }
|
|
1600 String stripMnemonic (String string) {
|
|
1601 int index = 0;
|
|
1602 int length_ = string.length;
|
|
1603 do {
|
|
1604 while ((index < length_) && (string[index] !is '&')) index++;
|
|
1605 if (++index >= length_) return string;
|
|
1606 if (string[index] !is '&') {
|
|
1607 return string[0 .. index-1] ~ string[index .. length_];
|
|
1608 }
|
|
1609 index++;
|
|
1610 } while (index < length_);
|
|
1611 return string;
|
|
1612 }
|
|
1613 void textEvent (Event event) {
|
|
1614 switch (event.type) {
|
|
1615 case SWT.FocusIn: {
|
|
1616 handleFocus (SWT.FocusIn);
|
|
1617 break;
|
|
1618 }
|
|
1619 case SWT.DefaultSelection: {
|
|
1620 dropDown (false);
|
|
1621 Event e = new Event ();
|
|
1622 e.time = event.time;
|
|
1623 e.stateMask = event.stateMask;
|
|
1624 notifyListeners (SWT.DefaultSelection, e);
|
|
1625 break;
|
|
1626 }
|
|
1627 case SWT.KeyDown: {
|
|
1628 Event keyEvent = new Event ();
|
|
1629 keyEvent.time = event.time;
|
|
1630 keyEvent.character = event.character;
|
|
1631 keyEvent.keyCode = event.keyCode;
|
|
1632 keyEvent.stateMask = event.stateMask;
|
|
1633 notifyListeners (SWT.KeyDown, keyEvent);
|
|
1634 if (isDisposed ()) break;
|
|
1635 event.doit = keyEvent.doit;
|
|
1636 if (!event.doit) break;
|
|
1637 if (event.keyCode is SWT.ARROW_UP || event.keyCode is SWT.ARROW_DOWN) {
|
|
1638 event.doit = false;
|
|
1639 if ((event.stateMask & SWT.ALT) !is 0) {
|
|
1640 bool dropped = isDropped ();
|
|
1641 text.selectAll ();
|
|
1642 if (!dropped) setFocus ();
|
|
1643 dropDown (!dropped);
|
|
1644 break;
|
|
1645 }
|
|
1646
|
|
1647 int oldIndex = getSelectionIndex ();
|
|
1648 if (event.keyCode is SWT.ARROW_UP) {
|
|
1649 select (Math.max (oldIndex - 1, 0));
|
|
1650 } else {
|
|
1651 select (Math.min (oldIndex + 1, getItemCount () - 1));
|
|
1652 }
|
|
1653 if (oldIndex !is getSelectionIndex ()) {
|
|
1654 Event e = new Event();
|
|
1655 e.time = event.time;
|
|
1656 e.stateMask = event.stateMask;
|
|
1657 notifyListeners (SWT.Selection, e);
|
|
1658 }
|
|
1659 if (isDisposed ()) break;
|
|
1660 }
|
|
1661
|
|
1662 // Further work : Need to add support for incremental search in
|
|
1663 // pop up list as characters typed in text widget
|
|
1664 break;
|
|
1665 }
|
|
1666 case SWT.KeyUp: {
|
|
1667 Event e = new Event ();
|
|
1668 e.time = event.time;
|
|
1669 e.character = event.character;
|
|
1670 e.keyCode = event.keyCode;
|
|
1671 e.stateMask = event.stateMask;
|
|
1672 notifyListeners (SWT.KeyUp, e);
|
|
1673 event.doit = e.doit;
|
|
1674 break;
|
|
1675 }
|
|
1676 case SWT.MenuDetect: {
|
|
1677 Event e = new Event ();
|
|
1678 e.time = event.time;
|
|
1679 notifyListeners (SWT.MenuDetect, e);
|
|
1680 break;
|
|
1681 }
|
|
1682 case SWT.Modify: {
|
|
1683 list.deselectAll ();
|
|
1684 Event e = new Event ();
|
|
1685 e.time = event.time;
|
|
1686 notifyListeners (SWT.Modify, e);
|
|
1687 break;
|
|
1688 }
|
|
1689 case SWT.MouseDown: {
|
|
1690 Event mouseEvent = new Event ();
|
|
1691 mouseEvent.button = event.button;
|
|
1692 mouseEvent.count = event.count;
|
|
1693 mouseEvent.stateMask = event.stateMask;
|
|
1694 mouseEvent.time = event.time;
|
|
1695 mouseEvent.x = event.x; mouseEvent.y = event.y;
|
|
1696 notifyListeners (SWT.MouseDown, mouseEvent);
|
|
1697 if (isDisposed ()) break;
|
|
1698 event.doit = mouseEvent.doit;
|
|
1699 if (!event.doit) break;
|
|
1700 if (event.button !is 1) return;
|
|
1701 if (text.getEditable ()) return;
|
|
1702 bool dropped = isDropped ();
|
|
1703 text.selectAll ();
|
|
1704 if (!dropped) setFocus ();
|
|
1705 dropDown (!dropped);
|
|
1706 break;
|
|
1707 }
|
|
1708 case SWT.MouseUp: {
|
|
1709 Event mouseEvent = new Event ();
|
|
1710 mouseEvent.button = event.button;
|
|
1711 mouseEvent.count = event.count;
|
|
1712 mouseEvent.stateMask = event.stateMask;
|
|
1713 mouseEvent.time = event.time;
|
|
1714 mouseEvent.x = event.x; mouseEvent.y = event.y;
|
|
1715 notifyListeners (SWT.MouseUp, mouseEvent);
|
|
1716 if (isDisposed ()) break;
|
|
1717 event.doit = mouseEvent.doit;
|
|
1718 if (!event.doit) break;
|
|
1719 if (event.button !is 1) return;
|
|
1720 if (text.getEditable ()) return;
|
|
1721 text.selectAll ();
|
|
1722 break;
|
|
1723 }
|
|
1724 case SWT.MouseDoubleClick: {
|
|
1725 Event mouseEvent = new Event ();
|
|
1726 mouseEvent.button = event.button;
|
|
1727 mouseEvent.count = event.count;
|
|
1728 mouseEvent.stateMask = event.stateMask;
|
|
1729 mouseEvent.time = event.time;
|
|
1730 mouseEvent.x = event.x; mouseEvent.y = event.y;
|
|
1731 notifyListeners (SWT.MouseDoubleClick, mouseEvent);
|
|
1732 break;
|
|
1733 }
|
|
1734 case SWT.MouseWheel: {
|
|
1735 Event keyEvent = new Event ();
|
|
1736 keyEvent.time = event.time;
|
|
1737 keyEvent.keyCode = event.count > 0 ? SWT.ARROW_UP : SWT.ARROW_DOWN;
|
|
1738 keyEvent.stateMask = event.stateMask;
|
|
1739 notifyListeners (SWT.KeyDown, keyEvent);
|
|
1740 if (isDisposed ()) break;
|
|
1741 event.doit = keyEvent.doit;
|
|
1742 if (!event.doit) break;
|
|
1743 if (event.count !is 0) {
|
|
1744 event.doit = false;
|
|
1745 int oldIndex = getSelectionIndex ();
|
|
1746 if (event.count > 0) {
|
|
1747 select (Math.max (oldIndex - 1, 0));
|
|
1748 } else {
|
|
1749 select (Math.min (oldIndex + 1, getItemCount () - 1));
|
|
1750 }
|
|
1751 if (oldIndex !is getSelectionIndex ()) {
|
|
1752 Event e = new Event();
|
|
1753 e.time = event.time;
|
|
1754 e.stateMask = event.stateMask;
|
|
1755 notifyListeners (SWT.Selection, e);
|
|
1756 }
|
|
1757 if (isDisposed ()) break;
|
|
1758 }
|
|
1759 break;
|
|
1760 }
|
|
1761 case SWT.Traverse: {
|
|
1762 switch (event.detail) {
|
|
1763 case SWT.TRAVERSE_ARROW_PREVIOUS:
|
|
1764 case SWT.TRAVERSE_ARROW_NEXT:
|
|
1765 // The enter causes default selection and
|
|
1766 // the arrow keys are used to manipulate the list contents so
|
|
1767 // do not use them for traversal.
|
|
1768 event.doit = false;
|
|
1769 break;
|
|
1770 case SWT.TRAVERSE_TAB_PREVIOUS:
|
|
1771 event.doit = traverse(SWT.TRAVERSE_TAB_PREVIOUS);
|
|
1772 event.detail = SWT.TRAVERSE_NONE;
|
|
1773 return;
|
|
1774 default:
|
|
1775 }
|
|
1776 Event e = new Event ();
|
|
1777 e.time = event.time;
|
|
1778 e.detail = event.detail;
|
|
1779 e.doit = event.doit;
|
|
1780 e.character = event.character;
|
|
1781 e.keyCode = event.keyCode;
|
|
1782 notifyListeners (SWT.Traverse, e);
|
|
1783 event.doit = e.doit;
|
|
1784 event.detail = e.detail;
|
|
1785 break;
|
|
1786 }
|
|
1787 case SWT.Verify: {
|
|
1788 Event e = new Event ();
|
|
1789 e.text = event.text;
|
|
1790 e.start = event.start;
|
|
1791 e.end = event.end;
|
|
1792 e.character = event.character;
|
|
1793 e.keyCode = event.keyCode;
|
|
1794 e.stateMask = event.stateMask;
|
|
1795 notifyListeners (SWT.Verify, e);
|
|
1796 event.doit = e.doit;
|
|
1797 break;
|
|
1798 }
|
|
1799 default:
|
|
1800 }
|
|
1801 }
|
|
1802 }
|