Make scrollbar_{resize,mapping,show} methods of scrollBar_t.
authorayin <ayin>
Tue, 19 Feb 2008 10:47:03 +0000 (10:47 +0000)
committerayin <ayin>
Tue, 19 Feb 2008 10:47:03 +0000 (10:47 +0000)
src/background.C
src/command.C
src/init.C
src/main.C
src/rxvt.h
src/screen.C
src/scrollbar.C
src/scrollbar.h

index 1db709d..ccd11bf 100644 (file)
@@ -1327,7 +1327,7 @@ bgPixmap_t::apply ()
       if (target->scrollBar.win)
         {
           target->scrollBar.state = STATE_IDLE;
-          target->scrollbar_show (0);
+          target->scrollBar.show (0);
         }
 
       target->want_refresh = 1;
index 0b7667d..475fb02 100644 (file)
@@ -1017,7 +1017,7 @@ rxvt_term::flush ()
         }
 
       scr_refresh ();
-      scrollbar_show (1);
+      scrollBar.show (1);
 #ifdef USE_XIM
       IMSendSpot ();
 #endif
@@ -1538,7 +1538,7 @@ rxvt_term::x_cb (XEvent &ev)
             if (scrollBar.state && ev.xany.window == scrollBar.win)
               {
                 scrollBar.state = STATE_IDLE;
-                scrollbar_show (0);
+                scrollBar.show (0);
               }
           }
         break;
@@ -1649,7 +1649,7 @@ rxvt_term::x_cb (XEvent &ev)
             scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
                          scrollBar.size ());
             want_refresh = 1;
-            scrollbar_show (1);
+            scrollBar.show (1);
           }
         break;
     }
@@ -2068,7 +2068,7 @@ rxvt_term::button_release (XButtonEvent &ev)
   if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
     {
       scrollBar.state = STATE_IDLE;
-      scrollbar_show (0);
+      scrollBar.show (0);
     }
 
 #ifdef SELECTION_SCROLLING
@@ -2161,7 +2161,7 @@ rxvt_term::button_release (XButtonEvent &ev)
 # endif
                 {
                   scr_page (v, i);
-                  scrollbar_show (1);
+                  scrollBar.show (1);
                 }
             }
             break;
@@ -2693,7 +2693,7 @@ rxvt_term::process_escape_seq ()
       case 'c':
         mbstate.reset ();
         scr_poweron ();
-        scrollbar_show (1);
+        scrollBar.show (1);
         break;
 
         /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
@@ -3679,7 +3679,7 @@ rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs,
               break;
 #ifdef scrollBar_esc
             case scrollBar_esc:
