comparison dwt/widgets/Widget.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children 387fe83aa839
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
99 /* More global widget state flags */ 99 /* More global widget state flags */
100 static const int TRACK_MOUSE = 1<<13; 100 static const int TRACK_MOUSE = 1<<13;
101 static const int FOREIGN_HANDLE = 1<<14; 101 static const int FOREIGN_HANDLE = 1<<14;
102 static const int DRAG_DETECT = 1<<15; 102 static const int DRAG_DETECT = 1<<15;
103 103
104 /* Move and resize state flags */
105 static final int MOVE_OCCURRED = 1<<16;
106 static final int MOVE_DEFERRED = 1<<17;
107 static final int RESIZE_OCCURRED = 1<<18;
108 static final int RESIZE_DEFERRED = 1<<19;
109
110 /* Ignore WM_CHANGEUISTATE */
111 static final int IGNORE_WM_CHANGEUISTATE = 1<<20;
112
104 /* Default size for widgets */ 113 /* Default size for widgets */
105 static const int DEFAULT_WIDTH = 64; 114 static const int DEFAULT_WIDTH = 64;
106 static const int DEFAULT_HEIGHT = 64; 115 static const int DEFAULT_HEIGHT = 64;
107 116
108 /* Check and initialize the Common Controls DLL */ 117 /* Check and initialize the Common Controls DLL */
195 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 204 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
196 * </ul> 205 * </ul>
197 * 206 *
198 * @see Listener 207 * @see Listener
199 * @see DWT 208 * @see DWT
209 * @see #getListeners(int)
200 * @see #removeListener(int, Listener) 210 * @see #removeListener(int, Listener)
201 * @see #notifyListeners 211 * @see #notifyListeners
202 */ 212 */
203 public void addListener (int eventType, Listener listener) { 213 public void addListener (int eventType, Listener listener) {
204 checkWidget(); 214 checkWidget();
355 * </ul> 365 * </ul>
356 */ 366 */
357 void checkWidget () { 367 void checkWidget () {
358 Display display = this.display; 368 Display display = this.display;
359 if (display is null) error (DWT.ERROR_WIDGET_DISPOSED); 369 if (display is null) error (DWT.ERROR_WIDGET_DISPOSED);
360 if (display.thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS); 370 if (display.thread !is Thread.getThis ()) {
371 /*
372 * Bug in IBM JVM 1.6. For some reason, under
373 * conditions that are yet to be full understood,
374 * Thread.currentThread() is either returning null
375 * or a different instance from the one that was
376 * saved when the Display was created. This is
377 * possibly a JIT problem because modifying this
378 * method to print logging information when the
379 * error happens seems to fix the problem. The
380 * fix is to use operating system calls to verify
381 * that the current thread is not the Display thread.
382 *
383 * NOTE: Despite the fact that Thread.currentThread()
384 * is used in other places, the failure has only been
385 * observed here.
386 */
387 if (display.threadId !is OS.GetCurrentThreadId ()) {
388 error (DWT.ERROR_THREAD_INVALID_ACCESS);
389 }
390 }
361 if ((state & DISPOSED) !is 0) error (DWT.ERROR_WIDGET_DISPOSED); 391 if ((state & DISPOSED) !is 0) error (DWT.ERROR_WIDGET_DISPOSED);
362 } 392 }
363 393
364 /** 394 /**
365 * Destroys the widget in the operating system and releases 395 * Destroys the widget in the operating system and releases
473 Widget findItem (HANDLE id) { 503 Widget findItem (HANDLE id) {
474 return null; 504 return null;
475 } 505 }
476 506
477 char [] fixMnemonic (String string) { 507 char [] fixMnemonic (String string) {
478 char [] buffer = string.dup; 508 return fixMnemonic (string, false);
509 }
510
511 char [] fixMnemonic (String string, bool spaces) {
512 char [] buffer = string ~ '\0';
479 int i = 0, j = 0; 513 int i = 0, j = 0;
480 while (i < buffer.length) { 514 while (i < buffer.length) {
481 if (buffer [i] is '&') { 515 if (buffer [i] is '&') {
482 if (i + 1 < buffer.length && buffer [i + 1] is '&') { 516 if (i + 1 < buffer.length && buffer [i + 1] is '&') {
483 buffer [j++] = ' '; 517 if (spaces) buffer [j] = ' ';
518 j++;
484 i++; 519 i++;
485 } 520 }
486 i++; 521 i++;
487 } else { 522 } else {
488 buffer [j++] = buffer [i++]; 523 buffer [j++] = buffer [i++];
575 Display display = this.display; 610 Display display = this.display;
576 if (display is null) error (DWT.ERROR_WIDGET_DISPOSED); 611 if (display is null) error (DWT.ERROR_WIDGET_DISPOSED);
577 return display; 612 return display;
578 } 613 }
579 614
615 /**
616 * Returns an array of listeners who will be notified when an event
617 * of the given type occurs. The event type is one of the event constants
618 * defined in class <code>DWT</code>.
619 *
620 * @param eventType the type of event to listen for
621 * @return an array of listeners that will be notified when the event occurs
622 *
623 * @exception DWTException <ul>
624 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
625 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
626 * </ul>
627 *
628 * @see Listener
629 * @see DWT
630 * @see #addListener(int, Listener)
631 * @see #removeListener(int, Listener)
632 * @see #notifyListeners
633 *
634 * @since 3.4
635 */
636 public Listener[] getListeners (int eventType) {
637 checkWidget();
638 if (eventTable is null) return new Listener[0];
639 return eventTable.getListeners(eventType);
640 }
641
580 Menu getMenu () { 642 Menu getMenu () {
581 return null; 643 return null;
582 } 644 }
583 645
584 /** 646 /**
730 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 792 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
731 * </ul> 793 * </ul>
732 * 794 *
733 * @see DWT 795 * @see DWT
734 * @see #addListener 796 * @see #addListener
797 * @see #getListeners(int)
735 * @see #removeListener(int, Listener) 798 * @see #removeListener(int, Listener)
736 */ 799 */
737 public void notifyListeners (int eventType, Event event) { 800 public void notifyListeners (int eventType, Event event) {
738 checkWidget(); 801 checkWidget();
739 if (event is null) event = new Event (); 802 if (event is null) event = new Event ();
878 * </ul> 941 * </ul>
879 * 942 *
880 * @see Listener 943 * @see Listener
881 * @see DWT 944 * @see DWT
882 * @see #addListener 945 * @see #addListener
946 * @see #getListeners(int)
883 * @see #notifyListeners 947 * @see #notifyListeners
884 */ 948 */
885 public void removeListener (int eventType, Listener listener) { 949 public void removeListener (int eventType, Listener listener) {
886 checkWidget(); 950 checkWidget();
887 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); 951 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
997 } else { 1061 } else {
998 display.postEvent (event); 1062 display.postEvent (event);
999 } 1063 }
1000 } 1064 }
1001 1065
1002 bool sendKeyEvent (int type, int msg, int wParam, int lParam) { 1066 bool sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam) {
1003 Event event = new Event (); 1067 Event event = new Event ();
1004 if (!setKeyState (event, type, wParam, lParam)) return true; 1068 if (!setKeyState (event, type, wParam, lParam)) return true;
1005 return sendKeyEvent (type, msg, wParam, lParam, event); 1069 return sendKeyEvent (type, msg, wParam, lParam, event);
1006 } 1070 }
1007 1071
1008 bool sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) { 1072 bool sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam, Event event) {
1009 sendEvent (type, event); 1073 sendEvent (type, event);
1010 if (isDisposed ()) return false; 1074 if (isDisposed ()) return false;
1011 return event.doit; 1075 return event.doit;
1012 } 1076 }
1013 1077
1019 if (!hooks (type) && !filters (type)) return true; 1083 if (!hooks (type) && !filters (type)) return true;
1020 Event event = new Event (); 1084 Event event = new Event ();
1021 event.button = button; 1085 event.button = button;
1022 event.detail = detail; 1086 event.detail = detail;
1023 event.count = count; 1087 event.count = count;
1024 event.x = cast(short) (lParam & 0xFFFF); 1088 event.x = OS.GET_X_LPARAM (lParam);
1025 event.y = cast(short) (lParam >> 16); 1089 event.y = OS.GET_Y_LPARAM (lParam);
1026 setInputState (event, type); 1090 setInputState (event, type);
1027 mapEvent (hwnd, event); 1091 mapEvent (hwnd, event);
1028 if (send) { 1092 if (send) {
1029 sendEvent (type, event); 1093 sendEvent (type, event);
1030 if (isDisposed ()) return false; 1094 if (isDisposed ()) return false;
1147 if (OS.GetKeyState (OS.VK_SHIFT) < 0) event.stateMask |= DWT.SHIFT; 1211 if (OS.GetKeyState (OS.VK_SHIFT) < 0) event.stateMask |= DWT.SHIFT;
1148 if (OS.GetKeyState (OS.VK_CONTROL) < 0) event.stateMask |= DWT.CONTROL; 1212 if (OS.GetKeyState (OS.VK_CONTROL) < 0) event.stateMask |= DWT.CONTROL;
1149 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) event.stateMask |= DWT.BUTTON1; 1213 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) event.stateMask |= DWT.BUTTON1;
1150 if (OS.GetKeyState (OS.VK_MBUTTON) < 0) event.stateMask |= DWT.BUTTON2; 1214 if (OS.GetKeyState (OS.VK_MBUTTON) < 0) event.stateMask |= DWT.BUTTON2;
1151 if (OS.GetKeyState (OS.VK_RBUTTON) < 0) event.stateMask |= DWT.BUTTON3; 1215 if (OS.GetKeyState (OS.VK_RBUTTON) < 0) event.stateMask |= DWT.BUTTON3;
1152 if (OS.GetKeyState (OS.VK_XBUTTON1) < 0) event.stateMask |= DWT.BUTTON4; 1216 if (display.xMouse) {
1153 if (OS.GetKeyState (OS.VK_XBUTTON2) < 0) event.stateMask |= DWT.BUTTON5; 1217 if (OS.GetKeyState (OS.VK_XBUTTON1) < 0) event.stateMask |= DWT.BUTTON4;
1218 if (OS.GetKeyState (OS.VK_XBUTTON2) < 0) event.stateMask |= DWT.BUTTON5;
1219 }
1154 switch (type) { 1220 switch (type) {
1155 case DWT.MouseDown: 1221 case DWT.MouseDown:
1156 case DWT.MouseDoubleClick: 1222 case DWT.MouseDoubleClick:
1157 if (event.button is 1) event.stateMask &= ~DWT.BUTTON1; 1223 if (event.button is 1) event.stateMask &= ~DWT.BUTTON1;
1158 if (event.button is 2) event.stateMask &= ~DWT.BUTTON2; 1224 if (event.button is 2) event.stateMask &= ~DWT.BUTTON2;
1181 default: 1247 default:
1182 } 1248 }
1183 return true; 1249 return true;
1184 } 1250 }
1185 1251
1186 bool setKeyState (Event event, int type, int wParam, int lParam) { 1252 bool setKeyState (Event event, int type, int /*long*/ wParam, int /*long*/ lParam) {
1187 1253
1188 /* 1254 /*
1189 * Feature in Windows. When the user presses Ctrl+Backspace 1255 * Feature in Windows. When the user presses Ctrl+Backspace
1190 * or Ctrl+Enter, Windows sends a WM_CHAR with Delete (0x7F) 1256 * or Ctrl+Enter, Windows sends a WM_CHAR with Delete (0x7F)
1191 * and '\n' instead of '\b' and '\r'. This is the correct 1257 * and '\n' instead of '\b' and '\r'. This is the correct
1355 * mouse was released in the client area. 1421 * mouse was released in the client area.
1356 */ 1422 */
1357 int x = 0, y = 0; 1423 int x = 0, y = 0;
1358 if (lParam !is -1) { 1424 if (lParam !is -1) {
1359 POINT pt; 1425 POINT pt;
1360 x = pt.x = cast(short) (lParam & 0xFFFF); 1426 OS.POINTSTOPOINT (pt, lParam);
1361 y = pt.y = cast(short) (lParam >> 16); 1427 x = pt.x;
1362 OS.ScreenToClient (hwnd, &pt); 1428 y = pt.y;
1363 RECT rect; 1429 RECT rect;
1364 OS.GetClientRect (hwnd, &rect); 1430 OS.GetClientRect (hwnd, &rect);
1365 if (!OS.PtInRect (&rect, pt)) return null; 1431 if (!OS.PtInRect (&rect, pt)) return null;
1366 } else { 1432 } else {
1367 int pos = OS.GetMessagePos (); 1433 int pos = OS.GetMessagePos ();
1368 x = cast(short) (pos & 0xFFFF); 1434 x = OS.GET_X_LPARAM (pos);
1369 y = cast(short) (pos >> 16); 1435 y = OS.GET_Y_LPARAM (pos);
1370 } 1436 }
1371 1437
1372 /* Show the menu */ 1438 /* Show the menu */
1373 return showMenu (x, y) ? LRESULT.ZERO : null; 1439 return showMenu (x, y) ? LRESULT.ZERO : null;
1374 } 1440 }
1432 case OS.VK_ESCAPE: mapKey = DWT.ESC; break; 1498 case OS.VK_ESCAPE: mapKey = DWT.ESC; break;
1433 case OS.VK_TAB: mapKey = DWT.TAB; break; 1499 case OS.VK_TAB: mapKey = DWT.TAB; break;
1434 default: 1500 default:
1435 } 1501 }
1436 } else { 1502 } else {
1437 mapKey = OS.MapVirtualKey (wParam, 2); 1503 /*
1504 * Feature in Windows. For numbers in Marathi and Bengali,
1505 * MapVirtualKey() returns the localized number instead of
1506 * the ASCII equivalent. For example, MapVirtualKey()
1507 * maps VK_1 on the Marathi keyboard to \u2407, which is
1508 * a valid Unicode Marathi '1' character, but not ASCII.
1509 * The fix is to test for VK_0 to VK_9 and map these
1510 * explicitly.
1511 *
1512 * NOTE: VK_0 to VK_9 are the same as ASCII.
1513 */
1514 if ('0' <= wParam && wParam <= '9') {
1515 mapKey = wParam;
1516 } else {
1517 mapKey = OS.MapVirtualKey (wParam, 2);
1518 }
1438 } 1519 }
1439 1520
1440 /* 1521 /*
1441 * Bug in Windows 95 and NT. When the user types an accent key such 1522 * Bug in Windows 95 and NT. When the user types an accent key such
1442 * as ^ to get an accented character on a German keyboard, the accent 1523 * as ^ to get an accented character on a German keyboard, the accent
1716 display.lastVirtual = display.lastNull = display.lastDead = false; 1797 display.lastVirtual = display.lastNull = display.lastDead = false;
1717 return result; 1798 return result;
1718 } 1799 }
1719 1800
1720 LRESULT wmKillFocus (HWND hwnd, int wParam, int lParam) { 1801 LRESULT wmKillFocus (HWND hwnd, int wParam, int lParam) {
1802 display.scrollRemainder = 0;
1721 int code = callWindowProc (hwnd, OS.WM_KILLFOCUS, wParam, lParam); 1803 int code = callWindowProc (hwnd, OS.WM_KILLFOCUS, wParam, lParam);
1722 sendFocusEvent (DWT.FocusOut); 1804 sendFocusEvent (DWT.FocusOut);
1723 // widget could be disposed at this point 1805 // widget could be disposed at this point
1724 1806
1725 /* 1807 /*
1764 } 1846 }
1765 1847
1766 LRESULT wmLButtonDown (HWND hwnd, int wParam, int lParam) { 1848 LRESULT wmLButtonDown (HWND hwnd, int wParam, int lParam) {
1767 Display display = this.display; 1849 Display display = this.display;
1768 LRESULT result = null; 1850 LRESULT result = null;
1769 int x = cast(short) (lParam & 0xFFFF); 1851 int x = OS.GET_X_LPARAM (lParam);
1770 int y = cast(short) (lParam >> 16); 1852 int y = OS.GET_Y_LPARAM (lParam);
1771 bool [] consume = null, detect = null; 1853 bool [] consume = null, detect = null;
1772 bool dragging = false, mouseDown = true; 1854 bool dragging = false, mouseDown = true;
1773 int count = display.getClickCount (DWT.MouseDown, 1, hwnd, lParam); 1855 int count = display.getClickCount (DWT.MouseDown, 1, hwnd, lParam);
1774 if (count is 1 && (state & DRAG_DETECT) !is 0 && hooks (DWT.DragDetect)) { 1856 if (count is 1 && (state & DRAG_DETECT) !is 0 && hooks (DWT.DragDetect)) {
1775 static if (!OS.IsWinCE) { 1857 static if (!OS.IsWinCE) {
1869 * causing mouse capture to become stuck. The fix is to test 1951 * causing mouse capture to become stuck. The fix is to test
1870 * for the extra buttons only when they exist. 1952 * for the extra buttons only when they exist.
1871 */ 1953 */
1872 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 1954 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
1873 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 1955 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
1874 if (((wParam & 0xFFFF) & mask) is 0) { 1956 if ((wParam & mask) is 0) {
1875 if (OS.GetCapture () is hwnd) OS.ReleaseCapture (); 1957 if (OS.GetCapture () is hwnd) OS.ReleaseCapture ();
1876 } 1958 }
1877 return result; 1959 return result;
1878 } 1960 }
1879 1961
1935 * causing mouse capture to become stuck. The fix is to test 2017 * causing mouse capture to become stuck. The fix is to test
1936 * for the extra buttons only when they exist. 2018 * for the extra buttons only when they exist.
1937 */ 2019 */
1938 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 2020 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
1939 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 2021 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
1940 if (((wParam & 0xFFFF) & mask) is 0) { 2022 if ((wParam & mask) is 0) {
1941 if (OS.GetCapture () is hwnd) OS.ReleaseCapture (); 2023 if (OS.GetCapture () is hwnd) OS.ReleaseCapture ();
1942 } 2024 }
1943 return result; 2025 return result;
1944 } 2026 }
1945 2027
1952 2034
1953 LRESULT wmMouseLeave (HWND hwnd, int wParam, int lParam) { 2035 LRESULT wmMouseLeave (HWND hwnd, int wParam, int lParam) {
1954 if (!hooks (DWT.MouseExit) && !filters (DWT.MouseExit)) return null; 2036 if (!hooks (DWT.MouseExit) && !filters (DWT.MouseExit)) return null;
1955 int pos = OS.GetMessagePos (); 2037 int pos = OS.GetMessagePos ();
1956 POINT pt; 2038 POINT pt;
1957 pt.x = cast(short) (pos & 0xFFFF); 2039 OS.POINTSTOPOINT (pt, pos);
1958 pt.y = cast(short) (pos >> 16);
1959 OS.ScreenToClient (hwnd, &pt); 2040 OS.ScreenToClient (hwnd, &pt);
1960 lParam = (pt.x & 0xFFFF) | ((pt.y << 16) & 0xFFFF0000); 2041 lParam = OS.MAKELPARAM (pt.x, pt.y);
1961 if (!sendMouseEvent (DWT.MouseExit, 0, hwnd, OS.WM_MOUSELEAVE, wParam, lParam)) { 2042 if (!sendMouseEvent (DWT.MouseExit, 0, hwnd, OS.WM_MOUSELEAVE, wParam, lParam)) {
1962 return LRESULT.ZERO; 2043 return LRESULT.ZERO;
1963 } 2044 }
1964 return null; 2045 return null;
1965 } 2046 }
2015 display.captureChanged = false; 2096 display.captureChanged = false;
2016 return result; 2097 return result;
2017 } 2098 }
2018 2099
2019 LRESULT wmMouseWheel (HWND hwnd, int wParam, int lParam) { 2100 LRESULT wmMouseWheel (HWND hwnd, int wParam, int lParam) {
2101 int delta = OS.GET_WHEEL_DELTA_WPARAM (wParam);
2102 int linesToScroll;
2103 int detail;
2104 OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, &linesToScroll, 0);
2105 if (linesToScroll is OS.WHEEL_PAGESCROLL) {
2106 detail = DWT.SCROLL_PAGE;
2107 } else {
2108 detail = DWT.SCROLL_LINE;
2109 delta *= linesToScroll;
2110 }
2111 /* Check if the delta and the remainder have the same direction (sign) */
2112 if ((delta ^ display.scrollRemainder) >= 0) delta += display.scrollRemainder;
2113 display.scrollRemainder = delta % OS.WHEEL_DELTA;
2114
2020 if (!hooks (DWT.MouseWheel) && !filters (DWT.MouseWheel)) return null; 2115 if (!hooks (DWT.MouseWheel) && !filters (DWT.MouseWheel)) return null;
2021 int delta = wParam >> 16; 2116 int count = delta / OS.WHEEL_DELTA;
2022 int value;
2023 int count, detail;
2024 OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, &value, 0);
2025 if (value is OS.WHEEL_PAGESCROLL) {
2026 detail = DWT.SCROLL_PAGE;
2027 count = delta / OS.WHEEL_DELTA;
2028 } else {
2029 detail = DWT.SCROLL_LINE;
2030 count = value * delta / OS.WHEEL_DELTA;
2031 }
2032 POINT pt; 2117 POINT pt;
2033 pt.x = cast(short) (lParam & 0xFFFF); 2118 OS.POINTSTOPOINT (pt, lParam);
2034 pt.y = cast(short) (lParam >> 16);
2035 OS.ScreenToClient (hwnd, &pt); 2119 OS.ScreenToClient (hwnd, &pt);
2036 lParam = (pt.x & 0xFFFF) | ((pt.y << 16) & 0xFFFF0000); 2120 lParam = OS.MAKELPARAM (pt.x, pt.y);
2037 if (!sendMouseEvent (DWT.MouseWheel, 0, count, detail, true, hwnd, OS.WM_MOUSEWHEEL, wParam, lParam)) { 2121 if (!sendMouseEvent (DWT.MouseWheel, 0, count, detail, true, hwnd, OS.WM_MOUSEWHEEL, wParam, lParam)) {
2038 return LRESULT.ZERO; 2122 return LRESULT.ZERO;
2039 } 2123 }
2040 return null; 2124 return null;
2041 } 2125 }
2042 2126
2043 LRESULT wmPaint (HWND hwnd, int wParam, int lParam) { 2127 LRESULT wmNCPaint (HWND hwnd, int /*long*/ wParam, int /*long*/ lParam) {
2128 return null;
2129 }
2130
2131 LRESULT wmPaint (HWND hwnd, int /*long*/ wParam, int /*long*/ lParam) {
2044 2132
2045 /* Exit early - don't draw the background */ 2133 /* Exit early - don't draw the background */
2046 if (!hooks (DWT.Paint) && !filters (DWT.Paint)) { 2134 if (!hooks (DWT.Paint) && !filters (DWT.Paint)) {
2047 return null; 2135 return null;
2048 } 2136 }
2049 2137
2050 /* Issue a paint event */ 2138 /* Issue a paint event */
2051 int result = 0; 2139 int /*long*/ result = 0;
2052 static if (OS.IsWinCE) { 2140 static if (OS.IsWinCE) {
2053 RECT rect; 2141 RECT rect;
2054 OS.GetUpdateRect (hwnd, &rect, false); 2142 OS.GetUpdateRect (hwnd, &rect, false);
2055 result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam); 2143 result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam);
2056 /* 2144 /*
2130 */ 2218 */
2131 if ((lParam & OS.PRF_NONCLIENT) !is 0) { 2219 if ((lParam & OS.PRF_NONCLIENT) !is 0) {
2132 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 2220 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
2133 int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE); 2221 int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
2134 if ((bits & OS.WS_EX_CLIENTEDGE) !is 0) { 2222 if ((bits & OS.WS_EX_CLIENTEDGE) !is 0) {
2135 int code = callWindowProc (hwnd, OS.WM_PRINT, wParam, lParam); 2223 int /*long*/ code = callWindowProc (hwnd, OS.WM_PRINT, wParam, lParam);
2136 RECT rect; 2224 RECT rect;
2137 OS.GetWindowRect (hwnd, &rect); 2225 OS.GetWindowRect (hwnd, &rect);
2138 rect.right -= rect.left; 2226 rect.right -= rect.left;
2139 rect.bottom -= rect.top; 2227 rect.bottom -= rect.top;
2140 rect.left = rect.top = 0; 2228 rect.left = rect.top = 0;
2208 * causing mouse capture to become stuck. The fix is to test 2296 * causing mouse capture to become stuck. The fix is to test
2209 * for the extra buttons only when they exist. 2297 * for the extra buttons only when they exist.
2210 */ 2298 */
2211 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 2299 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
2212 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 2300 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
2213 if (((wParam & 0xFFFF) & mask) is 0) { 2301 if ((wParam & mask) is 0) {
2214 if (OS.GetCapture () is hwnd) OS.ReleaseCapture (); 2302 if (OS.GetCapture () is hwnd) OS.ReleaseCapture ();
2215 } 2303 }
2216 return result; 2304 return result;
2217 } 2305 }
2218 2306
2219 LRESULT wmSetFocus (HWND hwnd, int wParam, int lParam) { 2307 LRESULT wmSetFocus (HWND hwnd, int wParam, int lParam) {
2220 int code = callWindowProc (hwnd, OS.WM_SETFOCUS, wParam, lParam); 2308 int /*long*/ code = callWindowProc (hwnd, OS.WM_SETFOCUS, wParam, lParam);
2221 sendFocusEvent (DWT.FocusIn); 2309 sendFocusEvent (DWT.FocusIn);
2222 // widget could be disposed at this point 2310 // widget could be disposed at this point
2223 2311
2224 /* 2312 /*
2225 * It is possible (but unlikely), that application 2313 * It is possible (but unlikely), that application
2244 } 2332 }
2245 2333
2246 /* Call the window proc to determine whether it is a system key or mnemonic */ 2334 /* Call the window proc to determine whether it is a system key or mnemonic */
2247 bool oldKeyHit = display.mnemonicKeyHit; 2335 bool oldKeyHit = display.mnemonicKeyHit;
2248 display.mnemonicKeyHit = true; 2336 display.mnemonicKeyHit = true;
2249 int result = callWindowProc (hwnd, OS.WM_SYSCHAR, wParam, lParam); 2337 int /*long*/ result = callWindowProc (hwnd, OS.WM_SYSCHAR, wParam, lParam);
2250 bool consumed = false; 2338 bool consumed = false;
2251 if (!display.mnemonicKeyHit) { 2339 if (!display.mnemonicKeyHit) {
2252 consumed = !sendKeyEvent (DWT.KeyDown, OS.WM_SYSCHAR, wParam, lParam); 2340 consumed = !sendKeyEvent (DWT.KeyDown, OS.WM_SYSCHAR, wParam, lParam);
2253 // widget could be disposed at this point 2341 // widget could be disposed at this point
2254 } 2342 }
2403 * fix is to send a mouse down event. 2491 * fix is to send a mouse down event.
2404 */ 2492 */
2405 LRESULT result = null; 2493 LRESULT result = null;
2406 Display display = this.display; 2494 Display display = this.display;
2407 display.captureChanged = false; 2495 display.captureChanged = false;
2408 int button = (wParam >> 16 is OS.XBUTTON1) ? 4 : 5; 2496 int button = OS.HIWORD (wParam) is OS.XBUTTON1 ? 4 : 5;
2409 sendMouseEvent (DWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam); 2497 sendMouseEvent (DWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam);
2410 if (sendMouseEvent (DWT.MouseDoubleClick, button, hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam)) { 2498 if (sendMouseEvent (DWT.MouseDoubleClick, button, hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam)) {
2411 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam)); 2499 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam));
2412 } else { 2500 } else {
2413 result = LRESULT.ZERO; 2501 result = LRESULT.ZERO;
2421 LRESULT wmXButtonDown (HWND hwnd, int wParam, int lParam) { 2509 LRESULT wmXButtonDown (HWND hwnd, int wParam, int lParam) {
2422 LRESULT result = null; 2510 LRESULT result = null;
2423 Display display = this.display; 2511 Display display = this.display;
2424 display.captureChanged = false; 2512 display.captureChanged = false;
2425 display.xMouse = true; 2513 display.xMouse = true;
2426 int button = (wParam >> 16 is OS.XBUTTON1) ? 4 : 5; 2514 int button = OS.HIWORD (wParam) is OS.XBUTTON1 ? 4 : 5;
2427 if (sendMouseEvent (DWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam)) { 2515 if (sendMouseEvent (DWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam)) {
2428 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDOWN, wParam, lParam)); 2516 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDOWN, wParam, lParam));
2429 } else { 2517 } else {
2430 result = LRESULT.ZERO; 2518 result = LRESULT.ZERO;
2431 } 2519 }
2436 } 2524 }
2437 2525
2438 LRESULT wmXButtonUp (HWND hwnd, int wParam, int lParam) { 2526 LRESULT wmXButtonUp (HWND hwnd, int wParam, int lParam) {
2439 Display display = this.display; 2527 Display display = this.display;
2440 LRESULT result = null; 2528 LRESULT result = null;
2441 int button = (wParam >> 16 is OS.XBUTTON1) ? 4 : 5; 2529 int button = OS.HIWORD (wParam) is OS.XBUTTON1 ? 4 : 5;
2442 if (sendMouseEvent (DWT.MouseUp, button, hwnd, OS.WM_XBUTTONUP, wParam, lParam)) { 2530 if (sendMouseEvent (DWT.MouseUp, button, hwnd, OS.WM_XBUTTONUP, wParam, lParam)) {
2443 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONUP, wParam, lParam)); 2531 result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONUP, wParam, lParam));
2444 } else { 2532 } else {
2445 result = LRESULT.ZERO; 2533 result = LRESULT.ZERO;
2446 } 2534 }
2450 * causing mouse capture to become stuck. The fix is to test 2538 * causing mouse capture to become stuck. The fix is to test
2451 * for the extra buttons only when they exist. 2539 * for the extra buttons only when they exist.
2452 */ 2540 */
2453 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON; 2541 int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
2454 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2; 2542 if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
2455 if (((wParam & 0xFFFF) & mask) is 0) { 2543 if ((wParam & mask) is 0) {
2456 if (OS.GetCapture () is hwnd) OS.ReleaseCapture (); 2544 if (OS.GetCapture () is hwnd) OS.ReleaseCapture ();
2457 } 2545 }
2458 return result; 2546 return result;
2459 } 2547 }
2460 } 2548 }