Mercurial > projects > dwt-win
changeset 71:effe4929903f
Tracker
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 22:23:04 +0100 |
parents | eabb41384d60 |
children | 14663720fb36 |
files | dwt/widgets/Tracker.d |
diffstat | 1 files changed, 100 insertions(+), 90 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/Tracker.d Mon Feb 04 21:48:28 2008 +0100 +++ b/dwt/widgets/Tracker.d Mon Feb 04 22:23:04 2008 +0100 @@ -10,12 +10,6 @@ *******************************************************************************/ module dwt.widgets.Tracker; -import dwt.widgets.Widget; -class Tracker : Widget { - this( Widget, int ); -} -/++ - import dwt.DWT; import dwt.DWTException; import dwt.events.ControlListener; @@ -23,13 +17,17 @@ import dwt.graphics.Cursor; import dwt.graphics.Point; import dwt.graphics.Rectangle; -import dwt.internal.Callback; -import dwt.internal.win32.LRESULT; -import dwt.internal.win32.MSG; import dwt.internal.win32.OS; -import dwt.internal.win32.PAINTSTRUCT; -import dwt.internal.win32.POINT; -import dwt.internal.win32.RECT; + +import dwt.widgets.Widget; +import dwt.widgets.Control; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.TypedListener; +import dwt.widgets.Shell; +import dwt.widgets.Event; + +import dwt.dwthelper.utils; /** * Instances of this class implement rubber banding rectangles that are @@ -50,14 +48,17 @@ * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ -public class Tracker extends Widget { +public class Tracker : Widget { Control parent; bool tracking, cancelled, stippled; - Rectangle [] rectangles = new Rectangle [0], proportions = rectangles; + Rectangle [] rectangles, proportions; Rectangle bounds; - int resizeCursor, clientCursor, cursorOrientation = DWT.NONE; + HCURSOR resizeCursor, clientCursor; + int cursorOrientation = DWT.NONE; bool inEvent = false; - int hwndTransparent, oldProc, oldX, oldY; + HWND hwndTransparent; + WNDPROC oldProc; + int oldX, oldY; /* * The following values mirror step sizes on Windows @@ -97,7 +98,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Tracker (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); this.parent = parent; } @@ -136,7 +137,7 @@ * @see DWT#UP * @see DWT#DOWN */ -public Tracker (Display display, int style) { +public this (Display display, int style) { if (display is null) display = Display.getCurrent (); if (display is null) display = Display.getDefault (); if (!display.isValidThread ()) { @@ -204,13 +205,13 @@ if (bounds is null) return null; int newX = bounds.x + bounds.width / 2; int newY = bounds.y; - POINT pt = new POINT (); + POINT pt; pt.x = newX; pt.y = newY; /* * Convert to screen coordinates iff needed */ if (parent !is null) { - OS.ClientToScreen (parent.handle, pt); + OS.ClientToScreen (parent.handle, &pt); } OS.SetCursorPos (pt.x, pt.y); return new Point (pt.x, pt.y); @@ -236,13 +237,13 @@ newY = bounds.y + bounds.height / 2; } - POINT pt = new POINT (); + POINT pt; pt.x = newX; pt.y = newY; /* * Convert to screen coordinates iff needed */ if (parent !is null) { - OS.ClientToScreen (parent.handle, pt); + OS.ClientToScreen (parent.handle, &pt); } OS.SetCursorPos (pt.x, pt.y); @@ -250,39 +251,39 @@ * If the client has not provided a custom cursor then determine * the appropriate resize cursor. */ - if (clientCursor is 0) { - int newCursor = 0; + if (clientCursor is null) { + HCURSOR newCursor; switch (cursorOrientation) { case DWT.UP: - newCursor = OS.LoadCursor (0, OS.IDC_SIZENS); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZENS); break; case DWT.DOWN: - newCursor = OS.LoadCursor (0, OS.IDC_SIZENS); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZENS); break; case DWT.LEFT: - newCursor = OS.LoadCursor (0, OS.IDC_SIZEWE); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZEWE); break; case DWT.RIGHT: - newCursor = OS.LoadCursor (0, OS.IDC_SIZEWE); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZEWE); break; case DWT.LEFT | DWT.UP: - newCursor = OS.LoadCursor (0, OS.IDC_SIZENWSE); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZENWSE); break; case DWT.RIGHT | DWT.DOWN: - newCursor = OS.LoadCursor (0, OS.IDC_SIZENWSE); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZENWSE); break; case DWT.LEFT | DWT.DOWN: - newCursor = OS.LoadCursor (0, OS.IDC_SIZENESW); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZENESW); break; case DWT.RIGHT | DWT.UP: - newCursor = OS.LoadCursor (0, OS.IDC_SIZENESW); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZENESW); break; default: - newCursor = OS.LoadCursor (0, OS.IDC_SIZEALL); + newCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZEALL); break; } OS.SetCursor (newCursor); - if (resizeCursor !is 0) { + if (resizeCursor !is null) { OS.DestroyCursor (resizeCursor); } resizeCursor = newCursor; @@ -360,7 +361,7 @@ */ void drawRectangles (Rectangle [] rects, bool stippled) { if (parent is null && !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { - RECT rect1 = new RECT(); + RECT rect1; int bandWidth = stippled ? 3 : 1; for (int i = 0; i < rects.length; i++) { Rectangle rect = rects[i]; @@ -368,19 +369,20 @@ rect1.top = rect.y - bandWidth; rect1.right = rect.x + rect.width + bandWidth * 2; rect1.bottom = rect.y + rect.height + bandWidth * 2; - OS.RedrawWindow (hwndTransparent, rect1, 0, OS.RDW_INVALIDATE); + OS.RedrawWindow (hwndTransparent, &rect1, null, OS.RDW_INVALIDATE); } return; } int bandWidth = 1; - int hwndTrack = OS.GetDesktopWindow (); + auto hwndTrack = OS.GetDesktopWindow (); if (parent !is null) hwndTrack = parent.handle; - int hDC = OS.GetDCEx (hwndTrack, 0, OS.DCX_CACHE); - int hBitmap = 0, hBrush = 0, oldBrush = 0; + auto hDC = OS.GetDCEx (hwndTrack, null, OS.DCX_CACHE); + HBITMAP hBitmap; + HBRUSH hBrush, oldBrush; if (stippled) { bandWidth = 3; - byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0}; - hBitmap = OS.CreateBitmap (8, 8, 1, 1, bits); + byte [] bits = [-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0]; + hBitmap = OS.CreateBitmap (8, 8, 1, 1, bits.ptr); hBrush = OS.CreatePatternBrush (hBitmap); oldBrush = OS.SelectObject (hDC, hBrush); } @@ -486,7 +488,7 @@ * in order to get all mouse/keyboard events that occur * outside of our visible windows (ie.- over the desktop). */ - Callback newProc = null; + //Callback newProc = null; bool mouseDown = OS.GetKeyState(OS.VK_LBUTTON) < 0; bool isVista = !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0); if ((parent is null && isVista) || !mouseDown) { @@ -494,22 +496,24 @@ int height = OS.GetSystemMetrics (OS.SM_CYSCREEN); hwndTransparent = OS.CreateWindowEx ( isVista ? OS.WS_EX_LAYERED | OS.WS_EX_NOACTIVATE : OS.WS_EX_TRANSPARENT, - display.windowClass, + display.windowClass_, null, OS.WS_POPUP, 0, 0, width, height, - 0, - 0, + null, + null, OS.GetModuleHandle (null), null); - oldProc = OS.GetWindowLong (hwndTransparent, OS.GWL_WNDPROC); - newProc = new Callback (this, "transparentProc", 4); //$NON-NLS-1$ - int newProcAddress = newProc.getAddress (); - if (newProcAddress is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); - OS.SetWindowLong (hwndTransparent, OS.GWL_WNDPROC, newProcAddress); - if (isVista) { - OS.SetLayeredWindowAttributes (hwndTransparent, 0xFFFFFF, (byte)0xFF, OS.LWA_COLORKEY | OS.LWA_ALPHA); + oldProc = cast(WNDPROC) OS.GetWindowLong (hwndTransparent, OS.GWL_WNDPROC); + //newProc = new Callback (this, "transparentProc", 4); //$NON-NLS-1$ + //int newProcAddress = newProc.getAddress (); + //if (newProcAddress is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); + OS.SetWindowLong (hwndTransparent, OS.GWL_WNDPROC, cast(int) &transparentFunc ); + + //PORTING_FIXME: Vista version + version( VISTA ) if (isVista) { + OS.SetLayeredWindowAttributes (hwndTransparent, 0xFFFFFF, cast(byte)0xFF, OS.LWA_COLORKEY | OS.LWA_ALPHA); } OS.ShowWindow (hwndTransparent, OS.SW_SHOWNOACTIVATE); } @@ -518,8 +522,8 @@ drawRectangles (rectangles, stippled); Point cursorPos = null; if (mouseDown) { - POINT pt = new POINT (); - OS.GetCursorPos (pt); + POINT pt; + OS.GetCursorPos (&pt); cursorPos = new Point (pt.x, pt.y); } else { if ((style & DWT.RESIZE) !is 0) { @@ -535,11 +539,11 @@ try { /* Tracker behaves like a Dialog with its own OS event loop. */ - MSG msg = new MSG (); + MSG msg; while (tracking && !cancelled) { if (parent !is null && parent.isDisposed ()) break; - OS.GetMessage (msg, 0, 0, 0); - OS.TranslateMessage (msg); + OS.GetMessage (&msg, null, 0, 0); + OS.TranslateMessage (&msg); switch (msg.message) { case OS.WM_LBUTTONUP: case OS.WM_MOUSEMOVE: @@ -561,7 +565,7 @@ drawRectangles (rectangles, stippled); } } - OS.DispatchMessage (msg); + OS.DispatchMessage (&msg); if (!(parent is null && isVista)) { if (msg.message is OS.WM_PAINT) { drawRectangles (rectangles, stippled); @@ -578,21 +582,21 @@ * Cleanup: If a transparent window was created in order to capture events then * destroy it and its callback object now. */ - if (hwndTransparent !is 0) { + if (hwndTransparent !is null) { OS.DestroyWindow (hwndTransparent); - hwndTransparent = 0; + hwndTransparent = null; } - if (newProc !is null) { - newProc.dispose (); - oldProc = 0; - } + //if (newProc !is null) { + //newProc.dispose (); + oldProc = null; + //} /* * Cleanup: If this tracker was resizing then the last cursor that it created * needs to be destroyed. */ - if (resizeCursor !is 0) { + if (resizeCursor !is null) { OS.DestroyCursor (resizeCursor); - resizeCursor = 0; + resizeCursor = null; } } tracking = false; @@ -781,7 +785,7 @@ */ public void setCursor(Cursor newCursor) { checkWidget(); - clientCursor = 0; + clientCursor = null; if (newCursor !is null) { clientCursor = newCursor.handle; if (inEvent) OS.SetCursor (clientCursor); @@ -829,7 +833,13 @@ this.stippled = stippled; } -int transparentProc (int hwnd, int msg, int wParam, int lParam) { +private static extern(Windows) int transparentFunc (HWND hwnd, int msg, int wParam, int lParam) { + Display d = Display.getCurrent(); + auto t = cast(Tracker) d.findControl( hwnd ); + return t.transparentProc( hwnd, msg, wParam, lParam ); +} + +int transparentProc (HWND hwnd, int msg, int wParam, int lParam) { switch (msg) { /* * We typically do not want to answer that the transparent window is @@ -844,30 +854,31 @@ if (inEvent) return OS.HTTRANSPARENT; break; case OS.WM_SETCURSOR: - if (clientCursor !is 0) { + if (clientCursor !is null) { OS.SetCursor (clientCursor); return 1; } - if (resizeCursor !is 0) { + if (resizeCursor !is null) { OS.SetCursor (resizeCursor); return 1; } break; case OS.WM_PAINT: if (parent is null && !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { - PAINTSTRUCT ps = new PAINTSTRUCT(); - int hDC = OS.BeginPaint (hwnd, ps); - int hBitmap = 0, hBrush = 0, oldBrush = 0; - int transparentBrush = OS.CreateSolidBrush(0xFFFFFF); + PAINTSTRUCT ps; + auto hDC = OS.BeginPaint (hwnd, &ps); + HBITMAP hBitmap; + HBRUSH hBrush, oldBrush; + auto transparentBrush = OS.CreateSolidBrush(0xFFFFFF); oldBrush = OS.SelectObject (hDC, transparentBrush); - OS.PatBlt (hDC, ps.left, ps.top, ps.right - ps.left, ps.bottom - ps.top, OS.PATCOPY); + OS.PatBlt (hDC, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top, OS.PATCOPY); OS.SelectObject (hDC, oldBrush); OS.DeleteObject (transparentBrush); int bandWidth = 1; if (stippled) { bandWidth = 3; - byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0}; - hBitmap = OS.CreateBitmap (8, 8, 1, 1, bits); + byte [] bits = [-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0]; + hBitmap = OS.CreateBitmap (8, 8, 1, 1, bits.ptr); hBrush = OS.CreatePatternBrush (hBitmap); oldBrush = OS.SelectObject (hDC, hBrush); OS.SetBkColor (hDC, 0xF0F0F0); @@ -887,7 +898,7 @@ OS.DeleteObject (hBrush); OS.DeleteObject (hBitmap); } - OS.EndPaint (hwnd, ps); + OS.EndPaint (hwnd, &ps); return 0; } } @@ -905,9 +916,9 @@ } } -override LRESULT wmKeyDown (int hwnd, int wParam, int lParam) { +override LRESULT wmKeyDown (HWND hwnd, int wParam, int lParam) { LRESULT result = super.wmKeyDown (hwnd, wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; bool isMirrored = parent !is null && (parent.style & DWT.MIRRORED) !is 0; int stepSize = OS.GetKeyState (OS.VK_CONTROL) < 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE; int xChange = 0, yChange = 0; @@ -972,7 +983,7 @@ draw = true; } else { for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { + if (rectangles [i]!=/*eq*/rectsToErase [i]) { draw = true; break; } @@ -1015,7 +1026,7 @@ draw = true; } else { for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { + if (rectangles [i]!=/*eq*/rectsToErase [i]) { draw = true; break; } @@ -1039,9 +1050,9 @@ return result; } -override LRESULT wmSysKeyDown (int hwnd, int wParam, int lParam) { +override LRESULT wmSysKeyDown (HWND hwnd, int wParam, int lParam) { LRESULT result = super.wmSysKeyDown (hwnd, wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; cancelled = true; tracking = false; return result; @@ -1050,8 +1061,8 @@ LRESULT wmMouse (int message, int wParam, int lParam) { bool isMirrored = parent !is null && (parent.style & DWT.MIRRORED) !is 0; int newPos = OS.GetMessagePos (); - int newX = (short) (newPos & 0xFFFF); - int newY = (short) (newPos >> 16); + int newX = cast(short) (newPos & 0xFFFF); + int newY = cast(short) (newPos >> 16); if (newX !is oldX || newY !is oldY) { Rectangle [] oldRectangles = rectangles; bool oldStippled = stippled; @@ -1095,7 +1106,7 @@ draw = true; } else { for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { + if (rectangles [i]!=/*eq*/rectsToErase [i]) { draw = true; break; } @@ -1147,7 +1158,7 @@ draw = true; } else { for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { + if (rectangles [i]!=/*eq*/rectsToErase [i]) { draw = true; break; } @@ -1166,8 +1177,7 @@ oldY = newY; } tracking = message !is OS.WM_LBUTTONUP; - return null; + return LRESULT.NULL; } } -++/ \ No newline at end of file