Skip to content

Commit 58e802e

Browse files
author
zhourenjian
committed
Refactor Desktop related classes
1 parent 1f335ae commit 58e802e

File tree

9 files changed

+344
-249
lines changed

9 files changed

+344
-249
lines changed

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ void bringToTop () {
218218
// } else {
219219
//OS.BringWindowToTop (handle);
220220
CSSStyle style = handle.style;
221-
style.visibility = "visible";
222-
if (style.display == "none") {
223-
style.display = "block";
224-
}
221+
// style.visibility = "visible";
222+
// if (style.display == "none") {
223+
// style.display = "block";
224+
// }
225225
if (window.currentTopZIndex == null) {
226226
window.currentTopZIndex = "1000";
227227
}
@@ -1875,20 +1875,28 @@ public void setMinimized (boolean minimized) {
18751875
OS.ShowWindow (handle, flags);
18761876
OS.UpdateWindow (handle);
18771877
*/
1878-
this.minimized = minimized;
1879-
if (this.minimized && !minimized) {
1878+
if (!minimized) {
18801879
if (this.maximized) {
1880+
this.minimized = minimized;
18811881
this.setMaximized(true);
18821882
return;
18831883
}
18841884
}
1885-
if (this.parent == null && minimized && display.taskBar != null) {
1886-
this.handle.style.display = "none";
1887-
display.taskBar.handleApproaching();
1888-
display.taskBar.updateLayout();
1889-
// lastMMed
1885+
if (display.taskBar != null) {
1886+
this.handle.style.display = minimized ? "none" : "";
1887+
if (this.minimized != minimized) {
1888+
display.taskBar.handleApproaching();
1889+
display.taskBar.setMinimized(false);
1890+
display.taskBar.updateLastModified();
1891+
display.taskBar.updateLayout();
1892+
}
1893+
if (!minimized) {
1894+
bringToTop();
1895+
}
1896+
this.minimized = minimized;
18901897
return;
18911898
}
1899+
this.minimized = minimized;
18921900
if (minimized && contentHandle != null) {
18931901
//handle.style.display = "none";
18941902
if (oldBounds == null) {
Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
11
package org.eclipse.swt.widgets;
22

3-
public interface DesktopItem {
3+
import java.util.Date;
44

5-
public void initialize();
5+
import org.eclipse.swt.internal.xhtml.Clazz;
6+
import org.eclipse.swt.internal.xhtml.Element;
7+
import org.eclipse.swt.internal.xhtml.window;
8+
9+
public abstract class DesktopItem implements DesktopListener {
10+
11+
Display display;
12+
13+
Element handle = null;
14+
15+
boolean isAutoHide = true;
16+
17+
// the last time that item is updated
18+
long lastUpdated = new Date().getTime();
19+
20+
boolean isJustUpdated = false;
21+
22+
boolean mouseAlreadyMoved;
23+
24+
String layerZIndex = null;
25+
26+
private Runnable leaving;
27+
28+
private int leavingTimeoutHandle = 0;
29+
30+
public void updateLastModified() {
31+
this.lastUpdated = new Date().getTime();
32+
mouseAlreadyMoved = false;
33+
if (isAutoHide) {
34+
if (leavingTimeoutHandle != 0) {
35+
window.clearTimeout(leavingTimeoutHandle);
36+
leavingTimeoutHandle = 0;
37+
}
38+
if (leaving == null) {
39+
leaving = Clazz.makeFunction(new Runnable() {
40+
41+
public void run() {
42+
if (!mouseAlreadyMoved) {
43+
handleLeaving();
44+
}
45+
leavingTimeoutHandle = 0;
46+
}
47+
48+
});
49+
}
50+
leavingTimeoutHandle = window.setTimeout(leaving, Display.AUTO_HIDE_DELAY);
51+
}
52+
}
53+
54+
public abstract void initialize();
55+
56+
public abstract void bringToTop(String zIndex);
657

7-
public void bringToTop(String zIndex);
58+
public abstract void updateLayout();
859

9-
public void updateLayout();
60+
public abstract void releaseWidget();
1061

1162
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,10 +3348,22 @@ protected void release () {
33483348
timerList = null;
33493349
// synchronizer.releaseSynchronizer ();
33503350
// synchronizer = null;
3351+
releaseDesktop ();
33513352
releaseDisplay ();
33523353
super.release ();
33533354
}
33543355

3356+
void releaseDesktop () {
3357+
for (int i = 0; i < desktopItems.length; i++) {
3358+
desktopItems[i].releaseWidget();
3359+
}
3360+
desktopItems = null;
3361+
trayCorner = null;
3362+
taskBar = null;
3363+
shortcutBar = null;
3364+
topBar = null;
3365+
}
3366+
33553367
void releaseDisplay () {
33563368
// if (embeddedHwnd != 0) {
33573369
// OS.PostMessage (embeddedHwnd, SWT_DESTROY, 0, 0);

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

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@
2727
* @j2sPrefix
2828
* $WTC$$.registerCSS ("$wt.widgets.MaximizedTitle");
2929
*/
30-
public class MaximizedTitle implements DesktopListener, DesktopItem {
30+
public class MaximizedTitle extends DesktopItem {
3131
private Shell lastMaximizedShell = null;
3232
private Element topbarEl = null;
33-
private Element topbarContainerEl = null;
34-
35-
// the last time that a window is minimized or maximized
36-
private long lastMMed = new Date().getTime();
3733

38-
Display display;
39-
4034
public MaximizedTitle(Display display) {
4135
super();
4236
this.display = display;
@@ -58,15 +52,15 @@ public void updateLayout() {
5852
}
5953

6054
// update topbar
61-
this.topbarContainerEl.style.left = Math.round ((document.body.clientWidth - 320) / 2) + "px";
55+
this.handle.style.left = Math.round ((document.body.clientWidth - 320) / 2) + "px";
6256
this.topbarEl.style.width = "316px";
6357
if (OS.isIE) {
6458
this.topbarEl.style.left = "1px";
6559
} else {
6660
this.topbarEl.style.left = "2px";
6761
}
6862
this.topbarEl.style.top = "1px";
69-
this.topbarContainerEl.ondblclick = lastShell.titleBar.ondblclick;
63+
this.handle.ondblclick = lastShell.titleBar.ondblclick;
7064
lastShell.updateShellTitle (320 + 4);
7165
}
7266
public void returnTopMaximized(Shell shell) {
@@ -83,29 +77,29 @@ public void returnTopMaximized(Shell shell) {
8377
lastShell.titleBar.appendChild (els[i]);
8478
}
8579
if (shell != null) {
86-
this.topbarContainerEl.style.display = "none";
80+
this.handle.style.display = "none";
8781
}
8882
}
8983
public void initialize() {
90-
if (this.topbarContainerEl != null) return;
84+
if (this.handle != null) return;
9185

9286
Element tbc = document.createElement ("DIV");
9387
tbc.className = "shell-manager-topbar-container";
9488
document.body.appendChild (tbc);
9589
tbc.style.display = "none";
9690
tbc.style.width = "320px";
9791
tbc.style.zIndex = "3456";
98-
this.topbarContainerEl = tbc;
92+
this.handle = tbc;
9993

10094
Element tb = document.createElement ("DIV");
10195
tb.className = "shell-title-bar shell-maximized";
102-
this.topbarContainerEl.appendChild (tb);
96+
this.handle.appendChild (tb);
10397
this.topbarEl = tb;
10498
}
10599

106100
boolean isAround(int x, int y) {
107101
long now = new Date().getTime();
108-
if (now - this.lastMMed < 1000) {
102+
if (now - this.lastUpdated < 1000) {
109103
return true;
110104
}
111105
int barWidth = 320;
@@ -117,15 +111,15 @@ boolean isAround(int x, int y) {
117111
};
118112

119113
void hide() {
120-
CSSStyle smStyle = this.topbarContainerEl.style;
114+
CSSStyle smStyle = this.handle.style;
121115
if (smStyle.display == "block") {
122116
smStyle.display = "none";
123117
}
124118

125119
}
126120
@Override
127121
public void handleApproaching() {
128-
Element topbar = topbarContainerEl;
122+
Element topbar = handle;
129123
if (topbar == null) return;
130124
if (topbar.style.display != "block") {
131125
Shell lastShell = Display.getTopMaximizedShell ();
@@ -137,7 +131,7 @@ public void handleApproaching() {
137131
}
138132
@Override
139133
public void handleLeaving() {
140-
Element topbar = topbarContainerEl;
134+
Element topbar = handle;
141135
if (topbar == null) return;
142136
if (topbar.style.display != "none") {
143137
topbar.style.display = "none";
@@ -146,14 +140,16 @@ public void handleLeaving() {
146140
}
147141
@Override
148142
public boolean isApproaching(HTMLEvent e) {
143+
mouseAlreadyMoved = true;
149144
return (e.clientY <= 8 && !e.ctrlKey) && isAround (e.clientX, e.clientY);
150145
}
151146
@Override
152147
public boolean isLeaving(HTMLEvent e) {
148+
mouseAlreadyMoved = true;
149+
long now = new Date().getTime();
150+
if (now - lastUpdated <= Display.AUTO_HIDE_DELAY) return false;
153151
Shell topShell = Display.getTopMaximizedShell ();
154152
if (topShell == null) return false;
155-
long now = new Date().getTime();
156-
if (now - lastMMed <= Display.AUTO_HIDE_DELAY) return false;
157153
return !isAround (e.clientX, e.clientY) || e.ctrlKey || e.clientY > 12 + ((topShell.titleBar != null) ? OS.getContainerHeight (topShell.titleBar) : 20);
158154
}
159155

@@ -162,12 +158,21 @@ public void bringToTop(String index) {
162158
// TODO Auto-generated method stub
163159

164160
}
165-
166-
public void updateLastModified() {
167-
this.lastMMed = new Date().getTime();
168-
}
169-
161+
170162
public boolean isVisible() {
171-
return topbarContainerEl.style.display != "none";
163+
return handle.style.display != "none";
172164
}
165+
166+
@Override
167+
public void releaseWidget() {
168+
if (handle != null) {
169+
OS.destroyHandle(handle);
170+
handle = null;
171+
}
172+
if (topbarEl != null) {
173+
OS.destroyHandle(topbarEl);
174+
topbarEl = null;
175+
}
176+
}
177+
173178
}

0 commit comments

Comments
 (0)