1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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.widgets;
17 import org.eclipse.swt.graphics.*;
20 * A layout controls the position and size
21 * of the children of a composite widget.
22 * This class is the abstract base class for
25 * @see Composite#setLayout(Layout)
26 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
28 public abstract class Layout {
31 * Computes and returns the size of the specified
32 * composite's client area according to this layout.
34 * This method computes the size that the client area
35 * of the composite must be in order to position all
36 * children at their preferred size inside the
37 * composite according to the layout algorithm
38 * encoded by this layout.
41 * When a width or height hint is supplied, it is
42 * used to constrain the result. For example, if a
43 * width hint is provided that is less than the
44 * width of the client area, the layout may choose
45 * to wrap and increase height, clip, overlap, or
46 * otherwise constrain the children.
49 * @param composite a composite widget using this layout
50 * @param wHint width (<code>SWT.DEFAULT</code> for preferred size)
51 * @param hHint height (<code>SWT.DEFAULT</code> for preferred size)
52 * @param flushCache <code>true</code> means flush cached layout values
53 * @return a point containing the computed size (width, height)
56 * @see Control#getBorderWidth
57 * @see Control#getBounds
58 * @see Control#getSize
59 * @see Control#pack(boolean)
60 * @see "computeTrim, getClientArea for controls that implement them"
62 protected abstract Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache);
65 * Instruct the layout to flush any cached values
66 * associated with the control specified in the argument
67 * <code>control</code>.
69 * @param control a control managed by this layout
70 * @return true if the Layout has flushed all cached information associated with control
74 protected boolean flushCache (Control control) {
79 * Lays out the children of the specified composite
80 * according to this layout.
82 * This method positions and sizes the children of a
83 * composite using the layout algorithm encoded by this
84 * layout. Children of the composite are positioned in
85 * the client area of the composite. The position of
86 * the composite is not altered by this method.
89 * When the flush cache hint is true, the layout is
90 * instructed to flush any cached values associated
91 * with the children. Typically, a layout will cache
92 * the preferred sizes of the children to avoid the
93 * expense of computing these values each time the
97 * When layout is triggered explicitly by the programmer
98 * the flush cache hint is true. When layout is triggered
99 * by a resize, either caused by the programmer or by the
100 * user, the hint is false.
103 * @param composite a composite widget using this layout
104 * @param flushCache <code>true</code> means flush cached layout values
106 protected abstract void layout (Composite composite, boolean flushCache);