comparison dwt/layout/FormLayout.d @ 7:e831403a80a9

Add 'cast' to casts
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 14:30:35 +0200
parents 1a8b3cb347e0
children a9ab4c738ed8
comparison
equal deleted inserted replaced
6:b903c16b6f48 7:e831403a80a9
167 167
168 /* 168 /*
169 * Computes the preferred height of the form with 169 * Computes the preferred height of the form with
170 * respect to the preferred height of the control. 170 * respect to the preferred height of the control.
171 * 171 *
172 * Given that the equations for top (T) and bottom (B) 172 * Given that the equations for top cast(T) and bottom cast(B)
173 * of the control in terms of the height of the form (X) 173 * of the control in terms of the height of the form cast(X)
174 * are: 174 * are:
175 * T = AX + B 175 * T = AX + B
176 * B = CX + D 176 * B = CX + D
177 * 177 *
178 * The equation for the height of the control (H) 178 * The equation for the height of the control cast(H)
179 * is bottom (B) minus top (T) or (H = B - T) or: 179 * is bottom cast(B) minus top cast(T) or (H = B - T) or:
180 * 180 *
181 * H = (CX + D) - (AX + B) 181 * H = (CX + D) - (AX + B)
182 * 182 *
183 * Solving for (X), the height of the form, we get: 183 * Solving for cast(X), the height of the form, we get:
184 * 184 *
185 * X = (H + B - D) / (C - A) 185 * X = (H + B - D) / (C - A)
186 * 186 *
187 * When (A = C), (C - A = 0) and the equation has no 187 * When (A = C), (C - A = 0) and the equation has no
188 * solution for X. This is a special case meaning that 188 * solution for X. This is a special case meaning that
189 * the control does not constrain the height of the 189 * the control does not constrain the height of the
190 * form. In this case, we need to arbitrarily define 190 * form. In this case, we need to arbitrarily define
191 * the height of the form (X): 191 * the height of the form cast(X):
192 * 192 *
193 * Case 1: A = C, A = 0, C = 0 193 * Case 1: A = C, A = 0, C = 0
194 * 194 *
195 * Let X = D, the distance from the top of the form 195 * Let X = D, the distance from the top of the form
196 * to the bottom edge of the control. In this case, 196 * to the bottom edge of the control. In this case,
248 return size; 248 return size;
249 } 249 }
250 250
251 protected bool flushCache (Control control) { 251 protected bool flushCache (Control control) {
252 Object data = control.getLayoutData (); 252 Object data = control.getLayoutData ();
253 if (data !is null) ((FormData) data).flushCache (); 253 if (data !is null) (cast(FormData) data).flushCache ();
254 return true; 254 return true;
255 } 255 }
256 256
257 String getName () { 257 String getName () {
258 String string = getClass ().getName (); 258 String string = getClass ().getName ();
292 292
293 Point layout (Composite composite, bool move, int x, int y, int width, int height, bool flushCache) { 293 Point layout (Composite composite, bool move, int x, int y, int width, int height, bool flushCache) {
294 Control [] children = composite.getChildren (); 294 Control [] children = composite.getChildren ();
295 for (int i=0; i<children.length; i++) { 295 for (int i=0; i<children.length; i++) {
296 Control child = children [i]; 296 Control child = children [i];
297 FormData data = (FormData) child.getLayoutData (); 297 FormData data = cast(FormData) child.getLayoutData ();
298 if (data is null) child.setLayoutData (data = new FormData ()); 298 if (data is null) child.setLayoutData (data = new FormData ());
299 if (flushCache) data.flushCache (); 299 if (flushCache) data.flushCache ();
300 data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null; 300 data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null;
301 } 301 }
302 bool [] flush = null; 302 bool [] flush = null;
303 Rectangle [] bounds = null; 303 Rectangle [] bounds = null;
304 int w = 0, h = 0; 304 int w = 0, h = 0;
305 for (int i=0; i<children.length; i++) { 305 for (int i=0; i<children.length; i++) {
306 Control child = children [i]; 306 Control child = children [i];
307 FormData data = (FormData) child.getLayoutData (); 307 FormData data = cast(FormData) child.getLayoutData ();
308 if (width !is DWT.DEFAULT) { 308 if (width !is DWT.DEFAULT) {
309 data.needed = false; 309 data.needed = false;
310 FormAttachment left = data.getLeftAttachment (child, spacing, flushCache); 310 FormAttachment left = data.getLeftAttachment (child, spacing, flushCache);
311 FormAttachment right = data.getRightAttachment (child, spacing, flushCache); 311 FormAttachment right = data.getRightAttachment (child, spacing, flushCache);
312 int x1 = left.solveX (width), x2 = right.solveX (width); 312 int x1 = left.solveX (width), x2 = right.solveX (width);
313 if (data.height is DWT.DEFAULT && !data.needed) { 313 if (data.height is DWT.DEFAULT && !data.needed) {
314 int trim = 0; 314 int trim = 0;
315 //TEMPORARY CODE 315 //TEMPORARY CODE
316 if (child instanceof Scrollable) { 316 if (child instanceof Scrollable) {
317 Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0); 317 Rectangle rect = (cast(Scrollable) child).computeTrim (0, 0, 0, 0);
318 trim = rect.width; 318 trim = rect.width;
319 } else { 319 } else {
320 trim = child.getBorderWidth () * 2; 320 trim = child.getBorderWidth () * 2;
321 } 321 }
322 data.cacheWidth = data.cacheHeight = -1; 322 data.cacheWidth = data.cacheHeight = -1;
336 w = Math.max (computeWidth (child, data, flushCache), w); 336 w = Math.max (computeWidth (child, data, flushCache), w);
337 } 337 }
338 } 338 }
339 for (int i=0; i<children.length; i++) { 339 for (int i=0; i<children.length; i++) {
340 Control child = children [i]; 340 Control child = children [i];
341 FormData data = (FormData) child.getLayoutData (); 341 FormData data = cast(FormData) child.getLayoutData ();
342 if (height !is DWT.DEFAULT) { 342 if (height !is DWT.DEFAULT) {
343 int y1 = data.getTopAttachment (child, spacing, flushCache).solveX (height); 343 int y1 = data.getTopAttachment (child, spacing, flushCache).solveX (height);
344 int y2 = data.getBottomAttachment (child, spacing, flushCache).solveX (height); 344 int y2 = data.getBottomAttachment (child, spacing, flushCache).solveX (height);
345 h = Math.max (y2, h); 345 h = Math.max (y2, h);
346 if (move) { 346 if (move) {
351 h = Math.max (computeHeight (child, data, flushCache), h); 351 h = Math.max (computeHeight (child, data, flushCache), h);
352 } 352 }
353 } 353 }
354 for (int i=0; i<children.length; i++) { 354 for (int i=0; i<children.length; i++) {
355 Control child = children [i]; 355 Control child = children [i];
356 FormData data = (FormData) child.getLayoutData (); 356 FormData data = cast(FormData) child.getLayoutData ();
357 if (flush !is null && flush [i]) data.cacheWidth = data.cacheHeight = -1; 357 if (flush !is null && flush [i]) data.cacheWidth = data.cacheHeight = -1;
358 data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null; 358 data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null;
359 } 359 }
360 if (move) { 360 if (move) {
361 for (int i=0; i<children.length; i++) { 361 for (int i=0; i<children.length; i++) {