35 #include <yui/YTableItem.h>
95 unsigned state = S_NORMAL );
99 std::vector<NCTableCol*> & cells,
102 unsigned state = S_NORMAL );
110 unsigned state = S_NORMAL );
117 unsigned state = S_NORMAL );
152 void SetCols( std::vector<NCTableCol*> & newCells );
170 void AddCol(
unsigned idx,
NCTableCol * item );
171 void DelCol(
unsigned idx );
193 void SetState (
const STATE s ) {
_state |= s; }
194 void ClearState(
const STATE s ) {
_state &= ~s; }
196 bool isHidden()
const {
return (
_state & S_HIDDEN ); }
197 bool isDisabled()
const {
return (
_state & S_DISABLED ); }
198 bool isSpecial()
const {
return (
_state & ( S_HIDDEN | S_DISABLED ) ); }
199 bool isActive()
const {
return (
_state & S_ACTIVE ); }
201 virtual bool isVisible()
const;
203 virtual bool isEnabled()
const {
return isVisible() && !isDisabled(); }
250 virtual unsigned Hotspot(
unsigned & at )
const { at = 0;
return 0; }
276 virtual NCTableLine * parent()
const {
return _parent; }
277 virtual NCTableLine * firstChild()
const {
return _firstChild; }
278 virtual NCTableLine * nextSibling()
const {
return _nextSibling; }
280 void setParent (
NCTableLine * newVal ) { _parent = newVal; }
281 void setFirstChild (
NCTableLine * newVal ) { _firstChild = newVal; }
282 void setNextSibling(
NCTableLine * newVal ) { _nextSibling = newVal; }
349 void assertCol(
unsigned idx );
369 friend std::ostream & operator<<( std::ostream & str,
const NCTableLine & obj );
401 mutable STATE _vstate;
408 std::string _prefixPlaceholder;
424 friend std::ostream & operator<<( std::ostream & str,
const NCTableCol & obj );
443 const NClabel & Label()
const {
return _label; }
444 virtual void SetLabel(
const NClabel & newVal ) { _label = newVal; }
445 virtual void SetLabel(
const std::string & newVal ) { _label =
NCstring( newVal ); }
453 virtual void setPrefix(
const NClabel & newVal ) { _prefix = newVal; }
454 virtual void setPrefix(
const std::string & newVal ) { _prefix =
NCstring( newVal); }
455 int prefixWidth()
const {
return _prefix.width(); }
463 virtual wsze Size()
const {
return wsze( 1, _prefix.width() + _label.width() ); }
468 NCTableLine::STATE linestate,
469 unsigned colidx )
const;
471 void stripHotkey() { _label.stripHotkey(); }
473 bool hasHotkey()
const {
return _label.hasHotkey(); }
474 unsigned char hotkey()
const {
return _label.hotkey(); }
480 NCTableLine::STATE linestate,
481 STYLE colstyle )
const ;
503 NCTableHead( std::vector<NCTableCol*> & headCells )
525 friend std::ostream & operator<<( std::ostream & str,
const NCTableStyle & obj );
529 static const chtype currentBG = (chtype) - 1;
539 bool SetStyleFrom(
const std::vector<NCstring> & head );
541 void SetSepChar(
const chtype sepChar ) { _colSepChar = sepChar; }
544 void SetSepWidth(
const unsigned sepWidth ) { _colSepWidth = sepWidth; }
546 void SetHotCol(
int hcol )
548 _hotCol = ( hcol < 0 || Cols() <= (unsigned) hcol ) ? -1 : hcol;
562 if ( _colWidth.size() < num )
564 _colWidth.resize( num, 0 );
565 _colAdjust.resize( _colWidth.size(), NC::LEFT );
576 if ( val > _colWidth[num] )
577 _colWidth[ num ] = val;
580 NC::ADJUST ColAdjust(
unsigned num )
const {
return _colAdjust[num]; }
582 unsigned Cols()
const {
return _colWidth.size(); }
584 unsigned ColWidth(
unsigned num )
const {
return _colWidth[num]; }
586 unsigned ColSepWidth()
const {
return _colSepWidth; }
588 chtype ColSepChar()
const {
return _colSepChar; }
590 unsigned HotCol()
const {
return _hotCol; }
592 const NCstyle::StList & listStyle()
const {
return _parentWidget.listStyle(); }
594 chtype getBG()
const {
return listStyle().item.plain; }
596 chtype getBG(
const NCTableLine::STATE lstate,
597 const NCTableCol::STYLE cstyle = NCTableCol::PLAIN )
const;
599 chtype highlightBG(
const NCTableLine::STATE lstate,
600 const NCTableCol::STYLE cstyle,
601 const NCTableCol::STYLE dstyle = NCTableCol::PLAIN )
const ;
603 chtype hotBG(
const NCTableLine::STATE lstate,
unsigned colidx )
const
605 return ( colidx == _hotCol ) ?
606 getBG( lstate, NCTableCol::HINT ) : currentBG;
609 const NCTableLine & Headline()
const {
return _headline; }
616 for (
unsigned i = 0; i < Cols(); ++i )
617 twidth += _colWidth[i];
620 twidth += _colSepWidth * ( Cols() - 1 );
630 std::vector<unsigned> _colWidth;
631 std::vector<NC::ADJUST> _colAdjust;
635 unsigned _colSepWidth;
658 NCTableTag( YItem *item,
bool sel =
false,
bool singleSel =
false )
662 , _singleSelection( singleSel )
665 _yitem->setData(
this );
670 virtual void SetLabel(
const NClabel & ) { ; }
675 NCTableLine::STATE linestate,
676 unsigned colidx )
const
679 NCTableCol::DrawAt( w, at, tableStyle, linestate, colidx );
685 setBkgd( w, tableStyle, linestate, DATA );
687 w.
addch( drawRect.Pos.L, drawRect.Pos.C + 1,
'x' );
691 virtual bool Selected()
const {
return _selected; }
693 virtual void SetSelected(
bool sel ) { _selected = sel; }
695 virtual bool SingleSelection()
const {
return _singleSelection; }
697 YItem *origItem()
const {
return _yitem; }
703 bool _singleSelection;
707 #endif // NCTableItem_h
int addch(const char ch)
Put attributed character to the window.
Screen dimension (screen size) in the order height, width: (H, W)
int treeLevel() const
Return the nesting level in the tree (toplevel is 0).
A string with an optional hot key.
bool isOpen(YItem *yitem) const
Return 'true' if yitem inherits YTreeItem or YTableItem and has its 'open' flag set to 'true'.
void closeBranch()
Close this tree branch.
One cell in an NCTableLine with a label and a cell-specific style.
unsigned _state
Or'ed STATE flags.
void toggleOpenClosedState()
Toggle the open/closed state of this branch.
void ResetToMinCols()
Forget sizing based on table content, resize according to headline only.
The header line of an NCTable.
ADJUST
Alignment aka justification: top/bottom, left/right, center.
unsigned Cols() const
Return the number of columns (cells) in this line.
virtual void DrawAt(NCursesWindow &w, const wrect at, NCTableStyle &tableStyle, bool active) const
Draw the header line with special attributes.
void ClearLine()
Delete all content.
bool _nested
using nested (tree-like) items?
const NClabel & prefix() const
Return the prefix that is drawn (without delimiter) before the label.
wrect prefixAdjusted(const wrect origRect) const
Return a wrect that is adjusted for the size of the prefix, i.e.
Multi-line string, with optional hotkey, drawable.
int prefixLen() const
Return the length of the prefix for tree hierarchy line graphics.
void drawPrefix(NCursesWindow &w, const wrect at, NCTableStyle &tableStyle) const
Draw the tree hierarchy line graphics prefix in _prefix in window 'w' into rectangle 'at' with style ...
const NCTableCol * GetCol(unsigned idx) const
Return a const pointer for read-only operatoins to the column (the cell) with the specified index or ...
std::vector< NCTableCol * > GetItems() const
Return all columns (cells).
void initPrefixPlaceholder()
Initialize _prefixPlaceholder, the placeholder for tree hierarchy line graphics.
std::string indentationStr() const
Return a string of a number of blanks suitable for the indentation of this tree level.
const std::string & prefixPlaceholder() const
Return a placeholder for the prefix string for this line consisting of enough blanks for the tree hie...
void MinColWidth(unsigned num, unsigned val)
Update colWidth[num] to be at least val.
void openBranch()
Open this tree branch.
virtual bool isNested() const
Return 'true' if this should be displayed as nested items, i.e.
virtual void DrawAt(NCursesWindow &w, const wrect at, NCTableStyle &tableStyle, bool active) const
int _index
unique index to identify this line
YTableItem * origItem() const
Return the YItem this line corresponds to.
bool SetStyleFrom(const std::vector< NCstring > &head)
Reset columns, setting their alignment and optionally titles.
void AssertMinCols(unsigned num)
Ensure we know width and alignment for at least num columns.
virtual bool ChangeToVisible()
Change a line that may have been invisible until now to be visible.
virtual ~NCTableLine()
Destructor.
int index() const
Return the unique index by which this line can be identified.
virtual void UpdateFormat(NCTableStyle &tableStyle)
Update TableStyle so that this line fits in.
NCTableCol * GetCol(unsigned idx)
Return a non-const pointer for read/write operations to the column (the cell) with the specified inde...
unsigned TableWidth() const
Add up the widths of columns with the separators.
virtual void setNested(bool val)
Set the 'nested' status.
NCTableTag * tagCell() const
Return the tag cell or 0 if there is none.
YItem * yitem() const
Return the YItem this line corresponds to as its base class.
One line in a NCTable with multiple cells and an optional tree hierarchy.
void setOrigItem(YTableItem *yitem)
Set the YItem this line corresponds to.
void SetSepWidth(const unsigned sepWidth)
total width of space between adjacent columns, including the separator character
Styling for a NCTable: column widths, alignment and colors.
void SetCols(unsigned idx)
Set a number of (empty) columns (cells).
std::vector< NCTableCol * > _cells
owned
NCTableTag(YItem *item, bool sel=false, bool singleSel=false)
Constructor.
void Append(NCTableCol *cell)
Append one cell.
void addToTree(NCTableLine *parent)
Add this line to the parent's tree hierarchy.
A rectangle is defined by its position and size: wpos Pos, wsze Sze.
void treeInit(NCTableLine *parentLine, YItem *yitem)
Common init for tree-related things in the constructors that have a 'parentLine' and a 'yitem' parame...
virtual bool handleInput(wint_t key)
Handle keyboard input.
NCTableLine(std::vector< NCTableCol * > &cells, int index=-1, bool nested=false, unsigned state=S_NORMAL)
Constructor: Create an NCTableLine and fill it with 'cells'.
virtual void updatePrefix()
Create the real tree hierarchy line graphics prefix and store it in _prefix.
void setTreeLevel(int newVal)
Set the tree nesting level.
void setYItem(YItem *yitem)
Set the YItem this line corresponds to.
A column (one cell) used as a selection marker: [ ]/[x] or ( )/(x).