Mercurial > projects > dwt-mac
comparison dwt/custom/CTabFolderLayout.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | f565d3a95c0a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * | |
11 * Port to the D Programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
13 *******************************************************************************/ | |
14 module dwt.custom.CTabFolderLayout; | |
15 | |
16 import Math = tango.math.Math; | |
17 | |
18 import dwt.DWT; | |
19 import dwt.custom.CTabFolder; | |
20 import dwt.custom.CTabItem; | |
21 import dwt.graphics.GC; | |
22 import dwt.graphics.Point; | |
23 import dwt.widgets.Composite; | |
24 import dwt.widgets.Control; | |
25 import dwt.widgets.Layout; | |
26 | |
27 /** | |
28 * This class provides the layout for CTabFolder | |
29 * | |
30 * @see CTabFolder | |
31 */ | |
32 class CTabFolderLayout : Layout { | |
33 protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) { | |
34 CTabFolder folder = cast(CTabFolder) composite; | |
35 CTabItem[] items = folder.items; | |
36 // preferred width of tab area to show all tabs | |
37 int tabW = 0; | |
38 GC gc = new GC(folder); | |
39 for (int i = 0; i < items.length; i++) { | |
40 if (folder.single) { | |
41 tabW = Math.max(tabW, items[i].preferredWidth(gc, true, false)); | |
42 } | |
43 else { | |
44 tabW += items[i].preferredWidth(gc, i is folder.selectedIndex, false); | |
45 } | |
46 } | |
47 gc.dispose(); | |
48 tabW += 3; | |
49 if (folder.showMax) | |
50 tabW += CTabFolder.BUTTON_SIZE; | |
51 if (folder.showMin) | |
52 tabW += CTabFolder.BUTTON_SIZE; | |
53 if (folder.single) | |
54 tabW += 3 * CTabFolder.BUTTON_SIZE / 2; //chevron | |
55 if (folder.topRight !is null) { | |
56 Point pt = folder.topRight.computeSize(DWT.DEFAULT, folder.tabHeight, flushCache); | |
57 tabW += 3 + pt.x; | |
58 } | |
59 if (!folder.single && !folder.simple) | |
60 tabW += folder.curveWidth - 2 * folder.curveIndent; | |
61 | |
62 int controlW = 0; | |
63 int controlH = 0; | |
64 // preferred size of controls in tab items | |
65 for (int i = 0; i < items.length; i++) { | |
66 Control control = items[i].getControl(); | |
67 if (control !is null && !control.isDisposed()) { | |
68 Point size = control.computeSize(wHint, hHint, flushCache); | |
69 controlW = Math.max(controlW, size.x); | |
70 controlH = Math.max(controlH, size.y); | |
71 } | |
72 } | |
73 | |
74 int minWidth = Math.max(tabW, controlW); | |
75 int minHeight = (folder.minimized) ? 0 : controlH; | |
76 if (minWidth is 0) | |
77 minWidth = CTabFolder.DEFAULT_WIDTH; | |
78 if (minHeight is 0) | |
79 minHeight = CTabFolder.DEFAULT_HEIGHT; | |
80 | |
81 if (wHint !is DWT.DEFAULT) | |
82 minWidth = wHint; | |
83 if (hHint !is DWT.DEFAULT) | |
84 minHeight = hHint; | |
85 | |
86 return new Point(minWidth, minHeight); | |
87 } | |
88 | |
89 protected bool flushCache (Control control) { | |
90 return true; | |
91 } | |
92 | |
93 protected void layout (Composite composite, bool flushCache) { | |
94 CTabFolder folder = cast(CTabFolder) composite; | |
95 // resize content | |
96 if (folder.selectedIndex !is -1) { | |
97 Control control = folder.items[folder.selectedIndex].getControl(); | |
98 if (control !is null && !control.isDisposed()) { | |
99 control.setBounds(folder.getClientArea()); | |
100 } | |
101 } | |
102 } | |
103 } |