KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > widgets > Text


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  *******************************************************************************/

11 package org.eclipse.swt.widgets;
12
13
14 import org.eclipse.swt.internal.win32.*;
15 import org.eclipse.swt.*;
16 import org.eclipse.swt.graphics.*;
17 import org.eclipse.swt.events.*;
18
19 /**
20  * Instances of this class are selectable user interface
21  * objects that allow the user to enter and modify text.
22  * <p>
23  * <dl>
24  * <dt><b>Styles:</b></dt>
25  * <dd>CANCEL, CENTER, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
26  * <dt><b>Events:</b></dt>
27  * <dd>DefaultSelection, Modify, Verify</dd>
28  * </dl>
29  * <p>
30  * Note: Only one of the styles MULTI and SINGLE may be specified,
31  * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
32  * </p><p>
33  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
34  * </p>
35  */

36 public class Text extends Scrollable {
37     int tabs, oldStart, oldEnd;
38     boolean doubleClick, ignoreModify, ignoreVerify, ignoreCharacter;
39     String JavaDoc message;
40     
41     /**
42     * The maximum number of characters that can be entered
43     * into a text widget.
44     * <p>
45     * Note that this value is platform dependent, based upon
46     * the native widget implementation.
47     * </p>
48     */

49     public static final int LIMIT;
50     
51     /**
52     * The delimiter used by multi-line text widgets. When text
53     * is queried and from the widget, it will be delimited using
54     * this delimiter.
55     */

56     public static final String JavaDoc DELIMITER;
57     
58     /*
59     * This code is intentionally commented.
60     */

61 // static final char PASSWORD;
62

63     /*
64     * These values can be different on different platforms.
65     * Therefore they are not initialized in the declaration
66     * to stop the compiler from inlining.
67     */

68     static {
69         LIMIT = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF;
70         DELIMITER = "\r\n";
71     }
72     
73     static final int EditProc;
74     static final TCHAR EditClass = new TCHAR (0, "EDIT", true);
75     static {
76         WNDCLASS lpWndClass = new WNDCLASS ();
77         OS.GetClassInfo (0, EditClass, lpWndClass);
78         EditProc = lpWndClass.lpfnWndProc;
79         /*
80         * This code is intentionally commented.
81         */

82 // int hwndText = OS.CreateWindowEx (0,
83
// EditClass,
84
// null,
85
// OS.WS_OVERLAPPED | OS.ES_PASSWORD,
86
// 0, 0, 0, 0,
87
// 0,
88
// 0,
89
// OS.GetModuleHandle (null),
90
// null);
91
// char echo = (char) OS.SendMessage (hwndText, OS.EM_GETPASSWORDCHAR, 0, 0);
92
// OS.DestroyWindow (hwndText);
93
// PASSWORD = echo != 0 ? echo : '*';
94
}
95
96 /**
97  * Constructs a new instance of this class given its parent
98  * and a style value describing its behavior and appearance.
99  * <p>
100  * The style value is either one of the style constants defined in
101  * class <code>SWT</code> which is applicable to instances of this
102  * class, or must be built by <em>bitwise OR</em>'ing together
103  * (that is, using the <code>int</code> "|" operator) two or more
104  * of those <code>SWT</code> style constants. The class description
105  * lists the style constants that are applicable to the class.
106  * Style bits are also inherited from superclasses.
107  * </p>
108  *
109  * @param parent a composite control which will be the parent of the new instance (cannot be null)
110  * @param style the style of control to construct
111  *
112  * @exception IllegalArgumentException <ul>
113  * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
114  * </ul>
115  * @exception SWTException <ul>
116  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
117  * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
118  * </ul>
119  *
120  * @see SWT#SINGLE
121  * @see SWT#MULTI
122  * @see SWT#READ_ONLY
123  * @see SWT#WRAP
124  * @see Widget#checkSubclass
125  * @see Widget#getStyle
126  */

127 public Text (Composite parent, int style) {
128     super (parent, checkStyle (style));
129 }
130
131 int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
132     if (handle == 0) return 0;
133     return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam);
134 }
135
136 void createHandle () {
137     super.createHandle ();
138     OS.SendMessage (handle, OS.EM_LIMITTEXT, 0, 0);
139     if ((style & SWT.READ_ONLY) != 0) {
140         if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
141             state |= THEME_BACKGROUND;
142         }
143     }
144 }
145
146 /**
147  * Adds the listener to the collection of listeners who will
148  * be notified when the receiver's text is modified, by sending
149  * it one of the messages defined in the <code>ModifyListener</code>
150  * interface.
151  *
152  * @param listener the listener which should be notified
153  *
154  * @exception IllegalArgumentException <ul>
155  * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
156  * </ul>
157  * @exception SWTException <ul>
158  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
159  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
160  * </ul>
161  *
162  * @see ModifyListener
163  * @see #removeModifyListener
164  */

165 public void addModifyListener (ModifyListener listener) {
166     checkWidget ();
167     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
168     TypedListener typedListener = new TypedListener (listener);
169     addListener (SWT.Modify, typedListener);
170 }
171
172 /**
173  * Adds the listener to the collection of listeners who will
174  * be notified when the control is selected by the user, by sending
175  * it one of the messages defined in the <code>SelectionListener</code>
176  * interface.
177  * <p>
178  * <code>widgetSelected</code> is not called for texts.
179  * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
180  * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
181  * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
182  * </p>
183  *
184  * @param listener the listener which should be notified when the control is selected by the user
185  *
186  * @exception IllegalArgumentException <ul>
187  * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
188  * </ul>
189  * @exception SWTException <ul>
190  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
191  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
192  * </ul>
193  *
194  * @see SelectionListener
195  * @see #removeSelectionListener
196  * @see SelectionEvent
197  */

198 public void addSelectionListener (SelectionListener listener) {
199     checkWidget ();
200     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
201     TypedListener typedListener = new TypedListener (listener);
202     addListener (SWT.Selection,typedListener);
203     addListener (SWT.DefaultSelection,typedListener);
204 }
205
206 /**
207  * Adds the listener to the collection of listeners who will
208  * be notified when the receiver's text is verified, by sending
209  * it one of the messages defined in the <code>VerifyListener</code>
210  * interface.
211  *
212  * @param listener the listener which should be notified
213  *
214  * @exception IllegalArgumentException <ul>
215  * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
216  * </ul>
217  * @exception SWTException <ul>
218  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
219  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
220  * </ul>
221  *
222  * @see VerifyListener
223  * @see #removeVerifyListener
224  */

225 public void addVerifyListener (VerifyListener listener) {
226     checkWidget ();
227     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
228     TypedListener typedListener = new TypedListener (listener);
229     addListener (SWT.Verify, typedListener);
230 }
231
232 /**
233  * Appends a string.
234  * <p>
235  * The new text is appended to the text at
236  * the end of the widget.
237  * </p>
238  *
239  * @param string the string to be appended
240  *
241  * @exception IllegalArgumentException <ul>
242  * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
243  * </ul>
244  * @exception SWTException <ul>
245  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
246  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
247  * </ul>
248  */

249 public void append (String JavaDoc string) {
250     checkWidget ();
251     if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
252     string = Display.withCrLf (string);
253     int length = OS.GetWindowTextLength (handle);
254     if (hooks (SWT.Verify) || filters (SWT.Verify)) {
255         string = verifyText (string, length, length, null);
256         if (string == null) return;
257     }
258     OS.SendMessage (handle, OS.EM_SETSEL, length, length);
259     TCHAR buffer = new TCHAR (getCodePage (), string, true);
260     /*
261     * Feature in Windows. When an edit control with ES_MULTILINE
262     * style that does not have the WS_VSCROLL style is full (i.e.
263     * there is no space at the end to draw any more characters),
264     * EM_REPLACESEL sends a WM_CHAR with a backspace character
265     * to remove any further text that is added. This is an
266     * implementation detail of the edit control that is unexpected
267     * and can cause endless recursion when EM_REPLACESEL is sent
268     * from a WM_CHAR handler. The fix is to ignore calling the
269     * handler from WM_CHAR.
270     */

271     ignoreCharacter = true;
272     OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
273     ignoreCharacter = false;
274     OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
275 }
276
277 static int checkStyle (int style) {
278     if ((style & SWT.SEARCH) != 0) {
279         style |= SWT.SINGLE | SWT.BORDER;
280         style &= ~SWT.PASSWORD;
281     }
282     if (OS.COMCTL32_MAJOR < 6) style &= ~SWT.SEARCH;
283     if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
284         style &= ~SWT.MULTI;
285     }
286     style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
287     if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
288     if ((style & SWT.WRAP) != 0) {
289         style |= SWT.MULTI;
290         style &= ~SWT.H_SCROLL;
291     }
292     if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
293     if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
294     if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
295     return style | SWT.SINGLE;
296 }
297
298 /**
299  * Clears the selection.
300  *
301  * @exception SWTException <ul>
302  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
303  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
304  * </ul>
305  */

