1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.custom;
16 import org.eclipse.swt.*;
17 import org.eclipse.swt.graphics.*;
18 import org.eclipse.swt.widgets.*;
21 * This class provides the layout for CBanner
25 class CBannerLayout extends Layout {
28 protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
29 CBanner banner = (CBanner)composite;
30 Control left = banner.left;
31 Control right = banner.right;
32 Control bottom = banner.bottom;
33 boolean showCurve = left != null && right != null;
37 // Calculate component sizes
38 Point bottomSize = new Point(0, 0);
40 int trim = computeTrim(bottom);
41 int w = wHint == SWT.DEFAULT ? SWT.DEFAULT : Math.max(0, width - trim);
42 bottomSize = computeChildSize(bottom, w, SWT.DEFAULT, flushCache);
44 Point rightSize = new Point(0, 0);
46 int trim = computeTrim(right);
48 if (banner.rightWidth != SWT.DEFAULT) {
49 w = banner.rightWidth - trim;
51 w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim);
55 rightSize = computeChildSize(right, w, SWT.DEFAULT, flushCache);
56 if (wHint != SWT.DEFAULT) {
57 width -= rightSize.x + banner.curve_width - 2* banner.curve_indent;
60 Point leftSize = new Point(0, 0);
62 int trim = computeTrim(left);
63 int w = wHint == SWT.DEFAULT ? SWT.DEFAULT : Math.max(0, width - trim);
64 leftSize = computeChildSize(left, w, SWT.DEFAULT, flushCache);
68 width = leftSize.x + rightSize.x;
69 height = bottomSize.y;
70 if (bottom != null && (left != null || right != null)) {
71 height += CBanner.BORDER_STRIPE + 2;
77 height += Math.max(leftSize.y, banner.rightMinHeight == SWT.DEFAULT ? rightSize.y : banner.rightMinHeight);
80 height += rightSize.y;
83 width += banner.curve_width - 2*banner.curve_indent;
84 height += CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2*CBanner.BORDER_STRIPE;
87 if (wHint != SWT.DEFAULT) width = wHint;
88 if (hHint != SWT.DEFAULT) height = hHint;
90 return new Point(width, height);
92 Point computeChildSize(Control control, int wHint, int hHint, boolean flushCache) {
93 Object data = control.getLayoutData();
94 if (data == null || !(data instanceof CLayoutData)) {
95 data = new CLayoutData();
96 control.setLayoutData(data);
98 return ((CLayoutData)data).computeSize(control, wHint, hHint, flushCache);
100 int computeTrim(Control c) {
101 if (c instanceof Scrollable) {
102 Rectangle rect = ((Scrollable) c).computeTrim (0, 0, 0, 0);
105 return c.getBorderWidth () * 2;
108 protected boolean flushCache(Control control) {
109 Object data = control.getLayoutData();
110 if (data != null && data instanceof CLayoutData) ((CLayoutData)data).flushCache();
114 protected void layout(Composite composite, boolean flushCache) {
115 CBanner banner = (CBanner)composite;
116 Control left = banner.left;
117 Control right = banner.right;
118 Control bottom = banner.bottom;
120 Point size = banner.getSize();
121 boolean showCurve = left != null && right != null;
122 int width = size.x - 2*banner.getBorderWidth();
123 int height = size.y - 2*banner.getBorderWidth();
125 Point bottomSize = new Point(0, 0);
126 if (bottom != null) {
127 int trim = computeTrim(bottom);
128 int w = Math.max(0, width - trim);
129 bottomSize = computeChildSize(bottom, w, SWT.DEFAULT, flushCache);
130 height -= bottomSize.y + CBanner.BORDER_STRIPE + 2;
132 if (showCurve) height -= CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2*CBanner.BORDER_STRIPE;
133 height = Math.max(0, height);
134 Point rightSize = new Point(0,0);
136 int trim = computeTrim(right);
138 if (banner.rightWidth != SWT.DEFAULT) {
139 w = banner.rightWidth - trim;
141 w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim);
145 rightSize = computeChildSize(right, w, SWT.DEFAULT, flushCache);
146 width = width - (rightSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent);
148 Point leftSize = new Point(0, 0);
150 int trim = computeTrim(left);
151 int w = Math.max(0, width - trim);
152 leftSize = computeChildSize(left, w, SWT.DEFAULT, flushCache);
157 int oldStart = banner.curveStart;
158 Rectangle leftRect = null;
159 Rectangle rightRect = null;
160 Rectangle bottomRect = null;
161 if (bottom != null) {
162 bottomRect = new Rectangle(x, y+size.y-bottomSize.y, bottomSize.x, bottomSize.y);
164 if (showCurve) y += CBanner.BORDER_TOP + CBanner.BORDER_STRIPE;
166 leftRect = new Rectangle(x, y, leftSize.x, leftSize.y);
167 banner.curveStart = x + leftSize.x - banner.curve_indent;
168 x += leftSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent;
172 rightSize.y = Math.max(leftSize.y, banner.rightMinHeight == SWT.DEFAULT ? rightSize.y : banner.rightMinHeight);
174 rightRect = new Rectangle(x, y, rightSize.x, rightSize.y);
176 if (banner.curveStart < oldStart) {
177 banner.redraw(banner.curveStart - CBanner.CURVE_TAIL, 0, oldStart + banner.curve_width - banner.curveStart + CBanner.CURVE_TAIL + 5, size.y, false);
179 if (banner.curveStart > oldStart) {
180 banner.redraw(oldStart - CBanner.CURVE_TAIL, 0, banner.curveStart + banner.curve_width - oldStart + CBanner.CURVE_TAIL + 5, size.y, false);
183 * The paint events must be flushed in order to make the curve draw smoothly
184 * while the user drags the divider.
185 * On Windows, it is necessary to flush the paints before the children are
186 * resized because otherwise the children (particularly toolbars) will flash.
189 banner.curveRect = new Rectangle(banner.curveStart, 0, banner.curve_width, size.y);
190 if (bottomRect != null) bottom.setBounds(bottomRect);
191 if (rightRect != null) right.setBounds(rightRect);
192 if (leftRect != null) left.setBounds(leftRect);