Skip to content

Commit 02813fd

Browse files
author
jossonsmith
committed
Add popup menu support;
Resize system works on SWT.NONE beside SWT.MAX & SWT.MIN, so monitor's client area can be calculated correctly.
1 parent b17e8d5 commit 02813fd

File tree

15 files changed

+1014
-64
lines changed

15 files changed

+1014
-64
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ResizeSystem {
4141
static ResizeHandler[] handlers = new ResizeHandler[0];
4242
public static void register(Decorations shell, int status) {
4343
for (int i = 0; i < handlers.length; i++) {
44-
if (handlers[i] != null && handlers[i].shell == shell) {
44+
if (handlers[i] != null && handlers[i].shell == shell && handlers[i].status == status) {
4545
return ;
4646
}
4747
}
@@ -54,19 +54,29 @@ public static void register(Decorations shell, int status) {
5454
handlers[handlers.length] = new ResizeHandler(shell, status);
5555
return ;
5656
}
57-
public static void unregister(Decorations shell) {
57+
public static void unregister(Decorations shell, int status) {
5858
for (int i = 0; i < handlers.length; i++) {
59-
if (handlers[i] != null && handlers[i].shell == shell) {
59+
if (handlers[i] != null && handlers[i].shell == shell && handlers[i].status == status) {
6060
handlers[i] = null;
6161
return ;
6262
}
6363
}
6464
}
65+
public static void reset() {
66+
for (int i = 0; i < handlers.length; i++) {
67+
if (handlers[i] != null) {
68+
handlers[i].shell = null;
69+
handlers[i] = null;
70+
return ;
71+
}
72+
}
73+
handlers = new ResizeHandler[0];
74+
}
6575
public static void updateResize() {
6676
for (int i = 0; i < handlers.length; i++) {
6777
ResizeHandler hdl = handlers[i];
68-
hdl.shell._updateMonitorSize();
6978
if (hdl != null) {
79+
hdl.shell._updateMonitorSize();
7080
int status = hdl.getStatus();
7181
if (status == SWT.MAX) {
7282
hdl.updateMaximized();

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/browser/OS.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public static void insertText(Object el, String text) {
164164
// el.appendChild (document.createTextNode (text));
165165
/**
166166
* @j2sNativeSrc
167-
if (!((/[\r\n\t&]/g).test (text))) {
167+
if (!((/[\r\n\t&]/).test (text))) {
168168
handle.style.display = "inline";
169169
handle.appendChild(document.createTextNode(text));
170170
return ;
@@ -182,7 +182,7 @@ public static void insertText(Object el, String text) {
182182
lines = s.split (/\r\n|\r|\n/g);
183183
}
184184
* @j2sNative
185-
if (!((/[\r\n\t&]/g).test (b))) {
185+
if (!((/[\r\n\t&]/).test (b))) {
186186
d.style.display = "inline";
187187
d.appendChild(document.createTextNode(b));
188188
return ;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/browser/Popup.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,79 @@ public static Rectangle popupList(Rectangle bounds, Rectangle rect, int height)
7676
return new Rectangle(x, y, w, h);
7777
}
7878

79+
80+
/**
81+
* Popup a given height box near the given rectangle box in the constrainted bounds.
82+
* The popup box is in the same width of give rectangle box.
83+
*
84+
* @param bounds
85+
* @param rect
86+
* @param width
87+
* @param height
88+
* @param preferredDirection
89+
* @return
90+
*/
91+
public static Rectangle popupMenu(Rectangle bounds, Rectangle rect, int width, int height, int preferredDirection) {
92+
if (height <= 0 || width <= 0) {
93+
return null;
94+
}
95+
int x, y, w = width, h = height;
96+
if (bounds == null) {
97+
if (rect == null) {
98+
x = y = 0;
99+
//w = 100;
100+
} else {
101+
x = rect.x;
102+
y = rect.y + height;
103+
//w = rect.width;
104+
}
105+
} else {
106+
if (rect == null) {
107+
x = bounds.x + bounds.width / 4;
108+
y = bounds.y + (bounds.height - height) / 2;
109+
//w = bounds.width / 2;
110+
} else {
111+
//x = rect.x;
112+
//w = rect.width;
113+
if (rect.y + rect.height + height > bounds.y + bounds.height) {
114+
if (rect.y - height >= bounds.y) {
115+
y = rect.y - height;
116+
} else {
117+
if (bounds.height < height) {
118+
y = bounds.y;
119+
h = bounds.height;
120+
} else {
121+
if (Math.abs(bounds.y + bounds.height - height - rect.y) > Math.abs(bounds.y + height - rect.y - rect.height)) {
122+
y = bounds.y;
123+
} else {
124+
y = bounds.y + bounds.height - height;
125+
}
126+
}
127+
}
128+
} else {
129+
y = rect.y + rect.height;
130+
}
131+
132+
if (rect.x + rect.width + width > bounds.x + bounds.width) {
133+
if (rect.x - width >= bounds.x) {
134+
x = rect.x - width;
135+
} else {
136+
if (bounds.width < width) {
137+
x = bounds.x;
138+
w = bounds.width;
139+
} else {
140+
if (Math.abs(bounds.x + bounds.width - width - rect.x) > Math.abs(bounds.x + width - rect.x - rect.width)) {
141+
x = bounds.x;
142+
} else {
143+
x = bounds.x + bounds.width - width;
144+
}
145+
}
146+
}
147+
} else {
148+
x = rect.x + rect.width;
149+
}
150+
}
151+
}
152+
return new Rectangle(x, y, w, h);
153+
}
79154
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ public static boolean onmousedown(Object e, DragAndDrop oThis) {
104104
document.onmousemove = DNDUtils.bindFunctionWith (DNDUtils.onmousemove, oThis);
105105
document.onkeyup = DNDUtils.bindFunctionWith (DNDUtils.onkeyup, oThis);
106106
document.onmouseup = DNDUtils.bindFunctionWith (DNDUtils.onmouseup, oThis); //oThis.element.onmouseup;
107+
/*
108+
* Why ? Sep 16, 2006
107109
evt.preventDefault ();
108110
evt.stopPropagation ();
109111
return false;
110-
//return true;
112+
*/
113+
return true;
111114
}
112115
public static boolean onkeyup(Object e, DragAndDrop oThis) {
113116
HTMLEventWrapper evt = new HTMLEventWrapper (e);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.swt.events.VerifyListener;
2020
import org.eclipse.swt.graphics.Point;
2121
import org.eclipse.swt.graphics.Rectangle;
22+
import org.eclipse.swt.internal.ResizeSystem;
2223
import org.eclipse.swt.internal.RunnableCompatibility;
2324
import org.eclipse.swt.internal.browser.OS;
2425
import org.eclipse.swt.internal.browser.Popup;
@@ -623,6 +624,8 @@ void createSelect() {
623624
selectInput.className = "combo-select-box-invisible combo-select-box-notsimple";
624625
selectInput.size = visibleCount;
625626
handle.appendChild(selectInput);
627+
628+
ResizeSystem.register(getShell(), SWT.NONE);
626629
}
627630
}
628631
void configureSelect() {
@@ -683,6 +686,10 @@ void show(){
683686
coordinate.y -= 2;
684687
}
685688
*/
689+
if (selectInput.style.overflow == "scroll") {
690+
selectInput.style.overflow = "auto";
691+
selectInput.style.height = "auto";
692+
}
686693
int w = OS.getContainerWidth(handle);
687694
int h = OS.getContainerHeight(handle);
688695
if (OS.isFirefox) {
@@ -708,9 +715,7 @@ void show(){
708715
selectInput.style.left = bounds.x + "px";
709716
selectInput.style.top = bounds.y + "px";
710717
if (bounds.height != height) {
711-
try {
712-
selectInput.style.overflow = "overflow";
713-
} catch (Throwable e) {} // IE
718+
selectInput.style.overflow = "scroll";
714719
selectInput.style.height = bounds.height + "px";
715720
}
716721
try {

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

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.eclipse.swt.graphics.Rectangle;
3333
import org.eclipse.swt.internal.RunnableCompatibility;
3434
import org.eclipse.swt.internal.browser.OS;
35+
import org.eclipse.swt.internal.browser.Popup;
36+
import org.eclipse.swt.internal.dnd.HTMLEventWrapper;
3537
import org.eclipse.swt.internal.struct.MESSAGE;
3638
import org.eclipse.swt.internal.struct.WINDOWPOS;
3739
import org.eclipse.swt.internal.xhtml.Element;
@@ -2476,14 +2478,128 @@ public void setMenu (Menu menu) {
24762478
}
24772479
}
24782480
this.menu = menu;
2479-
2480-
if (handle.oncontextmenu == null) {
2481-
handle.oncontextmenu = new RunnableCompatibility() {
2481+
Element el = null;
2482+
if (this instanceof Composite) {
2483+
el = ((Composite) this).containerHandle();
2484+
} else {
2485+
el = handle;
2486+
}
2487+
//if (el.oncontextmenu == null) {
2488+
if (OS.isOpera) {
2489+
el.onmousedown = new RunnableCompatibility() {
24822490
public void run() {
2483-
showMenu(0, 0);
2491+
Object evt = getEvent();
2492+
if (evt != null) {
2493+
HTMLEventWrapper evtHTML = new HTMLEventWrapper(evt);
2494+
if (!evtHTML.leftButtonHold) {
2495+
evtHTML.preventDefault();
2496+
evtHTML.stopPropagation();
2497+
toReturn(false);
2498+
/**
2499+
* @j2sNative
2500+
var bbtn = null;
2501+
var btns = document.getElementsByTagName ("INPUT");
2502+
for (var i = 0; i < btns.length; i++) {
2503+
if (btns[i].className == "opera-hide-context-menu") {
2504+
if (bbtn == null) {
2505+
bbtn = btns[i];
2506+
} else {
2507+
document.body.removeChild (btns[i]);
2508+
}
2509+
}
2510+
}
2511+
if (bbtn == null) {
2512+
bbtn = document.createElement ("INPUT");
2513+
bbtn.type = "BUTTON";
2514+
bbtn.className = "opera-hide-context-menu";
2515+
document.body.appendChild (bbtn);
2516+
}
2517+
bbtn.style.left = (evtHTML.x - 4) + "px";
2518+
bbtn.style.top = (evtHTML.y - 4) + "px";
2519+
bbtn.focus();
2520+
*/ {}
2521+
}
2522+
}
2523+
}
2524+
};
2525+
el.onmouseup = new RunnableCompatibility() {
2526+
public void run() {
2527+
Object evt = getEvent();
2528+
if (evt != null) {
2529+
HTMLEventWrapper evtHTML = new HTMLEventWrapper(evt);
2530+
if (!evtHTML.leftButtonHold) {
2531+
Element bbtn = null;
2532+
int x = 0, y = 0;
2533+
/**
2534+
* @j2sNative
2535+
var btns = document.getElementsByTagName ("INPUT");
2536+
for (var i = 0; i < btns.length; i++) {
2537+
if (btns[i].className == "opera-hide-context-menu") {
2538+
if (bbtn == null) {
2539+
bbtn = btns[i];
2540+
} else {
2541+
document.body.removeChild (btns[i]);
2542+
}
2543+
}
2544+
}
2545+
x = parseInt (bbtn.style.left);
2546+
y = parseInt (bbtn.style.top);
2547+
*/ {}
2548+
if (evtHTML.x - x < 0 || evtHTML.x - x > 8
2549+
|| evtHTML.y - y < 0 || evtHTML.y - y > 8) {
2550+
document.body.removeChild(bbtn);
2551+
return;
2552+
}
2553+
Menu menu = getMenu ();
2554+
if (menu != null && !menu.isDisposed ()) {
2555+
menu.handle.style.left = "-10000px";
2556+
menu.handle.style.top = "-10000px";
2557+
menu.handle.style.display = "block";
2558+
Rectangle bounds = menu.getBounds();
2559+
Rectangle rect = Popup.popupMenu(getMonitor().getClientArea(),
2560+
new Rectangle(evtHTML.x, evtHTML.y, 0, 0),
2561+
bounds.width, bounds.height, 0);
2562+
menu.handle.style.width = rect.width + "px";
2563+
menu.setLocation (rect.x, rect.y);
2564+
showMenu(rect.x, rect.y);
2565+
}
2566+
evtHTML.preventDefault();
2567+
evtHTML.stopPropagation();
2568+
toReturn(false);
2569+
document.body.removeChild(bbtn);
2570+
}
2571+
}
2572+
24842573
}
24852574
};
24862575
}
2576+
el.oncontextmenu = new RunnableCompatibility() {
2577+
public void run() {
2578+
System.out.println("..fsfd.s");
2579+
Object evt = getEvent();
2580+
if (evt != null) {
2581+
HTMLEventWrapper evtHTML = new HTMLEventWrapper(evt);
2582+
Menu menu = getMenu ();
2583+
if (menu != null && !menu.isDisposed ()) {
2584+
menu.handle.style.left = "-10000px";
2585+
menu.handle.style.top = "-10000px";
2586+
menu.handle.style.display = "block";
2587+
Rectangle bounds = menu.getBounds();
2588+
Rectangle rect = Popup.popupMenu(getMonitor().getClientArea(),
2589+
new Rectangle(evtHTML.x, evtHTML.y, 0, 0),
2590+
bounds.width, bounds.height, 0);
2591+
menu.handle.style.width = rect.width + "px";
2592+
menu.setLocation (rect.x, rect.y);
2593+
showMenu(rect.x, rect.y);
2594+
}
2595+
evtHTML.preventDefault();
2596+
evtHTML.stopPropagation();
2597+
}
2598+
System.out.println("to return false...");
2599+
toReturn(false);
2600+
}
2601+
};
2602+
//}
24872603
}
24882604

24892605
boolean setRadioFocus () {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ public void setMaximized (boolean maximized) {
15741574
if (maximized) {
15751575
ResizeSystem.register(this, SWT.MAX);
15761576
} else {
1577-
ResizeSystem.unregister(this);
1577+
ResizeSystem.unregister(this, SWT.MAX);
15781578
}
15791579
}
15801580

@@ -1589,7 +1589,7 @@ void toggleMaximize() {
15891589
titleBar.className = cssName.substring(0, idx) + cssName.substring(idx + key.length());
15901590
}
15911591
oldBounds = null;
1592-
ResizeSystem.unregister(this);
1592+
ResizeSystem.unregister(this, SWT.MAX);
15931593
} else {
15941594
setMaximized(true);
15951595
String cssName = titleBar.className;
@@ -1733,7 +1733,7 @@ public void setMinimized (boolean minimized) {
17331733
if (minimized) {
17341734
ResizeSystem.register(this, SWT.MIN);
17351735
} else {
1736-
ResizeSystem.unregister(this);
1736+
ResizeSystem.unregister(this, SWT.MIN);
17371737
}
17381738
}
17391739

@@ -1883,7 +1883,7 @@ void setSystemMenu () {
18831883
titleBar.appendChild(shellMin);
18841884
shellMin.onclick = new RunnableCompatibility() {
18851885
public void run() {
1886-
ResizeSystem.unregister(Decorations.this);
1886+
ResizeSystem.unregister(Decorations.this, SWT.MIN);
18871887
setMinimized(true);
18881888
}
18891889
};
@@ -1938,6 +1938,7 @@ public void run() {
19381938
if(contentHandle != null){
19391939
contentHandle.focus();
19401940
}
1941+
toReturn(true);
19411942
}
19421943
};
19431944

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,6 +3047,7 @@ public boolean readAndDispatch () {
30473047
messageProc = window.setInterval(new RunnableCompatibility() {
30483048
private boolean messageLoop = false;
30493049
public void run() {
3050+
runPopups ();
30503051
// System.out.println("I'm entering the run");
30513052
// System.out.println("msg " + Display.this.msgs);
30523053
// List layoutQueue = new ArrayList();

0 commit comments

Comments
 (0)