1
1
/* ******************************************************************************
2
- * Copyright (c) 2000, 2005 IBM Corporation and others.
2
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
3
3
* All rights reserved. This program and the accompanying materials
4
4
* are made available under the terms of the Eclipse Public License v1.0
5
5
* which accompanies this distribution, and is available at
9
9
* IBM Corporation - initial API and implementation
10
10
* Port to the D programming language:
11
11
* Frank Benoit <[email protected] >
12
+
12
13
*******************************************************************************/
13
14
module org.eclipse.swt.custom.CTabFolderLayout ;
14
15
@@ -22,36 +23,76 @@ import org.eclipse.swt.widgets.Control;
22
23
import org.eclipse.swt.widgets.Layout ;
23
24
import org.eclipse.swt.custom.CTabFolder;
24
25
import org.eclipse.swt.custom.CTabItem;
26
+ import org.eclipse.swt.custom.CTabFolderRenderer;
25
27
26
28
/**
27
29
* This class provides the layout for CTabFolder
28
30
*
29
31
* @see CTabFolder
30
32
*/
31
33
class CTabFolderLayout : Layout {
32
- protected override Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) {
34
+ package (org.eclipse.swt.custom):
35
+
36
+ override
37
+ protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) {
33
38
CTabFolder folder = cast (CTabFolder)composite;
34
39
CTabItem[] items = folder.items;
40
+ CTabFolderRenderer renderer = folder.renderer;
35
41
// preferred width of tab area to show all tabs
36
42
int tabW = 0 ;
43
+ int selectedIndex = folder.selectedIndex;
44
+ if (selectedIndex == - 1 ) selectedIndex = 0 ;
37
45
GC gc = new GC (folder);
38
46
for (int i = 0 ; i < items.length; i++ ) {
39
47
if (folder.single) {
40
- tabW = Math.max(tabW, items[i].preferredWidth( gc, true , false ) );
48
+ tabW = Math.max(tabW, renderer.computeSize(i, SWT . SELECTED , gc, SWT . DEFAULT , SWT . DEFAULT ).x );
41
49
} else {
42
- tabW += items[i].preferredWidth(gc, i is folder.selectedIndex, false );
50
+ int state = 0 ;
51
+ if (i == selectedIndex) state |= SWT .SELECTED ;
52
+ tabW += renderer.computeSize(i, state, gc, SWT .DEFAULT , SWT .DEFAULT ).x;
43
53
}
44
54
}
45
- gc.dispose();
46
- tabW += 3 ;
47
- if (folder.showMax) tabW += CTabFolder.BUTTON_SIZE ;
48
- if (folder.showMin) tabW += CTabFolder.BUTTON_SIZE ;
49
- if (folder.single) tabW += 3 * CTabFolder.BUTTON_SIZE / 2 ; // chevron
50
- if (folder.topRight ! is null ) {
51
- Point pt = folder.topRight.computeSize(SWT .DEFAULT , folder.tabHeight, flushCache);
52
- tabW += 3 + pt.x;
55
+
56
+ int width = 0 , wrapHeight = 0 ;
57
+ bool leftControl = false , rightControl = false ;
58
+ if (wHint == SWT .DEFAULT ) {
59
+ for (int i = 0 ; i < folder.controls.length; i++ ) {
60
+ Control control = folder.controls[i];
61
+ if (! control.isDisposed() && control.getVisible()) {
62
+ if ((folder.controlAlignments[i] & SWT .LEAD ) != 0 ) {
63
+ leftControl = true ;
64
+ } else {
65
+ rightControl = true ;
66
+ }
67
+ width += control.computeSize(SWT .DEFAULT , SWT .DEFAULT ).x;
68
+ }
69
+ }
70
+ } else {
71
+ Point size = new Point (wHint, hHint);
72
+ bool [][] positions;
73
+ /+ DWT: Port CTabFolder.computeControlBounds(Point, bool[][])
74
+ // Rectangle[] rects = folder.computeControlBounds(size, positions);
75
+ int minY = Integer.MAX_VALUE, maxY = 0;
76
+ for (int i = 0; i < rects.length; i++) {
77
+ if (positions[0][i]) {
78
+ minY = Math.min(minY, rects[i].y);
79
+ maxY = Math.max(maxY, rects[i].y + rects[i].height);
80
+ wrapHeight = maxY - minY;
81
+ } else {
82
+ if ((folder.controlAlignments[i] & SWT.LEAD) != 0) {
83
+ leftControl = true;
84
+ } else {
85
+ rightControl = true;
86
+ }
87
+ width += rects[i].width;
88
+ }
89
+ }+/
53
90
}
54
- if (! folder.single && ! folder.simple) tabW += folder.curveWidth - 2 * folder.curveIndent;
91
+ if (leftControl) width += CTabFolder.SPACING * 2 ;
92
+ if (rightControl) width += CTabFolder.SPACING * 2 ;
93
+ tabW += width;
94
+
95
+ gc.dispose();
55
96
56
97
int controlW = 0 ;
57
98
int controlH = 0 ;
@@ -65,8 +106,8 @@ protected override Point computeSize(Composite composite, int wHint, int hHint,
65
106
}
66
107
}
67
108
68
- int minWidth = Math.max(tabW, controlW);
69
- int minHeight = (folder.minimized) ? 0 : controlH;
109
+ int minWidth = Math.max(tabW, controlW + folder.marginWidth );
110
+ int minHeight = (folder.minimized) ? 0 : controlH + wrapHeight ;
70
111
if (minWidth is 0 ) minWidth = CTabFolder.DEFAULT_WIDTH ;
71
112
if (minHeight is 0 ) minHeight = CTabFolder.DEFAULT_HEIGHT ;
72
113
@@ -75,14 +116,16 @@ protected override Point computeSize(Composite composite, int wHint, int hHint,
75
116
76
117
return new Point (minWidth, minHeight);
77
118
}
78
- protected override bool flushCache (Control control) {
119
+ override
120
+ protected bool flushCache (Control control) {
79
121
return true ;
80
122
}
81
- protected override void layout (Composite composite, bool flushCache) {
123
+ override
124
+ protected void layout (Composite composite, bool flushCache) {
82
125
CTabFolder folder = cast (CTabFolder)composite;
83
126
// resize content
84
127
if (folder.selectedIndex ! is - 1 ) {
85
- Control control = folder.items[folder.selectedIndex].getControl() ;
128
+ Control control = folder.items[folder.selectedIndex].control ;
86
129
if (control ! is null && ! control.isDisposed()) {
87
130
control.setBounds(folder.getClientArea());
88
131
}
0 commit comments