306 public void clearSelection () {
307     checkWidget ();
308     if (OS.IsWinCE) {
309         /*
310         * Bug in WinCE. Calling EM_SETSEL with -1 and 0 is equivalent
311         * to calling EM_SETSEL with 0 and -1. It causes the entire
312         * text to be selected instead of clearing the selection. The
313         * fix is to set the start of the selection to the end of the
314         * current selection.
315         */

316         int [] end = new int [1];
317         OS.SendMessage (handle, OS.EM_GETSEL, (int []) null, end);
318         OS.SendMessage (handle, OS.EM_SETSEL, end [0], end [0]);
319     } else {
320         OS.SendMessage (handle, OS.EM_SETSEL, -1, 0);
321     }
322 }
323
324 public Point computeSize (int wHint, int hHint, boolean changed) {
325     checkWidget ();
326     int height = 0, width = 0;
327     if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
328         int newFont, oldFont = 0;
329         int hDC = OS.GetDC (handle);
330         newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
331         if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
332         TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
333         OS.GetTextMetrics (hDC, tm);
334         int count = (style & SWT.SINGLE) != 0 ? 1 : OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
335         height = count * tm.tmHeight;
336         RECT rect = new RECT ();
337         int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_NOPREFIX;
338         boolean wrap = (style & SWT.MULTI) != 0 && (style & SWT.WRAP) != 0;
339         if (wrap && wHint != SWT.DEFAULT) {
340             flags |= OS.DT_WORDBREAK;
341             rect.right = wHint;
342         }
343         int length = OS.GetWindowTextLength (handle);
344         if (length != 0) {
345             TCHAR buffer = new TCHAR (getCodePage (), length + 1);
346             OS.GetWindowText (handle, buffer, length + 1);
347             OS.DrawText (hDC, buffer, length, rect, flags);
348             width = rect.right - rect.left;
349         }
350         //This code is intentionally commented
351
// if (OS.COMCTL32_MAJOR >= 6) {
352
// if ((style & SWT.SEARCH) != 0) {
353
// length = message.length ();
354
// if (length != 0) {
355
// char [] buffer = new char [length + 1];
356
// message.getChars (0, length, buffer, 0);
357
// SIZE size = new SIZE ();
358
// OS.GetTextExtentPoint32W (hDC, buffer, length, size);
359
// width = Math.max (width, size.cx);
360
// }
361
// }
362
// }
363
if (wrap && hHint == SWT.DEFAULT) {
364             int newHeight = rect.bottom - rect.top;
365             if (newHeight != 0) height = newHeight;
366         }
367         if (newFont != 0) OS.SelectObject (hDC, oldFont);
368         OS.ReleaseDC (handle, hDC);
369     }
370     if (width == 0) width = DEFAULT_WIDTH;
371     if (height == 0) height = DEFAULT_HEIGHT;
372     if (wHint != SWT.DEFAULT) width = wHint;
373     if (hHint != SWT.DEFAULT) height = hHint;
374     Rectangle trim = computeTrim (0, 0, width, height);
375     return new Point (trim.width, trim.height);
376 }
377
378 public Rectangle computeTrim (int x, int y, int width, int height) {
379     checkWidget ();
380     Rectangle rect = super.computeTrim (x, y, width, height);
381     /*
382     * The preferred height of a single-line text widget
383     * has been hand-crafted to be the same height as
384     * the single-line text widget in an editable combo
385     * box.
386     */

387     int margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0);
388     rect.x -= margins & 0xFFFF;
389     rect.width += (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
390     if ((style & SWT.H_SCROLL) != 0) rect.width++;
391     if ((style & SWT.BORDER) != 0) {
392         rect.x -= 1;
393         rect.y -= 1;
394         rect.width += 2;
395         rect.height += 2;
396     }
397     return rect;
398 }
399
400 /**
401  * Copies the selected text.
402  * <p>
403  * The current selection is copied to the clipboard.
404  * </p>
405  *
406  * @exception SWTException <ul>
407  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
408  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
409  * </ul>
410  */

411 public void copy () {
412     checkWidget ();
413     OS.SendMessage (handle, OS.WM_COPY, 0, 0);
414 }
415
416 void createWidget () {
417     super.createWidget ();
418     message = "";
419     doubleClick = true;
420     setTabStops (tabs = 8);
421     fixAlignment ();
422 }
423
424 /**
425  * Cuts the selected text.
426  * <p>
427  * The current selection is first copied to the
428  * clipboard and then deleted from the widget.
429  * </p>
430  *
431  * @exception SWTException <ul>
432  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
433  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
434  * </ul>
435  */

436 public void cut () {
437     checkWidget ();
438     if ((style & SWT.READ_ONLY) != 0) return;
439     OS.SendMessage (handle, OS.WM_CUT, 0, 0);
440 }
441
442 int defaultBackground () {
443     int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
444     return OS.GetSysColor ((bits & OS.ES_READONLY) != 0 ? OS.COLOR_3DFACE : OS.COLOR_WINDOW);
445 }
446
447 boolean dragDetect (int hwnd, int x, int y, boolean filter, boolean [] detect, boolean [] consume) {
448     if (filter) {
449         int [] start = new int [1], end = new int [1];
450         OS.SendMessage (handle, OS.EM_GETSEL, start, end);
451         if (start [0] != end [0]) {
452             int lParam = (x & 0xFFFF) | ((y << 16) & 0xFFFF0000);
453             int position = OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam) & 0xFFFF;
454             if (start [0] <= position && position < end [0]) {
455                 if (super.dragDetect (hwnd, x, y, filter, detect, consume)) {
456                     if (consume != null) consume [0] = true;
457                     return true;
458                 }
459             }
460         }
461         return false;
462     }
463     return super.dragDetect (hwnd, x, y, filter, detect, consume);
464 }
465
466 void fixAlignment () {
467     /*
468     * Feature in Windows. When the edit control is not
469     * mirrored, it uses WS_EX_RIGHT, WS_EX_RTLREADING and
470     * WS_EX_LEFTSCROLLBAR to give the control a right to
471     * left appearance. This causes the control to be lead
472     * aligned no matter what alignment was specified by
473     * the programmer. For example, setting ES_RIGHT and
474     * WS_EX_LAYOUTRTL should cause the contents of the
475     * control to be left (trail) aligned in a mirrored world.
476     * When the orientation is changed by the user or
477     * specified by the programmer, WS_EX_RIGHT conflicts
478     * with the mirrored alignment. The fix is to clear
479     * or set WS_EX_RIGHT to achieve the correct alignment
480     * according to the orientation and mirroring.
481     */

482     if ((style & SWT.MIRRORED) != 0) return;
483     int bits1 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
484     int bits2 = OS.GetWindowLong (handle, OS.GWL_STYLE);
485     if ((style & SWT.LEFT_TO_RIGHT) != 0) {
486         /*
487         * Bug in Windows 98. When the edit control is created
488         * with the style ES_RIGHT it automatically sets the
489         * WS_EX_LEFTSCROLLBAR bit. The fix is to clear the
490         * bit when the orientation of the control is left
491         * to right.
492         */

493         bits1 &= ~OS.WS_EX_LEFTSCROLLBAR;
494         if ((style & SWT.RIGHT) != 0) {
495             bits1 |= OS.WS_EX_RIGHT;
496             bits2 |= OS.ES_RIGHT;
497         }
498         if ((style & SWT.LEFT) != 0) {
499             bits1 &= ~OS.WS_EX_RIGHT;
500             bits2 &= ~OS.ES_RIGHT;
501         }
502     } else {
503         if ((style & SWT.RIGHT) != 0) {
504             bits1 &= ~OS.WS_EX_RIGHT;
505             bits2 &= ~OS.ES_RIGHT;
506         }
507         if ((style & SWT.LEFT) != 0) {
508             bits1 |= OS.WS_EX_RIGHT;
509             bits2 |= OS.ES_RIGHT;
510         }
511     }
512     if ((style & SWT.CENTER) != 0) {
513         bits2 |= OS.ES_CENTER;
514     }
515     OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits1);
516     OS.SetWindowLong (handle, OS.GWL_STYLE, bits2);
517 }
518
519 public int getBorderWidth () {
520     checkWidget ();
521     /*
522     * Feature in Windows 2000 and XP. Despite the fact that WS_BORDER
523     * is set when the edit control is created, the style bit is cleared.
524     * The fix is to avoid the check for WS_BORDER and use the SWT widget
525     * style bits instead.
526     */

527 // if ((style & SWT.BORDER) != 0 && (style & SWT.FLAT) != 0) {
528
// return OS.GetSystemMetrics (OS.SM_CXBORDER);
529
// }
530
return super.getBorderWidth ();
531 }
532
533 /**
534  * Returns the line number of the caret.
535  * <p>
536  * The line number of the caret is returned.
537  * </p>
538  *
539  * @return the line number
540  *
541  * @exception SWTException <ul>
542  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
543  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
544  * </ul>
545  */

546 public int getCaretLineNumber () {
547     checkWidget ();
548     return OS.SendMessage (handle, OS.EM_LINEFROMCHAR, -1, 0);
549 }
550
551 /**
552  * Returns a point describing the receiver's location relative
553  * to its parent (or its display if its parent is null).
554  * <p>
555  * The location of the caret is returned.
556  * </p>
557  *
558  * @return a point, the location of the caret
559  *
560  * @exception SWTException <ul>
561  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
562  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
563  * </ul>
564  */

565 public Point getCaretLocation () {
566     checkWidget ();
567     /*
568     * Bug in Windows. For some reason, Windows is unable
569     * to return the pixel coordinates of the last character
570     * in the widget. The fix is to temporarily insert a
571     * space, query the coordinates and delete the space.
572     * The selection is always an i-beam in this case because
573     * this is the only time the start of the selection can
574     * be equal to the last character position in the widget.
575     * If EM_POSFROMCHAR fails for any other reason, return
576     * pixel coordinates (0,0).
577     */

578     int position = getCaretPosition ();
579     int caretPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, position, 0);
580     if (caretPos == -1) {
581         caretPos = 0;
582         if (position >= OS.GetWindowTextLength (handle)) {
583             int cp = getCodePage ();
584             int [] start = new int [1], end = new int [1];
585             OS.SendMessage (handle, OS.EM_GETSEL, start, end);
586             OS.SendMessage (handle, OS.EM_SETSEL, position, position);
587             /*
588             * Feature in Windows. When an edit control with ES_MULTILINE
589             * style that does not have the WS_VSCROLL style is full (i.e.
590             * there is no space at the end to draw any more characters),
591             * EM_REPLACESEL sends a WM_CHAR with a backspace character
592             * to remove any further text that is added. This is an
593             * implementation detail of the edit control that is unexpected
594             * and can cause endless recursion when EM_REPLACESEL is sent
595             * from a WM_CHAR handler. The fix is to ignore calling the
596             * handler from WM_CHAR.
597             */

598             ignoreCharacter = ignoreModify = true;
599             OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true));
600             caretPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, position, 0);
601             OS.SendMessage (handle, OS.EM_SETSEL, position, position + 1);
602             OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, "", true));
603             ignoreCharacter = ignoreModify = false;
604             OS.SendMessage (handle, OS.EM_SETSEL, start [0], start [0]);
605             OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
606         }
607     }
608     return new Point ((short) (caretPos & 0xFFFF), (short) (caretPos >> 16));
609 }
610
611 /**
612  * Returns the character position of the caret.
613  * <p>
614  * Indexing is zero based.
615  * </p>
616  *
617  * @return the position of the caret
618  *
619  * @exception SWTException <ul>
620  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
621  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
622  * </ul>
623  */

