Mercurial > projects > dwt-mac
diff dwt/custom/SashForm.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/SashForm.d Tue Oct 07 14:41:31 2008 +0200 +++ b/dwt/custom/SashForm.d Tue Oct 07 16:29:55 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,13 +7,26 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> *******************************************************************************/ -module dwt.custom; +module dwt.custom.SashForm; + -import dwt.*; -import dwt.widgets.*; -import dwt.graphics.*; +import dwt.DWT; +import dwt.DWTException; +import dwt.graphics.Color; +import dwt.graphics.Rectangle; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Event; +import dwt.widgets.Layout; +import dwt.widgets.Listener; +import dwt.widgets.Sash; +import dwt.custom.SashFormLayout; +import dwt.custom.SashFormData; +import dwt.dwthelper.utils; /** * The SashForm is a composite control that lays out its children in a @@ -27,23 +40,30 @@ * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd> * </dl> * </p> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#sashform">SashForm snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: CustomControlExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class SashForm : Composite { + /** + * The width of all sashes in the form. + */ public int SASH_WIDTH = 3; int sashStyle; - Sash[] sashes = new Sash[0]; + Sash[] sashes; // Remember background and foreground // colors to determine whether to set // sashes to the default color (null) or // a specific color Color background = null; Color foreground = null; - Control[] controls = new Control[0]; + Control[] controls; Control maxControl = null; Listener sashListener; - static final int DRAG_MINIMUM = 20; + static const int DRAG_MINIMUM = 20; /** * Constructs a new instance of this class given its parent @@ -51,7 +71,7 @@ * <p> * The style value is either one of the style constants defined in * class <code>DWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together + * class, or must be built by <em>bitwise OR</em>'ing together * (that is, using the <code>int</code> "|" operator) two or more * of those <code>DWT</code> style constants. The class description * lists the style constants that are applicable to the class. @@ -78,7 +98,7 @@ sashStyle = ((style & DWT.VERTICAL) !is 0) ? DWT.HORIZONTAL : DWT.VERTICAL; if ((style & DWT.BORDER) !is 0) sashStyle |= DWT.BORDER; if ((style & DWT.SMOOTH) !is 0) sashStyle |= DWT.SMOOTH; - sashListener = new Listener() { + sashListener = new class() Listener { public void handleEvent(Event e) { onDragSash(e); } @@ -91,7 +111,7 @@ /** * Returns DWT.HORIZONTAL if the controls in the SashForm are laid out side by side * or DWT.VERTICAL if the controls in the SashForm are laid out top to bottom. - * + * * @return DWT.HORIZONTAL or DWT.VERTICAL */ public int getOrientation() { @@ -115,16 +135,16 @@ checkWidget(); return SASH_WIDTH; } -public int getStyle() { +public override int getStyle() { int style = super.getStyle(); style |= getOrientation() is DWT.VERTICAL ? DWT.VERTICAL : DWT.HORIZONTAL; if ((sashStyle & DWT.SMOOTH) !is 0) style |= DWT.SMOOTH; return style; } /** - * Answer the control that currently is maximized in the SashForm. + * Answer the control that currently is maximized in the SashForm. * This value may be null. - * + * * @return the control that currently is maximized or null */ public Control getMaximizedControl(){ @@ -133,13 +153,13 @@ } /** * Answer the relative weight of each child in the SashForm. The weight represents the - * percent of the total width (if SashForm has Horizontal orientation) or + * percent of the total width (if SashForm has Horizontal orientation) or * total height (if SashForm has Vertical orientation) each control occupies. * The weights are returned in order of the creation of the widgets (weight[0] * corresponds to the weight of the first child created). - * + * * @return the relative weight of each child - * + * * @exception DWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> @@ -152,8 +172,8 @@ int[] ratios = new int[cArray.length]; 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(int)((cast(SashFormData)data).weight * 1000 >> 16); + if ( auto sfd = cast(SashFormData)data ) { + ratios[i] = cast(int)(sfd.weight * 1000 >> 16); } else { ratios[i] = 200; } @@ -164,7 +184,7 @@ Control[] children = getChildren(); Control[] result = new Control[0]; for (int i = 0; i < children.length; i++) { - if (children[i] instanceof Sash) continue; + if ( null !is cast(Sash)children[i]) continue; if (onlyVisible && !children[i].getVisible()) continue; Control[] newResult = new Control[result.length + 1]; @@ -189,13 +209,13 @@ Control c2 = controls[sashIndex + 1]; Rectangle b1 = c1.getBounds(); Rectangle b2 = c2.getBounds(); - + Rectangle sashBounds = sash.getBounds(); Rectangle area = getClientArea(); bool correction = false; if (getOrientation() is DWT.HORIZONTAL) { correction = b1.width < DRAG_MINIMUM || b2.width < DRAG_MINIMUM; - int totalWidth = b2.x + b2.width - b1.x; + int totalWidth = b2.x + b2.width - b1.x; int shift = event.x - sashBounds.x; b1.width += shift; b2.x += shift; @@ -253,7 +273,7 @@ c1.setLayoutData(data1); } Object data2 = c2.getLayoutData(); - if (data2 is null || !( null !is cast(SashFormData)data2 )) { + if (data2 is null || !(null !is cast(SashFormData)data2 )) { data2 = new SashFormData(); c2.setLayoutData(data2); } @@ -267,12 +287,12 @@ } } /** - * If orientation is DWT.HORIZONTAL, lay the controls in the SashForm - * out side by side. If orientation is DWT.VERTICAL, lay the + * If orientation is DWT.HORIZONTAL, lay the controls in the SashForm + * out side by side. If orientation is DWT.VERTICAL, lay the * controls in the SashForm out top to bottom. - * + * * @param orientation DWT.HORIZONTAL or DWT.VERTICAL - * + * * @exception DWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> @@ -296,14 +316,14 @@ } layout(false); } -public void setBackground (Color color) { +public override void setBackground (Color color) { super.setBackground(color); background = color; for (int i = 0; i < sashes.length; i++) { sashes[i].setBackground(background); } } -public void setForeground (Color color) { +public override void setForeground (Color color) { super.setForeground(color); foreground = color; for (int i = 0; i < sashes.length; i++) { @@ -325,19 +345,19 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setLayout (Layout layout) { +public override void setLayout (Layout layout) { checkWidget(); return; } /** - * Specify the control that should take up the entire client area of the SashForm. - * If one control has been maximized, and this method is called with a different control, + * Specify the control that should take up the entire client area of the SashForm. + * If one control has been maximized, and this method is called with a different control, * the previous control will be minimized and the new control will be maximized. * If the value of control is null, the SashForm will minimize all controls and return to * the default layout where all controls are laid out separated by sashes. - * + * * @param control the control to be maximized or null - * + * * @exception DWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> @@ -355,7 +375,7 @@ } return; } - + for (int i= 0; i < sashes.length; i++){ sashes[i].setVisible(false); } @@ -384,13 +404,13 @@ } /** * Specify the relative weight of each child in the SashForm. This will determine - * what percent of the total width (if SashForm has Horizontal orientation) or + * what percent of the total width (if SashForm has Horizontal orientation) or * total height (if SashForm has Vertical orientation) each control will occupy. * The weights must be positive values and there must be an entry for each * non-sash child of the SashForm. - * + * * @param weights the relative weight of each child - * + * * @exception DWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> @@ -403,7 +423,7 @@ if (weights is null || weights.length !is cArray.length) { DWT.error(DWT.ERROR_INVALID_ARGUMENT); } - + int total = 0; for (int i = 0; i < weights.length; i++) { if (weights[i] < 0) {