Skip to content

Commit 7581565

Browse files
Merge pull request #92 from summer-alice/update_custom_cTabFolder
Start update of CTabFolder to 4.7.3
2 parents 7772b33 + 1292328 commit 7581565

File tree

10 files changed

+926
-5061
lines changed

10 files changed

+926
-5061
lines changed

org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/SWT.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ version(Tango){
6060
*/
6161
public class SWT {
6262

63+
/**
64+
* MenuDetect event detail value indicating that a context menu
65+
* was requested by a keyboard or other focus-based device (value is 1).
66+
*
67+
* @since 3.8
68+
*/
69+
public static const int MENU_KEYBOARD = 1;
70+
6371
/* Widget Event Constants */
6472

6573
/**

org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/custom/CTabFolderLayout.d

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2005 IBM Corporation and others.
2+
* Copyright (c) 2000, 2012 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
99
* IBM Corporation - initial API and implementation
1010
* Port to the D programming language:
1111
* Frank Benoit <[email protected]>
12+
1213
*******************************************************************************/
1314
module org.eclipse.swt.custom.CTabFolderLayout;
1415

@@ -22,36 +23,76 @@ import org.eclipse.swt.widgets.Control;
2223
import org.eclipse.swt.widgets.Layout;
2324
import org.eclipse.swt.custom.CTabFolder;
2425
import org.eclipse.swt.custom.CTabItem;
26+
import org.eclipse.swt.custom.CTabFolderRenderer;
2527

2628
/**
2729
* This class provides the layout for CTabFolder
2830
*
2931
* @see CTabFolder
3032
*/
3133
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) {
3338
CTabFolder folder = cast(CTabFolder)composite;
3439
CTabItem[] items = folder.items;
40+
CTabFolderRenderer renderer = folder.renderer;
3541
// preferred width of tab area to show all tabs
3642
int tabW = 0;
43+
int selectedIndex = folder.selectedIndex;
44+
if (selectedIndex == -1) selectedIndex = 0;
3745
GC gc = new GC(folder);
3846
for (int i = 0; i < items.length; i++) {
3947
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);
4149
} 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;
4353
}
4454
}
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+
}+/
5390
}
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();
5596

5697
int controlW = 0;
5798
int controlH = 0;
@@ -65,8 +106,8 @@ protected override Point computeSize(Composite composite, int wHint, int hHint,
65106
}
66107
}
67108

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;
70111
if (minWidth is 0) minWidth = CTabFolder.DEFAULT_WIDTH;
71112
if (minHeight is 0) minHeight = CTabFolder.DEFAULT_HEIGHT;
72113

