Skip to content

Commit a614e55

Browse files
author
zhourenjian
committed
Support new window layout
Support simple window animation callback Support IE9 Lots of other improvements
1 parent da36597 commit a614e55

30 files changed

+1649
-499
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/custom/ScrolledComposite.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.eclipse.swt.*;
1414
import org.eclipse.swt.graphics.*;
15+
import org.eclipse.swt.internal.xhtml.Element;
1516
import org.eclipse.swt.widgets.*;
1617

1718
/**
@@ -487,6 +488,21 @@ void vScroll() {
487488
}
488489
protected void createHandle () {
489490
super.createHandle();
491+
492+
Element containerHandle = containerHandle();
493+
if ((style & SWT.V_SCROLL) != 0 && (style & SWT.H_SCROLL) != 0) {
494+
containerHandle.style.overflow = "scroll";
495+
} else if ((style & SWT.V_SCROLL) != 0) {
496+
/**
497+
* @j2sNative
498+
* containerHandle.style.overflowY = "scroll";
499+
*/ { }
500+
} else if ((style & SWT.H_SCROLL) != 0) {
501+
/**
502+
* @j2sNative
503+
* containerHandle.style.overflowX = "scroll";
504+
*/ { }
505+
}
490506
// ScrollBar hBar = getHorizontalBar ();
491507
// if (hBar != null) {
492508
// hBar.addListener (SWT.Selection, new Listener () {

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

Lines changed: 144 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
import org.eclipse.swt.graphics.Rectangle;
1717
import org.eclipse.swt.internal.browser.OS;
1818
import org.eclipse.swt.internal.xhtml.Element;
19-
import org.eclipse.swt.internal.xhtml.document;
2019
import org.eclipse.swt.widgets.Decorations;
2120
import org.eclipse.swt.widgets.Monitor;
21+
import org.eclipse.swt.widgets.QuickLaunch;
22+
import org.eclipse.swt.widgets.TaskBar;
2223

