Mercurial > projects > dwt-win
changeset 64:8c6992b95018
Slider
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 14:53:27 +0100 |
parents | adfa8c39be39 |
children | 66203354c9d3 |
files | dwt/widgets/Slider.d |
diffstat | 1 files changed, 53 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/Slider.d Mon Feb 04 14:45:37 2008 +0100 +++ b/dwt/widgets/Slider.d Mon Feb 04 14:53:27 2008 +0100 @@ -10,22 +10,19 @@ *******************************************************************************/ module dwt.widgets.Slider; -import dwt.widgets.Control; -import dwt.widgets.Composite; -class Slider : Control { - this (Composite parent, int style); -} -/++ 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.SCROLLINFO; -import dwt.internal.win32.TCHAR; -import dwt.internal.win32.WNDCLASS; + +import dwt.widgets.Control; +import dwt.widgets.Composite; +import dwt.widgets.TypedListener; +import dwt.widgets.Event; + +import dwt.dwthelper.utils; /** * Instances of this class are selectable user interface @@ -75,7 +72,7 @@ * * @see ScrollBar */ -public class Slider extends Control { +public class Slider : Control { alias Control.computeSize computeSize; alias Control.setBounds setBounds; @@ -83,11 +80,11 @@ int increment, pageIncrement; bool ignoreFocus; - static final int ScrollBarProc; - static final TCHAR ScrollBarClass = new TCHAR (0, "SCROLLBAR", true); - static { - WNDCLASS lpWndClass = new WNDCLASS (); - OS.GetClassInfo (0, ScrollBarClass, lpWndClass); + static const WNDPROC ScrollBarProc; + static const TCHAR[] ScrollBarClass = "SCROLLBAR"; + static this() { + WNDCLASS lpWndClass; + OS.GetClassInfo (null, ScrollBarClass.ptr, &lpWndClass); ScrollBarProc = lpWndClass.lpfnWndProc; } @@ -120,7 +117,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Slider (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); } @@ -164,8 +161,8 @@ addListener (DWT.DefaultSelection,typedListener); } -override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { - if (handle is 0) return 0; +override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { + if (handle is null) return LRESULT.ZERO; /* * Feature in Windows. Windows runs a modal message * loop when the user drags a scroll bar. This means @@ -179,7 +176,7 @@ case OS.WM_LBUTTONDBLCLK: display.runDeferredEvents (); } - return OS.CallWindowProc (ScrollBarProc, hwnd, msg, wParam, lParam); + return cast(LRESULT) OS.CallWindowProc (ScrollBarProc, hwnd, msg, wParam, lParam); } static int checkStyle (int style) { @@ -212,12 +209,12 @@ * info.nPage needs to be 11 in order to * get a thumb that is 10. */ - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_ALL; info.nMax = 100; info.nPage = 11; - OS.SetScrollInfo (handle, OS.SB_CTL, info, true); + OS.SetScrollInfo (handle, OS.SB_CTL, &info, true); } override int defaultBackground () { @@ -275,10 +272,10 @@ */ public int getMaximum () { checkWidget (); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); return info.nMax; } @@ -294,10 +291,10 @@ */ public int getMinimum () { checkWidget (); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); return info.nMin; } @@ -330,10 +327,10 @@ */ public int getSelection () { checkWidget (); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); return info.nPos; } @@ -350,10 +347,10 @@ */ public int getThumb () { checkWidget (); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_PAGE; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); if (info.nPage !is 0) --info.nPage; return info.nPage; } @@ -433,13 +430,13 @@ public void setMaximum (int value) { checkWidget (); if (value < 0) return; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); if (value - info.nMin - info.nPage < 1) return; info.nMax = value; - SetScrollInfo (handle, OS.SB_CTL, info, true); + SetScrollInfo (handle, OS.SB_CTL, &info, true); } /** @@ -458,13 +455,13 @@ public void setMinimum (int value) { checkWidget (); if (value < 0) return; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); if (info.nMax - value - info.nPage < 1) return; info.nMin = value; - SetScrollInfo (handle, OS.SB_CTL, info, true); + SetScrollInfo (handle, OS.SB_CTL, &info, true); } /** @@ -486,7 +483,7 @@ pageIncrement = value; } -bool SetScrollInfo (int hwnd, int flags, SCROLLINFO info, bool fRedraw) { +bool SetScrollInfo (HWND hwnd, int flags, SCROLLINFO* info, bool fRedraw) { /* * Feature in Windows. Using SIF_DISABLENOSCROLL, * SetScrollInfo () can change enabled and disabled @@ -496,7 +493,7 @@ * the application has disabled the scroll bar. */ if ((state & DISABLED) !is 0) fRedraw = false; - bool result = OS.SetScrollInfo (hwnd, flags, info, fRedraw); + bool result = cast(bool) OS.SetScrollInfo (hwnd, flags, info, fRedraw); if ((state & DISABLED) !is 0) { OS.EnableWindow (handle, false); if (!OS.IsWinCE) { @@ -533,11 +530,11 @@ */ public void setSelection (int value) { checkWidget (); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; info.nPos = value; - SetScrollInfo (handle, OS.SB_CTL, info, true); + SetScrollInfo (handle, OS.SB_CTL, &info, true); } /** @@ -557,13 +554,13 @@ public void setThumb (int value) { checkWidget (); if (value < 1) return; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); info.nPage = value; if (info.nPage !is 0) info.nPage++; - SetScrollInfo (handle, OS.SB_CTL, info, true); + SetScrollInfo (handle, OS.SB_CTL, &info, true); } /** @@ -596,7 +593,7 @@ if (pageIncrement < 1) return; this.increment = increment; this.pageIncrement = pageIncrement; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS | OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; info.nPos = selection; @@ -604,7 +601,7 @@ info.nMax = maximum; info.nPage = thumb; if (info.nPage !is 0) info.nPage++; - SetScrollInfo (handle, OS.SB_CTL, info, true); + SetScrollInfo (handle, OS.SB_CTL, &info, true); } override int widgetExtStyle () { @@ -631,17 +628,17 @@ return bits | OS.SBS_VERT; } -override TCHAR windowClass () { - return ScrollBarClass; +override char[] windowClass () { + return TCHARsToStr(ScrollBarClass); } override int windowProc () { - return ScrollBarProc; + return cast(int) ScrollBarProc; } 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; if ((style & DWT.VERTICAL) !is 0) return result; /* * Bug in Windows. When a horizontal scroll bar is mirrored, @@ -658,7 +655,7 @@ case OS.VK_RIGHT: { int key = wParam is OS.VK_LEFT ? OS.VK_RIGHT : OS.VK_LEFT; int code = callWindowProc (handle, OS.WM_KEYDOWN, key, lParam); - return new LRESULT (code); + return cast(LRESULT) (code); } } } @@ -732,7 +729,7 @@ } override LRESULT WM_SETFOCUS (int wParam, int lParam) { - if (ignoreFocus) return null; + if (ignoreFocus) return LRESULT.NULL; return super.WM_SETFOCUS (wParam, lParam); } @@ -740,14 +737,14 @@ /* Do nothing when scrolling is ending */ int code = wParam & 0xFFFF; - if (code is OS.SB_ENDSCROLL) return null; + if (code is OS.SB_ENDSCROLL) return LRESULT.NULL; /* Move the thumb */ Event event = new Event (); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_TRACKPOS | OS.SIF_POS | OS.SIF_RANGE; - OS.GetScrollInfo (handle, OS.SB_CTL, info); + OS.GetScrollInfo (handle, OS.SB_CTL, &info); info.fMask = OS.SIF_POS; switch (code) { case OS.SB_THUMBPOSITION: @@ -783,7 +780,7 @@ info.nPos = Math.max (info.nMin, info.nPos - pageIncrement); break; } - OS.SetScrollInfo (handle, OS.SB_CTL, info, true); + OS.SetScrollInfo (handle, OS.SB_CTL, &info, true); /* * Feature in Windows. Windows runs a modal message @@ -794,8 +791,7 @@ */ sendEvent (DWT.Selection, event); // the widget could be destroyed at this point - return null; + return LRESULT.NULL; } } -++/ \ No newline at end of file