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