Mercurial > projects > dwt-mac
comparison dwt/custom/CBannerLayout.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 | f565d3a95c0a |
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 * | |
11 * Port to the D programming language: | 10 * Port to the D programming language: |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 11 * Frank Benoit <benoit@tionex.de> |
13 *******************************************************************************/ | 12 *******************************************************************************/ |
14 module dwt.custom.CBannerLayout; | 13 module dwt.custom.CBannerLayout; |
15 | 14 |
16 import Math = tango.math.Math; | |
17 | 15 |
18 import dwt.DWT; | 16 import dwt.DWT; |
19 import dwt.custom.CBanner; | |
20 import dwt.graphics.Point; | 17 import dwt.graphics.Point; |
21 import dwt.graphics.Rectangle; | 18 import dwt.graphics.Rectangle; |
22 import dwt.widgets.Composite; | 19 import dwt.widgets.Composite; |
23 import dwt.widgets.Control; | 20 import dwt.widgets.Control; |
24 import dwt.widgets.Layout; | 21 import dwt.widgets.Layout; |
25 import dwt.widgets.Scrollable; | 22 import dwt.widgets.Scrollable; |
23 import dwt.custom.CBanner; | |
24 import dwt.custom.CLayoutData; | |
25 | |
26 import Math = tango.math.Math; | |
26 | 27 |
27 /** | 28 /** |
28 * This class provides the layout for CBanner | 29 * This class provides the layout for CBanner |
29 * | 30 * |
30 * @see CBanner | 31 * @see CBanner |
31 */ | 32 */ |
32 class CBannerLayout : Layout { | 33 class CBannerLayout : Layout { |
33 | 34 |
34 protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) { | 35 protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { |
35 CBanner banner = cast(CBanner) composite; | 36 CBanner banner = cast(CBanner)composite; |
36 Control left = banner.left; | 37 Control left = banner.left; |
37 Control right = banner.right; | 38 Control right = banner.right; |
38 Control bottom = banner.bottom; | 39 Control bottom = banner.bottom; |
39 bool showCurve = left !is null && right !is null; | 40 bool showCurve = left !is null && right !is null; |
40 int height = hHint; | 41 int height = hHint; |
41 int width = wHint; | 42 int width = wHint; |
42 | 43 |
43 // Calculate component sizes | 44 // Calculate component sizes |
44 Point bottomSize = new Point(0, 0); | 45 Point bottomSize = new Point(0, 0); |
45 if (bottom !is null) { | 46 if (bottom !is null) { |
46 int trim = computeTrim(bottom); | 47 int trim = computeTrim(bottom); |
47 int w = wHint is DWT.DEFAULT ? DWT.DEFAULT : Math.max(0, width - trim); | 48 int w = wHint is DWT.DEFAULT ? DWT.DEFAULT : Math.max(0, width - trim); |
48 bottomSize = computeChildSize(bottom, w, DWT.DEFAULT, flushCache); | 49 bottomSize = computeChildSize(bottom, w, DWT.DEFAULT, flushCache); |
50 } | |
51 Point rightSize = new Point(0, 0); | |
52 if (right !is null) { | |
53 int trim = computeTrim(right); | |
54 int w = DWT.DEFAULT; | |
55 if (banner.rightWidth !is DWT.DEFAULT) { | |
56 w = banner.rightWidth - trim; | |
57 if (left !is null) { | |
58 w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim); | |
59 } | |
60 w = Math.max(0, w); | |
49 } | 61 } |
50 Point rightSize = new Point(0, 0); | 62 rightSize = computeChildSize(right, w, DWT.DEFAULT, flushCache); |
51 if (right !is null) { | 63 if (wHint !is DWT.DEFAULT) { |
52 int trim = computeTrim(right); | 64 width -= rightSize.x + banner.curve_width - 2* banner.curve_indent; |
53 int w = DWT.DEFAULT; | |
54 if (banner.rightWidth !is DWT.DEFAULT) { | |
55 w = banner.rightWidth - trim; | |
56 if (left !is null) { | |
57 w = Math.min(w, width - banner.curve_width + 2 * banner.curve_indent - CBanner.MIN_LEFT - trim); | |
58 } | |
59 w = Math.max(0, w); | |
60 } | |
61 rightSize = computeChildSize(right, w, DWT.DEFAULT, flushCache); | |
62 if (wHint !is DWT.DEFAULT) { | |
63 width -= rightSize.x + banner.curve_width - 2 * banner.curve_indent; | |
64 } | |
65 } | 65 } |
66 Point leftSize = new Point(0, 0); | 66 } |
67 if (left !is null) { | 67 Point leftSize = new Point(0, 0); |
68 int trim = computeTrim(left); | 68 if (left !is null) { |
69 int w = wHint is DWT.DEFAULT ? DWT.DEFAULT : Math.max(0, width - trim); | 69 int trim = computeTrim(left); |
70 leftSize = computeChildSize(left, w, DWT.DEFAULT, flushCache); | 70 int w = wHint is DWT.DEFAULT ? DWT.DEFAULT : Math.max(0, width - trim); |
71 } | 71 leftSize = computeChildSize(left, w, DWT.DEFAULT, flushCache); |
72 | |
73 // Add up sizes | |
74 width = leftSize.x + rightSize.x; | |
75 height = bottomSize.y; | |
76 if (bottom !is null && (left !is null || right !is null)) { | |
77 height += CBanner.BORDER_STRIPE + 2; | |
78 } | |
79 if (left !is null) { | |
80 if (right is null) { | |
81 height += leftSize.y; | |
82 } | |
83 else { | |
84 height += Math.max(leftSize.y, banner.rightMinHeight is DWT.DEFAULT ? rightSize.y : banner.rightMinHeight); | |
85 } | |
86 } | |
87 else { | |
88 height += rightSize.y; | |
89 } | |
90 if (showCurve) { | |
91 width += banner.curve_width - 2 * banner.curve_indent; | |
92 height += CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2 * CBanner.BORDER_STRIPE; | |
93 } | |
94 | |
95 if (wHint !is DWT.DEFAULT) | |
96 width = wHint; | |
97 if (hHint !is DWT.DEFAULT) | |
98 height = hHint; | |
99 | |
100 return new Point(width, height); | |
101 } | 72 } |
102 | 73 |
103 Point computeChildSize (Control control, int wHint, int hHint, bool flushCache) { | 74 // Add up sizes |
104 Object data = control.getLayoutData(); | 75 width = leftSize.x + rightSize.x; |
105 if (data is null || !(cast(CLayoutData) data)) { | 76 height = bottomSize.y; |
106 data = new CLayoutData(); | 77 if (bottom !is null && (left !is null || right !is null)) { |
107 control.setLayoutData(data); | 78 height += CBanner.BORDER_STRIPE + 2; |
79 } | |
80 if (left !is null) { | |
81 if (right is null) { | |
82 height += leftSize.y; | |
83 } else { | |
84 height += Math.max(leftSize.y, banner.rightMinHeight is DWT.DEFAULT ? rightSize.y : banner.rightMinHeight); | |
108 } | 85 } |
109 return (cast(CLayoutData) data).computeSize(control, wHint, hHint, flushCache); | 86 } else { |
87 height += rightSize.y; | |
88 } | |
89 if (showCurve) { | |
90 width += banner.curve_width - 2*banner.curve_indent; | |
91 height += CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2*CBanner.BORDER_STRIPE; | |
110 } | 92 } |
111 | 93 |
112 int computeTrim (Control c) { | 94 if (wHint !is DWT.DEFAULT) width = wHint; |
113 if (cast(Scrollable) c) { | 95 if (hHint !is DWT.DEFAULT) height = hHint; |
114 Rectangle rect = (cast(Scrollable) c).computeTrim(0, 0, 0, 0); | 96 |
115 return rect.width; | 97 return new Point(width, height); |
98 } | |
99 Point computeChildSize(Control control, int wHint, int hHint, bool flushCache) { | |
100 Object data = control.getLayoutData(); | |
101 if (data is null || !( null !is cast(CLayoutData)data)) { | |
102 data = new CLayoutData(); | |
103 control.setLayoutData(data); | |
104 } | |
105 return (cast(CLayoutData)data).computeSize(control, wHint, hHint, flushCache); | |
106 } | |
107 int computeTrim(Control c) { | |
108 if ( auto s = cast(Scrollable)c) { | |
109 Rectangle rect = s.computeTrim (0, 0, 0, 0); | |
110 return rect.width; | |
111 } | |
112 return c.getBorderWidth () * 2; | |
113 } | |
114 protected override bool flushCache(Control control) { | |
115 Object data = control.getLayoutData(); | |
116 if ( auto ld = cast(CLayoutData)data ) ld.flushCache(); | |
117 return true; | |
118 } | |
119 protected override void layout(Composite composite, bool flushCache) { | |
120 CBanner banner = cast(CBanner)composite; | |
121 Control left = banner.left; | |
122 Control right = banner.right; | |
123 Control bottom = banner.bottom; | |
124 | |
125 Point size = banner.getSize(); | |
126 bool showCurve = left !is null && right !is null; | |
127 int width = size.x - 2*banner.getBorderWidth(); | |
128 int height = size.y - 2*banner.getBorderWidth(); | |
129 | |
130 Point bottomSize = new Point(0, 0); | |
131 if (bottom !is null) { | |
132 int trim = computeTrim(bottom); | |
133 int w = Math.max(0, width - trim); | |
134 bottomSize = computeChildSize(bottom, w, DWT.DEFAULT, flushCache); | |
135 height -= bottomSize.y + CBanner.BORDER_STRIPE + 2; | |
136 } | |
137 if (showCurve) height -= CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2*CBanner.BORDER_STRIPE; | |
138 height = Math.max(0, height); | |
139 Point rightSize = new Point(0,0); | |
140 if (right !is null) { | |
141 int trim = computeTrim(right); | |
142 int w = DWT.DEFAULT; | |
143 if (banner.rightWidth !is DWT.DEFAULT) { | |
144 w = banner.rightWidth - trim; | |
145 if (left !is null) { | |
146 w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim); | |
147 } | |
148 w = Math.max(0, w); | |
116 } | 149 } |
117 return c.getBorderWidth() * 2; | 150 rightSize = computeChildSize(right, w, DWT.DEFAULT, flushCache); |
151 width = width - (rightSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent); | |
152 } | |
153 Point leftSize = new Point(0, 0); | |
154 if (left !is null) { | |
155 int trim = computeTrim(left); | |
156 int w = Math.max(0, width - trim); | |
157 leftSize = computeChildSize(left, w, DWT.DEFAULT, flushCache); | |
118 } | 158 } |
119 | 159 |
120 protected bool flushCache (Control control) { | 160 int x = 0; |
121 Object data = control.getLayoutData(); | 161 int y = 0; |
122 if (data !is null && cast(CLayoutData) data) | 162 int oldStart = banner.curveStart; |
123 (cast(CLayoutData) data).flushCache(); | 163 Rectangle leftRect = null; |
124 return true; | 164 Rectangle rightRect = null; |
165 Rectangle bottomRect = null; | |
166 if (bottom !is null) { | |
167 bottomRect = new Rectangle(x, y+size.y-bottomSize.y, bottomSize.x, bottomSize.y); | |
125 } | 168 } |
126 | 169 if (showCurve) y += CBanner.BORDER_TOP + CBanner.BORDER_STRIPE; |
127 protected void layout (Composite composite, bool flushCache) { | 170 if(left !is null) { |
128 CBanner banner = cast(CBanner) composite; | 171 leftRect = new Rectangle(x, y, leftSize.x, leftSize.y); |
129 Control left = banner.left; | 172 banner.curveStart = x + leftSize.x - banner.curve_indent; |
130 Control right = banner.right; | 173 x += leftSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent; |
131 Control bottom = banner.bottom; | 174 } |
132 | 175 if (right !is null) { |
133 Point size = banner.getSize(); | 176 if (left !is null) { |
134 bool showCurve = left !is null && right !is null; | 177 rightSize.y = Math.max(leftSize.y, banner.rightMinHeight is DWT.DEFAULT ? rightSize.y : banner.rightMinHeight); |
135 int width = size.x - 2 * banner.getBorderWidth(); | |
136 int height = size.y - 2 * banner.getBorderWidth(); | |
137 | |
138 Point bottomSize = new Point(0, 0); | |
139 if (bottom !is null) { | |
140 int trim = computeTrim(bottom); | |
141 int w = Math.max(0, width - trim); | |
142 bottomSize = computeChildSize(bottom, w, DWT.DEFAULT, flushCache); | |
143 height -= bottomSize.y + CBanner.BORDER_STRIPE + 2; | |
144 } | 178 } |
145 if (showCurve) | 179 rightRect = new Rectangle(x, y, rightSize.x, rightSize.y); |
146 height -= CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2 * CBanner.BORDER_STRIPE; | |
147 height = Math.max(0, height); | |
148 Point rightSize = new Point(0, 0); | |
149 if (right !is null) { | |
150 int trim = computeTrim(right); | |
151 int w = DWT.DEFAULT; | |
152 if (banner.rightWidth !is DWT.DEFAULT) { | |
153 w = banner.rightWidth - trim; | |
154 if (left !is null) { | |
155 w = Math.min(w, width - banner.curve_width + 2 * banner.curve_indent - CBanner.MIN_LEFT - trim); | |
156 } | |
157 w = Math.max(0, w); | |
158 } | |
159 rightSize = computeChildSize(right, w, DWT.DEFAULT, flushCache); | |
160 width = width - (rightSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent); | |
161 } | |
162 Point leftSize = new Point(0, 0); | |
163 if (left !is null) { | |
164 int trim = computeTrim(left); | |
165 int w = Math.max(0, width - trim); | |
166 leftSize = computeChildSize(left, w, DWT.DEFAULT, flushCache); | |
167 } | |
168 | |
169 int x = 0; | |
170 int y = 0; | |
171 int oldStart = banner.curveStart; | |
172 Rectangle leftRect = null; | |
173 Rectangle rightRect = null; | |
174 Rectangle bottomRect = null; | |
175 if (bottom !is null) { | |
176 bottomRect = new Rectangle(x, y + size.y - bottomSize.y, bottomSize.x, bottomSize.y); | |
177 } | |
178 if (showCurve) | |
179 y += CBanner.BORDER_TOP + CBanner.BORDER_STRIPE; | |
180 if (left !is null) { | |
181 leftRect = new Rectangle(x, y, leftSize.x, leftSize.y); | |
182 banner.curveStart = x + leftSize.x - banner.curve_indent; | |
183 x += leftSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent; | |
184 } | |
185 if (right !is null) { | |
186 if (left !is null) { | |
187 rightSize.y = Math.max(leftSize.y, banner.rightMinHeight is DWT.DEFAULT ? rightSize.y : banner.rightMinHeight); | |
188 } | |
189 rightRect = new Rectangle(x, y, rightSize.x, rightSize.y); | |
190 } | |
191 if (banner.curveStart < oldStart) { | |
192 banner.redraw(banner.curveStart - CBanner.CURVE_TAIL, 0, oldStart + banner.curve_width - banner.curveStart + CBanner.CURVE_TAIL + 5, | |
193 size.y, false); | |
194 } | |
195 if (banner.curveStart > oldStart) { | |
196 banner.redraw(oldStart - CBanner.CURVE_TAIL, 0, banner.curveStart + banner.curve_width - oldStart + CBanner.CURVE_TAIL + 5, size.y, false); | |
197 } | |
198 /* | |
199 * The paint events must be flushed in order to make the curve draw smoothly | |
200 * while the user drags the divider. | |
201 * On Windows, it is necessary to flush the paints before the children are | |
202 * resized because otherwise the children (particularly toolbars) will flash. | |
203 */ | |
204 banner.update(); | |
205 banner.curveRect = new Rectangle(banner.curveStart, 0, banner.curve_width, size.y); | |
206 if (bottomRect !is null) | |
207 bottom.setBounds(bottomRect); | |
208 if (rightRect !is null) | |
209 right.setBounds(rightRect); | |
210 if (leftRect !is null) | |
211 left.setBounds(leftRect); | |
212 } | 180 } |
181 if (banner.curveStart < oldStart) { | |
182 banner.redraw(banner.curveStart - CBanner.CURVE_TAIL, 0, oldStart + banner.curve_width - banner.curveStart + CBanner.CURVE_TAIL + 5, size.y, false); | |
183 } | |
184 if (banner.curveStart > oldStart) { | |
185 banner.redraw(oldStart - CBanner.CURVE_TAIL, 0, banner.curveStart + banner.curve_width - oldStart + CBanner.CURVE_TAIL + 5, size.y, false); | |
186 } | |
187 /* | |
188 * The paint events must be flushed in order to make the curve draw smoothly | |
189 * while the user drags the divider. | |
190 * On Windows, it is necessary to flush the paints before the children are | |
191 * resized because otherwise the children (particularly toolbars) will flash. | |
192 */ | |
193 banner.update(); | |
194 banner.curveRect = new Rectangle(banner.curveStart, 0, banner.curve_width, size.y); | |
195 if (bottomRect !is null) bottom.setBounds(bottomRect); | |
196 if (rightRect !is null) right.setBounds(rightRect); | |
197 if (leftRect !is null) left.setBounds(leftRect); | |
213 } | 198 } |
199 } |