1 /* 2 ** Copyright 2002, Double Precision Inc. 3 ** 4 ** See COPYING for distribution information. 5 */ 6 7 #ifndef cursesvscroll_H 8 #define cursesvscroll_H 9 10 #include "mycurses.H" 11 #include "cursescontainer.H" 12 13 // 14 // A vertically-scrolling viewport. The subclass must define getWidth() 15 // and getHeight(). 16 // 17 18 class CursesVScroll : public CursesContainer { 19 20 size_t firstRowShown; 21 22 public: 23 CursesVScroll(CursesContainer *parent); 24 ~CursesVScroll(); 25 26 // When something is deleted from the viewport, jump the view port 27 // to the top 28 29 void deleteChild(Curses *child); 30 31 // Automatically scroll the viewport to following keyboard input. 32 // This is done by overriding getCursorPosition(), calling 33 // scrollTo(), then simply subtracting the topmost row shown. 34 35 int getCursorPosition(int &row, int &col); 36 37 // 38 // Adjust for vertical scroll position: 39 // 40 41 bool writeText(const char *text, int row, int col, 42 const CursesAttr &attr) const; 43 bool writeText(const std::u32string &text, 44 int row, int col, 45 const Curses::CursesAttr &attr) const; 46 47 // 48 // Make sure the following row is visible right now. 49 // 50 void scrollTo(size_t rowNum); 51 52 // Intercept getVerticalViewport(), and return reality. 53 54 void getVerticalViewport(size_t &first_row, 55 size_t &nrows); 56 57 void erase(); 58 59 int getWidth() const; getFirstRowShown()60 size_t getFirstRowShown() const { return firstRowShown; } setFirstRowShown(size_t rowNum)61 void setFirstRowShown(size_t rowNum) 62 { 63 firstRowShown=rowNum; 64 redraw(); 65 } 66 67 private: 68 void redraw(); 69 }; 70 71 #endif 72