Mercurial > projects > dwt-win
changeset 62:7757dae4f29f
Sash
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 14:32:57 +0100 |
parents | cb74965f7ca3 |
children | adfa8c39be39 |
files | dwt/widgets/Sash.d dwt/widgets/Scale.d |
diffstat | 2 files changed, 85 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/Sash.d Mon Feb 04 14:20:47 2008 +0100 +++ b/dwt/widgets/Sash.d Mon Feb 04 14:32:57 2008 +0100 @@ -10,20 +10,21 @@ *******************************************************************************/ module dwt.widgets.Sash; -import dwt.widgets.Control; -class Sash : Control { -} -/++ + + import dwt.DWT; import dwt.DWTException; import dwt.events.SelectionEvent; import dwt.events.SelectionListener; import dwt.graphics.Point; -import dwt.internal.win32.LRESULT; import dwt.internal.win32.OS; -import dwt.internal.win32.POINT; -import dwt.internal.win32.RECT; -import dwt.internal.win32.TCHAR; + +import dwt.widgets.Control; +import dwt.widgets.Composite; +import dwt.widgets.TypedListener; +import dwt.widgets.Event; + +import dwt.dwthelper.utils; /** * Instances of the receiver represent a selectable user interface object @@ -42,15 +43,15 @@ * within the DWT implementation. * </p> */ -public class Sash extends Control { +public class Sash : Control { alias Control.computeSize computeSize; alias Control.windowProc windowProc; bool dragging; int startX, startY, lastX, lastY; - final static int INCREMENT = 1; - final static int PAGE_INCREMENT = 9; + const static int INCREMENT = 1; + const static int PAGE_INCREMENT = 9; /** * Constructs a new instance of this class given its parent @@ -81,7 +82,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Sash (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); } @@ -118,9 +119,9 @@ addListener (DWT.DefaultSelection,typedListener); } -override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { - if (handle is 0) return 0; - return OS.DefWindowProc (hwnd, msg, wParam, lParam); +override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { + if (handle is null) return LRESULT.ZERO; + return cast(LRESULT) OS.DefWindowProc (hwnd, msg, wParam, lParam); } override void createHandle () { @@ -148,12 +149,12 @@ void drawBand (int x, int y, int width, int height) { if ((style & DWT.SMOOTH) !is 0) return; - int hwndTrack = parent.handle; - byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0}; - int stippleBitmap = OS.CreateBitmap (8, 8, 1, 1, bits); - int stippleBrush = OS.CreatePatternBrush (stippleBitmap); - int hDC = OS.GetDCEx (hwndTrack, 0, OS.DCX_CACHE); - int oldBrush = OS.SelectObject (hDC, stippleBrush); + HWND hwndTrack = parent.handle; + byte [] bits = [-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0]; + auto stippleBitmap = OS.CreateBitmap (8, 8, 1, 1, bits.ptr); + auto stippleBrush = OS.CreatePatternBrush (stippleBitmap); + auto hDC = OS.GetDCEx (hwndTrack, null, OS.DCX_CACHE); + auto oldBrush = OS.SelectObject (hDC, stippleBrush); OS.PatBlt (hDC, x, y, width, height, OS.PATINVERT); OS.SelectObject (hDC, oldBrush); OS.ReleaseDC (hwndTrack, hDC); @@ -186,23 +187,23 @@ eventTable.unhook (DWT.DefaultSelection,listener); } -override TCHAR windowClass () { - return display.windowClass; +override char[] windowClass () { + return display.windowClass(); } override int windowProc () { - return display.windowProc; + return display.windowProc(); } override LRESULT WM_ERASEBKGND (int wParam, int lParam) { super.WM_ERASEBKGND (wParam, lParam); - drawBackground (wParam); + drawBackground (cast(HANDLE) wParam); return LRESULT.ONE; } override LRESULT WM_KEYDOWN (int wParam, int lParam) { LRESULT result = super.WM_KEYDOWN (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; switch (wParam) { case OS.VK_LEFT: case OS.VK_RIGHT: @@ -212,7 +213,7 @@ /* Calculate the new x or y position */ if (OS.GetKeyState (OS.VK_LBUTTON) < 0) return result; int step = OS.GetKeyState (OS.VK_CONTROL) < 0 ? INCREMENT : PAGE_INCREMENT; - POINT pt = new POINT (); + POINT pt; if ((style & DWT.VERTICAL) !is 0) { if (wParam is OS.VK_UP || wParam is OS.VK_DOWN) break; pt.x = wParam is OS.VK_LEFT ? -step : step; @@ -220,13 +221,13 @@ if (wParam is OS.VK_LEFT || wParam is OS.VK_RIGHT) break; pt.y = wParam is OS.VK_UP ? -step : step; } - int hwndTrack = parent.handle; - OS.MapWindowPoints (handle, hwndTrack, pt, 1); - RECT rect = new RECT (), clientRect = new RECT (); - OS.GetWindowRect (handle, rect); + auto hwndTrack = parent.handle; + OS.MapWindowPoints (handle, hwndTrack, &pt, 1); + RECT rect, clientRect; + OS.GetWindowRect (handle, &rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; - OS.GetClientRect (hwndTrack, clientRect); + OS.GetClientRect (hwndTrack, &clientRect); int clientWidth = clientRect.right - clientRect.left; int clientHeight = clientRect.bottom - clientRect.top; int newX = lastX, newY = lastY; @@ -238,9 +239,9 @@ if (newX is lastX && newY is lastY) return result; /* Update the pointer position */ - POINT cursorPt = new POINT (); + POINT cursorPt; cursorPt.x = pt.x; cursorPt.y = pt.y; - OS.ClientToScreen (hwndTrack, cursorPt); + OS.ClientToScreen (hwndTrack, &cursorPt); if ((style & DWT.VERTICAL) !is 0) { cursorPt.y += height / 2; } @@ -267,7 +268,7 @@ } override LRESULT WM_GETDLGCODE (int wParam, int lParam) { - return new LRESULT (OS.DLGC_STATIC); + return cast(LRESULT)(OS.DLGC_STATIC); } override LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { @@ -275,16 +276,16 @@ if (result is LRESULT.ZERO) return result; /* Compute the banding rectangle */ - int hwndTrack = parent.handle; - POINT pt = new POINT (); - pt.x = (short) (lParam & 0xFFFF); - pt.y = (short) (lParam >> 16); - RECT rect = new RECT (); - OS.GetWindowRect (handle, rect); - OS.MapWindowPoints (handle, 0, pt, 1); + auto hwndTrack = parent.handle; + POINT pt; + pt.x = cast(short) (lParam & 0xFFFF); + pt.y = cast(short) (lParam >> 16); + RECT rect; + OS.GetWindowRect (handle, &rect); + OS.MapWindowPoints (handle, null, &pt, 1); startX = pt.x - rect.left; startY = pt.y - rect.top; - OS.MapWindowPoints (0, hwndTrack, rect, 2); + OS.MapWindowPoints (null, hwndTrack, cast(POINT*) &rect, 2); lastX = rect.left; lastY = rect.top; int width = rect.right - rect.left; @@ -313,7 +314,7 @@ OS.UpdateWindow (hwndTrack); } else { int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; - OS.RedrawWindow (hwndTrack, null, 0, flags); + OS.RedrawWindow (hwndTrack, null, null, flags); } drawBand (event.x, event.y, width, height); if ((style & DWT.SMOOTH) !is 0) { @@ -331,8 +332,8 @@ /* Compute the banding rectangle */ if (!dragging) return result; dragging = false; - RECT rect = new RECT (); - OS.GetWindowRect (handle, rect); + RECT rect; + OS.GetWindowRect (handle, &rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; @@ -356,20 +357,20 @@ override LRESULT WM_MOUSEMOVE (int wParam, int lParam) { LRESULT result = super.WM_MOUSEMOVE (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; if (!dragging || (wParam & OS.MK_LBUTTON) is 0) return result; /* Compute the banding rectangle */ - POINT pt = new POINT (); - pt.x = (short) (lParam & 0xFFFF); - pt.y = (short) (lParam >> 16); - int hwndTrack = parent.handle; - OS.MapWindowPoints (handle, hwndTrack, pt, 1); - RECT rect = new RECT (), clientRect = new RECT (); - OS.GetWindowRect (handle, rect); + POINT pt; + pt.x = cast(short) (lParam & 0xFFFF); + pt.y = cast(short) (lParam >> 16); + auto hwndTrack = parent.handle; + OS.MapWindowPoints (handle, hwndTrack, &pt, 1); + RECT rect, clientRect; + OS.GetWindowRect (handle, &rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; - OS.GetClientRect (hwndTrack, clientRect); + OS.GetClientRect (hwndTrack, &clientRect); int newX = lastX, newY = lastY; if ((style & DWT.VERTICAL) !is 0) { int clientWidth = clientRect.right - clientRect.left; @@ -400,7 +401,7 @@ OS.UpdateWindow (hwndTrack); } else { int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; - OS.RedrawWindow (hwndTrack, null, 0, flags); + OS.RedrawWindow (hwndTrack, null, null, flags); } drawBand (lastX, lastY, width, height); if ((style & DWT.SMOOTH) !is 0) { @@ -412,14 +413,14 @@ override LRESULT WM_SETCURSOR (int wParam, int lParam) { LRESULT result = super.WM_SETCURSOR (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; int hitTest = lParam & 0xFFFF; if (hitTest is OS.HTCLIENT) { - int hCursor = 0; + HCURSOR hCursor; if ((style & DWT.HORIZONTAL) !is 0) { - hCursor = OS.LoadCursor (0, OS.IDC_SIZENS); + hCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZENS); } else { - hCursor = OS.LoadCursor (0, OS.IDC_SIZEWE); + hCursor = OS.LoadCursor (null, cast(TCHAR*)OS.IDC_SIZEWE); } OS.SetCursor (hCursor); return LRESULT.ONE; @@ -428,4 +429,4 @@ } } -++/ +
--- a/dwt/widgets/Scale.d Mon Feb 04 14:20:47 2008 +0100 +++ b/dwt/widgets/Scale.d Mon Feb 04 14:32:57 2008 +0100 @@ -10,13 +10,6 @@ *******************************************************************************/ module dwt.widgets.Scale; -import dwt.widgets.Control; -import dwt.widgets.Composite; - -class Scale : Control { - this (Composite parent, int style) ; -} -/++ import dwt.DWT; import dwt.DWTException; import dwt.events.SelectionListener; @@ -27,6 +20,11 @@ import dwt.internal.win32.TCHAR; import dwt.internal.win32.WNDCLASS; +import dwt.widgets.Control; +import dwt.widgets.Composite; + +import dwt.dwthelper.utils; + /** * Instances of the receiver represent a selectable user * interface object that present a range of continuous @@ -46,18 +44,18 @@ * </p> */ -public class Scale extends Control { +public class Scale : Control { alias Control.computeSize computeSize; alias Control.setBackgroundImage setBackgroundImage; alias Control.windowProc windowProc; bool ignoreResize; - static final int TrackBarProc; - static final TCHAR TrackBarClass = new TCHAR (0, OS.TRACKBAR_CLASS, true); - static { - WNDCLASS lpWndClass = new WNDCLASS (); - OS.GetClassInfo (0, TrackBarClass, lpWndClass); + static const WNDPROC TrackBarProc; + static const TCHAR[] TrackBarClass = OS.TRACKBAR_CLASS; + static this() { + WNDCLASS lpWndClass; + OS.GetClassInfo (null, TrackBarClass.ptr, &lpWndClass); TrackBarProc = lpWndClass.lpfnWndProc; /* * Feature in Windows. The track bar window class @@ -76,13 +74,13 @@ * code, other than DWT, could create a control with * this class name, and fail unexpectedly. */ - int hInstance = OS.GetModuleHandle (null); - int hHeap = OS.GetProcessHeap (); + auto hInstance = OS.GetModuleHandle (null); + auto hHeap = OS.GetProcessHeap (); lpWndClass.hInstance = hInstance; lpWndClass.style &= ~OS.CS_GLOBALCLASS; lpWndClass.style |= OS.CS_DBLCLKS; int byteCount = TrackBarClass.length () * TCHAR.sizeof; - int lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); + auto lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); OS.MoveMemory (lpszClassName, TrackBarClass, byteCount); lpWndClass.lpszClassName = lpszClassName; OS.RegisterClass (lpWndClass); @@ -118,7 +116,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Scale (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); } @@ -153,9 +151,9 @@ addListener (DWT.DefaultSelection,typedListener); } -override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { - if (handle is 0) return 0; - return OS.CallWindowProc (TrackBarProc, hwnd, msg, wParam, lParam); +override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { + if (handle is null) return LRESULT.ZERO; + return cast(LRESULT)OS.CallWindowProc (TrackBarProc, hwnd, msg, wParam, lParam); } static int checkStyle (int style) { @@ -166,8 +164,8 @@ checkWidget (); int border = getBorderWidth (); int width = border * 2, height = border * 2; - RECT rect = new RECT (); - OS.SendMessage (handle, OS.TBM_GETTHUMBRECT, 0, rect); + RECT rect; + OS.SendMessage (handle, OS.TBM_GETTHUMBRECT, 0, &rect); if ((style & DWT.HORIZONTAL) !is 0) { width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10; int scrollY = OS.GetSystemMetrics (OS.SM_CYHSCROLL); @@ -485,7 +483,7 @@ switch (code) { case OS.TB_ENDTRACK: case OS.TB_THUMBPOSITION: - return null; + return LRESULT.NULL; } Event event = new Event (); @@ -510,8 +508,8 @@ */ sendEvent (DWT.Selection, event); // widget could be disposed at this point - return null; + return LRESULT.NULL; } } -++/ +