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