diff --git a/src/gui/components/cc_frm.cpp b/src/gui/components/cc_frm.cpp index 54964741c..ac82a666a 100644 --- a/src/gui/components/cc_frm.cpp +++ b/src/gui/components/cc_frm.cpp @@ -444,3 +444,36 @@ u_int8_t CComponentsForm::getPageCount() return page_count; } + +void CComponentsForm::setSelectedItem(size_t item_id) +{ + size_t btn_count = v_cc_items.size(); + + if (item_id > (btn_count-1) || (btn_count == 0)){ + dprintf(DEBUG_NORMAL, "[CComponentsForm] [%s - %d] invalid parameter item_id = %u, available items = %u, allowed values are: 0...%u! \n", __func__, + __LINE__, + item_id, + btn_count, + btn_count==0 ? 0:btn_count-1); + return; + } + + for (size_t i= 0; i< btn_count; i++) + v_cc_items[i]->setSelected(i == item_id); + + OnSelect(); +} + +void CComponentsForm::setSelectedItem(CComponentsItem* cc_item) +{ + size_t id = getCCItemId(cc_item); + setSelectedItem(id); +} + +int CComponentsForm::getSelectedItem() +{ + for (size_t i= 0; i< size(); i++) + if (getCCItem(i)->isSelected()) + return static_cast(i); + return -1; +} diff --git a/src/gui/components/cc_frm.h b/src/gui/components/cc_frm.h index 79ba3ffb9..ae15a37fb 100644 --- a/src/gui/components/cc_frm.h +++ b/src/gui/components/cc_frm.h @@ -117,6 +117,12 @@ class CComponentsForm : public CComponentsItem virtual void paintPage(const u_int8_t& page_number, bool do_save_bg = CC_SAVE_SCREEN_NO); ///set width of scrollbar virtual void setScrollBarWidth(const int& scrollbar_width){w_sb = scrollbar_width;}; + ///returns id of select item, return value as int, returns -1: if is nothing selected + virtual int getSelectedItem(); + ///select a definied item, parameter1 as size_t + virtual void setSelectedItem(size_t item_id); + ///select a definied item, parameter1 as CComponentsItem* + virtual void setSelectedItem(CComponentsItem* cc_item); }; #endif