2324
/**
2425
* @author zhou renjian
@@ -39,29 +40,51 @@ public ResizeHandler(Decorations shell, int status) {
3940
this.status = status;
4041
}
4142

43+
private Rectangle getClientArea() {
44+
int orientation = SWT.LEFT;
45+
int clientWidth = 0;
46+
int clientHeight = 0;
47+
int offsetX = 0;
48+
int offsetY = 0;
49+
/**
50+
* @j2sNative
51+
* clientWidth = document.body.parentNode.clientWidth;
52+
* clientHeight = O$.getFixedBodyClientHeight(); //document.body.clientHeight;
53+
* var display = null;
54+
* if (this.shell != null) {
55+
* display = this.shell.display;
56+
* }
57+
* if (display == null) {
58+
* display = $wt.widgets.Display.Default;
59+
* }
60+
* if (display != null && display.taskBar != null) {
61+
* orientation = display.taskBar.orientation;
62+
* }
63+
*/ {}
64+
if (orientation == SWT.BOTTOM) {
65+
offsetY = QuickLaunch.BAR_HEIGHT;
66+
clientHeight = clientHeight - QuickLaunch.BAR_HEIGHT - TaskBar.BAR_HEIGHT;
67+
} else if (orientation == SWT.TOP) {
68+
offsetY = TaskBar.BAR_HEIGHT;
69+
clientHeight = clientHeight - TaskBar.BAR_HEIGHT;
70+
}
71+
return new Rectangle(offsetX, offsetY, clientWidth, clientHeight);
72+
}
73+
4274
public void updateMinimized() {
75+
Rectangle clientArea = getClientArea();
4376
Element tb = null;
4477
/**
4578
* @j2sNative
4679
* tb = this.shell.titleBar;
4780
*/ {}
4881
int h = ((shell.getStyle() & SWT.TITLE) != 0) ? OS.getContainerHeight(tb) : 0;
49-
shell.setLocation(-1, shell.getMonitor().getClientArea().height - h - 6);
82+
shell.setLocation(clientArea.x - 1, clientArea.y + clientArea.height - h - 6);
5083
}
84+
5185
public void updateMaximized() {
52-
Monitor monitor = shell.getMonitor();
53-
Rectangle area = monitor.getClientArea();
54-
int height = area.height;
55-
int width = area.width;
56-
boolean isBodyMonitor = false;
57-
/**
58-
* @j2sNative
59-
* isBodyMonitor = monitor.handle == document.body;
60-
*/ {}
61-
if (isBodyMonitor) { // update with current body client area
62-
width = document.body.parentNode.clientWidth;
63-
height = OS.getFixedBodyClientHeight();
64-
}
86+
Rectangle clientArea = getClientArea();
87+
6588
//int titleHeight = ((shell.getStyle() & SWT.TITLE) != 0) ? 20 : 0;
6689
Element tb = null;
6790
/**
@@ -71,41 +94,122 @@ public void updateMaximized() {
7194
int titleHeight = ((shell.getStyle() & SWT.TITLE) != 0) ? OS.getContainerHeight(tb) : 0;
7295
// FIXME: maximized size is not accurate
7396
//shell.setBounds(shell.computeTrim(0, 0, width + 4, height - titleHeight + 6));
74-
// boolean isOptMaximized = false;
75-
// /**
76-
// * @j2sNative
77-
// * isOptMaximized = window["ShellManager"] != null;
78-
// */ {}
79-
// if (!isOptMaximized) {
80-
// shell.setBounds(shell.computeTrim(0, 0, width, height - titleHeight));
81-
// } else {
82-
shell.setBounds(shell.computeTrim(0, -titleHeight, width, height));
83-
// }
97+
boolean disablingMaxBar = false;
98+
/**
99+
* @j2sNative
100+
* disablingMaxBar = window["swt.maximized.bar"] == false;
101+
*/ {}
102+
if (disablingMaxBar) {
103+
if (status == SWT.MAX) {
104+
shell.setBounds(shell.computeTrim(clientArea.x, clientArea.y, clientArea.width, clientArea.height - titleHeight));
105+
} else if ((status & SWT.TOP) != 0 && (status & SWT.BOTTOM) != 0) {
106+
Rectangle bounds = shell.getBounds();
107+
int shellWidth = shell.getSize().x;
108+
if ((status & SWT.LEFT) != 0) {
109+
shell.setBounds(clientArea.x, clientArea.y, shellWidth, clientArea.height + 2);
110+
} else if ((status & SWT.RIGHT) != 0) {
111+
shell.setBounds(clientArea.x + clientArea.width - shellWidth, clientArea.y, shellWidth, clientArea.height + 2);
112+
} else {
113+
shell.setBounds(bounds.x, clientArea.y, shellWidth, clientArea.height + 2);
114+
}
115+
} else if ((status & SWT.LEFT) != 0 && (status & SWT.RIGHT) != 0) {
116+
Rectangle bounds = shell.getBounds();
117+
int shellHeight = shell.getSize().y;
118+
if ((status & SWT.TOP) != 0) {
119+
shell.setBounds(clientArea.x, clientArea.y, clientArea.width + 2, shellHeight);
120+
} else if ((status & SWT.BOTTOM) != 0) {
121+
shell.setBounds(clientArea.x, clientArea.y + clientArea.height - 2 - shellHeight, clientArea.width + 2, shellHeight);
122+
} else {
123+
shell.setBounds(clientArea.x, bounds.y, clientArea.width + 2, shellHeight);
124+
}
125+
}
126+
} else {
127+
if (status == SWT.MAX) {
128+
shell.setBounds(shell.computeTrim(clientArea.x, clientArea.y - titleHeight, clientArea.width, clientArea.height));
129+
} else if ((status & SWT.TOP) != 0 && (status & SWT.BOTTOM) != 0) {
130+
Rectangle bounds = shell.getBounds();
131+
int shellWidth = shell.getSize().x;
132+
if ((status & SWT.LEFT) != 0) {
133+
shell.setBounds(clientArea.x, clientArea.y, shellWidth, clientArea.height + 2);
134+
} else if ((status & SWT.RIGHT) != 0) {
135+
shell.setBounds(clientArea.x + clientArea.width - shellWidth + 2, clientArea.y, shellWidth, clientArea.height + 2);
136+
} else {
137+
shell.setBounds(bounds.x, clientArea.y, shellWidth, clientArea.height + 2);
138+
}
139+
} else if ((status & SWT.LEFT) != 0 && (status & SWT.RIGHT) != 0) {
140+
Rectangle bounds = shell.getBounds();
141+
int shellHeight = shell.getSize().y;
142+
if ((status & SWT.TOP) != 0) {
143+
shell.setBounds(clientArea.x, clientArea.y, clientArea.width + 2, shellHeight);
144+
} else if ((status & SWT.BOTTOM) != 0) {
145+
shell.setBounds(clientArea.x, clientArea.y + clientArea.height - 2 - shellHeight, clientArea.width + 2, shellHeight);
146+
} else {
147+
shell.setBounds(clientArea.x, bounds.y, clientArea.width + 2, shellHeight);
148+
}
149+
}
150+
}
84151
// shell.setBounds(0 - 4, 0 - 4, width - 2, height + 4);
85152
//shell.setBounds(shell.computeTrim(0, 0, width + 2, height - 18));
86153
}
154+
87155
public void updateCentered() {
88-
Element tb = null;
89-
/**
90-
* @j2sNative
91-
* tb = this.shell.titleBar;
92-
*/ {}
93-
int h = ((shell.getStyle() & SWT.TITLE) != 0) ? OS.getContainerHeight(tb) : 20;
94-
// Not used now
95-
Monitor monitor = shell.getMonitor();
156+
Rectangle clientArea = getClientArea();
157+
96158
Point size = shell.getSize();
97-
int y = (monitor.getClientArea().height - size.y) / 2 - h;
159+
int y = (clientArea.height - size.y) / 2;
98160
if (y < 0) {
99161
y = 0;
100162
}
101-
shell.setLocation((monitor.getClientArea().width - size.x) / 2, y);
163+
if (status == SWT.CENTER) {
164+
if (y > 0) {
165+
y = (int) Math.round((clientArea.height - size.y) * 0.618 / 1.618);
166+
}
167+
shell.setLocation((clientArea.width - size.x) / 2 + clientArea.x, y + clientArea.y);
168+
} else if ((status & SWT.TOP) != 0){
169+
shell.setLocation((clientArea.width - size.x) / 2 + clientArea.x, clientArea.y);
170+
} else if ((status & SWT.BOTTOM) != 0){
171+
int trimWidth = (shell.getStyle() & SWT.NO_TRIM) != 0 ? 0 : 4; // 4: shadow
172+
shell.setLocation((clientArea.width - size.x) / 2 + clientArea.x, clientArea.height - 2 - size.y + clientArea.y + trimWidth);
173+
} else if ((status & SWT.LEFT) != 0){
174+
shell.setLocation(clientArea.x, y + clientArea.y);
175+
} else if ((status & SWT.RIGHT) != 0){
176+
int trimWidth = (shell.getStyle() & SWT.NO_TRIM) != 0 ? 0 : 4; // 4: shadow
177+
shell.setLocation(clientArea.width - size.x + clientArea.x + trimWidth, y + clientArea.y);
178+
}
102179
}
103-
/**
104-
* @j2sNative
105-
* this.monitor.clientWidth = document.body.parentNode.clientWidth;
106-
* this.monitor.clientHeight = O$.getFixedBodyClientHeight(); //document.body.clientHeight;
107-
*/
180+
181+
public void updateCornered() {
182+
Rectangle clientArea = getClientArea();
183+
Point size = shell.getSize();
184+
int trimWidth = (shell.getStyle() & SWT.NO_TRIM) != 0 ? 0 : 4; // 4: shadow
185+
if ((status & SWT.TOP) != 0){
186+
if ((status & SWT.LEFT) != 0) {
187+
shell.setLocation(clientArea.x, clientArea.y);
188+
} else if ((status & SWT.RIGHT) != 0) {
189+
shell.setLocation(clientArea.width - size.x + trimWidth, clientArea.y);
190+
}
191+
} else if ((status & SWT.BOTTOM) != 0){
192+
if ((status & SWT.LEFT) != 0) {
193+
shell.setLocation(clientArea.x, clientArea.height - 2 - size.y + clientArea.y + trimWidth);
194+
} else if ((status & SWT.RIGHT) != 0) {
195+
shell.setLocation(clientArea.width - size.x + trimWidth, clientArea.height - 2 - size.y + clientArea.y + trimWidth);
196+
}
197+
}
198+
}
199+
108200
public void updateMonitor() {
201+
if (monitor == null) {
202+
return;
203+
}
204+
205+
Rectangle clientArea = getClientArea();
206+
/**
207+
* @j2sNative
208+
* this.monitor.clientX = clientArea.x;
209+
* this.monitor.clientY = clientArea.y;
210+
* this.monitor.clientWidth = clientArea.width;
211+
* this.monitor.clientHeight = clientArea.height;
212+
*/ { clientArea.toString(); }
109213
}
110214

