Mercurial > projects > dwt-win
changeset 36:ceb20ad6c0f8
Scrollable
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 29 Jan 2008 00:52:45 +0100 |
parents | 99d8b02576c3 |
children | e3a5d61b33cd |
files | dwt/widgets/Control.d dwt/widgets/Display.d dwt/widgets/ScrollBar.d dwt/widgets/Scrollable.d |
diffstat | 4 files changed, 75 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/Control.d Tue Jan 29 00:16:12 2008 +0100 +++ b/dwt/widgets/Control.d Tue Jan 29 00:52:45 2008 +0100 @@ -12,46 +12,6 @@ *******************************************************************************/ module dwt.widgets.Control; -/+ -import dwt.widgets.Widget; -import dwt.widgets.Composite; -import dwt.widgets.Event; -import dwt.widgets.Shell; -import dwt.graphics.Drawable; -import dwt.graphics.Rectangle; -import dwt.graphics.Point; -import dwt.graphics.GCData; -import dwt.internal.win32.OS; - -class Control : Widget, Drawable { - public HANDLE handle; - this(); - this( Widget, int ); -public HDC internal_new_GC (GCData data) ; -public void internal_dispose_GC (HDC hDC, GCData data) ; -public Point computeSize (int wHint, int hHint) ; -public Point computeSize (int wHint, int hHint, bool changed) ; -public Composite getParent () ; -public Object getLayoutData () ; -public int getBorderWidth () ; -public void setLayoutData (Object layoutData) ; -public void setBounds (int x, int y, int width, int height) ; -void setBounds (int x, int y, int width, int height, int flags) ; -void setBounds (int x, int y, int width, int height, int flags, bool defer) ; -public void setBounds (Rectangle rect) ; -Shell getShell(); -bool checkHandle (HWND hwnd) ; -bool translateAccelerator (MSG* msg) ; -bool translateMnemonic (Event event, Control control) ; -bool translateMnemonic (MSG* msg) ; -bool translateTraversal (MSG* msg) ; -public void update () ; -void update (bool all) ; -void updateImages () ; -int windowProc (HWND hwnd, int msg, int wParam, int lParam) ; - -} -+/ import dwt.DWT; import dwt.DWTException; import dwt.accessibility.Accessible; @@ -114,6 +74,7 @@ public abstract class Control : Widget, Drawable { alias Widget.dragDetect dragDetect; + alias Widget.callWindowProc callWindowProc; /** * the handle to the OS resource
--- a/dwt/widgets/Display.d Tue Jan 29 00:16:12 2008 +0100 +++ b/dwt/widgets/Display.d Tue Jan 29 00:52:45 2008 +0100 @@ -185,7 +185,7 @@ //Callback windowCallback; //int windowProc_; int threadId; - TCHAR* windowClass, windowShadowClass; + TCHAR* windowClass_, windowShadowClass; static int WindowClassCount; static const char[] WindowName = "SWT_Window"; //$NON-NLS-1$ static const char[] WindowShadowName = "SWT_WindowShadow"; //$NON-NLS-1$ @@ -2005,7 +2005,7 @@ if (embeddedHwnd is null) { auto hInstance = OS.GetModuleHandle (null); embeddedHwnd = OS.CreateWindowEx (0, - windowClass, + windowClass_, null, OS.WS_OVERLAPPED, 0, 0, 0, 0, @@ -2502,7 +2502,7 @@ threadId = OS.GetCurrentThreadId (); /* Use the character encoding for the default locale */ - windowClass = StrToTCHARz ( WindowName ~ to!(char[])(WindowClassCount)); + windowClass_ = StrToTCHARz ( WindowName ~ to!(char[])(WindowClassCount)); windowShadowClass = StrToTCHARz ( WindowShadowName ~ to!(char[])(WindowClassCount)); WindowClassCount++; @@ -2514,10 +2514,10 @@ lpWndClass.lpfnWndProc = &windowProcFunc; lpWndClass.style = OS.CS_BYTEALIGNWINDOW | OS.CS_DBLCLKS; lpWndClass.hCursor = OS.LoadCursor (null, cast(wchar*)OS.IDC_ARROW); - int len = strlenz( windowClass ); + int len = strlenz( windowClass_ ); int byteCount = len * TCHAR.sizeof; lpWndClass.lpszClassName = cast(wchar*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - lpWndClass.lpszClassName[ 0 .. len ] = windowClass[ 0 .. len ]; + lpWndClass.lpszClassName[ 0 .. len ] = windowClass_[ 0 .. len ]; OS.RegisterClass (&lpWndClass); OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName); @@ -2532,7 +2532,7 @@ /* Create the message only HWND */ hwndMessage = OS.CreateWindowEx (0, - windowClass, + windowClass_, null, OS.WS_OVERLAPPED, 0, 0, 0, 0, @@ -3505,11 +3505,11 @@ /* Unregister the DWT window class */ auto hHeap = OS.GetProcessHeap (); auto hInstance = OS.GetModuleHandle (null); - OS.UnregisterClass (windowClass, hInstance); + OS.UnregisterClass (windowClass_, hInstance); /* Unregister the DWT drop shadow window class */ OS.UnregisterClass (windowShadowClass, hInstance); - windowClass = windowShadowClass = null; + windowClass_ = windowShadowClass = null; //windowCallback.dispose (); //windowCallback = null; //windowProc_ = 0; @@ -4530,4 +4530,8 @@ return result.toString (); } +char[] windowClass(){ + return TCHARzToStr( windowClass_ ); } + +}
--- a/dwt/widgets/ScrollBar.d Tue Jan 29 00:16:12 2008 +0100 +++ b/dwt/widgets/ScrollBar.d Tue Jan 29 00:52:45 2008 +0100 @@ -13,6 +13,14 @@ import dwt.widgets.Widget; class ScrollBar : Widget { this( Widget, int ); +public void setMaximum (int value) ; +public void setThumb (int value) ; +public int getThumb () ; +public bool getEnabled () ; +public int getSelection () ; +public int getIncrement () ; +public int getPageIncrement () ; +LRESULT wmScrollChild (int wParam, int lParam) ; } /++ import dwt.DWT;
--- a/dwt/widgets/Scrollable.d Tue Jan 29 00:16:12 2008 +0100 +++ b/dwt/widgets/Scrollable.d Tue Jan 29 00:52:45 2008 +0100 @@ -10,26 +10,17 @@ *******************************************************************************/ module dwt.widgets.Scrollable; +import dwt.widgets.Widget; +import dwt.widgets.Event; import dwt.widgets.Control; +import dwt.widgets.ScrollBar; import dwt.widgets.Composite; -import dwt.graphics.Rectangle; - -class Scrollable : Control { - this(); - this( Composite, int ); -public Rectangle computeTrim (int x, int y, int width, int height) ; -public Rectangle getClientArea () ; -} - -/++ import dwt.DWT; import dwt.DWTException; import dwt.graphics.Rectangle; -import dwt.internal.win32.LRESULT; import dwt.internal.win32.OS; -import dwt.internal.win32.RECT; -import dwt.internal.win32.SCROLLINFO; -import dwt.internal.win32.TCHAR; + +import dwt.dwthelper.utils; /** * This class is the abstract superclass of all classes which @@ -46,13 +37,13 @@ * </p> */ -public abstract class Scrollable extends Control { +public abstract class Scrollable : Control { ScrollBar horizontalBar, verticalBar; /** * Prevents uninitialized instances from being created outside the package. */ -Scrollable () { +this () { } /** @@ -84,13 +75,13 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Scrollable (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, style); } -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); } /** @@ -122,12 +113,12 @@ */ public Rectangle computeTrim (int x, int y, int width, int height) { checkWidget (); - int scrolledHandle = scrolledHandle (); - RECT rect = new RECT (); - OS.SetRect (rect, x, y, x + width, y + height); - int bits1 = OS.GetWindowLong (scrolledHandle, OS.GWL_STYLE); - int bits2 = OS.GetWindowLong (scrolledHandle, OS.GWL_EXSTYLE); - OS.AdjustWindowRectEx (rect, bits1, false, bits2); + auto scrolledHandle_ = scrolledHandle (); + RECT rect; + OS.SetRect (&rect, x, y, x + width, y + height); + int bits1 = OS.GetWindowLong (scrolledHandle_, OS.GWL_STYLE); + int bits2 = OS.GetWindowLong (scrolledHandle_, OS.GWL_EXSTYLE); + OS.AdjustWindowRectEx (&rect, bits1, false, bits2); if (horizontalBar !is null) rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL); if (verticalBar !is null) rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL); int nWidth = rect.right - rect.left, nHeight = rect.bottom - rect.top; @@ -166,15 +157,15 @@ public Rectangle getClientArea () { checkWidget (); forceResize (); - RECT rect = new RECT (); - int scrolledHandle = scrolledHandle (); - OS.GetClientRect (scrolledHandle, rect); + RECT rect; + auto scrolledHandle_ = scrolledHandle (); + OS.GetClientRect (scrolledHandle_, &rect); int x = rect.left, y = rect.top; int width = rect.right - rect.left; int height = rect.bottom - rect.top; - if (scrolledHandle !is handle) { - OS.GetClientRect (handle, rect); - OS.MapWindowPoints(handle, scrolledHandle, rect, 2); + if (scrolledHandle_ !is handle) { + OS.GetClientRect (handle, &rect); + OS.MapWindowPoints(handle, scrolledHandle_, cast(POINT*)&rect, 2); x = -rect.left; y = -rect.top; } @@ -225,7 +216,7 @@ super.releaseChildren (destroy); } -int scrolledHandle () { +HANDLE scrolledHandle () { return handle; } @@ -250,17 +241,17 @@ return bits; } -TCHAR windowClass () { - return display.windowClass; +override char[] windowClass () { + return display.windowClass(); } -int windowProc () { +override int windowProc () { return display.windowProc; } -LRESULT WM_HSCROLL (int wParam, int lParam) { +override LRESULT WM_HSCROLL (int wParam, int lParam) { LRESULT result = super.WM_HSCROLL (wParam, lParam); - if (result !is null) return result; + if (result !is 0) return result; /* * Bug on WinCE. lParam should be NULL when the message is not sent @@ -269,15 +260,15 @@ * contains the handle to the scroll bar. The fix is to check for * both. */ - if (horizontalBar !is null && (lParam is 0 || lParam is handle)) { + if (horizontalBar !is null && (lParam is 0 || lParam is cast(int)handle)) { return wmScroll (horizontalBar, (state & CANVAS) !is 0, handle, OS.WM_HSCROLL, wParam, lParam); } return result; } -LRESULT WM_MOUSEWHEEL (int wParam, int lParam) { +override LRESULT WM_MOUSEWHEEL (int wParam, int lParam) { LRESULT result = super.WM_MOUSEWHEEL (wParam, lParam); - if (result !is null) return result; + if (result !is 0) return result; /* * Translate WM_MOUSEWHEEL to WM_VSCROLL or WM_HSCROLL. @@ -288,11 +279,11 @@ bool horizontal = horizontalBar !is null && horizontalBar.getEnabled (); int msg = (vertical) ? OS.WM_VSCROLL : (horizontal) ? OS.WM_HSCROLL : 0; if (msg is 0) return result; - int [] value = new int [1]; - OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, value, 0); - int delta = (short) (wParam >> 16); + int value; + OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, &value, 0); + int delta = cast(short) (wParam >> 16); int code = 0, count = 0; - if (value [0] is OS.WHEEL_PAGESCROLL) { + if (value is OS.WHEEL_PAGESCROLL) { code = delta < 0 ? OS.SB_PAGEDOWN : OS.SB_PAGEUP; count = Math.abs (delta / OS.WHEEL_DELTA); } else { @@ -300,7 +291,7 @@ delta = Math.abs (delta); if (delta < OS.WHEEL_DELTA) return result; if (msg is OS.WM_VSCROLL) { - count = value [0] * delta / OS.WHEEL_DELTA; + count = value * delta / OS.WHEEL_DELTA; } else { count = delta / OS.WHEEL_DELTA; } @@ -324,7 +315,7 @@ */ int vPosition = verticalBar is null ? 0 : verticalBar.getSelection (); int hPosition = horizontalBar is null ? 0 : horizontalBar.getSelection (); - int code = callWindowProc (handle, OS.WM_MOUSEWHEEL, wParam, lParam); + LRESULT code = callWindowProc (handle, OS.WM_MOUSEWHEEL, wParam, lParam); if (verticalBar !is null) { int position = verticalBar.getSelection (); if (position !is vPosition) { @@ -341,20 +332,20 @@ horizontalBar.sendEvent (DWT.Selection, event); } } - return new LRESULT (code); + return code; } -LRESULT WM_SIZE (int wParam, int lParam) { - int code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam); +override LRESULT WM_SIZE (int wParam, int lParam) { + LRESULT code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam); super.WM_SIZE (wParam, lParam); // widget may be disposed at this point if (code is 0) return LRESULT.ZERO; - return new LRESULT (code); + return code; } -LRESULT WM_VSCROLL (int wParam, int lParam) { +override LRESULT WM_VSCROLL (int wParam, int lParam) { LRESULT result = super.WM_VSCROLL (wParam, lParam); - if (result !is null) return result; + if (result !is 0) return result; /* * Bug on WinCE. lParam should be NULL when the message is not sent * by a scroll bar control, but it contains the handle to the window. @@ -362,24 +353,24 @@ * contains the handle to the scroll bar. The fix is to check for * both. */ - if (verticalBar !is null && (lParam is 0 || lParam is handle)) { + if (verticalBar !is null && (lParam is 0 || lParam is cast(int)handle)) { return wmScroll (verticalBar, (state & CANVAS) !is 0, handle, OS.WM_VSCROLL, wParam, lParam); } return result; } -LRESULT wmScroll (ScrollBar bar, bool update, int hwnd, int msg, int wParam, int lParam) { - LRESULT result = null; +LRESULT wmScroll (ScrollBar bar, bool update, HWND hwnd, int msg, int wParam, int lParam) { + LRESULT result = LRESULT.NULL; if (update) { int type = msg is OS.WM_HSCROLL ? OS.SB_HORZ : OS.SB_VERT; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_TRACKPOS | OS.SIF_POS | OS.SIF_RANGE; - OS.GetScrollInfo (hwnd, type, info); + OS.GetScrollInfo (hwnd, type, &info); info.fMask = OS.SIF_POS; int code = wParam & 0xFFFF; switch (code) { - case OS.SB_ENDSCROLL: return null; + case OS.SB_ENDSCROLL: return LRESULT.NULL; case OS.SB_THUMBPOSITION: case OS.SB_THUMBTRACK: /* @@ -411,14 +402,14 @@ info.nPos = Math.max (info.nMin, info.nPos - pageIncrement); break; } - OS.SetScrollInfo (hwnd, type, info, true); + OS.SetScrollInfo (hwnd, type, &info, true); } else { - int code = callWindowProc (hwnd, msg, wParam, lParam); - result = code is 0 ? LRESULT.ZERO : new LRESULT (code); + LRESULT code = callWindowProc (hwnd, msg, wParam, lParam); + result = code is 0 ? LRESULT.ZERO : code; } bar.wmScrollChild (wParam, lParam); return result; } } -++/ +