comparison 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
comparison
equal deleted inserted replaced
40:fbe68c33eeee 41:6337764516f1
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
10 *******************************************************************************/ 12 *******************************************************************************/
11 module dwt.custom; 13 module dwt.custom.SashFormLayout;
12 14
13 import dwt.*; 15
14 import dwt.graphics.*; 16 import dwt.DWT;
15 import dwt.widgets.*; 17 import dwt.graphics.Point;
18 import dwt.graphics.Rectangle;
19 import dwt.widgets.Composite;
20 import dwt.widgets.Control;
21 import dwt.widgets.Layout;
22 import dwt.widgets.Sash;
23 import dwt.custom.SashForm;
24 import dwt.custom.SashFormData;
25 import dwt.dwthelper.utils;
16 26
17 /** 27 /**
18 * This class provides the layout for SashForm 28 * This class provides the layout for SashForm
19 * 29 *
20 * @see SashForm 30 * @see SashForm
21 */ 31 */
22 class SashFormLayout : Layout { 32 class SashFormLayout : Layout {
23 protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { 33 protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
24 SashForm sashForm = cast(SashForm)composite; 34 SashForm sashForm = cast(SashForm)composite;
25 Control[] cArray = sashForm.getControls(true); 35 Control[] cArray = sashForm.getControls(true);
26 int width = 0; 36 int width = 0;
27 int height = 0; 37 int height = 0;
28 if (cArray.length is 0) { 38 if (cArray.length is 0) {
29 if (wHint !is DWT.DEFAULT) width = wHint; 39 if (wHint !is DWT.DEFAULT) width = wHint;
30 if (hHint !is DWT.DEFAULT) height = hHint; 40 if (hHint !is DWT.DEFAULT) height = hHint;
31 return new Point(width, height); 41 return new Point(width, height);
32 } 42 }
33 // determine control sizes 43 // determine control sizes
54 // get the ratios 64 // get the ratios
55 long[] ratios = new long[cArray.length]; 65 long[] ratios = new long[cArray.length];
56 long total = 0; 66 long total = 0;
57 for (int i = 0; i < cArray.length; i++) { 67 for (int i = 0; i < cArray.length; i++) {
58 Object data = cArray[i].getLayoutData(); 68 Object data = cArray[i].getLayoutData();
59 if (data !is null && null !is cast(SashFormData)data ) { 69 if ( auto sfd = cast(SashFormData)data) {
60 ratios[i] = (cast(SashFormData)data).weight; 70 ratios[i] = sfd.weight;
61 } else { 71 } else {
62 data = new SashFormData(); 72 data = new SashFormData();
63 cArray[i].setLayoutData(data); 73 cArray[i].setLayoutData(data);
64 (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; 74 (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000;
65 75
66 } 76 }
67 total += ratios[i]; 77 total += ratios[i];
68 } 78 }
69 if (ratios[maxIndex] > 0) { 79 if (ratios[maxIndex] > 0) {
70 int sashwidth = sashForm.sashes.length > 0 ? sashForm.SASH_WIDTH + sashForm.sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; 80 int sashwidth = sashForm.sashes.length > 0 ? sashForm.SASH_WIDTH + sashForm.sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH;
79 if (wHint !is DWT.DEFAULT) width = wHint; 89 if (wHint !is DWT.DEFAULT) width = wHint;
80 if (hHint !is DWT.DEFAULT) height = hHint; 90 if (hHint !is DWT.DEFAULT) height = hHint;
81 return new Point(width, height); 91 return new Point(width, height);
82 } 92 }
83 93
84 protected bool flushCache(Control control) { 94 protected override bool flushCache(Control control) {
85 return true; 95 return true;
86 } 96 }
87 97
88 protected void layout(Composite composite, bool flushCache) { 98 protected override void layout(Composite composite, bool flushCache) {
89 SashForm sashForm = cast(SashForm)composite; 99 SashForm sashForm = cast(SashForm)composite;
90 Rectangle area = sashForm.getClientArea(); 100 Rectangle area = sashForm.getClientArea();
91 if (area.width <= 1 || area.height <= 1) return; 101 if (area.width <= 1 || area.height <= 1) return;
92 102
93 Control[] newControls = sashForm.getControls(true); 103 Control[] newControls = sashForm.getControls(true);
94 if (sashForm.controls.length is 0 && newControls.length is 0) return; 104 if (sashForm.controls.length is 0 && newControls.length is 0) return;
95 sashForm.controls = newControls; 105 sashForm.controls = newControls;
96 106
97 Control[] controls = sashForm.controls; 107 Control[] controls = sashForm.controls;
98 108
99 if (sashForm.maxControl !is null && !sashForm.maxControl.isDisposed()) { 109 if (sashForm.maxControl !is null && !sashForm.maxControl.isDisposed()) {
100 for (int i= 0; i < controls.length; i++){ 110 for (int i= 0; i < controls.length; i++){
101 if (controls[i] !is sashForm.maxControl) { 111 if (controls[i] !is sashForm.maxControl) {
102 controls[i].setBounds(-200, -200, 0, 0); 112 controls[i].setBounds(-200, -200, 0, 0);
103 } else { 113 } else {
104 controls[i].setBounds(area); 114 controls[i].setBounds(area);
105 } 115 }
106 } 116 }
107 return; 117 return;
108 } 118 }
109 119
110 // keep just the right number of sashes 120 // keep just the right number of sashes
111 if (sashForm.sashes.length < controls.length - 1) { 121 if (sashForm.sashes.length < controls.length - 1) {
112 Sash[] newSashes = new Sash[controls.length - 1]; 122 Sash[] newSashes = new Sash[controls.length - 1];
113 System.arraycopy(sashForm.sashes, 0, newSashes, 0, sashForm.sashes.length); 123 System.arraycopy(sashForm.sashes, 0, newSashes, 0, sashForm.sashes.length);
114 for (int i = sashForm.sashes.length; i < newSashes.length; i++) { 124 for (int i = sashForm.sashes.length; i < newSashes.length; i++) {
139 // get the ratios 149 // get the ratios
140 long[] ratios = new long[controls.length]; 150 long[] ratios = new long[controls.length];
141 long total = 0; 151 long total = 0;
142 for (int i = 0; i < controls.length; i++) { 152 for (int i = 0; i < controls.length; i++) {
143 Object data = controls[i].getLayoutData(); 153 Object data = controls[i].getLayoutData();
144 if (data !is null && null !is cast(SashFormData)data ) { 154 if ( auto sfd = cast(SashFormData)data ) {
145 ratios[i] = (cast(SashFormData)data).weight; 155 ratios[i] = sfd.weight;
146 } else { 156 } else {
147 data = new SashFormData(); 157 data = new SashFormData();
148 controls[i].setLayoutData(data); 158 controls[i].setLayoutData(data);
149 (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000; 159 (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000;
150 160
151 } 161 }
152 total += ratios[i]; 162 total += ratios[i];
153 } 163 }
154 164
155 int sashwidth = sashes.length > 0 ? sashForm.SASH_WIDTH + sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; 165 int sashwidth = sashes.length > 0 ? sashForm.SASH_WIDTH + sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH;
156 if (sashForm.getOrientation() is DWT.HORIZONTAL) { 166 if (sashForm.getOrientation() is DWT.HORIZONTAL) {
157 int width = cast(int)(ratios[0] * (area.width - sashes.length * sashwidth) / total); 167 int width = cast(int)(ratios[0] * (area.width - sashes.length * sashwidth) / total);
158 int x = area.x; 168 int x = area.x;
159 controls[0].setBounds(x, area.y, width, area.height); 169 controls[0].setBounds(x, area.y, width, area.height);