]> source.dussan.org Git - tigervnc.git/commitdiff
Add a scroll widget so that we can allow resizing of the main window.
authorPierre Ossman <ossman@cendio.se>
Fri, 15 Apr 2011 12:58:31 +0000 (12:58 +0000)
committerPierre Ossman <ossman@cendio.se>
Fri, 15 Apr 2011 12:58:31 +0000 (12:58 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4374 3789f03b-4d11-0410-bbf8-ca57d06f2519

vncviewer/DesktopWindow.cxx
vncviewer/DesktopWindow.h

index deae16ec99c19814e2dbe14c6fb22c372a3f4269..b8dce85600d9b6c66ca9289bc3c3ea461636e738 100644 (file)
@@ -21,6 +21,8 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <FL/Fl_Scroll.H>
+
 #include <rfb/LogWriter.h>
 
 #include "DesktopWindow.h"
@@ -37,8 +39,19 @@ DesktopWindow::DesktopWindow(int w, int h, const char *name,
                              CConn* cc_)
   : Fl_Window(w, h)
 {
+  // Allow resize
+  size_range(100, 100);
+
+  Fl_Scroll *scroll = new Fl_Scroll(0, 0, w, h);
+  scroll->color(FL_BLACK);
+
+  // Automatically adjust the scroll box to the window
+  resizable(scroll);
+
   viewport = new Viewport(w, h, serverPF, cc_);
 
+  scroll->end();
+
   callback(handleClose, this);
 
   setName(name);
@@ -101,6 +114,38 @@ void DesktopWindow::updateWindow()
 }
 
 
+void DesktopWindow::resize(int x, int y, int w, int h)
+{
+  // Deal with some scrolling corner cases:
+  //
+  // a) If the window is larger then the viewport, center the viewport.
+  // b) If the window is smaller than the viewport, make sure there is
+  //    no wasted space on the sides.
+  //
+  // FIXME: Doesn't compensate for scroll widget size properly.
+  if (w > viewport->w())
+    viewport->position((w - viewport->w()) / 2, viewport->y());
+  else {
+    if (viewport->x() > 0)
+      viewport->position(0, viewport->y());
+    else if (w > (viewport->x() + viewport->w()))
+      viewport->position(w - viewport->w(), viewport->y());
+  }
+
+  // Same thing for y axis
+  if (h > viewport->h())
+    viewport->position(viewport->x(), (h - viewport->h()) / 2);
+  else {
+    if (viewport->y() > 0)
+      viewport->position(viewport->x(), 0);
+    else if (h > (viewport->y() + viewport->h()))
+      viewport->position(viewport->x(), h - viewport->h());
+  }
+
+  Fl_Window::resize(x, y, w, h);
+}
+
+
 void DesktopWindow::handleClose(Fl_Widget *wnd, void *data)
 {
   exit_vncviewer();
index 39fb9e7bbe0b53c6a24e080c8456d3d997ed255d..e616b05bbb3f7c265cb514ee30248ca2350c5076 100644 (file)
@@ -65,6 +65,9 @@ public:
     viewport->copyRect(r, srcX, srcY);
   }
 
+  // Fl_Window callback methods
+  void resize(int x, int y, int w, int h);
+
 private:
   static void handleClose(Fl_Widget *wnd, void *data);