624 public int getCaretPosition () {
625     checkWidget ();
626     int [] start = new int [1], end = new int [1];
627     OS.SendMessage (handle, OS.EM_GETSEL, start, end);
628     /*
629     * In Windows, there is no API to get the position of the caret
630     * when the selection is not an i-beam. The best that can be done
631     * is to query the pixel position of the current caret and compare
632     * it to the pixel position of the start and end of the selection.
633     *
634     * NOTE: This does not work when the i-beam belongs to another
635     * control. In this case, guess that the i-beam is at the start
636     * of the selection.
637     */

638     int caret = start [0];
639     if (start [0] != end [0]) {
640         int startLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0);
641         int endLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0);
642         if (startLine == endLine) {
643             if (!OS.IsWinCE) {
644                 int idThread = OS.GetWindowThreadProcessId (handle, null);
645                 GUITHREADINFO lpgui = new GUITHREADINFO ();
646                 lpgui.cbSize = GUITHREADINFO.sizeof;
647                 if (OS.GetGUIThreadInfo (idThread, lpgui)) {
648                     if (lpgui.hwndCaret == handle || lpgui.hwndCaret == 0) {
649                         POINT ptCurrentPos = new POINT ();
650                         if (OS.GetCaretPos (ptCurrentPos)) {
651                             int endPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, end [0], 0);
652                             if (endPos == -1) {
653                                 int startPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
654                                 int startX = (short) (startPos & 0xFFFF);
655                                 if (ptCurrentPos.x > startX) caret = end [0];
656                             } else {
657                                 int endX = (short) (endPos & 0xFFFF);
658                                 if (ptCurrentPos.x >= endX) caret = end [0];
659                             }
660                         }
661                     }
662                 }
663             }
664         } else {
665             int caretPos = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
666             int caretLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, caretPos, 0);
667             if (caretLine == endLine) caret = end [0];
668         }
669     }
670     if (!OS.IsUnicode && OS.IsDBLocale) caret = mbcsToWcsPos (caret);
671     return caret;
672 }
673
674 /**
675  * Returns the number of characters.
676  *
677  * @return number of characters in the widget
678  *
679  * @exception SWTException <ul>
680  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
681  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
682  * </ul>
683  */

684 public int getCharCount () {
685     checkWidget ();
686     int length = OS.GetWindowTextLength (handle);
687     if (!OS.IsUnicode && OS.IsDBLocale) length = mbcsToWcsPos (length);
688     return length;
689 }
690
691 /**
692  * Returns the double click enabled flag.
693  * <p>
694  * The double click flag enables or disables the
695  * default action of the text widget when the user
696  * double clicks.
697  * </p>
698  *
699  * @return whether or not double click is enabled
700  *
701  * @exception SWTException <ul>
702  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
703  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
704  * </ul>
705  */

706 public boolean getDoubleClickEnabled () {
707     checkWidget ();
708     return doubleClick;
709 }
710
711 /**
712  * Returns the echo character.
713  * <p>
714  * The echo character is the character that is
715  * displayed when the user enters text or the
716  * text is changed by the programmer.
717  * </p>
718  *
719  * @return the echo character
720  *
721  * @exception SWTException <ul>
722  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
723  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
724  * </ul>
725  *
726  * @see #setEchoChar
727  */

728 public char getEchoChar () {
729     checkWidget ();
730     char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0);
731     if (echo != 0 && (echo = Display.mbcsToWcs (echo, getCodePage ())) == 0) echo = '*';
732     return echo;
733 }
734
735 /**
736  * Returns the editable state.
737  *
738  * @return whether or not the receiver is editable
739  *
740  * @exception SWTException <ul>
741  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
742  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
743  * </ul>
744  */

745 public boolean getEditable () {
746     checkWidget ();
747     int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
748     return (bits & OS.ES_READONLY) == 0;
749 }
750
751 /**
752  * Returns the number of lines.
753  *
754  * @return the number of lines in the widget
755  *
756  * @exception SWTException <ul>
757  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
758  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
759  * </ul>
760  */

761 public int getLineCount () {
762     checkWidget ();
763     return OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
764 }
765
766 /**
767  * Returns the line delimiter.
768  *
769  * @return a string that is the line delimiter
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  * @see #DELIMITER
777  */

778 public String JavaDoc getLineDelimiter () {
779     checkWidget ();
780     return DELIMITER;
781 }
782
783 /**
784  * Returns the height of a line.
785  *
786  * @return the height of a row of text
787  *
788  * @exception SWTException <ul>
789  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
790  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
791  * </ul>
792  */

793 public int getLineHeight () {
794     checkWidget ();
795     int newFont, oldFont = 0;
796     int hDC = OS.GetDC (handle);
797     newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
798     if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
799     TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
800     OS.GetTextMetrics (hDC, tm);
801     if (newFont != 0) OS.SelectObject (hDC, oldFont);
802     OS.ReleaseDC (handle, hDC);
803     return tm.tmHeight;
804 }
805
806 /**
807  * Returns the orientation of the receiver, which will be one of the
808  * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
809  *
810  * @return the orientation style
811  *
812  * @exception SWTException <ul>
813  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
814  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
815  * </ul>
816  *
817  * @since 2.1.2
818  */

819 public int getOrientation () {
820     checkWidget();
821     return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
822 }
823
824 /**
825  * Returns the widget message. When the widget is created
826  * with the style <code>SWT.SEARCH</code>, the message text
827  * is displayed as a hint for the user, indicating the
828  * purpose of the field.
829  * <p>
830  * Note: This operation is a <em>HINT</em> and is not
831  * supported on platforms that do not have this concept.
832  * </p>
833  *
834  * @return the widget message
835  *
836  * @exception SWTException <ul>
837  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
838  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
839  * </ul>
840  *
841  * @since 3.3
842  */

843 public String JavaDoc getMessage () {
844     checkWidget ();
845     return message;
846 }
847
848 /**
849  * Returns the character position at the given point in the receiver
850  * or -1 if no such position exists. The point is in the coordinate
851  * system of the receiver.
852  * <p>
853  * Indexing is zero based.
854  * </p>
855  *
856  * @return the position of the caret
857  *
858  * @exception SWTException <ul>
859  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
860  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
861  * </ul>
862  *
863  * @since 3.3
864  */

865 //TODO - Javadoc
866
/*public*/ int getPosition (Point point) {
867     checkWidget();
868     if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
869     int lParam = (point.x & 0xFFFF) | ((point.y << 16) & 0xFFFF0000);
870     int position = OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam) & 0xFFFF;
871     if (!OS.IsUnicode && OS.IsDBLocale) position = mbcsToWcsPos (position);
872     return position;
873 }
874
875 /**
876  * Returns a <code>Point</code> whose x coordinate is the
877  * character position representing the start of the selected
878  * text, and whose y coordinate is the character position
879  * representing the end of the selection. An "empty" selection
880  * is indicated by the x and y coordinates having the same value.
881  * <p>
882  * Indexing is zero based. The range of a selection is from
883  * 0..N where N is the number of characters in the widget.
884  * </p>
885  *
886  * @return a point representing the selection start and end
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 Point getSelection () {
894     checkWidget ();
895     int [] start = new int [1], end = new int [1];
896     OS.SendMessage (handle, OS.EM_GETSEL, start, end);
897     if (!OS.IsUnicode && OS.IsDBLocale) {
898         start [0] = mbcsToWcsPos (start [0]);
899         end [0] = mbcsToWcsPos (end [0]);
900     }
901     return new Point (start [0], end [0]);
902 }
903
904 /**
905  * Returns the number of selected characters.
906  *
907  * @return the number of selected characters.
908  *
909  * @exception SWTException <ul>
910  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
911  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
912  * </ul>
913  */

914 public int getSelectionCount () {
915     checkWidget ();
916     Point selection = getSelection ();
917     return selection.y - selection.x;
918 }
919
920 /**
921  * Gets the selected text, or an empty string if there is no current selection.
922  *
923  * @return the selected text
924  *
925  * @exception SWTException <ul>
926  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
927  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
928  * </ul>
929  */

930 public String JavaDoc getSelectionText () {
931     checkWidget ();
932     int length = OS.GetWindowTextLength (handle);
933     if (length == 0) return "";
934     int [] start = new int [1], end = new int [1];
935     OS.SendMessage (handle, OS.EM_GETSEL, start, end);
936     if (start [0] == end [0]) return "";
937     TCHAR buffer = new TCHAR (getCodePage (), length + 1);
938     OS.GetWindowText (handle, buffer, length + 1);
939     return buffer.toString (start [0], end [0] - start [0]);
940 }
941
942 /**
943  * Returns the number of tabs.
944  * <p>
945  * Tab stop spacing is specified in terms of the
946  * space (' ') character. The width of a single
947  * tab stop is the pixel width of the spaces.
948  * </p>
949  *
950  * @return the number of tab characters
951  *
952  * @exception SWTException <ul>
953  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
954  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
955  * </ul>
956  */

