[11/66] Introduce methods for scrolling

Message ID 20190623224329.16060-12-tom@tromey.com
State New
Headers show
Series
  • Clean up the TUI
Related show

Commit Message

Tom Tromey June 23, 2019, 10:42 p.m.
This changes the TUI to use virtual methods on the various window
types for scrolling.  Window-specific functions for this purpose are
renamed to be methods, and the generic tui_scroll function is removed
as it is no longer called.

gdb/ChangeLog
2019-06-23  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (tui_horizontal_source_scroll):  Don't
	declare.
	* tui/tui-winsource.c
	(tui_source_window_base::do_scroll_horizontal): Rename from
	tui_horizontal_source_scroll.
	* tui/tui-windata.h (tui_vertical_data_scroll): Don't declare.
	* tui/tui-windata.c (tui_data_window::do_scroll_vertical): Rename
	from tui_vertical_data_scroll.
	* tui/tui-win.h (tui_scroll): Don't declare.
	* tui/tui-win.c (tui_win_info::forward_scroll)
	(tui_win_info::backward_scroll, tui_win_info::left_scroll)
	(tui_win_info::right_scroll): Rename and update.
	(tui_scroll_forward_command, tui_scroll_backward_command)
	(tui_scroll_left_command, tui_scroll_right_command): Update.
	(tui_scroll): Remove.
	* tui/tui-source.h: Don't declare tui_vertical_source_scroll.
	* tui/tui-source.c (tui_source_window::do_scroll_vertical): Rename
	from tui_vertical_source_scroll.
	* tui/tui-disasm.h (tui_vertical_disassem_scroll): Don't declare.
	* tui/tui-disasm.c (tui_disasm_window::do_scroll_vertical): Rename
	from tui_vertical_disassem_scroll.
	* tui/tui-data.h (struct tui_win_info) <do_scroll_vertical,
	do_scroll_horizontal>: New methods.
	<forward_scroll, backward_scroll, left_scroll, right_scroll>:
	Likewise.
	(struct tui_source_window_base): Add do_scroll_horizontal.
	(struct tui_source_window, struct tui_disasm_window): Add
	do_scroll_vertical.
	(struct tui_data_window, struct tui_cmd_window): Add
	do_scroll_horizontal and do_scroll_vertical.
	* tui/tui-command.c (tui_dispatch_ctrl_char): Use method calls.
---
 gdb/ChangeLog           |  34 +++++++++++
 gdb/tui/tui-command.c   |  12 ++--
 gdb/tui/tui-data.h      |  52 ++++++++++++++++
 gdb/tui/tui-disasm.c    |  10 ++--
 gdb/tui/tui-disasm.h    |   2 -
 gdb/tui/tui-source.c    |   8 +--
 gdb/tui/tui-source.h    |   2 -
 gdb/tui/tui-win.c       | 130 +++++++---------------------------------
 gdb/tui/tui-win.h       |   2 -
 gdb/tui/tui-windata.c   |   6 +-
 gdb/tui/tui-windata.h   |   2 -
 gdb/tui/tui-winsource.c |  15 +++--
 gdb/tui/tui-winsource.h |   3 -
 13 files changed, 134 insertions(+), 144 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/tui/tui-command.c b/gdb/tui/tui-command.c
