1 /** DGui project file. 2 3 Copyright: Trogu Antonio Davide 2011-2013 4 5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 7 Authors: Trogu Antonio Davide 8 */ 9 module dguihub.core.controls.scrollablecontrol; 10 11 public import dguihub.core.controls.reflectedcontrol; 12 public import dguihub.core.events.mouseeventargs; 13 public import dguihub.core.events.scrolleventargs; 14 15 abstract class ScrollableControl : ReflectedControl { 16 public Event!(Control, ScrollEventArgs) scroll; 17 public Event!(Control, MouseWheelEventArgs) mouseWheel; 18 19 protected final void scrollWindow(ScrollWindowDirection swd, int amount) { 20 this.scrollWindow(swd, amount, nullRect); 21 } 22 23 protected final void scrollWindow(ScrollWindowDirection swd, int amount, Rect rectScroll) { 24 if (this.created) { 25 switch (swd) { 26 case ScrollWindowDirection.left: 27 ScrollWindowEx(this._handle, amount, 0, null, 28 rectScroll == nullRect ? null : &rectScroll.rect, null, null, SW_INVALIDATE); 29 break; 30 31 case ScrollWindowDirection.up: 32 ScrollWindowEx(this._handle, 0, amount, null, 33 rectScroll == nullRect ? null : &rectScroll.rect, null, null, SW_INVALIDATE); 34 break; 35 36 case ScrollWindowDirection.right: 37 ScrollWindowEx(this._handle, -amount, 0, null, 38 rectScroll == nullRect ? null : &rectScroll.rect, null, null, SW_INVALIDATE); 39 break; 40 41 case ScrollWindowDirection.down: 42 ScrollWindowEx(this._handle, 0, -amount, null, 43 rectScroll == nullRect ? null : &rectScroll.rect, null, null, SW_INVALIDATE); 44 break; 45 46 default: 47 break; 48 } 49 } 50 } 51 52 protected void onMouseWheel(MouseWheelEventArgs e) { 53 this.mouseWheel(this, e); 54 } 55 56 protected void onScroll(ScrollEventArgs e) { 57 this.scroll(this, e); 58 } 59 60 protected override void wndProc(ref Message m) { 61 switch (m.msg) { 62 case WM_MOUSEWHEEL: { 63 short delta = GetWheelDelta(m.wParam); 64 scope MouseWheelEventArgs e = new MouseWheelEventArgs(Point(LOWORD(m.lParam), 65 HIWORD(m.lParam)), cast(MouseKeys)m.wParam, delta > 0 66 ? MouseWheel.up : MouseWheel.down); 67 this.onMouseWheel(e); 68 this.originalWndProc(m); 69 } 70 break; 71 72 case WM_VSCROLL, WM_HSCROLL: { 73 ScrollDirection sd = m.msg == WM_VSCROLL ? ScrollDirection.vertical 74 : ScrollDirection.horizontal; 75 ScrollMode sm = cast(ScrollMode)m.wParam; 76 77 scope ScrollEventArgs e = new ScrollEventArgs(sd, sm); 78 this.onScroll(e); 79 80 this.originalWndProc(m); 81 } 82 break; 83 84 default: 85 break; 86 } 87 88 super.wndProc(m); 89 } 90 }