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 )
42 NCSelectionBox::~NCSelectionBox()
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()
const
77 if ( !
myPad()->Lines() )
86 std::string NCSelectionBox::getLine(
int index )
92 if ( line->
Cols() == 1 )
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 )
116 void NCSelectionBox::selectItem( YItem *item,
bool selected )
118 YSelectionBox::selectItem( item, selected );
124 void NCSelectionBox::selectItem(
int index )
126 YSelectionBox::deselectAllItems();
128 if ( hasItems() && index >= 0 )
130 YItem * item = YSelectionBox::itemAt( index );
135 item->setSelected(
true );
138 YUI_THROW( YUIException(
"Can't find selected item" ) );
143 void NCSelectionBox::addItem( YItem * item )
145 std::vector<NCTableCol*> cells( 1U, 0 );
149 item->setIndex( itemsCount() );
150 YSelectionBox::addItem( item );
155 if ( item->selected() )
161 void NCSelectionBox::addItem(
const std::string & description,
bool selected )
163 YSelectionWidget::addItem( description, selected );
167 void NCSelectionBox::setLabel(
const std::string & nlabel )
169 YSelectionBox::setLabel( nlabel );
170 NCPadWidget::setLabel(
NCstring( nlabel ) );
174 NCPad * NCSelectionBox::CreatePad()
176 wsze psze( defPadSze() );
178 npad->
bkgd( listStyle().item.plain );
184 void NCSelectionBox::wRecoded()
186 NCPadWidget::wRecoded();
194 int oldItem = getCurrentItem();
198 if ( sendKeyEvents() &&
199 ( key == KEY_LEFT || key == KEY_RIGHT ) )
201 ret = NCursesEvent::key;
206 ret.keySymbol =
"CursorLeft";
210 ret.keySymbol =
"CursorRight";
220 int citem = getCurrentItem();
229 if ( notify() && citem != -1 )
231 return NCursesEvent::Activated;
237 if ( notify() && immediateMode() && oldItem != citem )
239 ret = NCursesEvent::SelectionChanged;
251 YSelectionBox::deleteAllItems();