25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include <yui/YDialog.h>
28 #include "YNCursesUI.h"
31 #include "NCDumbTab.h"
32 #include "NCPopupList.h"
35 NCDumbTab::NCDumbTab( YWidget * parent )
40 framedim.Pos =
wpos( 1 );
41 framedim.Sze =
wsze( 2 );
45 NCDumbTab::~NCDumbTab()
51 int NCDumbTab::preferredWidth()
53 defsze.W = hasChildren() ? firstChild()->preferredWidth() : 0;
55 YItemIterator listIt = itemsBegin();
57 unsigned tabBarWidth = 0;
60 while ( listIt != itemsEnd() )
62 tabLabel =
NClabel( (*listIt)->label() );
63 tabBarWidth += tabLabel.width() + 1;
68 if ( tabBarWidth > (
unsigned) defsze.W )
69 defsze.W = tabBarWidth;
71 defsze.W += framedim.Sze.W;
73 if ( defsze.W > NCurses::cols() )
74 defsze.W = NCurses::cols();
80 int NCDumbTab::preferredHeight()
82 defsze.H = hasChildren() ? firstChild()->preferredHeight() : 0;
83 defsze.H += framedim.Sze.H;
93 YDumbTab::setEnabled( do_bv );
97 void NCDumbTab::setSize(
int newwidth,
int newheight )
99 wsze csze( newheight, newwidth );
100 wRelocate(
wpos( 0 ), csze );
101 csze = wsze::max( 0, csze - framedim.Sze );
104 firstChild()->setSize( csze.W, csze.H );
115 if ( currentIndex > 0 &&
116 currentIndex <= (
unsigned) itemsCount() - 1 )
121 ret = createMenuEvent( currentIndex );
126 if ( currentIndex < (
unsigned) itemsCount() - 1 &&
132 ret = createMenuEvent( currentIndex );
137 setCurrentTab( hotKey );
140 ret = createMenuEvent( currentIndex );
149 void NCDumbTab::setCurrentTab( wint_t key )
152 YItemIterator listIt = itemsBegin();
156 while ( listIt != itemsEnd() )
158 tablabel =
NCstring( (*listIt)->label() );
159 tablabel.stripHotkey();
161 if ( tolower ( tablabel.hotkey() ) == tolower ( key ) )
172 NCursesEvent NCDumbTab::createMenuEvent(
unsigned index )
177 item = itemAt( index );
180 yuiDebug() <<
"Show tab: " << item->label() << std::endl;
181 ret.selection = (YMenuItem *)item;
188 void NCDumbTab::addItem( YItem * item )
190 YDumbTab::addItem( item );
195 if ( item->selected() )
196 currentIndex = item->index();
200 void NCDumbTab::selectItem( YItem * item,
bool selected )
204 currentIndex = item->index();
208 YDumbTab::selectItem( item, selected );
214 void NCDumbTab::shortcutChanged()
223 void NCDumbTab::wRedraw()
232 YItemIterator listIt = itemsBegin();
235 unsigned labelPos = 1;
237 bool nonActive =
false;
240 while ( listIt != itemsEnd() )
242 tablabel =
NCstring( (*listIt)->label() );
243 tablabel.stripHotkey();
244 hotlabel = &tablabel;
246 nonActive = ( i != currentIndex );
248 if ( GetState() == NC::WSactive )
251 tablabel.drawAt( *
win,
255 NC::TOPLEFT, false );
261 tablabel.drawAt( *
win,
266 NC::TOPLEFT, false );
270 tablabel.drawAt( *
win,
274 NC::TOPLEFT, false );
278 labelPos += tablabel.width() + 2;
283 if ( listIt != itemsEnd() )
285 winWidth -= tablabel.width() -1;
296 redrawChild( firstChild() );
301 bool NCDumbTab::HasHotkey(
int key )
305 YItemIterator listIt = itemsBegin();
308 while ( listIt != itemsEnd() )
310 tablabel =
NCstring( (*listIt)->label() );
311 tablabel.stripHotkey();
312 if ( tablabel.hasHotkey() && tolower ( tablabel.hotkey() ) == tolower ( key ) )
314 hotKey = tolower( key ) ;
326 void NCDumbTab::redrawChild( YWidget *widget )
330 if ( widget->hasChildren() )
332 YWidgetListConstIterator widgetIt = widget->childrenBegin();
334 while ( widgetIt != widget->childrenEnd() )
336 child =
dynamic_cast<NCWidget *
>( *widgetIt );
339 redrawChild( *widgetIt );
351 YItem * item = selectedItem();
353 event.selection = (YMenuItem *) item;