Skip to content

Commit 6d936d2

Browse files
author
jossonsmith
committed
Early implementation of CoolBar' DND
1 parent 526220e commit 6d936d2

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/DNDUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public static boolean onmousemove(Object e, DragAndDrop oThis) {
8585
oThis.startX, oThis.startY);
8686
if (oThis.status == 0) {
8787
oThis.status = 1;
88-
oThis.startX = evt.x;
89-
oThis.startY = evt.y;
88+
oThis.startX = dndEvt.startX = evt.x;
89+
oThis.startY = dndEvt.startY = evt.y;
9090
dndEvt.mouseMoveTo (evt.x, evt.y);
9191
oThis.notifyDragBegan (dndEvt);
9292
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
.composite-border {
1414
white-space:nowrap;
1515
border-style:solid;
16-
border-width:2px;
16+
border-width:2px 1px 1px 2px;
1717
border-color:black white white black;
1818
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
position:absolute;
33
background-color:menu;
44
cursor:default;
5-
}
6-
.cool-bar-border {
7-
border:2px inset white;
5+
/*overflow:visible;
6+
overflow-x:hidden;*/
87
}
98
.cool-item-default {
109
position:absolute;
@@ -45,7 +44,7 @@
4544
}
4645
.cool-item-content {
4746
position:absolute;
48-
left:11px;
47+
left:10px;
4948
top:0;
5049
}
5150
.cool-item-more {

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

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import org.eclipse.swt.graphics.Point;
1717
import org.eclipse.swt.graphics.Rectangle;
1818
import org.eclipse.swt.internal.browser.OS;
19+
import org.eclipse.swt.internal.dnd.DragAdapter;
20+
import org.eclipse.swt.internal.dnd.DragAndDrop;
21+
import org.eclipse.swt.internal.dnd.DragEvent;
1922
import org.eclipse.swt.internal.xhtml.CSSStyle;
2023
import org.eclipse.swt.internal.xhtml.Element;
2124
import org.eclipse.swt.internal.xhtml.document;
@@ -177,13 +180,13 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
177180
rowWidth += rbBand.cxIdeal + getMargin (i) + separator;
178181
*/
179182
if (items[i].wrap) {
180-
System.out.println("wrap...");
183+
//System.out.println("wrap...");
181184
width = Math.max(width, rowWidth - separator);
182185
rowWidth = 0;
183186
height += rowHeight;
184-
if (i != count - 1) {
187+
//if (i != count - 1) {
185188
height += 2;
186-
}
189+
//}
187190
rowHeight = 0;
188191
}
189192
if (items[i].ideal) {
@@ -252,7 +255,7 @@ protected void createHandle () {
252255
handle.className += cssName;
253256
}
254257

255-
void createItem (CoolItem item, int index) {
258+
void createItem (final CoolItem item, int index) {
256259
//int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
257260
int count = items.length;
258261
if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
@@ -325,6 +328,46 @@ void createItem (CoolItem item, int index) {
325328
el = document.createElement("DIV");
326329
el.className = "cool-item-handler";
327330
item.handle.appendChild(el);
331+
final DragAndDrop dnd = new DragAndDrop();
332+
dnd.addDragListener(new DragAdapter() {
333+
int dxx;
334+
public boolean dragging(DragEvent e) {
335+
Rectangle b1 = getBounds();
336+
Rectangle b2 = item.getBounds();
337+
int idx = indexOf(item);
338+
int dx = e.deltaX() - dxx;
339+
if (dx != 0 && idx != 0) {
340+
CoolItem prevItem = items[idx - 1];
341+
Point size = prevItem.getPreferredSize();
342+
size.x += dx;
343+
if (size.x > 13 && size.x + prevItem.getPosition().x< b1.width) {
344+
prevItem.setPreferredSize(size);
345+
size = item.getPreferredSize();
346+
size.x -= dx;
347+
if (size.x > 13 && size.x + b2.x < b1.width) {
348+
item.setPreferredSize(size);
349+
SetWindowPos(handle, null, left, top, width, height, 0);
350+
dxx = e.deltaX();
351+
} else {
352+
353+
}
354+
}
355+
}
356+
// System.out.println(b1);
357+
// System.out.println(b2);
358+
// System.out.println(e.currentX + ":" + e.currentY);
359+
return true;
360+
}
361+
public boolean dragBegan(DragEvent e) {
362+
dxx = e.deltaX();
363+
return true;
364+
}
365+
public boolean dragEnded(DragEvent e) {
366+
dxx = 0;
367+
return super.dragEnded(e);
368+
}
369+
});
370+
dnd.bind(el);
328371

329372
if ((item.style & SWT.DROP_DOWN) != 0) {
330373
el = document.createElement("DIV");
@@ -1103,17 +1146,21 @@ public void setWrapIndices (int [] indices) {
11031146
* @see org.eclipse.swt.widgets.Composite#SetWindowPos(java.lang.Object, java.lang.Object, int, int, int, int, int)
11041147
*/
11051148
protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) {
1149+
int bw = getBorderWidth() * 2;
11061150
for (int i = 0; i < items.length; i++) {
11071151
CoolItem item = items[i];
11081152
CSSStyle s = item.handle.style;
11091153
Rectangle bounds = item.getBounds();
11101154
s.left = bounds.x + "px";
11111155
s.top = bounds.y + "px";
1112-
int w = bounds.width - getMargin(i) - getBorderWidth() * 2;
1156+
int w = bounds.width - getMargin(i) - bw;
11131157
s.width = (w > 0 ? w : 0) + "px";
11141158
s.height = bounds.height + "px";
11151159
if (item.control != null) {
1116-
item.control.setSize(w, bounds.height/* - 4*/);
1160+
item.control.setSize(w + bw - (!isLastItemOfRow(i) ? 2 : 0), bounds.height);
1161+
Point pt = item.getPosition();
1162+
item.control.left = pt.x + getMargin(i) - 4;
1163+
item.control.top = pt.y;
11171164
}
11181165
}
11191166
return super.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,13 @@ public Rectangle getBounds () {
231231
int height = rect.bottom - rect.top;
232232
return new Rectangle (rect.left, rect.top, width, height);
233233
*/
234-
//Point pt = OS.calcuateRelativePosition(handle, parent.handle);
234+
Point size = getSize();
235+
Point pos = getPosition();
236+
return new Rectangle (pos.x, pos.y, size.x, size.y);
237+
}
238+
239+
Point getPosition() {
240+
int index = parent.indexOf (this);
235241
int x = 0;
236242
int y = 0;
237243
int rowHeight = 0;
@@ -255,8 +261,7 @@ public Rectangle getBounds () {
255261
}
256262
}
257263
}
258-
Point size = getSize();
259-
return new Rectangle (x, y, size.x, size.y);
264+
return new Point(x, y);
260265
}
261266

262267
/*
@@ -423,7 +428,11 @@ public Point getPreferredSize () {
423428
int width = rbBand.cxIdeal + parent.getMargin (index);
424429
return new Point (width, rbBand.cyMinChild);
425430
*/
426-
return new Point (0, 0);
431+
if (ideal) {
432+
return new Point (idealWidth + parent.getMargin (index), idealHeight);
433+
} else {
434+
return getSize();
435+
}
427436
}
428437

429438
/**
@@ -541,6 +550,8 @@ public Point getSize() {
541550
}
542551
if (!parent.isLastItemOfRow (index)) {
543552
width += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
553+
} else if (ideal) {
554+
width = parent.width - 2 * parent.getBorderWidth() - getPosition().x;
544555
}
545556
lastCachedWidth = width;
546557
lastCachedHeight = height;

0 commit comments

Comments
 (0)