Mercurial > projects > dwt-mac
diff dwt/custom/SashFormLayout.d @ 41:6337764516f1
Sync dwt/custom with dwt-linux (took copy of complete folder)
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 16:29:55 +0200 |
parents | a9ab4c738ed8 |
children |
line wrap: on
line diff
--- a/dwt/custom/SashFormLayout.d Tue Oct 07 14:41:31 2008 +0200 +++ b/dwt/custom/SashFormLayout.d Tue Oct 07 16:29:55 2008 +0200 @@ -7,25 +7,35 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> *******************************************************************************/ -module dwt.custom; +module dwt.custom.SashFormLayout; + -import dwt.*; -import dwt.graphics.*; -import dwt.widgets.*; +import dwt.DWT; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Layout; +import dwt.widgets.Sash; +import dwt.custom.SashForm; +import dwt.custom.SashFormData; +import dwt.dwthelper.utils; /** * This class provides the layout for SashForm - * + * * @see SashForm */ class SashFormLayout : Layout { -protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { +protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { SashForm sashForm = cast(SashForm)composite; Control[] cArray = sashForm.getControls(true); int width = 0; int height = 0; - if (cArray.length is 0) { + if (cArray.length is 0) { if (wHint !is DWT.DEFAULT) width = wHint; if (hHint !is DWT.DEFAULT) height = hHint; return new Point(width, height); @@ -56,13 +66,13 @@ long total = 0; for (int i = 0; i < cArray.length; i++) { Object data = cArray[i].getLayoutData(); - if (data !is null && null !is cast(SashFormData)data ) { - ratios[i] = (cast(SashFormData)data).weight; + if ( auto sfd = cast(SashFormData)data) { + ratios[i] = sfd.weight; } else { data = new SashFormData(); cArray[i].setLayoutData(data); (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; - + } total += ratios[i]; } @@ -81,21 +91,21 @@ return new Point(width, height); } -protected bool flushCache(Control control) { +protected override bool flushCache(Control control) { return true; } -protected void layout(Composite composite, bool flushCache) { +protected override void layout(Composite composite, bool flushCache) { SashForm sashForm = cast(SashForm)composite; Rectangle area = sashForm.getClientArea(); if (area.width <= 1 || area.height <= 1) return; - + Control[] newControls = sashForm.getControls(true); if (sashForm.controls.length is 0 && newControls.length is 0) return; sashForm.controls = newControls; - + Control[] controls = sashForm.controls; - + if (sashForm.maxControl !is null && !sashForm.maxControl.isDisposed()) { for (int i= 0; i < controls.length; i++){ if (controls[i] !is sashForm.maxControl) { @@ -106,7 +116,7 @@ } return; } - + // keep just the right number of sashes if (sashForm.sashes.length < controls.length - 1) { Sash[] newSashes = new Sash[controls.length - 1]; @@ -141,17 +151,17 @@ long total = 0; for (int i = 0; i < controls.length; i++) { Object data = controls[i].getLayoutData(); - if (data !is null && null !is cast(SashFormData)data ) { - ratios[i] = (cast(SashFormData)data).weight; + if ( auto sfd = cast(SashFormData)data ) { + ratios[i] = sfd.weight; } else { data = new SashFormData(); controls[i].setLayoutData(data); (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; - + } total += ratios[i]; } - + int sashwidth = sashes.length > 0 ? sashForm.SASH_WIDTH + sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; if (sashForm.getOrientation() is DWT.HORIZONTAL) { int width = cast(int)(ratios[0] * (area.width - sashes.length * sashwidth) / total);