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.progressbar;
10 
11 import dguihub.core.controls.subclassedcontrol;
12 
13 class ProgressBar : SubclassedControl {
14    private uint _minRange = 0;
15    private uint _maxRange = 100;
16    private uint _step = 10;
17    private uint _value = 0;
18 
19    @property public uint minRange() {
20       return this._minRange;
21    }
22 
23    @property public void minRange(uint mr) {
24       this._minRange = mr;
25 
26       if (this.created) {
27          this.sendMessage(PBM_SETRANGE32, this._minRange, this._maxRange);
28       }
29    }
30 
31    @property public uint maxRange() {
32       return this._maxRange;
33    }
34 
35    @property public void maxRange(uint mr) {
36       this._maxRange = mr;
37 
38       if (this.created) {
39          this.sendMessage(PBM_SETRANGE32, this._minRange, this._maxRange);
40       }
41    }
42 
43    @property public uint step() {
44       return this._minRange;
45    }
46 
47    @property public void step(uint s) {
48       this._step = s;
49 
50       if (this.created) {
51          this.sendMessage(PBM_SETSTEP, this._step, 0);
52       }
53    }
54 
55    @property public uint value() {
56       if (this.created) {
57          return this.sendMessage(PBM_GETPOS, 0, 0);
58       }
59 
60       return this._value;
61    }
62 
63    @property public void value(uint p) {
64       this._value = p;
65 
66       if (this.created) {
67          this.sendMessage(PBM_SETPOS, p, 0);
68       }
69    }
70 
71    public void increment() {
72       if (this.created) {
73          this.sendMessage(PBM_STEPIT, 0, 0);
74       } else {
75          throwException!(DGuiException)("Cannot increment the progress bar");
76       }
77    }
78 
79    protected override void createControlParams(ref CreateControlParams ccp) {
80       ccp.superclassName = WC_PROGRESSBAR;
81       ccp.className = WC_DPROGRESSBAR;
82 
83       assert(this._dock !is DockStyle.fill, "ProgressBar: Invalid Dock Style");
84 
85       if (this._dock is DockStyle.left || this._dock is DockStyle.right) {
86          this.setStyle(PBS_VERTICAL, true);
87       }
88 
89       super.createControlParams(ccp);
90    }
91 
92    protected override void onHandleCreated(EventArgs e) {
93       this.sendMessage(PBM_SETRANGE32, this._minRange, this._maxRange);
94       this.sendMessage(PBM_SETSTEP, this._step, 0);
95       this.sendMessage(PBM_SETPOS, this._value, 0);
96 
97       super.onHandleCreated(e);
98    }
99 }