Skip to content

Commit 32d4d07

Browse files
author
zhourenjian
committed
Add "swt-desktop-panel" layer if it does not exist while initializing SWT desktop
Fixing insert Console tray item Fixing other bugs
1 parent 4045e57 commit 32d4d07

File tree

2 files changed

+138
-41
lines changed

2 files changed

+138
-41
lines changed

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

Lines changed: 137 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
fss.isMonitoring = false;
135135
fss.initialize = function () {
136136
this.monitorEl = document.createElement ("DIV");
137+
this.monitorEl.id = "swt-font-monitor";
137138
this.monitorEl.style.cssText = "position:absolute;top:-1000px;left:-1000px;font-family:Arial, sans-serif;font-size:10pt;overflow:visible;";
138139
document.body.appendChild (this.monitorEl);
139140
this.monitorEl.appendChild (document.createTextNode ("Java2Script"));
@@ -1798,7 +1799,7 @@ Shell getModalDialogShell () {
17981799
monitor.handle = document.body;
17991800
monitor.clientWidth = OS.getFixedBodyClientWidth(); //document.body.clientWidth;
18001801
int parentWidth = OS.getContainerWidth(document.body.parentNode);
1801-
if (parentWidth > monitor.clientWidth && parentWidth <= window.screen.availWidth) {
1802+
if (parentWidth - 8 > monitor.clientWidth && parentWidth <= window.screen.availWidth) {
18021803
monitor.clientWidth = parentWidth;
18031804
}
18041805
monitor.width = window.screen.availWidth;
@@ -2498,6 +2499,132 @@ void initializeDekstop() {
24982499
}
24992500
if (taskBar != null) return;
25002501

2502+
/* initialize desktop panel */
2503+
Element panel = document.getElementById("swt-desktop-panel");
2504+
boolean needScrolling = false;
2505+
boolean injecting = false;
2506+
if (panel == null) {
2507+
boolean forceInsertingPanel = true;
2508+
/**
2509+
* @j2sNative
2510+
* forceInsertingPanel = (window["swt.desktop.panel"] != false);
2511+
*/ {}
2512+
if (forceInsertingPanel) {
2513+
injecting = true;
2514+
panel = document.createElement("DIV");
2515+
panel.id = "swt-desktop-panel";
2516+
/**
2517+
* @j2sNative
2518+
* panel.style.overflowX = "hidden";
2519+
*/ {}
2520+
Element[] childNodes = document.body.childNodes;
2521+
if (childNodes.length > 0) {
2522+
document.body.insertBefore(panel, childNodes[0]);
2523+
} else {
2524+
document.body.appendChild(panel);
2525+
}
2526+
childNodes = document.body.childNodes;
2527+
Element[] removedChildren = new Element[0];
2528+
for (int i = childNodes.length - 1; i >= 0; i--) {
2529+
Element child = childNodes[i];
2530+
boolean okToMove = false;
2531+
if (child.nodeName == null) {
2532+
okToMove = true;
2533+
} else if (!"SCRIPT".equalsIgnoreCase(child.nodeName)) {
2534+
okToMove = true;
2535+
String id = child.id;
2536+
if (id != null) {
2537+
if ("swt-desktop-panel".equalsIgnoreCase(id)) {
2538+
okToMove = false;
2539+
} else if ("xss-cookie".equalsIgnoreCase(id)) {
2540+
okToMove = false;
2541+
} else if ("clazzloader-status".equalsIgnoreCase(id)) {
2542+
okToMove = false;
2543+
} else if ("swt-font-monitor".equalsIgnoreCase(id)) {
2544+
okToMove = false;
2545+
} else if ("swt-invisible-container".equalsIgnoreCase(id)) {
2546+
okToMove = false;
2547+
} else if ("_console_".equalsIgnoreCase(id)) {
2548+
okToMove = false;
2549+
} else if (id.startsWith("alaa-")) {
2550+
okToMove = false;
2551+
}
2552+
} else {
2553+
String cssClass = child.className;
2554+
if (cssClass != null) {
2555+
String[] allSWTClasses = new String[] {
2556+
"tray-cell",
2557+
"tray-item",
2558+
"tray-logo-item",
2559+
"shell-manager",
2560+
"shortcut-bar",
2561+
"shell-default",
2562+
"shell-trim"
2563+
};
2564+
for (int j = 0; j < allSWTClasses.length; j++) {
2565+
if (cssClass.indexOf(allSWTClasses[j]) != -1) {
2566+
okToMove = false;
2567+
break;
2568+
}
2569+
}
2570+
}
2571+
}
2572+
}
2573+
if (okToMove) {
2574+
removedChildren[removedChildren.length] = child;
2575+
document.body.removeChild(child);
2576+
}
2577+
}
2578+
for (int i = removedChildren.length - 1; i >= 0; i--) {
2579+
panel.appendChild(removedChildren[i]);
2580+
}
2581+
document.body.style.overflow = "hidden";
2582+
document.body.style.padding = "0";
2583+
document.body.style.margin = "0";
2584+
needScrolling = true;
2585+
}
2586+
}
2587+
if (panel != null) {
2588+
document.body.style.overflow = "hidden";
2589+
int height = OS.getFixedBodyClientHeight();
2590+
int width = OS.getFixedBodyClientWidth();
2591+
panel.style.position = "absolute";
2592+
if (!injecting) {
2593+
panel.style.backgroundColor = "white";
2594+
}
2595+
/**
2596+
* @j2sNative
2597+
* var vsb = window["swt.desktop.vscrollbar"];
2598+
* if (vsb != null && (vsb == true || vsb == "true" || vsb == "enable")) {
2599+
* panel.style.overflowY = "auto";
2600+
* }
2601+
* var hsb = window["swt.desktop.hscrollbar"];
2602+
* if (hsb != null && (hsb == true || hsb == "true" || hsb == "enable")) {
2603+
* panel.style.overflowX = "auto";
2604+
* }
2605+
*/ {}
2606+
panel.style.paddingBottom = "80px";
2607+
if (!OS.isIE || OS.isIE70 || OS.isIE80 || OS.isIE90) { // to ensure that it is at least 80px height?
2608+
Element div = document.createElement("DIV");
2609+
div.id = "page-bottom-end";
2610+
/**
2611+
* @j2sNative
2612+
* div.style.cssFloat = "left";
2613+
*/ {}
2614+
div.style.height = "80px";
2615+
div.style.width = "1px";
2616+
div.style.marginLeft = "-1px";
2617+
panel.appendChild(div);
2618+
}
2619+
panel.style.left = "0";
2620+
panel.style.top = "0";
2621+
panel.style.width = width + "px";
2622+
panel.style.height = (height - 80) + "px";
2623+
if (needScrolling) {
2624+
panel.scrollTop = panel.scrollHeight;
2625+
}
2626+
}
2627+
25012628
taskBar = new TaskBar(this);
25022629
topBar = new MaximizedTitle(this);
25032630
if (QuickLaunch.defaultQuickLaunch != null) {
@@ -2531,51 +2658,16 @@ void initializeDekstop() {
25312658
* this.taskBar.toggleAutoHide(); // by default, it is being hide automatically.
25322659
* }
25332660
*/ {}
2534-
2535-
Element panel = document.getElementById("swt-desktop-panel");
2536-
if (panel != null) {
2537-
int height = OS.getFixedBodyClientHeight();
2538-
int width = OS.getFixedBodyClientWidth();
2539-
panel.style.position = "absolute";
2540-
panel.style.backgroundColor = "white";
2541-
/**
2542-
* @j2sNative
2543-
* var vsb = window["swt.desktop.vscrollbar"];
2544-
* if (vsb != null && (vsb == true || vsb == "true" || vsb == "enable")) {
2545-
* panel.style.overflowY = "auto";
2546-
* }
2547-
* var hsb = window["swt.desktop.hscrollbar"];
2548-
* if (hsb != null && (hsb == true || hsb == "true" || hsb == "enable")) {
2549-
* panel.style.overflowX = "auto";
2550-
* }
2551-
*/ {}
2552-
panel.style.paddingBottom = "80px";
2553-
if (!OS.isIE) {
2554-
Element div = document.createElement("DIV");
2555-
/**
2556-
* @j2sNative
2557-
* div.style.cssFloat = "left";
2558-
*/ {}
2559-
div.style.height = "80px";
2560-
div.style.width = "1px";
2561-
div.style.marginLeft = "-1px";
2562-
panel.appendChild(div);
2563-
}
2564-
panel.style.left = "0";
2565-
panel.style.top = "0";
2566-
panel.style.width = width + "px";
2567-
panel.style.height = (height - 80) + "px";
2568-
}
25692661

25702662
mouseMoveListener = new RunnableCompatibility(){
25712663

25722664
public void run() {
25732665
HTMLEvent e = (HTMLEvent) getEvent();
2574-
int height = OS.getFixedBodyClientHeight();
2666+
int bottom = getPrimaryMonitor().clientHeight - 128;
25752667
// Hacks: Return as quickly as possible to avoid CPU 100%
25762668
int x = e.clientX;
25772669
int y = e.clientY;
2578-
if (x > 264 && y >= 100 && y <= height - 128) {
2670+
if (x > 264 && y >= 100 && y <= bottom) {
25792671
return;
25802672
}
25812673

@@ -2595,7 +2687,7 @@ public void run() {
25952687
}
25962688
}
25972689

2598-
if (y > height - 128) {
2690+
if (y > bottom) {
25992691
if (shortcutBar.isApproaching(now, x, y, ctrlKey)) {
26002692
shortcutBar.handleApproaching();
26012693
} else if (!inDelay && shortcutBar.isLeaving(now, x, y, ctrlKey)) {
@@ -2665,7 +2757,12 @@ public void run() {
26652757
}
26662758

26672759
static void insertOpenConsoleLink() {
2668-
TrayItem item = new TrayItem(getTray(), SWT.NONE);
2760+
Tray t = getTray();
2761+
if (t == null || t.isDisposed()) {
2762+
t = Default.getSystemTray();
2763+
}
2764+
2765+
TrayItem item = new TrayItem(t, SWT.NONE);
26692766
item.setText("Console");
26702767
item.handle.className = "tray-item tray-item-console";
26712768
item.setToolTipText("Console");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ public void run() {
950950
Widget widgetThis = Widget.this;
951951
/**
952952
* @j2sNative
953-
* if (O$.isIE60 || O$.isIE55 || O$.isIE50) {
953+
* if (O$.isIE) {
954954
* if (e.x == widgetThis.lastMouseMoveX && e.y == widgetThis.lastMouseMoveY) {
955955
* return true;
956956
* }

0 commit comments

Comments
 (0)