Mercurial > projects > dwt-win
comparison dwt/layout/RowLayout.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | fd9c62a2998e |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
136 * @since 3.0 | 136 * @since 3.0 |
137 */ | 137 */ |
138 public bool fill = false; | 138 public bool fill = false; |
139 | 139 |
140 /** | 140 /** |
141 * center specifies whether the controls in a row should be | |
142 * centered vertically in each cell for horizontal layouts, | |
143 * or centered horizontally in each cell for vertical layouts. | |
144 * | |
145 * The default value is false. | |
146 * | |
147 * @since 3.4 | |
148 */ | |
149 public bool center = false; | |
150 | |
151 /** | |
141 * justify specifies whether the controls in a row should be | 152 * justify specifies whether the controls in a row should be |
142 * fully justified, with any extra space placed between the controls. | 153 * fully justified, with any extra space placed between the controls. |
143 * | 154 * |
144 * The default value is false. | 155 * The default value is false. |
145 */ | 156 */ |
266 clientY = rect.y; | 277 clientY = rect.y; |
267 } | 278 } |
268 int [] wraps = null; | 279 int [] wraps = null; |
269 bool wrapped = false; | 280 bool wrapped = false; |
270 Rectangle [] bounds = null; | 281 Rectangle [] bounds = null; |
271 if (move && (justify || fill)) { | 282 if (move && (justify || fill || center)) { |
272 bounds = new Rectangle [count]; | 283 bounds = new Rectangle [count]; |
273 wraps = new int [count]; | 284 wraps = new int [count]; |
274 } | 285 } |
275 int maxX = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight; | 286 int maxX = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight; |
276 for (int i=0; i<count; i++) { | 287 for (int i=0; i<count; i++) { |
280 childWidth = size.x; | 291 childWidth = size.x; |
281 childHeight = size.y; | 292 childHeight = size.y; |
282 } | 293 } |
283 if (wrap && (i !is 0) && (x + childWidth > width)) { | 294 if (wrap && (i !is 0) && (x + childWidth > width)) { |
284 wrapped = true; | 295 wrapped = true; |
285 if (move && (justify || fill)) wraps [i - 1] = maxHeight; | 296 if (move && (justify || fill || center)) wraps [i - 1] = maxHeight; |
286 x = marginLeft + marginWidth; | 297 x = marginLeft + marginWidth; |
287 y += spacing + maxHeight; | 298 y += spacing + maxHeight; |
288 if (pack) maxHeight = 0; | 299 if (pack) maxHeight = 0; |
289 } | 300 } |
290 if (pack || fill) { | 301 if (pack || fill || center) { |
291 maxHeight = Math.max (maxHeight, childHeight); | 302 maxHeight = Math.max (maxHeight, childHeight); |
292 } | 303 } |
293 if (move) { | 304 if (move) { |
294 int childX = x + clientX, childY = y + clientY; | 305 int childX = x + clientX, childY = y + clientY; |
295 if (justify || fill) { | 306 if (justify || fill || center) { |
296 bounds [i] = new Rectangle (childX, childY, childWidth, childHeight); | 307 bounds [i] = new Rectangle (childX, childY, childWidth, childHeight); |
297 } else { | 308 } else { |
298 child.setBounds (childX, childY, childWidth, childHeight); | 309 child.setBounds (childX, childY, childWidth, childHeight); |
299 } | 310 } |
300 } | 311 } |
301 x += spacing + childWidth; | 312 x += spacing + childWidth; |
302 maxX = Math.max (maxX, x); | 313 maxX = Math.max (maxX, x); |
303 } | 314 } |
304 maxX = Math.max (clientX + marginLeft + marginWidth, maxX - spacing); | 315 maxX = Math.max (clientX + marginLeft + marginWidth, maxX - spacing); |
305 if (!wrapped) maxX += marginRight + marginWidth; | 316 if (!wrapped) maxX += marginRight + marginWidth; |
306 if (move && (justify || fill)) { | 317 if (move && (justify || fill || center)) { |
307 int space = 0, margin = 0; | 318 int space = 0, margin = 0; |
308 if (!wrapped) { | 319 if (!wrapped) { |
309 space = Math.max (0, (width - maxX) / (count + 1)); | 320 space = Math.max (0, (width - maxX) / (count + 1)); |
310 margin = Math.max (0, ((width - maxX) % (count + 1)) / 2); | 321 margin = Math.max (0, ((width - maxX) % (count + 1)) / 2); |
311 } else { | 322 } else { |
312 if (fill || justify) { | 323 if (fill || justify || center) { |
313 int last = 0; | 324 int last = 0; |
314 if (count > 0) wraps [count - 1] = maxHeight; | 325 if (count > 0) wraps [count - 1] = maxHeight; |
315 for (int i=0; i<count; i++) { | 326 for (int i=0; i<count; i++) { |
316 if (wraps [i] !is 0) { | 327 if (wraps [i] !is 0) { |
317 int wrapCount = i - last + 1; | 328 int wrapCount = i - last + 1; |
323 space = Math.max (0, (width - wrapX) / (wrapCount + 1)); | 334 space = Math.max (0, (width - wrapX) / (wrapCount + 1)); |
324 margin = Math.max (0, ((width - wrapX) % (wrapCount + 1)) / 2); | 335 margin = Math.max (0, ((width - wrapX) % (wrapCount + 1)) / 2); |
325 } | 336 } |
326 for (int j=last; j<=i; j++) { | 337 for (int j=last; j<=i; j++) { |
327 if (justify) bounds [j].x += (space * (j - last + 1)) + margin; | 338 if (justify) bounds [j].x += (space * (j - last + 1)) + margin; |
328 if (fill) bounds [j].height = wraps [i]; | 339 if (fill) { |
340 bounds [j].height = wraps [i]; | |
341 } else { | |
342 if (center) { | |
343 bounds [j].y += Math.max (0, (wraps [i] - bounds [j].height) / 2); | |
344 } | |
345 } | |
329 } | 346 } |
330 last = i + 1; | 347 last = i + 1; |
331 } | 348 } |
332 } | 349 } |
333 } | 350 } |
334 } | 351 } |
335 for (int i=0; i<count; i++) { | 352 for (int i=0; i<count; i++) { |
336 if (!wrapped) { | 353 if (!wrapped) { |
337 if (justify) bounds [i].x += (space * (i + 1)) + margin; | 354 if (justify) bounds [i].x += (space * (i + 1)) + margin; |
338 if (fill) bounds [i].height = maxHeight; | 355 if (fill) { |
356 bounds [i].height = maxHeight; | |
357 } else { | |
358 if (center) { | |
359 bounds [i].y += Math.max (0, (maxHeight - bounds [i].height) / 2); | |
360 } | |
361 } | |
339 } | 362 } |
340 children [i].setBounds (bounds [i]); | 363 children [i].setBounds (bounds [i]); |
341 } | 364 } |
342 } | 365 } |
343 return new Point (maxX, y + maxHeight + marginBottom + marginHeight); | 366 return new Point (maxX, y + maxHeight + marginBottom + marginHeight); |
373 clientY = rect.y; | 396 clientY = rect.y; |
374 } | 397 } |
375 int [] wraps = null; | 398 int [] wraps = null; |
376 bool wrapped = false; | 399 bool wrapped = false; |
377 Rectangle [] bounds = null; | 400 Rectangle [] bounds = null; |
378 if (move && (justify || fill)) { | 401 if (move && (justify || fill || center)) { |
379 bounds = new Rectangle [count]; | 402 bounds = new Rectangle [count]; |
380 wraps = new int [count]; | 403 wraps = new int [count]; |
381 } | 404 } |
382 int maxY = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight; | 405 int maxY = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight; |
383 for (int i=0; i<count; i++) { | 406 for (int i=0; i<count; i++) { |
387 childWidth = size.x; | 410 childWidth = size.x; |
388 childHeight = size.y; | 411 childHeight = size.y; |
389 } | 412 } |
390 if (wrap && (i !is 0) && (y + childHeight > height)) { | 413 if (wrap && (i !is 0) && (y + childHeight > height)) { |
391 wrapped = true; | 414 wrapped = true; |
392 if (move && (justify || fill)) wraps [i - 1] = maxWidth; | 415 if (move && (justify || fill || center)) wraps [i - 1] = maxWidth; |
393 x += spacing + maxWidth; | 416 x += spacing + maxWidth; |
394 y = marginTop + marginHeight; | 417 y = marginTop + marginHeight; |
395 if (pack) maxWidth = 0; | 418 if (pack) maxWidth = 0; |
396 } | 419 } |
397 if (pack || fill) { | 420 if (pack || fill || center) { |
398 maxWidth = Math.max (maxWidth, childWidth); | 421 maxWidth = Math.max (maxWidth, childWidth); |
399 } | 422 } |
400 if (move) { | 423 if (move) { |
401 int childX = x + clientX, childY = y + clientY; | 424 int childX = x + clientX, childY = y + clientY; |
402 if (justify || fill) { | 425 if (justify || fill || center) { |
403 bounds [i] = new Rectangle (childX, childY, childWidth, childHeight); | 426 bounds [i] = new Rectangle (childX, childY, childWidth, childHeight); |
404 } else { | 427 } else { |
405 child.setBounds (childX, childY, childWidth, childHeight); | 428 child.setBounds (childX, childY, childWidth, childHeight); |
406 } | 429 } |
407 } | 430 } |
408 y += spacing + childHeight; | 431 y += spacing + childHeight; |
409 maxY = Math.max (maxY, y); | 432 maxY = Math.max (maxY, y); |
410 } | 433 } |
411 maxY = Math.max (clientY + marginTop + marginHeight, maxY - spacing); | 434 maxY = Math.max (clientY + marginTop + marginHeight, maxY - spacing); |
412 if (!wrapped) maxY += marginBottom + marginHeight; | 435 if (!wrapped) maxY += marginBottom + marginHeight; |
413 if (move && (justify || fill)) { | 436 if (move && (justify || fill || center)) { |
414 int space = 0, margin = 0; | 437 int space = 0, margin = 0; |
415 if (!wrapped) { | 438 if (!wrapped) { |
416 space = Math.max (0, (height - maxY) / (count + 1)); | 439 space = Math.max (0, (height - maxY) / (count + 1)); |
417 margin = Math.max (0, ((height - maxY) % (count + 1)) / 2); | 440 margin = Math.max (0, ((height - maxY) % (count + 1)) / 2); |
418 } else { | 441 } else { |
419 if (fill || justify) { | 442 if (fill || justify || center) { |
420 int last = 0; | 443 int last = 0; |
421 if (count > 0) wraps [count - 1] = maxWidth; | 444 if (count > 0) wraps [count - 1] = maxWidth; |
422 for (int i=0; i<count; i++) { | 445 for (int i=0; i<count; i++) { |
423 if (wraps [i] !is 0) { | 446 if (wraps [i] !is 0) { |
424 int wrapCount = i - last + 1; | 447 int wrapCount = i - last + 1; |
430 space = Math.max (0, (height - wrapY) / (wrapCount + 1)); | 453 space = Math.max (0, (height - wrapY) / (wrapCount + 1)); |
431 margin = Math.max (0, ((height - wrapY) % (wrapCount + 1)) / 2); | 454 margin = Math.max (0, ((height - wrapY) % (wrapCount + 1)) / 2); |
432 } | 455 } |
433 for (int j=last; j<=i; j++) { | 456 for (int j=last; j<=i; j++) { |
434 if (justify) bounds [j].y += (space * (j - last + 1)) + margin; | 457 if (justify) bounds [j].y += (space * (j - last + 1)) + margin; |
435 if (fill) bounds [j].width = wraps [i]; | 458 if (fill) { |
459 bounds [j].width = wraps [i]; | |
460 } else { | |
461 if (center) { | |
462 bounds [j].x += Math.max (0, (wraps [i] - bounds [j].width) / 2); | |
463 } | |
464 } | |
436 } | 465 } |
437 last = i + 1; | 466 last = i + 1; |
438 } | 467 } |
439 } | 468 } |
440 } | 469 } |
441 } | 470 } |
442 for (int i=0; i<count; i++) { | 471 for (int i=0; i<count; i++) { |
443 if (!wrapped) { | 472 if (!wrapped) { |
444 if (justify) bounds [i].y += (space * (i + 1)) + margin; | 473 if (justify) bounds [i].y += (space * (i + 1)) + margin; |
445 if (fill) bounds [i].width = maxWidth; | 474 if (fill) { |
475 bounds [i].width = maxWidth; | |
476 } else { | |
477 if (center) { | |
478 bounds [i].x += Math.max (0, (maxWidth - bounds [i].width) / 2); | |
479 } | |
480 } | |
481 | |
446 } | 482 } |
447 children [i].setBounds (bounds [i]); | 483 children [i].setBounds (bounds [i]); |
448 } | 484 } |
449 } | 485 } |
450 return new Point (x + maxWidth + marginRight + marginWidth, maxY); | 486 return new Point (x + maxWidth + marginRight + marginWidth, maxY); |