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.statusbar; 10 11 import std.utf: toUTFz; 12 import dgui.core.controls.subclassedcontrol; 13 14 final class StatusPart 15 { 16 private StatusBar _owner; 17 private string _text; 18 private int _width; 19 20 package this(StatusBar sb, string txt, int w) 21 { 22 this._owner = sb; 23 this._text = txt; 24 this._width = w; 25 } 26 27 @property public string text() 28 { 29 return this._text; 30 } 31 32 @property public void text(string s) 33 { 34 this._text = s; 35 36 if(this._owner && this._owner.created) 37 { 38 this._owner.sendMessage(SB_SETTEXTW, MAKEWPARAM(this.index, 0), cast(LPARAM)toUTFz!(wchar*)(s)); 39 } 40 } 41 42 @property public int width() 43 { 44 return this._width; 45 } 46 47 @property public int index() 48 { 49 foreach(int i, StatusPart sp; this._owner.parts) 50 { 51 if(sp is this) 52 { 53 return i; 54 } 55 } 56 57 return -1; 58 } 59 60 @property public StatusBar statusBar() 61 { 62 return this._owner; 63 } 64 } 65 66 class StatusBar: SubclassedControl 67 { 68 private Collection!(StatusPart) _parts; 69 private bool _partsVisible = false; 70 71 public StatusPart addPart(string s, int w) 72 { 73 if(!this._parts) 74 { 75 this._parts = new Collection!(StatusPart)(); 76 } 77 78 StatusPart sp = new StatusPart(this, s, w); 79 this._parts.add(sp); 80 81 if(this.created) 82 { 83 StatusBar.insertPart(sp); 84 } 85 86 return sp; 87 } 88 89 public StatusPart addPart(int w) 90 { 91 return this.addPart(null, w); 92 } 93 94 /* 95 public void removePanel(int idx) 96 { 97 98 } 99 */ 100 101 @property public bool partsVisible() 102 { 103 return this._partsVisible; 104 } 105 106 @property public void partsVisible(bool b) 107 { 108 this._partsVisible = b; 109 110 if(this.created) 111 { 112 this.setStyle(SBARS_SIZEGRIP, b); 113 } 114 } 115 116 @property public StatusPart[] parts() 117 { 118 if(this._parts) 119 { 120 return this._parts.get(); 121 } 122 123 return null; 124 } 125 126 private static void insertPart(StatusPart stp) 127 { 128 StatusBar owner = stp.statusBar; 129 StatusPart[] sparts = owner.parts; 130 uint[] parts = new uint[sparts.length]; 131 132 foreach(int i, StatusPart sp; sparts) 133 { 134 if(!i) 135 { 136 parts[i] = sp.width; 137 } 138 else 139 { 140 parts[i] = parts[i - 1] + sp.width; 141 } 142 } 143 144 owner.sendMessage(SB_SETPARTS, sparts.length, cast(LPARAM)parts.ptr); 145 146 foreach(int i, StatusPart sp; sparts) 147 { 148 owner.sendMessage(SB_SETTEXTW, MAKEWPARAM(i, 0), cast(LPARAM)toUTFz!(wchar*)(sp.text)); 149 } 150 } 151 152 protected override void createControlParams(ref CreateControlParams ccp) 153 { 154 this._dock = DockStyle.bottom; //Force dock 155 156 ccp.superclassName = WC_STATUSBAR; 157 ccp.className = WC_DSTATUSBAR; 158 159 if(this._partsVisible) 160 { 161 this.setStyle(SBARS_SIZEGRIP, true); 162 } 163 164 super.createControlParams(ccp); 165 } 166 167 protected override void onHandleCreated(EventArgs e) 168 { 169 if(this._parts) 170 { 171 foreach(StatusPart sp; this._parts) 172 { 173 StatusBar.insertPart(sp); 174 } 175 } 176 177 super.onHandleCreated(e); 178 } 179 }