4 * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
7 * GiWoong Kim <giwoong.kim@samsung.com>
8 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 package org.tizen.emulator.skin.custom;
31 import java.util.logging.Logger;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.graphics.Point;
35 import org.eclipse.swt.graphics.Rectangle;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Layout;
39 import org.tizen.emulator.skin.log.SkinLogger;
41 class ScrolledCompositeLayout extends Layout {
42 static final int DEFAULT_WIDTH = 64;
43 static final int DEFAULT_HEIGHT = 64;
45 private Logger logger = SkinLogger.getSkinLogger(
46 ScrolledCompositeLayout.class).getLogger();
48 private boolean inLayout = false;
50 protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
51 CustomScrolledComposite sc = (CustomScrolledComposite)composite;
52 Point size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
54 if (sc.content != null) {
55 Point preferredSize = sc.content.computeSize(wHint, hHint, flushCache);
56 size.x = preferredSize.x;
57 size.y = preferredSize.y;
59 size.x = Math.max(size.x, sc.minWidth);
60 size.y = Math.max(size.y, sc.minHeight);
62 if (wHint != SWT.DEFAULT) size.x = wHint;
63 if (hHint != SWT.DEFAULT) size.y = hHint;
68 protected boolean flushCache(Control control) {
72 protected void layout(Composite composite, boolean flushCache) {
77 CustomScrolledComposite sc = (CustomScrolledComposite)composite;
78 if (sc.content == null) {
83 Rectangle contentRect = sc.content.getBounds();
85 Rectangle hostRect = sc.getClientArea();
86 if (sc.expandHorizontal) {
87 contentRect.width = Math.max(sc.minWidth, hostRect.width);
89 if (sc.expandVertical) {
90 contentRect.height = Math.max(sc.minHeight, hostRect.height);
93 sc.content.setBounds(contentRect);
95 Point size = sc.compositeRight.computeSize(SWT.DEFAULT, SWT.DEFAULT);
96 sc.compositeRight.setBounds(
97 contentRect.width - size.x, 0, size.x, contentRect.height);