Mercurial > projects > dwt-mac
comparison dwt/custom/ViewFormLayout.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | e831403a80a9 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 *******************************************************************************/ | |
11 module dwt.custom; | |
12 | |
13 import dwt.*; | |
14 import dwt.graphics.*; | |
15 import dwt.widgets.*; | |
16 | |
17 /** | |
18 * This class provides the layout for ViewForm | |
19 * | |
20 * @see ViewForm | |
21 */ | |
22 class ViewFormLayout : Layout { | |
23 | |
24 protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { | |
25 ViewForm form = (ViewForm)composite; | |
26 Control left = form.topLeft; | |
27 Control center = form.topCenter; | |
28 Control right = form.topRight; | |
29 Control content = form.content; | |
30 | |
31 Point leftSize = new Point(0, 0); | |
32 if (left !is null) { | |
33 leftSize = computeChildSize(left, DWT.DEFAULT, DWT.DEFAULT, flushCache); | |
34 } | |
35 Point centerSize = new Point(0, 0); | |
36 if (center !is null) { | |
37 centerSize = computeChildSize(center, DWT.DEFAULT, DWT.DEFAULT, flushCache); | |
38 } | |
39 Point rightSize = new Point(0, 0); | |
40 if (right !is null) { | |
41 rightSize = computeChildSize(right, DWT.DEFAULT, DWT.DEFAULT, flushCache); | |
42 } | |
43 Point size = new Point(0, 0); | |
44 // calculate width of title bar | |
45 if (form.separateTopCenter || | |
46 (wHint !is DWT.DEFAULT && leftSize.x + centerSize.x + rightSize.x > wHint)) { | |
47 size.x = leftSize.x + rightSize.x; | |
48 if (leftSize.x > 0 && rightSize.x > 0) size.x += form.horizontalSpacing; | |
49 size.x = Math.max(centerSize.x, size.x); | |
50 size.y = Math.max(leftSize.y, rightSize.y); | |
51 if (center !is null){ | |
52 size.y += centerSize.y; | |
53 if (left !is null ||right !is null)size.y += form.verticalSpacing; | |
54 } | |
55 } else { | |
56 size.x = leftSize.x + centerSize.x + rightSize.x; | |
57 int count = -1; | |
58 if (leftSize.x > 0) count++; | |
59 if (centerSize.x > 0) count++; | |
60 if (rightSize.x > 0) count++; | |
61 if (count > 0) size.x += count * form.horizontalSpacing; | |
62 size.y = Math.max(leftSize.y, Math.max(centerSize.y, rightSize.y)); | |
63 } | |
64 | |
65 if (content !is null) { | |
66 if (left !is null || right !is null || center !is null) size.y += 1; // allow space for a vertical separator | |
67 Point contentSize = new Point(0, 0); | |
68 contentSize = computeChildSize(content, DWT.DEFAULT, DWT.DEFAULT, flushCache); | |
69 size.x = Math.max (size.x, contentSize.x); | |
70 size.y += contentSize.y; | |
71 if (size.y > contentSize.y) size.y += form.verticalSpacing; | |
72 } | |
73 | |
74 size.x += 2*form.marginWidth; | |
75 size.y += 2*form.marginHeight; | |
76 | |
77 if (wHint !is DWT.DEFAULT) size.x = wHint; | |
78 if (hHint !is DWT.DEFAULT) size.y = hHint; | |
79 | |
80 return size; | |
81 } | |
82 | |
83 Point computeChildSize(Control control, int wHint, int hHint, bool flushCache) { | |
84 Object data = control.getLayoutData(); | |
85 if (data is null || !(data instanceof CLayoutData)) { | |
86 data = new CLayoutData(); | |
87 control.setLayoutData(data); | |
88 } | |
89 return ((CLayoutData)data).computeSize(control, wHint, hHint, flushCache); | |
90 } | |
91 | |
92 int computeTrim(Control c) { | |
93 if (c instanceof Scrollable) { | |
94 Rectangle rect = ((Scrollable) c).computeTrim (0, 0, 0, 0); | |
95 return rect.width; | |
96 } | |
97 return c.getBorderWidth () * 2; | |
98 } | |
99 | |
100 protected bool flushCache(Control control) { | |
101 Object data = control.getLayoutData(); | |
102 if (data !is null && data instanceof CLayoutData) ((CLayoutData)data).flushCache(); | |
103 return true; | |
104 } | |
105 | |
106 protected void layout(Composite composite, bool flushCache) { | |
107 ViewForm form = (ViewForm)composite; | |
108 Control left = form.topLeft; | |
109 Control center = form.topCenter; | |
110 Control right = form.topRight; | |
111 Control content = form.content; | |
112 | |
113 Rectangle rect = composite.getClientArea(); | |
114 | |
115 Point leftSize = new Point(0, 0); | |
116 if (left !is null && !left.isDisposed()) { | |
117 leftSize = computeChildSize(left, DWT.DEFAULT, DWT.DEFAULT, flushCache); | |
118 } | |
119 Point centerSize = new Point(0, 0); | |
120 if (center !is null && !center.isDisposed()) { | |
121 centerSize = computeChildSize(center, DWT.DEFAULT, DWT.DEFAULT, flushCache); | |
122 } | |
123 Point rightSize = new Point(0, 0); | |
124 if (right !is null && !right.isDisposed()) { | |
125 rightSize = computeChildSize(right, DWT.DEFAULT, DWT.DEFAULT, flushCache); | |
126 } | |
127 | |
128 int minTopWidth = leftSize.x + centerSize.x + rightSize.x + 2*form.marginWidth + 2*form.highlight; | |
129 int count = -1; | |
130 if (leftSize.x > 0) count++; | |
131 if (centerSize.x > 0) count++; | |
132 if (rightSize.x > 0) count++; | |
133 if (count > 0) minTopWidth += count * form.horizontalSpacing; | |
134 | |
135 int x = rect.x + rect.width - form.marginWidth - form.highlight; | |
136 int y = rect.y + form.marginHeight + form.highlight; | |
137 | |
138 bool top = false; | |
139 if (form.separateTopCenter || minTopWidth > rect.width) { | |
140 int topHeight = Math.max(rightSize.y, leftSize.y); | |
141 if (right !is null && !right.isDisposed()) { | |
142 top = true; | |
143 x -= rightSize.x; | |
144 right.setBounds(x, y, rightSize.x, topHeight); | |
145 x -= form.horizontalSpacing; | |
146 } | |
147 if (left !is null && !left.isDisposed()) { | |
148 top = true; | |
149 int trim = computeTrim(left); | |
150 int leftW = x - rect.x - form.marginWidth - form.highlight - trim; | |
151 leftSize = computeChildSize(left, leftW, DWT.DEFAULT, false); | |
152 left.setBounds(rect.x + form.marginWidth + form.highlight, y, leftSize.x, topHeight); | |
153 } | |
154 if (top) y += topHeight + form.verticalSpacing; | |
155 if (center !is null && !center.isDisposed()) { | |
156 top = true; | |
157 int trim = computeTrim(center); | |
158 int w = rect.width - 2*form.marginWidth - 2*form.highlight - trim; | |
159 centerSize = computeChildSize(center, w, DWT.DEFAULT, false); | |
160 center.setBounds(rect.x + rect.width - form.marginWidth - form.highlight - centerSize.x, y, centerSize.x, centerSize.y); | |
161 y += centerSize.y + form.verticalSpacing; | |
162 } | |
163 } else { | |
164 int topHeight = Math.max(rightSize.y, Math.max(centerSize.y, leftSize.y)); | |
165 if (right !is null && !right.isDisposed()) { | |
166 top = true; | |
167 x -= rightSize.x; | |
168 right.setBounds(x, y, rightSize.x, topHeight); | |
169 x -= form.horizontalSpacing; | |
170 } | |
171 if (center !is null && !center.isDisposed()) { | |
172 top = true; | |
173 x -= centerSize.x; | |
174 center.setBounds(x, y, centerSize.x, topHeight); | |
175 x -= form.horizontalSpacing; | |
176 } | |
177 if (left !is null && !left.isDisposed()) { | |
178 top = true; | |
179 Rectangle trim = left instanceof Composite ? ((Composite)left).computeTrim(0, 0, 0, 0) : new Rectangle(0, 0, 0, 0); | |
180 int w = x - rect.x - form.marginWidth - form.highlight - trim.width; | |
181 int h = topHeight - trim.height; | |
182 leftSize = computeChildSize(left, w, h, false); | |
183 left.setBounds(rect.x + form.marginWidth + form.highlight, y, leftSize.x, topHeight); | |
184 } | |
185 if (top)y += topHeight + form.verticalSpacing; | |
186 } | |
187 int oldSeperator = form.separator; | |
188 form.separator = -1; | |
189 if (content !is null && !content.isDisposed()) { | |
190 if (left !is null || right!= null || center !is null){ | |
191 form.separator = y; | |
192 y++; | |
193 } | |
194 content.setBounds(rect.x + form.marginWidth + form.highlight, y, rect.width - 2 * form.marginWidth - 2*form.highlight, rect.y + rect.height - y - form.marginHeight - form.highlight); | |
195 } | |
196 if (oldSeperator !is -1 && form.separator !is -1) { | |
197 int t = Math.min(form.separator, oldSeperator); | |
198 int b = Math.max(form.separator, oldSeperator); | |
199 form.redraw(form.borderLeft, t, form.getSize().x - form.borderLeft - form.borderRight, b - t, false); | |
200 } | |
201 } | |
202 } |