25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCTreePad.h"
31 NCTreePad::NCTreePad(
int lines,
int cols,
const NCWidget & p )
32 :
NCPad( lines, cols, p )
35 , dirtyFormat( false )
46 NCTreePad::~NCTreePad()
53 void NCTreePad::assertLine(
unsigned idx )
61 void NCTreePad::SetLines(
unsigned idx )
66 unsigned olines = Lines();
70 for (
unsigned i = idx; i < Lines(); ++i )
76 Items.resize( idx, 0 );
78 for (
unsigned i = olines; i < Lines(); ++i )
89 void NCTreePad::SetLines( std::vector<NCTableLine*> & nItems )
94 for (
unsigned i = 0; i < Lines(); ++i )
105 void NCTreePad::AddLine(
unsigned idx,
NCTableLine * item )
116 void NCTreePad::DelLine(
unsigned idx )
120 Items[idx]->ClearLine();
127 const NCTableLine * NCTreePad::GetCurrentLine()
const
129 if ( citem.L >= 0 && (
unsigned )citem.L < visLines() )
130 return visItems[citem.L];
137 NCTableLine * NCTreePad::ModifyLine(
unsigned idx )
150 const NCTableLine * NCTreePad::GetLine(
unsigned idx )
const
160 bool NCTreePad::SetHeadline(
const std::vector<NCstring> & head )
162 bool hascontent = ItemStyle.SetStyleFrom( head );
172 NCPad::Destwin( dwin );
176 maxspos.L = visLines() > ( unsigned )srect.Sze.H ? visLines() - srect.Sze.H : 0;
182 void NCTreePad::wRecoded()
190 wpos NCTreePad::CurPos()
const
192 citem.C = srect.Pos.C;
198 void NCTreePad::ShowItem(
const NCTableLine * item )
203 if ( const_cast<NCTableLine *>( item )->ChangeToVisible() || dirtyFormat )
206 for (
unsigned l = 0; l < visLines(); ++l )
208 if ( visItems[l] == item )
210 setpos(
wpos( l, srect.Pos.C ) );
218 wsze NCTreePad::UpdateFormat()
223 ItemStyle.ResetToMinCols();
225 for (
unsigned l = 0; l < Lines(); ++l )
227 Items[l]->UpdateFormat( ItemStyle );
229 if ( Items[l]->isVisible() )
230 visItems.push_back( Items[l] );
233 maxspos.L = visLines() > ( unsigned )srect.Sze.H ? visLines() - srect.Sze.H : 0;
235 resize(
wsze( visLines(), ItemStyle.TableWidth() ) );
236 return wsze( visLines(), ItemStyle.TableWidth() );
241 int NCTreePad::DoRedraw()
258 for (
unsigned l = 0; l < visLines(); ++l )
260 visItems[l]->DrawAt( *
this,
wrect(
wpos( l, 0 ), lSze ),
261 ItemStyle, ( l == (
unsigned )citem.L ) );
265 Headpad.resize( 1,
width() );
269 ItemStyle.Headline().DrawAt( Headpad,
wrect(
wpos( 0, 0 ), lSze ),
281 int NCTreePad::setpos(
const wpos & newpos )
297 int opos = srect.Pos.C;
300 citem.L = newpos.L < 0 ? 0 : newpos.L;
302 if ((
unsigned )citem.L >= visLines() )
303 citem.L = visLines() - 1;
305 srect.Pos =
wpos( citem.L - ( drect.Sze.H - 1 ) / 2, newpos.C ).between( 0, maxspos );
307 if ( citem.L != oitem )
312 if ( citem.L >= 0 && visItems[citem.L] )
313 len = visItems[citem.L]->Hotspot( at );
319 if ((
int )at < srect.Pos.C )
323 else if ((
int )( at + len - srect.Pos.C ) > drect.Sze.W )
325 srect.Pos.C = ( int )at < maxspos.C ? at : maxspos.C;
336 if ( citem.L != oitem )
346 if ( srect.Pos.C != opos )
354 void NCTreePad::updateScrollHint()
356 NCPad::updateScrollHint();
361 bool NCTreePad::handleInput( wint_t key )
365 if ( !GetCurrentLine() )
383 handled = NCPad::handleInput( key );
395 if ( visItems[citem.L]->handleInput( key ) )
398 setpos(
wpos( citem.L, srect.Pos.C ) );
411 std::ostream & operator<<( std::ostream & STREAM,
const NCTreePad & OBJ )
413 STREAM <<
"TreePad: lines " << OBJ.Lines() << std::endl;
415 for (
unsigned idx = 0; idx < OBJ.Lines(); ++idx )
417 STREAM << idx <<
" " << *OBJ.GetLine( idx );