1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.*; 15 import org.eclipse.swt.internal.win32.*; 16 import org.eclipse.swt.*; 17 import org.eclipse.swt.graphics.*; 18 import org.eclipse.swt.events.*; 19 20 46 47 public abstract class Widget { 48 int style, state; 49 Display display; 50 EventTable eventTable; 51 Object data; 52 53 54 static final int DISPOSED = 1<<0; 55 static final int CANVAS = 1<<1; 56 static final int KEYED_DATA = 1<<2; 57 static final int DISABLED = 1<<3; 58 static final int HIDDEN = 1<<4; 59 60 61 static final int LAYOUT_NEEDED = 1<<5; 62 63 64 static final int LAYOUT_CHANGED = 1<<6; 65 66 67 static final int LAYOUT_CHILD = 1<<7; 68 69 70 static final int THEME_BACKGROUND = 1<<8; 71 static final int DRAW_BACKGROUND = 1<<9; 72 static final int PARENT_BACKGROUND = 1<<10; 73 74 75 static final int RELEASED = 1<<11; 76 static final int DISPOSE_SENT = 1<<12; 77 78 79 static final int TRACK_MOUSE = 1<<13; 80 static final int FOREIGN_HANDLE = 1<<14; 81 static final int DRAG_DETECT = 1<<15; 82 83 84 static final int DEFAULT_WIDTH = 64; 85 static final int DEFAULT_HEIGHT = 64; 86 87 88 static final int MAJOR = 5, MINOR = 80; 89 static { 90 if (!OS.IsWinCE) { 91 if (OS.COMCTL32_VERSION < OS.VERSION (MAJOR, MINOR)) { 92 System.out.println ("***WARNING: SWT requires comctl32.dll version " + MAJOR + "." + MINOR + " or greater"); System.out.println ("***WARNING: Detected: " + OS.COMCTL32_MAJOR + "." + OS.COMCTL32_MINOR); } 95 } 96 OS.InitCommonControls (); 97 } 98 99 102 Widget () { 103 } 104 105 134 public Widget (Widget parent, int style) { 135 checkSubclass (); 136 checkParent (parent); 137 this.style = style; 138 display = parent.display; 139 } 140 141 void _addListener (int eventType, Listener listener) { 142 if (eventTable == null) eventTable = new EventTable (); 143 eventTable.hook (eventType, listener); 144 } 145 146 169 public void addListener (int eventType, Listener listener) { 170 checkWidget(); 171 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 172 _addListener (eventType, listener); 173 } 174 175 194 public void addDisposeListener (DisposeListener listener) { 195 checkWidget(); 196 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 197 TypedListener typedListener = new TypedListener (listener); 198 addListener (SWT.Dispose, typedListener); 199 } 200 201 int callWindowProc (int hwnd, int msg, int wParam, int lParam) { 202 return 0; 203 } 204 205 222 static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) { 223 int mask = int0 | int1 | int2 | int3 | int4 | int5; 224 if ((style & mask) == 0) style |= int0; 225 if ((style & int0) != 0) style = (style & ~mask) | int0; 226 if ((style & int1) != 0) style = (style & ~mask) | int1; 227 if ((style & int2) != 0) style = (style & ~mask) | int2; 228 if ((style & int3) != 0) style = (style & ~mask) | int3; 229 if ((style & int4) != 0) style = (style & ~mask) | int4; 230 if ((style & int5) != 0) style = (style & ~mask) | int5; 231 return style; 232 } 233 234 void checkOrientation (Widget parent) { 235 style &= ~SWT.MIRRORED; 236 if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) { 237 if (parent != null) { 238 if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT; 239 if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT; 240 } 241 } 242 style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0); 243 } 244 245 void checkOpened () { 246 247 } 248 249 261 void checkParent (Widget parent) { 262 if (parent == null) error (SWT.ERROR_NULL_ARGUMENT); 263 if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); 264 parent.checkWidget (); 265 parent.checkOpened (); 266 } 267 268 297 protected void checkSubclass () { 298 if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); 299 } 300 301 323 protected void checkWidget () { 324 Display display = this.display; 325 if (display == null) error (SWT.ERROR_WIDGET_DISPOSED); 326 if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); 327 if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED); 328 } 329 330 349 void destroyWidget () { 350 releaseHandle (); 351 } 352 353 int DeferWindowPos(int hWinPosInfo, int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags){ 354 if (OS.IsWinCE) { 355 361 if ((uFlags & OS.SWP_NOSIZE) == 0) { 362 RECT lpRect = new RECT (); 363 OS.GetWindowRect (hWnd, lpRect); 364 if (cy == lpRect.bottom - lpRect.top && cx == lpRect.right - lpRect.left) { 365 372 uFlags &= ~OS.SWP_DRAWFRAME; 373 uFlags |= OS.SWP_NOSIZE; 374 } 375 } 376 } 377 return OS.DeferWindowPos (hWinPosInfo, hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags); 378 } 379 380 403 public void dispose () { 404 408 if (isDisposed ()) return; 409 if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); 410 release (true); 411 } 412 413 boolean dragDetect (int hwnd, int x, int y, boolean filter, boolean [] detect, boolean [] consume) { 414 if (consume != null) consume [0] = false; 415 if (detect != null) detect [0] = true; 416 POINT pt = new POINT (); 417 pt.x = x; 418 pt.y = y; 419 OS.ClientToScreen (hwnd, pt); 420 return OS.DragDetect (hwnd, pt); 421 } 422 423 431 void error (int code) { 432 SWT.error(code); 433 } 434 435 boolean filters (int eventType) { 436 return display.filters (eventType); 437 } 438 439 Widget findItem (int id) { 440 return null; 441 } 442 443 char [] fixMnemonic (String string) { 444 char [] buffer = new char [string.length ()]; 445 string.getChars (0, string.length (), buffer, 0); 446 int i = 0, j = 0; 447 while (i < buffer.length) { 448 if (buffer [i] == '&') { 449 if (i + 1 < buffer.length && buffer [i + 1] == '&') { 450 buffer [j++] = ' '; 451 i++; 452 } 453 i++; 454 } else { 455 buffer [j++] = buffer [i++]; 456 } 457 } 458 while (j < buffer.length) buffer [j++] = 0; 459 return buffer; 460 } 461 462 484 public Object getData () { 485 checkWidget(); 486 return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data; 487 } 488 489 513 public Object getData (String key) { 514 checkWidget(); 515 if (key == null) error (SWT.ERROR_NULL_ARGUMENT); 516 if ((state & KEYED_DATA) != 0) { 517 Object [] table = (Object []) data; 518 for (int i=1; i<table.length; i+=2) { 519 if (key.equals (table [i])) return table [i+1]; 520 } 521 } 522 return null; 523 } 524 525 540 public Display getDisplay () { 541 Display display = this.display; 542 if (display == null) error (SWT.ERROR_WIDGET_DISPOSED); 543 return display; 544 } 545 546 Menu getMenu () { 547 return null; 548 } 549 550 556 String getName () { 557 String string = getClass ().getName (); 558 int index = string.lastIndexOf ('.'); 559 if (index == -1) return string; 560 return string.substring (index + 1, string.length ()); 561 } 562 563 573 String getNameText () { 574 return ""; } 576 577 597 public int getStyle () { 598 checkWidget(); 599 return style; 600 } 601 602 615 boolean hooks (int eventType) { 616 if (eventTable == null) return false; 617 return eventTable.hooks (eventType); 618 } 619 620 631 public boolean isDisposed () { 632 return (state & DISPOSED) != 0; 633 } 634 635 651 public boolean isListening (int eventType) { 652 checkWidget(); 653 return hooks (eventType); 654 } 655 656 662 boolean isValidSubclass () { 663 return Display.isValidClass (getClass ()); 664 } 665 666 673 boolean isValidThread () { 674 return getDisplay ().isValidThread (); 675 } 676 677 void mapEvent (int hwnd, Event event) { 678 } 679 680 GC new_GC (GCData data) { 681 return null; 682 } 683 684 703 public void notifyListeners (int eventType, Event event) { 704 checkWidget(); 705 if (event == null) event = new Event (); 706 sendEvent (eventType, event); 707 } 708 709 void postEvent (int eventType) { 710 sendEvent (eventType, null, false); 711 } 712 713 void postEvent (int eventType, Event event) { 714 sendEvent (eventType, event, false); 715 } 716 717 737 void release (boolean destroy) { 738 if ((state & DISPOSE_SENT) == 0) { 739 state |= DISPOSE_SENT; 740 sendEvent (SWT.Dispose); 741 } 742 if ((state & DISPOSED) == 0) { 743 releaseChildren (destroy); 744 } 745 if ((state & RELEASED) == 0) { 746 state |= RELEASED; 747 if (destroy) { 748 releaseParent (); 749 releaseWidget (); 750 destroyWidget (); 751 } else { 752 releaseWidget (); 753 releaseHandle (); 754 } 755 } 756 } 757 758 void releaseChildren (boolean destroy) { 759 } 760 761 779 void releaseHandle () { 780 state |= DISPOSED; 781 display = null; 782 } 783 784 802 void releaseParent () { 803 } 804 805 825 void releaseWidget () { 826 eventTable = null; 827 data = null; 828 } 829 830 851 public void removeListener (int eventType, Listener listener) { 852 checkWidget(); 853 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 854 if (eventTable == null) return; 855 eventTable.unhook (eventType, listener); 856 } 857 858 882 protected void removeListener (int eventType, SWTEventListener listener) { 883 checkWidget(); 884 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 885 if (eventTable == null) return; 886 eventTable.unhook (eventType, listener); 887 } 888 889 906 public void removeDisposeListener (DisposeListener listener) { 907 checkWidget(); 908 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 909 if (eventTable == null) return; 910 eventTable.unhook (SWT.Dispose, listener); 911 } 912 913 boolean sendDragEvent (int button, int x, int y) { 914 Event event = new Event (); 915 event.button = button; 916 event.x = x; 917 event.y = y; 918 setInputState (event, SWT.DragDetect); 919 postEvent (SWT.DragDetect, event); 920 if (isDisposed ()) return false; 921 return event.doit; 922 } 923 924 boolean sendDragEvent (int button, int stateMask, int x, int y) { 925 Event event = new Event (); 926 event.button = button; 927 event.x = x; 928 event.y = y; 929 event.stateMask = stateMask; 930 postEvent (SWT.DragDetect, event); 931 if (isDisposed ()) return false; 932 return event.doit; 933 } 934 935 void sendEvent (Event event) { 936 Display display = event.display; 937 if (!display.filterEvent (event)) { 938 if (eventTable != null) eventTable.sendEvent (event); 939 } 940 } 941 942 void sendEvent (int eventType) { 943 sendEvent (eventType, null, true); 944 } 945 946 void sendEvent (int eventType, Event event) { 947 sendEvent (eventType, event, true); 948 } 949 950 void sendEvent (int eventType, Event event, boolean send) { 951 if (eventTable == null && !display.filters (eventType)) { 952 return; 953 } 954 if (event == null) event = new Event (); 955 event.type = eventType; 956 event.display = display; 957 event.widget = this; 958 if (event.time == 0) { 959 event.time = display.getLastEventTime (); 960 } 961 if (send) { 962 sendEvent (event); 963 } else { 964 display.postEvent (event); 965 } 966 } 967 968 boolean sendKeyEvent (int type, int msg, int wParam, int lParam) { 969 Event event = new Event (); 970 if (!setKeyState (event, type, wParam, lParam)) return true; 971 return sendKeyEvent (type, msg, wParam, lParam, event); 972 } 973 974 boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) { 975 sendEvent (type, event); 976 if (isDisposed ()) return false; 977 return event.doit; 978 } 979 980 boolean sendMouseEvent (int type, int button, int hwnd, int msg, int wParam, int lParam) { 981 return sendMouseEvent (type, button, display.getClickCount (type, button, hwnd, lParam), 0, false, hwnd, msg, wParam, lParam); 982 } 983 984 boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int hwnd, int msg, int wParam, int lParam) { 985 if (!hooks (type) && !filters (type)) return true; 986 Event event = new Event (); 987 event.button = button; 988 event.detail = detail; 989 event.count = count; 990 event.x = (short) (lParam & 0xFFFF); 991 event.y = (short) (lParam >> 16); 992 setInputState (event, type); 993 mapEvent (hwnd, event); 994 if (send) { 995 sendEvent (type, event); 996 if (isDisposed ()) return false; 997 } else { 998 postEvent (type, event); 999 } 1000 return event.doit; 1001} 1002 1003 1025public void setData (Object data) { 1026 checkWidget(); 1027 if ((state & KEYED_DATA) != 0) { 1028 ((Object []) this.data) [0] = data; 1029 } else { 1030 this.data = data; 1031 } 1032} 1033 1034 1058public void setData (String key, Object value) { 1059 checkWidget(); 1060 if (key == null) error (SWT.ERROR_NULL_ARGUMENT); 1061 int index = 1; 1062 Object [] table = null; 1063 if ((state & KEYED_DATA) != 0) { 1064 table = (Object []) data; 1065 while (index < table.length) { 1066 if (key.equals (table [index])) break; 1067 index += 2; 1068 } 1069 } 1070 if (value != null) { 1071 if ((state & KEYED_DATA) != 0) { 1072 if (index == table.length) { 1073 Object [] newTable = new Object [table.length + 2]; 1074 System.arraycopy (table, 0, newTable, 0, table.length); 1075 data = table = newTable; 1076 } 1077 } else { 1078 table = new Object [3]; 1079 table [0] = data; 1080 data = table; 1081 state |= KEYED_DATA; 1082 } 1083 table [index] = key; 1084 table [index + 1] = value; 1085 } else { 1086 if ((state & KEYED_DATA) != 0) { 1087 if (index != table.length) { 1088 int length = table.length - 2; 1089 if (length == 1) { 1090 data = table [0]; 1091 state &= ~KEYED_DATA; 1092 } else { 1093 Object [] newTable = new Object [length]; 1094 System.arraycopy (table, 0, newTable, 0, index); 1095 System.arraycopy (table, index + 2, newTable, index, length - index); 1096 data = newTable; 1097 } 1098 } 1099 } 1100 } 1101} 1102 1103boolean sendFocusEvent (int type) { 1104 sendEvent (type); 1105 return true; 1107} 1108 1109boolean setInputState (Event event, int type) { 1110 if (OS.GetKeyState (OS.VK_MENU) < 0) event.stateMask |= SWT.ALT; 1111 if (OS.GetKeyState (OS.VK_SHIFT) < 0) event.stateMask |= SWT.SHIFT; 1112 if (OS.GetKeyState (OS.VK_CONTROL) < 0) event.stateMask |= SWT.CONTROL; 1113 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) event.stateMask |= SWT.BUTTON1; 1114 if (OS.GetKeyState (OS.VK_MBUTTON) < 0) event.stateMask |= SWT.BUTTON2; 1115 if (OS.GetKeyState (OS.VK_RBUTTON) < 0) event.stateMask |= SWT.BUTTON3; 1116 if (OS.GetKeyState (OS.VK_XBUTTON1) < 0) event.stateMask |= SWT.BUTTON4; 1117 if (OS.GetKeyState (OS.VK_XBUTTON2) < 0) event.stateMask |= SWT.BUTTON5; 1118 switch (type) { 1119 case SWT.MouseDown: 1120 case SWT.MouseDoubleClick: 1121 if (event.button == 1) event.stateMask &= ~SWT.BUTTON1; 1122 if (event.button == 2) event.stateMask &= ~SWT.BUTTON2; 1123 if (event.button == 3) event.stateMask &= ~SWT.BUTTON3; 1124 if (event.button == 4) event.stateMask &= ~SWT.BUTTON4; 1125 if (event.button == 5) event.stateMask &= ~SWT.BUTTON5; 1126 break; 1127 case SWT.MouseUp: 1128 if (event.button == 1) event.stateMask |= SWT.BUTTON1; 1129 if (event.button == 2) event.stateMask |= SWT.BUTTON2; 1130 if (event.button == 3) event.stateMask |= SWT.BUTTON3; 1131 if (event.button == 4) event.stateMask |= SWT.BUTTON4; 1132 if (event.button == 5) event.stateMask |= SWT.BUTTON5; 1133 break; 1134 case SWT.KeyDown: 1135 case SWT.Traverse: 1136 if (event.keyCode == SWT.ALT) event.stateMask &= ~SWT.ALT; 1137 if (event.keyCode == SWT.SHIFT) event.stateMask &= ~SWT.SHIFT; 1138 if (event.keyCode == SWT.CONTROL) event.stateMask &= ~SWT.CONTROL; 1139 break; 1140 case SWT.KeyUp: 1141 if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT; 1142 if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT; 1143 if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL; 1144 break; 1145 } 1146 return true; 1147} 1148 1149boolean setKeyState (Event event, int type, int wParam, int lParam) { 1150 1151 1158 switch (display.lastAscii) { 1159 case SWT.DEL: 1160 if (display.lastKey == SWT.BS) display.lastAscii = SWT.BS; 1161 break; 1162 case SWT.LF: 1163 if (display.lastKey == SWT.CR) display.lastAscii = SWT.CR; 1164 break; 1165 } 1166 1167 1174 if (display.lastKey == SWT.CR && display.lastAscii == SWT.CR) { 1175 if ((lParam & 0x1000000) != 0) display.lastKey = SWT.KEYPAD_CR; 1176 } 1177 1178 if (display.lastVirtual) { 1179 1186 if (display.lastKey == OS.VK_DELETE) display.lastAscii = 0x7F; 1187 1188 1196 if (display.lastKey == OS.VK_CANCEL) display.lastAscii = 0x0; 1197 1198 event.keyCode = Display.translateKey (display.lastKey); 1199 } else { 1200 event.keyCode = display.lastKey; 1201 } 1202 if (display.lastAscii != 0 || display.lastNull) { 1203 event.character = Display.mbcsToWcs ((char) display.lastAscii); 1204 } 1205 if (event.keyCode == 0 && event.character == 0) { 1206 if (!display.lastNull) return false; 1207 } 1208 return setInputState (event, type); 1209} 1210 1211boolean SetWindowPos (int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) { 1212 if (OS.IsWinCE) { 1213 1219 if ((uFlags & OS.SWP_NOSIZE) == 0) { 1220 RECT lpRect = new RECT (); 1221 OS.GetWindowRect (hWnd, lpRect); 1222 if (cy == lpRect.bottom - lpRect.top && cx == lpRect.right - lpRect.left) { 1223 1230 uFlags &= ~OS.SWP_DRAWFRAME; 1231 uFlags |= OS.SWP_NOSIZE; 1232 } 1233 } 1234 } 1235 return OS.SetWindowPos (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags); 1236} 1237 1238boolean showMenu (int x, int y) { 1239 Event event = new Event (); 1240 event.x = x; 1241 event.y = y; 1242 sendEvent (SWT.MenuDetect, event); 1243 if (!event.doit) return true; 1244 Menu menu = getMenu (); 1245 if (menu != null && !menu.isDisposed ()) { 1246 if (x != event.x || y != event.y) { 1247 menu.setLocation (event.x, event.y); 1248 } 1249 menu.setVisible (true); 1250 return true; 1251 } 1252 return false; 1253} 1254 1255 1261public String toString () { 1262 String string = "*Disposed*"; if (!isDisposed ()) { 1264 string = "*Wrong Thread*"; if (isValidThread ()) string = getNameText (); 1266 } 1267 return getName () + " {" + string + "}"; } 1269 1270LRESULT wmCaptureChanged (int hwnd, int wParam, int lParam) { 1271 display.captureChanged = true; 1272 return null; 1273} 1274 1275LRESULT wmChar (int hwnd, int wParam, int lParam) { 1276 1279 if (!OS.IsUnicode && OS.IsDBLocale) { 1280 byte lead = (byte) (wParam & 0xFF); 1281 if (OS.IsDBCSLeadByte (lead)) return null; 1282 } 1283 display.lastAscii = wParam; 1284 display.lastNull = wParam == 0; 1285 if (!sendKeyEvent (SWT.KeyDown, OS.WM_CHAR, wParam, lParam)) { 1286 return LRESULT.ONE; 1287 } 1288 return null; 1290} 1291 1292LRESULT wmContextMenu (int hwnd, int wParam, int lParam) { 1293 if (wParam != hwnd) return null; 1294 1295 1306 if (OS.IsWinCE) return null; 1307 1308 1319 int x = 0, y = 0; 1320 if (lParam != -1) { 1321 POINT pt = new POINT (); 1322 x = pt.x = (short) (lParam & 0xFFFF); 1323 y = pt.y = (short) (lParam >> 16); 1324 OS.ScreenToClient (hwnd, pt); 1325 RECT rect = new RECT (); 1326 OS.GetClientRect (hwnd, rect); 1327 if (!OS.PtInRect (rect, pt)) return null; 1328 } else { 1329 int pos = OS.GetMessagePos (); 1330 x = (short) (pos & 0xFFFF); 1331 y = (short) (pos >> 16); 1332 } 1333 1334 1335 return showMenu (x, y) ? LRESULT.ZERO : null; 1336} 1337 1338LRESULT wmIMEChar (int hwnd, int wParam, int lParam) { 1339 Display display = this.display; 1340 display.lastKey = 0; 1341 display.lastAscii = wParam; 1342 display.lastVirtual = display.lastNull = display.lastDead = false; 1343 if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) { 1344 return LRESULT.ONE; 1345 } 1346 sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam); 1347 display.lastKey = display.lastAscii = 0; 1349 return LRESULT.ONE; 1350} 1351 1352LRESULT wmKeyDown (int hwnd, int wParam, int lParam) { 1353 1354 1355 switch (wParam) { 1356 case OS.VK_SHIFT: 1357 case OS.VK_MENU: 1358 case OS.VK_CONTROL: 1359 case OS.VK_CAPITAL: 1360 case OS.VK_NUMLOCK: 1361 case OS.VK_SCROLL: 1362 if ((lParam & 0x40000000) != 0) return null; 1363 } 1364 1365 1366 display.lastAscii = display.lastKey = 0; 1367 display.lastVirtual = display.lastNull = display.lastDead = false; 1368 1369 1372 if (!OS.IsUnicode && OS.IsDBLocale) { 1373 byte lead = (byte) (wParam & 0xFF); 1374 if (OS.IsDBCSLeadByte (lead)) return null; 1375 } 1376 1377 1378 1387 int mapKey = 0; 1388 if (OS.IsWinCE) { 1389 switch (wParam) { 1390 case OS.VK_BACK: mapKey = SWT.BS; break; 1391 case OS.VK_RETURN: mapKey = SWT.CR; break; 1392 case OS.VK_DELETE: mapKey = SWT.DEL; break; 1393 case OS.VK_ESCAPE: mapKey = SWT.ESC; break; 1394 case OS.VK_TAB: mapKey = SWT.TAB; break; 1395 } 1396 } else { 1397 mapKey = OS.MapVirtualKey (wParam, 2); 1398 } 1399 1400 1417 if (OS.IsWinNT) { 1418 if ((mapKey & 0x80000000) != 0) return null; 1419 } else { 1420 if ((mapKey & 0x8000) != 0) return null; 1421 } 1422 MSG msg = new MSG (); 1423 int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE; 1424 if (OS.PeekMessage (msg, hwnd, OS.WM_DEADCHAR, OS.WM_DEADCHAR, flags)) { 1425 display.lastDead = true; 1426 display.lastVirtual = mapKey == 0; 1427 display.lastKey = display.lastVirtual ? wParam : mapKey; 1428 return null; 1429 } 1430 1431 1442 if (isDisposed ()) return LRESULT.ONE; 1443 1444 1464 display.lastVirtual = mapKey == 0 || display.numpadKey (wParam) != 0; 1465 if (display.lastVirtual) { 1466 display.lastKey = wParam; 1467 1474 if (display.lastKey == OS.VK_DELETE) display.lastAscii = 0x7F; 1475 1476 1485 if (OS.VK_NUMPAD0 <= display.lastKey && display.lastKey <= OS.VK_DIVIDE) { 1486 1494 if (display.asciiKey (display.lastKey) != 0) return null; 1495 display.lastAscii = display.numpadKey (display.lastKey); 1496 } 1497 } else { 1498 1504 display.lastKey = OS.CharLower ((short) mapKey); 1505 1506 1513 if (wParam == OS.VK_CANCEL) display.lastVirtual = true; 1514 1515 1523 int asciiKey = display.asciiKey (wParam); 1524 if (asciiKey != 0) { 1525 1532 if (asciiKey == ' ') return null; 1533 if (asciiKey != wParam) return null; 1534 1541 if (wParam == OS.VK_CANCEL) return null; 1542 } 1543 1544 1550 if (OS.GetKeyState (OS.VK_CONTROL) >= 0) return null; 1551 1552 1559 if (OS.GetKeyState (OS.VK_SHIFT) < 0) { 1560 display.lastAscii = display.shiftedKey (wParam); 1561 if (display.lastAscii == 0) display.lastAscii = mapKey; 1562 } else { 1563 display.lastAscii = OS.CharLower ((short) mapKey); 1564 } 1565 1566 1567 if (display.lastAscii == '@') return null; 1568 display.lastAscii = display.controlKey (display.lastAscii); 1569 } 1570 if (!sendKeyEvent (SWT.KeyDown, OS.WM_KEYDOWN, wParam, lParam)) { 1571 return LRESULT.ONE; 1572 } 1573 return null; 1575} 1576 1577LRESULT wmKeyUp (int hwnd, int wParam, int lParam) { 1578 Display display = this.display; 1579 1580 1581 if (OS.IsWinCE) { 1582 if (OS.VK_APP1 <= wParam && wParam <= OS.VK_APP6) { 1583 display.lastKey = display.lastAscii = 0; 1584 display.lastVirtual = display.lastNull = display.lastDead = false; 1585 Event event = new Event (); 1586 event.detail = wParam - OS.VK_APP1 + 1; 1587 1588 int type = (lParam & 0x40000000) != 0 ? SWT.HardKeyUp : SWT.HardKeyDown; 1589 if (setInputState (event, type)) sendEvent (type, event); 1590 return null; 1592 } 1593 } 1594 1595 1599 if (!hooks (SWT.KeyUp) && !display.filters (SWT.KeyUp)) { 1600 display.lastKey = display.lastAscii = 0; 1601 display.lastVirtual = display.lastNull = display.lastDead = false; 1602 return null; 1603 } 1604 1605 1606 1615 int mapKey = 0; 1616 if (OS.IsWinCE) { 1617 switch (wParam) { 1618 case OS.VK_BACK: mapKey = SWT.BS; break; 1619 case OS.VK_RETURN: mapKey = SWT.CR; break; 1620 case OS.VK_DELETE: mapKey = SWT.DEL; break; 1621 case OS.VK_ESCAPE: mapKey = SWT.ESC; break; 1622 case OS.VK_TAB: mapKey = SWT.TAB; break; 1623 } 1624 } else { 1625 mapKey = OS.MapVirtualKey (wParam, 2); 1626 } 1627 1628 1638 if (OS.IsWinNT) { 1639 if ((mapKey & 0x80000000) != 0) return null; 1640 } else { 1641 if ((mapKey & 0x8000) != 0) return null; 1642 } 1643 if (display.lastDead) return null; 1644 1645 1651 display.lastVirtual = mapKey == 0 || display.numpadKey (wParam) != 0; 1652 if (display.lastVirtual) { 1653 display.lastKey = wParam; 1654 } else { 1655 1662 if (wParam == OS.VK_CANCEL) display.lastVirtual = true; 1663 if (display.lastKey == 0) { 1664 display.lastAscii = 0; 1665 display.lastNull = display.lastDead = false; 1666 return null; 1667 } 1668 } 1669 LRESULT result = null; 1670 if (!sendKeyEvent (SWT.KeyUp, OS.WM_KEYUP, wParam, lParam)) { 1671 result = LRESULT.ONE; 1672 } 1673 display.lastKey = display.lastAscii = 0; 1675 display.lastVirtual = display.lastNull = display.lastDead = false; 1676 return result; 1677} 1678 1679LRESULT wmKillFocus (int hwnd, int wParam, int lParam) { 1680 int code = callWindowProc (hwnd, OS.WM_KILLFOCUS, wParam, lParam); 1681 sendFocusEvent (SWT.FocusOut); 1682 1684 1691 if (isDisposed ()) return LRESULT.ZERO; 1692 if (code == 0) return LRESULT.ZERO; 1693 return new LRESULT (code); 1694} 1695 1696LRESULT wmLButtonDblClk (int hwnd, int wParam, int lParam) { 1697 1710 LRESULT result = null; 1711 Display display = this.display; 1712 display.captureChanged = false; 1713 sendMouseEvent (SWT.MouseDown, 1, hwnd, OS.WM_LBUTTONDOWN, wParam, lParam); 1714 if (sendMouseEvent (SWT.MouseDoubleClick, 1, hwnd, OS.WM_LBUTTONDBLCLK, wParam, lParam)) { 1715 result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONDBLCLK, wParam, lParam)); 1716 } else { 1717 result = LRESULT.ZERO; 1718 } 1719 if (!display.captureChanged && !isDisposed ()) { 1720 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 1721 } 1722 return result; 1723} 1724 1725LRESULT wmLButtonDown (int hwnd, int wParam, int lParam) { 1726 Display display = this.display; 1727 LRESULT result = null; 1728 int x = (short) (lParam & 0xFFFF); 1729 int y = (short) (lParam >> 16); 1730 boolean [] consume = null, detect = null; 1731 boolean dragging = false, mouseDown = true; 1732 int count = display.getClickCount (SWT.MouseDown, 1, hwnd, lParam); 1733 if (count == 1 && (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) { 1734 if (!OS.IsWinCE) { 1735 1743 detect = new boolean [1]; 1744 consume = new boolean [1]; 1745 dragging = dragDetect (hwnd, x, y, true, detect, consume); 1746 if (isDisposed ()) return LRESULT.ZERO; 1747 mouseDown = OS.GetKeyState (OS.VK_LBUTTON) < 0; 1748 } 1749 } 1750 display.captureChanged = false; 1751 boolean dispatch = sendMouseEvent (SWT.MouseDown, 1, count, 0, false, hwnd, OS.WM_LBUTTONDOWN, wParam, lParam); 1752 if (dispatch && (consume == null || !consume [0])) { 1753 result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONDOWN, wParam, lParam)); 1754 } else { 1755 result = LRESULT.ZERO; 1756 } 1757 if (OS.IsPPC) { 1758 1763 Menu menu = getMenu (); 1764 boolean hasMenu = menu != null && !menu.isDisposed (); 1765 if (hasMenu || hooks (SWT.MenuDetect)) { 1766 SHRGINFO shrg = new SHRGINFO (); 1767 shrg.cbSize = SHRGINFO.sizeof; 1768 shrg.hwndClient = hwnd; 1769 shrg.ptDown_x = x; 1770 shrg.ptDown_y = y; 1771 shrg.dwFlags = OS.SHRG_RETURNCMD; 1772 int type = OS.SHRecognizeGesture (shrg); 1773 if (type == OS.GN_CONTEXTMENU) showMenu (x, y); 1774 } 1775 } 1776 if (mouseDown) { 1777 if (!display.captureChanged && !isDisposed ()) { 1778 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 1779 } 1780 } 1781 if (dragging) { 1782 sendDragEvent (1, x, y); 1783 } else { 1784 if (detect != null && detect [0]) { 1785 1805 if (OS.GetKeyState (OS.VK_ESCAPE) >= 0) { 1806 OS.SendMessage (hwnd, OS.WM_LBUTTONUP, wParam, lParam); 1807 } 1808 } 1809 } 1810 return result; 1811} 1812 1813LRESULT wmLButtonUp (int hwnd, int wParam, int lParam) { 1814 Display display = this.display; 1815 LRESULT result = null; 1816 if (sendMouseEvent (SWT.MouseUp, 1, hwnd, OS.WM_LBUTTONUP, wParam, lParam)) { 1817 result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONUP, wParam, lParam)); 1818 } else { 1819 result = LRESULT.ZERO; 1820 } 1821 1827 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 1828 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 1829 if (((wParam & 0xFFFF) & mask) == 0) { 1830 if (OS.GetCapture () == hwnd) OS.ReleaseCapture (); 1831 } 1832 return result; 1833} 1834 1835LRESULT wmMButtonDblClk (int hwnd, int wParam, int lParam) { 1836 1849 LRESULT result = null; 1850 Display display = this.display; 1851 display.captureChanged = false; 1852 sendMouseEvent (SWT.MouseDown, 2, hwnd, OS.WM_MBUTTONDOWN, wParam, lParam); 1853 if (sendMouseEvent (SWT.MouseDoubleClick, 2, hwnd, OS.WM_MBUTTONDBLCLK, wParam, lParam)) { 1854 result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONDBLCLK, wParam, lParam)); 1855 } else { 1856 result = LRESULT.ZERO; 1857 } 1858 if (!display.captureChanged && !isDisposed ()) { 1859 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 1860 } 1861 return result; 1862} 1863 1864LRESULT wmMButtonDown (int hwnd, int wParam, int lParam) { 1865 LRESULT result = null; 1866 Display display = this.display; 1867 display.captureChanged = false; 1868 if (sendMouseEvent (SWT.MouseDown, 2, hwnd, OS.WM_MBUTTONDOWN, wParam, lParam)) { 1869 result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONDOWN, wParam, lParam)); 1870 } else { 1871 result = LRESULT.ZERO; 1872 } 1873 if (!display.captureChanged && !isDisposed ()) { 1874 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 1875 } 1876 return result; 1877} 1878 1879LRESULT wmMButtonUp (int hwnd, int wParam, int lParam) { 1880 Display display = this.display; 1881 LRESULT result = null; 1882 if (sendMouseEvent (SWT.MouseUp, 2, hwnd, OS.WM_MBUTTONUP, wParam, lParam)) { 1883 result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONUP, wParam, lParam)); 1884 } else { 1885 result = LRESULT.ZERO; 1886 } 1887 1893 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 1894 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 1895 if (((wParam & 0xFFFF) & mask) == 0) { 1896 if (OS.GetCapture () == hwnd) OS.ReleaseCapture (); 1897 } 1898 return result; 1899} 1900 1901LRESULT wmMouseHover (int hwnd, int wParam, int lParam) { 1902 if (!sendMouseEvent (SWT.MouseHover, 0, hwnd, OS.WM_MOUSEHOVER, wParam, lParam)) { 1903 return LRESULT.ZERO; 1904 } 1905 return null; 1906} 1907 1908LRESULT wmMouseLeave (int hwnd, int wParam, int lParam) { 1909 if (!hooks (SWT.MouseExit) && !filters (SWT.MouseExit)) return null; 1910 int pos = OS.GetMessagePos (); 1911 POINT pt = new POINT (); 1912 pt.x = (short) (pos & 0xFFFF); 1913 pt.y = (short) (pos >> 16); 1914 OS.ScreenToClient (hwnd, pt); 1915 lParam = (pt.x & 0xFFFF) | ((pt.y << 16) & 0xFFFF0000); 1916 if (!sendMouseEvent (SWT.MouseExit, 0, hwnd, OS.WM_MOUSELEAVE, wParam, lParam)) { 1917 return LRESULT.ZERO; 1918 } 1919 return null; 1920} 1921 1922LRESULT wmMouseMove (int hwnd, int wParam, int lParam) { 1923 LRESULT result = null; 1924 Display display = this.display; 1925 int pos = OS.GetMessagePos (); 1926 if (pos != display.lastMouse || display.captureChanged) { 1927 if (!OS.IsWinCE) { 1928 boolean trackMouse = (state & TRACK_MOUSE) != 0; 1929 boolean mouseEnter = hooks (SWT.MouseEnter) || display.filters (SWT.MouseEnter); 1930 boolean mouseExit = hooks (SWT.MouseExit) || display.filters (SWT.MouseExit); 1931 boolean mouseHover = hooks (SWT.MouseHover) || display.filters (SWT.MouseHover); 1932 if (trackMouse || mouseEnter || mouseExit || mouseHover) { 1933 TRACKMOUSEEVENT lpEventTrack = new TRACKMOUSEEVENT (); 1934 lpEventTrack.cbSize = TRACKMOUSEEVENT.sizeof; 1935 lpEventTrack.dwFlags = OS.TME_QUERY; 1936 lpEventTrack.hwndTrack = hwnd; 1937 OS.TrackMouseEvent (lpEventTrack); 1938 if (lpEventTrack.dwFlags == 0) { 1939 lpEventTrack.dwFlags = OS.TME_LEAVE | OS.TME_HOVER; 1940 lpEventTrack.hwndTrack = hwnd; 1941 OS.TrackMouseEvent (lpEventTrack); 1942 if (mouseEnter) { 1943 1949 MSG msg = new MSG (); 1950 int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE; 1951 while (OS.PeekMessage (msg, 0, OS.WM_MOUSELEAVE, OS.WM_MOUSELEAVE, flags)) { 1952 OS.TranslateMessage (msg); 1953 OS.DispatchMessage (msg); 1954 } 1955 sendMouseEvent (SWT.MouseEnter, 0, hwnd, OS.WM_MOUSEMOVE, wParam, lParam); 1956 } 1957 } else { 1958 lpEventTrack.dwFlags = OS.TME_HOVER; 1959 OS.TrackMouseEvent (lpEventTrack); 1960 } 1961 } 1962 } 1963 if (pos != display.lastMouse) { 1964 display.lastMouse = pos; 1965 if (!sendMouseEvent (SWT.MouseMove, 0, hwnd, OS.WM_MOUSEMOVE, wParam, lParam)) { 1966 result = LRESULT.ZERO; 1967 } 1968 } 1969 } 1970 display.captureChanged = false; 1971 return result; 1972} 1973 1974LRESULT wmMouseWheel (int hwnd, int wParam, int lParam) { 1975 if (!hooks (SWT.MouseWheel) && !filters (SWT.MouseWheel)) return null; 1976 int delta = wParam >> 16; 1977 int [] value = new int [1]; 1978 int count, detail; 1979 OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, value, 0); 1980 if (value [0] == OS.WHEEL_PAGESCROLL) { 1981 detail = SWT.SCROLL_PAGE; 1982 count = delta / OS.WHEEL_DELTA; 1983 } else { 1984 detail = SWT.SCROLL_LINE; 1985 count = value [0] * delta / OS.WHEEL_DELTA; 1986 } 1987 POINT pt = new POINT (); 1988 pt.x = (short) (lParam & 0xFFFF); 1989 pt.y = (short) (lParam >> 16); 1990 OS.ScreenToClient (hwnd, pt); 1991 lParam = (pt.x & 0xFFFF) | ((pt.y << 16) & 0xFFFF0000); 1992 if (!sendMouseEvent (SWT.MouseWheel, 0, count, detail, true, hwnd, OS.WM_MOUSEWHEEL, wParam, lParam)) { 1993 return LRESULT.ZERO; 1994 } 1995 return null; 1996} 1997 1998LRESULT wmPaint (int hwnd, int wParam, int lParam) { 1999 2000 2001 if (!hooks (SWT.Paint) && !filters (SWT.Paint)) { 2002 return null; 2003 } 2004 2005 2006 int result = 0; 2007 if (OS.IsWinCE) { 2008 RECT rect = new RECT (); 2009 OS.GetUpdateRect (hwnd, rect, false); 2010 result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam); 2011 2019 OS.HideCaret (hwnd); 2020 OS.InvalidateRect (hwnd, rect, false); 2021 OS.ShowCaret (hwnd); 2022 PAINTSTRUCT ps = new PAINTSTRUCT (); 2023 GCData data = new GCData (); 2024 data.ps = ps; 2025 data.hwnd = hwnd; 2026 GC gc = new_GC (data); 2027 if (gc != null) { 2028 int width = ps.right - ps.left; 2029 int height = ps.bottom - ps.top; 2030 if (width != 0 && height != 0) { 2031 Event event = new Event (); 2032 event.gc = gc; 2033 event.x = ps.left; 2034 event.y = ps.top; 2035 event.width = width; 2036 event.height = height; 2037 sendEvent (SWT.Paint, event); 2038 event.gc = null; 2040 } 2041 gc.dispose (); 2042 } 2043 } else { 2044 int rgn = OS.CreateRectRgn (0, 0, 0, 0); 2045 OS.GetUpdateRgn (hwnd, rgn, false); 2046 result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam); 2047 GCData data = new GCData (); 2048 data.hwnd = hwnd; 2049 GC gc = new_GC (data); 2050 if (gc != null) { 2051 OS.HideCaret (hwnd); 2052 RECT rect = new RECT(); 2053 OS.GetRgnBox (rgn, rect); 2054 int width = rect.right - rect.left; 2055 int height = rect.bottom - rect.top; 2056 if (width != 0 && height != 0) { 2057 int hDC = gc.handle; 2058 OS.SelectClipRgn (hDC, rgn); 2059 OS.SetMetaRgn (hDC); 2060 Event event = new Event (); 2061 event.gc = gc; 2062 event.x = rect.left; 2063 event.y = rect.top; 2064 event.width = width; 2065 event.height = height; 2066 sendEvent (SWT.Paint, event); 2067 event.gc = null; 2069 } 2070 gc.dispose (); 2071 OS.ShowCaret (hwnd); 2072 } 2073 OS.DeleteObject (rgn); 2074 } 2075 if (result == 0) return LRESULT.ZERO; 2076 return new LRESULT (result); 2077} 2078 2079LRESULT wmPrint (int hwnd, int wParam, int lParam) { 2080 2086 if ((lParam & OS.PRF_NONCLIENT) != 0) { 2087 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 2088 int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE); 2089 if ((bits & OS.WS_EX_CLIENTEDGE) != 0) { 2090 int code = callWindowProc (hwnd, OS.WM_PRINT, wParam, lParam); 2091 RECT rect = new RECT (); 2092 OS.GetWindowRect (hwnd, rect); 2093 rect.right -= rect.left; 2094 rect.bottom -= rect.top; 2095 rect.left = rect.top = 0; 2096 int border = OS.GetSystemMetrics (OS.SM_CXEDGE); 2097 OS.ExcludeClipRect (wParam, border, border, rect.right - border, rect.bottom - border); 2098 OS.DrawThemeBackground (display.hEditTheme (), wParam, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null); 2099 return new LRESULT (code); 2100 } 2101 } 2102 } 2103 return null; 2104} 2105 2106LRESULT wmRButtonDblClk (int hwnd, int wParam, int lParam) { 2107 2120 LRESULT result = null; 2121 Display display = this.display; 2122 display.captureChanged = false; 2123 sendMouseEvent (SWT.MouseDown, 3, hwnd, OS.WM_RBUTTONDOWN, wParam, lParam); 2124 if (sendMouseEvent (SWT.MouseDoubleClick, 3, hwnd, OS.WM_RBUTTONDBLCLK, wParam, lParam)) { 2125 result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONDBLCLK, wParam, lParam)); 2126 } else { 2127 result = LRESULT.ZERO; 2128 } 2129 if (!display.captureChanged && !isDisposed ()) { 2130 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 2131 } 2132 return result; 2133} 2134 2135LRESULT wmRButtonDown (int hwnd, int wParam, int lParam) { 2136 LRESULT result = null; 2137 Display display = this.display; 2138 display.captureChanged = false; 2139 if (sendMouseEvent (SWT.MouseDown, 3, hwnd, OS.WM_RBUTTONDOWN, wParam, lParam)) { 2140 result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONDOWN, wParam, lParam)); 2141 } else { 2142 result = LRESULT.ZERO; 2143 } 2144 if (!display.captureChanged && !isDisposed ()) { 2145 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 2146 } 2147 return result; 2148} 2149 2150LRESULT wmRButtonUp (int hwnd, int wParam, int lParam) { 2151 Display display = this.display; 2152 LRESULT result = null; 2153 if (sendMouseEvent (SWT.MouseUp, 3, hwnd, OS.WM_RBUTTONUP, wParam, lParam)) { 2154 result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONUP, wParam, lParam)); 2155 } else { 2156 2157 OS.DefWindowProc (hwnd, OS.WM_RBUTTONUP, wParam, lParam); 2158 result = LRESULT.ZERO; 2159 } 2160 2166 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 2167 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 2168 if (((wParam & 0xFFFF) & mask) == 0) { 2169 if (OS.GetCapture () == hwnd) OS.ReleaseCapture (); 2170 } 2171 return result; 2172} 2173 2174LRESULT wmSetFocus (int hwnd, int wParam, int lParam) { 2175 int code = callWindowProc (hwnd, OS.WM_SETFOCUS, wParam, lParam); 2176 sendFocusEvent (SWT.FocusIn); 2177 2179 2186 if (isDisposed ()) return LRESULT.ZERO; 2187 if (code == 0) return LRESULT.ZERO; 2188 return new LRESULT (code); 2189} 2190 2191LRESULT wmSysChar (int hwnd, int wParam, int lParam) { 2192 Display display = this.display; 2193 display.lastAscii = wParam; 2194 display.lastNull = wParam == 0; 2195 2196 2197 if (!hooks (SWT.KeyDown) && !display.filters (SWT.KeyDown)) { 2198 return null; 2199 } 2200 2201 2202 boolean oldKeyHit = display.mnemonicKeyHit; 2203 display.mnemonicKeyHit = true; 2204 int result = callWindowProc (hwnd, OS.WM_SYSCHAR, wParam, lParam); 2205 boolean consumed = false; 2206 if (!display.mnemonicKeyHit) { 2207 consumed = !sendKeyEvent (SWT.KeyDown, OS.WM_SYSCHAR, wParam, lParam); 2208 } 2210 consumed |= display.mnemonicKeyHit; 2211 display.mnemonicKeyHit = oldKeyHit; 2212 return consumed ? LRESULT.ONE : new LRESULT (result); 2213} 2214 2215LRESULT wmSysKeyDown (int hwnd, int wParam, int lParam) { 2216 2224 if (wParam != OS.VK_F10) { 2225 2226 if ((lParam & 0x20000000) == 0) return null; 2227 } 2228 2229 2230 switch (wParam) { 2231 case OS.VK_F4: { 2232 int hwndShell = hwnd; 2233 while (OS.GetParent (hwndShell) != 0) { 2234 if (OS.GetWindow (hwndShell, OS.GW_OWNER) != 0) break; 2235 hwndShell = OS.GetParent (hwndShell); 2236 } 2237 int bits = OS.GetWindowLong (hwndShell, OS.GWL_STYLE); 2238 if ((bits & OS.WS_SYSMENU) != 0) return null; 2239 } 2240 } 2241 2242 2243 switch (wParam) { 2244 case OS.VK_SHIFT: 2245 case OS.VK_MENU: 2246 case OS.VK_CONTROL: 2247 case OS.VK_CAPITAL: 2248 case OS.VK_NUMLOCK: 2249 case OS.VK_SCROLL: 2250 if ((lParam & 0x40000000) != 0) return null; 2251 } 2252 2253 2254 display.lastAscii = display.lastKey = 0; 2255 display.lastVirtual = display.lastNull = display.lastDead = false; 2256 2257 2258 2267 int mapKey = 0; 2268 if (OS.IsWinCE) { 2269 switch (wParam) { 2270 case OS.VK_BACK: mapKey = SWT.BS; break; 2271 case OS.VK_RETURN: mapKey = SWT.CR; break; 2272 case OS.VK_DELETE: mapKey = SWT.DEL; break; 2273 case OS.VK_ESCAPE: mapKey = SWT.ESC; break; 2274 case OS.VK_TAB: mapKey = SWT.TAB; break; 2275 } 2276 } else { 2277 mapKey = OS.MapVirtualKey (wParam, 2); 2278 } 2279 display.lastVirtual = mapKey == 0 || display.numpadKey (wParam) != 0; 2280 if (display.lastVirtual) { 2281 display.lastKey = wParam; 2282 2289 if (display.lastKey == OS.VK_DELETE) display.lastAscii = 0x7F; 2290 2291 2292 if (OS.VK_NUMPAD0 <= display.lastKey && display.lastKey <= OS.VK_DIVIDE) { 2293 2302 switch (display.lastKey) { 2303 case OS.VK_MULTIPLY: 2304 case OS.VK_ADD: 2305 case OS.VK_SUBTRACT: 2306 case OS.VK_DECIMAL: 2307 case OS.VK_DIVIDE: return null; 2308 } 2309 display.lastAscii = display.numpadKey (display.lastKey); 2310 } 2311 } else { 2312 2318 display.lastKey = OS.CharLower ((short) mapKey); 2319 2320 2326 if (OS.IsWinNT) return null; 2327 if (wParam != OS.VK_RETURN) return null; 2328 display.lastAscii = '\r'; 2329 } 2330 2331 if (!sendKeyEvent (SWT.KeyDown, OS.WM_SYSKEYDOWN, wParam, lParam)) { 2332 return LRESULT.ONE; 2333 } 2334 return null; 2336} 2337 2338LRESULT wmSysKeyUp (int hwnd, int wParam, int lParam) { 2339 return wmKeyUp (hwnd, wParam, lParam); 2340} 2341 2342LRESULT wmXButtonDblClk (int hwnd, int wParam, int lParam) { 2343 2356 LRESULT result = null; 2357 Display display = this.display; 2358 display.captureChanged = false; 2359 int button = (wParam >> 16 == OS.XBUTTON1) ? 4 : 5; 2360 sendMouseEvent (SWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam); 2361 if (sendMouseEvent (SWT.MouseDoubleClick, button, hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam)) { 2362 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam)); 2363 } else { 2364 result = LRESULT.ZERO; 2365 } 2366 if (!display.captureChanged && !isDisposed ()) { 2367 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 2368 } 2369 return result; 2370} 2371 2372LRESULT wmXButtonDown (int hwnd, int wParam, int lParam) { 2373 LRESULT result = null; 2374 Display display = this.display; 2375 display.captureChanged = false; 2376 display.xMouse = true; 2377 int button = (wParam >> 16 == OS.XBUTTON1) ? 4 : 5; 2378 if (sendMouseEvent (SWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam)) { 2379 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDOWN, wParam, lParam)); 2380 } else { 2381 result = LRESULT.ZERO; 2382 } 2383 if (!display.captureChanged && !isDisposed ()) { 2384 if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd); 2385 } 2386 return result; 2387} 2388 2389LRESULT wmXButtonUp (int hwnd, int wParam, int lParam) { 2390 Display display = this.display; 2391 LRESULT result = null; 2392 int button = (wParam >> 16 == OS.XBUTTON1) ? 4 : 5; 2393 if (sendMouseEvent (SWT.MouseUp, button, hwnd, OS.WM_XBUTTONUP, wParam, lParam)) { 2394 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONUP, wParam, lParam)); 2395 } else { 2396 result = LRESULT.ZERO; 2397 } 2398 2404 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 2405 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 2406 if (((wParam & 0xFFFF) & mask) == 0) { 2407 if (OS.GetCapture () == hwnd) OS.ReleaseCapture (); 2408 } 2409 return result; 2410} 2411} 2412 | Popular Tags |