1 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 36 public class Text extends Scrollable { 37 int tabs, oldStart, oldEnd; 38 boolean doubleClick, ignoreModify, ignoreVerify, ignoreCharacter; 39 String message; 40 41 49 public static final int LIMIT; 50 51 56 public static final String DELIMITER; 57 58 61 63 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 82 } 95 96 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 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 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 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 249 public void append (String 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 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 306 public void clearSelection () { 307 checkWidget (); 308 if (OS.IsWinCE) { 309 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 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 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 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 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 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 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 527 return super.getBorderWidth (); 531 } 532 533 546 public int getCaretLineNumber () { 547 checkWidget (); 548 return OS.SendMessage (handle, OS.EM_LINEFROMCHAR, -1, 0); 549 } 550 551 565 public Point getCaretLocation () { 566 checkWidget (); 567 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 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 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 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 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 706 public boolean getDoubleClickEnabled () { 707 checkWidget (); 708 return doubleClick; 709 } 710 711 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 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 761 public int getLineCount () { 762 checkWidget (); 763 return OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0); 764 } 765 766 778 public String getLineDelimiter () { 779 checkWidget (); 780 return DELIMITER; 781 } 782 783 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 819 public int getOrientation () { 820 checkWidget(); 821 return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); 822 } 823 824 843 public String getMessage () { 844 checkWidget (); 845 return message; 846 } 847 848 865 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 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 914 public int getSelectionCount () { 915 checkWidget (); 916 Point selection = getSelection (); 917 return selection.y - selection.x; 918 } 919 920 930 public String 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 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 990 public String 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 1017public String 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 1029 return getText ().substring (start, end + 1); 1030} 1031 1032 1048public int getTextLimit () { 1049 checkWidget (); 1050 return OS.SendMessage (handle, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF; 1051} 1052 1053 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 1093public int getTopPixel () { 1094 checkWidget (); 1095 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 1122public void insert (String 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 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 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 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 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 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 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 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 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 1318 switch (msg) { 1319 case OS.WM_CHAR: 1320 if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break; 1321 case OS.WM_KEYDOWN: 1323 if ((stateMask & (SWT.ALT | SWT.SHIFT | SWT.CONTROL)) != 0) return false; 1324 break; 1325 } 1326 1327 1333 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) { 1334 if (handle == OS.GetCapture()) return true; 1335 } 1336 1337 1338 String 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: 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: 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': 1381 if ((style & SWT.SINGLE) != 0) return true; 1382 oldText = DELIMITER; 1383 break; 1384 default: 1385 if (key != '\t' && key < 0x20) return true; 1386 oldText = new String (new char [] {key}); 1387 break; 1388 } 1389 String 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 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 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 1470public void setDoubleClickEnabled (boolean doubleClick) { 1471 checkWidget (); 1472 this.doubleClick = doubleClick; 1473} 1474 1475 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 1508 OS.InvalidateRect (handle, null, true); 1509} 1510 1511 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 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 1571public void setMessage (String 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 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 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 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 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 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 1760public void setTabs (int tabs) { 1761 checkWidget (); 1762 if (tabs < 0) return; 1763 setTabStops (this.tabs = tabs); 1764} 1765 1766void setTabStops (int tabs) { 1767 1773 int width = (getTabWidth (tabs) * 4) / (OS.GetDialogBaseUnits () & 0xFFFF); 1774 OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, new int [] {width}); 1775} 1776 1777 1792public void setText (String 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 1812 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 1813 if ((bits & OS.ES_MULTILINE) != 0) { 1814 sendEvent (SWT.Modify); 1815 } 1817} 1818 1819 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 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 1883public void showSelection () { 1884 checkWidget (); 1885 OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); 1886} 1887 1888String verifyText (String 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 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 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 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 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 2028 switch (wParam) { 2029 case SWT.DEL: 2030 if (OS.GetKeyState (OS.VK_CONTROL) < 0) { 2031 return LRESULT.ZERO; 2032 } 2033 } 2034 2035 2042 if ((style & SWT.SINGLE) != 0) { 2043 switch (wParam) { 2044 case SWT.CR: 2045 postEvent (SWT.DefaultSelection); 2046 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 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 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 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 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 display.lastKey = display.lastAscii = 0; 2156 return new LRESULT (result); 2157} 2158 2159LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) { 2160 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 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 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 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 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 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 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 |