957 public int getTabs () {
958     checkWidget ();
959     return tabs;
960 }
961
962 int getTabWidth (int tabs) {
963     int oldFont = 0;
964     RECT rect = new RECT ();
965     int hDC = OS.GetDC (handle);
966     int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
967     if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
968     int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
969     TCHAR SPACE = new TCHAR (getCodePage (), " ", false);
970     OS.DrawText (hDC, SPACE, SPACE.length (), rect, flags);
971     if (newFont != 0) OS.SelectObject (hDC, oldFont);
972     OS.ReleaseDC (handle, hDC);
973     return (rect.right - rect.left) * tabs;
974 }
975
976 /**
977  * Returns the widget text.
978  * <p>
979  * The text for a text widget is the characters in the widget, or
980  * an empty string if this has never been set.
981  * </p>
982  *
983  * @return the widget text
984  *
985  * @exception SWTException <ul>
986  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
987  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
988  * </ul>
989  */

990 public String JavaDoc getText () {
991     checkWidget ();
992     int length = OS.GetWindowTextLength (handle);
993     if (length == 0) return "";
994     TCHAR buffer = new TCHAR (getCodePage (), length + 1);
995     OS.GetWindowText (handle, buffer, length + 1);
996     return buffer.toString (0, length);
997 }
998
999 /**
1000 * Returns a range of text. Returns an empty string if the
1001 * start of the range is greater than the end.
1002 * <p>
1003 * Indexing is zero based. The range of
1004 * a selection is from 0..N-1 where N is
1005 * the number of characters in the widget.
1006 * </p>
1007 *
1008 * @param start the start of the range
1009 * @param end the end of the range
1010 * @return the range of text
1011 *
1012 * @exception SWTException <ul>
1013 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1014 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1015 * </ul>
1016 */

1017public String JavaDoc getText (int start, int end) {
1018    checkWidget ();
1019    if (!(start <= end && 0 <= end)) return "";
1020    int length = OS.GetWindowTextLength (handle);
1021    if (!OS.IsUnicode && OS.IsDBLocale) length = mbcsToWcsPos (length);
1022    start = Math.max (0, start);
1023    end = Math.min (end, length - 1);
1024    /*
1025    * NOTE: The current implementation uses substring ()
1026    * which can reference a potentially large character
1027    * array.
1028    */

1029    return getText ().substring (start, end + 1);
1030}
1031
1032/**
1033 * Returns the maximum number of characters that the receiver is capable of holding.
1034 * <p>
1035 * If this has not been changed by <code>setTextLimit()</code>,
1036 * it will be the constant <code>Text.LIMIT</code>.
1037 * </p>
1038 *
1039 * @return the text limit
1040 *
1041 * @exception SWTException <ul>
1042 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1043 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1044 * </ul>
1045 *
1046 * @see #LIMIT
1047 */

1048public int getTextLimit () {
1049    checkWidget ();
1050    return OS.SendMessage (handle, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
1051}
1052
1053/**
1054 * Returns the zero-relative index of the line which is currently
1055 * at the top of the receiver.
1056 * <p>
1057 * This index can change when lines are scrolled or new lines are added or removed.
1058 * </p>
1059 *
1060 * @return the index of the top line
1061 *
1062 * @exception SWTException <ul>
1063 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1064 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1065 * </ul>
1066 */

1067public int getTopIndex () {
1068    checkWidget ();
1069    if ((style & SWT.SINGLE) != 0) return 0;
1070    return OS.SendMessage (handle, OS.EM_GETFIRSTVISIBLELINE, 0, 0);
1071}
1072
1073/**
1074 * Returns the top pixel.
1075 * <p>
1076 * The top pixel is the pixel position of the line
1077 * that is currently at the top of the widget. On
1078 * some platforms, a text widget can be scrolled by
1079 * pixels instead of lines so that a partial line
1080 * is displayed at the top of the widget.
1081 * </p><p>
1082 * The top pixel changes when the widget is scrolled.
1083 * The top pixel does not include the widget trimming.
1084 * </p>
1085 *
1086 * @return the pixel position of the top line
1087 *
1088 * @exception SWTException <ul>
1089 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1090 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1091 * </ul>
1092 */

1093public int getTopPixel () {
1094    checkWidget ();
1095    /*
1096    * Note, EM_GETSCROLLPOS is implemented in Rich Edit 3.0
1097    * and greater. The plain text widget and previous versions
1098    * of Rich Edit return zero.
1099    */

1100    int [] buffer = new int [2];
1101    int code = OS.SendMessage (handle, OS.EM_GETSCROLLPOS, 0, buffer);
1102    if (code == 1) return buffer [1];
1103    return getTopIndex () * getLineHeight ();
1104}
1105
1106/**
1107 * Inserts a string.
1108 * <p>
1109 * The old selection is replaced with the new text.
1110 * </p>
1111 *
1112 * @param string the string
1113 *
1114 * @exception IllegalArgumentException <ul>
1115 * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
1116 * </ul>
1117 * @exception SWTException <ul>
1118 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1119 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1120 * </ul>
1121 */

1122public void insert (String JavaDoc string) {
1123    checkWidget ();
1124    if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
1125    string = Display.withCrLf (string);
1126    if (hooks (SWT.Verify) || filters (SWT.Verify)) {
1127        int [] start = new int [1], end = new int [1];
1128        OS.SendMessage (handle, OS.EM_GETSEL, start, end);
1129        string = verifyText (string, start [0], end [0], null);
1130        if (string == null) return;
1131    }
1132    TCHAR buffer = new TCHAR (getCodePage (), string, true);
1133    /*
1134    * Feature in Windows. When an edit control with ES_MULTILINE
1135    * style that does not have the WS_VSCROLL style is full (i.e.
1136    * there is no space at the end to draw any more characters),
1137    * EM_REPLACESEL sends a WM_CHAR with a backspace character
1138    * to remove any further text that is added. This is an
1139    * implementation detail of the edit control that is unexpected
1140    * and can cause endless recursion when EM_REPLACESEL is sent
1141    * from a WM_CHAR handler. The fix is to ignore calling the
1142    * handler from WM_CHAR.
1143    */

1144    ignoreCharacter = true;
1145    OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
1146    ignoreCharacter = false;
1147}
1148
1149int mbcsToWcsPos (int mbcsPos) {
1150    if (mbcsPos <= 0) return 0;
1151    if (OS.IsUnicode) return mbcsPos;
1152    int cp = getCodePage ();
1153    int wcsTotal = 0, mbcsTotal = 0;
1154    byte [] buffer = new byte [128];
1155    String JavaDoc delimiter = getLineDelimiter();
1156    int delimiterSize = delimiter.length ();
1157    int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0);
1158    for (int line=0; line<count; line++) {
1159        int wcsSize = 0;
1160        int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0);
1161        int mbcsSize = OS.SendMessageA (handle, OS.EM_LINELENGTH, linePos, 0);
1162        if (mbcsSize != 0) {
1163            if (mbcsSize + delimiterSize > buffer.length) {
1164                buffer = new byte [mbcsSize + delimiterSize];
1165            }
1166            //ENDIAN
1167
buffer [0] = (byte) (mbcsSize & 0xFF);
1168            buffer [1] = (byte) (mbcsSize >> 8);
1169            mbcsSize = OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer);
1170            wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, mbcsSize, null, 0);
1171        }
1172        if (line - 1 != count) {
1173            for (int i=0; i<delimiterSize; i++) {
1174                buffer [mbcsSize++] = (byte) delimiter.charAt (i);
1175            }
1176            wcsSize += delimiterSize;
1177        }
1178        if ((mbcsTotal + mbcsSize) >= mbcsPos) {
1179            int bufferSize = mbcsPos - mbcsTotal;
1180            wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, bufferSize, null, 0);
1181            return wcsTotal + wcsSize;
1182        }
1183        wcsTotal += wcsSize;
1184        mbcsTotal += mbcsSize;
1185    }
1186    return wcsTotal;
1187}
1188
1189/**
1190 * Pastes text from clipboard.
1191 * <p>
1192 * The selected text is deleted from the widget
1193 * and new text inserted from the clipboard.
1194 * </p>
1195 *
1196 * @exception SWTException <ul>
1197 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1198 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1199 * </ul>
1200 */

1201public void paste () {
1202    checkWidget ();
1203    if ((style & SWT.READ_ONLY) != 0) return;
1204    OS.SendMessage (handle, OS.WM_PASTE, 0, 0);
1205}
1206
1207void releaseWidget () {
1208    super.releaseWidget ();
1209    message = null;
1210}
1211
1212/**
1213 * Removes the listener from the collection of listeners who will
1214 * be notified when the receiver's text is modified.
1215 *
1216 * @param listener the listener which should no longer be notified
1217 *
1218 * @exception IllegalArgumentException <ul>
1219 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1220 * </ul>
1221 * @exception SWTException <ul>
1222 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1223 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1224 * </ul>
1225 *
1226 * @see ModifyListener
1227 * @see #addModifyListener
1228 */

1229public void removeModifyListener (ModifyListener listener) {
1230    checkWidget ();
1231    if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1232    if (eventTable == null) return;
1233    eventTable.unhook (SWT.Modify, listener);
1234}
1235
1236/**
1237 * Removes the listener from the collection of listeners who will
1238 * be notified when the control is selected by the user.
1239 *
1240 * @param listener the listener which should no longer be notified
1241 *
1242 * @exception IllegalArgumentException <ul>
1243 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1244 * </ul>
1245 * @exception SWTException <ul>
1246 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1247 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1248 * </ul>
1249 *
1250 * @see SelectionListener
1251 * @see #addSelectionListener
1252 */

1253public void removeSelectionListener (SelectionListener listener) {
1254    checkWidget ();
1255    if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1256    if (eventTable == null) return;
1257    eventTable.unhook (SWT.Selection, listener);
1258    eventTable.unhook (SWT.DefaultSelection,listener);
1259}
1260
1261/**
1262 * Removes the listener from the collection of listeners who will
1263 * be notified when the control is verified.
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 VerifyListener
1276 * @see #addVerifyListener
1277 */

1278public void removeVerifyListener (VerifyListener listener) {
1279    checkWidget ();
1280    if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1281    if (eventTable == null) return;
1282    eventTable.unhook (SWT.Verify, listener);
1283}
1284
1285/**
1286 * Selects all the text in the receiver.
1287 *
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 */

