libyui-ncurses
 
Loading...
Searching...
No Matches
NCTablePadBase.h
1/*
2 Copyright (C) 2020 SUSE LLC
3 This library is free software; you can redistribute it and/or modify
4 it under the terms of the GNU Lesser General Public License as
5 published by the Free Software Foundation; either version 2.1 of the
6 License, or (at your option) version 3.0 of the License. This library
7 is distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 License for more details. You should have received a copy of the GNU
11 Lesser General Public License along with this library; if not, write
12 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13 Floor, Boston, MA 02110-1301 USA
14*/
15
16
17/*-/
18
19 File: NCTablePadBase.h
20
21 Authors: Michael Andres <ma@suse.de>
22 Stefan Hundhammer <shundhammer@suse.de>
23
24/-*/
25
26#ifndef NCTablePadBase_h
27#define NCTablePadBase_h
28
29#include <vector>
30#include "NCPad.h"
31#include "NCTableItem.h"
32
33class NCTableCol;
34
35
58class NCTablePadBase : public NCPad
59{
60 friend std::ostream & operator<<( std::ostream & str, const NCTablePadBase & obj );
61
62protected:
67 NCTablePadBase( int lines, int cols, const NCWidget & p );
68
69public:
70
71 virtual ~NCTablePadBase();
72
76 void ClearTable();
77
78 virtual void wRecoded();
79
81 virtual wpos CurPos() const;
82
83 wsze tableSize();
84
89 unsigned visibleLines() const { return _visibleItems.size(); }
90
91 bool SetHeadline( const std::vector<NCstring> & head );
92
93 virtual void SendHead()
94 {
95 SetHead( _headpad, srect.Pos.C );
96 _dirtyHead = false;
97 }
98
99 void SetSepChar( const chtype colSepchar )
100 {
101 _itemStyle.SetSepChar( colSepchar );
102 }
103
104 void SetSepWidth( const unsigned sepwidth )
105 {
106 _itemStyle.SetSepWidth( sepwidth );
107 }
108
109 void SetHotCol( int hcol )
110 {
111 _itemStyle.SetHotCol( hcol );
112 }
113
117 unsigned Cols() const { return _itemStyle.Cols(); }
118
122 unsigned Lines() const { return _items.size(); }
123
124 bool empty() const { return _items.empty(); }
125
126 unsigned HotCol() const { return _itemStyle.HotCol(); }
127
131 void SetLines( unsigned count );
132
133 void SetLines( std::vector<NCTableLine*> & newItems );
134
142 void AddLine( unsigned idx, NCTableLine * item );
143
147 void Append( NCTableLine * item ) { AddLine( Lines(), item ); }
148
152 void Append( std::vector<NCTableCol*> & cells, int index )
153 { AddLine( Lines(), new NCTableLine( cells, index ) ); }
154
158 const NCTableLine * GetLine( unsigned idx ) const;
159
163 NCTableLine * ModifyLine( unsigned idx );
164
169 int findIndex( unsigned idx ) const;
170
175 NCTableLine * GetCurrentLine() const;
176
187 virtual bool handleInput( wint_t key );
188
189
190private:
191
192 // Disable unwanted assignment operator and copy constructor
193
194 NCTablePadBase & operator=( const NCTablePadBase & );
196
200 NCTableLine * getLineWithIndex( unsigned idx ) const;
201
202
203protected:
204
205 virtual wsze UpdateFormat();
206
211 virtual bool currentItemHandleInput( wint_t key );
212
220 void updateVisibleItems();
221
222 void setFormatDirty() { dirty = _dirtyFormat = true; }
223
224 virtual int dirtyPad() { return setpos( CurPos() ); }
225
231 virtual int DoRedraw();
232
237 virtual void prepareRedraw();
238
242 virtual void drawContentLines();
243
247 virtual void drawHeader();
248
256 virtual int setpos( const wpos & newPos );
257
261 int currentLineNo() const { return _citem.L; }
262
266 void setCurrentLineNo( int newVal ) { _citem.L = newVal; }
267
271 int currentColNo() const { return _citem.C; }
272
276 void setCurrentColNo( int newVal ) { _citem.C = newVal; }
277
282 void assertLine( unsigned index );
283
284
285 //
286 // Data members
287 //
288
289 std::vector<NCTableLine*> _items;
290 std::vector<NCTableLine*> _visibleItems;
291 NCursesPad _headpad;
292 bool _dirtyHead;
294 NCTableStyle _itemStyle;
296};
297
298
299#endif // NCTablePadBase_h
wrect srect
Source rectangle: the visible part of this pad.
Definition NCPad.h:138
NCPad(int lines, int cols, const NCWidget &p)
Definition NCPad.cc:40
Definition NCTableItem.h:422
Definition NCTableItem.h:68
Definition NCTablePadBase.h:59
virtual bool handleInput(wint_t key)
Definition NCTablePadBase.cc:386
void updateVisibleItems()
Definition NCTablePadBase.cc:227
void Append(NCTableLine *item)
Definition NCTablePadBase.h:147
virtual int DoRedraw()
Definition NCTablePadBase.cc:239
std::vector< NCTableLine * > _visibleItems
not owned
Definition NCTablePadBase.h:290
virtual void prepareRedraw()
Definition NCTablePadBase.cc:261
void setCurrentLineNo(int newVal)
Definition NCTablePadBase.h:266
NCTableLine * GetCurrentLine() const
Definition NCTablePadBase.cc:444
void Append(std::vector< NCTableCol * > &cells, int index)
Definition NCTablePadBase.h:152
unsigned Lines() const
Definition NCTablePadBase.h:122
int currentColNo() const
Definition NCTablePadBase.h:271
unsigned Cols() const
Definition NCTablePadBase.h:117
NCTableLine * ModifyLine(unsigned idx)
Definition NCTablePadBase.cc:93
std::vector< NCTableLine * > _items
(owned)
Definition NCTablePadBase.h:289
void setCurrentColNo(int newVal)
Definition NCTablePadBase.h:276
virtual bool currentItemHandleInput(wint_t key)
Definition NCTablePadBase.cc:424
virtual void drawContentLines()
Definition NCTablePadBase.cc:271
virtual int setpos(const wpos &newPos)
Definition NCTablePadBase.cc:301
wpos _citem
current/cursor position
Definition NCTablePadBase.h:295
void AddLine(unsigned idx, NCTableLine *item)
Definition NCTablePadBase.cc:154
int currentLineNo() const
Definition NCTablePadBase.h:261
void SetLines(unsigned count)
Definition NCTablePadBase.cc:112
virtual void drawHeader()
Definition NCTablePadBase.cc:285
NCTablePadBase(int lines, int cols, const NCWidget &p)
Definition NCTablePadBase.cc:33
void ClearTable()
Definition NCTablePadBase.cc:51
const NCTableLine * GetLine(unsigned idx) const
Definition NCTablePadBase.cc:87
virtual wpos CurPos() const
CurPos().L is the index of the selected item.
Definition NCTablePadBase.cc:188
bool _dirtyFormat
does table format (size) need recalculating?
Definition NCTablePadBase.h:293
unsigned visibleLines() const
Definition NCTablePadBase.h:89
void assertLine(unsigned index)
Definition NCTablePadBase.cc:164
int findIndex(unsigned idx) const
Definition NCTablePadBase.cc:100
Styling for a NCTable: column widths, alignment and colors.
Definition NCTableItem.h:523
Definition NCWidget.h:46
static long count
Definition ncursesw.h:941
static int lines()
Definition ncursesw.h:1044
static int cols()
Definition ncursesw.h:1049
Screen position pair in the order line, column: (L, C)
Definition position.h:110
Screen dimension (screen size) in the order height, width: (H, W)
Definition position.h:154