CComponentsForm: add members to set or get selected items

This commit is contained in:
2014-08-25 14:31:46 +02:00
committed by [CST] Focus
parent cc5b17a620
commit ec7d5772f0
2 changed files with 39 additions and 0 deletions

View File

@@ -444,3 +444,36 @@ u_int8_t CComponentsForm::getPageCount()
return page_count; 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<int>(i);
return -1;
}

View File

@@ -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); virtual void paintPage(const u_int8_t& page_number, bool do_save_bg = CC_SAVE_SCREEN_NO);
///set width of scrollbar ///set width of scrollbar
virtual void setScrollBarWidth(const int& scrollbar_width){w_sb = scrollbar_width;}; 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 #endif