Skip to content

Commit fde080e

Browse files
author
jossonsmith
committed
Update all shells when Browser's font size is changed.
1 parent 4f4c476 commit fde080e

1 file changed

Lines changed: 60 additions & 3 deletions

File tree

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

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

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,46 @@
113113
window.attachEvent ("onunload", function () {
114114
try {
115115
org.eclipse.swt.widgets.Display.releaseAllDisplays ();
116-
//popupAlert ("OK");
117116
} catch (e) {
118-
// popupAlert (e.message);
119-
// throw e;
120117
}
121118
return true;
122119
});
123120
}
121+
FontSizeSystem = new Object ();
122+
var fss = FontSizeSystem;
123+
fss.monitorEl = null;
124+
fss.cachedFontSize = 10;
125+
fss.isMonitoring = false;
126+
fss.initialize = function () {
127+
this.monitorEl = document.createElement ("DIV");
128+
this.monitorEl.style.cssText = "position:absolute;top:-1000px;left:-1000px;font-family:Arial, sans-serif;font-size:10pt;overflow:visible;";
129+
document.body.appendChild (this.monitorEl);
130+
this.monitorEl.appendChild (document.createTextNode ("Java2Script"));
131+
this.cachedFontSize = this.getActualFontSize ();
132+
};
133+
fss.getActualFontSize = function () {
134+
var el = this.monitorEl;
135+
return Math.max (el.offsetHeight, Math.max (el.clientHeight, el.scrollHeight));
136+
};
137+
fss.monitorFontSize = function (looping) {
138+
if (looping != true && this.isMonitoring) {
139+
return; // already monitoring.
140+
}
141+
var el = this.monitorEl;
142+
if (el == null) {
143+
this.initialize ();
144+
} else {
145+
var width = this.getActualFontSize ();
146+
if (width != this.cachedFontSize) {
147+
this.cachedFontSize = width;
148+
org.eclipse.swt.widgets.Display.updateAllShellLayouts ();
149+
}
150+
}
151+
this.isMonitoring = true;
152+
window.setTimeout (function () {
153+
FontSizeSystem.monitorFontSize (true)
154+
}, 250);
155+
};
124156
*/
125157

126158
public class Display extends Device {
@@ -419,6 +451,10 @@ public void run () {
419451
*/
420452
public Display () {
421453
this (null);
454+
/**
455+
* @j2sNative
456+
* FontSizeSystem.monitorFontSize ();
457+
*/ {}
422458
}
423459

424460
/**
@@ -433,6 +469,10 @@ public Display () {
433469
*/
434470
public Display (DeviceData data) {
435471
super (data);
472+
/**
473+
* @j2sNative
474+
* FontSizeSystem.monitorFontSize ();
475+
*/ {}
436476
}
437477

438478
/*
@@ -4279,4 +4319,21 @@ static void releaseAllDisplays() {
42794319
Default = null; // Default will be disposed in the above for loop
42804320
}
42814321

4322+
4323+
static void updateAllShellLayouts() {
4324+
if (Displays != null) {
4325+
for (int i = 0; i < Displays.length; i++) {
4326+
if (Displays[i] != null && !Displays[i].isDisposed()) {
4327+
Shell[] shells = Displays[i].getShells();
4328+
for (int j = 0; j < shells.length; j++) {
4329+
Shell shell = shells[j];
4330+
if (shell != null && !shell.isDisposed()) {
4331+
shell.layout(true, true);
4332+
}
4333+
}
4334+
}
4335+
}
4336+
}
4337+
}
4338+
42824339
}

0 commit comments

Comments
 (0)