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.scrollbar; 10 11 import dguihub.core.controls.control; //?? Control ?? 12 import dguihub.core.winapi; 13 14 enum ScrollBarType { 15 vertical = SB_VERT, 16 horizontal = SB_HORZ, 17 separate = SB_CTL, 18 } 19 20 class ScrollBar : Control { 21 private ScrollBarType _sbt; 22 23 public this() { 24 this._sbt = ScrollBarType.separate; 25 } 26 27 private this(Control c, ScrollBarType sbt) { 28 this._handle = c.handle; 29 this._sbt = sbt; 30 } 31 32 private void setInfo(uint mask, SCROLLINFO* si) { 33 si.cbSize = SCROLLINFO.sizeof; 34 si.fMask = mask | SIF_DISABLENOSCROLL; 35 36 SetScrollInfo(this._handle, this._sbt, si, true); 37 } 38 39 private void getInfo(uint mask, SCROLLINFO* si) { 40 si.cbSize = SCROLLINFO.sizeof; 41 si.fMask = mask; 42 43 GetScrollInfo(this._handle, this._sbt, si); 44 } 45 46 public void setRange(uint min, uint max) { 47 if (this.created) { 48 SCROLLINFO si; 49 si.nMin = min; 50 si.nMax = max; 51 52 this.setInfo(SIF_RANGE, &si); 53 } 54 } 55 56 public void increment(int amount = 1) { 57 this.position = this.position + amount; 58 } 59 60 public void decrement(int amount = 1) { 61 this.position = this.position - amount; 62 } 63 64 @property public uint minRange() { 65 if (this.created) { 66 SCROLLINFO si; 67 68 this.getInfo(SIF_RANGE, &si); 69 return si.nMin; 70 } 71 72 return -1; 73 } 74 75 @property public uint maxRange() { 76 if (this.created) { 77 SCROLLINFO si; 78 79 this.getInfo(SIF_RANGE, &si); 80 return si.nMax; 81 } 82 83 return -1; 84 } 85 86 @property public uint position() { 87 if (this.created) { 88 SCROLLINFO si; 89 90 this.getInfo(SIF_POS, &si); 91 return si.nPos; 92 } 93 94 return -1; 95 } 96 97 @property public void position(uint p) { 98 if (this.created) { 99 SCROLLINFO si; 100 si.nPos = p; 101 102 this.setInfo(SIF_POS, &si); 103 } 104 } 105 106 @property public uint page() { 107 if (this.created) { 108 SCROLLINFO si; 109 110 this.getInfo(SIF_PAGE, &si); 111 return si.nPage; 112 } 113 114 return -1; 115 } 116 117 @property public void page(uint p) { 118 if (this.created) { 119 SCROLLINFO si; 120 si.nPage = p; 121 122 this.setInfo(SIF_PAGE, &si); 123 } 124 } 125 126 public static ScrollBar fromControl(Control c, ScrollBarType sbt) { 127 assert(sbt !is ScrollBarType.separate, "ScrollBarType.separate not allowed here"); 128 return new ScrollBar(c, sbt); 129 } 130 }