27 #define YUILogComponent "ncurses"
28 #include <yui/YUILog.h>
29 #include "NCTableItem.h"
31 #include "stringutil.h"
62 std::vector<NCTableCol*> & cells,
72 , _parent( parentLine )
82 if ( ! cells.empty() && nested )
83 cells[0]->setPrefix( _prefixPlaceholder );
100 , _vstate( S_HIDDEN )
119 , _parent( parentLine )
122 , _vstate( S_HIDDEN )
141 _parent = parentLine;
150 SetState( S_HIDDEN );
183 if ( parent->firstChild() )
189 while ( lastChild->nextSibling() )
190 lastChild = lastChild->nextSibling();
192 lastChild->setNextSibling(
this );
196 parent->setFirstChild(
this );
207 YTreeItem * treeItem =
dynamic_cast<YTreeItem *
>(
yitem );
210 return treeItem->isOpen();
234 void NCTableLine::assertCol(
unsigned idx )
248 for (
unsigned i = idx; i <
Cols(); ++i )
258 void NCTableLine::stripHotkeys()
260 for (
unsigned i = 0; i <
Cols(); ++i )
275 void NCTableLine::AddCol(
unsigned idx,
NCTableCol * cell )
283 void NCTableLine::DelCol(
unsigned idx )
306 for (
unsigned col = 0; col <
Cols(); ++col )
329 _vstate = S_DISABLED;
331 _vstate = active ? S_ACTIVE : S_NORMAL;
334 w.
bkgdset( tableStyle.getBG( _vstate ) );
336 for (
int i = 0; i < at.Sze.H; ++i )
338 w.
move( at.Pos.L + i, at.Pos.C );
342 DrawItems( w, at, tableStyle, active );
351 if ( !( at.Sze >
wsze( 0 ) ) )
357 for (
unsigned col = 0; col <
Cols(); ++col )
359 if ( col > 0 && tableStyle.ColSepWidth() )
362 destWidth = tableStyle.ColSepWidth() / 2;
364 if ( destWidth < (
unsigned) lRect.Sze.W )
366 w.
bkgdset( tableStyle.getBG( _vstate, NCTableCol::SEPARATOR ) );
367 w.
vline( lRect.Pos.L, lRect.Pos.C + destWidth,
368 lRect.Sze.H, tableStyle.ColSepChar() );
370 destWidth = tableStyle.ColSepWidth();
372 if ( (
unsigned) lRect.Sze.W <= destWidth )
375 lRect.Pos.C += destWidth;
376 lRect.Sze.W -= destWidth;
380 destWidth = tableStyle.ColWidth( col );
382 wrect cRect( lRect );
385 lRect.Pos.C += destWidth;
386 lRect.Sze.W -= destWidth;
388 if ( lRect.Sze.W < 0 )
389 cRect.Sze.W = destWidth + lRect.Sze.W;
391 cRect.Sze.W = destWidth;
396 _cells[ col ]->DrawAt( w, cRect, tableStyle, _vstate, col );
400 if ( col == 0 && _prefix )
415 chtype * tagend = &_prefix[
prefixLen()-1 ];
416 *tagend-- = ACS_HLINE;
417 *tagend-- = firstChild() ? ACS_TTEE : ACS_HLINE;
423 *tagend-- = nextSibling() ? ACS_LTEE : ACS_LLCORNER;
429 for (
NCTableLine * p = parent(); p; p = p->parent() )
431 *tagend-- = p->nextSibling() ? ACS_VLINE : (
' '&A_CHARTEXT );
436 *tagend-- = ACS_HLINE;
448 w.
move( at.Pos.L, at.Pos.C );
451 w.
addch( _prefix[i] );
458 if ( firstChild() && !isSpecial() )
460 w.
bkgdset( tableStyle.highlightBG( _vstate,
462 NCTableCol::SEPARATOR ) );
465 if ( firstChild() && !firstChild()->isVisible() )
474 bool handled =
false;
479 yuiMilestone() <<
_yitem <<
": index: " <<
index() << endl;
517 if ( firstChild() && ! firstChild()->isVisible() )
521 YTreeItem * treeItem =
dynamic_cast<YTreeItem *
>(
_yitem );
525 treeItem->setOpen(
true );
526 yuiDebug() <<
"Opening item " << treeItem->label() << endl;
528 for (
NCTableLine * child = firstChild(); child; child = child->nextSibling() )
529 child->ClearState( S_HIDDEN );
537 if ( firstChild() && firstChild()->isVisible() )
541 YTreeItem * treeItem =
dynamic_cast<YTreeItem *
>(
_yitem );
545 treeItem->setOpen(
false );
546 yuiDebug() <<
"Closing item " << treeItem->label() << endl;
548 for (
NCTableLine * child = firstChild(); child; child = child->nextSibling() )
549 child->SetState( S_HIDDEN );
559 if ( firstChild()->isVisible() )
567 bool NCTableLine::isVisible()
const
569 return ! parent() || ( !isHidden() && parent()->isVisible() );
585 std::ostream & operator<<( std::ostream & str,
const NCTableLine & obj )
587 str <<
"Line: cols " << obj.
Cols() << endl;
589 for (
unsigned idx = 0; idx < obj.
Cols(); ++idx )
591 str <<
" " << idx <<
" ";
612 NCTableCol::NCTableCol(
const NCstring & label, STYLE style )
619 NCTableCol::~NCTableCol()
626 NCTableLine::STATE linestate,
627 STYLE colstyle )
const
629 chtype bkgdstyle = tableStyle.getBG( linestate, colstyle );
631 if ( bkgdstyle != NCTableStyle::currentBG )
642 wrect newRect = origRect;
644 if ( _prefix.width() > 0 )
646 newRect.Pos.C += _prefix.width();
647 newRect.Sze.W -= _prefix.width();
657 NCTableLine::STATE linestate,
658 unsigned colidx )
const
660 chtype bg = setBkgd( w, tableStyle, linestate, _style );
661 chtype hbg = tableStyle.hotBG( linestate, colidx );
663 if ( hbg == NCTableStyle::currentBG )
666 if ( _prefix.width() > 0 )
667 _prefix.drawAt( w, bg, hbg, at );
669 _label.drawAt( w, bg, hbg,
671 tableStyle.ColAdjust( colidx ) );
675 std::ostream & operator<<( std::ostream & str,
const NCTableCol & obj )
677 return str << obj._label;
691 _vstate = S_HEADLINE;
692 w.
bkgdset( tableStyle.getBG( _vstate ) );
694 for (
int i = 0; i < at.Sze.H; ++i )
696 w.
move( at.Pos.L + i, at.Pos.C );
700 DrawItems( w, at, tableStyle, active );
709 NCTableStyle::NCTableStyle(
const NCWidget & parentWidget )
710 : _parentWidget( parentWidget )
715 , _colSepChar( ACS_VLINE )
716 , _hotCol( (unsigned) - 1 )
723 unsigned ncols = head.size();
732 bool hasContent =
false;
734 for (
unsigned i = 0; i < head.size(); ++i )
736 const wstring & entry( head[i].str() );
739 if ( entry.length() )
745 _colAdjust[i] = NC::RIGHT;
750 _colAdjust[i] = NC::CENTER;
755 _colAdjust[i] = NC::LEFT;
759 yuiWarning() <<
"No style char [LRC] at beginning of '" << entry <<
"'" << std::endl;
764 NCstring coltxt = strip ? entry.substr( 1 ) : entry;
765 _headline.AddCol( i,
new NCTableCol( coltxt ) );
767 if ( ! hasContent && coltxt.str().length() )
775 chtype NCTableStyle::highlightBG(
const NCTableLine::STATE lstate,
776 const NCTableCol::STYLE cstyle,
777 const NCTableCol::STYLE dstyle )
const
779 return getBG( lstate, cstyle );
783 chtype NCTableStyle::getBG(
const NCTableLine::STATE lstate,
784 const NCTableCol::STYLE cstyle )
const
788 case NCTableLine::S_NORMAL:
792 case NCTableCol::PLAIN:
return listStyle().item.plain;
793 case NCTableCol::DATA:
return listStyle().item.data;
794 case NCTableCol::ACTIVEDATA:
return listStyle().item.plain;
795 case NCTableCol::HINT:
return listStyle().item.hint;
796 case NCTableCol::SEPARATOR:
return listStyle().item.plain;
797 case NCTableCol::NONE:
return currentBG;
802 case NCTableLine::S_ACTIVE:
806 case NCTableCol::PLAIN:
return listStyle().selected.plain;
807 case NCTableCol::DATA:
return listStyle().selected.data;
808 case NCTableCol::ACTIVEDATA:
return listStyle().selected.data;
809 case NCTableCol::HINT:
return listStyle().selected.hint;
810 case NCTableCol::SEPARATOR:
return listStyle().selected.plain;
811 case NCTableCol::NONE:
return currentBG;
815 case NCTableLine::S_DISABLED:
819 case NCTableCol::PLAIN:
return _parentWidget.wStyle().disabledList.item.plain;
820 case NCTableCol::DATA:
return _parentWidget.wStyle().disabledList.item.data;
821 case NCTableCol::ACTIVEDATA:
return _parentWidget.wStyle().disabledList.item.plain;
822 case NCTableCol::HINT:
return _parentWidget.wStyle().disabledList.item.hint;
823 case NCTableCol::SEPARATOR:
return listStyle().item.plain;
824 case NCTableCol::NONE:
return currentBG;
829 case NCTableLine::S_HEADLINE:
830 return listStyle().title;
833 case NCTableLine::S_HIDDEN:
842 std::ostream & operator<<( std::ostream & str,
const NCTableStyle & obj )
844 str << form(
"cols %d, sep %d (%lx)\n",
845 obj.Cols(), obj.ColSepWidth(), (
unsigned long)obj.ColSepChar() );
847 for (
unsigned i = 0; i < obj.Cols(); ++i )
849 str << form(
"%2d %d(%3d) ", i, obj.ColAdjust( i ), obj.ColWidth( i ) );
851 if ( obj.Headline().
GetCol( i ) )
852 str << obj.Headline().
GetCol( i )->Label();