index 76fe9dad814..9603b3cfdca 100644
--- a/gdb/tui/tui-command.c
+++ b/gdb/tui/tui-command.c
@@ -57,24 +57,24 @@  tui_dispatch_ctrl_char (unsigned int ch)
   switch (ch)
     {
     case KEY_NPAGE:
-      tui_scroll_forward (win_info, 0);
+      win_info->forward_scroll (0);
       break;
     case KEY_PPAGE:
-      tui_scroll_backward (win_info, 0);
+      win_info->backward_scroll (0);
       break;
     case KEY_DOWN:
     case KEY_SF:
-      tui_scroll_forward (win_info, 1);
+      win_info->forward_scroll (1);
       break;
     case KEY_UP:
     case KEY_SR:
-      tui_scroll_backward (win_info, 1);
+      win_info->backward_scroll (1);
       break;
     case KEY_RIGHT:
-      tui_scroll_left (win_info, 1);
+      win_info->left_scroll (1);
       break;
     case KEY_LEFT:
-      tui_scroll_right (win_info, 1);
+      win_info->right_scroll (1);
       break;
     case '\f':
       break;
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index fe00d9ed2bd..a4dce4d036b 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -268,6 +268,16 @@  protected:
   tui_win_info (enum tui_win_type type);
   DISABLE_COPY_AND_ASSIGN (tui_win_info);
 
+  /* Scroll the contents vertically.  This is only called via
+     forward_scroll and backward_scroll.  */
+  virtual void do_scroll_vertical (enum tui_scroll_direction,
+				   int num_to_scroll) = 0;
+
+  /* Scroll the contents horizontally.  This is only called via
+     left_scroll and right_scroll.  */
+  virtual void do_scroll_horizontal (enum tui_scroll_direction,
+				     int num_to_scroll) = 0;
+
 public:
 
   virtual ~tui_win_info ();
@@ -275,6 +285,14 @@  public:
   /* Clear the pertinent detail in the window.  */
   virtual void clear_detail () = 0;
 
+  /* Methods to scroll the contents of this window.  Note that they
+     are named with "_scroll" coming at the end because the more
+     obvious "scroll_forward" is defined as a macro in term.h.  */
+  void forward_scroll (int num_to_scroll);
+  void backward_scroll (int num_to_scroll);
+  void left_scroll (int num_to_scroll);
+  void right_scroll (int num_to_scroll);
+
   struct tui_gen_win_info generic;	/* General window information.  */
   union
   {
@@ -301,6 +319,9 @@  protected:
   ~tui_source_window_base () override;
   DISABLE_COPY_AND_ASSIGN (tui_source_window_base);
 
+  void do_scroll_horizontal (enum tui_scroll_direction,
+			     int num_to_scroll) override;
+
 public:
 
   void clear_detail () override;
@@ -316,6 +337,11 @@  struct tui_source_window : public tui_source_window_base
   }
 
   DISABLE_COPY_AND_ASSIGN (tui_source_window);
+
+protected:
+
+  void do_scroll_vertical (enum tui_scroll_direction,
+			   int num_to_scroll) override;
 };
 
 /* A TUI disassembly window.  */
@@ -328,6 +354,11 @@  struct tui_disasm_window : public tui_source_window_base
   }
 
   DISABLE_COPY_AND_ASSIGN (tui_disasm_window);
+
+protected:
+
+  void do_scroll_vertical (enum tui_scroll_direction,
+			   int num_to_scroll) override;
 };
 
 struct tui_data_window : public tui_win_info
@@ -337,6 +368,15 @@  struct tui_data_window : public tui_win_info
   DISABLE_COPY_AND_ASSIGN (tui_data_window);
 
   void clear_detail () override;
+
+protected:
+
+  void do_scroll_vertical (enum tui_scroll_direction,
+			   int num_to_scroll) override;
+  void do_scroll_horizontal (enum tui_scroll_direction,
+			     int num_to_scroll) override
+  {
+  }
 };
 
 struct tui_cmd_window : public tui_win_info
@@ -345,6 +385,18 @@  struct tui_cmd_window : public tui_win_info
   DISABLE_COPY_AND_ASSIGN (tui_cmd_window);
 
   void clear_detail () override;
