25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCTablePad.h"
28 #include "NCPopupMenu.h"
33 NCTablePad::NCTablePad(
int lines,
int cols,
const NCWidget & p )
34 :
NCPad( lines, cols, p )
37 , dirtyFormat( false )
48 NCTablePad::~NCTablePad()
55 void NCTablePad::assertLine(
unsigned idx )
63 void NCTablePad::SetLines(
unsigned idx )
68 unsigned olines = Lines();
72 for (
unsigned i = idx; i < Lines(); ++i )
78 Items.resize( idx, 0 );
80 for (
unsigned i = olines; i < Lines(); ++i )
91 void NCTablePad::SetLines( std::vector<NCTableLine*> & nItems )
96 for (
unsigned i = 0; i < Lines(); ++i )
107 void NCTablePad::AddLine(
unsigned idx,
NCTableLine * item )
118 void NCTablePad::DelLine(
unsigned idx )
122 Items[idx]->ClearLine();
129 const NCTableLine * NCTablePad::GetLine(
unsigned idx )
const
139 NCTableLine * NCTablePad::ModifyLine(
unsigned idx )
152 bool NCTablePad::SetHeadline(
const std::vector<NCstring> & head )
154 bool hascontent = ItemStyle.SetStyleFrom( head );
162 void NCTablePad::wRecoded()
170 wpos NCTablePad::CurPos()
const
172 citem.C = srect.Pos.C;
178 wsze NCTablePad::UpdateFormat()
180 yuiDebug() << std::endl;
183 ItemStyle.ResetToMinCols();
185 for (
unsigned l = 0; l < Lines(); ++l )
187 Items[l]->UpdateFormat( ItemStyle );
190 resize(
wsze( Lines(), ItemStyle.TableWidth() ) );
192 return wsze( Lines(), ItemStyle.TableWidth() );
197 int NCTablePad::DoRedraw()
205 yuiDebug() <<
"dirtyFormat " << dirtyFormat << std::endl;
218 for (
unsigned l = 0; l < Lines(); ++l )
220 Items[l]->DrawAt( *
this,
wrect(
wpos( l, 0 ), lSze ),
221 ItemStyle, ((
unsigned )citem.L == l ) );
227 Headpad.resize( 1,
width() );
231 ItemStyle.Headline().DrawAt( Headpad,
wrect(
wpos( 0, 0 ), lSze ),
245 if ( lineno < Lines() )
246 Items[lineno]->DrawAt( w, at, ItemStyle, ((
unsigned)citem.L == lineno) );
248 yuiWarning() <<
"Illegal Lineno " << lineno <<
" (" << Lines() <<
")" << std::endl;
253 int NCTablePad::setpos(
const wpos & newpos )
257 if ( dirty || dirtyFormat )
263 yuiDebug() << newpos <<
" : l " << Lines() <<
" : cl " << citem.L
265 <<
" : d " << dirty <<
" : df " << dirtyFormat << std::endl;
273 int opos = srect.Pos.C;
276 citem.L = newpos.L < 0 ? 0 : newpos.L;
278 if ((
unsigned )citem.L >= Lines() )
279 citem.L = Lines() - 1;
281 srect.Pos =
wpos( citem.L - ( drect.Sze.H - 1 ) / 2, newpos.C ).between( 0, maxspos );
291 if ( citem.L != oitem )
303 if ( srect.Pos.C != opos )
311 void NCTablePad::updateScrollHint()
313 NCPad::updateScrollHint();
318 bool NCTablePad::setItemByKey(
int key )
320 if ( HotCol() >= Cols() )
323 if ( key < 0 || UCHAR_MAX < key )
326 unsigned hcol = HotCol();
328 unsigned hkey = tolower( key );
330 for (
unsigned l = 0; l < Lines(); ++l )
332 if ( Items[l]->GetCol( hcol )->hasHotkey()
334 ( unsigned )tolower( Items[l]->GetCol( hcol )->hotkey() ) == hkey )
349 void NCTablePad::setOrder(
int col,
bool do_reverse )
354 if ( sortStrategy->getColumn() == col && do_reverse )
356 std::reverse( Items.begin(), Items.end() );
360 sortStrategy->setColumn( col );
361 sortStrategy->sort( Items.begin(), Items.end(), col );
370 bool NCTablePad::handleInput( wint_t key )
372 return NCPad::handleInput( key );
375 void NCTablePad::stripHotkeys()
377 for (
unsigned i = 0; i < Lines(); ++i )
381 Items[i]->stripHotkeys();
387 std::ostream & operator<<( std::ostream & STREAM,
const NCTablePad & OBJ )
389 STREAM <<
"TablePad: lines " << OBJ.Lines() << std::endl;
391 for (
unsigned idx = 0; idx < OBJ.Lines(); ++idx )
393 STREAM << idx <<
" " << *OBJ.GetLine( idx );
virtual void directDraw(NCursesWindow &w, const wrect at, unsigned lineno)