Added DesktopWindow::resizeDesktopWindowToBuffer() method.
Now the Desktop Window resizes against the pixel buffer size
when the scale ratio changed.
This update fixes the bug with zero size of the desktop
window when it restore from minimized position.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2221 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx
index ee941fd..8265723 100644
--- a/win/vncviewer/DesktopWindow.cxx
+++ b/win/vncviewer/DesktopWindow.cxx
@@ -475,8 +475,7 @@
       // Resize child windows
       GetClientRect(handle, &r);
       if (tb.isVisible()) {
-        MoveWindow(frameHandle, 0, tb.getHeight(),
-                   r.right, r.bottom - tb.getHeight(), TRUE);
+        MoveWindow(frameHandle, 0, tb.getHeight(), r.right, r.bottom - tb.getHeight(), TRUE);
       } else {
         MoveWindow(frameHandle, 0, 0, r.right, r.bottom, TRUE);
       }
@@ -985,13 +984,13 @@
 
 void DesktopWindow::setDesktopScaleRatio(double scale_ratio) {
   buffer->setScaleRatio(scale_ratio);
-  InvalidateRect(frameHandle, 0, FALSE);
-  if (!isAutoScaling()) calculateScrollBars();
+  if (!isAutoScaling()) resizeDesktopWindowToBuffer();
   if (isToolbarEnabled()) refreshToolbarButtons();
   char *newTitle = new char[strlen(desktopName)+20];
   sprintf(newTitle, "%s @ %i%%", desktopName, getDesktopScale());
   SetWindowText(handle, TStr(newTitle));
   delete [] newTitle;
+  InvalidateRect(frameHandle, 0, FALSE);
 }
 
 void DesktopWindow::fitBufferToWindow(bool repaint) {
@@ -1139,6 +1138,28 @@
   client_size = Rect(r.left, r.top, r.right, r.bottom);
 }
 
+void DesktopWindow::resizeDesktopWindowToBuffer() {
+  RECT r;
+  DWORD style = GetWindowLong(frameHandle, GWL_STYLE) & ~(WS_VSCROLL | WS_HSCROLL);
+  DWORD style_ex = GetWindowLong(frameHandle, GWL_EXSTYLE);
+
+  // Calculate the required size of the desktop window
+  SetRect(&r, 0, 0, buffer->width(), buffer->height());
+  AdjustWindowRectEx(&r, style, FALSE, style_ex);
+  if (isToolbarEnabled())
+    r.bottom += tb.getHeight();
+  AdjustWindowRect(&r, GetWindowLong(handle, GWL_STYLE), FALSE);
+
+  // Set the required size, center the main window and clip to the current monitor
+  SetWindowPos(handle, 0, 0, 0, r.right-r.left, r.bottom-r.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE);
+  centerWindow(handle, NULL);
+  MonitorInfo mi(getMonitor());
+  mi.clipTo(handle);
+
+  // Enable/disable scrollbars as appropriate
+  calculateScrollBars();      
+}
+
 
 void
 DesktopWindow::setName(const char* name) {