diff --git a/src/gui/components/cc_frm.cpp b/src/gui/components/cc_frm.cpp index c29ffc950..e0816833d 100644 --- a/src/gui/components/cc_frm.cpp +++ b/src/gui/components/cc_frm.cpp @@ -32,6 +32,7 @@ #include #include #include + using namespace std; //------------------------------------------------------------------------------------------------------- @@ -71,6 +72,12 @@ CComponentsForm::CComponentsForm( const int x_pos, const int y_pos, const int w, cur_page = 0; sb = NULL; w_sb = 15; + + page_scroll_mode = PG_SCROLL_M_UP_DOWN_KEY; + + //connect page scroll slot + sigc::slot3 sl = sigc::mem_fun(*this, &CComponentsForm::execPageScroll); + this->OnExec.connect(sl); } CComponentsForm::~CComponentsForm() @@ -79,6 +86,101 @@ CComponentsForm::~CComponentsForm() delete sb; } +int CComponentsForm::exec() +{ + dprintf(DEBUG_NORMAL, "[CComponentsForm] [%s - %d] \n", __func__, __LINE__); + OnBeforeExec(); + neutrino_msg_t msg; + neutrino_msg_data_t data; + + int res = menu_return::RETURN_REPAINT; + + uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(-1); + + //required exit keys + msg_list_t exit_keys[2]; + exit_keys[0].msg = CRCInput::RC_setup; + exit_keys[1].msg = CRCInput::RC_home; + + bool exit_loop = false; + while (!exit_loop) + { + g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); + + //execute connected slots + OnExec(msg, data, res); + + //exit loop + execExit(msg, data, res, exit_loop, exit_keys, 2); + + if (CNeutrinoApp::getInstance()->handleMsg(msg, data) & messages_return::cancel_all) + { + dprintf(DEBUG_INFO, "[CComponentsForm] [%s - %d] messages_return::cancel_all\n", __func__, __LINE__); + res = menu_return::RETURN_EXIT_ALL; + exit_loop = EXIT; + } + } + + OnAfterExec(); + return res; +} + + +void CComponentsForm::execKey(neutrino_msg_t& msg, neutrino_msg_data_t& data, int& res, bool& exit_loop, const struct msg_list_t * const msg_list, const size_t& key_count, bool force_exit) +{ + for(size_t i = 0; i < key_count; i++){ + if (execKey(msg, data, res, exit_loop, msg_list[i].msg, force_exit)){ + break; + } + } +} + +void CComponentsForm::execKey(neutrino_msg_t& msg, neutrino_msg_data_t& data, int& res, bool& exit_loop, const std::vector& v_msg_list, bool force_exit) +{ + for(size_t i = 0; i < v_msg_list.size(); i++){ + if (execKey(msg, data, res, exit_loop, v_msg_list[i], force_exit)){ + break; + } + } +} + +inline bool CComponentsForm::execKey(neutrino_msg_t& msg, neutrino_msg_data_t& data, int& res, bool& exit_loop, const neutrino_msg_t& msg_val, bool force_exit) +{ + if (msg == msg_val){ + OnExecMsg(msg, data, res); + if (force_exit) + exit_loop = EXIT; + return true; + } + return false; +} + + +void CComponentsForm::execPageScroll(neutrino_msg_t& msg, neutrino_msg_data_t& /*data*/, int& /*res*/) +{ + if (page_scroll_mode == PG_SCROLL_M_OFF) + return; + + if (page_scroll_mode & PG_SCROLL_M_UP_DOWN_KEY){ + if (msg == CRCInput::RC_page_up) + ScrollPage(SCROLL_P_DOWN); + if (msg == CRCInput::RC_page_down) + ScrollPage(SCROLL_P_UP); + } + + if (page_scroll_mode & PG_SCROLL_M_LEFT_RIGHT_KEY){ + if (msg == CRCInput::RC_left) + ScrollPage(SCROLL_P_DOWN); + if (msg == CRCInput::RC_right) + ScrollPage(SCROLL_P_UP); + } +} + +void CComponentsForm::execExit(neutrino_msg_t& msg, neutrino_msg_data_t& data, int& res, bool& exit_loop, const struct msg_list_t * const msg_list, const size_t& key_count) +{ + execKey(msg, data, res, exit_loop, msg_list, key_count, true); +} + void CComponentsForm::clear() { @@ -503,3 +605,23 @@ CComponentsItem* CComponentsForm::getSelectedItemObject() return ret; } + +void CComponentsForm::ScrollPage(int direction, bool do_paint) +{ + OnBeforeScrollPage(); + + int target_page_id = (int)getPageCount() - 1; + int target_page = (int)cur_page; + + if (direction == SCROLL_P_DOWN) + target_page = target_page+1 > target_page_id ? 0 : target_page+1; + else if (direction == SCROLL_P_UP) + target_page = target_page-1 < 0 ? target_page_id : target_page-1; + + if (do_paint) + paintPage((uint8_t)target_page); + else + cur_page = (uint8_t)target_page; + + OnAfterScrollPage(); +} diff --git a/src/gui/components/cc_frm.h b/src/gui/components/cc_frm.h index 9b4867a2c..cd99a0bb3 100644 --- a/src/gui/components/cc_frm.h +++ b/src/gui/components/cc_frm.h @@ -52,6 +52,9 @@ class CComponentsForm : public CComponentsItem ///returns true, if current page is changed, see also: setCurrentPage() bool isPageChanged(); + ///enable/disable page scrolling, default enabled with page scroll mode up/down keys, see also enablePageScroll() + int page_scroll_mode; + public: CComponentsForm( const int x_pos = 0, const int y_pos = 0, const int w = 800, const int h = 600, CComponentsForm *parent = NULL, @@ -115,6 +118,16 @@ class CComponentsForm : public CComponentsItem virtual u_int8_t getCurrentPage(){return cur_page;}; ///paint defined page number 0...n virtual void paintPage(const u_int8_t& page_number, bool do_save_bg = CC_SAVE_SCREEN_NO); + ///enum page scroll modes + enum + { + PG_SCROLL_M_UP_DOWN_KEY = 1, + PG_SCROLL_M_LEFT_RIGHT_KEY = 2, + PG_SCROLL_M_OFF = 4, + }; + ///enable/disable page scroll, parameter1 default enabled for up/down keys + virtual void enablePageScroll(const int& mode = PG_SCROLL_M_UP_DOWN_KEY){page_scroll_mode = mode;}; + ///set width of scrollbar virtual void setScrollBarWidth(const int& scrollbar_width){w_sb = scrollbar_width;}; ///returns id of selected item, return value as int, returns -1: if is nothing selected @@ -125,6 +138,58 @@ class CComponentsForm : public CComponentsItem virtual void setSelectedItem(int item_id); ///select a definied item, parameter1 as CComponentsItem* virtual void setSelectedItem(CComponentsItem* cc_item); + + ///exec main method, see also sub exec methods + virtual int exec(); + + ///enum exec loop control + enum + { + NO_EXIT = 0, + EXIT = 1 + }; + ///execKey() methods handle events for defined neutrino messages, see class CRCInput::, this methodes contains a signal handler named OnExecMsg, so it is possible to connect with any common function or method + ///exec sub method for pressed keys, parameters1/2 by rev, parameter3 msg_list as struct contains a list of possible RC-messages for defined message, parameter4 defines size of struct, parameter5 force_exit default = false + virtual void execKey( neutrino_msg_t& msg, + neutrino_msg_data_t& data, + int& res, + bool& exit_loop, + const struct msg_list_t * const msg_list, + const size_t& key_count, + bool force_exit = false); + ///exec sub method for pressed keys, parameters1/2 by rev, parameter3 msg_list as vector contains a list of possible RC-messages for defined message, parameter4 force_exit default = false + virtual void execKey( neutrino_msg_t& msg, + neutrino_msg_data_t& data, + int& res, + bool& exit_loop, + const std::vector& msg_list, + bool force_exit = false); + ///exec sub method for pressed key, parameters1/2 by rev, parameter3 force_exit default = false + virtual bool execKey( neutrino_msg_t& msg, + neutrino_msg_data_t& data, + int& res, + bool& exit_loop, + const neutrino_msg_t& msg_val, + bool force_exit = false); + + ///exec sub method for page scroll, parameter1 neutrino_msg_t by rev + virtual void execPageScroll(neutrino_msg_t& msg, neutrino_msg_data_t& data, int& res); + + ///exec sub method for exit loop, parameters by rev + virtual void execExit( neutrino_msg_t& msg, + neutrino_msg_data_t& data, + int& res, bool& exit_loop, + const struct msg_list_t * const msg_list, + const size_t& key_count); + + ///enum scroll direction + enum + { + SCROLL_P_DOWN = 0, + SCROLL_P_UP = 1 + }; + ///scroll page and paint current selected page, if parameter2 = true (default) + virtual void ScrollPage(int direction = SCROLL_P_DOWN, bool do_paint = true); }; #endif diff --git a/src/gui/components/cc_frm_window.cpp b/src/gui/components/cc_frm_window.cpp index 570ae7485..07f2b67a5 100644 --- a/src/gui/components/cc_frm_window.cpp +++ b/src/gui/components/cc_frm_window.cpp @@ -153,6 +153,8 @@ void CComponentsWindow::initVarWindow( const int& x_pos, const int& y_pos, const ccw_show_r_sideber = false; ccw_w_sidebar = 40; + page_scroll_mode = PG_SCROLL_M_OFF; //permanent disabled here, only in body used! + initCCWItems(); initParent(parent); } @@ -370,11 +372,26 @@ u_int8_t CComponentsWindow::getCurrentPage() return ccw_body->getCurrentPage(); } + +bool CComponentsWindow::isPageChanged() +{ + for(size_t i=0; isize(); i++){ + if (ccw_body->getCCItem(i)->getPageNumber() != getCurrentPage()) + return true; + } + return false; +} + void CComponentsWindow::setScrollBarWidth(const int& scrollbar_width) { ccw_body->setScrollBarWidth(scrollbar_width); } +void CComponentsWindow::enablePageScroll(const int& mode) +{ + ccw_body->enablePageScroll(mode); +} + void CComponentsWindow::paintCurPage(bool do_save_bg) { if (is_painted) //ensure that we have painted already the parent form before paint body diff --git a/src/gui/components/cc_frm_window.h b/src/gui/components/cc_frm_window.h index c5d479771..79b0c9433 100644 --- a/src/gui/components/cc_frm_window.h +++ b/src/gui/components/cc_frm_window.h @@ -110,6 +110,9 @@ class CComponentsWindow : public CComponentsForm ///initialize position void initWindowPos(); + ///returns true, if current page is changed, see also: setCurrentPage() + bool isPageChanged(); + public: enum { @@ -192,6 +195,9 @@ class CComponentsWindow : public CComponentsForm void paintCurPage(bool do_save_bg = CC_SAVE_SCREEN_NO); ///paint defined page of body, parameter number 0...n void paintPage(const u_int8_t& page_number, bool do_save_bg = CC_SAVE_SCREEN_NO); + ///enable/disable page scroll, parameter1 default enabled for up/down keys, only for body! + void enablePageScroll(const int& mode = PG_SCROLL_M_UP_DOWN_KEY); + ///set width of body scrollbar void setScrollBarWidth(const int& scrollbar_width);