From 427babb11df02136e1c1290d12ca2f6fdb1a9516 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 22 May 2013 10:13:02 -0700 Subject: [PATCH] kcApp.h/cpp:App menu now has About and Quit options. Added _onCloseApp(). --- src/kc/kcApp.cpp | 75 ++++++++++++++++++++++++++++++++++++------------ src/kc/kcApp.h | 8 ++++-- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/kc/kcApp.cpp b/src/kc/kcApp.cpp index 1e97208..accef31 100644 --- a/src/kc/kcApp.cpp +++ b/src/kc/kcApp.cpp @@ -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; imenu()[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); } diff --git a/src/kc/kcApp.h b/src/kc/kcApp.h index be3e2de..6445677 100644 --- a/src/kc/kcApp.h +++ b/src/kc/kcApp.h @@ -147,7 +147,10 @@ private: kPgmBtnId, kSubSystemIdxBtnId, kSrateBtnId, - kTestBtnId + kTestBtnId, + + kAboutMenuId, + kQuitMenuId }; enum @@ -383,7 +386,8 @@ private: private: static kcApp* _getApp( Fl_Widget* w ); - + void _onCloseApp(); + void _testStub(); // main app callback