]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/custom/CBannerLayout.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / custom / CBannerLayout.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  *
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/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.custom;
15
16 import org.eclipse.swt.*;
17 import org.eclipse.swt.graphics.*;
18 import org.eclipse.swt.widgets.*;
19
20 /**
21  * This class provides the layout for CBanner
22  *
23  * @see CBanner
24  */
25 class CBannerLayout extends Layout {
26
27 @Override
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;
34         int height = hHint;
35         int width = wHint;
36
37         // Calculate component sizes
38         Point bottomSize = new Point(0, 0);
39         if (bottom != null) {
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);
43         }
44         Point rightSize = new Point(0, 0);
45         if (right != null) {
46                 int trim = computeTrim(right);
47                 int w = SWT.DEFAULT;
48                 if (banner.rightWidth != SWT.DEFAULT) {
49                         w = banner.rightWidth - trim;
50                         if (left != null) {
51                                 w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim);
52                         }
53                         w = Math.max(0, w);
54                 }
55                 rightSize = computeChildSize(right, w, SWT.DEFAULT, flushCache);
56                 if (wHint != SWT.DEFAULT) {
57                         width -= rightSize.x + banner.curve_width - 2* banner.curve_indent;
58                 }
59         }
60         Point leftSize = new Point(0, 0);
61         if (left != null) {
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);
65         }
66
67         // Add up sizes
68         width = leftSize.x + rightSize.x;
69         height = bottomSize.y;
70         if (bottom != null && (left != null || right != null)) {
71                 height += CBanner.BORDER_STRIPE + 2;
72         }
73         if (left != null) {
74                 if (right == null) {
75                         height += leftSize.y;
76                 } else {
77                         height += Math.max(leftSize.y, banner.rightMinHeight == SWT.DEFAULT ? rightSize.y : banner.rightMinHeight);
78                 }
79         } else {
80                 height += rightSize.y;
81         }
82         if (showCurve) {
83                 width += banner.curve_width - 2*banner.curve_indent;
84                 height +=  CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2*CBanner.BORDER_STRIPE;
85         }
86
87         if (wHint != SWT.DEFAULT) width = wHint;
88         if (hHint != SWT.DEFAULT) height = hHint;
89
90         return new Point(width, height);
91 }
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);
97         }
98         return ((CLayoutData)data).computeSize(control, wHint, hHint, flushCache);
99 }
100 int computeTrim(Control c) {
101         if (c instanceof Scrollable) {
102                 Rectangle rect = ((Scrollable) c).computeTrim (0, 0, 0, 0);
103                 return rect.width;
104         }
105         return c.getBorderWidth () * 2;
106 }
107 @Override
108 protected boolean flushCache(Control control) {
109         Object data = control.getLayoutData();
110         if (data != null && data instanceof CLayoutData) ((CLayoutData)data).flushCache();
111         return true;
112 }
113 @Override
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;
119
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();
124
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;
131         }
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);
135         if (right != null) {
136                 int trim = computeTrim(right);
137                 int w = SWT.DEFAULT;
138                 if (banner.rightWidth != SWT.DEFAULT) {
139                         w = banner.rightWidth - trim;
140                         if (left != null) {
141                                 w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim);
142                         }
143                         w = Math.max(0, w);
144                 }
145                 rightSize = computeChildSize(right, w, SWT.DEFAULT, flushCache);
146                 width = width - (rightSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent);
147         }
148         Point leftSize = new Point(0, 0);
149         if (left != null) {
150                 int trim = computeTrim(left);
151                 int w = Math.max(0, width - trim);
152                 leftSize = computeChildSize(left, w, SWT.DEFAULT, flushCache);
153         }
154
155         int x = 0;
156         int y = 0;
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);
163         }
164         if (showCurve) y += CBanner.BORDER_TOP + CBanner.BORDER_STRIPE;
165         if(left != null) {
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;
169         }
170         if (right != null) {
171                 if (left != null) {
172                         rightSize.y = Math.max(leftSize.y, banner.rightMinHeight == SWT.DEFAULT ? rightSize.y : banner.rightMinHeight);
173                 }
174                 rightRect = new Rectangle(x, y, rightSize.x, rightSize.y);
175         }
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);
178         }
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);
181         }
182         /*
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.
187          */
188         banner.update();
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);
193 }
194 }