25 #define YUILogComponent "ncurses" 26 #include <yui/YUILog.h> 27 #include "NCTableItem.h" 28 #include "stringutil.h" 34 NCTableCol::NCTableCol(
const NCstring & l, STYLE st )
41 NCTableCol::~NCTableCol()
48 NCTableLine::STATE linestate,
49 STYLE colstyle )
const 51 chtype bkgdstyle = tableStyle.getBG( linestate, colstyle );
53 if ( bkgdstyle != NCTableStyle::currentBG )
64 NCTableLine::STATE linestate,
65 unsigned colidx )
const 67 chtype bg = setBkgd( w, tableStyle, linestate, style );
68 chtype hbg = tableStyle.hotBG( linestate, colidx );
70 if ( hbg == NCTableStyle::currentBG )
73 label.drawAt( w, bg, hbg, at, tableStyle.ColAdjust( colidx ) );
77 std::ostream & operator<<( std::ostream & str,
const NCTableCol & obj )
79 return str << obj.label;
86 NCTableLine::NCTableLine(
unsigned cols,
int idx,
const unsigned s )
96 NCTableLine::NCTableLine( std::vector<NCTableCol*> & nItems,
int idx,
const unsigned s )
106 void NCTableLine::setOrigItem( YTableItem *it )
109 yitem->setData(
this ) ;
113 NCTableLine::~NCTableLine()
119 void NCTableLine::assertCol(
unsigned idx )
126 void NCTableLine::SetCols(
unsigned idx )
133 for (
unsigned i = idx; i < Cols(); ++i )
139 Items.resize( idx, 0 );
143 void NCTableLine::stripHotkeys()
145 for (
unsigned i = 0; i < Cols(); ++i )
148 Items[i]->stripHotkey();
154 void NCTableLine::SetCols( std::vector<NCTableCol*> & nItems )
161 void NCTableLine::AddCol(
unsigned idx,
NCTableCol * item )
169 void NCTableLine::DelCol(
unsigned idx )
179 NCTableCol * NCTableLine::GetCol(
unsigned idx )
188 void NCTableLine::UpdateFormat(
NCTableStyle & tableStyle )
190 tableStyle.AssertMinCols( Cols() );
192 for (
unsigned c = 0; c < Cols(); ++c )
197 tableStyle.MinColWidth( c, Items[c]->Size().W );
211 vstate = S_DISABELED;
213 vstate = active ? S_ACTIVE : S_NORMAL;
216 w.
bkgdset( tableStyle.getBG( vstate ) );
218 for (
int l = 0; l < at.Sze.H; ++l )
220 w.
move( at.Pos.L + l, at.Pos.C );
224 DrawItems( w, at, tableStyle, active );
232 if ( !( at.Sze >
wsze( 0 ) ) )
239 for (
unsigned c = 0; c < Cols(); ++c )
242 if ( c && tableStyle.ColSepwidth() )
245 destWidth = tableStyle.ColSepwidth() / 2;
247 if ( destWidth < (
unsigned )lRect.Sze.W )
249 w.
bkgdset( tableStyle.getBG( vstate, NCTableCol::SEPARATOR ) );
250 w.
vline( lRect.Pos.L, lRect.Pos.C + destWidth,
251 lRect.Sze.H, tableStyle.ColSepchar() );
253 destWidth = tableStyle.ColSepwidth();
255 if ((
unsigned )lRect.Sze.W <= destWidth )
258 lRect.Pos.C += destWidth;
260 lRect.Sze.W -= destWidth;
264 destWidth = tableStyle.ColWidth( c );
266 wrect cRect( lRect );
268 lRect.Pos.C += destWidth;
269 lRect.Sze.W -= destWidth;
272 if ( lRect.Sze.W < 0 )
273 cRect.Sze.W = destWidth + lRect.Sze.W;
275 cRect.Sze.W = destWidth;
280 Items[c]->DrawAt( w, cRect, tableStyle, vstate, c );
286 std::ostream & operator<<( std::ostream & str,
const NCTableLine & obj )
288 str <<
"Line: cols " << obj.Cols() << std::endl;
290 for (
unsigned idx = 0; idx < obj.Cols(); ++idx )
292 str <<
" " << idx <<
" ";
317 w.
bkgdset( tableStyle.getBG( vstate ) );
319 for (
int l = 0; l < at.Sze.H; ++l )
321 w.
move( at.Pos.L + l, at.Pos.C );
325 DrawItems( w, at, tableStyle, active );
333 NCTableStyle::NCTableStyle(
const NCWidget & p )
339 , colSepchar( ACS_VLINE )
340 , hotCol(( unsigned ) - 1 )
345 bool NCTableStyle::SetStyleFrom(
const std::vector<NCstring> & head )
347 unsigned ncols = head.size();
349 headline.ClearLine();
350 headline.SetCols( ncols );
354 AssertMinCols( ncols );
356 bool hasContent =
false;
358 for (
unsigned i = 0; i < head.size(); ++i )
360 const std::wstring & entry( head[i].str() );
363 if ( entry.length() )
369 colAdjust[i] = NC::RIGHT;
374 colAdjust[i] = NC::CENTER;
379 colAdjust[i] = NC::LEFT;
383 yuiWarning() <<
"No style char [LRC] at beginning of '" << entry <<
"'" << std::endl;
388 NCstring coltxt = strip ? entry.substr( 1 ) : entry;
389 headline.AddCol( i,
new NCTableCol( coltxt ) );
391 if ( ! hasContent && coltxt.str().length() )
399 chtype NCTableStyle::highlightBG(
const NCTableLine::STATE lstate,
400 const NCTableCol::STYLE cstyle,
401 const NCTableCol::STYLE dstyle )
const 403 return getBG( lstate, cstyle );
406 if ( lstate == NCTableLine::S_ACTIVE
408 parw.GetState() == NC::WSactive )
409 return getBG( lstate, cstyle );
411 return getBG( lstate, dstyle );
415 chtype NCTableStyle::getBG(
const NCTableLine::STATE lstate,
416 const NCTableCol::STYLE cstyle )
const 420 case NCTableLine::S_NORMAL:
424 case NCTableCol::PLAIN:
425 return listStyle().item.plain;
427 case NCTableCol::DATA:
428 return listStyle().item.data;
430 case NCTableCol::ACTIVEDATA:
431 return listStyle().item.plain;
433 case NCTableCol::HINT:
434 return listStyle().item.hint;
436 case NCTableCol::SEPARATOR:
437 return listStyle().item.plain;
439 case NCTableCol::NONE:
445 case NCTableLine::S_ACTIVE:
449 case NCTableCol::PLAIN:
450 return listStyle().selected.plain;
452 case NCTableCol::DATA:
453 return listStyle().selected.data;
455 case NCTableCol::ACTIVEDATA:
456 return listStyle().selected.data;
458 case NCTableCol::HINT:
459 return listStyle().selected.hint;
461 case NCTableCol::SEPARATOR:
462 return listStyle().selected.plain;
464 case NCTableCol::NONE:
469 case NCTableLine::S_DISABELED:
473 case NCTableCol::PLAIN:
474 return parw.wStyle().disabledList.item.plain;
476 case NCTableCol::DATA:
477 return parw.wStyle().disabledList.item.data;
479 case NCTableCol::ACTIVEDATA:
480 return parw.wStyle().disabledList.item.plain;
482 case NCTableCol::HINT:
483 return parw.wStyle().disabledList.item.hint;
485 case NCTableCol::SEPARATOR:
486 return listStyle().item.plain;
488 case NCTableCol::NONE:
494 case NCTableLine::S_HEADLINE:
495 return listStyle().title;
498 case NCTableLine::S_HIDDEN:
507 std::ostream & operator<<( std::ostream & str,
const NCTableStyle & obj )
509 str << form(
"cols %d, sep %d (%lx)\n",
510 obj.Cols(), obj.ColSepwidth(), (
unsigned long)obj.ColSepchar() );
512 for (
unsigned i = 0; i < obj.Cols(); ++i )
514 str << form(
"%2d %d(%3d) ", i, obj.ColAdjust( i ), obj.ColWidth( i ) );
516 if ( obj.Headline().GetCol( i ) )
517 str << obj.Headline().GetCol( i )->Label();
chtype getbkgd() const
Get current background setting.
int vline(int len, chtype ch=0)
Draw a vertical line of len characters with the given character.
void bkgdset(chtype ch)
Set the background property.
int clrtoeol()
Clear to the end of the line.
int move(int y, int x)
Move cursor the this position.