-              if (scrollbar_mapping (state))
+              if (scrollBar.map (state))
                 {
                   resize_all_windows (0, 0, 0);
                   scr_touch (true);
index 3648785..b16099d 100644 (file)
@@ -569,7 +569,7 @@ rxvt_term::init (int argc, const char *const *argv, stringvec *envv)
 #endif
 
   if (option (Opt_scrollBar))
-    resize_scrollbar ();      /* create and map scrollbar */
+    scrollBar.resize ();      /* create and map scrollbar */
 #ifdef HAVE_BG_PIXMAP
   {
     bgPixmap.set_target (this);
index 42beb63..c6cf973 100644 (file)
@@ -980,7 +980,7 @@ rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, in
   if (fix_screen || newwidth != old_width || newheight != old_height)
     {
       if (scrollBar.state)
-        resize_scrollbar ();
+        scrollBar.resize ();
 
       XMoveResizeWindow (dpy, vt,
                          window_vt_x, window_vt_y,
index efc70f2..db8ae85 100644 (file)
@@ -1466,11 +1466,6 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen {
   int scrollbar_show_plain (int update, int last_top, int last_bot, int scrollbar_len);
 #endif
 
-  // scrollbar.C
-  void resize_scrollbar ();
-  int scrollbar_mapping (int map);
-  int scrollbar_show (int update);
-
   // xdefaults.C
   void get_options (int argc, const char *const *argv);
   int parse_keysym (const char *str, const char *arg);
index e497d72..4ce0478 100644 (file)
@@ -2480,7 +2480,7 @@ rxvt_term::scr_recolour () NOTHROW
    {
      XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
      scrollBar.state = STATE_IDLE;
-     scrollbar_show (0);
+     scrollBar.show (0);
    }
 
 #endif
index 8d03802..4506363 100644 (file)
  * Map or unmap a scrollbar.  Returns non-zero upon change of state
  */
 int
-rxvt_term::scrollbar_mapping (int map)
+scrollBar_t::map (int map)
 {
   int change = 0;
 
   if (map)
     {
-      scrollBar.state = STATE_IDLE;
+      state = STATE_IDLE;
 
-      if (!scrollBar.win)
-        resize_scrollbar ();
+      if (!win)
+        resize ();
 
-      if (scrollBar.win)
+      if (win)
         {
-          XMapWindow (dpy, scrollBar.win);
+          XMapWindow (term->dpy, win);
           change = 1;
         }
     }
   else
     {
-      scrollBar.state = 0;
-      XUnmapWindow (dpy, scrollBar.win);
+      state = 0;
+      XUnmapWindow (term->dpy, win);
       change = 1;
     }
 
@@ -60,82 +60,82 @@ rxvt_term::scrollbar_mapping (int map)
 }
 
 void
-rxvt_term::resize_scrollbar ()
+scrollBar_t::resize ()
 {
   int delayed_init = 0;
   int window_sb_x = 0;
 
-  if (option (Opt_scrollBar_right))
-    window_sb_x = szHint.width - scrollBar.total_width ();
+  if (term->option (Opt_scrollBar_right))
+    window_sb_x = term->szHint.width - total_width ();
 
-  scrollBar.update_data ();
+  update_data ();
 
-  if (!scrollBar.win)
+  if (!win)
     {
       /* create the scrollbar window */
-      scrollBar.win = XCreateSimpleWindow (dpy,
-                                           parent[0],
-                                           window_sb_x, 0,
-                                           scrollBar.total_width (),
-                                           szHint.height,
-                                           0,
-                                           pix_colors[Color_fg],
-                                           pix_colors[Color_border]);
-      XDefineCursor (dpy, scrollBar.win, scrollBar.leftptr_cursor);
-
-      XSelectInput (dpy, scrollBar.win,
+      win = XCreateSimpleWindow (term->dpy,
+                                 term->parent[0],
+                                 window_sb_x, 0,
+                                 total_width (),
+                                 term->szHint.height,
+                                 0,
+                                 term->pix_colors[Color_fg],
+                                 term->pix_colors[Color_border]);
+      XDefineCursor (term->dpy, win, leftptr_cursor);
+
+      XSelectInput (term->dpy, win,
                    ExposureMask | ButtonPressMask | ButtonReleaseMask
                    | Button1MotionMask | Button2MotionMask
                    | Button3MotionMask);
-      scrollbar_ev.start (display, scrollBar.win);
+      term->scrollbar_ev.start (term->display, win);
 
       delayed_init = 1;
     }
   else
-    XMoveResizeWindow (dpy, scrollBar.win,
+    XMoveResizeWindow (term->dpy, win,
                        window_sb_x, 0,
-                       scrollBar.total_width (), szHint.height);
+                       total_width (), term->szHint.height);
 
-  scrollbar_show (1);
+  show (1);
 
   if (delayed_init)
-    XMapWindow (dpy, scrollBar.win);
+    XMapWindow (term->dpy, win);
 }
 
 /*
  * Update current scrollbar view w.r.t. slider heights, etc.
  */
 int
-rxvt_term::scrollbar_show (int refresh)
+scrollBar_t::show (int refresh)
 {
   int ret;
 
-  if (!scrollBar.state)
+  if (!state)
     return 0;
 
   if (refresh)
     {
-      int sb_top = view_start - top_row;
-      int sb_bot = sb_top + (nrow - 1);
-      int sb_len = max (nrow - 1 - top_row, 1);
-      int sb_size = (sb_bot - sb_top) * scrollBar.size ();
-
-      scrollBar.top = (scrollBar.beg + (sb_top * scrollBar.size ()) / sb_len);
-      scrollBar.len = sb_size / sb_len + scrollBar.min_height () + (sb_size % sb_len > 0);
-      scrollBar.bot = (scrollBar.top + scrollBar.len);
+      int sb_top = term->view_start - term->top_row;
+      int sb_bot = sb_top + (term->nrow - 1);
+      int sb_len = max (term->nrow - 1 - term->top_row, 1);
+      int sb_size = (sb_bot - sb_top) * size ();
+
+      top = beg + (sb_top * size ()) / sb_len;
+      len = sb_size / sb_len + min_height () + (sb_size % sb_len > 0);
+      bot = top + len;
       /* no change */
-      if (scrollBar.top == scrollBar.last_top
-          && scrollBar.bot == scrollBar.last_bot
-          && (scrollBar.state == scrollBar.last_state
-              || !(scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)))
+      if (top == last_top
+          && bot == last_bot
+          && (state == last_state
+              || !(state == STATE_UP || state == STATE_DOWN)))
         return 0;
     }
 
-  ret = (this->*scrollBar.update) (refresh, scrollBar.last_top, scrollBar.last_bot, scrollBar.len);
+  ret = (term->*update) (refresh, last_top, last_bot, len);
 
-  scrollBar.last_top = scrollBar.top;
-  scrollBar.last_bot = scrollBar.bot;
-  scrollBar.last_state = scrollBar.state;
+  last_top = top;
+  last_bot = bot;
+  last_state = state;
 
   return ret;
 }
index 4a2c077..f14cbe7 100644 (file)
@@ -68,6 +68,9 @@ struct scrollBar_t {
   void setup (rxvt_term *);
   // update style dependent data
   void update_data ();
+  void resize ();
+  int map (int);
+  int show (int);
 
   bool upButton (int y)
   {