Fixed the bug with crashing vncviewer when it works in the 
scaling mode and scale < 10%.
Scale part of vncviewer code improvements.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2232 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx
index 5aba780..4a316ad 100644
--- a/win/vncviewer/DesktopWindow.cxx
+++ b/win/vncviewer/DesktopWindow.cxx
@@ -858,8 +858,8 @@
     // Send a pointer event to the server
     oldpos = p;
     if (buffer->isScaling()) {
-      p.x /= buffer->getScaleRatio();
-      p.y /= buffer->getScaleRatio();
+      p.x /= buffer->getScaleRatioX();
+      p.y /= buffer->getScaleRatioY();
     }
     ptr.pointerEvent(callback, p, mask);
 #ifdef WM_MOUSEWHEEL
@@ -1005,13 +1005,15 @@
 
 void DesktopWindow::setAutoScaling(bool as) { 
   autoScaling = as;
+  if (isToolbarEnabled()) refreshToolbarButtons();
   if (as) fitBufferToWindow();
 }
 
-void DesktopWindow::setDesktopScaleRatio(double scale_ratio) {
-  buffer->setScaleRatio(scale_ratio);
-  if (!isAutoScaling()) resizeDesktopWindowToBuffer();
+void DesktopWindow::setDesktopScale(int scale_) {
+  if (buffer->getScale() == scale_ || scale_ <= 0) return;
+  buffer->setScale(scale_);
   if (isToolbarEnabled()) refreshToolbarButtons();
+  if (!isAutoScaling()) resizeDesktopWindowToBuffer();
   char *newTitle = new char[strlen(desktopName)+20];
   sprintf(newTitle, "%s @ %i%%", desktopName, getDesktopScale());
   SetWindowText(handle, TStr(newTitle));
@@ -1037,7 +1039,7 @@
   } else { 
     scale_ratio = double(client_size.width()) / buffer->getSrcWidth();
   }
-  setDesktopScaleRatio(scale_ratio);
+  setDesktopScale(int(scale_ratio * 100));
 }
 
 void
diff --git a/win/vncviewer/DesktopWindow.h b/win/vncviewer/DesktopWindow.h
index bce7cf7..7a8fa2c 100644
--- a/win/vncviewer/DesktopWindow.h
+++ b/win/vncviewer/DesktopWindow.h
@@ -88,8 +88,7 @@
       void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);}
       void setAutoScaling(bool as);
       bool isAutoScaling() const { return autoScaling; }
-      void setDesktopScaleRatio(double scale_ratio);
-      void setDesktopScale(int scale) { setDesktopScaleRatio(double(scale)/100); }
+      void setDesktopScale(int scale);
       int  getDesktopScale() const { return buffer->getScale(); }
       void fitBufferToWindow(bool repaint = true);