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