25 #define YUILogComponent "ncurses" 26 #include <yui/YUILog.h> 28 #include "NCPopupMenu.h" 29 #include <yui/YMenuButton.h> 30 #include <yui/YTypes.h> 48 NCTable::NCTable( YWidget * parent, YTableHeader *tableHeader,
bool multiSelection )
49 : YTable( parent, tableHeader, multiSelection )
52 , multiselect( multiSelection )
54 yuiDebug() << std::endl;
60 _header.assign( tableHeader->columns(),
NCstring(
"" ) );
61 for (
int col = 0; col < tableHeader->columns(); col++ )
63 if ( hasColumn( col ) )
66 setAlignment( col, alignment( col ) );
68 _header[ col ] +=
NCstring( tableHeader->header( col ) ) ;
74 _header.assign( tableHeader->columns()+1,
NCstring(
"" ) );
76 for (
int col = 1; col <= tableHeader->columns(); col++ )
78 if ( hasColumn( col-1 ) )
81 setAlignment( col, alignment( col-1 ) );
83 _header[ col ] +=
NCstring( tableHeader->header( col-1 ) ) ;
88 hasHeadline = myPad()->SetHeadline( _header );
97 yuiDebug() << std::endl;
105 void NCTable::cellChanged(
int index,
int colnum,
const std::string & newtext )
111 yuiWarning() <<
"No such line: " <<
wpos( index, colnum ) << newtext << std::endl;
119 yuiWarning() <<
"No such colnum: " <<
wpos( index, colnum ) << newtext << std::endl;
124 cc->SetLabel(
NCstring( newtext ) );
134 void NCTable::cellChanged(
const YTableCell *cell )
137 cellChanged( cell->itemIndex(), cell->column(), cell->label() );
145 void NCTable::setHeader(
const std::vector<std::string>& head )
147 _header.assign( head.size(),
NCstring(
"" ) );
148 YTableHeader *th =
new YTableHeader();
150 for (
unsigned int i = 0; i < head.size(); i++ )
152 th->addColumn( head[ i ] );
153 _header[ i ] +=
NCstring( head[ i ] ) ;
156 hasHeadline = myPad()->SetHeadline( _header );
158 YTable::setTableHeader( th );
164 std::vector<std::string> NCTable::getHeader( )
const 166 std::vector<std::string> header;
168 header.assign( _header.size(),
"" );
170 for (
unsigned int i = 0; i < _header.size(); i++ )
172 header[ i ] = _header[i].Str().substr( 1 );
183 void NCTable::setAlignment(
int col, YAlignmentType al )
189 case YAlignUnchanged:
211 void NCTable::addItem( YItem *yitem)
213 addItem(yitem,
false);
221 void NCTable::addItem( YItem *yitem,
bool allAtOnce )
224 YTableItem *item =
dynamic_cast<YTableItem *
>( yitem );
225 YUI_CHECK_PTR( item );
226 YTable::addItem( item );
227 unsigned int itemCount;
230 itemCount = item->cellCount();
232 itemCount = item->cellCount()+1;
234 std::vector<NCTableCol*> Items( itemCount );
240 for ( YTableCellIterator it = item->cellsBegin();
241 it != item->cellsEnd();
251 Items[0] =
new NCTableTag( yitem, yitem->selected() );
254 for ( YTableCellIterator it = item->cellsBegin();
255 it != item->cellsEnd();
266 YUI_CHECK_PTR( newline );
268 newline->setOrigItem( item );
270 myPad()->Append( newline );
272 if ( item->selected() )
274 setCurrentItem( item->index() ) ;
288 void NCTable::addItems(
const YItemCollection & itemCollection )
291 for ( YItemConstIterator it = itemCollection.begin();
292 it != itemCollection.end();
298 if ( !keepSorting() )
311 void NCTable::deleteAllItems()
313 myPad()->ClearTable();
315 YTable::deleteAllItems();
322 int NCTable::getCurrentItem()
const 324 if ( !myPad()->Lines() )
327 return keepSorting() ? myPad()->GetLine( myPad()->CurPos().L )->getIndex()
328 : myPad()->CurPos().L;
335 YItem * NCTable::getCurrentItemPointer()
337 const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
340 return cline->origItem();
349 void NCTable::setCurrentItem(
int index )
351 myPad()->ScrlLine( index );
358 void NCTable::selectItem( YItem *yitem,
bool selected )
363 YTableItem *item =
dynamic_cast<YTableItem *
>( yitem );
364 YUI_CHECK_PTR( item );
367 YUI_CHECK_PTR( line );
369 const NCTableLine *current_line = myPad()->GetLine( myPad()->CurPos().L );
370 YUI_CHECK_PTR( current_line );
374 if ( !selected && ( line == current_line ) )
381 setCurrentItem( line->getIndex() );
382 YTable::selectItem( item, selected );
387 YTable::selectItem( item, selected );
389 yuiDebug() << item->label() <<
" is selected: " << (selected?
"yes":
"no") << endl;
392 tag->SetSelected( selected );
405 void NCTable::selectCurrentItem()
407 const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
410 YTable::selectItem( cline->origItem(), true );
417 void NCTable::deselectAllItems()
421 setCurrentItem( -1 );
422 YTable::deselectAllItems();
426 YItemCollection itemCollection = YTable::selectedItems();
427 for ( YItemConstIterator it = itemCollection.begin();
428 it != itemCollection.end(); ++it )
430 selectItem( *it,
false );
441 int NCTable::preferredWidth()
443 wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
451 int NCTable::preferredHeight()
453 wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
461 void NCTable::setSize(
int newwidth,
int newheight )
463 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
469 void NCTable::setLabel(
const std::string & nlabel )
472 NCPadWidget::setLabel(
NCstring( nlabel ) );
482 YTable::setEnabled( do_bv );
488 bool NCTable::setItemByKey(
int key )
490 return myPad()->setItemByKey( key );
498 NCPad * NCTable::CreatePad()
500 wsze psze( defPadSze() );
502 npad->
bkgd( listStyle().item.plain );
515 int citem = getCurrentItem();
516 bool sendEvent =
false;
518 if ( ! handleInput( key ) )
524 if ( ! keepSorting() )
527 wpos at( ScreenPos() +
wpos( 2, 1 ) );
530 ic.reserve( _header.size() );
533 for ( std::vector<NCstring>::const_iterator it = _header.begin();
534 it != _header.end() ; it++, i++ )
537 std::string col = ( *it ).Str();
540 YMenuItem *item =
new YMenuItem( col ) ;
544 ic.push_back( item );
549 int column = dialog->post();
553 myPad()->setOrder( column,
true );
560 YDialog::deleteTopmostDialog();
562 return NCursesEvent::none;
571 if ( notify() && citem != -1 )
572 return NCursesEvent::Activated;
578 if ( notify() && sendEvent )
580 return NCursesEvent::ValueChanged;
589 if ( citem != getCurrentItem() )
591 if ( notify() && immediateMode() )
592 ret = NCursesEvent::SelectionChanged;
606 YTableItem *it =
dynamic_cast<YTableItem *
>( getCurrentItemPointer() );
609 selectItem( it, !( it->selected() ) );
int bkgd(const chtype ch)
Set the background property and apply it to the window.
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.
void toggleCurrentItem()
Toggle item from selected -> deselected and vice versa.