comparison dwt/widgets/Display.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 a8fed3e56433
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
28 import dwt.graphics.Point; 28 import dwt.graphics.Point;
29 import dwt.graphics.RGB; 29 import dwt.graphics.RGB;
30 import dwt.graphics.Rectangle; 30 import dwt.graphics.Rectangle;
31 import dwt.graphics.Resource; 31 import dwt.graphics.Resource;
32 import dwt.internal.ImageList; 32 import dwt.internal.ImageList;
33 import dwt.internal.Library;
33 import dwt.internal.win32.OS; 34 import dwt.internal.win32.OS;
34 35
35 import dwt.widgets.Control; 36 import dwt.widgets.Control;
37 import dwt.widgets.Dialog;
36 import dwt.widgets.Tray; 38 import dwt.widgets.Tray;
37 import dwt.widgets.Event; 39 import dwt.widgets.Event;
38 import dwt.widgets.EventTable; 40 import dwt.widgets.EventTable;
39 import dwt.widgets.Menu; 41 import dwt.widgets.Menu;
40 import dwt.widgets.MenuItem; 42 import dwt.widgets.MenuItem;
141 * public API. It is marked public only so that it can be shared 143 * public API. It is marked public only so that it can be shared
142 * within the packages provided by DWT. It is not available on all 144 * within the packages provided by DWT. It is not available on all
143 * platforms and should never be accessed from application code. 145 * platforms and should never be accessed from application code.
144 * </p> 146 * </p>
145 */ 147 */
146 public MSG msg; 148 public MSG* msg;
147 149
148 /* Windows and Events */ 150 /* Windows and Events */
149 Event [] eventQueue; 151 Event [] eventQueue;
150 //Callback windowCallback; 152 //Callback windowCallback;
151 //int windowProc_; 153 //int windowProc_;
155 static const String WindowName = "SWT_Window"; //$NON-NLS-1$ 157 static const String WindowName = "SWT_Window"; //$NON-NLS-1$
156 static const String WindowShadowName = "SWT_WindowShadow"; //$NON-NLS-1$ 158 static const String WindowShadowName = "SWT_WindowShadow"; //$NON-NLS-1$
157 EventTable eventTable, filterTable; 159 EventTable eventTable, filterTable;
158 160
159 /* Widget Table */ 161 /* Widget Table */
162 int freeSlot;
160 int [] indexTable; 163 int [] indexTable;
161 Control lastControl, lastGetControl; 164 Control lastControl, lastGetControl;
162 int freeSlot;
163 HANDLE lastHwnd; 165 HANDLE lastHwnd;
164 HWND lastGetHwnd; 166 HWND lastGetHwnd;
165 Control [] controlTable; 167 Control [] controlTable;
166 static const int GROW_SIZE = 1024; 168 static const int GROW_SIZE = 1024;
167 private static /+const+/ int SWT_OBJECT_INDEX; 169 private static /+const+/ int SWT_OBJECT_INDEX;
226 228
227 /* Filter Hook */ 229 /* Filter Hook */
228 //Callback msgFilterCallback; 230 //Callback msgFilterCallback;
229 //int msgFilterProc_, 231 //int msgFilterProc_,
230 HHOOK filterHook; 232 HHOOK filterHook;
231 MSG hookMsg; 233 bool runDragDrop = true, dragCancelled = false;
232 bool runDragDrop = true; 234 MSG* hookMsg;
233 235
234 /* Idle Hook */ 236 /* Idle Hook */
235 //Callback foregroundIdleCallback; 237 //Callback foregroundIdleCallback;
236 //int foregroundIdleProc_; 238 //int foregroundIdleProc_;
237 HHOOK idleHook; 239 HHOOK idleHook;
246 static const String AWT_WINDOW_CLASS = "SunAwtWindow"; 248 static const String AWT_WINDOW_CLASS = "SunAwtWindow";
247 static const short [] ACCENTS = [ cast(short) '~', '`', '\'', '^', '"']; 249 static const short [] ACCENTS = [ cast(short) '~', '`', '\'', '^', '"'];
248 250
249 /* Sync/Async Widget Communication */ 251 /* Sync/Async Widget Communication */
250 Synchronizer synchronizer; 252 Synchronizer synchronizer;
251 bool runMessages = true, runMessagesInIdle = false; 253 bool runMessages = true, runMessagesInIdle = false, runMessagesInMessageProc = true;
252 static const String RUN_MESSAGES_IN_IDLE_KEY = "org.eclipse.swt.internal.win32.runMessagesInIdle"; //$NON-NLS-1$ 254 static const String RUN_MESSAGES_IN_IDLE_KEY = "org.eclipse.swt.internal.win32.runMessagesInIdle"; //$NON-NLS-1$
255 static final String RUN_MESSAGES_IN_MESSAGE_PROC_KEY = "dwt.internal.win32.runMessagesInMessageProc"; //$NON-NLS-1$
253 Thread thread; 256 Thread thread;
254 257
255 /* Display Shutdown */ 258 /* Display Shutdown */
256 Runnable [] disposeList; 259 Runnable [] disposeList;
257 260
258 /* System Tray */ 261 /* System Tray */
259 Tray tray; 262 Tray tray;
260 int nextTrayId; 263 int nextTrayId;
261 264
262 /* Timers */ 265 /* Timers */
263 int [] timerIds; 266 int /*long*/ [] timerIds;
264 Runnable [] timerList; 267 Runnable [] timerList;
265 int nextTimerId = SETTINGS_ID + 1; 268 int /*long*/ nextTimerId = SETTINGS_ID + 1;
266 static const int SETTINGS_ID = 100; 269 static const int SETTINGS_ID = 100;
267 static const int SETTINGS_DELAY = 2000; 270 static const int SETTINGS_DELAY = 2000;
268 271
269 /* Keyboard and Mouse */ 272 /* Keyboard and Mouse */
270 RECT clickRect; 273 RECT* clickRect;
271 int clickCount, lastTime, lastButton; 274 int clickCount, lastTime, lastButton;
272 HWND lastClickHwnd; 275 HWND lastClickHwnd;
276 int scrollRemainder;
273 int lastKey, lastAscii, lastMouse; 277 int lastKey, lastAscii, lastMouse;
274 bool lastVirtual, lastNull, lastDead; 278 bool lastVirtual, lastNull, lastDead;
275 ubyte [256] keyboard; 279 ubyte [256] keyboard;
276 bool accelKeyHit, mnemonicKeyHit; 280 bool accelKeyHit, mnemonicKeyHit;
277 bool lockActiveWindow, captureChanged, xMouse; 281 bool lockActiveWindow, captureChanged, xMouse;
306 /* Sort Indicators */ 310 /* Sort Indicators */
307 Image upArrow, downArrow; 311 Image upArrow, downArrow;
308 312
309 /* Table */ 313 /* Table */
310 char [] tableBuffer; 314 char [] tableBuffer;
315 NMHDR* hdr;
316 NMLVDISPINFO* plvfi;
317 HWND hwndParent;
318 int columnCount;
319 bool [] columnVisible;
320
321 /* Resize and move recursion */
322 int resizeCount;
323 static final int RESIZE_LIMIT = 4;
311 324
312 /* Display Data */ 325 /* Display Data */
313 Object data; 326 Object data;
314 String [] keys; 327 String [] keys;
315 Object [] values; 328 Object [] values;
402 dwt.widgets.Monitor.Monitor[] monitors = null; 415 dwt.widgets.Monitor.Monitor[] monitors = null;
403 int monitorCount = 0; 416 int monitorCount = 0;
404 417
405 /* Modality */ 418 /* Modality */
406 Shell [] modalShells; 419 Shell [] modalShells;
407 Shell modalDialogShell; 420 Dialog modalDialog;
408 static bool TrimEnabled = false; 421 static bool TrimEnabled = false;
409 422
410 /* Private DWT Window Messages */ 423 /* Private DWT Window Messages */
411 static const int SWT_GETACCELCOUNT = OS.WM_APP; 424 static const int SWT_GETACCELCOUNT = OS.WM_APP;
412 static const int SWT_GETACCEL = OS.WM_APP + 1; 425 static const int SWT_GETACCEL = OS.WM_APP + 1;
415 static const int SWT_TRAYICONMSG = OS.WM_APP + 4; 428 static const int SWT_TRAYICONMSG = OS.WM_APP + 4;
416 static const int SWT_NULL = OS.WM_APP + 5; 429 static const int SWT_NULL = OS.WM_APP + 5;
417 static const int SWT_RUNASYNC = OS.WM_APP + 6; 430 static const int SWT_RUNASYNC = OS.WM_APP + 6;
418 static int SWT_TASKBARCREATED; 431 static int SWT_TASKBARCREATED;
419 static int SWT_RESTORECARET; 432 static int SWT_RESTORECARET;
433 static int DI_GETDRAGIMAGE;
420 434
421 /* Workaround for Adobe Reader 7.0 */ 435 /* Workaround for Adobe Reader 7.0 */
422 int hitCount; 436 int hitCount;
423 437
424 /* Package Name */ 438 /* Package Name */
488 * 502 *
489 * @param data the device data 503 * @param data the device data
490 */ 504 */
491 public this (DeviceData data) { 505 public this (DeviceData data) {
492 static_this(); 506 static_this();
507 msg = new MSG();
508 hookMsg = new MSG();
493 super (data); 509 super (data);
494 synchronizer = new Synchronizer (this); 510 synchronizer = new Synchronizer (this);
495 cursors = new Cursor [DWT.CURSOR_HAND + 1]; 511 cursors = new Cursor [DWT.CURSOR_HAND + 1];
496 } 512 }
497 513
532 controlTable = newControlTable; 548 controlTable = newControlTable;
533 } 549 }
534 static if (USE_PROPERTY) { 550 static if (USE_PROPERTY) {
535 OS.SetProp (handle, cast(wchar*)SWT_OBJECT_INDEX, cast(void*) freeSlot + 1); 551 OS.SetProp (handle, cast(wchar*)SWT_OBJECT_INDEX, cast(void*) freeSlot + 1);
536 } else { 552 } else {
537 OS.SetWindowLong (handle, OS.GWL_USERDATA, freeSlot + 1); 553 OS.SetWindowLongPtr (handle, OS.GWLP_USERDATA, freeSlot + 1);
538 } 554 }
539 int oldSlot = freeSlot; 555 int oldSlot = freeSlot;
540 freeSlot = indexTable [oldSlot]; 556 freeSlot = indexTable [oldSlot];
541 indexTable [oldSlot] = -2; 557 indexTable [oldSlot] = -2;
542 controlTable [oldSlot] = control; 558 controlTable [oldSlot] = control;
690 * </ul> 706 * </ul>
691 * 707 *
692 * @see #syncExec 708 * @see #syncExec
693 */ 709 */
694 public void asyncExec (Runnable runnable) { 710 public void asyncExec (Runnable runnable) {
695 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 711 synchronized (Device.classinfo) {
696 synchronizer.asyncExec (runnable); 712 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
713 synchronizer.asyncExec (runnable);
714 }
697 } 715 }
698 716
699 /** 717 /**
700 * Causes the system hardware to emit a short sound 718 * Causes the system hardware to emit a short sound
701 * (if it supports this capability). 719 * (if it supports this capability).
730 if (thread is null) error (DWT.ERROR_WIDGET_DISPOSED); 748 if (thread is null) error (DWT.ERROR_WIDGET_DISPOSED);
731 if (thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS); 749 if (thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
732 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 750 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
733 } 751 }
734 752
735 static synchronized void checkDisplay (Thread thread, bool multiple) { 753 static void checkDisplay (Thread thread, bool multiple) {
736 for (int i=0; i<Displays.length; i++) { 754 synchronized (Device.classinfo) {
737 if (Displays [i] !is null) { 755 for (int i=0; i<Displays.length; i++) {
738 if (!multiple) DWT.error (DWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); 756 if (Displays [i] !is null) {
739 if (Displays [i].thread is thread) DWT.error (DWT.ERROR_THREAD_INVALID_ACCESS); 757 if (!multiple) DWT.error (DWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$
758 if (Displays [i].thread is thread) DWT.error (DWT.ERROR_THREAD_INVALID_ACCESS);
759 }
740 } 760 }
741 } 761 }
742 } 762 }
743 763
744 void clearModal (Shell shell) { 764 void clearModal (Shell shell) {
843 bmiHeader.biPlanes = 1; 863 bmiHeader.biPlanes = 1;
844 bmiHeader.biBitCount = cast(short)32; 864 bmiHeader.biBitCount = cast(short)32;
845 bmiHeader.biCompression = OS.BI_RGB; 865 bmiHeader.biCompression = OS.BI_RGB;
846 byte [] bmi = new byte [BITMAPINFOHEADER.sizeof]; 866 byte [] bmi = new byte [BITMAPINFOHEADER.sizeof];
847 bmi[ 0 .. BITMAPINFOHEADER.sizeof ] = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof ]; 867 bmi[ 0 .. BITMAPINFOHEADER.sizeof ] = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof ];
848 int[1] pBits; 868 void* pBits;
849 auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, pBits.ptr, null, 0); 869 auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0);
850 if (memDib is null) DWT.error (DWT.ERROR_NO_HANDLES); 870 if (memDib is null) DWT.error (DWT.ERROR_NO_HANDLES);
851 auto oldMemBitmap = OS.SelectObject (memHdc, memDib); 871 auto oldMemBitmap = OS.SelectObject (memHdc, memDib);
852 BITMAP dibBM; 872 BITMAP dibBM;
853 OS.GetObject (memDib, BITMAP.sizeof, &dibBM); 873 OS.GetObject (memDib, BITMAP.sizeof, &dibBM);
854 int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight; 874 int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
880 break; 900 break;
881 default: 901 default:
882 } 902 }
883 } 903 }
884 } 904 }
885 byte [] srcData = (cast(byte*)pBits [0])[ 0 .. sizeInBytes].dup; 905 byte [] srcData = (cast(byte*)pBits)[ 0 .. sizeInBytes].dup;
886 if (hMask !is null) { 906 if (hMask !is null) {
887 OS.SelectObject(srcHdc, hMask); 907 OS.SelectObject(srcHdc, hMask);
888 for (int y = 0, dp = 0; y < imgHeight; ++y) { 908 for (int y = 0, dp = 0; y < imgHeight; ++y) {
889 for (int x = 0; x < imgWidth; ++x) { 909 for (int x = 0; x < imgWidth; ++x) {
890 if (OS.GetPixel(srcHdc, x, y) !is 0) { 910 if (OS.GetPixel(srcHdc, x, y) !is 0) {
928 srcData [dp + 3] = cast(byte)0xFF; 948 srcData [dp + 3] = cast(byte)0xFF;
929 dp += 4; 949 dp += 4;
930 } 950 }
931 } 951 }
932 } 952 }
933 (cast(byte*)pBits [0])[ 0 .. sizeInBytes] = srcData[]; 953 (cast(byte*)pBits)[ 0 .. sizeInBytes] = srcData[];
934 OS.SelectObject (srcHdc, oldSrcBitmap); 954 OS.SelectObject (srcHdc, oldSrcBitmap);
935 OS.SelectObject (memHdc, oldMemBitmap); 955 OS.SelectObject (memHdc, oldMemBitmap);
936 OS.DeleteObject (srcHdc); 956 OS.DeleteObject (srcHdc);
937 OS.DeleteObject (memHdc); 957 OS.DeleteObject (memHdc);
938 OS.ReleaseDC (null, hDC); 958 OS.ReleaseDC (null, hDC);
957 bmiHeader.biHeight = -imgHeight; 977 bmiHeader.biHeight = -imgHeight;
958 bmiHeader.biPlanes = 1; 978 bmiHeader.biPlanes = 1;
959 bmiHeader.biBitCount = cast(short)32; 979 bmiHeader.biBitCount = cast(short)32;
960 bmiHeader.biCompression = OS.BI_RGB; 980 bmiHeader.biCompression = OS.BI_RGB;
961 byte [] bmi = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof]; 981 byte [] bmi = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof];
962 int [1] pBits; 982 void* pBits;
963 auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, pBits.ptr, null, 0); 983 auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0);
964 if (memDib is null) DWT.error (DWT.ERROR_NO_HANDLES); 984 if (memDib is null) DWT.error (DWT.ERROR_NO_HANDLES);
965 auto oldMemBitmap = OS.SelectObject (memHdc, memDib); 985 auto oldMemBitmap = OS.SelectObject (memHdc, memDib);
966 BITMAP dibBM; 986 BITMAP dibBM;
967 OS.GetObject (memDib, BITMAP.sizeof, &dibBM); 987 OS.GetObject (memDib, BITMAP.sizeof, &dibBM);
968 int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight; 988 int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
999 OS.SelectObject (srcHdc, oldSrcBitmap); 1019 OS.SelectObject (srcHdc, oldSrcBitmap);
1000 OS.SelectObject (memHdc, oldMemBitmap); 1020 OS.SelectObject (memHdc, oldMemBitmap);
1001 OS.DeleteObject (srcHdc); 1021 OS.DeleteObject (srcHdc);
1002 OS.DeleteObject (memHdc); 1022 OS.DeleteObject (memHdc);
1003 OS.ReleaseDC (null, hDC); 1023 OS.ReleaseDC (null, hDC);
1004 byte [] srcData = (cast(byte*)pBits[0])[ 0 .. sizeInBytes ].dup; 1024 byte [] srcData = (cast(byte*)pBits)[ 0 .. sizeInBytes ].dup;
1005 if (alpha !is -1) { 1025 if (alpha !is -1) {
1006 for (int y = 0, dp = 0; y < imgHeight; ++y) { 1026 for (int y = 0, dp = 0; y < imgHeight; ++y) {
1007 for (int x = 0; x < imgWidth; ++x) { 1027 for (int x = 0; x < imgWidth; ++x) {
1008 srcData [dp + 3] = cast(byte)alpha; 1028 srcData [dp + 3] = cast(byte)alpha;
1009 dp += 4; 1029 dp += 4;
1026 } 1046 }
1027 dp += 4; 1047 dp += 4;
1028 } 1048 }
1029 } 1049 }
1030 } 1050 }
1031 (cast(byte*)pBits[0])[ 0 .. sizeInBytes ] = srcData[]; 1051 (cast(byte*)pBits)[ 0 .. sizeInBytes ] = srcData[];
1032 return memDib; 1052 return memDib;
1033 } 1053 }
1034 1054
1035 static Image createIcon (Image image) { 1055 static Image createIcon (Image image) {
1036 static_this(); 1056 static_this();
1110 hMask = hMask2; 1130 hMask = hMask2;
1111 } 1131 }
1112 return hMask; 1132 return hMask;
1113 } 1133 }
1114 1134
1115 static synchronized void deregister (Display display) { 1135 static void deregister (Display display) {
1116 static_this(); 1136 synchronized (Device.classinfo) {
1117 for (int i=0; i<Displays.length; i++) { 1137 for (int i=0; i<Displays.length; i++) {
1118 if (display is Displays [i]) Displays [i] = null; 1138 if (display is Displays [i]) Displays [i] = null;
1139 }
1119 } 1140 }
1120 } 1141 }
1121 1142
1122 /** 1143 /**
1123 * Destroys the device in the operating system and releases 1144 * Destroys the device in the operating system and releases
1292 * 1313 *
1293 * @since 3.1 1314 * @since 3.1
1294 */ 1315 */
1295 public Widget findWidget (HANDLE handle, int id) { 1316 public Widget findWidget (HANDLE handle, int id) {
1296 checkDevice (); 1317 checkDevice ();
1318 //TODO - should ids be long
1297 Control control = getControl (handle); 1319 Control control = getControl (handle);
1298 return control !is null ? control.findItem (cast(HANDLE) id) : null; 1320 return control !is null ? control.findItem (cast(HANDLE) id) : null;
1299 } 1321 }
1300 1322
1301 /** 1323 /**
1313 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1335 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1314 * </ul> 1336 * </ul>
1315 * 1337 *
1316 * @since 3.3 1338 * @since 3.3
1317 */ 1339 */
1318 public Widget findWidget (Widget widget, int id) { 1340 public Widget findWidget (Widget widget, int /*long*/ id) {
1319 checkDevice (); 1341 checkDevice ();
1342 //TODO - should ids be long
1320 if (cast(Control)widget) { 1343 if (cast(Control)widget) {
1321 return findWidget ((cast(Control) widget).handle, id); 1344 return findWidget ((cast(Control) widget).handle, id);
1322 } 1345 }
1323 return null; 1346 return null;
1324 } 1347 }
1327 auto d = Display.getCurrent(); 1350 auto d = Display.getCurrent();
1328 return d.foregroundIdleProc( code, wParam, lParam ); 1351 return d.foregroundIdleProc( code, wParam, lParam );
1329 } 1352 }
1330 1353
1331 int foregroundIdleProc (int code, int wParam, int lParam) { 1354 int foregroundIdleProc (int code, int wParam, int lParam) {
1332 if (runMessages) { 1355 if (code >= 0) {
1333 if (code >= 0) { 1356 if (runMessages && getMessageCount () !is 0) {
1334 if (getMessageCount () !is 0) { 1357 if (runMessagesInIdle) {
1335 if (runMessagesInIdle) { 1358 if (runMessagesInMessageProc) {
1336 OS.PostMessage (hwndMessage, SWT_RUNASYNC, 0, 0); 1359 OS.PostMessage (hwndMessage, SWT_RUNASYNC, 0, 0);
1360 } else {
1361 runAsyncMessages (false);
1337 } 1362 }
1338 wakeThread (); 1363 }
1339 } 1364 wakeThread ();
1340 } 1365 }
1341 } 1366 }
1342 return OS.CallNextHookEx (idleHook, code, wParam, lParam); 1367 return OS.CallNextHookEx (idleHook, code, wParam, lParam);
1343 } 1368 }
1344 1369
1350 * for the display. 1375 * for the display.
1351 * 1376 *
1352 * @param thread the user-interface thread 1377 * @param thread the user-interface thread
1353 * @return the display for the given thread 1378 * @return the display for the given thread
1354 */ 1379 */
1355 public static synchronized Display findDisplay (Thread thread) { 1380 public static Display findDisplay (Thread thread) {
1356 static_this(); 1381 static_this();
1357 for (int i=0; i<Displays.length; i++) { 1382 synchronized (Device.classinfo) {
1358 Display display = Displays [i]; 1383 for (int i=0; i<Displays.length; i++) {
1359 if (display !is null && display.thread is thread) { 1384 Display display = Displays [i];
1360 return display; 1385 if (display !is null && display.thread is thread) {
1361 } 1386 return display;
1362 } 1387 }
1363 return null; 1388 }
1389 return null;
1390 }
1364 } 1391 }
1365 1392
1366 /** 1393 /**
1367 * Returns the currently active <code>Shell</code>, or null 1394 * Returns the currently active <code>Shell</code>, or null
1368 * if no shell belonging to the currently running application 1395 * if no shell belonging to the currently running application
1380 Control control = findControl (OS.GetActiveWindow ()); 1407 Control control = findControl (OS.GetActiveWindow ());
1381 return control !is null ? control.getShell () : null; 1408 return control !is null ? control.getShell () : null;
1382 } 1409 }
1383 1410
1384 /** 1411 /**
1385 * Returns a rectangle describing the receiver's size and location. 1412 * Returns a rectangle describing the receiver's size and location. Note that
1413 * on multi-monitor systems the origin can be negative.
1386 * 1414 *
1387 * @return the bounding rectangle 1415 * @return the bounding rectangle
1388 * 1416 *
1389 * @exception DWTException <ul> 1417 * @exception DWTException <ul>
1390 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1418 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1410 * the user-interface thread for, or null if the currently 1438 * the user-interface thread for, or null if the currently
1411 * running thread is not a user-interface thread for any display. 1439 * running thread is not a user-interface thread for any display.
1412 * 1440 *
1413 * @return the current display 1441 * @return the current display
1414 */ 1442 */
1415 public static synchronized Display getCurrent () { 1443 public static Display getCurrent () {
1416 static_this(); 1444 static_this();
1417 return findDisplay (Thread.getThis ()); 1445 return findDisplay (Thread.getThis ());
1418 } 1446 }
1419 1447
1420 int getClickCount (int type, int button, HWND hwnd, int lParam) { 1448 int getClickCount (int type, int button, HWND hwnd, int lParam) {
1421 switch (type) { 1449 switch (type) {
1422 case DWT.MouseDown: 1450 case DWT.MouseDown:
1423 int doubleClick = OS.GetDoubleClickTime (); 1451 int doubleClick = OS.GetDoubleClickTime ();
1424 //if (clickRect is null) clickRect = new RECT (); 1452 if (clickRect is null) clickRect = new RECT ();
1425 int deltaTime = Math.abs (lastTime - getLastEventTime ()); 1453 int deltaTime = Math.abs (lastTime - getLastEventTime ());
1426 POINT pt; 1454 POINT pt;
1427 pt.x = cast(short) (lParam & 0xFFFF); 1455 OS.POINTSTOPOINT (pt, lParam);
1428 pt.y = cast(short) (lParam >> 16); 1456 if (lastClickHwnd is hwnd && lastButton is button && (deltaTime <= doubleClick) && OS.PtInRect (clickRect, pt)) {
1429 if (lastClickHwnd is hwnd && lastButton is button && (deltaTime <= doubleClick) && OS.PtInRect (&clickRect, pt)) {
1430 clickCount++; 1457 clickCount++;
1431 } else { 1458 } else {
1432 clickCount = 1; 1459 clickCount = 1;
1433 } 1460 }
1434 //FALL THROUGH 1461 //FALL THROUGH
1436 lastButton = button; 1463 lastButton = button;
1437 lastClickHwnd = hwnd; 1464 lastClickHwnd = hwnd;
1438 lastTime = getLastEventTime (); 1465 lastTime = getLastEventTime ();
1439 int xInset = OS.GetSystemMetrics (OS.SM_CXDOUBLECLK) / 2; 1466 int xInset = OS.GetSystemMetrics (OS.SM_CXDOUBLECLK) / 2;
1440 int yInset = OS.GetSystemMetrics (OS.SM_CYDOUBLECLK) / 2; 1467 int yInset = OS.GetSystemMetrics (OS.SM_CYDOUBLECLK) / 2;
1441 int x = cast(short) (lParam & 0xFFFF), y = cast(short) (lParam >> 16); 1468 int x = OS.GET_X_LPARAM (lParam), y = OS.GET_Y_LPARAM (lParam);
1442 OS.SetRect (&clickRect, x - xInset, y - yInset, x + xInset, y + yInset); 1469 OS.SetRect (clickRect, x - xInset, y - yInset, x + xInset, y + yInset);
1443 //FALL THROUGH 1470 //FALL THROUGH
1444 case DWT.MouseUp: 1471 case DWT.MouseUp:
1445 return clickCount; 1472 return clickCount;
1446 default: 1473 default:
1447 } 1474 }
1487 } 1514 }
1488 int index; 1515 int index;
1489 static if (USE_PROPERTY) { 1516 static if (USE_PROPERTY) {
1490 index = cast(int) OS.GetProp (handle, cast(wchar*)SWT_OBJECT_INDEX) - 1; 1517 index = cast(int) OS.GetProp (handle, cast(wchar*)SWT_OBJECT_INDEX) - 1;
1491 } else { 1518 } else {
1492 index = OS.GetWindowLong (handle, OS.GWL_USERDATA) - 1; 1519 index = OS.GetWindowLongPtr (handle, OS.GWLP_USERDATA) - 1;
1493 } 1520 }
1494 if (0 <= index && index < controlTable.length) { 1521 if (0 <= index && index < controlTable.length) {
1495 Control control = controlTable [index]; 1522 Control control = controlTable [index];
1496 /* 1523 /*
1497 * Because GWL_USERDATA can be used by native widgets that 1524 * Because GWL_USERDATA can be used by native widgets that
1570 * thread that invokes this method its user-interface thread) 1597 * thread that invokes this method its user-interface thread)
1571 * if it did not already exist. 1598 * if it did not already exist.
1572 * 1599 *
1573 * @return the default display 1600 * @return the default display
1574 */ 1601 */
1575 public static synchronized Display getDefault () { 1602 public static Display getDefault () {
1576 static_this(); 1603 static_this();
1577 if (Default is null) Default = new Display (); 1604 synchronized (Device.classinfo) {
1578 return Default; 1605 if (Default is null) Default = new Display ();
1606 return Default;
1607 }
1579 } 1608 }
1580 1609
1581 //PORTING_TODO 1610 //PORTING_TODO
1582 /+static bool isValidClass (Class clazz) { 1611 /+static bool isValidClass (Class clazz) {
1583 String name = clazz.getName (); 1612 String name = clazz.getName ();
1613 public Object getData (String key) { 1642 public Object getData (String key) {
1614 checkDevice (); 1643 checkDevice ();
1615 if (key is null) error (DWT.ERROR_NULL_ARGUMENT); 1644 if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
1616 if (key ==/*eq*/RUN_MESSAGES_IN_IDLE_KEY) { 1645 if (key ==/*eq*/RUN_MESSAGES_IN_IDLE_KEY) {
1617 return new ValueWrapperBool(runMessagesInIdle); 1646 return new ValueWrapperBool(runMessagesInIdle);
1647 }
1648 if (key.equals (RUN_MESSAGES_IN_MESSAGE_PROC_KEY)) {
1649 return new Boolean (runMessagesInMessageProc);
1618 } 1650 }
1619 if (keys.length is 0) return null; 1651 if (keys.length is 0) return null;
1620 for (int i=0; i<keys.length; i++) { 1652 for (int i=0; i<keys.length; i++) {
1621 if (keys [i] ==/*eq*/key) return values [i]; 1653 if (keys [i] ==/*eq*/key) return values [i];
1622 } 1654 }
1965 if (shell !is null) return shell; 1997 if (shell !is null) return shell;
1966 } 1998 }
1967 return null; 1999 return null;
1968 } 2000 }
1969 2001
1970 Shell getModalDialogShell () { 2002 Dialog getModalDialog () {
1971 if (modalDialogShell !is null && modalDialogShell.isDisposed ()) modalDialogShell = null; 2003 return modalDialog;
1972 return modalDialogShell;
1973 } 2004 }
1974 2005
1975 /** 2006 /**
1976 * Returns an array of monitors attached to the device. 2007 * Returns an array of monitors attached to the device.
1977 * 2008 *
2010 hInstance, 2041 hInstance,
2011 null); 2042 null);
2012 //embeddedCallback = new Callback (this, "embeddedProc", 4); //$NON-NLS-1$ 2043 //embeddedCallback = new Callback (this, "embeddedProc", 4); //$NON-NLS-1$
2013 //embeddedProc_ = embeddedCallback.getAddress (); 2044 //embeddedProc_ = embeddedCallback.getAddress ();
2014 //if (embeddedProc_ is 0) error (DWT.ERROR_NO_MORE_CALLBACKS); 2045 //if (embeddedProc_ is 0) error (DWT.ERROR_NO_MORE_CALLBACKS);
2015 OS.SetWindowLong (embeddedHwnd, OS.GWL_WNDPROC, cast(int) &embeddedFunc); 2046 OS.SetWindowLongPtr (embeddedHwnd, OS.GWLP_WNDPROC, cast(LONG_PTR) &embeddedFunc);
2016 } 2047 }
2017 if (code >= 0 && wParam !is OS.PM_NOREMOVE) { 2048 if (code >= 0 && (wParam & OS.PM_REMOVE) !is 0) {
2018 MSG* msg = cast(MSG*)lParam; 2049 MSG* msg = cast(MSG*)lParam;
2019 switch (msg.message) { 2050 switch (msg.message) {
2020 case OS.WM_KEYDOWN: 2051 case OS.WM_KEYDOWN:
2021 case OS.WM_KEYUP: 2052 case OS.WM_KEYUP:
2022 case OS.WM_SYSKEYDOWN: 2053 case OS.WM_SYSKEYDOWN:
2165 } 2196 }
2166 return null; 2197 return null;
2167 } 2198 }
2168 2199
2169 /** 2200 /**
2201 * Gets the synchronizer used by the display.
2202 *
2203 * @return the receiver's synchronizer
2204 *
2205 * @exception DWTException <ul>
2206 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2207 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2208 * </ul>
2209 *
2210 * @since 3.4
2211 */
2212 public Synchronizer getSynchronizer () {
2213 checkDevice ();
2214 return synchronizer;
2215 }
2216
2217 /**
2170 * Returns the thread that has invoked <code>syncExec</code> 2218 * Returns the thread that has invoked <code>syncExec</code>
2171 * or null if no such runnable is currently being invoked by 2219 * or null if no such runnable is currently being invoked by
2172 * the user-interface thread. 2220 * the user-interface thread.
2173 * <p> 2221 * <p>
2174 * Note: If a runnable invoked by asyncExec is currently 2222 * Note: If a runnable invoked by asyncExec is currently
2180 * @exception DWTException <ul> 2228 * @exception DWTException <ul>
2181 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 2229 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2182 * </ul> 2230 * </ul>
2183 */ 2231 */
2184 public Thread getSyncThread () { 2232 public Thread getSyncThread () {
2185 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 2233 synchronized (Device.classinfo) {
2186 return synchronizer.syncThread; 2234 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
2235 return synchronizer.syncThread;
2236 }
2187 } 2237 }
2188 2238
2189 /** 2239 /**
2190 * Returns the matching standard color for the given 2240 * Returns the matching standard color for the given
2191 * constant, which should be one of the color constants 2241 * constant, which should be one of the color constants
2412 * @exception DWTException <ul> 2462 * @exception DWTException <ul>
2413 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 2463 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2414 * </ul> 2464 * </ul>
2415 */ 2465 */
2416 public Thread getThread () { 2466 public Thread getThread () {
2417 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 2467 synchronized (Device.classinfo) {
2418 return thread; 2468 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
2469 return thread;
2470 }
2419 } 2471 }
2420 2472
2421 HTHEME hButtonTheme () { 2473 HTHEME hButtonTheme () {
2422 if (hButtonTheme_ !is null) return hButtonTheme_; 2474 if (hButtonTheme_ !is null) return hButtonTheme_;
2423 return hButtonTheme_ = OS.OpenThemeData (hwndMessage, BUTTON.ptr); 2475 return hButtonTheme_ = OS.OpenThemeData (hwndMessage, BUTTON.ptr);
2473 data.layout = (data.style & DWT.RIGHT_TO_LEFT) !is 0 ? OS.LAYOUT_RTL : 0; 2525 data.layout = (data.style & DWT.RIGHT_TO_LEFT) !is 0 ? OS.LAYOUT_RTL : 0;
2474 } else { 2526 } else {
2475 data.style |= DWT.LEFT_TO_RIGHT; 2527 data.style |= DWT.LEFT_TO_RIGHT;
2476 } 2528 }
2477 data.device = this; 2529 data.device = this;
2478 data.hFont = getSystemFont ().handle; 2530 data.font = getSystemFont ();
2479 } 2531 }
2480 return hDC; 2532 return hDC;
2481 } 2533 }
2482 2534
2483 /** 2535 /**
2511 WNDCLASS lpWndClass; 2563 WNDCLASS lpWndClass;
2512 lpWndClass.hInstance = hInstance; 2564 lpWndClass.hInstance = hInstance;
2513 lpWndClass.lpfnWndProc = &windowProcFunc; 2565 lpWndClass.lpfnWndProc = &windowProcFunc;
2514 lpWndClass.style = OS.CS_BYTEALIGNWINDOW | OS.CS_DBLCLKS; 2566 lpWndClass.style = OS.CS_BYTEALIGNWINDOW | OS.CS_DBLCLKS;
2515 lpWndClass.hCursor = OS.LoadCursor (null, cast(wchar*)OS.IDC_ARROW); 2567 lpWndClass.hCursor = OS.LoadCursor (null, cast(wchar*)OS.IDC_ARROW);
2568
2569
2570 //DWT_TODO: Check if this can be disabled for DWT
2571 /+
2572 /*
2573 * Set the default icon for the window class to IDI_APPLICATION.
2574 * This is not necessary for native Windows applications but
2575 * versions of Java starting at JDK 1.6 set the icon in the
2576 * executable instead of leaving the default.
2577 */
2578 if (!OS.IsWinCE && Library.JAVA_VERSION >= Library.JAVA_VERSION (1, 6, 0)) {
2579 TCHAR[] lpszFile = NewTCHARs (0, OS.MAX_PATH);
2580 while (OS.GetModuleFileName (0, lpszFile.ptr, lpszFile.length) is lpszFile.length) {
2581 lpszFile = NewTCHARs (0, lpszFile.length + OS.MAX_PATH);
2582 }
2583 if (OS.ExtractIconEx (lpszFile.ptr, -1, null, null, 1) !is 0) {
2584 String fileName = TCHARzToStr( lpszFile.ptr );
2585 if (fileName.endsWith ("java.exe") || fileName.endsWith ("javaw.exe")) { //$NON-NLS-1$ //$NON-NLS-2$
2586 lpWndClass.hIcon = OS.LoadIcon (0, OS.IDI_APPLICATION);
2587 }
2588 }
2589 }
2590 +/
2516 int byteCount = windowClass_.length * TCHAR.sizeof; 2591 int byteCount = windowClass_.length * TCHAR.sizeof;
2517 lpWndClass.lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 2592 lpWndClass.lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
2518 OS.MoveMemory (lpWndClass.lpszClassName, windowClass_.ptr, byteCount); 2593 OS.MoveMemory (lpWndClass.lpszClassName, windowClass_.ptr, byteCount);
2519 OS.RegisterClass (&lpWndClass); 2594 OS.RegisterClass (&lpWndClass);
2520 OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName); 2595 OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName);
2521 2596
2522 /* Register the DWT drop shadow window class */ 2597 /* Register the DWT drop shadow window class */
2523 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) lpWndClass.style |= OS.CS_DROPSHADOW; 2598 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
2599 lpWndClass.style |= OS.CS_DROPSHADOW;
2600 }
2524 byteCount = windowShadowClass.length * TCHAR.sizeof; 2601 byteCount = windowShadowClass.length * TCHAR.sizeof;
2525 lpWndClass.lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 2602 lpWndClass.lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
2526 OS.MoveMemory (lpWndClass.lpszClassName, windowShadowClass.ptr, byteCount); 2603 OS.MoveMemory (lpWndClass.lpszClassName, windowShadowClass.ptr, byteCount);
2527 OS.RegisterClass (&lpWndClass); 2604 OS.RegisterClass (&lpWndClass);
2528 OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName); 2605 OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName);
2538 hInstance, 2615 hInstance,
2539 null); 2616 null);
2540 //messageCallback = new Callback (this, "messageProc", 4); //$NON-NLS-1$ 2617 //messageCallback = new Callback (this, "messageProc", 4); //$NON-NLS-1$
2541 //messageProc_ = messageCallback.getAddress (); 2618 //messageProc_ = messageCallback.getAddress ();
2542 //if (messageProc_ is 0) error (DWT.ERROR_NO_MORE_CALLBACKS); 2619 //if (messageProc_ is 0) error (DWT.ERROR_NO_MORE_CALLBACKS);
2543 OS.SetWindowLong (hwndMessage, OS.GWL_WNDPROC, cast(int) &messageProcFunc); 2620 OS.SetWindowLongPtr (hwndMessage, OS.GWLP_WNDPROC, cast(LONG_PTR) &messageProcFunc);
2544 2621
2545 /* Create the filter hook */ 2622 /* Create the filter hook */
2546 static if (!OS.IsWinCE) { 2623 static if (!OS.IsWinCE) {
2547 //msgFilterCallback = new Callback (this, "msgFilterProc", 3); //$NON-NLS-1$ 2624 //msgFilterCallback = new Callback (this, "msgFilterProc", 3); //$NON-NLS-1$
2548 //msgFilterProc_ = msgFilterCallback.getAddress (); 2625 //msgFilterProc_ = msgFilterCallback.getAddress ();
2559 } 2636 }
2560 2637
2561 /* Register custom messages message */ 2638 /* Register custom messages message */
2562 SWT_TASKBARCREATED = OS.RegisterWindowMessage (StrToTCHARz ( "TaskbarCreated" )); 2639 SWT_TASKBARCREATED = OS.RegisterWindowMessage (StrToTCHARz ( "TaskbarCreated" ));
2563 SWT_RESTORECARET = OS.RegisterWindowMessage (StrToTCHARz ( "SWT_RESTORECARET")); 2640 SWT_RESTORECARET = OS.RegisterWindowMessage (StrToTCHARz ( "SWT_RESTORECARET"));
2641 DI_GETDRAGIMAGE = OS.RegisterWindowMessage (StrToTCHARz ( "ShellGetDragImage")); //$NON-NLS-1$
2564 2642
2565 /* Initialize OLE */ 2643 /* Initialize OLE */
2566 static if (!OS.IsWinCE) OS.OleInitialize (null); 2644 static if (!OS.IsWinCE) OS.OleInitialize (null);
2567 2645
2568 /* Initialize buffered painting */ 2646 /* Initialize buffered painting */
2986 * NOTE: If the modal shell is disabled for any 3064 * NOTE: If the modal shell is disabled for any
2987 * reason, it should not be brought to the front. 3065 * reason, it should not be brought to the front.
2988 */ 3066 */
2989 if (wParam !is 0) { 3067 if (wParam !is 0) {
2990 if (!isXMouseActive ()) { 3068 if (!isXMouseActive ()) {
2991 if (modalDialogShell !is null && modalDialogShell.isDisposed ()) modalDialogShell = null; 3069 auto hwndActive = OS.GetActiveWindow ();
2992 Shell modal = modalDialogShell !is null ? modalDialogShell : getModalShell (); 3070 if (hwndActive !is null && OS.IsWindowEnabled (hwndActive)) break;
2993 if (modal !is null) { 3071 Shell modal = modalDialog !is null ? modalDialog.parent : getModalShell ();
3072 if (modal !is null && !modal.isDisposed ()) {
2994 auto hwndModal = modal.handle; 3073 auto hwndModal = modal.handle;
2995 if (OS.IsWindowEnabled (hwndModal)) { 3074 if (OS.IsWindowEnabled (hwndModal)) {
2996 modal.bringToTop (); 3075 modal.bringToTop ();
2997 if (modal.isDisposed ()) break; 3076 if (modal.isDisposed ()) break;
2998 } 3077 }
3015 /* 3094 /*
3016 * When the session is ending, no DWT program can continue 3095 * When the session is ending, no DWT program can continue
3017 * to run. In order to avoid running code after the display 3096 * to run. In order to avoid running code after the display
3018 * has been disposed, exit from Java. 3097 * has been disposed, exit from Java.
3019 */ 3098 */
3020 System.exit (0); 3099 /* This code is intentionally commented */
3100 // System.exit (0);
3021 } 3101 }
3022 break; 3102 break;
3023 } 3103 }
3024 case OS.WM_QUERYENDSESSION: { 3104 case OS.WM_QUERYENDSESSION: {
3025 Event event = new Event (); 3105 Event event = new Event ();
3026 sendEvent (DWT.Close, event); 3106 sendEvent (DWT.Close, event);
3027 if (!event.doit) return 0; 3107 if (!event.doit) return 0;
3028 break; 3108 break;
3029 } 3109 }
3110 case OS.WM_DWMCOLORIZATIONCOLORCHANGED: {
3111 OS.SetTimer (hwndMessage, SETTINGS_ID, SETTINGS_DELAY, null);
3112 break;
3113 }
3030 case OS.WM_SETTINGCHANGE: { 3114 case OS.WM_SETTINGCHANGE: {
3115 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
3116 OS.SetTimer (hwndMessage, SETTINGS_ID, SETTINGS_DELAY, null);
3117 break;
3118 }
3031 switch (wParam) { 3119 switch (wParam) {
3032 case 0: 3120 case 0:
3033 case 1: 3121 case 1:
3034 case OS.SPI_SETHIGHCONTRAST: 3122 case OS.SPI_SETHIGHCONTRAST:
3035 OS.SetTimer (hwndMessage, SETTINGS_ID, SETTINGS_DELAY, null); 3123 OS.SetTimer (hwndMessage, SETTINGS_ID, SETTINGS_DELAY, null);
3105 } 3193 }
3106 3194
3107 int msgFilterProc (int code, int wParam, int lParam) { 3195 int msgFilterProc (int code, int wParam, int lParam) {
3108 switch (code) { 3196 switch (code) {
3109 case OS.MSGF_COMMCTRL_BEGINDRAG: { 3197 case OS.MSGF_COMMCTRL_BEGINDRAG: {
3110 if (!runDragDrop) { 3198 if (!runDragDrop && !dragCancelled) {
3111 hookMsg = *cast(MSG*)lParam; 3199 *hookMsg = *cast(MSG*)lParam;
3112 if (hookMsg.message is OS.WM_MOUSEMOVE) { 3200 if (hookMsg.message is OS.WM_MOUSEMOVE) {
3201 dragCancelled = true;
3113 OS.SendMessage (hookMsg.hwnd, OS.WM_CANCELMODE, 0, 0); 3202 OS.SendMessage (hookMsg.hwnd, OS.WM_CANCELMODE, 0, 0);
3114 } 3203 }
3115 } 3204 }
3116 break; 3205 break;
3117 } 3206 }
3129 case OS.MSGF_MESSAGEBOX: 3218 case OS.MSGF_MESSAGEBOX:
3130 case OS.MSGF_NEXTWINDOW: 3219 case OS.MSGF_NEXTWINDOW:
3131 case OS.MSGF_SCROLLBAR: 3220 case OS.MSGF_SCROLLBAR:
3132 case OS.MSGF_SIZE: { 3221 case OS.MSGF_SIZE: {
3133 if (runMessages) { 3222 if (runMessages) {
3134 hookMsg = *cast(MSG*)lParam; 3223 *hookMsg = *cast(MSG*)lParam;
3135 if (hookMsg.message is OS.WM_NULL) { 3224 if (hookMsg.message is OS.WM_NULL) {
3136 MSG msg; 3225 MSG msg;
3137 int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE; 3226 int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
3138 if (!OS.PeekMessage (&msg, null, 0, 0, flags)) { 3227 if (!OS.PeekMessage (&msg, null, 0, 0, flags)) {
3139 if (runAsyncMessages (false)) wakeThread (); 3228 if (runAsyncMessages (false)) wakeThread ();
3222 * 3311 *
3223 * @since 3.0 3312 * @since 3.0
3224 * 3313 *
3225 */ 3314 */
3226 public bool post (Event event) { 3315 public bool post (Event event) {
3227 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 3316 synchronized (Device.classinfo) {
3228 if (event is null) error (DWT.ERROR_NULL_ARGUMENT); 3317 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
3229 int type = event.type; 3318 if (event is null) error (DWT.ERROR_NULL_ARGUMENT);
3230 switch (type){ 3319 int type = event.type;
3231 case DWT.KeyDown: 3320 switch (type){
3232 case DWT.KeyUp: { 3321 case DWT.KeyDown:
3322 case DWT.KeyUp: {
3233 KEYBDINPUT inputs; 3323 KEYBDINPUT inputs;
3234 inputs.wVk = cast(short) untranslateKey (event.keyCode); 3324 inputs.wVk = cast(short) untranslateKey (event.keyCode);
3235 if (inputs.wVk is 0) { 3325 if (inputs.wVk is 0) {
3236 char key = event.character; 3326 char key = event.character;
3237 switch (key) { 3327 switch (key) {
3238 case DWT.BS: inputs.wVk = cast(short) OS.VK_BACK; break; 3328 case DWT.BS: inputs.wVk = cast(short) OS.VK_BACK; break;
3239 case DWT.CR: inputs.wVk = cast(short) OS.VK_RETURN; break; 3329 case DWT.CR: inputs.wVk = cast(short) OS.VK_RETURN; break;
3240 case DWT.DEL: inputs.wVk = cast(short) OS.VK_DELETE; break; 3330 case DWT.DEL: inputs.wVk = cast(short) OS.VK_DELETE; break;
3241 case DWT.ESC: inputs.wVk = cast(short) OS.VK_ESCAPE; break; 3331 case DWT.ESC: inputs.wVk = cast(short) OS.VK_ESCAPE; break;
3242 case DWT.TAB: inputs.wVk = cast(short) OS.VK_TAB; break; 3332 case DWT.TAB: inputs.wVk = cast(short) OS.VK_TAB; break;
3243 /* 3333 /*
3244 * Since there is no LF key on the keyboard, do not attempt 3334 * Since there is no LF key on the keyboard, do not attempt
3245 * to map LF to CR or attempt to post an LF key. 3335 * to map LF to CR or attempt to post an LF key.
3246 */ 3336 */
3247 // case DWT.LF: inputs.wVk = cast(short) OS.VK_RETURN; break; 3337 // case DWT.LF: inputs.wVk = cast(short) OS.VK_RETURN; break;
3248 case DWT.LF: return false; 3338 case DWT.LF: return false;
3249 default: { 3339 default: {
3250 static if (OS.IsWinCE) { 3340 static if (OS.IsWinCE) {
3251 inputs.wVk = cast(int)OS.CharUpper (cast(wchar*) key); 3341 inputs.wVk = cast(int)OS.CharUpper (cast(wchar*) key);
3252 } else { 3342 } else {
3253 inputs.wVk = OS.VkKeyScan (cast(short) wcsToMbcs (key, 0)); 3343 inputs.wVk = OS.VkKeyScan (cast(short) wcsToMbcs (key, 0));
3254 if (inputs.wVk is -1) return false; 3344 if (inputs.wVk is -1) return false;
3255 inputs.wVk &= 0xFF; 3345 inputs.wVk &= 0xFF;
3346 }
3256 } 3347 }
3257 } 3348 }
3258 } 3349 }
3259 } 3350 inputs.dwFlags = type is DWT.KeyUp ? OS.KEYEVENTF_KEYUP : 0;
3260 inputs.dwFlags = type is DWT.KeyUp ? OS.KEYEVENTF_KEYUP : 0;
3261 auto hHeap = OS.GetProcessHeap (); 3351 auto hHeap = OS.GetProcessHeap ();
3262 auto pInputs = cast(INPUT*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof); 3352 auto pInputs = cast(INPUT*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof);
3263 pInputs.type = OS.INPUT_KEYBOARD; 3353 pInputs.type = OS.INPUT_KEYBOARD;
3264 pInputs.ki = inputs; 3354 //TODO - DWORD type of INPUT structure aligned to 8 bytes on 64 bit
3265 //OS.MoveMemory (pInputs + 4, inputs, KEYBDINPUT.sizeof); 3355 pInputs.ki = inputs;
3266 bool result = OS.SendInput (1, pInputs, INPUT.sizeof) !is 0; 3356 //OS.MoveMemory (pInputs + 4, inputs, KEYBDINPUT.sizeof);
3267 OS.HeapFree (hHeap, 0, pInputs); 3357 bool result = OS.SendInput (1, pInputs, INPUT.sizeof) !is 0;
3268 return result; 3358 OS.HeapFree (hHeap, 0, pInputs);
3269 } 3359 return result;
3270 case DWT.MouseDown: 3360 }
3271 case DWT.MouseMove: 3361 case DWT.MouseDown:
3272 case DWT.MouseUp: 3362 case DWT.MouseMove:
3273 case DWT.MouseWheel: { 3363 case DWT.MouseUp:
3274 MOUSEINPUT inputs; 3364 case DWT.MouseWheel: {
3275 if (type is DWT.MouseMove){ 3365 MOUSEINPUT inputs;
3276 inputs.dwFlags = OS.MOUSEEVENTF_MOVE | OS.MOUSEEVENTF_ABSOLUTE; 3366 if (type is DWT.MouseMove){
3277 int x= 0, y = 0, width = 0, height = 0; 3367 inputs.dwFlags = OS.MOUSEEVENTF_MOVE | OS.MOUSEEVENTF_ABSOLUTE;
3278 if (OS.WIN32_VERSION >= OS.VERSION (5, 0)) { 3368 int x= 0, y = 0, width = 0, height = 0;
3279 inputs.dwFlags |= OS.MOUSEEVENTF_VIRTUALDESK; 3369 if (OS.WIN32_VERSION >= OS.VERSION (5, 0)) {
3280 x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN); 3370 inputs.dwFlags |= OS.MOUSEEVENTF_VIRTUALDESK;
3281 y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN); 3371 x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN);
3282 width = OS.GetSystemMetrics (OS.SM_CXVIRTUALSCREEN); 3372 y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN);
3283 height = OS.GetSystemMetrics (OS.SM_CYVIRTUALSCREEN); 3373 width = OS.GetSystemMetrics (OS.SM_CXVIRTUALSCREEN);
3374 height = OS.GetSystemMetrics (OS.SM_CYVIRTUALSCREEN);
3375 } else {
3376 width = OS.GetSystemMetrics (OS.SM_CXSCREEN);
3377 height = OS.GetSystemMetrics (OS.SM_CYSCREEN);
3378 }
3379 inputs.dx = ((event.x - x) * 65535 + width - 2) / (width - 1);
3380 inputs.dy = ((event.y - y) * 65535 + height - 2) / (height - 1);
3284 } else { 3381 } else {
3285 width = OS.GetSystemMetrics (OS.SM_CXSCREEN); 3382 if (type is DWT.MouseWheel) {
3286 height = OS.GetSystemMetrics (OS.SM_CYSCREEN); 3383 if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false;
3287 } 3384 inputs.dwFlags = OS.MOUSEEVENTF_WHEEL;
3288 inputs.dx = ((event.x - x) * 65535 + width - 2) / (width - 1); 3385 switch (event.detail) {
3289 inputs.dy = ((event.y - y) * 65535 + height - 2) / (height - 1); 3386 case DWT.SCROLL_PAGE:
3290 } else { 3387 inputs.mouseData = event.count * OS.WHEEL_DELTA;
3291 if (type is DWT.MouseWheel) { 3388 break;
3292 if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false; 3389 case DWT.SCROLL_LINE:
3293 inputs.dwFlags = OS.MOUSEEVENTF_WHEEL; 3390 int value;
3294 switch (event.detail) { 3391 OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, &value, 0);
3295 case DWT.SCROLL_PAGE: 3392 inputs.mouseData = event.count * OS.WHEEL_DELTA / value;
3296 inputs.mouseData = event.count * OS.WHEEL_DELTA; 3393 break;
3297 break; 3394 default: return false;
3298 case DWT.SCROLL_LINE:
3299 int value;
3300 OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, &value, 0);
3301 inputs.mouseData = event.count * OS.WHEEL_DELTA / value;
3302 break;
3303 default: return false;
3304 }
3305 } else {
3306 switch (event.button) {
3307 case 1: inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_LEFTDOWN : OS.MOUSEEVENTF_LEFTUP; break;
3308 case 2: inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_MIDDLEDOWN : OS.MOUSEEVENTF_MIDDLEUP; break;
3309 case 3: inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_RIGHTDOWN : OS.MOUSEEVENTF_RIGHTUP; break;
3310 case 4: {
3311 if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false;
3312 inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_XDOWN : OS.MOUSEEVENTF_XUP;
3313 inputs.mouseData = OS.XBUTTON1;
3314 break;
3315 } 3395 }
3316 case 5: { 3396 } else {
3317 if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false; 3397 switch (event.button) {
3318 inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_XDOWN : OS.MOUSEEVENTF_XUP; 3398 case 1: inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_LEFTDOWN : OS.MOUSEEVENTF_LEFTUP; break;
3319 inputs.mouseData = OS.XBUTTON2; 3399 case 2: inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_MIDDLEDOWN : OS.MOUSEEVENTF_MIDDLEUP; break;
3320 break; 3400 case 3: inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_RIGHTDOWN : OS.MOUSEEVENTF_RIGHTUP; break;
3401 case 4: {
3402 if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false;
3403 inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_XDOWN : OS.MOUSEEVENTF_XUP;
3404 inputs.mouseData = OS.XBUTTON1;
3405 break;
3406 }
3407 case 5: {
3408 if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false;
3409 inputs.dwFlags = type is DWT.MouseDown ? OS.MOUSEEVENTF_XDOWN : OS.MOUSEEVENTF_XUP;
3410 inputs.mouseData = OS.XBUTTON2;
3411 break;
3412 }
3413 default: return false;
3321 } 3414 }
3322 default: return false;
3323 } 3415 }
3324 } 3416 }
3325 } 3417 auto hHeap = OS.GetProcessHeap ();
3326 auto hHeap = OS.GetProcessHeap (); 3418 auto pInputs = cast(INPUT*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof);
3327 auto pInputs = cast(INPUT*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof); 3419 pInputs.type = OS.INPUT_MOUSE;
3328 pInputs.type = OS.INPUT_MOUSE; 3420 //TODO - DWORD type of INPUT structure aligned to 8 bytes on 64 bit
3329 //OS.MoveMemory(pInputs, [OS.INPUT_MOUSE], 4); 3421 pInputs.mi = inputs;
3330 pInputs.mi = inputs; 3422 bool result = OS.SendInput (1, pInputs, INPUT.sizeof) !is 0;
3331 //OS.MoveMemory (pInputs + 4, inputs, MOUSEINPUT.sizeof); 3423 OS.HeapFree (hHeap, 0, pInputs);
3332 bool result = OS.SendInput (1, pInputs, INPUT.sizeof) !is 0; 3424 return result;
3333 OS.HeapFree (hHeap, 0, pInputs); 3425 }
3334 return result;
3335 }
3336 default: 3426 default:
3337 } 3427 }
3338 return false; 3428 return false;
3429 }
3339 } 3430 }
3340 3431
3341 void postEvent (Event event) { 3432 void postEvent (Event event) {
3342 /* 3433 /*
3343 * Place the event at the end of the event queue. 3434 * Place the event at the end of the event queue.
3387 public bool readAndDispatch () { 3478 public bool readAndDispatch () {
3388 checkDevice (); 3479 checkDevice ();
3389 lpStartupInfo = null; 3480 lpStartupInfo = null;
3390 drawMenuBars (); 3481 drawMenuBars ();
3391 runPopups (); 3482 runPopups ();
3392 if (OS.PeekMessage (&msg, null, 0, 0, OS.PM_REMOVE)) { 3483 if (OS.PeekMessage (msg, null, 0, 0, OS.PM_REMOVE)) {
3393 if (!filterMessage (&msg)) { 3484 if (!filterMessage (msg)) {
3394 OS.TranslateMessage (&msg); 3485 OS.TranslateMessage (msg);
3395 OS.DispatchMessage (&msg); 3486 OS.DispatchMessage (msg);
3396 } 3487 }
3397 runDeferredEvents (); 3488 runDeferredEvents ();
3398 return true; 3489 return true;
3399 } 3490 }
3400 return runMessages && runAsyncMessages (false); 3491 return runMessages && runAsyncMessages (false);
3401 } 3492 }
3402 3493
3403 static synchronized void register (Display display) { 3494 static void register (Display display) {
3404 static_this(); 3495 static_this();
3405 for (int i=0; i<Displays.length; i++) { 3496 synchronized (Device.classinfo) {
3406 if (Displays [i] is null) { 3497 for (int i=0; i<Displays.length; i++) {
3407 Displays [i] = display; 3498 if (Displays [i] is null) {
3408 return; 3499 Displays [i] = display;
3409 } 3500 return;
3410 } 3501 }
3411 Display [] newDisplays = new Display [Displays.length + 4]; 3502 }
3412 System.arraycopy (Displays, 0, newDisplays, 0, Displays.length); 3503 Display [] newDisplays = new Display [Displays.length + 4];
3413 newDisplays [Displays.length] = display; 3504 System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
3414 Displays = newDisplays; 3505 newDisplays [Displays.length] = display;
3506 Displays = newDisplays;
3507 }
3415 } 3508 }
3416 3509
3417 /** 3510 /**
3418 * Releases any internal resources back to the operating 3511 * Releases any internal resources back to the operating
3419 * system and clears all fields except the device handle. 3512 * system and clears all fields except the device handle.
3561 OS.BufferedPaintUnInit (); 3654 OS.BufferedPaintUnInit ();
3562 } 3655 }
3563 3656
3564 /* Release references */ 3657 /* Release references */
3565 thread = null; 3658 thread = null;
3566 //msg = null; 3659 msg = null;
3660 hookMsg = null;
3567 //keyboard = null; 3661 //keyboard = null;
3568 modalDialogShell = null; 3662 modalDialog = null;
3569 modalShells = null; 3663 modalShells = null;
3570 data = null; 3664 data = null;
3571 keys = null; 3665 keys = null;
3572 values = null; 3666 values = null;
3573 bars = popups = null; 3667 bars = popups = null;
3574 indexTable = null; 3668 indexTable = null;
3669 timerIds = null;
3575 controlTable = null; 3670 controlTable = null;
3576 lastControl = lastGetControl = lastHittestControl = null; 3671 lastControl = lastGetControl = lastHittestControl = null;
3577 imageList = toolImageList = toolHotImageList = toolDisabledImageList = null; 3672 imageList = toolImageList = toolHotImageList = toolDisabledImageList = null;
3673 timerList = null;
3674 tableBuffer = null;
3675 columnVisible = null;
3676 eventTable = filterTable = null;
3677 items = null;
3678 clickRect = null;
3679 hdr = null;
3680 plvfi = null;
3681
3682 /* Release handles */
3683 threadId = 0;
3578 } 3684 }
3579 3685
3580 void releaseImageList (ImageList list) { 3686 void releaseImageList (ImageList list) {
3581 int i = 0; 3687 int i = 0;
3582 int length_ = imageList.length; 3688 int length_ = imageList.length;
3729 Control control = null; 3835 Control control = null;
3730 int index; 3836 int index;
3731 static if (USE_PROPERTY) { 3837 static if (USE_PROPERTY) {
3732 index = cast(int)OS.RemoveProp (handle, cast(wchar*)SWT_OBJECT_INDEX) - 1; 3838 index = cast(int)OS.RemoveProp (handle, cast(wchar*)SWT_OBJECT_INDEX) - 1;
3733 } else { 3839 } else {
3734 index = OS.GetWindowLong (handle, OS.GWL_USERDATA) - 1; 3840 index = OS.GetWindowLongPtr (handle, OS.GWLP_USERDATA) - 1;
3841 OS.SetWindowLongPtr (handle, OS.GWLP_USERDATA, 0);
3735 } 3842 }
3736 if (0 <= index && index < controlTable.length) { 3843 if (0 <= index && index < controlTable.length) {
3737 control = controlTable [index]; 3844 control = controlTable [index];
3738 controlTable [index] = null; 3845 controlTable [index] = null;
3739 indexTable [index] = freeSlot; 3846 indexTable [index] = freeSlot;
3740 freeSlot = index; 3847 freeSlot = index;
3741 if (!USE_PROPERTY) {
3742 OS.SetWindowLong (handle, OS.GWL_USERDATA, 0);
3743 }
3744 } 3848 }
3745 return control; 3849 return control;
3746 } 3850 }
3747 3851
3748 void removeMenuItem (MenuItem item) { 3852 void removeMenuItem (MenuItem item) {
3836 shell.layout (true, true); 3940 shell.layout (true, true);
3837 } 3941 }
3838 } 3942 }
3839 } 3943 }
3840 3944
3841 bool runTimer (int id) { 3945 bool runTimer (int /*long*/ id) {
3842 if (timerList !is null && timerIds !is null) { 3946 if (timerList !is null && timerIds !is null) {
3843 int index = 0; 3947 int index = 0;
3844 while (index <timerIds.length) { 3948 while (index <timerIds.length) {
3845 if (timerIds [index] is id) { 3949 if (timerIds [index] is id) {
3846 OS.KillTimer (hwndMessage, timerIds [index]); 3950 OS.KillTimer (hwndMessage, timerIds [index]);
3997 if (key ==/*eq*/RUN_MESSAGES_IN_IDLE_KEY) { 4101 if (key ==/*eq*/RUN_MESSAGES_IN_IDLE_KEY) {
3998 auto data = cast(ValueWrapperBool) value; 4102 auto data = cast(ValueWrapperBool) value;
3999 runMessagesInIdle = data !is null && data.value; 4103 runMessagesInIdle = data !is null && data.value;
4000 return; 4104 return;
4001 } 4105 }
4106 if (key.equals (RUN_MESSAGES_IN_MESSAGE_PROC_KEY)) {
4107 Boolean data = cast(Boolean) value;
4108 runMessagesInMessageProc = data !is null && data.booleanValue ();
4109 return;
4110 }
4002 4111
4003 /* Remove the key/value pair */ 4112 /* Remove the key/value pair */
4004 if (value is null) { 4113 if (value is null) {
4005 if (keys is null) return; 4114 if (keys is null) return;
4006 int index = 0; 4115 int index = 0;
4084 */ 4193 */
4085 public static void setAppName (String name) { 4194 public static void setAppName (String name) {
4086 /* Do nothing */ 4195 /* Do nothing */
4087 } 4196 }
4088 4197
4089 void setModalDialogShell (Shell modalDailog) { 4198 void setModalDialog (Dialog modalDailog) {
4090 if (modalDialogShell !is null && modalDialogShell.isDisposed ()) modalDialogShell = null; 4199 this.modalDialog = modalDailog;
4091 this.modalDialogShell = modalDailog;
4092 Shell [] shells = getShells (); 4200 Shell [] shells = getShells ();
4093 for (int i=0; i<shells.length; i++) shells [i].updateModal (); 4201 for (int i=0; i<shells.length; i++) shells [i].updateModal ();
4094 } 4202 }
4095 4203
4096 void setModalShell (Shell shell) { 4204 void setModalShell (Shell shell) {
4127 * </ul> 4235 * </ul>
4128 */ 4236 */
4129 public void setSynchronizer (Synchronizer synchronizer) { 4237 public void setSynchronizer (Synchronizer synchronizer) {
4130 checkDevice (); 4238 checkDevice ();
4131 if (synchronizer is null) error (DWT.ERROR_NULL_ARGUMENT); 4239 if (synchronizer is null) error (DWT.ERROR_NULL_ARGUMENT);
4132 if (this.synchronizer !is null) { 4240 if (synchronizer is this.synchronizer) return;
4133 this.synchronizer.runAsyncMessages(true); 4241 Synchronizer oldSynchronizer;
4134 } 4242 synchronized (Device.classinfo) {
4135 this.synchronizer = synchronizer; 4243 oldSynchronizer = this.synchronizer;
4244 this.synchronizer = synchronizer;
4245 }
4246 if (oldSynchronizer !is null) {
4247 oldSynchronizer.runAsyncMessages(true);
4248 }
4136 } 4249 }
4137 4250
4138 int shiftedKey (int key) { 4251 int shiftedKey (int key) {
4139 static if (OS.IsWinCE) return 0; 4252 static if (OS.IsWinCE) return 0;
4140 4253
4198 * </ul> 4311 * </ul>
4199 * 4312 *
4200 * @see #asyncExec 4313 * @see #asyncExec
4201 */ 4314 */
4202 public void syncExec (Runnable runnable) { 4315 public void syncExec (Runnable runnable) {
4203 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 4316 Synchronizer synchronizer;
4317 synchronized (Device.classinfo) {
4318 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
4319 synchronizer = this.synchronizer;
4320 }
4204 synchronizer.syncExec (runnable); 4321 synchronizer.syncExec (runnable);
4205 } 4322 }
4206 4323
4207 /** 4324 /**
4208 * Causes the <code>run()</code> method of the runnable to 4325 * Causes the <code>run()</code> method of the runnable to
4232 public void timerExec (int milliseconds, Runnable runnable) { 4349 public void timerExec (int milliseconds, Runnable runnable) {
4233 checkDevice (); 4350 checkDevice ();
4234 if (runnable is null) error (DWT.ERROR_NULL_ARGUMENT); 4351 if (runnable is null) error (DWT.ERROR_NULL_ARGUMENT);
4235 assert( runnable ); 4352 assert( runnable );
4236 if (timerList is null) timerList = new Runnable [4]; 4353 if (timerList is null) timerList = new Runnable [4];
4237 if (timerIds is null) timerIds = new int [4]; 4354 if (timerIds is null) timerIds = new int /*long*/ [4];
4238 int index = 0; 4355 int index = 0;
4239 while (index < timerList.length) { 4356 while (index < timerList.length) {
4240 if (timerList [index] is runnable) break; 4357 if (timerList [index] is runnable) break;
4241 index++; 4358 index++;
4242 } 4359 }
4243 int timerId = 0; 4360 int /*long*/ timerId = 0;
4244 if (index !is timerList.length) { 4361 if (index !is timerList.length) {
4245 timerId = timerIds [index]; 4362 timerId = timerIds [index];
4246 if (milliseconds < 0) { 4363 if (milliseconds < 0) {
4247 OS.KillTimer (hwndMessage, timerId); 4364 OS.KillTimer (hwndMessage, timerId);
4248 timerList [index] = null; 4365 timerList [index] = null;
4259 timerId = nextTimerId++; 4376 timerId = nextTimerId++;
4260 if (index is timerList.length) { 4377 if (index is timerList.length) {
4261 Runnable [] newTimerList = new Runnable [timerList.length + 4]; 4378 Runnable [] newTimerList = new Runnable [timerList.length + 4];
4262 SimpleType!(Runnable).arraycopy (timerList, 0, newTimerList, 0, timerList.length); 4379 SimpleType!(Runnable).arraycopy (timerList, 0, newTimerList, 0, timerList.length);
4263 timerList = newTimerList; 4380 timerList = newTimerList;
4264 int [] newTimerIds = new int [timerIds.length + 4]; 4381 int /*long*/ [] newTimerIds = new int /*long*/ [timerIds.length + 4];
4265 System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length); 4382 System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
4266 timerIds = newTimerIds; 4383 timerIds = newTimerIds;
4267 } 4384 }
4268 } 4385 }
4269 int newTimerID = OS.SetTimer (hwndMessage, timerId, milliseconds, null); 4386 int newTimerID = OS.SetTimer (hwndMessage, timerId, milliseconds, null);
4393 * </ul> 4510 * </ul>
4394 * 4511 *
4395 * @see #sleep 4512 * @see #sleep
4396 */ 4513 */
4397 public void wake () { 4514 public void wake () {
4398 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 4515 synchronized (Device.classinfo) {
4399 if (thread is Thread.getThis ()) return; 4516 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
4400 wakeThread (); 4517 if (thread is Thread.getThis ()) return;
4518 wakeThread ();
4519 }
4401 } 4520 }
4402 4521
4403 void wakeThread () { 4522 void wakeThread () {
4404 static if (OS.IsWinCE) { 4523 static if (OS.IsWinCE) {
4405 OS.PostMessage (hwndMessage, OS.WM_NULL, 0, 0); 4524 OS.PostMessage (hwndMessage, OS.WM_NULL, 0, 0);
4448 int windowProc(){ 4567 int windowProc(){
4449 return cast(int)&windowProcFunc; 4568 return cast(int)&windowProcFunc;
4450 } 4569 }
4451 4570
4452 int windowProc (HWND hwnd, uint msg, uint wParam, int lParam) { 4571 int windowProc (HWND hwnd, uint msg, uint wParam, int lParam) {
4572 /*
4573 * Feature in Windows. On Vista only, it is faster to
4574 * compute and answer the data for the visible columns
4575 * of a table when scrolling, rather than just return
4576 * the data for each column when asked.
4577 */
4578 if (columnVisible !is null) {
4579 if (msg is OS.WM_NOTIFY && hwndParent is hwnd) {
4580 OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
4581 switch (hdr.code) {
4582 case OS.LVN_GETDISPINFOA:
4583 case OS.LVN_GETDISPINFOW: {
4584 OS.MoveMemory (plvfi, lParam, NMLVDISPINFO.sizeof);
4585 if (0 <= plvfi.item.iSubItem && plvfi.item.iSubItem < columnCount) {
4586 if (!columnVisible [plvfi.item.iSubItem]) return 0;
4587 }
4588 break;
4589 }
4590 }
4591 }
4592 }
4453 /* 4593 /*
4454 * Bug in Adobe Reader 7.0. For some reason, when Adobe 4594 * Bug in Adobe Reader 7.0. For some reason, when Adobe
4455 * Reader 7.0 is deactivated from within Internet Explorer, 4595 * Reader 7.0 is deactivated from within Internet Explorer,
4456 * it sends thousands of consecutive WM_NCHITTEST messages 4596 * it sends thousands of consecutive WM_NCHITTEST messages
4457 * to the control that is under the cursor. It seems that 4597 * to the control that is under the cursor. It seems that
4475 } 4615 }
4476 int index; 4616 int index;
4477 static if (USE_PROPERTY) { 4617 static if (USE_PROPERTY) {
4478 index = cast(int)OS.GetProp (hwnd, cast(wchar*)SWT_OBJECT_INDEX) - 1; 4618 index = cast(int)OS.GetProp (hwnd, cast(wchar*)SWT_OBJECT_INDEX) - 1;
4479 } else { 4619 } else {
4480 index = OS.GetWindowLong (hwnd, OS.GWL_USERDATA) - 1; 4620 index = OS.GetWindowLongPtr (hwnd, OS.GWLP_USERDATA) - 1;
4481 } 4621 }
4482 if (0 <= index && index < controlTable.length) { 4622 if (0 <= index && index < controlTable.length) {
4483 Control control = controlTable [index]; 4623 Control control = controlTable [index];
4484 if (control !is null) { 4624 if (control !is null) {
4485 lastHwnd = hwnd; 4625 lastHwnd = hwnd;