25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCSelectionBox.h"
31 NCSelectionBox::NCSelectionBox( YWidget * parent,
const std::string & nlabel )
32 : YSelectionBox( parent, nlabel )
36 yuiDebug() << std::endl;
42 NCSelectionBox::~NCSelectionBox()
44 yuiDebug() << std::endl;
48 int NCSelectionBox::preferredWidth()
50 wsze sze = ( biglist ) ?
myPad()->tableSize() + 2 : wGetDefsze();
51 return sze.W > ( int )( labelWidth() + 2 ) ? sze.W : ( labelWidth() + 2 );
55 int NCSelectionBox::preferredHeight()
57 wsze sze = ( biglist ) ?
myPad()->tableSize() + 2 : wGetDefsze();
62 void NCSelectionBox::setSize(
int newwidth,
int newheight )
64 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
71 YSelectionBox::setEnabled( do_bv );
75 int NCSelectionBox::getCurrentItem()
77 if ( !
myPad()->Lines() )
80 yuiDebug() <<
"Current pos: " <<
myPad()->CurPos().L << std::endl;
82 return myPad()->CurPos().L;
86 std::string NCSelectionBox::getLine(
const int & index )
92 if ( line->Cols() == 1 )
94 value = line->GetItems()[0];
95 const NClabel label = value->Label();
96 const std::list<NCstring> text = label.getText();
97 std::list<NCstring>::const_iterator it = text.begin();
99 while ( it != text.end() )
101 val += ( *it ).Str();
110 void NCSelectionBox::setCurrentItem(
int index )
112 myPad()->ScrlLine( index );
116 void NCSelectionBox::selectItem( YItem *item,
bool selected )
118 YSelectionBox::selectItem( item, selected );
120 myPad()->ScrlLine( selected ? item->index() : -1 );
124 void NCSelectionBox::selectItem(
int index )
126 YSelectionBox::deselectAllItems();
128 if ( hasItems() && index >= 0 )
130 YItem * item = YSelectionBox::itemAt( index );
134 yuiDebug() <<
"selectItem: " << item->label().c_str() << std::endl;
135 item->setSelected(
true );
138 YUI_THROW( YUIException(
"Can't find selected item" ) );
143 void NCSelectionBox::addItem( YItem * item )
145 std::vector<NCTableCol*> Items( 1U, 0 );
149 YSelectionBox::addItem( item );
151 myPad()->Append( Items );
154 if ( item->selected() )
160 void NCSelectionBox::addItem(
const std::string & description,
bool selected )
162 YSelectionWidget::addItem( description, selected );
166 void NCSelectionBox::setLabel(
const std::string & nlabel )
168 YSelectionBox::setLabel( nlabel );
169 NCPadWidget::setLabel(
NCstring( nlabel ) );
173 NCPad * NCSelectionBox::CreatePad()
175 wsze psze( defPadSze() );
177 npad->
bkgd( listStyle().item.plain );
183 void NCSelectionBox::wRecoded()
185 NCPadWidget::wRecoded();
193 int oldItem = getCurrentItem();
197 if ( sendKeyEvents() &&
198 ( key == KEY_LEFT || key == KEY_RIGHT ) )
200 ret = NCursesEvent::key;
205 ret.keySymbol =
"CursorLeft";
209 ret.keySymbol =
"CursorRight";
219 int citem = getCurrentItem();
228 if ( notify() && citem != -1 )
230 return NCursesEvent::Activated;
236 if ( notify() && immediateMode() && oldItem != citem )
238 ret = NCursesEvent::SelectionChanged;
250 YSelectionBox::deleteAllItems();
int bkgd(const chtype ch)
virtual NCTablePad * myPad() const
virtual void setEnabled(bool do_bv)