Auto scaling mode of the vncviewer make improved.
In this mode scaling works against vncviewer window size
(instead scale factor). 
Added ScaledDIBSectionBuffer::setScaleWindowSize() and
DesktopWindow::printScale() methods.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2234 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/vncviewer/CConn.cxx b/win/vncviewer/CConn.cxx
index 0d95180..2341f76 100644
--- a/win/vncviewer/CConn.cxx
+++ b/win/vncviewer/CConn.cxx
@@ -157,6 +157,7 @@
     window->setMenuKey(options.menuKey);
     window->setDisableWinKeys(options.disableWinKeys);
     window->setShowToolbar(options.showToolbar);
+    window->printScale();
     if (options.autoScaling) {
       window->setAutoScaling(true);
     } else {
diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx
index 679964a..c7c6e61 100644
--- a/win/vncviewer/DesktopWindow.cxx
+++ b/win/vncviewer/DesktopWindow.cxx
@@ -18,6 +18,7 @@
 
 #include <windows.h>
 #include <commctrl.h>
+#include <math.h>
 #include <rfb/Configuration.h>
 #include <rfb/LogWriter.h>
 #include <rfb_win32/WMShatter.h>
@@ -1014,10 +1015,7 @@
   buffer->setScale(scale_);
   if (isToolbarEnabled()) refreshToolbarButtons();
   if (!isAutoScaling() && !isFullscreen()) resizeDesktopWindowToBuffer();
-  char *newTitle = new char[strlen(desktopName)+20];
-  sprintf(newTitle, "%s @ %i%%", desktopName, getDesktopScale());
-  SetWindowText(handle, TStr(newTitle));
-  delete [] newTitle;
+  printScale();
   InvalidateRect(frameHandle, 0, FALSE);
 }
 
@@ -1035,11 +1033,21 @@
     client_size = Rect(r.left, r.top, r.right, r.bottom);
   }
   if (resized_aspect_corr > aspect_corr) {
-    scale_ratio = double(client_size.height()) / buffer->getSrcHeight();
+    scale_ratio = (double)client_size.height() / buffer->getSrcHeight();
+    buffer->setScaleWindowSize(ceil(buffer->getSrcWidth()*scale_ratio), client_size.height());
   } else { 
-    scale_ratio = double(client_size.width()) / buffer->getSrcWidth();
+    scale_ratio = (double)client_size.width() / buffer->getSrcWidth();
+    buffer->setScaleWindowSize(client_size.width(), ceil(buffer->getSrcHeight()*scale_ratio));
   }
-  setDesktopScale(int(scale_ratio * 100));
+  printScale();
+  InvalidateRect(frameHandle, 0, FALSE);
+}
+
+void DesktopWindow::printScale() {
+  char *newTitle = new char[strlen(desktopName)+20];
+  sprintf(newTitle, "%s @ %i%%", desktopName, getDesktopScale());
+  SetWindowText(handle, TStr(newTitle));
+  delete [] newTitle;
 }
 
 void
diff --git a/win/vncviewer/DesktopWindow.h b/win/vncviewer/DesktopWindow.h
index 7a8fa2c..a6bc5df 100644
--- a/win/vncviewer/DesktopWindow.h
+++ b/win/vncviewer/DesktopWindow.h
@@ -91,6 +91,7 @@
       void setDesktopScale(int scale);
       int  getDesktopScale() const { return buffer->getScale(); }
       void fitBufferToWindow(bool repaint = true);
+      void printScale();
 
       // - Set the cursor to render when the pointer is within the desktop buffer
       void setCursor(int w, int h, const Point& hotspot, void* data, void* mask);