Added the autoScaling mode implementation to the vncviewer.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@645 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx
index babcd45..00f4c10 100644
--- a/win/vncviewer/DesktopWindow.cxx
+++ b/win/vncviewer/DesktopWindow.cxx
@@ -181,7 +181,7 @@
 
 DesktopWindow::DesktopWindow(Callback* cb) 
   : buffer(0),
-    showToolbar(false),
+    showToolbar(false), autoScaling(false),
     client_size(0, 0, 16, 16), window_size(0, 0, 32, 32),
     cursorVisible(false), cursorAvailable(false), cursorInBuffer(false),
     systemCursorVisible(true), trackingMouseLeave(false),
@@ -406,7 +406,7 @@
   case WM_WINDOWPOSCHANGING:
     {
       WINDOWPOS* wpos = (WINDOWPOS*)lParam;
-      if (wpos->flags & SWP_NOSIZE)
+      if ((wpos->flags & SWP_NOSIZE) || isAutoScaling())
         break;
 
       // Work out how big the window should ideally be
@@ -469,11 +469,16 @@
       GetClientRect(frameHandle, &r);
       client_size = Rect(r.left, r.top, r.right, r.bottom);
 
-      // Determine whether scrollbars are required
-      calculateScrollBars();
+      // Perform the AutoScaling operation
+      if (isAutoScaling()) {
+        fitBufferToWindow(false);
+      } else {
+        // Determine whether scrollbars are required
+        calculateScrollBars();
+      }
 
       // Redraw if required
-      if ((!old_offset.equals(desktopToClient(Point(0, 0)))))
+      if ((!old_offset.equals(desktopToClient(Point(0, 0)))) || isAutoScaling())
         InvalidateRect(frameHandle, 0, TRUE);
     }
     break;
@@ -791,8 +796,8 @@
         // Send a pointer event to the server
         oldpos = p;
         if (buffer->isScaling()) {
-          p.x /= double(buffer->getScale()) / 100.0;
-          p.y /= double(buffer->getScale()) / 100.0;
+          p.x /= buffer->getScaleRatio();
+          p.y /= buffer->getScaleRatio();
         }
         ptr.pointerEvent(callback, p, mask);
 #ifdef WM_MOUSEWHEEL
@@ -917,6 +922,10 @@
   // Resize the backing buffer
   buffer->setSize(w, h);
 
+  // Calculate the pixel buffer aspect correlation. It's used
+  // for the autoScaling operation.
+  aspect_corr = (double)w / h;
+
   // If the window is not maximised or full-screen then resize it
   if (!(GetWindowLong(handle, GWL_STYLE) & WS_MAXIMIZE) && !fullscreenActive) {
     // Resize the window to the required size