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