OSDN Git Service

replace scrolled window and viewport with hbox and scrollbar
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Sat, 8 Dec 2007 15:13:46 +0000 (00:13 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Sat, 8 Dec 2007 15:13:46 +0000 (00:13 +0900)
src/FukuiNoNamari/thread_window.py
src/data/thread_window.glade

index e847dff..7688e4e 100644 (file)
@@ -96,32 +96,53 @@ class WinWrap(winwrapbase.WinWrapBase):
             layout.posY = sum_height
             x, y = layout.get_pixel_size()
             sum_height += y
             layout.posY = sum_height
             x, y = layout.get_pixel_size()
             sum_height += y
-        self.drawingarea.set_size_request(-1, sum_height)
+        self.adjustment.upper = sum_height
 
 
-    def draw_viewport(self, area):
-        gc = self.drawingarea.window.new_gc()
+    def draw_viewport(self):
+        view_y = self.adjustment.get_value()
         self.drawingarea.window.draw_rectangle(
             self.drawingarea.style.base_gc[0],
         self.drawingarea.window.draw_rectangle(
             self.drawingarea.style.base_gc[0],
-            True, area.x, area.y, area.width, area.height)
+            True, 0, 0,
+            self.drawingarea.allocation.width,
+            self.drawingarea.allocation.height)
 
 
+        gc = self.drawingarea.window.new_gc()
         for layout in self.pangolayout:
             w, h = layout.get_pixel_size()
         for layout in self.pangolayout:
             w, h = layout.get_pixel_size()
-            if ((layout.posY >= area.y and
-                layout.posY < area.y + area.height) or
-                (layout.posY + h >= area.y and
-                 layout.posY + h < area.y + area.height) or
-                (layout.posY <= area.y and layout.posY + h >= area.y)):
-                self.drawingarea.window.draw_layout(gc, 0, layout.posY, layout)
+            layout_top = layout.posY
+            layout_bottom = layout.posY + h
+            area_top = view_y
+            area_bottom = view_y + self.drawingarea.allocation.height
+            if layout_top <= area_bottom and layout_bottom >= area_top:
+                self.drawingarea.window.draw_layout(
+                    gc, 0, layout.posY - int(view_y), layout)
 
     def on_drawingarea_expose_event(self, widget, event, data=None):
 
     def on_drawingarea_expose_event(self, widget, event, data=None):
-        self.draw_viewport(event.area)
-        return True
+        self.draw_viewport()
 
     def on_drawingarea_size_allocate(self, widget, allocation, data=None):
         if allocation.width != self.drawingarea.prev_width:
             self.relayout()
             self.drawingarea.prev_width = allocation.width
 
     def on_drawingarea_size_allocate(self, widget, allocation, data=None):
         if allocation.width != self.drawingarea.prev_width:
             self.relayout()
             self.drawingarea.prev_width = allocation.width
-        return False
+        self.adjustment.page_size = self.drawingarea.allocation.height
+        self.adjustment.page_increment = self.drawingarea.allocation.height
+
+    def on_drawingarea_button_press_event(self, widget, event, data=None):
+        self.drawingarea.queue_draw()
+
+    def on_vscrollbar_value_changed(self, widget, data=None):
+        self.drawingarea.queue_draw()
+
+    def on_drawingarea_scroll_event(self, widget, event, data=None):
+        if event.direction == gtk.gdk.SCROLL_UP:
+            self.adjustment.value -= 66.476200804
+            if self.adjustment.value < self.adjustment.lower:
+                self.adjustment.value = self.adjustment.lower
+        if event.direction == gtk.gdk.SCROLL_DOWN:
+            self.adjustment.value += 66.476200804
+            max_value = self.adjustment.upper - self.adjustment.page_size
+            if self.adjustment.value > max_value:
+                self.adjustment.value = max_value
 
     def __init__(self, uri):
         self.pangolayout = []
 
     def __init__(self, uri):
         self.pangolayout = []
@@ -146,8 +167,9 @@ class WinWrap(winwrapbase.WinWrapBase):
         self.toolbar.unset_style()
         self.statusbar = self.widget_tree.get_widget("statusbar")
         self.drawingarea = self.widget_tree.get_widget("drawingarea")
         self.toolbar.unset_style()
         self.statusbar = self.widget_tree.get_widget("statusbar")
         self.drawingarea = self.widget_tree.get_widget("drawingarea")
-        self.viewport = self.drawingarea.parent
-        self.adjustment = self.viewport.get_vadjustment()
+        self.vscrollbar = self.widget_tree.get_widget("vscrollbar")
+        self.adjustment = self.vscrollbar.get_adjustment()
+        self.adjustment.step_increment = 20
 
         self.drawingarea.prev_width = 0
 
 
         self.drawingarea.prev_width = 0
 
@@ -167,6 +189,12 @@ class WinWrap(winwrapbase.WinWrapBase):
                   self.on_drawingarea_size_allocate,
                   "on_thread_window_delete_event":
                   self.on_thread_window_delete_event,
                   self.on_drawingarea_size_allocate,
                   "on_thread_window_delete_event":
                   self.on_thread_window_delete_event,
+                  "on_drawingarea_button_press_event":
+                  self.on_drawingarea_button_press_event,
+                  "on_drawingarea_scroll_event":
+                  self.on_drawingarea_scroll_event,
+                  "on_vscrollbar_value_changed":
+                  self.on_vscrollbar_value_changed,
                   "on_add_bookmark_activate": self.on_add_bookmark_activate,
                   "on_manage_bookmarks_activate": \
                   self.on_manage_bookmarks_activate,
                   "on_add_bookmark_activate": self.on_add_bookmark_activate,
                   "on_manage_bookmarks_activate": \
                   self.on_manage_bookmarks_activate,
@@ -488,6 +516,7 @@ class WinWrap(winwrapbase.WinWrapBase):
         layout.resnum = num
         self.pangolayout.append(layout)
         self.relayout()
         layout.resnum = num
         self.pangolayout.append(layout)
         self.relayout()
+        self.drawingarea.queue_draw()
 #             taglist = []
 #             if bold:
 #                 taglist.append(self.boldtag)
 #             taglist = []
 #             if bold:
 #                 taglist.append(self.boldtag)
@@ -503,7 +532,7 @@ class WinWrap(winwrapbase.WinWrapBase):
 
     def jump(self, value):
         def j():
 
     def jump(self, value):
         def j():
-            if value > self.adjustment.upper - self.viewport.allocation.height:
+            if value > self.adjustment.upper - self.adjustment.page_size:
                 self.jump_to_the_end()
             else:
                 self.adjustment.set_value(value)
                 self.jump_to_the_end()
             else:
                 self.adjustment.set_value(value)
@@ -515,7 +544,7 @@ class WinWrap(winwrapbase.WinWrapBase):
     def jump_to_the_end(self):
         def j():
             self.adjustment.set_value(
     def jump_to_the_end(self):
         def j():
             self.adjustment.set_value(
-                self.adjustment.upper - self.viewport.allocation.height)
+                self.adjustment.upper - self.adjustment.page_size)
         gobject.idle_add(j)
 #        mark = self.textbuffer.get_mark(str(num+1))
 #        if mark:
         gobject.idle_add(j)
 #        mark = self.textbuffer.get_mark(str(num+1))
 #        if mark:
index 774c417..d74aa98 100644 (file)
           </packing>
         </child>
         <child>
           </packing>
         </child>
         <child>
-          <widget class="GtkScrolledWindow" id="scrolledwindow1">
+          <widget class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-            <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
             <child>
             <child>
-              <widget class="GtkViewport" id="viewport1">
+              <widget class="GtkDrawingArea" id="drawingarea">
                 <property name="visible">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="visible">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="resize_mode">GTK_RESIZE_QUEUE</property>
-                <child>
-                  <widget class="GtkDrawingArea" id="drawingarea">
-                    <property name="visible">True</property>
-                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                    <signal name="expose_event" handler="on_drawingarea_expose_event"/>
-                    <signal name="size_allocate" handler="on_drawingarea_size_allocate"/>
-                  </widget>
-                </child>
+                <signal name="expose_event" handler="on_drawingarea_expose_event"/>
+                <signal name="button_press_event" handler="on_drawingarea_button_press_event"/>
+                <signal name="size_allocate" handler="on_drawingarea_size_allocate"/>
+                <signal name="scroll_event" handler="on_drawingarea_scroll_event"/>
               </widget>
             </child>
               </widget>
             </child>
+            <child>
+              <widget class="GtkVScrollbar" id="vscrollbar">
+                <property name="visible">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="adjustment">0 0 100 1 10 10</property>
+                <property name="restrict_to_fill_level">False</property>
+                <signal name="value_changed" handler="on_vscrollbar_value_changed"/>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
           </widget>
           <packing>
             <property name="position">2</property>
           </widget>
           <packing>
             <property name="position">2</property>