25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
28 #include "NCPopupMenu.h"
29 #include <yui/YMenuButton.h>
30 #include <yui/YTypes.h>
34 NCTable::NCTable( YWidget * parent, YTableHeader *tableHeader,
bool multiSelection )
35 : YTable( parent, tableHeader, multiSelection )
38 , multiselect( multiSelection )
40 yuiDebug() << std::endl;
46 _header.assign( tableHeader->columns(),
NCstring(
"" ) );
47 for (
int col = 0; col < tableHeader->columns(); col++ )
49 if ( hasColumn( col ) )
52 setAlignment( col, alignment( col ) );
54 _header[ col ] +=
NCstring( tableHeader->header( col ) ) ;
60 _header.assign( tableHeader->columns()+1,
NCstring(
"" ) );
62 for (
int col = 1; col <= tableHeader->columns(); col++ )
64 if ( hasColumn( col-1 ) )
67 setAlignment( col, alignment( col-1 ) );
69 _header[ col ] +=
NCstring( tableHeader->header( col-1 ) ) ;
74 hasHeadline = myPad()->SetHeadline( _header );
83 yuiDebug() << std::endl;
91 void NCTable::cellChanged(
int index,
int colnum,
const std::string & newtext )
97 yuiWarning() <<
"No such line: " <<
wpos( index, colnum ) << newtext << std::endl;
105 yuiWarning() <<
"No such colnum: " <<
wpos( index, colnum ) << newtext << std::endl;
110 cc->SetLabel(
NCstring( newtext ) );
120 void NCTable::cellChanged(
const YTableCell *cell )
123 cellChanged( cell->itemIndex(), cell->column(), cell->label() );
131 void NCTable::setHeader( std::vector<std::string> head )
133 _header.assign( head.size(),
NCstring(
"" ) );
134 YTableHeader *th =
new YTableHeader();
136 for (
unsigned int i = 0; i < head.size(); i++ )
138 th->addColumn( head[ i ] );
139 _header[ i ] +=
NCstring( head[ i ] ) ;
142 hasHeadline = myPad()->SetHeadline( _header );
144 YTable::setTableHeader( th );
150 void NCTable::getHeader( std::vector<std::string> & header )
152 header.assign( _header.size(),
"" );
154 for (
unsigned int i = 0; i < _header.size(); i++ )
156 header[ i ] = _header[i].Str().substr( 1 );
165 void NCTable::setAlignment(
int col, YAlignmentType al )
171 case YAlignUnchanged:
193 void NCTable::addItem( YItem *yitem)
195 addItem(yitem,
false);
203 void NCTable::addItem( YItem *yitem,
bool allAtOnce )
206 YTableItem *item =
dynamic_cast<YTableItem *
>( yitem );
207 YUI_CHECK_PTR( item );
208 YTable::addItem( item );
209 unsigned int itemCount;
212 itemCount = item->cellCount();
214 itemCount = item->cellCount()+1;
216 std::vector<NCTableCol*> Items( itemCount );
222 for ( YTableCellIterator it = item->cellsBegin();
223 it != item->cellsEnd();
233 Items[0] =
new NCTableTag( yitem, yitem->selected() );
236 for ( YTableCellIterator it = item->cellsBegin();
237 it != item->cellsEnd();
248 YUI_CHECK_PTR( newline );
250 newline->setOrigItem( item );
252 myPad()->Append( newline );
254 if ( item->selected() )
256 setCurrentItem( item->index() ) ;
270 void NCTable::addItems(
const YItemCollection & itemCollection )
273 for ( YItemConstIterator it = itemCollection.begin();
274 it != itemCollection.end();
284 void NCTable::deleteAllItems()
286 myPad()->ClearTable();
288 YTable::deleteAllItems();
295 int NCTable::getCurrentItem()
297 if ( !myPad()->Lines() )
300 return keepSorting() ? myPad()->GetLine( myPad()->CurPos().L )->getIndex()
301 : myPad()->CurPos().L;
309 YItem * NCTable::getCurrentItemPointer()
311 const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
314 return cline->origItem();
323 void NCTable::setCurrentItem(
int index )
325 myPad()->ScrlLine( index );
332 void NCTable::selectItem( YItem *yitem,
bool selected )
337 YTableItem *item =
dynamic_cast<YTableItem *
>( yitem );
338 YUI_CHECK_PTR( item );
341 YUI_CHECK_PTR( line );
343 const NCTableLine *current_line = myPad()->GetLine( myPad()->CurPos().L );
344 YUI_CHECK_PTR( current_line );
348 if ( !selected && ( line == current_line ) )
355 setCurrentItem( line->getIndex() );
356 YTable::selectItem( item, selected );
361 setCurrentItem( line->getIndex() );
362 YTable::selectItem( item, selected );
364 yuiMilestone() << item->label() <<
" is selected: " << (selected?
"yes":
"no") << endl;
367 tag->SetSelected( selected );
380 void NCTable::selectCurrentItem()
382 const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
385 YTable::selectItem( cline->origItem(), true );
392 void NCTable::deselectAllItems()
394 setCurrentItem( -1 );
395 YTable::deselectAllItems();
403 int NCTable::preferredWidth()
405 wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
413 int NCTable::preferredHeight()
415 wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
423 void NCTable::setSize(
int newwidth,
int newheight )
425 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
431 void NCTable::setLabel(
const std::string & nlabel )
434 NCPadWidget::setLabel(
NCstring( nlabel ) );
444 YTable::setEnabled( do_bv );
450 bool NCTable::setItemByKey(
int key )
452 return myPad()->setItemByKey( key );
460 NCPad * NCTable::CreatePad()
462 wsze psze( defPadSze() );
464 npad->
bkgd( listStyle().item.plain );
477 int citem = getCurrentItem();
479 if ( ! handleInput( key ) )
485 if ( ! keepSorting() )
488 wpos at( ScreenPos() +
wpos( win->height() / 2, 1 ) );
491 ic.reserve( _header.size() );
494 for ( std::vector<NCstring>::const_iterator it = _header.begin();
495 it != _header.end() ; it++, i++ )
498 std::string col = ( *it ).Str();
501 YMenuItem *item =
new YMenuItem( col ) ;
505 ic.push_back( item );
510 int column = dialog->post();
513 myPad()->setOrder( column,
true );
516 YDialog::deleteTopmostDialog();
518 return NCursesEvent::none;
526 if ( notify() && citem != -1 )
527 return NCursesEvent::Activated;
539 if ( citem != getCurrentItem() )
541 if ( notify() && immediateMode() )
542 ret = NCursesEvent::SelectionChanged;
556 YTableItem *it =
dynamic_cast<YTableItem *
>( getCurrentItemPointer() );
559 selectItem( it, !( it->selected() ) );