OSDN Git Service

prevent adjustment.value overflow
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 9 Dec 2007 20:47:13 +0000 (05:47 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 9 Dec 2007 20:47:13 +0000 (05:47 +0900)
src/FukuiNoNamari/thread_view.py

index b256795..6722770 100644 (file)
@@ -61,6 +61,7 @@ class ThreadView(gtk.HBox):
         self.pangolayout.append(pangolayout)
         x, y = pangolayout.get_pixel_size()
         self.adjustment.upper = pangolayout.posY + y
+        self.prevent_adjustment_overflow()
         self.redraw()
 
     def create_pango_layout(self, text):
@@ -82,6 +83,7 @@ class ThreadView(gtk.HBox):
             x, y = layout.get_pixel_size()
             sum_height += y
         self.adjustment.upper = sum_height
+        self.prevent_adjustment_overflow()
 
     def jump(self, value):
         if value > self.adjustment.upper - self.adjustment.page_size:
@@ -131,6 +133,17 @@ class ThreadView(gtk.HBox):
         self.adjustment.page_size = self.drawingarea.allocation.height
         self.adjustment.page_increment = self.drawingarea.allocation.height
 
+        self.prevent_adjustment_overflow()
+
+    def prevent_adjustment_overflow(self):
+        if (self.adjustment.value >
+            self.adjustment.upper - self.adjustment.page_size):
+            self.adjustment.value = (self.adjustment.upper -
+                                     self.adjustment.page_size)
+
+        if self.adjustment.value < 0:
+            self.adjustment.value = 0
+
     def on_drawingarea_button_press_event(self, widget, event, data=None):
         self.drawingarea.queue_draw()
 
@@ -147,3 +160,4 @@ class ThreadView(gtk.HBox):
             max_value = self.adjustment.upper - self.adjustment.page_size
             if self.adjustment.value > max_value:
                 self.adjustment.value = max_value
+        self.prevent_adjustment_overflow()