+
+protected:
+
+  void do_scroll_vertical (enum tui_scroll_direction,
+			   int num_to_scroll) override
+  {
+  }
+
+  void do_scroll_horizontal (enum tui_scroll_direction,
+			     int num_to_scroll) override
+  {
+  }
 };
 
 extern int tui_win_is_source_type (enum tui_win_type win_type);
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 003462c2244..838f36cf295 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -373,18 +373,18 @@  tui_get_low_disassembly_address (struct gdbarch *gdbarch,
 
 /* Scroll the disassembly forward or backward vertically.  */
 void
-tui_vertical_disassem_scroll (enum tui_scroll_direction scroll_direction,
-			      int num_to_scroll)
+tui_disasm_window::do_scroll_vertical
+  (enum tui_scroll_direction scroll_direction, int num_to_scroll)
 {
-  if (TUI_DISASM_WIN->generic.content != NULL)
+  if (generic.content != NULL)
     {
-      struct gdbarch *gdbarch = TUI_DISASM_WIN->detail.source_info.gdbarch;
+      struct gdbarch *gdbarch = detail.source_info.gdbarch;
       CORE_ADDR pc;
       tui_win_content content;
       struct tui_line_or_address val;
       int dir;
 
-      content = TUI_DISASM_WIN->generic.content;
+      content = generic.content;
 
       pc = content[0]->which_element.source.line_or_addr.u.addr;
       num_to_scroll++;
diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h
index b7325917435..925c7495947 100644
--- a/gdb/tui/tui-disasm.h
+++ b/gdb/tui/tui-disasm.h
@@ -28,8 +28,6 @@ 
 extern enum tui_status tui_set_disassem_content (struct gdbarch *, CORE_ADDR);
 extern void tui_show_disassem (struct gdbarch *, CORE_ADDR);
 extern void tui_show_disassem_and_update_source (struct gdbarch *, CORE_ADDR);
-extern void tui_vertical_disassem_scroll (enum tui_scroll_direction, 
-					  int);
 extern void tui_get_begin_asm_address (struct gdbarch **, CORE_ADDR *);
 
 #endif /* TUI_TUI_DISASM_H */
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 5066c7d7b4f..5c50d2fb794 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -309,14 +309,14 @@  tui_source_is_displayed (const char *fullname)
 
 /* Scroll the source forward or backward vertically.  */
 void
-tui_vertical_source_scroll (enum tui_scroll_direction scroll_direction,
-			    int num_to_scroll)
+tui_source_window::do_scroll_vertical
+  (enum tui_scroll_direction scroll_direction, int num_to_scroll)
 {
-  if (TUI_SRC_WIN->generic.content != NULL)
+  if (generic.content != NULL)
     {
       struct tui_line_or_address l;
       struct symtab *s;
-      tui_win_content content = TUI_SRC_WIN->generic.content;
+      tui_win_content content = generic.content;
       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
 
       if (cursal.symtab == NULL)
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index 40fdac5c381..7757373a2a2 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -36,7 +36,5 @@  extern void tui_show_symtab_source (struct gdbarch *, struct symtab *,
 				    struct tui_line_or_address,
 				    int);
 extern int tui_source_is_displayed (const char *);
-extern void tui_vertical_source_scroll (enum tui_scroll_direction,
-					int);
 
 #endif /* TUI_TUI_SOURCE_H */
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 21a9946792e..4dad1443352 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -470,125 +470,41 @@  tui_set_win_focus_to (struct tui_win_info *win_info)
 
 
 void
-tui_scroll_forward (struct tui_win_info *win_to_scroll, 
-		    int num_to_scroll)
+tui_win_info::forward_scroll (int num_to_scroll)
 {
-  if (win_to_scroll != TUI_CMD_WIN)
-    {
-      int _num_to_scroll = num_to_scroll;
-
-      if (num_to_scroll == 0)
-	_num_to_scroll = win_to_scroll->generic.height - 3;
-
-      /* If we are scrolling the source or disassembly window, do a
-         "psuedo" scroll since not all of the source is in memory,
-         only what is in the viewport.  If win_to_scroll is the
-         command window do nothing since the term should handle
-         it.  */
-      if (win_to_scroll == TUI_SRC_WIN)
-	tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
-      else if (win_to_scroll == TUI_DISASM_WIN)
-	tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
-      else if (win_to_scroll == TUI_DATA_WIN)
-	tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
-    }
-}
+  if (num_to_scroll == 0)
+    num_to_scroll = generic.height - 3;
 
-void
-tui_scroll_backward (struct tui_win_info *win_to_scroll, 
-		     int num_to_scroll)
-{
-  if (win_to_scroll != TUI_CMD_WIN)
-    {
-      int _num_to_scroll = num_to_scroll;
-
-      if (num_to_scroll == 0)
-	_num_to_scroll = win_to_scroll->generic.height - 3;
-
-      /* If we are scrolling the source or disassembly window, do a
-         "psuedo" scroll since not all of the source is in memory,
-         only what is in the viewport.  If win_to_scroll is the
-         command window do nothing since the term should handle
-         it.  */
-      if (win_to_scroll == TUI_SRC_WIN)
-	tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
-      else if (win_to_scroll == TUI_DISASM_WIN)
-	tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
-      else if (win_to_scroll == TUI_DATA_WIN)
-	tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
-    }
+  do_scroll_vertical (FORWARD_SCROLL, num_to_scroll);
 }
 
-
 void
-tui_scroll_left (struct tui_win_info *win_to_scroll,
-		 int num_to_scroll)
+tui_win_info::backward_scroll (int num_to_scroll)
 {
-  if (win_to_scroll != TUI_CMD_WIN)
-    {
-      int _num_to_scroll = num_to_scroll;
-
-      if (_num_to_scroll == 0)
-	_num_to_scroll = 1;
-
-      /* If we are scrolling the source or disassembly window, do a
-         "psuedo" scroll since not all of the source is in memory,
-         only what is in the viewport. If win_to_scroll is the command
-         window do nothing since the term should handle it.  */
-      if (win_to_scroll == TUI_SRC_WIN
-	  || win_to_scroll == TUI_DISASM_WIN)
-	tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL,
-				      _num_to_scroll);
-    }
+  if (num_to_scroll == 0)
+    num_to_scroll = generic.height - 3;
+
+  do_scroll_vertical (BACKWARD_SCROLL, num_to_scroll);
 }
 
 
 void
-tui_scroll_right (struct tui_win_info *win_to_scroll, 
-		  int num_to_scroll)
+tui_win_info::left_scroll (int num_to_scroll)
 {
-  if (win_to_scroll != TUI_CMD_WIN)
-    {
-      int _num_to_scroll = num_to_scroll;
-
-      if (_num_to_scroll == 0)
-	_num_to_scroll = 1;
-
-      /* If we are scrolling the source or disassembly window, do a
-         "psuedo" scroll since not all of the source is in memory,
-         only what is in the viewport. If win_to_scroll is the command
-         window do nothing since the term should handle it.  */
-      if (win_to_scroll == TUI_SRC_WIN
-	  || win_to_scroll == TUI_DISASM_WIN)
-	tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL,
-				      _num_to_scroll);
-    }
+  if (num_to_scroll == 0)
+    num_to_scroll = 1;
+
+  do_scroll_horizontal (LEFT_SCROLL, num_to_scroll);
 }
 
 
-/* Scroll a window.  Arguments are passed through a va_list.  */
 void
-tui_scroll (enum tui_scroll_direction direction,
-	    struct tui_win_info *win_to_scroll,
-	    int num_to_scroll)
+tui_win_info::right_scroll (int num_to_scroll)
 {
-  switch (direction)
-    {
-    case FORWARD_SCROLL:
-      tui_scroll_forward (win_to_scroll, num_to_scroll);
-      break;
-    case BACKWARD_SCROLL:
-      tui_scroll_backward (win_to_scroll, num_to_scroll);
-      break;
-    case LEFT_SCROLL:
-      tui_scroll_left (win_to_scroll, num_to_scroll);
-      break;
-    case RIGHT_SCROLL:
-      tui_scroll_right (win_to_scroll, num_to_scroll);
-      break;
-    default:
-      break;
-    }
+  if (num_to_scroll == 0)
+    num_to_scroll = 1;
+
+  do_scroll_horizontal (RIGHT_SCROLL, num_to_scroll);
 }
 
 
@@ -880,7 +796,7 @@  tui_scroll_forward_command (const char *arg, int from_tty)
     parse_scrolling_args (arg, &win_to_scroll, NULL);
   else
     parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
-  tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
+  win_to_scroll->forward_scroll (num_to_scroll);
 }
 
 
@@ -896,7 +812,7 @@  tui_scroll_backward_command (const char *arg, int from_tty)
     parse_scrolling_args (arg, &win_to_scroll, NULL);
   else
     parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
-  tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
+  win_to_scroll->backward_scroll (num_to_scroll);
 }
 
 
@@ -909,7 +825,7 @@  tui_scroll_left_command (const char *arg, int from_tty)
   /* Make sure the curses mode is enabled.  */
   tui_enable ();
   parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
-  tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
+  win_to_scroll->left_scroll (num_to_scroll);
 }
 
 
