Skip to content

Commit 2e5cea6

Browse files
author
jossonsmith
committed
Support SWT.VERTICAL in ToolBar
Add ">>" button to CoolBar without further implementation.
1 parent d9dde7f commit 2e5cea6

File tree

5 files changed

+213
-61
lines changed

5 files changed

+213
-61
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/CoolBar.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.eclipse.swt.SWTException;
1616
import org.eclipse.swt.graphics.Point;
1717
import org.eclipse.swt.graphics.Rectangle;
18+
import org.eclipse.swt.internal.RunnableCompatibility;
1819
import org.eclipse.swt.internal.browser.OS;
1920
import org.eclipse.swt.internal.dnd.DragAdapter;
2021
import org.eclipse.swt.internal.dnd.DragAndDrop;
@@ -366,6 +367,18 @@ public boolean dragBegan(DragEvent e) {
366367
el.appendChild(document.createTextNode(">"));
367368
el.className = "cool-item-more-arrow";
368369
item.moreHandle.appendChild(el);
370+
item.moreHandle.onclick = new RunnableCompatibility() {
371+
public void run() {
372+
Event e = new Event();
373+
e.detail = SWT.ARROW;
374+
e.x = 0;
375+
e.y = 0;
376+
e.display = display;
377+
e.widget = item;
378+
e.type = SWT.Selection;
379+
item.sendEvent(e);
380+
}
381+
};
369382
}
370383

