25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCTableItem.h"
28 #include "stringutil.h"
34 NCTableCol::NCTableCol(
const NCstring & l,
const 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 & STREAM,
const NCTableCol & OBJ )
79 return STREAM << OBJ.label;
86 NCTableLine::NCTableLine(
unsigned cols,
int idx,
const unsigned s )
95 NCTableLine::NCTableLine( std::vector<NCTableCol*> & nItems,
int idx,
const unsigned s )
104 void NCTableLine::setOrigItem( YTableItem *it )
107 yitem->setData(
this ) ;
111 NCTableLine::~NCTableLine()
117 void NCTableLine::assertCol(
unsigned idx )
124 void NCTableLine::SetCols(
unsigned idx )
131 for (
unsigned i = idx; i < Cols(); ++i )
137 Items.resize( idx, 0 );
141 void NCTableLine::stripHotkeys()
143 for (
unsigned i = 0; i < Cols(); ++i )
146 Items[i]->stripHotkey();
152 void NCTableLine::SetCols( std::vector<NCTableCol*> & nItems )
159 void NCTableLine::AddCol(
unsigned idx,
NCTableCol * item )
167 void NCTableLine::DelCol(
unsigned idx )
177 NCTableCol * NCTableLine::GetCol(
unsigned idx )
186 void NCTableLine::UpdateFormat(
NCTableStyle & tableStyle )
188 tableStyle.AssertMinCols( Cols() );
190 for (
unsigned c = 0; c < Cols(); ++c )
195 tableStyle.MinColWidth( c, Items[c]->Size().W );
209 vstate = S_DISABELED;
211 vstate = active ? S_ACTIVE : S_NORMAL;
214 w.
bkgdset( tableStyle.getBG( vstate ) );
216 for (
int l = 0; l < at.Sze.H; ++l )
218 w.
move( at.Pos.L + l, at.Pos.C );
222 DrawItems( w, at, tableStyle, active );
230 if ( !( at.Sze >
wsze( 0 ) ) )
237 for (
unsigned c = 0; c < Cols(); ++c )
240 if ( c && tableStyle.ColSepwidth() )
243 destWidth = tableStyle.ColSepwidth() / 2;
245 if ( destWidth < (
unsigned )lRect.Sze.W )
247 w.
bkgdset( tableStyle.getBG( vstate, NCTableCol::SEPARATOR ) );
248 w.
vline( lRect.Pos.L, lRect.Pos.C + destWidth,
249 lRect.Sze.H, tableStyle.ColSepchar() );
251 destWidth = tableStyle.ColSepwidth();
253 if ((
unsigned )lRect.Sze.W <= destWidth )
256 lRect.Pos.C += destWidth;
258 lRect.Sze.W -= destWidth;
262 destWidth = tableStyle.ColWidth( c );
264 wrect cRect( lRect );
266 lRect.Pos.C += destWidth;
267 lRect.Sze.W -= destWidth;
270 if ( lRect.Sze.W < 0 )
271 cRect.Sze.W = destWidth + lRect.Sze.W;
273 cRect.Sze.W = destWidth;
278 Items[c]->DrawAt( w, cRect, tableStyle, vstate, c );
284 std::ostream & operator<<( std::ostream & STREAM,
const NCTableLine & OBJ )
286 STREAM <<
"Line: cols " << OBJ.Cols() << std::endl;
288 for (
unsigned idx = 0; idx < OBJ.Cols(); ++idx )
290 STREAM <<
" " << idx <<
" ";
315 w.
bkgdset( tableStyle.getBG( vstate ) );
317 for (
int l = 0; l < at.Sze.H; ++l )
319 w.
move( at.Pos.L + l, at.Pos.C );
323 DrawItems( w, at, tableStyle, active );
331 NCTableStyle::NCTableStyle(
const NCWidget & p )
337 , colSepchar( ACS_VLINE )
338 , hotCol(( unsigned ) - 1 )
343 bool NCTableStyle::SetStyleFrom(
const std::vector<NCstring> & head )
345 unsigned ncols = head.size();
347 headline.ClearLine();
348 headline.SetCols( ncols );
352 AssertMinCols( ncols );
354 bool hasContent =
false;
356 for (
unsigned i = 0; i < head.size(); ++i )
358 const std::wstring & entry( head[i].str() );
361 if ( entry.length() )
367 colAdjust[i] = NC::RIGHT;
372 colAdjust[i] = NC::CENTER;
377 colAdjust[i] = NC::LEFT;
381 yuiWarning() <<
"No style char [LRC] at beginning of '" << entry <<
"'" << std::endl;
386 NCstring coltxt = strip ? entry.substr( 1 ) : entry;
387 headline.AddCol( i,
new NCTableCol( coltxt ) );
389 if ( ! hasContent && coltxt.str().length() )
397 chtype NCTableStyle::highlightBG(
const NCTableLine::STATE lstate,
398 const NCTableCol::STYLE cstyle,
399 const NCTableCol::STYLE dstyle )
const
401 return getBG( lstate, cstyle );
404 if ( lstate == NCTableLine::S_ACTIVE
406 parw.GetState() == NC::WSactive )
407 return getBG( lstate, cstyle );
409 return getBG( lstate, dstyle );
413 chtype NCTableStyle::getBG(
const NCTableLine::STATE lstate,
414 const NCTableCol::STYLE cstyle )
const
418 case NCTableLine::S_NORMAL:
422 case NCTableCol::PLAIN:
423 return listStyle().item.plain;
425 case NCTableCol::DATA:
426 return listStyle().item.data;
428 case NCTableCol::ACTIVEDATA:
429 return listStyle().item.plain;
431 case NCTableCol::HINT:
432 return listStyle().item.hint;
434 case NCTableCol::SEPARATOR:
435 return listStyle().item.plain;
437 case NCTableCol::NONE:
443 case NCTableLine::S_ACTIVE:
447 case NCTableCol::PLAIN:
448 return listStyle().selected.plain;
450 case NCTableCol::DATA:
451 return listStyle().selected.data;
453 case NCTableCol::ACTIVEDATA:
454 return listStyle().selected.data;
456 case NCTableCol::HINT:
457 return listStyle().selected.hint;
459 case NCTableCol::SEPARATOR:
460 return listStyle().selected.plain;
462 case NCTableCol::NONE:
467 case NCTableLine::S_DISABELED:
471 case NCTableCol::PLAIN:
472 return parw.wStyle().disabledList.item.plain;
474 case NCTableCol::DATA:
475 return parw.wStyle().disabledList.item.data;
477 case NCTableCol::ACTIVEDATA:
478 return parw.wStyle().disabledList.item.plain;
480 case NCTableCol::HINT:
481 return parw.wStyle().disabledList.item.hint;
483 case NCTableCol::SEPARATOR:
484 return listStyle().item.plain;
486 case NCTableCol::NONE:
492 case NCTableLine::S_HEADLINE:
493 return listStyle().title;
496 case NCTableLine::S_HIDDEN:
505 std::ostream & operator<<( std::ostream & STREAM,
const NCTableStyle & OBJ )
507 STREAM << form(
"cols %d, sep %d (%lx)\n",
508 OBJ.Cols(), OBJ.ColSepwidth(), (
unsigned long)OBJ.ColSepchar() );
510 for (
unsigned i = 0; i < OBJ.Cols(); ++i )
512 STREAM << form(
"%2d %d(%3d) ", i, OBJ.ColAdjust( i ), OBJ.ColWidth( i ) );
514 if ( OBJ.Headline().GetCol( i ) )
515 STREAM << OBJ.Headline().GetCol( i )->Label();
int vline(int len, chtype ch=0)