# HG changeset patch # User Frank Benoit # Date 1202132737 -3600 # Node ID adfa8c39be3979e49e064bb7daaf6809de3bb8ae # Parent 7757dae4f29ff565d561053ff6aa67a29c72d5fb Scale, ScrollBar diff -r 7757dae4f29f -r adfa8c39be39 dwt/internal/win32/OS.d --- a/dwt/internal/win32/OS.d Mon Feb 04 14:32:57 2008 +0100 +++ b/dwt/internal/win32/OS.d Mon Feb 04 14:45:37 2008 +0100 @@ -1708,7 +1708,7 @@ public static const int TPM_LEFTBUTTON = 0x0; public static const int TPM_RIGHTBUTTON = 0x2; public static const int TPM_RIGHTALIGN = 0x8; - public static const char[] TRACKBAR_CLASS = "msctls_trackbar32"; //$NON-NLS-1$ + public static const TCHAR[] TRACKBAR_CLASS = "msctls_trackbar32"; //$NON-NLS-1$ public static const int TRANSPARENT = 0x1; public static const int TREIS_DISABLED = 4; public static const int TREIS_HOT = 2; diff -r 7757dae4f29f -r adfa8c39be39 dwt/widgets/Scale.d --- a/dwt/widgets/Scale.d Mon Feb 04 14:32:57 2008 +0100 +++ b/dwt/widgets/Scale.d Mon Feb 04 14:45:37 2008 +0100 @@ -14,14 +14,12 @@ import dwt.DWTException; import dwt.events.SelectionListener; import dwt.graphics.Point; -import dwt.internal.win32.LRESULT; import dwt.internal.win32.OS; -import dwt.internal.win32.RECT; -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; @@ -79,11 +77,11 @@ lpWndClass.hInstance = hInstance; lpWndClass.style &= ~OS.CS_GLOBALCLASS; lpWndClass.style |= OS.CS_DBLCLKS; - int byteCount = TrackBarClass.length () * TCHAR.sizeof; + int byteCount = (TrackBarClass.length+1) * TCHAR.sizeof; auto lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (lpszClassName, TrackBarClass, byteCount); + OS.MoveMemory (lpszClassName, TrackBarClass.ptr, byteCount); lpWndClass.lpszClassName = lpszClassName; - OS.RegisterClass (lpWndClass); + OS.RegisterClass (&lpWndClass); OS.HeapFree (hHeap, 0, lpszClassName); } @@ -296,7 +294,7 @@ eventTable.unhook (DWT.DefaultSelection,listener); } -override void setBackgroundImage (int hImage) { +override void setBackgroundImage (HBITMAP hImage) { super.setBackgroundImage (hImage); /* * Bug in Windows. Changing the background color of the Scale @@ -431,12 +429,12 @@ return bits | OS.TBS_VERT; } -override TCHAR windowClass () { - return TrackBarClass; +override char[] windowClass () { + return TCHARsToStr(TrackBarClass); } override int windowProc () { - return TrackBarProc; + return cast(int) TrackBarProc; } override LRESULT WM_PAINT (int wParam, int lParam) { @@ -472,7 +470,7 @@ } override LRESULT WM_SIZE (int wParam, int lParam) { - if (ignoreResize) return null; + if (ignoreResize) return LRESULT.NULL; return super.WM_SIZE (wParam, lParam); } diff -r 7757dae4f29f -r adfa8c39be39 dwt/widgets/ScrollBar.d --- a/dwt/widgets/ScrollBar.d Mon Feb 04 14:32:57 2008 +0100 +++ b/dwt/widgets/ScrollBar.d Mon Feb 04 14:45:37 2008 +0100 @@ -10,30 +10,20 @@ *******************************************************************************/ module dwt.widgets.ScrollBar; -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) ; -public bool getVisible () ; -} -/++ import dwt.DWT; import dwt.DWTException; import dwt.events.SelectionEvent; import dwt.events.SelectionListener; import dwt.graphics.Point; 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.widgets.Widget; +import dwt.widgets.TypedListener; +import dwt.widgets.Event; +import dwt.widgets.Scrollable; + +import dwt.dwthelper.utils; /** * Instances of this class are selectable user interface @@ -99,7 +89,7 @@ * @see Scrollable#getVerticalBar */ -public class ScrollBar extends Widget { +public class ScrollBar : Widget { Scrollable parent; int increment, pageIncrement; @@ -132,7 +122,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -ScrollBar (Scrollable parent, int style) { +this (Scrollable parent, int style) { super (parent, checkStyle (style)); this.parent = parent; createWidget (); @@ -198,15 +188,16 @@ } override void destroyWidget () { - int hwnd = hwndScrollBar (), type = scrollBarType (); - if (OS.IsWinCE) { - SCROLLINFO info = new SCROLLINFO (); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); + static if (OS.IsWinCE) { + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE | OS.SIF_PAGE; info.nPage = 101; info.nMax = 100; info.nMin = 0; - OS.SetScrollInfo (hwnd, type, info, true); + OS.SetScrollInfo (hwnd, type, &info, true); } else { OS.ShowScrollBar (hwnd, type, false); } @@ -216,8 +207,8 @@ Rectangle getBounds () { // checkWidget (); parent.forceResize (); - RECT rect = new RECT (); - OS.GetClientRect (parent.scrolledHandle (), rect); + RECT rect; + OS.GetClientRect (parent.scrolledHandle (), &rect); int x = 0, y = 0, width, height; if ((style & DWT.HORIZONTAL) !is 0) { y = rect.bottom - rect.top; @@ -280,12 +271,12 @@ */ public int getMaximum () { checkWidget(); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE; - int hwnd = hwndScrollBar (); - int type = scrollBarType (); - OS.GetScrollInfo (hwnd, type, info); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); + OS.GetScrollInfo (hwnd, type, &info); return info.nMax; } @@ -301,12 +292,12 @@ */ public int getMinimum () { checkWidget(); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE; - int hwnd = hwndScrollBar (); - int type = scrollBarType (); - OS.GetScrollInfo (hwnd, type, info); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); + OS.GetScrollInfo (hwnd, type, &info); return info.nMin; } @@ -354,12 +345,12 @@ */ public int getSelection () { checkWidget(); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; - int hwnd = hwndScrollBar (); - int type = scrollBarType (); - OS.GetScrollInfo (hwnd, type, info); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); + OS.GetScrollInfo (hwnd, type, &info); return info.nPos; } @@ -379,8 +370,8 @@ public Point getSize () { checkWidget(); parent.forceResize (); - RECT rect = new RECT (); - OS.GetClientRect (parent.scrolledHandle (), rect); + RECT rect; + OS.GetClientRect (parent.scrolledHandle (), &rect); int width, height; if ((style & DWT.HORIZONTAL) !is 0) { width = rect.right - rect.left; @@ -407,12 +398,12 @@ */ public int getThumb () { checkWidget(); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_PAGE; - int hwnd = hwndScrollBar (); - int type = scrollBarType (); - OS.GetScrollInfo (hwnd, type, info); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); + OS.GetScrollInfo (hwnd, type, &info); if (info.nPage !is 0) --info.nPage; return info.nPage; } @@ -439,7 +430,7 @@ return (state & HIDDEN) is 0; } -int hwndScrollBar () { +HWND hwndScrollBar () { return parent.scrolledHandle (); } @@ -542,8 +533,9 @@ * always show scrollbar as being enabled and visible. */ // if (OS.IsWinCE) error (DWT.ERROR_NOT_IMPLEMENTED); - if (!OS.IsWinCE) { - int hwnd = hwndScrollBar (), type = scrollBarType (); + static if (!OS.IsWinCE) { + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); int flags = enabled ? OS.ESB_ENABLE_BOTH : OS.ESB_DISABLE_BOTH; OS.EnableScrollBar (hwnd, type, flags); if (enabled) { @@ -589,14 +581,15 @@ public void setMaximum (int value) { checkWidget(); if (value < 0) return; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; - int hwnd = hwndScrollBar (), type = scrollBarType (); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; - OS.GetScrollInfo (hwnd, type, info); + OS.GetScrollInfo (hwnd, type, &info); if (value - info.nMin - info.nPage < 1) return; info.nMax = value; - SetScrollInfo (hwnd, type, info, true); + SetScrollInfo (hwnd, type, &info, true); } /** @@ -615,14 +608,15 @@ public void setMinimum (int value) { checkWidget(); if (value < 0) return; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; - int hwnd = hwndScrollBar (), type = scrollBarType (); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; - OS.GetScrollInfo (hwnd, type, info); + OS.GetScrollInfo (hwnd, type, &info); if (info.nMax - value - info.nPage < 1) return; info.nMin = value; - SetScrollInfo (hwnd, type, info, true); + SetScrollInfo (hwnd, type, &info, true); } /** @@ -644,7 +638,7 @@ pageIncrement = value; } -bool SetScrollInfo (int hwnd, int flags, SCROLLINFO info, bool fRedraw) { +bool SetScrollInfo (HWND hwnd, int flags, SCROLLINFO* info, bool fRedraw) { /* * Bug in Windows. For some reason, when SetScrollInfo() * is used with SIF_POS and the scroll bar is hidden, @@ -654,7 +648,7 @@ * bar draws. The fix is to hide both scroll bars. */ if ((state & (DISABLED | HIDDEN)) !is 0) fRedraw = false; - bool result = OS.SetScrollInfo (hwnd, flags, info, fRedraw); + bool result = cast(bool) OS.SetScrollInfo (hwnd, flags, info, fRedraw); /* * Bug in Windows. For some reason, when the widget @@ -721,12 +715,13 @@ */ public void setSelection (int selection) { checkWidget(); - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; - int hwnd = hwndScrollBar (), type = scrollBarType (); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); info.fMask = OS.SIF_POS; info.nPos = selection; - SetScrollInfo (hwnd, type, info, true); + SetScrollInfo (hwnd, type, &info, true); } /** @@ -746,14 +741,15 @@ public void setThumb (int value) { checkWidget(); if (value < 1) return; - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; - int hwnd = hwndScrollBar (), type = scrollBarType (); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); info.fMask = OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; - OS.GetScrollInfo (hwnd, type, info); + OS.GetScrollInfo (hwnd, type, &info); info.nPage = value; if (info.nPage !is 0) info.nPage++; - SetScrollInfo (hwnd, type, info, true); + SetScrollInfo (hwnd, type, &info, true); } /** @@ -786,7 +782,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; @@ -794,8 +790,9 @@ info.nMax = maximum; info.nPage = thumb; if (info.nPage !is 0) info.nPage++; - int hwnd = hwndScrollBar (), type = scrollBarType (); - SetScrollInfo (hwnd, type, info, true); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); + SetScrollInfo (hwnd, type, &info, true); } /** @@ -825,12 +822,13 @@ * the range. */ if (OS.IsWinCE) { - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; - int hwnd = hwndScrollBar (), type = scrollBarType (); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); info.fMask = OS.SIF_RANGE | OS.SIF_PAGE; if (visible) info.fMask |= OS.SIF_DISABLENOSCROLL; - OS.GetScrollInfo (hwnd, type, info); + OS.GetScrollInfo (hwnd, type, &info); if (info.nPage is info.nMax - info.nMin + 1) { /* * Bug in Windows. When the only changed flag to @@ -841,9 +839,9 @@ */ int max = info.nMax; info.nMax++; - OS.SetScrollInfo (hwnd, type, info, false); + OS.SetScrollInfo (hwnd, type, &info, false); info.nMax = max; - OS.SetScrollInfo (hwnd, type, info, true); + OS.SetScrollInfo (hwnd, type, &info, true); } else { /* * This line is intentionally commented. Currently @@ -863,7 +861,8 @@ * of the scroll bar will get the correct value. */ state = visible ? state & ~HIDDEN : state | HIDDEN; - int hwnd = hwndScrollBar (), type = scrollBarType (); + auto hwnd = hwndScrollBar (); + auto type = scrollBarType (); if (OS.ShowScrollBar (hwnd, type, visible)) { /* * Bug in Windows. For some reason, when the widget @@ -879,10 +878,10 @@ * visible. */ if ((state & DISABLED) is 0) { - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE | OS.SIF_PAGE; - OS.GetScrollInfo (hwnd, type, info); + OS.GetScrollInfo (hwnd, type, &info); if (info.nMax - info.nMin - info.nPage >= 0) { OS.EnableScrollBar (hwnd, type, OS.ESB_ENABLE_BOTH); } @@ -896,7 +895,7 @@ /* 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; /* * Send the event because WM_HSCROLL and @@ -917,8 +916,8 @@ } sendEvent (DWT.Selection, event); // the widget could be destroyed at this point - return null; + return LRESULT.NULL; } } -++/ +