[Developement] Added auto scaling on resizing window (non applet mode), auto scaling in applet.
[BugFix] Wrong auto scaling in applet and application.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3293 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/src/com/tightvnc/vncviewer/VncCanvas.java b/java/src/com/tightvnc/vncviewer/VncCanvas.java
index a457469..d3a4070 100644
--- a/java/src/com/tightvnc/vncviewer/VncCanvas.java
+++ b/java/src/com/tightvnc/vncviewer/VncCanvas.java
@@ -77,6 +77,7 @@
int[] zrleTilePixels24;
ZlibInStream zrleInStream;
boolean zrleRecWarningShown = false;
+ boolean isFirstSizeAutoUpdate = true;
// Zlib encoder's data.
byte[] zlibBuf;
@@ -263,10 +264,28 @@
int fbWidth = rfb.framebufferWidth;
int fbHeight = rfb.framebufferHeight;
+ // FIXME: This part of code must be in VncViewer i think
if (viewer.options.autoScale) {
- if (!(maxWidth > 0 && maxHeight > 0)) {
- maxWidth = fbWidth;
- maxHeight = fbHeight;
+ if (viewer.inAnApplet) {
+ maxWidth = viewer.getWidth();
+ maxHeight = viewer.getHeight();
+ } else {
+ if (viewer.vncFrame != null) {
+ if (isFirstSizeAutoUpdate) {
+ isFirstSizeAutoUpdate = false;
+ Dimension screenSize = viewer.vncFrame.getToolkit().getScreenSize();
+ maxWidth = (int)screenSize.getWidth() - 100;
+ maxHeight = (int)screenSize.getHeight() - 100;
+ viewer.vncFrame.setSize(maxWidth, maxHeight);
+ } else {
+ viewer.desktopScrollPane.doLayout();
+ maxWidth = viewer.desktopScrollPane.getWidth();
+ maxHeight = viewer.desktopScrollPane.getHeight();
+ }
+ } else {
+ maxWidth = fbWidth;
+ maxHeight = fbHeight;
+ }
}
int f1 = maxWidth * 100 / fbWidth;
int f2 = maxHeight * 100 / fbHeight;
@@ -322,10 +341,18 @@
pixelsSource.setAnimated(true);
rawPixelsImage = Toolkit.getDefaultToolkit().createImage(pixelsSource);
+ // FIXME: This part of code must be in VncViewer i think
// Update the size of desktop containers.
if (viewer.inSeparateFrame) {
- if (viewer.desktopScrollPane != null)
- resizeDesktopFrame();
+ if (viewer.desktopScrollPane != null) {
+ if (!viewer.options.autoScale) {
+ resizeDesktopFrame();
+ } else {
+ setSize(scaledWidth, scaledHeight);
+ viewer.desktopScrollPane.setSize(maxWidth + 200,
+ maxHeight + 200);
+ }
+ }
} else {
setSize(scaledWidth, scaledHeight);
}
diff --git a/java/src/com/tightvnc/vncviewer/VncViewer.java b/java/src/com/tightvnc/vncviewer/VncViewer.java
index c6fa157..7b913b3 100644
--- a/java/src/com/tightvnc/vncviewer/VncViewer.java
+++ b/java/src/com/tightvnc/vncviewer/VncViewer.java
@@ -33,7 +33,7 @@
import java.net.*;
public class VncViewer extends java.applet.Applet
- implements java.lang.Runnable, WindowListener {
+ implements java.lang.Runnable, WindowListener, ComponentListener {
boolean inAnApplet = true;
boolean inSeparateFrame = false;
@@ -127,8 +127,10 @@
cursorUpdatesDef = null;
eightBitColorsDef = null;
- if (inSeparateFrame)
+ if (inSeparateFrame) {
vncFrame.addWindowListener(this);
+ vncFrame.addComponentListener(this);
+ }
rfbThread = new Thread(this);
rfbThread.start();
@@ -195,6 +197,11 @@
gbc.fill = GridBagConstraints.BOTH;
gridbag.setConstraints(desktopScrollPane, gbc);
desktopScrollPane.add(canvasPanel);
+ // If auto scale is not enabled we don't need to set first frame
+ // size to fullscreen
+ if (!options.autoScale) {
+ vc.isFirstSizeAutoUpdate = false;
+ }
// Finally, add our ScrollPane to the Frame window.
vncFrame.add(desktopScrollPane);
@@ -203,12 +210,10 @@
vc.resizeDesktopFrame();
} else {
-
// Just add the VncCanvas component to the Applet.
gridbag.setConstraints(vc, gbc);
add(vc);
validate();
-
}
if (showControls) {
@@ -985,6 +990,30 @@
public void enableInput(boolean enable) {
vc.enableInput(enable);
}
+
+ //
+ // Resize framebuffer if autoScale is enabled.
+ //
+
+ public void componentResized(ComponentEvent e) {
+ if (e.getComponent() == vncFrame) {
+ if (options.autoScale) {
+ if (vc != null) {
+ if (!vc.isFirstSizeAutoUpdate) {
+ vc.updateFramebufferSize();
+ }
+ }
+ }
+ }
+ }
+
+ //
+ // Ignore component events we're not interested in.
+ //
+
+ public void componentShown(ComponentEvent e) { }
+ public void componentMoved(ComponentEvent e) { }
+ public void componentHidden(ComponentEvent e) { }
//
// Close application properly on window close event.