1293public void selectAll () {
1294    checkWidget ();
1295    OS.SendMessage (handle, OS.EM_SETSEL, 0, -1);
1296}
1297
1298boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) {
1299    if (!super.sendKeyEvent (type, msg, wParam, lParam, event)) {
1300        return false;
1301    }
1302    if ((style & SWT.READ_ONLY) != 0) return true;
1303    if (ignoreVerify) return true;
1304    if (type != SWT.KeyDown) return true;
1305    if (msg != OS.WM_CHAR && msg != OS.WM_KEYDOWN && msg != OS.WM_IME_CHAR) {
1306        return true;
1307    }
1308    if (event.character == 0) return true;
1309    if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return true;
1310    char key = event.character;
1311    int stateMask = event.stateMask;
1312    
1313    /*
1314    * Disable all magic keys that could modify the text
1315    * and don't send events when Alt, Shift or Ctrl is
1316    * pressed.
1317    */

1318    switch (msg) {
1319        case OS.WM_CHAR:
1320            if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break;
1321            // FALL THROUGH
1322
case OS.WM_KEYDOWN:
1323            if ((stateMask & (SWT.ALT | SWT.SHIFT | SWT.CONTROL)) != 0) return false;
1324            break;
1325    }
1326
1327    /*
1328    * Feature in Windows. If the left button is down in
1329    * the text widget, it refuses the character. The fix
1330    * is to detect this case and avoid sending a verify
1331    * event.
1332    */

1333    if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
1334        if (handle == OS.GetCapture()) return true;
1335    }
1336
1337    /* Verify the character */
1338    String JavaDoc oldText = "";
1339    int [] start = new int [1], end = new int [1];
1340    OS.SendMessage (handle, OS.EM_GETSEL, start, end);
1341    switch (key) {
1342        case 0x08: /* Bs */
1343            if (start [0] == end [0]) {
1344                if (start [0] == 0) return true;
1345                int lineStart = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
1346                if (start [0] == lineStart) {
1347                    start [0] = start [0] - DELIMITER.length ();
1348                } else {
1349                    start [0] = start [0] - 1;
1350                    if (!OS.IsUnicode && OS.IsDBLocale) {
1351                        int [] newStart = new int [1], newEnd = new int [1];
1352                        OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
1353                        OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd);
1354                        if (start [0] != newStart [0]) start [0] = start [0] - 1;
1355                    }
1356                }
1357                start [0] = Math.max (start [0], 0);
1358            }
1359            break;
1360        case 0x7F: /* Del */
1361            if (start [0] == end [0]) {
1362                int length = OS.GetWindowTextLength (handle);
1363                if (start [0] == length) return true;
1364                int line = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0);
1365                int lineStart = OS.SendMessage (handle, OS.EM_LINEINDEX, line + 1, 0);
1366                if (end [0] == lineStart - DELIMITER.length ()) {
1367                    end [0] = end [0] + DELIMITER.length ();
1368                } else {
1369                    end [0] = end [0] + 1;
1370                    if (!OS.IsUnicode && OS.IsDBLocale) {
1371                        int [] newStart = new int [1], newEnd = new int [1];
1372                        OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
1373                        OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd);
1374                        if (end [0] != newEnd [0]) end [0] = end [0] + 1;
1375                    }
1376                }
1377                end [0] = Math.min (end [0], length);
1378            }
1379            break;
1380        case '\r': /* Return */
1381            if ((style & SWT.SINGLE) != 0) return true;
1382            oldText = DELIMITER;
1383            break;
1384        default: /* Tab and other characters */
1385            if (key != '\t' && key < 0x20) return true;
1386            oldText = new String JavaDoc (new char [] {key});
1387            break;
1388    }
1389    String JavaDoc newText = verifyText (oldText, start [0], end [0], event);
1390    if (newText == null) return false;
1391    if (newText == oldText) return true;
1392    newText = Display.withCrLf (newText);
1393    TCHAR buffer = new TCHAR (getCodePage (), newText, true);
1394    OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
1395    /*
1396    * Feature in Windows. When an edit control with ES_MULTILINE
1397    * style that does not have the WS_VSCROLL style is full (i.e.
1398    * there is no space at the end to draw any more characters),
1399    * EM_REPLACESEL sends a WM_CHAR with a backspace character
1400    * to remove any further text that is added. This is an
1401    * implementation detail of the edit control that is unexpected
1402    * and can cause endless recursion when EM_REPLACESEL is sent
1403    * from a WM_CHAR handler. The fix is to ignore calling the
1404    * handler from WM_CHAR.
1405    */

1406    ignoreCharacter = true;
1407    OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
1408    ignoreCharacter = false;
1409    return false;
1410}
1411
1412void setBounds (int x, int y, int width, int height, int flags) {
1413    /*
1414    * Feature in Windows. When the caret is moved,
1415    * the text widget scrolls to show the new location.
1416    * This means that the text widget may be scrolled
1417    * to the right in order to show the caret when the
1418    * widget is not large enough to show both the caret
1419    * location and all the text. Unfortunately, when
1420    * the text widget is resized such that all the text
1421    * and the caret could be visible, Windows does not
1422    * scroll the widget back. The fix is to resize the
1423    * text widget, set the selection to the start of the
1424    * text and then restore the selection. This will
1425    * cause the text widget compute the correct scroll
1426    * position.
1427    */

1428    if ((flags & OS.SWP_NOSIZE) == 0 && width != 0) {
1429        RECT rect = new RECT ();
1430        OS.GetWindowRect (handle, rect);
1431        int margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0);
1432        int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
1433        if (rect.right - rect.left <= marginWidth) {
1434            int [] start = new int [1], end = new int [1];
1435            OS.SendMessage (handle, OS.EM_GETSEL, start, end);
1436            if (start [0] != 0 || end [0] != 0) {
1437                SetWindowPos (handle, 0, x, y, width, height, flags);
1438                OS.SendMessage (handle, OS.EM_SETSEL, 0, 0);
1439                OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
1440                return;
1441            }
1442        }
1443    }
1444    super.setBounds (x, y, width, height, flags);
1445}
1446
1447void setDefaultFont () {
1448    super.setDefaultFont ();
1449    setMargins ();
1450}
1451
1452/**
1453 * Sets the double click enabled flag.
1454 * <p>
1455 * The double click flag enables or disables the
1456 * default action of the text widget when the user
1457 * double clicks.
1458 * </p><p>
1459 * Note: This operation is a hint and is not supported on
1460 * platforms that do not have this concept.
1461 * </p>
1462 *
1463 * @param doubleClick the new double click flag
1464 *
1465 * @exception SWTException <ul>
1466 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1467 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1468 * </ul>
1469 */

1470public void setDoubleClickEnabled (boolean doubleClick) {
1471    checkWidget ();
1472    this.doubleClick = doubleClick;
1473}
1474
1475/**
1476 * Sets the echo character.
1477 * <p>
1478 * The echo character is the character that is
1479 * displayed when the user enters text or the
1480 * text is changed by the programmer. Setting
1481 * the echo character to '\0' clears the echo
1482 * character and redraws the original text.
1483 * If for any reason the echo character is invalid,
1484 * or if the platform does not allow modification
1485 * of the echo character, the default echo character
1486 * for the platform is used.
1487 * </p>
1488 *
1489 * @param echo the new echo character
1490 *
1491 * @exception SWTException <ul>
1492 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1493 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1494 * </ul>
1495 */

1496public void setEchoChar (char echo) {
1497    checkWidget ();
1498    if ((style & SWT.MULTI) != 0) return;
1499    if (echo != 0) {
1500        if ((echo = (char) Display.wcsToMbcs (echo, getCodePage ())) == 0) echo = '*';
1501    }
1502    OS.SendMessage (handle, OS.EM_SETPASSWORDCHAR, echo, 0);
1503    /*
1504    * Bug in Windows. When the password character is changed,
1505    * Windows does not redraw to show the new password character.
1506    * The fix is to force a redraw when the character is set.
1507    */

1508    OS.InvalidateRect (handle, null, true);
1509}
1510
1511/**
1512 * Sets the editable state.
1513 *
1514 * @param editable the new editable state
1515 *
1516 * @exception SWTException <ul>
1517 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1518 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1519 * </ul>
1520 */

1521public void setEditable (boolean editable) {
1522    checkWidget ();
1523    style &= ~SWT.READ_ONLY;
1524    if (!editable) style |= SWT.READ_ONLY;
1525    OS.SendMessage (handle, OS.EM_SETREADONLY, editable ? 0 : 1, 0);
1526}
1527
1528public void setFont (Font font) {
1529    checkWidget ();
1530    super.setFont (font);
1531    setTabStops (tabs);
1532    setMargins ();
1533}
1534
1535void setMargins () {
1536    /*
1537    * Bug in Windows. When EM_SETCUEBANNER is used to set the
1538    * banner text, the control does not take into account the
1539    * margins, causing the first character to be clipped. The
1540    * fix is to set the margins to zero.
1541    */

1542    if (OS.COMCTL32_MAJOR >= 6) {
1543        if ((style & SWT.SEARCH) != 0) {
1544            OS.SendMessage (handle, OS.EM_SETMARGINS, OS.EC_LEFTMARGIN | OS.EC_RIGHTMARGIN, 0);
1545        }
1546    }
1547}
1548
1549/**
1550 * Sets the widget message. When the widget is created
1551 * with the style <code>SWT.SEARCH</code>, the message text
1552 * is displayed as a hint for the user, indicating the
1553 * purpose of the field.
1554 * <p>
1555 * Note: This operation is a <em>HINT</em> and is not
1556 * supported on platforms that do not have this concept.
1557 * </p>
1558 *
1559 * @param message the new message
1560 *
1561 * @exception IllegalArgumentException <ul>
1562 * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
1563 * </ul>
1564 * @exception SWTException <ul>
1565 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1566 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1567 * </ul>
1568 *
1569 * @since 3.3
1570 */

