Mercurial > projects > dwt-mac
comparison dwt/custom/SashFormLayout.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 380af2bdd8e5 |
children | a9ab4c738ed8 |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
19 * | 19 * |
20 * @see SashForm | 20 * @see SashForm |
21 */ | 21 */ |
22 class SashFormLayout : Layout { | 22 class SashFormLayout : Layout { |
23 protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { | 23 protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { |
24 SashForm sashForm = (SashForm)composite; | 24 SashForm sashForm = cast(SashForm)composite; |
25 Control[] cArray = sashForm.getControls(true); | 25 Control[] cArray = sashForm.getControls(true); |
26 int width = 0; | 26 int width = 0; |
27 int height = 0; | 27 int height = 0; |
28 if (cArray.length is 0) { | 28 if (cArray.length is 0) { |
29 if (wHint !is DWT.DEFAULT) width = wHint; | 29 if (wHint !is DWT.DEFAULT) width = wHint; |
55 long[] ratios = new long[cArray.length]; | 55 long[] ratios = new long[cArray.length]; |
56 long total = 0; | 56 long total = 0; |
57 for (int i = 0; i < cArray.length; i++) { | 57 for (int i = 0; i < cArray.length; i++) { |
58 Object data = cArray[i].getLayoutData(); | 58 Object data = cArray[i].getLayoutData(); |
59 if (data !is null && data instanceof SashFormData) { | 59 if (data !is null && data instanceof SashFormData) { |
60 ratios[i] = ((SashFormData)data).weight; | 60 ratios[i] = (cast(SashFormData)data).weight; |
61 } else { | 61 } else { |
62 data = new SashFormData(); | 62 data = new SashFormData(); |
63 cArray[i].setLayoutData(data); | 63 cArray[i].setLayoutData(data); |
64 ((SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; | 64 (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; |
65 | 65 |
66 } | 66 } |
67 total += ratios[i]; | 67 total += ratios[i]; |
68 } | 68 } |
69 if (ratios[maxIndex] > 0) { | 69 if (ratios[maxIndex] > 0) { |
70 int sashwidth = sashForm.sashes.length > 0 ? sashForm.SASH_WIDTH + sashForm.sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; | 70 int sashwidth = sashForm.sashes.length > 0 ? sashForm.SASH_WIDTH + sashForm.sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; |
71 if (vertical) { | 71 if (vertical) { |
72 height += (int)(total * maxValue / ratios[maxIndex]) + (cArray.length - 1) * sashwidth; | 72 height += cast(int)(total * maxValue / ratios[maxIndex]) + (cArray.length - 1) * sashwidth; |
73 } else { | 73 } else { |
74 width += (int)(total * maxValue / ratios[maxIndex]) + (cArray.length - 1) * sashwidth; | 74 width += cast(int)(total * maxValue / ratios[maxIndex]) + (cArray.length - 1) * sashwidth; |
75 } | 75 } |
76 } | 76 } |
77 width += sashForm.getBorderWidth()*2; | 77 width += sashForm.getBorderWidth()*2; |
78 height += sashForm.getBorderWidth()*2; | 78 height += sashForm.getBorderWidth()*2; |
79 if (wHint !is DWT.DEFAULT) width = wHint; | 79 if (wHint !is DWT.DEFAULT) width = wHint; |
84 protected bool flushCache(Control control) { | 84 protected bool flushCache(Control control) { |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 protected void layout(Composite composite, bool flushCache) { | 88 protected void layout(Composite composite, bool flushCache) { |
89 SashForm sashForm = (SashForm)composite; | 89 SashForm sashForm = cast(SashForm)composite; |
90 Rectangle area = sashForm.getClientArea(); | 90 Rectangle area = sashForm.getClientArea(); |
91 if (area.width <= 1 || area.height <= 1) return; | 91 if (area.width <= 1 || area.height <= 1) return; |
92 | 92 |
93 Control[] newControls = sashForm.getControls(true); | 93 Control[] newControls = sashForm.getControls(true); |
94 if (sashForm.controls.length is 0 && newControls.length is 0) return; | 94 if (sashForm.controls.length is 0 && newControls.length is 0) return; |
140 long[] ratios = new long[controls.length]; | 140 long[] ratios = new long[controls.length]; |
141 long total = 0; | 141 long total = 0; |
142 for (int i = 0; i < controls.length; i++) { | 142 for (int i = 0; i < controls.length; i++) { |
143 Object data = controls[i].getLayoutData(); | 143 Object data = controls[i].getLayoutData(); |
144 if (data !is null && data instanceof SashFormData) { | 144 if (data !is null && data instanceof SashFormData) { |
145 ratios[i] = ((SashFormData)data).weight; | 145 ratios[i] = (cast(SashFormData)data).weight; |
146 } else { | 146 } else { |
147 data = new SashFormData(); | 147 data = new SashFormData(); |
148 controls[i].setLayoutData(data); | 148 controls[i].setLayoutData(data); |
149 ((SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; | 149 (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; |
150 | 150 |
151 } | 151 } |
152 total += ratios[i]; | 152 total += ratios[i]; |
153 } | 153 } |
154 | 154 |
155 int sashwidth = sashes.length > 0 ? sashForm.SASH_WIDTH + sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; | 155 int sashwidth = sashes.length > 0 ? sashForm.SASH_WIDTH + sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; |
156 if (sashForm.getOrientation() is DWT.HORIZONTAL) { | 156 if (sashForm.getOrientation() is DWT.HORIZONTAL) { |
157 int width = (int)(ratios[0] * (area.width - sashes.length * sashwidth) / total); | 157 int width = cast(int)(ratios[0] * (area.width - sashes.length * sashwidth) / total); |
158 int x = area.x; | 158 int x = area.x; |
159 controls[0].setBounds(x, area.y, width, area.height); | 159 controls[0].setBounds(x, area.y, width, area.height); |
160 x += width; | 160 x += width; |
161 for (int i = 1; i < controls.length - 1; i++) { | 161 for (int i = 1; i < controls.length - 1; i++) { |
162 sashes[i - 1].setBounds(x, area.y, sashwidth, area.height); | 162 sashes[i - 1].setBounds(x, area.y, sashwidth, area.height); |
163 x += sashwidth; | 163 x += sashwidth; |
164 width = (int)(ratios[i] * (area.width - sashes.length * sashwidth) / total); | 164 width = cast(int)(ratios[i] * (area.width - sashes.length * sashwidth) / total); |
165 controls[i].setBounds(x, area.y, width, area.height); | 165 controls[i].setBounds(x, area.y, width, area.height); |
166 x += width; | 166 x += width; |
167 } | 167 } |
168 if (controls.length > 1) { | 168 if (controls.length > 1) { |
169 sashes[sashes.length - 1].setBounds(x, area.y, sashwidth, area.height); | 169 sashes[sashes.length - 1].setBounds(x, area.y, sashwidth, area.height); |
170 x += sashwidth; | 170 x += sashwidth; |
171 width = area.width - x; | 171 width = area.width - x; |
172 controls[controls.length - 1].setBounds(x, area.y, width, area.height); | 172 controls[controls.length - 1].setBounds(x, area.y, width, area.height); |
173 } | 173 } |
174 } else { | 174 } else { |
175 int height = (int)(ratios[0] * (area.height - sashes.length * sashwidth) / total); | 175 int height = cast(int)(ratios[0] * (area.height - sashes.length * sashwidth) / total); |
176 int y = area.y; | 176 int y = area.y; |
177 controls[0].setBounds(area.x, y, area.width, height); | 177 controls[0].setBounds(area.x, y, area.width, height); |
178 y += height; | 178 y += height; |
179 for (int i = 1; i < controls.length - 1; i++) { | 179 for (int i = 1; i < controls.length - 1; i++) { |
180 sashes[i - 1].setBounds(area.x, y, area.width, sashwidth); | 180 sashes[i - 1].setBounds(area.x, y, area.width, sashwidth); |
181 y += sashwidth; | 181 y += sashwidth; |
182 height = (int)(ratios[i] * (area.height - sashes.length * sashwidth) / total); | 182 height = cast(int)(ratios[i] * (area.height - sashes.length * sashwidth) / total); |
183 controls[i].setBounds(area.x, y, area.width, height); | 183 controls[i].setBounds(area.x, y, area.width, height); |
184 y += height; | 184 y += height; |
185 } | 185 } |
186 if (controls.length > 1) { | 186 if (controls.length > 1) { |
187 sashes[sashes.length - 1].setBounds(area.x, y, area.width, sashwidth); | 187 sashes[sashes.length - 1].setBounds(area.x, y, area.width, sashwidth); |