25 #define YUILogComponent "ncurses" 26 #include <yui/YUILog.h> 27 #include "NCTablePad.h" 28 #include "NCPopupMenu.h" 35 NCTableSortDefault::sort ( std::vector<NCTableLine *>::iterator itemsBegin,
36 std::vector<NCTableLine *>::iterator itemsEnd )
38 std::sort ( itemsBegin, itemsEnd, Compare(getColumn(), isReverse()) );
43 NCTableSortDefault::Compare::operator() (
const NCTableLine * first,
46 std::wstring w1 = smartSortKey( first );
47 std::wstring w2 = smartSortKey( second );
50 long long number1 = toNumber(w1, &ok1);
51 long long number2 = toNumber(w2, &ok2);
56 return !reverse ? number1 < number2 : number1 > number2;
71 int result = std::wcscoll ( w1.c_str(), w2.c_str() );
73 return !reverse ? result < 0 : result > 0;
79 NCTableSortDefault::Compare::toNumber(
const std::wstring& s,
bool* ok)
const 95 NCTableSortDefault::Compare::smartSortKey(
const NCTableLine * tableLine )
const 97 const YTableCell* tableCell = tableLine->origItem()->cell(column);
99 if (tableCell->hasSortKey())
100 return NCstring(tableCell->sortKey()).str();
102 return tableLine->GetCol( column )->Label().getText().begin()->str();
106 NCTablePad::NCTablePad(
int lines,
int cols,
const NCWidget & p )
107 :
NCPad( lines, cols, p )
110 , dirtyFormat( false )
121 NCTablePad::~NCTablePad()
128 void NCTablePad::assertLine(
unsigned idx )
130 if ( idx >= Lines() )
136 void NCTablePad::SetLines(
unsigned idx )
138 if ( idx == Lines() )
141 unsigned olines = Lines();
145 for (
unsigned i = idx; i < Lines(); ++i )
151 Items.resize( idx, 0 );
153 for (
unsigned i = olines; i < Lines(); ++i )
164 void NCTablePad::SetLines( std::vector<NCTableLine*> & nItems )
169 for (
unsigned i = 0; i < Lines(); ++i )
180 void NCTablePad::AddLine(
unsigned idx,
NCTableLine * item )
191 void NCTablePad::DelLine(
unsigned idx )
195 Items[idx]->ClearLine();
202 const NCTableLine * NCTablePad::GetLine(
unsigned idx )
const 212 NCTableLine * NCTablePad::ModifyLine(
unsigned idx )
225 bool NCTablePad::SetHeadline(
const std::vector<NCstring> & head )
227 bool hascontent = ItemStyle.SetStyleFrom( head );
235 void NCTablePad::wRecoded()
243 wpos NCTablePad::CurPos()
const 245 citem.C = srect.Pos.C;
251 wsze NCTablePad::UpdateFormat()
256 ItemStyle.ResetToMinCols();
258 for (
unsigned l = 0; l < Lines(); ++l )
260 Items[l]->UpdateFormat( ItemStyle );
263 resize(
wsze( Lines(), ItemStyle.TableWidth() ) );
265 return wsze( Lines(), ItemStyle.TableWidth() );
270 int NCTablePad::DoRedraw()
291 for (
unsigned l = 0; l < Lines(); ++l )
293 Items[l]->DrawAt( *
this,
wrect(
wpos( l, 0 ), lSze ),
294 ItemStyle, ((
unsigned )citem.L == l ) );
300 Headpad.resize( 1,
width() );
304 ItemStyle.Headline().DrawAt( Headpad,
wrect(
wpos( 0, 0 ), lSze ),
318 if ( lineno < Lines() )
319 Items[lineno]->DrawAt(
w, at, ItemStyle, ((
unsigned)citem.L == lineno) );
321 yuiWarning() <<
"Illegal Lineno " << lineno <<
" (" << Lines() <<
")" << std::endl;
326 int NCTablePad::setpos(
const wpos & newpos )
330 if ( dirty || dirtyFormat )
337 yuiDebug() << newpos <<
" : l " << Lines() <<
" : cl " << citem.L
338 <<
" : d " << dirty <<
" : df " << dirtyFormat << std::endl;
347 int opos = srect.Pos.C;
350 citem.L = newpos.L < 0 ? 0 : newpos.L;
352 if ((
unsigned )citem.L >= Lines() )
353 citem.L = Lines() - 1;
355 srect.Pos =
wpos( citem.L - ( drect.Sze.H - 1 ) / 2, newpos.C ).between( 0, maxspos );
365 if ( citem.L != oitem )
376 if ( srect.Pos.C != opos )
384 void NCTablePad::updateScrollHint()
386 NCPad::updateScrollHint();
391 bool NCTablePad::setItemByKey(
int key )
393 if ( HotCol() >= Cols() )
396 if ( key < 0 || UCHAR_MAX < key )
399 unsigned hcol = HotCol();
401 unsigned hkey = tolower( key );
403 for (
unsigned l = 0; l < Lines(); ++l )
405 if ( Items[l]->GetCol( hcol )->hasHotkey()
406 && (unsigned) tolower( Items[l]->GetCol( hcol )->hotkey() ) == hkey )
421 void NCTablePad::setOrder(
int col,
bool do_reverse )
426 if ( sortStrategy->getColumn() != col )
428 sortStrategy->setColumn( col );
429 sortStrategy->setReverse(
false );
431 else if ( do_reverse )
433 sortStrategy->setReverse( !sortStrategy->isReverse() );
443 void NCTablePad::sort()
445 if (sortStrategy->getColumn() < 0)
448 sortStrategy->sort( Items.begin(), Items.end() );
456 bool NCTablePad::handleInput( wint_t key )
458 return NCPad::handleInput( key );
462 void NCTablePad::stripHotkeys()
464 for (
unsigned i = 0; i < Lines(); ++i )
468 Items[i]->stripHotkeys();
474 std::ostream & operator<<( std::ostream & str,
const NCTablePad & obj )
476 str <<
"TablePad: lines " << obj.Lines() << std::endl;
478 for (
unsigned idx = 0; idx < obj.Lines(); ++idx )
480 str << idx <<
" " << *obj.GetLine( idx );
int clear()
Clear the window.
void bkgdset(chtype ch)
Set the background property.
virtual void directDraw(NCursesWindow &w, const wrect at, unsigned lineno)
Directly draw a table item at a specific location.
int width() const
Number of columns in this window.
WINDOW * w
the curses WINDOW
bool pageing() const
Whether the Pad is truncated (we're pageing).