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()
47 yuiDebug() << std::endl;
51 int NCDumbTab::preferredWidth()
53 defsze.W = hasChildren() ? firstChild()->preferredWidth() : 0;
55 YItemIterator listIt = itemsBegin();
57 unsigned int 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;
91 yuiDebug() <<
"Set enabled" << std::endl;
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 );
114 if ( currentIndex > 0 &&
115 currentIndex <= (
unsigned)itemsCount() -1 )
120 ret = createMenuEvent( currentIndex );
125 if ( currentIndex < (
unsigned)itemsCount()-1 &&
131 ret = createMenuEvent( currentIndex );
136 setCurrentTab( hotKey );
139 ret = createMenuEvent( currentIndex );
147 void NCDumbTab::setCurrentTab( wint_t key )
150 YItemIterator listIt = itemsBegin();
154 while ( listIt != itemsEnd() )
156 tablabel =
NCstring( (*listIt)->label() );
157 tablabel.stripHotkey();
158 yuiDebug() <<
"HOTkey: " << tablabel.hotkey() <<
" key: " << key << std::endl;
159 if ( tolower ( tablabel.hotkey() ) == tolower ( key ) )
169 NCursesEvent NCDumbTab::createMenuEvent(
unsigned int index )
174 item = itemAt( index );
177 yuiMilestone() <<
"Show tab: " << item->label() << std::endl;
178 ret.selection = (YMenuItem *)item;
184 void NCDumbTab::addItem( YItem * item )
186 YDumbTab::addItem( item );
189 yuiDebug() <<
"Add item: " << item->label() << std::endl;
191 if ( item->selected() )
192 currentIndex = item->index();
195 void NCDumbTab::selectItem( YItem * item,
bool selected )
199 currentIndex = item->index();
200 yuiDebug() <<
"Select item: " << item->index() << std::endl;
203 YDumbTab::selectItem( item, selected );
208 void NCDumbTab::shortcutChanged()
216 void NCDumbTab::wRedraw()
222 win->
bkgd( style.plain );
225 YItemIterator listIt = itemsBegin();
227 int winWidth = win->
width() - 2;
228 unsigned int labelPos = 1;
230 bool nonActive =
false;
233 while ( listIt != itemsEnd() )
235 tablabel =
NCstring( (*listIt)->label() );
236 tablabel.stripHotkey();
237 hotlabel = &tablabel;
239 nonActive = (i == currentIndex)?
false:
true;
241 if ( GetState() == NC::WSactive )
244 tablabel.drawAt( *win,
248 NC::TOPLEFT, false );
254 tablabel.drawAt( *win,
259 NC::TOPLEFT, false );
263 tablabel.drawAt( *win,
267 NC::TOPLEFT, false );
271 labelPos += tablabel.width() + 2;
276 if ( listIt != itemsEnd() )
278 winWidth -= tablabel.width() -1;
289 redrawChild( firstChild() );
293 bool NCDumbTab::HasHotkey(
int key )
297 YItemIterator listIt = itemsBegin();
300 while ( listIt != itemsEnd() )
302 tablabel =
NCstring( (*listIt)->label() );
303 tablabel.stripHotkey();
304 if ( tablabel.hasHotkey() && tolower ( tablabel.hotkey() ) == tolower ( key ) )
306 hotKey = tolower ( key ) ;
312 yuiDebug() <<
"Has hot key: " << key <<
" " << (ret?
"yes":
"no") << std::endl;
317 void NCDumbTab::redrawChild( YWidget *widget )
321 if ( widget->hasChildren() )
323 YWidgetListConstIterator widgetIt = widget->childrenBegin();
324 while ( widgetIt != widget->childrenEnd() )
326 child =
dynamic_cast<NCWidget *
>(*widgetIt);
329 redrawChild( *widgetIt );
341 YItem * item = selectedItem();
343 event.selection = (YMenuItem *)item;
virtual void activate()
Activate selected tab.
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.
int bkgd(const chtype ch)
Set the background property and apply it to the window.
int box()
Draw a box around the window with the given vertical and horizontal drawing characters.
int width() const
Number of columns in this window.
void sendEvent(NCursesEvent event)
Send an event to the UI.
static YNCursesUI * ui()
Access the global Y2NCursesUI.