libyui-ncurses  2.57.2
NCTablePad.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  Copyright (C) 2020 SUSE LLC
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as
6  published by the Free Software Foundation; either version 2.1 of the
7  License, or (at your option) version 3.0 of the License. This library
8  is distributed in the hope that it will be useful, but WITHOUT ANY
9  WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11  License for more details. You should have received a copy of the GNU
12  Lesser General Public License along with this library; if not, write
13  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14  Floor, Boston, MA 02110-1301 USA
15 */
16 
17 
18 /*-/
19 
20  File: NCTablePad.h
21 
22  Authors: Michael Andres <ma@suse.de>
23  Stefan Hundhammer <shundhammer@suse.de>
24 
25 /-*/
26 
27 #ifndef NCTablePad_h
28 #define NCTablePad_h
29 
30 #include <iosfwd>
31 #include <vector>
32 
33 #include "NCTablePadBase.h"
34 #include "NCTableItem.h"
35 #include "NCstring.h"
36 
37 
38 /**
39  * An NCPad for an NCTable.
40  *
41  * Most of its former functionality is now handled in the NCTablePadBase base
42  * class.
43  *
44  * See also
45  * https://github.com/libyui/libyui-ncurses/blob/master/doc/nctable-and-nctree.md
46  *
47  * Notice that this class is heavily used in other selection widgets like
48  *
49  * - NCFileSelection
50  * - NCItemSelector
51  * - NCMultiSelectionBox
52  * - NCSelectionBox
53  *
54  * And the table classes from libyui-ncurses-pkg:
55  * - NCPkgTable
56  * - NCPkgLocaleTable
57  * - NCPkgRepoTable
58  *
59  * So if you change anything here, make sure to test all those classes.
60  **/
61 class NCTablePad : public NCTablePadBase
62 {
63 public:
64 
65  NCTablePad( int lines, int cols, const NCWidget & p );
66  virtual ~NCTablePad();
67 
68 public:
69 
70  /**
71  * Handle a keyboard input event. Return 'true' if the event is now
72  * handled, 'false' if it should be propagated to the parent widget.
73  *
74  * Most of the keys are now handled in the NCTablePadBase base class or in
75  * the individual items' handlers (NCTreeLine, NCTableLine). This method
76  * is mostly here as a stub for future extensions.
77  *
78  * Reimplemented from NCTablePadBase and NCPad.
79  **/
80  virtual bool handleInput( wint_t key );
81 
82  bool setItemByKey( int key );
83 
84  void AssertMinCols( unsigned num )
85  {
86  _itemStyle.AssertMinCols( num );
87  }
88 
89  void SetSepChar( const chtype colSepchar )
90  {
91  _itemStyle.SetSepChar( colSepchar );
92  }
93 
94  void SetSepWidth( const unsigned sepwidth )
95  {
96  _itemStyle.SetSepWidth( sepwidth );
97  }
98 
99  unsigned HotCol() const
100  {
101  return _itemStyle.HotCol();
102  }
103 
104  void SetHotCol( int hcol )
105  {
106  _itemStyle.SetHotCol( hcol );
107  }
108 
109  /**
110  * Find the item index in a sorted table.
111  * Return -1 if not found.
112  * An item/line remembers its insertion index.
113  *
114  * @param id the index before sorting
115  **/
116  int findIndexById( int id ) const;
117 
118  void stripHotkeys();
119 
120 
121 protected:
122 
123  /**
124  * Redraw the pad.
125  *
126  * Reimplemented from NCTablePadBase and NCPad.
127  **/
128  virtual int DoRedraw();
129 
130  virtual void directDraw( NCursesWindow & w, const wrect at, unsigned lineno );
131 
132 
133 private:
134 
135  // Disable unwanted assignment operator and copy constructor
136 
137  NCTablePad & operator=( const NCTablePad & );
138  NCTablePad( const NCTablePad & );
139 };
140 
141 
142 #endif // NCTablePad_h
NCursesWindow::lines
static int lines()
Number of lines on terminal, not window.
Definition: ncursesw.h:1044
NCursesWindow
C++ class for windows.
Definition: ncursesw.h:907
NCTablePad::DoRedraw
virtual int DoRedraw()
Redraw the pad.
Definition: NCTablePad.cc:44
NCTablePad
An NCPad for an NCTable.
Definition: NCTablePad.h:62
NCursesWindow::cols
static int cols()
Number of cols on terminal, not window.
Definition: ncursesw.h:1049
NCursesWindow::w
WINDOW * w
the curses WINDOW
Definition: ncursesw.h:949
NCWidget
Definition: NCWidget.h:46
NCTablePad::handleInput
virtual bool handleInput(wint_t key)
Handle a keyboard input event.
Definition: NCTablePad.cc:81
NCTableStyle::AssertMinCols
void AssertMinCols(unsigned num)
Ensure we know width and alignment for at least num columns.
Definition: NCTableItem.h:560
NCTablePad::findIndexById
int findIndexById(int id) const
Find the item index in a sorted table.
Definition: NCTablePad.cc:153
NCTableStyle::SetSepWidth
void SetSepWidth(const unsigned sepWidth)
total width of space between adjacent columns, including the separator character
Definition: NCTableItem.h:544
wrect
A rectangle is defined by its position and size: wpos Pos, wsze Sze.
Definition: position.h:194
NCTablePadBase
An NCPad for an NCTable or an NCTree.
Definition: NCTablePadBase.h:59
NCTablePad::directDraw
virtual void directDraw(NCursesWindow &w, const wrect at, unsigned lineno)
Directly draw a table item at a specific location.
Definition: NCTablePad.cc:67