Fix scrolling functionality
[WebThing.git] / WebThing.cs
index 5e2000b..ff51354 100644 (file)
@@ -65,6 +65,21 @@ namespace bytex64.WebThing {
             // based on the executable name, which I don't like.
             _Window.SetWmclass("webthing", "WebThing");  
             _Window.Role = "browser";
+            {
+                int w, h;
+
+                if (Config.Options.ContainsKey("Width"))
+                    w = Convert.ToInt32(Config.Options["Width"]);
+                else
+                    w = 640;
+
+                if (Config.Options.ContainsKey("Height"))
+                    h = Convert.ToInt32(Config.Options["Height"]);
+                else
+                    h = 480;
+
+                _Window.DefaultSize = new Gdk.Size(w, h);
+            }
             _Window.Destroyed += delegate { Quit(); };
 
             // Initialize WidgetGrid
@@ -210,5 +225,18 @@ namespace bytex64.WebThing {
             wtv.WebView.Open(uri);
             return true;
         }
+
+        public void Scroll(double x, double y) {
+            ScrolledWindow.Hadjustment.Value += x;
+            if (ScrolledWindow.Hadjustment.Value > ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize)
+                ScrolledWindow.Hadjustment.Value = ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize;
+            ScrolledWindow.Vadjustment.Value += y;
+            if (ScrolledWindow.Vadjustment.Value > ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize)
+                ScrolledWindow.Vadjustment.Value = ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize;
+        }
+
+        public void Bump(int x, int y) {
+            Scroll(x * ScrolledWindow.Hadjustment.StepIncrement, y * ScrolledWindow.Vadjustment.StepIncrement);
+        }
     }
 }