1571public void setMessage (String JavaDoc message) {
1572    checkWidget ();
1573    if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
1574    this.message = message;
1575    if (OS.COMCTL32_MAJOR >= 6) {
1576        if ((style & SWT.SEARCH) != 0) {
1577            int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
1578            if ((bits & OS.ES_MULTILINE) == 0) {
1579                int length = message.length ();
1580                char [] chars = new char [length + 1];
1581                message.getChars(0, length, chars, 0);
1582                OS.SendMessage (handle, OS.EM_SETCUEBANNER, 0, chars);
1583            }
1584        }
1585    }
1586}
1587
1588/**
1589 * Sets the orientation of the receiver, which must be one
1590 * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
1591 * <p>
1592 * Note: This operation is a hint and is not supported on
1593 * platforms that do not have this concept.
1594 * </p>
1595 *
1596 * @param orientation new orientation style
1597 *
1598 * @exception SWTException <ul>
1599 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1600 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1601 * </ul>
1602 *
1603 * @since 2.1.2
1604 */

1605public void setOrientation (int orientation) {
1606    checkWidget();
1607    if (OS.IsWinCE) return;
1608    if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return;
1609    int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
1610    if ((orientation & flags) == 0 || (orientation & flags) == flags) return;
1611    style &= ~flags;
1612    style |= orientation & flags;
1613    int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1614    if ((style & SWT.RIGHT_TO_LEFT) != 0) {
1615        bits |= OS.WS_EX_RTLREADING | OS.WS_EX_LEFTSCROLLBAR;
1616    } else {
1617        bits &= ~(OS.WS_EX_RTLREADING | OS.WS_EX_LEFTSCROLLBAR);
1618    }
1619    OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits);
1620    fixAlignment ();
1621}
1622
1623/**
1624 * Sets the selection.
1625 * <p>
1626 * Indexing is zero based. The range of
1627 * a selection is from 0..N where N is
1628 * the number of characters in the widget.
1629 * </p><p>
1630 * Text selections are specified in terms of
1631 * caret positions. In a text widget that
1632 * contains N characters, there are N+1 caret
1633 * positions, ranging from 0..N. This differs
1634 * from other functions that address character
1635 * position such as getText () that use the
1636 * regular array indexing rules.
1637 * </p>
1638 *
1639 * @param start new caret position
1640 *
1641 * @exception SWTException <ul>
1642 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1643 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1644 * </ul>
1645 */

1646public void setSelection (int start) {
1647    checkWidget ();
1648    if (!OS.IsUnicode && OS.IsDBLocale) start = wcsToMbcsPos (start);
1649    OS.SendMessage (handle, OS.EM_SETSEL, start, start);
1650    OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
1651}
1652
1653/**
1654 * Sets the selection to the range specified
1655 * by the given start and end indices.
1656 * <p>
1657 * Indexing is zero based. The range of
1658 * a selection is from 0..N where N is
1659 * the number of characters in the widget.
1660 * </p><p>
1661 * Text selections are specified in terms of
1662 * caret positions. In a text widget that
1663 * contains N characters, there are N+1 caret
1664 * positions, ranging from 0..N. This differs
1665 * from other functions that address character
1666 * position such as getText () that use the
1667 * usual array indexing rules.
1668 * </p>
1669 *
1670 * @param start the start of the range
1671 * @param end the end of the range
1672 *
1673 * @exception SWTException <ul>
1674 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1675 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1676 * </ul>
1677 */

1678public void setSelection (int start, int end) {
1679    checkWidget ();
1680    if (!OS.IsUnicode && OS.IsDBLocale) {
1681        start = wcsToMbcsPos (start);
1682        end = wcsToMbcsPos (end);
1683    }
1684    OS.SendMessage (handle, OS.EM_SETSEL, start, end);
1685    OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
1686}
1687
1688public void setRedraw (boolean redraw) {
1689    checkWidget ();
1690    super.setRedraw (redraw);
1691    /*
1692    * Feature in Windows. When WM_SETREDRAW is used to turn
1693    * redraw off, the edit control is not scrolled to show the
1694    * i-beam. The fix is to detect that the i-beam has moved
1695    * while redraw is turned off and force it to be visible
1696    * when redraw is restored.
1697    */

1698    if (drawCount != 0) return;
1699    int [] start = new int [1], end = new int [1];
1700    OS.SendMessage (handle, OS.EM_GETSEL, start, end);
1701    if (!redraw) {
1702        oldStart = start [0]; oldEnd = end [0];
1703    } else {
1704        if (oldStart == start [0] && oldEnd == end [0]) return;
1705        OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
1706    }
1707}
1708
1709/**
1710 * Sets the selection to the range specified
1711 * by the given point, where the x coordinate
1712 * represents the start index and the y coordinate
1713 * represents the end index.
1714 * <p>
1715 * Indexing is zero based. The range of
1716 * a selection is from 0..N where N is
1717 * the number of characters in the widget.
1718 * </p><p>
1719 * Text selections are specified in terms of
1720 * caret positions. In a text widget that
1721 * contains N characters, there are N+1 caret
1722 * positions, ranging from 0..N. This differs
1723 * from other functions that address character
1724 * position such as getText () that use the
1725 * usual array indexing rules.
1726 * </p>
1727 *
1728 * @param selection the point
1729 *
1730 * @exception IllegalArgumentException <ul>
1731 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
1732 * </ul>
1733 * @exception SWTException <ul>
1734 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1735 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1736 * </ul>
1737 */

1738public void setSelection (Point selection) {
1739    checkWidget ();
1740    if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
1741    setSelection (selection.x, selection.y);
1742}
1743
1744/**
1745 * Sets the number of tabs.
1746 * <p>
1747 * Tab stop spacing is specified in terms of the
1748 * space (' ') character. The width of a single
1749 * tab stop is the pixel width of the spaces.
1750 * </p>
1751 *
1752 * @param tabs the number of tabs
1753 *
1754 * </ul>
1755 * @exception SWTException <ul>
1756 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1757 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1758 * </ul>
1759 */

1760public void setTabs (int tabs) {
1761    checkWidget ();
1762    if (tabs < 0) return;
1763    setTabStops (this.tabs = tabs);
1764}
1765
1766void setTabStops (int tabs) {
1767    /*
1768    * Feature in Windows. Windows expects the tab spacing in
1769    * dialog units so we must convert from space widths. Due
1770    * to round off error, the tab spacing may not be the exact
1771    * number of space widths, depending on the font.
1772    */

1773    int width = (getTabWidth (tabs) * 4) / (OS.GetDialogBaseUnits () & 0xFFFF);
1774    OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, new int [] {width});
1775}
1776
1777/**
1778 * Sets the contents of the receiver to the given string. If the receiver has style
1779 * SINGLE and the argument contains multiple lines of text, the result of this
1780 * operation is undefined and may vary from platform to platform.
1781 *
1782 * @param string the new text
1783 *
1784 * @exception IllegalArgumentException <ul>
1785 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
1786 * </ul>
1787 * @exception SWTException <ul>
1788 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1789 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1790 * </ul>
1791 */

