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( 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 void NCTable::getHeader( std::vector<std::string> & header )
166 header.assign( _header.size(),
"" );
168 for (
unsigned int i = 0; i < _header.size(); i++ )
170 header[ i ] = _header[i].Str().substr( 1 );
179 void NCTable::setAlignment(
int col, YAlignmentType al )
185 case YAlignUnchanged:
207 void NCTable::addItem( YItem *yitem)
209 addItem(yitem,
false);
217 void NCTable::addItem( YItem *yitem,
bool allAtOnce )
220 YTableItem *item =
dynamic_cast<YTableItem *
>( yitem );
221 YUI_CHECK_PTR( item );
222 YTable::addItem( item );
223 unsigned int itemCount;
226 itemCount = item->cellCount();
228 itemCount = item->cellCount()+1;
230 std::vector<NCTableCol*> Items( itemCount );
236 for ( YTableCellIterator it = item->cellsBegin();
237 it != item->cellsEnd();
247 Items[0] =
new NCTableTag( yitem, yitem->selected() );
250 for ( YTableCellIterator it = item->cellsBegin();
251 it != item->cellsEnd();
262 YUI_CHECK_PTR( newline );
264 newline->setOrigItem( item );
266 myPad()->Append( newline );
268 if ( item->selected() )
270 setCurrentItem( item->index() ) ;
284 void NCTable::addItems(
const YItemCollection & itemCollection )
287 for ( YItemConstIterator it = itemCollection.begin();
288 it != itemCollection.end();
298 void NCTable::deleteAllItems()
300 myPad()->ClearTable();
302 YTable::deleteAllItems();
309 int NCTable::getCurrentItem()
311 if ( !myPad()->Lines() )
314 return keepSorting() ? myPad()->GetLine( myPad()->CurPos().L )->getIndex()
315 : myPad()->CurPos().L;
323 YItem * NCTable::getCurrentItemPointer()
325 const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
328 return cline->origItem();
337 void NCTable::setCurrentItem(
int index )
339 myPad()->ScrlLine( index );
346 void NCTable::selectItem( YItem *yitem,
bool selected )
351 YTableItem *item =
dynamic_cast<YTableItem *
>( yitem );
352 YUI_CHECK_PTR( item );
355 YUI_CHECK_PTR( line );
357 const NCTableLine *current_line = myPad()->GetLine( myPad()->CurPos().L );
358 YUI_CHECK_PTR( current_line );
362 if ( !selected && ( line == current_line ) )
369 setCurrentItem( line->getIndex() );
370 YTable::selectItem( item, selected );
375 setCurrentItem( line->getIndex() );
376 YTable::selectItem( item, selected );
378 yuiMilestone() << item->label() <<
" is selected: " << (selected?
"yes":
"no") << endl;
381 tag->SetSelected( selected );
394 void NCTable::selectCurrentItem()
396 const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
399 YTable::selectItem( cline->origItem(), true );
406 void NCTable::deselectAllItems()
410 setCurrentItem( -1 );
411 YTable::deselectAllItems();
415 YItemCollection itemCollection = YTable::selectedItems();
416 for ( YItemConstIterator it = itemCollection.begin();
417 it != itemCollection.end(); ++it )
419 selectItem( *it,
false );
430 int NCTable::preferredWidth()
432 wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
440 int NCTable::preferredHeight()
442 wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
450 void NCTable::setSize(
int newwidth,
int newheight )
452 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
458 void NCTable::setLabel(
const std::string & nlabel )
461 NCPadWidget::setLabel(
NCstring( nlabel ) );
471 YTable::setEnabled( do_bv );
477 bool NCTable::setItemByKey(
int key )
479 return myPad()->setItemByKey( key );
487 NCPad * NCTable::CreatePad()
489 wsze psze( defPadSze() );
491 npad->
bkgd( listStyle().item.plain );
504 int citem = getCurrentItem();
505 bool sendEvent =
false;
507 if ( ! handleInput( key ) )
513 if ( ! keepSorting() )
516 wpos at( ScreenPos() +
wpos( win->height() / 2, 1 ) );
519 ic.reserve( _header.size() );
522 for ( std::vector<NCstring>::const_iterator it = _header.begin();
523 it != _header.end() ; it++, i++ )
526 std::string col = ( *it ).Str();
529 YMenuItem *item =
new YMenuItem( col ) ;
533 ic.push_back( item );
538 int column = dialog->post();
541 myPad()->setOrder( column,
true );
544 YDialog::deleteTopmostDialog();
546 return NCursesEvent::none;
555 if ( notify() && citem != -1 )
556 return NCursesEvent::Activated;
562 if ( notify() && sendEvent )
564 return NCursesEvent::ValueChanged;
573 if ( citem != getCurrentItem() )
575 if ( notify() && immediateMode() )
576 ret = NCursesEvent::SelectionChanged;
590 YTableItem *it =
dynamic_cast<YTableItem *
>( getCurrentItemPointer() );
593 selectItem( it, !( it->selected() ) );
int bkgd(const chtype ch)
virtual void setEnabled(bool do_bv)