kcApp.h/cpp:App menu now has About and Quit options. Added _onCloseApp().

This commit is contained in:
kevin 2013-05-22 10:13:02 -07:00
parent 99504d8fc8
commit 427babb11d
2 changed files with 62 additions and 21 deletions

View File

@ -214,14 +214,17 @@ void kcApp::_createMenu(int w, int h)
{
Fl_Menu_Item items[] =
{
{ "&File", 0, 0, 0, FL_SUBMENU },
{ "&New File", 0, (Fl_Callback*)_s_menu_cb },
{ "kc", 0, 0, 0, FL_SUBMENU },
{ "&About", FL_COMMAND + 'a', (Fl_Callback*)_s_menu_cb, (void*)kAboutMenuId },
{ "&Quit", FL_COMMAND + 'q', (Fl_Callback*)_s_menu_cb, (void*)kQuitMenuId },
{ 0 },
{ 0 }
};
_menu = new Fl_Menu_Bar(0,0,w,h);
_menu->copy(items);
this->add(_menu);
}
kcApp::page_t* kcApp::_createPage( const char* title )
@ -1388,7 +1391,7 @@ void kcApp::_setSampleRateBtn( unsigned value )
unsigned n = _sr_btn->size();
for(i=0; i<n-1; ++i)
{
if( _sr_btn->menu()[i].argument() == value )
if( _sr_btn->menu()[i].argument() == (int)value )
{
_sr_btn->value(i);
_sr_btn->copy_label( _sr_btn->mvalue()->label() );
@ -1825,6 +1828,29 @@ kcApp* kcApp::_getApp( Fl_Widget* w )
return (kcApp*)gp->user_data();
}
void kcApp::_onCloseApp()
{
if( _tlCtl != NULL )
{
delete _tlCtl;
_tlCtl = NULL;
}
_stopTimerFl = true;
// When all windows are windows are closed then the app.
// will close - so hiding the application window
// causes the program to close.
//
// Note that simply returning from this callback will
// prevent the application from closing. Because the existence
// of the callback alone is enough to disable default
// event handling.
hide();
}
void kcApp::_testStub()
{
@ -1863,20 +1889,7 @@ void kcApp::_callback(void* data)
{
if( Fl::event() == FL_CLOSE )
{
delete _tlCtl;
_stopTimerFl = true;
// When all windows are windows are closed then the app.
// will close - so hiding the application window
// causes the program to close.
//
// Note that simply returning from this callback will
// prevent the application from closing. Because the existence
// of the callback alone is enough to disable default
// event handling.
hide();
_onCloseApp();
}
}
@ -1921,7 +1934,31 @@ bool kcApp::_status_timeout_cb()
}
void kcApp::_s_menu_cb(Fl_Widget *w, void *data)
{ }
{
const Fl_Menu_Item* mip;
kcApp* p;
if((p=_getApp(w)) == NULL )
return;
if((mip = p->_menu->mvalue()) == NULL )
return;
unsigned id = (long int)mip->user_data();
switch(id)
{
case kAboutMenuId:
fl_message("%s Compiled:%s %s",PACKAGE_STRING,__DATE__,__TIME__);
break;
case kQuitMenuId:
p->_onCloseApp();
break;
}
}
void kcApp::_s_tab_cb(Fl_Widget* w, void* data)
{ ((kcApp*)data)->_tab_cb(w); }

View File

@ -147,7 +147,10 @@ private:
kPgmBtnId,
kSubSystemIdxBtnId,
kSrateBtnId,
kTestBtnId
kTestBtnId,
kAboutMenuId,
kQuitMenuId
};
enum
@ -383,6 +386,7 @@ private:
private:
static kcApp* _getApp( Fl_Widget* w );
void _onCloseApp();
void _testStub();