26 #define YUILogComponent "ncurses"
27 #include <yui/YUILog.h>
28 #include "NCTablePadBase.h"
34 :
NCPad( lines, cols, p )
38 , _dirtyFormat( false )
45 NCTablePadBase::~NCTablePadBase()
53 for (
unsigned i = 0; i <
Lines(); ++i )
62 NCTableLine * NCTablePadBase::getLineWithIndex(
unsigned idx )
const
69 if ( (
unsigned) line->
index() == idx )
76 yuiWarning() <<
"Found item with index " << idx <<
" at pos " << pos << endl;
81 yuiError() <<
"Can't find item with index " << idx << endl;
89 return getLineWithIndex( idx );
96 return getLineWithIndex( idx );
102 for (
unsigned i=0; i <
Lines(); i++ )
104 if ( (
unsigned)
_items[ i ]->index() == idx )
114 if ( idx ==
Lines() )
117 unsigned olines =
Lines();
121 for (
unsigned i = idx; i <
Lines(); ++i )
129 for (
unsigned i = olines; i <
Lines(); ++i )
144 for (
unsigned i = 0; i <
Lines(); ++i )
166 if ( idx >=
Lines() )
171 bool NCTablePadBase::SetHeadline(
const vector<NCstring> & head )
181 void NCTablePadBase::wRecoded()
195 wsze NCTablePadBase::tableSize()
204 wsze NCTablePadBase::UpdateFormat()
209 for (
unsigned i = 0; i <
Lines(); ++i )
210 _items[i]->UpdateFormat( _itemStyle );
231 for (
unsigned i = 0; i <
Lines(); ++i )
233 if (
_items[ i ]->isVisible() )
275 for (
unsigned lineNo = 0; lineNo <
visibleLines(); ++lineNo )
290 _headpad.resize( 1,
width() );
293 _itemStyle.Headline().
DrawAt( _headpad,
316 int oldPos =
srect.Pos.C;
343 if ( (
int) at <
srect.Pos.C )
347 else if ( (
int) ( at + len -
srect.Pos.C ) > drect.Sze.W )
349 srect.Pos.C = (int) at < maxspos.C ? at : maxspos.C;
379 if (
srect.Pos.C != oldPos )
415 handled = NCPad::handleInput( key );
426 bool handled =
false;
456 std::ostream & operator<<( std::ostream & str,
const NCTablePadBase & obj )
458 str <<
"TablePadBase: lines " << obj.
Lines() << std::endl;
460 for (
unsigned idx = 0; idx < obj.
Lines(); ++idx )
462 str << idx <<
" " << *obj.
GetLine( idx );
Screen dimension (screen size) in the order height, width: (H, W)
void ClearTable()
Clear all content.
void ResetToMinCols()
Forget sizing based on table content, resize according to headline only.
int findIndex(unsigned idx) const
Find the item with index 'idx' in the items and return its position.
NCTableLine * GetCurrentLine() const
Return the current line (the line at the cursor position) or 0 if there is none.
void SetLines(unsigned count)
Expand or shrink to have exactly count logical lines.
void updateVisibleItems()
Update the internal _visibleItems vector with the items that are currently visible: Clear the old con...
wpair between(const wpair &Min, const wpair &Max) const
a copy of this clamped between Min and Max
unsigned Lines() const
Return the number of table lines (logical, not screen)
int clear()
Clear the window.
virtual wpos CurPos() const
CurPos().L is the index of the selected item.
virtual void prepareRedraw()
Prepare a redraw: Update the format if needed, set the background, clear the old content.
virtual void drawHeader()
Redraw the table header.
bool _dirtyFormat
does table format (size) need recalculating?
NCTableLine * ModifyLine(unsigned idx)
Return line at idx for read-write operations and mark it as modified.
unsigned visibleLines() const
Return the number of lines that are currently visible.
virtual int setpos(const wpos &newPos)
Base function for scrolling: Move the cursor position to 'newPos' and redraw the old and the new curr...
int width() const
Number of columns in this window.
void assertLine(unsigned index)
Ensure that a line with the specified index exists.
const NCTableLine * GetLine(unsigned idx) const
Return the line at idx for read-only operations.
int currentLineNo() const
Return the current line number (the cursor position).
wpos _citem
current/cursor position
std::vector< NCTableLine * > _visibleItems
not owned
A virtual window with a real viewport (which is NCursesWindow) and a scrolling mechanism.
virtual void DrawAt(NCursesWindow &w, const wrect at, NCTableStyle &tableStyle, bool active) const
virtual void drawContentLines()
Redraw the (visible) content lines one by one.
Screen position pair in the order line, column: (L, C)
bool SetStyleFrom(const std::vector< NCstring > &head)
Reset columns, setting their alignment and optionally titles.
virtual bool currentItemHandleInput(wint_t key)
Call the current item's handleInput() method and return 'true' if the event is now handled,...
virtual bool handleInput(wint_t key)
Handle a keyboard input event.
std::vector< NCTableLine * > _items
(owned)
int index() const
Return the unique index by which this line can be identified.
bool paging() const
Whether the Pad is truncated (we're paging).
unsigned TableWidth() const
Add up the widths of columns with the separators.
One line in a NCTable with multiple cells and an optional tree hierarchy.
virtual int DoRedraw()
Redraw the pad.
A rectangle is defined by its position and size: wpos Pos, wsze Sze.
NCTablePadBase(int lines, int cols, const NCWidget &p)
Constructor.
An NCPad for an NCTable or an NCTree.
virtual bool handleInput(wint_t key)
Handle keyboard input.
void bkgdset(chtype ch)
Set the background property.
void setCurrentLineNo(int newVal)
Set the current line number (the cursor position).
wrect srect
Source rectangle: the visible part of this pad.
void AddLine(unsigned idx, NCTableLine *item)
Add item at position idx, expanding if needed.