@@ -922,7 +838,7 @@  tui_scroll_right_command (const char *arg, int from_tty)
   /* Make sure the curses mode is enabled.  */
   tui_enable ();
   parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
-  tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
+  win_to_scroll->right_scroll (num_to_scroll);
 }
 
 
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index 98c497eb07d..e97eb672d78 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -30,8 +30,6 @@  extern void tui_scroll_forward (struct tui_win_info *, int);
 extern void tui_scroll_backward (struct tui_win_info *, int);
 extern void tui_scroll_left (struct tui_win_info *, int);
 extern void tui_scroll_right (struct tui_win_info *, int);
-extern void tui_scroll (enum tui_scroll_direction, 
-			struct tui_win_info *, int);
 extern void tui_set_win_focus_to (struct tui_win_info *);
 extern void tui_resize_all (void);
 extern void tui_refresh_all_win (void);
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index 646adfbb74d..0c9661f1cbe 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -245,15 +245,15 @@  tui_check_data_values (struct frame_info *frame)
 
 /* Scroll the data window vertically forward or backward.  */
 void
-tui_vertical_data_scroll (enum tui_scroll_direction scroll_direction,
-			  int num_to_scroll)
+tui_data_window::do_scroll_vertical
+  (enum tui_scroll_direction scroll_direction, int num_to_scroll)
 {
   int first_element_no;
   int first_line = (-1);
 
   first_element_no = tui_first_data_item_displayed ();
   if (first_element_no 
-      < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
+      < detail.data_display_info.regs_content_count)
     first_line = tui_line_from_reg_element_no (first_element_no);
   else
     { /* Calculate the first line from the element number which is in
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index 56bf1ede9b4..c070f76c392 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -32,7 +32,5 @@  extern int tui_first_data_item_displayed (void);
 extern void tui_delete_data_content_windows (void);
 extern void tui_refresh_data_win (void);
 extern void tui_display_data_from (int, int);
-extern void tui_vertical_data_scroll (enum tui_scroll_direction, 
-				      int);
 
 #endif /* TUI_TUI_WINDATA_H */
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 20f39c4fb6e..8c269e2ec4a 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -335,26 +335,25 @@  tui_refill_source_window (struct tui_win_info *win_info)
 /* Scroll the source forward or backward horizontally.  */
 
 void
-tui_horizontal_source_scroll (struct tui_win_info *win_info,
-			      enum tui_scroll_direction direction,
-			      int num_to_scroll)
+tui_source_window_base::do_scroll_horizontal
+  (enum tui_scroll_direction direction, int num_to_scroll)
 {
-  if (win_info->generic.content != NULL)
+  if (generic.content != NULL)
     {
       int offset;
 
       if (direction == LEFT_SCROLL)
-	offset = win_info->detail.source_info.horizontal_offset
+	offset = detail.source_info.horizontal_offset
 	  + num_to_scroll;
       else
 	{
-	  offset = win_info->detail.source_info.horizontal_offset
+	  offset = detail.source_info.horizontal_offset
 	    - num_to_scroll;
 	  if (offset < 0)
 	    offset = 0;
 	}
-      win_info->detail.source_info.horizontal_offset = offset;
-      tui_refill_source_window (win_info);
+      detail.source_info.horizontal_offset = offset;
+      tui_refill_source_window (this);
     }
 }
 
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 920032b04ea..98ce75fb620 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -53,9 +53,6 @@  extern void tui_update_source_windows_with_line (struct symtab *,
 extern void tui_clear_source_content (struct tui_win_info *, int);
 extern void tui_erase_source_content (struct tui_win_info *, int);
 extern void tui_show_source_content (struct tui_win_info *);
-extern void tui_horizontal_source_scroll (struct tui_win_info *,
-					  enum tui_scroll_direction, 
-					  int);
 extern void tui_refill_source_window (struct tui_win_info *);
 extern enum tui_status tui_set_exec_info_content (struct tui_win_info *);
 extern void tui_show_exec_info_content (struct tui_win_info *);