comparison dwt/layout/GridLayout.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
168 return size; 168 return size;
169 } 169 }
170 170
171 protected bool flushCache (Control control) { 171 protected bool flushCache (Control control) {
172 Object data = control.getLayoutData (); 172 Object data = control.getLayoutData ();
173 if (data !is null) ((GridData) data).flushCache (); 173 if (data !is null) (cast(GridData) data).flushCache ();
174 return true; 174 return true;
175 } 175 }
176 176
177 GridData getData (Control [][] grid, int row, int column, int rowCount, int columnCount, bool first) { 177 GridData getData (Control [][] grid, int row, int column, int rowCount, int columnCount, bool first) {
178 Control control = grid [row] [column]; 178 Control control = grid [row] [column];
179 if (control !is null) { 179 if (control !is null) {
180 GridData data = (GridData) control.getLayoutData (); 180 GridData data = cast(GridData) control.getLayoutData ();
181 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); 181 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
182 int vSpan = Math.max (1, data.verticalSpan); 182 int vSpan = Math.max (1, data.verticalSpan);
183 int i = first ? row + vSpan - 1 : row - vSpan + 1; 183 int i = first ? row + vSpan - 1 : row - vSpan + 1;
184 int j = first ? column + hSpan - 1 : column - hSpan + 1; 184 int j = first ? column + hSpan - 1 : column - hSpan + 1;
185 if (0 <= i && i < rowCount) { 185 if (0 <= i && i < rowCount) {
202 } 202 }
203 Control [] children = composite.getChildren (); 203 Control [] children = composite.getChildren ();
204 int count = 0; 204 int count = 0;
205 for (int i=0; i<children.length; i++) { 205 for (int i=0; i<children.length; i++) {
206 Control control = children [i]; 206 Control control = children [i];
207 GridData data = (GridData) control.getLayoutData (); 207 GridData data = cast(GridData) control.getLayoutData ();
208 if (data is null || !data.exclude) { 208 if (data is null || !data.exclude) {
209 children [count++] = children [i]; 209 children [count++] = children [i];
210 } 210 }
211 } 211 }
212 if (count is 0) { 212 if (count is 0) {
213 return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); 213 return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
214 } 214 }
215 for (int i=0; i<count; i++) { 215 for (int i=0; i<count; i++) {
216 Control child = children [i]; 216 Control child = children [i];
217 GridData data = (GridData) child.getLayoutData (); 217 GridData data = cast(GridData) child.getLayoutData ();
218 if (data is null) child.setLayoutData (data = new GridData ()); 218 if (data is null) child.setLayoutData (data = new GridData ());
219 if (flushCache) data.flushCache (); 219 if (flushCache) data.flushCache ();
220 data.computeSize (child, data.widthHint, data.heightHint, flushCache); 220 data.computeSize (child, data.widthHint, data.heightHint, flushCache);
221 if (data.grabExcessHorizontalSpace && data.minimumWidth > 0) { 221 if (data.grabExcessHorizontalSpace && data.minimumWidth > 0) {
222 if (data.cacheWidth < data.minimumWidth) { 222 if (data.cacheWidth < data.minimumWidth) {
223 int trim = 0; 223 int trim = 0;
224 //TEMPORARY CODE 224 //TEMPORARY CODE
225 if (child instanceof Scrollable) { 225 if (child instanceof Scrollable) {
226 Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0); 226 Rectangle rect = (cast(Scrollable) child).computeTrim (0, 0, 0, 0);
227 trim = rect.width; 227 trim = rect.width;
228 } else { 228 } else {
229 trim = child.getBorderWidth () * 2; 229 trim = child.getBorderWidth () * 2;
230 } 230 }
231 data.cacheWidth = data.cacheHeight = DWT.DEFAULT; 231 data.cacheWidth = data.cacheHeight = DWT.DEFAULT;
240 /* Build the grid */ 240 /* Build the grid */
241 int row = 0, column = 0, rowCount = 0, columnCount = numColumns; 241 int row = 0, column = 0, rowCount = 0, columnCount = numColumns;
242 Control [][] grid = new Control [4] [columnCount]; 242 Control [][] grid = new Control [4] [columnCount];
243 for (int i=0; i<count; i++) { 243 for (int i=0; i<count; i++) {
244 Control child = children [i]; 244 Control child = children [i];
245 GridData data = (GridData) child.getLayoutData (); 245 GridData data = cast(GridData) child.getLayoutData ();
246 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); 246 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
247 int vSpan = Math.max (1, data.verticalSpan); 247 int vSpan = Math.max (1, data.verticalSpan);
248 while (true) { 248 while (true) {
249 int lastRow = row + vSpan; 249 int lastRow = row + vSpan;
250 if (lastRow >= grid.length) { 250 if (lastRow >= grid.length) {
470 } 470 }
471 currentWidth += (hSpan - 1) * horizontalSpacing - data.horizontalIndent; 471 currentWidth += (hSpan - 1) * horizontalSpacing - data.horizontalIndent;
472 if ((currentWidth !is data.cacheWidth && data.horizontalAlignment is DWT.FILL) || (data.cacheWidth > currentWidth)) { 472 if ((currentWidth !is data.cacheWidth && data.horizontalAlignment is DWT.FILL) || (data.cacheWidth > currentWidth)) {
473 int trim = 0; 473 int trim = 0;
474 if (child instanceof Scrollable) { 474 if (child instanceof Scrollable) {
475 Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0); 475 Rectangle rect = (cast(Scrollable) child).computeTrim (0, 0, 0, 0);
476 trim = rect.width; 476 trim = rect.width;
477 } else { 477 } else {
478 trim = child.getBorderWidth () * 2; 478 trim = child.getBorderWidth () * 2;
479 } 479 }
480 data.cacheWidth = data.cacheHeight = DWT.DEFAULT; 480 data.cacheWidth = data.cacheHeight = DWT.DEFAULT;