update source for tizen_2.1
[sdk/emulator/qemu.git] / tizen / src / skin / client / src / org / tizen / emulator / skin / custom / CustomScrolledCompositeLayout.java
1 /**
2  *
3  *
4  * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  * GiWoong Kim <giwoong.kim@samsung.com>
8  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
9  *
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.
14  *
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.
19  *
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.
23  *
24  * Contributors:
25  * - S-Core Co., Ltd
26  *
27  */
28
29 package org.tizen.emulator.skin.custom;
30
31 import java.util.logging.Logger;
32
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;
40
41 class ScrolledCompositeLayout extends Layout {
42         static final int DEFAULT_WIDTH = 64;
43         static final int DEFAULT_HEIGHT = 64;
44
45         private Logger logger = SkinLogger.getSkinLogger(
46                         ScrolledCompositeLayout.class).getLogger();
47
48         private boolean inLayout = false;
49
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);
53
54                 if (sc.content != null) {
55                         Point preferredSize = sc.content.computeSize(wHint, hHint, flushCache);
56                         size.x = preferredSize.x;
57                         size.y = preferredSize.y;
58                 }
59                 size.x = Math.max(size.x, sc.minWidth);
60                 size.y = Math.max(size.y, sc.minHeight);
61
62                 if (wHint != SWT.DEFAULT) size.x = wHint;
63                 if (hHint != SWT.DEFAULT) size.y = hHint;
64
65                 return size;
66         }
67
68         protected boolean flushCache(Control control) {
69                 return true;
70         }
71
72         protected void layout(Composite composite, boolean flushCache) {
73                 if (inLayout) {
74                         return;
75                 }
76
77                 CustomScrolledComposite sc = (CustomScrolledComposite)composite;
78                 if (sc.content == null) {
79                         return;
80                 }
81
82                 inLayout = true;
83                 Rectangle contentRect = sc.content.getBounds();
84
85                 Rectangle hostRect = sc.getClientArea();
86                 if (sc.expandHorizontal) {
87                         contentRect.width = Math.max(sc.minWidth, hostRect.width);
88                 }
89                 if (sc.expandVertical) {
90                         contentRect.height = Math.max(sc.minHeight, hostRect.height);
91                 }
92
93                 sc.content.setBounds(contentRect);
94
95                 Point size = sc.compositeRight.computeSize(SWT.DEFAULT, SWT.DEFAULT);
96                 sc.compositeRight.setBounds(
97                                 contentRect.width - size.x, 0, size.x, contentRect.height);
98
99                 inLayout = false;
100         }
101 }