111215
public int getStatus() {

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,27 @@ public static void register(Decorations shell, int status) {
4545
return ;
4646
}
4747
}
48+
boolean ok = false;
49+
ResizeHandler hdl = new ResizeHandler(shell, status);
4850
for (int i = 0; i < handlers.length; i++) {
4951
if (handlers[i] == null) {
50-
handlers[i] = new ResizeHandler(shell, status);
51-
return ;
52+
handlers[i] = hdl;
53+
ok = true;
54+
break;
5255
}
5356
}
54-
handlers[handlers.length] = new ResizeHandler(shell, status);
57+
if (!ok) {
58+
handlers[handlers.length] = hdl;
59+
}
60+
if ((status & SWT.VIRTUAL) != 0) {
61+
hdl.updateCornered();
62+
} else if ((status & SWT.CENTER) != 0) {
63+
hdl.updateCentered();
64+
} else if ((status & SWT.MAX) != 0) {
65+
hdl.updateMaximized();
66+
} else if ((status & SWT.MIN) != 0) {
67+
hdl.updateMinimized();
68+
}
5569
return ;
5670
}
5771
public static void unregister(Decorations shell, int status) {
@@ -97,20 +111,25 @@ public static void reset() {
97111
handlers = new ResizeHandler[0];
98112
}
99113
public static void updateResize() {
114+
for (int i = 0; i < handlers.length; i++) {
115+
ResizeHandler hdl = handlers[i];
116+
if (hdl != null && hdl.monitor != null){
117+
hdl.updateMonitor();
118+
}
119+
}
100120
for (int i = 0; i < handlers.length; i++) {
101121
ResizeHandler hdl = handlers[i];
102122
if (hdl != null && hdl.shell != null && hdl.shell.handle != null) {
103-
hdl.shell._updateMonitorSize();
104123
int status = hdl.getStatus();
105-
if (status == SWT.MAX) {
124+
if ((status & SWT.VIRTUAL) != 0) { // corners!
125+
hdl.updateCornered();
126+
} else if ((status & SWT.CENTER) != 0) {
127+
hdl.updateCentered();
128+
} else if ((status & SWT.MAX) != 0) {
106129
hdl.updateMaximized();
107-
} else if (status == SWT.MIN) {
130+
} else if ((status & SWT.MIN) != 0) {
108131
hdl.updateMinimized();
109-
} else if (status == SWT.CENTER) {
110-
hdl.updateCentered();
111132
}
112-
} else if (hdl != null && hdl.monitor != null){
113-
hdl.updateMonitor();
114133
}
115134
}
116135

0 commit comments

Comments
 (0)