1792public void setText (String JavaDoc string) {
1793    checkWidget ();
1794    if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
1795    string = Display.withCrLf (string);
1796    if (hooks (SWT.Verify) || filters (SWT.Verify)) {
1797        int length = OS.GetWindowTextLength (handle);
1798        string = verifyText (string, 0, length, null);
1799        if (string == null) return;
1800    }
1801    int limit = OS.SendMessage (handle, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
1802    if (string.length () > limit) string = string.substring (0, limit);
1803    TCHAR buffer = new TCHAR (getCodePage (), string, true);
1804    OS.SetWindowText (handle, buffer);
1805    /*
1806    * Bug in Windows. When the widget is multi line
1807    * text widget, it does not send a WM_COMMAND with
1808    * control code EN_CHANGE from SetWindowText () to
1809    * notify the application that the text has changed.
1810    * The fix is to send the event.
1811    */

1812    int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
1813    if ((bits & OS.ES_MULTILINE) != 0) {
1814        sendEvent (SWT.Modify);
1815        // widget could be disposed at this point
1816
}
1817}
1818
1819/**
1820 * Sets the maximum number of characters that the receiver
1821 * is capable of holding to be the argument.
1822 * <p>
1823 * Instead of trying to set the text limit to zero, consider
1824 * creating a read-only text widget.
1825 * </p><p>
1826 * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
1827 * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
1828 * receiver's limit to <code>Text.LIMIT</code>.
1829 * </p>
1830 *
1831 * @param limit new text limit
1832 *
1833 * @exception IllegalArgumentException <ul>
1834 * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
1835 * </ul>
1836 * @exception SWTException <ul>
1837 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1838 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1839 * </ul>
1840 *
1841 * @see #LIMIT
1842 */

1843public void setTextLimit (int limit) {
1844    checkWidget ();
1845    if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
1846    OS.SendMessage (handle, OS.EM_SETLIMITTEXT, limit, 0);
1847}
1848
1849/**
1850 * Sets the zero-relative index of the line which is currently
1851 * at the top of the receiver. This index can change when lines
1852 * are scrolled or new lines are added and removed.
1853 *
1854 * @param index the index of the top item
1855 *
1856 * @exception SWTException <ul>
1857 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1858 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1859 * </ul>
1860 */

1861public void setTopIndex (int index) {
1862    checkWidget ();
1863    if ((style & SWT.SINGLE) != 0) return;
1864    int count = OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
1865    index = Math.min (Math.max (index, 0), count - 1);
1866    int topIndex = OS.SendMessage (handle, OS.EM_GETFIRSTVISIBLELINE, 0, 0);
1867    OS.SendMessage (handle, OS.EM_LINESCROLL, 0, index - topIndex);
1868}
1869
1870/**
1871 * Shows the selection.
1872 * <p>
1873 * If the selection is already showing
1874 * in the receiver, this method simply returns. Otherwise,
1875 * lines are scrolled until the selection is visible.
1876 * </p>
1877 *
1878 * @exception SWTException <ul>
1879 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1880 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1881 * </ul>
1882 */

1883public void showSelection () {
1884    checkWidget ();
1885    OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
1886}
1887
1888String JavaDoc verifyText (String JavaDoc string, int start, int end, Event keyEvent) {
1889    if (ignoreVerify) return string;
1890    Event event = new Event ();
1891    event.text = string;
1892    event.start = start;
1893    event.end = end;
1894    if (keyEvent != null) {
1895        event.character = keyEvent.character;
1896        event.keyCode = keyEvent.keyCode;
1897        event.stateMask = keyEvent.stateMask;
1898    }
1899    if (!OS.IsUnicode && OS.IsDBLocale) {
1900        event.start = mbcsToWcsPos (start);
1901        event.end = mbcsToWcsPos (end);
1902    }
1903    /*
1904    * It is possible (but unlikely), that application
1905    * code could have disposed the widget in the verify
1906    * event. If this happens, answer null to cancel
1907    * the operation.
1908    */

1909    sendEvent (SWT.Verify, event);
1910    if (!event.doit || isDisposed ()) return null;
1911    return event.text;
1912}
1913
1914int wcsToMbcsPos (int wcsPos) {
1915    if (wcsPos <= 0) return 0;
1916    if (OS.IsUnicode) return wcsPos;
1917    int cp = getCodePage ();
1918    int wcsTotal = 0, mbcsTotal = 0;
1919    byte [] buffer = new byte [128];
1920    String JavaDoc delimiter = getLineDelimiter ();
1921    int delimiterSize = delimiter.length ();
1922    int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0);
1923    for (int line=0; line<count; line++) {
1924        int wcsSize = 0;
1925        int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0);
1926        int mbcsSize = OS.SendMessageA (handle, OS.EM_LINELENGTH, linePos, 0);
1927        if (mbcsSize != 0) {
1928            if (mbcsSize + delimiterSize > buffer.length) {
1929                buffer = new byte [mbcsSize + delimiterSize];
1930            }
1931            //ENDIAN
1932
buffer [0] = (byte) (mbcsSize & 0xFF);
1933            buffer [1] = (byte) (mbcsSize >> 8);
1934            mbcsSize = OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer);
1935            wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, mbcsSize, null, 0);
1936        }
1937        if (line - 1 != count) {
1938            for (int i=0; i<delimiterSize; i++) {
1939                buffer [mbcsSize++] = (byte) delimiter.charAt (i);
1940            }
1941            wcsSize += delimiterSize;
1942        }
1943        if ((wcsTotal + wcsSize) >= wcsPos) {
1944            wcsSize = 0;
1945            int index = 0;
1946            while (index < mbcsSize) {
1947                if ((wcsTotal + wcsSize) == wcsPos) {
1948                    return mbcsTotal + index;
1949                }
1950                if (OS.IsDBCSLeadByte (buffer [index++])) index++;
1951                wcsSize++;
1952            }
1953            return mbcsTotal + mbcsSize;
1954        }
1955        wcsTotal += wcsSize;
1956        mbcsTotal += mbcsSize;
1957    }
1958    return mbcsTotal;
1959}
1960
1961int widgetStyle () {
1962    int bits = super.widgetStyle () | OS.ES_AUTOHSCROLL;
1963    if ((style & SWT.PASSWORD) != 0) bits |= OS.ES_PASSWORD;
1964    if ((style & SWT.CENTER) != 0) bits |= OS.ES_CENTER;
1965    if ((style & SWT.RIGHT) != 0) bits |= OS.ES_RIGHT;
1966    if ((style & SWT.READ_ONLY) != 0) bits |= OS.ES_READONLY;
1967    if ((style & SWT.SINGLE) != 0) {
1968        /*
1969        * Feature in Windows. When a text control is read-only,
1970        * uses COLOR_3DFACE for the background . If the text
1971        * controls single-line and is within a tab folder or
1972        * some other themed control, using WM_ERASEBKGND and
1973        * WM_CTRCOLOR to draw the theme background results in
1974        * pixel corruption. The fix is to use an ES_MULTILINE
1975        * text control instead.
1976        */

1977        if ((style & SWT.READ_ONLY) != 0) {
1978            if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
1979                if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
1980                    bits |= OS.ES_MULTILINE;
1981                }
1982            }
1983        }
1984        return bits;
1985    }
1986    bits |= OS.ES_MULTILINE | OS.ES_NOHIDESEL | OS.ES_AUTOVSCROLL;
1987    if ((style & SWT.WRAP) != 0) bits &= ~(OS.WS_HSCROLL | OS.ES_AUTOHSCROLL);
1988    return bits;
1989}
1990
1991TCHAR windowClass () {
1992    return EditClass;
1993}
1994
1995int windowProc () {
1996    return EditProc;
1997}
1998
1999int windowProc (int hwnd, int msg, int wParam, int lParam) {
2000    if (msg == OS.EM_UNDO) {
2001        int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
2002        if ((bits & OS.ES_MULTILINE) == 0) {
2003            LRESULT result = wmClipboard (OS.EM_UNDO, wParam, lParam);
2004            if (result != null) return result.value;
2005            return callWindowProc (hwnd, OS.EM_UNDO, wParam, lParam);
2006        }
2007    }
2008    if (msg == Display.SWT_RESTORECARET) {
2009        callWindowProc (hwnd, OS.WM_KILLFOCUS, 0, 0);
2010        callWindowProc (hwnd, OS.WM_SETFOCUS, 0, 0);
2011        return 1;
2012    }
2013    return super.windowProc (hwnd, msg, wParam, lParam);
2014}
2015
2016LRESULT WM_CHAR (int wParam, int lParam) {
2017    if (ignoreCharacter) return null;
2018    LRESULT result = super.WM_CHAR (wParam, lParam);
2019    if (result != null) return result;
2020    
2021    /*
2022    * Bug in Windows. When the user types CTRL and BS
2023    * in an edit control, a DEL character is generated.
2024    * Rather than deleting the text, the DEL character
2025    * is inserted into the control. The fix is to detect
2026    * this case and not call the window proc.
2027    */

2028    switch (wParam) {
2029        case SWT.DEL:
2030            if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
2031                return LRESULT.ZERO;
2032            }
2033    }
2034    
2035    /*
2036    * Feature in Windows. For some reason, when the
2037    * widget is a single line text widget, when the
2038    * user presses tab, return or escape, Windows beeps.
2039    * The fix is to look for these keys and not call
2040    * the window proc.
2041    */

2042    if ((style & SWT.SINGLE) != 0) {
2043        switch (wParam) {
2044            case SWT.CR:
2045                postEvent (SWT.DefaultSelection);
2046                // FALL THROUGH
2047
case SWT.TAB:
2048            case SWT.ESC: return LRESULT.ZERO;
2049        }
2050    }
2051    return result;
2052}
2053
2054LRESULT WM_CLEAR (int wParam, int lParam) {
2055    LRESULT result = super.WM_CLEAR (wParam, lParam);
2056    if (result != null) return result;
2057    return wmClipboard (OS.WM_CLEAR, wParam, lParam);
2058}
2059
2060LRESULT WM_CUT (int wParam, int lParam) {
2061    LRESULT result = super.WM_CUT (wParam, lParam);
2062    if (result != null) return result;
2063    return wmClipboard (OS.WM_CUT, wParam, lParam);
2064}
2065
2066LRESULT WM_ERASEBKGND (int wParam, int lParam) {
2067    LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
2068    if ((style & SWT.READ_ONLY) != 0) {
2069        if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
2070            int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
2071            if ((bits & OS.ES_MULTILINE) != 0) {
2072                Control control = findBackgroundControl ();
2073                if (control == null && background == -1) {
2074                    if ((state & THEME_BACKGROUND) != 0) {
2075                        if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
2076                            control = findThemeControl ();
2077                            if (control != null) {
2078                                RECT rect = new RECT ();
2079                                OS.GetClientRect (handle, rect);
2080                                fillThemeBackground (wParam, control, rect);
2081                                return LRESULT.ONE;
2082                            }
2083                        }
2084                    }
2085                }
2086            }
2087        }
2088    }
2089    return result;
2090}
2091
2092LRESULT WM_GETDLGCODE (int wParam, int lParam) {
2093    LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
2094    if (result != null) return result;
2095    
2096    /*
2097    * Bug in WinCE PPC. For some reason, sending WM_GETDLGCODE
2098    * to a multi-line edit control causes it to ignore return and
2099    * tab keys. The fix is to return the value which is normally
2100    * returned by the text window proc on other versions of Windows.
2101    */

2102    if (OS.IsPPC) {
2103        if ((style & SWT.MULTI) != 0 && (style & SWT.READ_ONLY) == 0 && lParam == 0) {
2104            return new LRESULT (OS.DLGC_HASSETSEL | OS.DLGC_WANTALLKEYS | OS.DLGC_WANTCHARS);
2105        }
2106    }
2107
2108    /*
2109    * Feature in Windows. Despite the fact that the
2110    * edit control is read only, it still returns a
2111    * dialog code indicating that it wants all keys.
2112    * The fix is to detect this case and clear the bits.
2113    *
2114    * NOTE: A read only edit control processes arrow keys
2115    * so DLGC_WANTARROWS should not be cleared.
2116    */

2117    if ((style & SWT.READ_ONLY) != 0) {
2118        int code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam);
2119        code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB);
2120        return new LRESULT (code);
2121    }
2122    return null;
2123}
2124
2125LRESULT WM_IME_CHAR (int wParam, int lParam) {
2126
2127    /* Process a DBCS character */
2128    Display display = this.display;
2129    display.lastKey = 0;
2130    display.lastAscii = wParam;
2131    display.lastVirtual = display.lastNull = display.lastDead = false;
2132    if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) {
2133        return LRESULT.ZERO;
2134    }
2135
2136    /*
2137    * Feature in Windows. The Windows text widget uses
2138    * two 2 WM_CHAR's to process a DBCS key instead of
2139    * using WM_IME_CHAR. The fix is to allow the text
2140    * widget to get the WM_CHAR's but ignore sending
2141    * them to the application.
2142    */

