1 /*******************************************************************************
2  * Copyright (c) 2005 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 class CLayoutData {
21 
22 	int defaultWidth = -1, defaultHeight = -1;
23 	int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
24 
computeSize(Control control, int wHint, int hHint, boolean flushCache)25 Point computeSize (Control control, int wHint, int hHint, boolean flushCache) {
26 	if (flushCache) flushCache();
27 	if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
28 		if (defaultWidth == -1 || defaultHeight == -1) {
29 			Point size = control.computeSize (wHint, hHint, flushCache);
30 			defaultWidth = size.x;
31 			defaultHeight = size.y;
32 		}
33 		return new Point(defaultWidth, defaultHeight);
34 	}
35 	if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) {
36 		Point size = control.computeSize (wHint, hHint, flushCache);
37 		currentWhint = wHint;
38 		currentHhint = hHint;
39 		currentWidth = size.x;
40 		currentHeight = size.y;
41 	}
42 	return new Point(currentWidth, currentHeight);
43 }
flushCache()44 void flushCache () {
45 	defaultWidth = defaultHeight = -1;
46 	currentWidth = currentHeight = -1;
47 }
48 }
49