]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/custom/ViewFormLayout.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / custom / ViewFormLayout.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2009 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 ViewForm
22  *
23  * @see ViewForm
24  */
25 class ViewFormLayout extends Layout {
26
27 @Override
28 protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
29         ViewForm form = (ViewForm)composite;
30         Control left = form.topLeft;
31         Control center = form.topCenter;
32         Control right = form.topRight;
33         Control content = form.content;
34
35         Point leftSize = new Point(0, 0);
36         if (left != null) {
37                 leftSize = computeChildSize(left, SWT.DEFAULT, SWT.DEFAULT, flushCache);
38         }
39         Point centerSize = new Point(0, 0);
40         if (center != null) {
41                 centerSize = computeChildSize(center, SWT.DEFAULT, SWT.DEFAULT, flushCache);
42         }
43         Point rightSize = new Point(0, 0);
44         if (right != null) {
45                 rightSize = computeChildSize(right, SWT.DEFAULT, SWT.DEFAULT, flushCache);
46         }
47         Point size = new Point(0, 0);
48         // calculate width of title bar
49         if (form.separateTopCenter ||
50                 (wHint != SWT.DEFAULT &&  leftSize.x + centerSize.x + rightSize.x > wHint)) {
51                 size.x = leftSize.x + rightSize.x;
52                 if (leftSize.x > 0 && rightSize.x > 0) size.x += form.horizontalSpacing;
53                 size.x = Math.max(centerSize.x, size.x);
54                 size.y = Math.max(leftSize.y, rightSize.y);
55                 if (center != null){
56                         size.y += centerSize.y;
57                         if (left != null ||right != null)size.y += form.verticalSpacing;
58                 }
59         } else {
60                 size.x = leftSize.x + centerSize.x + rightSize.x;
61                 int count = -1;
62                 if (leftSize.x > 0) count++;
63                 if (centerSize.x > 0) count++;
64                 if (rightSize.x > 0) count++;
65                 if (count > 0) size.x += count * form.horizontalSpacing;
66                 size.y = Math.max(leftSize.y, Math.max(centerSize.y, rightSize.y));
67         }
68
69         if (content != null) {
70                 if (left != null || right != null || center != null) size.y += 1; // allow space for a vertical separator
71                 Point contentSize = new Point(0, 0);
72                 contentSize = computeChildSize(content, SWT.DEFAULT, SWT.DEFAULT, flushCache);
73                 size.x = Math.max (size.x, contentSize.x);
74                 size.y += contentSize.y;
75                 if (size.y > contentSize.y) size.y += form.verticalSpacing;
76         }
77
78         size.x += 2*form.marginWidth;
79         size.y += 2*form.marginHeight;
80
81         if (wHint != SWT.DEFAULT) size.x  = wHint;
82         if (hHint != SWT.DEFAULT) size.y = hHint;
83
84         return size;
85 }
86
87 Point computeChildSize(Control control, int wHint, int hHint, boolean flushCache) {
88         Object data = control.getLayoutData();
89         if (data == null || !(data instanceof CLayoutData)) {
90                 data = new CLayoutData();
91                 control.setLayoutData(data);
92         }
93         return ((CLayoutData)data).computeSize(control, wHint, hHint, flushCache);
94 }
95
96 int computeTrim(Control c) {
97         if (c instanceof Scrollable) {
98                 Rectangle rect = ((Scrollable) c).computeTrim (0, 0, 0, 0);
99                 return rect.width;
100         }
101         return c.getBorderWidth () * 2;
102 }
103
104 @Override
105 protected boolean flushCache(Control control) {
106         Object data = control.getLayoutData();
107         if (data != null && data instanceof CLayoutData) ((CLayoutData)data).flushCache();
108         return true;
109 }
110
111 @Override
112 protected void layout(Composite composite, boolean flushCache) {
113         ViewForm form = (ViewForm)composite;
114         Control left = form.topLeft;
115         Control center = form.topCenter;
116         Control right = form.topRight;
117         Control content = form.content;
118
119         Rectangle rect = composite.getClientArea();
120
121         Point leftSize = new Point(0, 0);
122         if (left != null && !left.isDisposed()) {
123                 leftSize = computeChildSize(left, SWT.DEFAULT, SWT.DEFAULT, flushCache);
124         }
125         Point centerSize = new Point(0, 0);
126         if (center != null && !center.isDisposed()) {
127                 centerSize = computeChildSize(center, SWT.DEFAULT, SWT.DEFAULT, flushCache);
128         }
129         Point rightSize = new Point(0, 0);
130         if (right != null && !right.isDisposed()) {
131                 rightSize = computeChildSize(right, SWT.DEFAULT, SWT.DEFAULT, flushCache);
132         }
133
134         int minTopWidth = leftSize.x + centerSize.x + rightSize.x + 2*form.marginWidth + 2*form.highlight;
135         int count = -1;
136         if (leftSize.x > 0) count++;
137         if (centerSize.x > 0) count++;
138         if (rightSize.x > 0) count++;
139         if (count > 0) minTopWidth += count * form.horizontalSpacing;
140
141         int x = rect.x + rect.width - form.marginWidth - form.highlight;
142         int y = rect.y + form.marginHeight + form.highlight;
143
144         boolean top = false;
145         if (form.separateTopCenter || minTopWidth > rect.width) {
146                 int topHeight = Math.max(rightSize.y, leftSize.y);
147                 if (right != null && !right.isDisposed()) {
148                         top = true;
149                         x -= rightSize.x;
150                         right.setBounds(x, y, rightSize.x, topHeight);
151                         x -= form.horizontalSpacing;
152                 }
153                 if (left != null && !left.isDisposed()) {
154                         top = true;
155                         int trim = computeTrim(left);
156                         int leftW = x - rect.x - form.marginWidth - form.highlight - trim;
157                         leftSize = computeChildSize(left, leftW, SWT.DEFAULT, false);
158                         left.setBounds(rect.x + form.marginWidth + form.highlight, y, leftSize.x, topHeight);
159                 }
160                 if (top) y += topHeight + form.verticalSpacing;
161                 if (center != null && !center.isDisposed()) {
162                         top = true;
163                         int trim = computeTrim(center);
164                         int w = rect.width - 2*form.marginWidth - 2*form.highlight - trim;
165                         Point size = computeChildSize(center, w, SWT.DEFAULT, false);
166                         if (size.x < centerSize.x) {
167                                 centerSize = size;
168                         }
169                         center.setBounds(rect.x + rect.width - form.marginWidth - form.highlight - centerSize.x, y, centerSize.x, centerSize.y);
170                         y += centerSize.y + form.verticalSpacing;
171                 }
172         } else {
173                 int topHeight = Math.max(rightSize.y, Math.max(centerSize.y, leftSize.y));
174                 if (right != null && !right.isDisposed()) {
175                         top = true;
176                         x -= rightSize.x;
177                         right.setBounds(x, y, rightSize.x, topHeight);
178                         x -= form.horizontalSpacing;
179                 }
180                 if (center != null && !center.isDisposed()) {
181                         top = true;
182                         x -= centerSize.x;
183                         center.setBounds(x, y, centerSize.x, topHeight);
184                         x -= form.horizontalSpacing;
185                 }
186                 if (left != null && !left.isDisposed()) {
187                         top = true;
188                         Rectangle trim = left instanceof Composite ? ((Composite)left).computeTrim(0, 0, 0, 0) : new Rectangle(0, 0, 0, 0);
189                         int w = x - rect.x - form.marginWidth - form.highlight - trim.width;
190                         int h = topHeight - trim.height;
191                         leftSize = computeChildSize(left, w, h, false);
192                         left.setBounds(rect.x + form.marginWidth + form.highlight, y, leftSize.x, topHeight);
193                 }
194                 if (top)y += topHeight + form.verticalSpacing;
195         }
196         int oldSeperator = form.separator;
197         form.separator = -1;
198         if (content != null && !content.isDisposed()) {
199                 if (left != null || right!= null || center != null){
200                         form.separator = y;
201                         y++;
202                 }
203                 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);
204         }
205         if (oldSeperator != form.separator) {
206                 int t, b;
207                 if (oldSeperator == -1) {
208                         t = form.separator;
209                         b = form.separator + 1;
210                 } else if (form.separator == -1) {
211                         t = oldSeperator;
212                         b = oldSeperator + 1;
213                 } else {
214                         t = Math.min(form.separator, oldSeperator);
215                         b = Math.max(form.separator, oldSeperator);
216                 }
217                 form.redraw(form.borderLeft, t, form.getSize().x - form.borderLeft - form.borderRight, b - t, false);
218         }
219 }
220 }