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.trackbar; 10 11 import dgui.core.controls.subclassedcontrol; 12 13 class TrackBar: SubclassedControl 14 { 15 public Event!(Control, EventArgs) valueChanged; 16 17 private int _minRange = 0; 18 private int _maxRange = 100; 19 private int _value = 0; 20 private int _lastValue = 0; 21 22 @property public uint minRange() 23 { 24 return this._minRange; 25 } 26 27 @property public void minRange(uint mr) 28 { 29 this._minRange = mr; 30 31 if(this.created) 32 { 33 this.sendMessage(TBM_SETRANGE, true, MAKELPARAM(this._minRange, this._maxRange)); 34 } 35 } 36 37 @property public uint maxRange() 38 { 39 return this._maxRange; 40 } 41 42 @property public void maxRange(uint mr) 43 { 44 this._maxRange = mr; 45 46 if(this.created) 47 { 48 this.sendMessage(TBM_SETRANGE, true, MAKELPARAM(this._minRange, this._maxRange)); 49 } 50 } 51 52 @property public int value() 53 { 54 if(this.created) 55 { 56 return this.sendMessage(TBM_GETPOS, 0, 0); 57 } 58 59 return this._value; 60 } 61 62 @property public void value(int p) 63 { 64 this._value = p; 65 66 if(this.created) 67 { 68 this.sendMessage(TBM_SETPOS, true, p); 69 } 70 } 71 72 protected override void createControlParams(ref CreateControlParams ccp) 73 { 74 ccp.superclassName = WC_TRACKBAR; 75 ccp.className = WC_DTRACKBAR; 76 this.setStyle(TBS_AUTOTICKS, true); 77 78 assert(this._dock is DockStyle.fill, "TrackBar: Invalid Dock Style"); 79 80 if(this._dock is DockStyle.top || this._dock is DockStyle.bottom || (this._dock is DockStyle.none && this._bounds.width >= this._bounds.height)) 81 { 82 this.setStyle(TBS_HORZ, true); 83 } 84 else if(this._dock is DockStyle.left || this._dock is DockStyle.right || (this._dock is DockStyle.none && this._bounds.height < this._bounds.width)) 85 { 86 this.setStyle(TBS_VERT, true); 87 } 88 89 super.createControlParams(ccp); 90 } 91 92 protected override void onHandleCreated(EventArgs e) 93 { 94 this.sendMessage(TBM_SETRANGE, true, MAKELPARAM(this._minRange, this._maxRange)); 95 this.sendMessage(TBM_SETTIC, 20, 0); 96 this.sendMessage(TBM_SETPOS, true, this._value); 97 98 super.onHandleCreated(e); 99 } 100 101 protected override void wndProc(ref Message m) 102 { 103 if(m.msg == WM_MOUSEMOVE && (cast(MouseKeys)m.wParam) is MouseKeys.left || 104 m.msg == WM_KEYDOWN && ((cast(Keys)m.wParam) is Keys.left || 105 (cast(Keys)m.wParam) is Keys.up || 106 (cast(Keys)m.wParam) is Keys.right || 107 (cast(Keys)m.wParam) is Keys.down)) 108 { 109 int val = this.value; 110 111 if(this._lastValue != val) 112 { 113 this._lastValue = val; //Save last position. 114 this.onValueChanged(EventArgs.empty); 115 } 116 } 117 118 super.wndProc(m); 119 } 120 121 private void onValueChanged(EventArgs e) 122 { 123 this.valueChanged(this, e); 124 } 125 }