2143    ignoreCharacter = true;
2144    int result = callWindowProc (handle, OS.WM_IME_CHAR, wParam, lParam);
2145    MSG msg = new MSG ();
2146    int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
2147    while (OS.PeekMessage (msg, handle, OS.WM_CHAR, OS.WM_CHAR, flags)) {
2148        OS.TranslateMessage (msg);
2149        OS.DispatchMessage (msg);
2150    }
2151    ignoreCharacter = false;
2152    
2153    sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
2154    // widget could be disposed at this point
2155
display.lastKey = display.lastAscii = 0;
2156    return new LRESULT (result);
2157}
2158
2159LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) {
2160    /*
2161    * Prevent Windows from processing WM_LBUTTONDBLCLK
2162    * when double clicking behavior is disabled by not
2163    * calling the window proc.
2164    */

2165    LRESULT result = null;
2166    sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam);
2167    if (!sendMouseEvent (SWT.MouseDoubleClick, 1, handle, OS.WM_LBUTTONDBLCLK, wParam, lParam)) {
2168        result = LRESULT.ZERO;
2169    }
2170    if (!display.captureChanged && !isDisposed ()) {
2171        if (OS.GetCapture () != handle) OS.SetCapture (handle);
2172    }
2173    if (!doubleClick) return LRESULT.ZERO;
2174        
2175    /*
2176    * Bug in Windows. When the last line of text in the
2177    * widget is double clicked and the line is empty, Windows
2178    * hides the i-beam then moves it to the first line in
2179    * the widget but does not scroll to show the user.
2180    * If the user types without clicking the mouse, invalid
2181    * characters are displayed at the end of each line of
2182    * text in the widget. The fix is to detect this case
2183    * and avoid calling the window proc.
2184    */

2185    int [] start = new int [1], end = new int [1];
2186    OS.SendMessage (handle, OS.EM_GETSEL, start, end);
2187    if (start [0] == end [0]) {
2188        int length = OS.GetWindowTextLength (handle);
2189        if (length == start [0]) {
2190            int code = OS.SendMessage (handle, OS.EM_LINELENGTH, length, 0);
2191            if (code == 0) return LRESULT.ZERO;
2192        }
2193    }
2194    return result;
2195}
2196
2197LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
2198    if (OS.IsPPC) {
2199        LRESULT result = null;
2200        Display display = this.display;
2201        display.captureChanged = false;
2202        boolean dispatch = sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam);
2203        /*
2204        * Note: On WinCE PPC, only attempt to recognize the gesture for
2205        * a context menu when the control contains a valid menu or there
2206        * are listeners for the MenuDetect event.
2207        *
2208        * Note: On WinCE PPC, the gesture that brings up a popup menu
2209        * on the text widget must keep the current text selection. As a
2210        * result, the window proc is only called if the menu is not shown.
2211        */

2212        boolean hasMenu = menu != null && !menu.isDisposed ();
2213        if (hasMenu || hooks (SWT.MenuDetect)) {
2214            int x = (short) (lParam & 0xFFFF);
2215            int y = (short) (lParam >> 16);
2216            SHRGINFO shrg = new SHRGINFO ();
2217            shrg.cbSize = SHRGINFO.sizeof;
2218            shrg.hwndClient = handle;
2219            shrg.ptDown_x = x;
2220            shrg.ptDown_y = y;
2221            shrg.dwFlags = OS.SHRG_RETURNCMD;
2222            int type = OS.SHRecognizeGesture (shrg);
2223            if (type == OS.GN_CONTEXTMENU) {
2224                showMenu (x, y);
2225                return LRESULT.ONE;
2226            }
2227        }
2228        if (dispatch) {
2229            result = new LRESULT (callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam));
2230        } else {
2231            result = LRESULT.ZERO;
2232        }
2233        if (!display.captureChanged && !isDisposed ()) {
2234            if (OS.GetCapture () != handle) OS.SetCapture (handle);
2235        }
2236        return result;
2237    }
2238     return super.WM_LBUTTONDOWN (wParam, lParam);
2239}
2240
2241LRESULT WM_PASTE (int wParam, int lParam) {
2242    LRESULT result = super.WM_PASTE (wParam, lParam);
2243    if (result != null) return result;
2244    return wmClipboard (OS.WM_PASTE, wParam, lParam);
2245}
2246
2247LRESULT WM_UNDO (int wParam, int lParam) {
2248    LRESULT result = super.WM_UNDO (wParam, lParam);
2249    if (result != null) return result;
2250    return wmClipboard (OS.WM_UNDO, wParam, lParam);
2251}
2252
2253LRESULT wmClipboard (int msg, int wParam, int lParam) {
2254    if ((style & SWT.READ_ONLY) != 0) return null;
2255    if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return null;
2256    boolean call = false;
2257    int [] start = new int [1], end = new int [1];
2258    String JavaDoc newText = null;
2259    switch (msg) {
2260        case OS.WM_CLEAR:
2261        case OS.WM_CUT:
2262            OS.SendMessage (handle, OS.EM_GETSEL, start, end);
2263            if (start [0] != end [0]) {
2264                newText = "";
2265                call = true;
2266            }
2267            break;
2268        case OS.WM_PASTE:
2269            OS.SendMessage (handle, OS.EM_GETSEL, start, end);
2270            newText = getClipboardText ();
2271            break;
2272        case OS.EM_UNDO:
2273        case OS.WM_UNDO:
2274            if (OS.SendMessage (handle, OS.EM_CANUNDO, 0, 0) != 0) {
2275                ignoreModify = ignoreCharacter = true;
2276                OS.SendMessage (handle, OS.EM_GETSEL, start, end);
2277                callWindowProc (handle, msg, wParam, lParam);
2278                int length = OS.GetWindowTextLength (handle);
2279                int [] newStart = new int [1], newEnd = new int [1];
2280                OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd);
2281                if (length != 0 && newStart [0] != newEnd [0]) {
2282                    TCHAR buffer = new TCHAR (getCodePage (), length + 1);
2283                    OS.GetWindowText (handle, buffer, length + 1);
2284                    newText = buffer.toString (newStart [0], newEnd [0] - newStart [0]);
2285                } else {
2286                    newText = "";
2287                }
2288                callWindowProc (handle, msg, wParam, lParam);
2289                ignoreModify = ignoreCharacter = false;
2290            }
2291            break;
2292    }
2293    if (newText != null) {
2294        String JavaDoc oldText = newText;
2295        newText = verifyText (newText, start [0], end [0], null);
2296        if (newText == null) return LRESULT.ZERO;
2297        if (!newText.equals (oldText)) {
2298            if (call) {
2299                callWindowProc (handle, msg, wParam, lParam);
2300            }
2301            newText = Display.withCrLf (newText);
2302            TCHAR buffer = new TCHAR (getCodePage (), newText, true);
2303            /*
2304            * Feature in Windows. When an edit control with ES_MULTILINE
2305            * style that does not have the WS_VSCROLL style is full (i.e.
2306            * there is no space at the end to draw any more characters),
2307            * EM_REPLACESEL sends a WM_CHAR with a backspace character
2308            * to remove any further text that is added. This is an
2309            * implementation detail of the edit control that is unexpected
2310            * and can cause endless recursion when EM_REPLACESEL is sent
2311            * from a WM_CHAR handler. The fix is to ignore calling the
2312            * handler from WM_CHAR.
2313            */

2314            ignoreCharacter = true;
2315            OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
2316            ignoreCharacter = false;
2317            return LRESULT.ZERO;
2318        }
2319    }
2320    if (msg == OS.WM_UNDO) {
2321        ignoreVerify = ignoreCharacter = true;
2322        callWindowProc (handle, OS.WM_UNDO, wParam, lParam);
2323        ignoreVerify = ignoreCharacter = false;
2324        return LRESULT.ONE;
2325    }
2326    return null;
2327}
2328
2329LRESULT wmColorChild (int wParam, int lParam) {
2330    if ((style & SWT.READ_ONLY) != 0) {
2331        if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
2332            int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
2333            if ((bits & OS.ES_MULTILINE) != 0) {
2334                Control control = findBackgroundControl ();
2335                if (control == null && background == -1) {
2336                    if ((state & THEME_BACKGROUND) != 0) {
2337                        if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
2338                            control = findThemeControl ();
2339                            if (control != null) {
2340                                OS.SetTextColor (wParam, getForegroundPixel ());
2341                                OS.SetBkColor (wParam, getBackgroundPixel ());
2342                                OS.SetBkMode (wParam, OS.TRANSPARENT);
2343                                return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH));
2344                            }
2345                        }
2346                    }
2347                }
2348            }
2349        }
2350    }
2351    return super.wmColorChild (wParam, lParam);
2352}
2353
2354LRESULT wmCommandChild (int wParam, int lParam) {
2355    int code = wParam >> 16;
2356    switch (code) {
2357        case OS.EN_CHANGE:
2358            if (ignoreModify) break;
2359            /*
2360            * It is possible (but unlikely), that application
2361            * code could have disposed the widget in the modify
2362            * event. If this happens, end the processing of the
2363            * Windows message by returning zero as the result of
2364            * the window proc.
2365            */

2366            sendEvent (SWT.Modify);
2367            if (isDisposed ()) return LRESULT.ZERO;
2368            break;
2369        case OS.EN_ALIGN_LTR_EC:
2370            style &= ~SWT.RIGHT_TO_LEFT;
2371            style |= SWT.LEFT_TO_RIGHT;
2372            fixAlignment ();
2373            break;
2374        case OS.EN_ALIGN_RTL_EC:
2375            style &= ~SWT.LEFT_TO_RIGHT;
2376            style |= SWT.RIGHT_TO_LEFT;
2377            fixAlignment ();
2378            break;
2379    }
2380    return super.wmCommandChild (wParam, lParam);
2381}
2382
2383}
2384
Popular Tags