371384
el = document.createElement("DIV");
@@ -1535,8 +1548,21 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
15351548
* e.className = newClazz.join (" ");
15361549
*/ {}
15371550
}
1551+
15381552
if (item.control != null) {
1539-
item.control.setSize(w - 2 - (isLastItemOfRow(i) ? 0 : 2), bounds.height);
1553+
int ww = w - 2 - (isLastItemOfRow(i) ? 0 : 2);
1554+
boolean more = false;
1555+
if ((item.style & SWT.DROP_DOWN) != 0) {
1556+
more = item.control.computeSize(SWT.DEFAULT, bounds.height).x + 8 >= ww;
1557+
OS.updateCSSClass(item.handle, "cool-item-more-enabled", more);
1558+
}
1559+
if (more) {
1560+
item.moreHandle.style.height = (bounds.height - 6 > 0 ? bounds.height - 6 : 0) + "px";
1561+
s.width = (w - 12 > 0 ? w - 12 : 0) + "px";
1562+
item.control.setSize(ww - 8, bounds.height);
1563+
} else {
1564+
item.control.setSize(ww, bounds.height);
1565+
}
15401566
Point pt = item.getPosition();
15411567
item.control.left = pt.x + 9;
15421568
item.control.top = pt.y;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/TabItem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ protected void checkSubclass () {
126126
private void configure(final int index) {
127127
textEl.onclick = new RunnableCompatibility() {
128128
public void run() {
129-
System.out.println("hoy hoy ");
130129
parent.setSelection(index, true);
131130
}
132131
};

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/ToolBar.css

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ DIV.tool-item-default {
2424
border-color:white #666 #666 white;
2525
padding:3px 4px 2px 4px;
2626
}
27+
.tool-bar-vertical DIV.tool-item-default {
28+
padding-left:4px;
29+
padding-right:4px;
30+
}
2731
DIV.tool-item-selected {
2832
border-color:#666 white white #666 !important;
2933
border-width:2px 1px 1px 2px !important;
@@ -46,6 +50,7 @@ DIV.tool-item-down {
4650
.tool-item-text {
4751
font-family:Tahoma, Arial, sans-serif;
4852
font-size:8pt;
53+
text-align:center;
4954
}
5055
.tool-bar-flat .tool-item-default {
5156
border:1px solid menu;
@@ -82,17 +87,15 @@ DIV.tool-item-down {
8287
font-size:0;
8388
}
8489
.tool-bar-vertical .tool-item-seperator {
90+
font-size:0;
8591
height:0;
8692
width:100%;
8793
border:0 solid menu !important;
8894
border-top-width:2px;
8995
margin:3px 0;
9096
}
91-
.tool-bar-vertical .tool-item-seperator:hover {
92-
border:0 solid menu !important;
93-
border-top-width:2px !important;
94-
}
9597
.tool-bar-horizontal .tool-item-seperator {
98+
font-size:0;
9699
width:0;
97100
height:100%;
98101
border:0 solid menu;
@@ -127,7 +130,6 @@ DIV.tool-item-down {
127130

128131
.tool-item-enable-image .tool-item-text {
129132
margin-top:15px;
130-
text-align:center;
131133
}
132134
.tool-bar-right .tool-item-enable-image .tool-item-text {
133135
margin-top:0;
@@ -239,3 +241,7 @@ tool-bar-default .tool-item-inner-control:hover {
239241
border-style:none !important;
240242
border-width:0 !important;
241243
}
244+
.tool-bar-vertical .tool-item-seperator:hover {
245+
border:0 solid menu !important;
246+
border-top-width:0px !important;
247+
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/ToolBar.java

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public class ToolBar extends Composite {
5353

5454
Element btnFocus;
5555
boolean containsImage, containsText;
56-
int imgMaxHeight, imgMaxWidth, txtMaxHeight, txtMaxWidth;
56+
int imgMaxHeight, imgMaxWidth, txtMaxHeight, txtMaxWidth;
57+
int cachedMaxItemWidth;
5758

5859
/*
5960
static final int ToolBarProc;
@@ -106,8 +107,6 @@ public class ToolBar extends Composite {
106107
* @see SWT#VERTICAL
107108
* @see Widget#checkSubclass()
108109
* @see Widget#getStyle()
109-
*
110-
* @j2sIgnore
111110
*/
112111
public ToolBar (Composite parent, int style) {
113112
super (parent, checkStyle (style));
@@ -123,7 +122,11 @@ public ToolBar (Composite parent, int style) {
123122
* widget is created because of this conflict.
124123
*/
125124
if ((style & SWT.VERTICAL) != 0) {
125+
if (OS.existedCSSClass(handle, "tool-bar-horizontal")) {
126+
OS.removeCSSClass(handle, "tool-bar-horizontal");
127+
}
126128
this.style |= SWT.VERTICAL;
129+
OS.addCSSClass(handle, "tool-bar-vertical");
127130
/*
128131
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
129132
OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.CCS_VERT);
@@ -261,19 +264,31 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
261264
*/
262265

263266
calculateImagesMaxSize();
264-
calculateTextsMaxSize();
267+
calculateTextsMaxSize();
265268
if ((style & SWT.VERTICAL) != 0) {
266-
int count = items.length;
269+
int count = items.length;
270+
cachedMaxItemWidth = 0;
267271
for (int i=0; i<count; i++) {
268-
Rectangle rect = items[i].getBounds();
269-
//height = Math.max (height, rect.height);
270-
height += rect.height;
271-
if ((items[i].style & SWT.SEPARATOR) != 0) {
272+
ToolItem item = items[i];
273+
item.isInnerBounds = true;
274+
Rectangle rect = item.getBounds();
275+
item.isInnerBounds = false;
276+
if ((item.style & SWT.SEPARATOR) != 0) {
277+
cachedMaxItemWidth = Math.max(cachedMaxItemWidth, rect.width - getBorderWidth() * 2);
278+
} else {
279+
cachedMaxItemWidth = Math.max(cachedMaxItemWidth, rect.width);
280+
}
281+
//height = Math.max (height, rect.height);
282+
//System.out.println("xx::" + rect);
283+
height += rect.height;
284+
//if (i != count - 1)
285+
if ((item.style & SWT.SEPARATOR) != 0) {
272286
width = Math.max (width, DEFAULT_WIDTH);
273287
} else {
274288
width = Math.max (width, rect.width);
275289
}
276-
}
290+
}
291+
if ((style & SWT.FLAT) == 0) height += 2;
277292
} else {
278293
int count = items.length;
279294
for (int i=0; i<count; i++) {
@@ -386,7 +401,8 @@ protected void createHandle () {
386401
lastFocusId = -1;
387402

388403
String[] css = new String[0];
389-
css[0] = " tool-bar-default";
404+
css[0] = " tool-bar-default";
405+
//System.out.println(".." + (style & SWT.VERTICAL));
390406
if ((style & SWT.VERTICAL) != 0) {
391407
css[css.length] = "tool-bar-vertical";
392408
} else {
@@ -461,7 +477,8 @@ void createItem (ToolItem item, int index) {
461477
if ((item.style & SWT.SEPARATOR) != 0) {
462478
el = document.createElement("DIV");
463479
handle.appendChild(el);
464-
cssName += " tool-item-seperator";
480+
cssName += " tool-item-seperator";
481+
item.seperatorWidth = -1;
465482
} else if ((item.style & SWT.DROP_DOWN) != 0) {
466483
el = document.createElement("DIV");
467484
handle.appendChild(el);
@@ -1026,6 +1043,45 @@ boolean setTabItemFocus () {
10261043
if (index == items.length) return false;
10271044
return super.setTabItemFocus ();
10281045
}
1046+
1047+
protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) {
1048+
int border = 3;
1049+
if ((style & SWT.FLAT) != 0) {
1050+
border = 2;
1051+
}
1052+
// int maxWidth = 0;
1053+
// Rectangle[] itemsBounds = null;
1054+
// if ((style & SWT.VERTICAL) != 0) {
1055+
// itemsBounds = new Rectangle[items.length];
1056+
// for (int i = 0; i < items.length; i++) {
1057+
// ToolItem item = items[i];
1058+
// Rectangle bounds = item.getBounds();
1059+
// maxWidth = Math.max(maxWidth, bounds.width);
1060+
// itemsBounds[i] = bounds;
1061+
// }
1062+
// }
1063+
for (int i = 0; i < items.length; i++) {
1064+
ToolItem item = items[i];
1065+
Rectangle bounds = item.getBounds();
1066+
int w = bounds.width;
1067+
int h = bounds.height;
1068+
if ((item.style & SWT.DROP_DOWN) != 0) {
1069+
w -= 8 + 2 + border;
1070+
}
1071+
if ((style & SWT.FLAT) != 0) {
1072+
h -= 1;
1073+
if ((item.style & SWT.SEPARATOR) == 0) {
1074+
w -= 1;
1075+
}
1076+
if ((item.style & SWT.DROP_DOWN) != 0) {
1077+
w -= 1;
1078+
}
1079+
}
1080+
item.updateItemBounds(w, h);
1081+
}
1082+
return super.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
1083+
}
1084+
10291085
/*
10301086
String toolTipText (NMTTDISPINFO hdr) {
10311087
if ((hdr.uFlags & OS.TTF_IDISHWND) != 0) {

0 commit comments

Comments
 (0)