Added DesktopWindow::fitBufferToWindow() method.
It's used to scale buffer to the vncviewer client window.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@643 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx
index f96c7e4..babcd45 100644
--- a/win/vncviewer/DesktopWindow.cxx
+++ b/win/vncviewer/DesktopWindow.cxx
@@ -946,6 +946,28 @@
   calculateScrollBars();
 }
 
+void DesktopWindow::fitBufferToWindow(bool repaint) {
+  double scale_ratio;
+  double resized_aspect_corr = double(client_size.width()) / client_size.height();
+  DWORD style = GetWindowLong(frameHandle, GWL_STYLE);
+  if (style & (WS_VSCROLL | WS_HSCROLL)) {
+    style &= ~(WS_VSCROLL | WS_HSCROLL);
+    SetWindowLong(frameHandle, GWL_STYLE, style);
+    SetWindowPos(frameHandle, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
+    // Update the cached client size
+    RECT r;
+    GetClientRect(frameHandle, &r);
+    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();
+  } else { 
+    scale_ratio = double(client_size.width()) / buffer->getSrcWidth();
+  }
+  buffer->setScaleRatio(scale_ratio);
+  if (repaint) InvalidateRect(frameHandle, 0, TRUE);
+}
+
 void
 DesktopWindow::setCursor(int w, int h, const Point& hotspot, void* data, void* mask) {
   hideLocalCursor();
diff --git a/win/vncviewer/DesktopWindow.h b/win/vncviewer/DesktopWindow.h
index f471fcc..f0db427 100644
--- a/win/vncviewer/DesktopWindow.h
+++ b/win/vncviewer/DesktopWindow.h
@@ -83,6 +83,7 @@
       void setSize(int w, int h);
       void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);}
       void setDesktopScale(int scale);
+      void fitBufferToWindow(bool repaint = true);
 
       // - 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);
@@ -236,6 +237,7 @@
 
       // Local window state
       win32::ScaledDIBSectionBuffer* buffer;
+      double aspect_corr;
       bool has_focus;
       Rect window_size;
       Rect client_size;