@@ -75,14 +116,16 @@ protected override Point computeSize(Composite composite, int wHint, int hHint,
75116

76117
return new Point (minWidth, minHeight);
77118
}
78-
protected override bool flushCache(Control control) {
119+
override
120+
protected bool flushCache(Control control) {
79121
return true;
80122
}
81-
protected override void layout(Composite composite, bool flushCache) {
123+
override
124+
protected void layout(Composite composite, bool flushCache) {
82125
CTabFolder folder = cast(CTabFolder)composite;
83126
// resize content
84127
if (folder.selectedIndex !is -1) {
85-
Control control = folder.items[folder.selectedIndex].getControl();
128+
Control control = folder.items[folder.selectedIndex].control;
86129
if (control !is null && !control.isDisposed()) {
87130
control.setBounds(folder.getClientArea());
88131
}

org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/custom/CTabItem.d

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,11 @@ public class CTabItem : Item {
7171
Image disabledImage;
7272

7373
Rectangle closeRect;
74-
int closeImageState = CTabFolder.NONE;
74+
int closeImageState = SWT.BACKGROUND;
75+
int state = SWT.NONE;
7576
bool showClose = false;
7677
bool showing = false;
7778

78-
// internal constants
79-
static const int TOP_MARGIN = 2;
80-
static const int BOTTOM_MARGIN = 2;
81-
static const int LEFT_MARGIN = 4;
82-
static const int RIGHT_MARGIN = 4;
83-
static const int INTERNAL_SPACING = 4;
84-
static const int FLAGS = SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC;
85-
static const String ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026"
86-
8779
/**
8880
* Constructs a new instance of this class given its parent
8981
* (which must be a <code>CTabFolder</code>) and a style value
@@ -158,7 +150,7 @@ public this (CTabFolder parent, int style, int index) {
158150
bool useEllipses() {
159151
return parent.simple;
160152
}
161-
153+
/+
162154
String shortenText(GC gc, String text, int width) {
163155
return useEllipses()
164156
? shortenText(gc, text, width, ELLIPSIS)
@@ -182,7 +174,7 @@ String shortenText(GC gc, String text, int width, String ellipses) {
182174
}
183175
layout.dispose();
184176
return end is 0 ? .toString(toString32(text)[0 .. 1]) : text ~ ellipses;
185-
}
177+
}+/
186178

187179
public override void dispose() {
188180
if (isDisposed ()) return;
@@ -195,6 +187,7 @@ public override void dispose() {
195187
shortenedText = null;
196188
font = null;
197189
}
190+
/+
198191
void drawClose(GC gc) {
199192
if (closeRect.width is 0 || closeRect.height is 0) return;
200193
Display display = getDisplay();
@@ -700,7 +693,8 @@ void drawUnselected(GC gc) {
700693
}
701694
// draw close
702695
if (parent.showUnselectedClose && (parent.showClose || showClose)) drawClose(gc);
703-
}
696+
}+/
697+
704698
/**
705699
* Returns a rectangle describing the receiver's size and location
706700
* relative to its parent.
@@ -714,9 +708,9 @@ void drawUnselected(GC gc) {
714708
*/
715709
public Rectangle getBounds () {
716710
//checkWidget();
717-
int w = width;
718-
if (!parent.simple && !parent.single && parent.indexOf(this) is parent.selectedIndex) w += parent.curveWidth - parent.curveIndent;
719-
return new Rectangle(x, y, w, height);
711+
// DWT: Port CTabFolder.runUpdate
712+
// parent.runUpdate();
713+
return new Rectangle(x, y, width, height);
720714
}
721715
/**
722716
* Gets the control that is displayed in the content area of the tab item.
@@ -832,6 +826,7 @@ public bool isShowing () {
832826
checkWidget();
833827
return showing;
834828
}
829+
/+
835830
void onPaint(GC gc, bool isSelected) {
836831
if (width is 0 || height is 0) return;
837832
if (isSelected) {
@@ -898,7 +893,7 @@ int preferredWidth(GC gc, bool isSelected, bool minimum) {
898893
}
899894
}
900895
return w + LEFT_MARGIN + RIGHT_MARGIN;
901-
}
896+
}+/
902897
/**
903898
* Sets the control that is used to fill the client area of
904899
* the tab folder when the user selects the tab item.
@@ -984,49 +979,18 @@ public void setFont (Font font){
984979
parent.redrawTabs();
985980
}
986981
}
987-
public override void setImage (Image image) {
982+
override
983+
public void setImage (Image image) {
988984
checkWidget();
989985
if (image !is null && image.isDisposed ()) {
990986
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
991987
}
992988
Image oldImage = getImage();
993989
if (image is null && oldImage is null) return;
994-
if (image !is null && image==oldImage) return;
990+
if (image !is null && image == oldImage) return;
995991
super.setImage(image);
996-
if (!parent.updateTabHeight(false)) {
997-
// If image is the same size as before,
998-
// redraw only the image
999-
if (oldImage !is null && image !is null) {
1000-
Rectangle oldBounds = oldImage.getBounds();
1001-
Rectangle bounds = image.getBounds();
1002-
if (bounds.width is oldBounds.width && bounds.height is oldBounds.height) {
1003-
if (showing) {
1004-
bool selected = parent.indexOf(this) is parent.selectedIndex;
1005-
if (selected || parent.showUnselectedImage) {
1006-
int imageX = x + LEFT_MARGIN, maxImageWidth;
1007-
if (selected) {
1008-
if (parent.single && (parent.showClose || showClose)) imageX += CTabFolder.BUTTON_SIZE;
1009-
int rightEdge = Math.min (x + width, parent.getRightItemEdge());
1010-
maxImageWidth = rightEdge - imageX - RIGHT_MARGIN;
1011-
if (!parent.single && closeRect.width > 0) maxImageWidth -= closeRect.width + INTERNAL_SPACING;
1012-
} else {
1013-
maxImageWidth = x + width - imageX - RIGHT_MARGIN;
1014-
if (parent.showUnselectedClose && (parent.showClose || showClose)) {
1015-
maxImageWidth -= closeRect.width + INTERNAL_SPACING;
1016-
}
1017-
}
1018-
if (bounds.width < maxImageWidth) {
1019-
int imageY = y + (height - bounds.height) / 2 + (parent.onBottom ? -1 : 1);
1020-
parent.redraw(imageX, imageY, bounds.width, bounds.height, false);
1021-
}
1022-
}
1023-
}
1024-
return;
1025-
}
1026-
}
1027-
parent.updateItems();
1028-
parent.redrawTabs();
1029-
}
992+
// DWT: Port CTabFolder.updateFolder
993+
// parent.updateFolder(CTabFolder.UPDATE_TAB_HEIGHT | CTabFolder.REDRAW_TABS);
1030994
}
1031995
/**
1032996
* Sets to <code>true</code> to indicate that the receiver's close button should be shown.

org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/SWT.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ import java.lang.all;
5353
*/
5454
public class SWT {
5555

56+
/**
57+
* MenuDetect event detail value indicating that a context menu
58+
* was requested by a keyboard or other focus-based device (value is 1).
59+
*
60+
* @since 3.8
61+
*/
62+
public static const int MENU_KEYBOARD = 1;
63+
5664
/* Widget Event Constants */
5765

5866
/**

0 commit comments

Comments
 (0)