CComponentsForm/Header/Icons/Window: try to fix multiple inits and paints

Some items had multiple inits and some calls of clearCCItems()
have caused segfaults, hope this fix this.


Origin commit data
------------------
Branch: ni/coolstream
Commit: 4a931af6ef
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-03-13 (Wed, 13 Mar 2013)



------------------
This commit was generated by Migit
This commit is contained in:
2013-03-13 23:23:19 +01:00
parent bfda4b1d37
commit f918ed8e2a
5 changed files with 164 additions and 111 deletions

View File

@@ -377,6 +377,7 @@ class CComponentsForm : public CComponentsItem
std::vector<CComponentsItem*> v_cc_items; std::vector<CComponentsItem*> v_cc_items;
void initVarForm(); void initVarForm();
void clearCCItems(); void clearCCItems();
void paintForm(bool do_save_bg);
public: public:
CComponentsForm(); CComponentsForm();
@@ -481,7 +482,7 @@ class CComponentsHeader : public CComponentsForm
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, neutrino_locale_t caption_locale = NONEXISTANT_LOCALE, const char* icon_name = NULL, const int buttons = 0,bool has_shadow = CC_SHADOW_OFF, CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, neutrino_locale_t caption_locale = NONEXISTANT_LOCALE, const char* icon_name = NULL, const int buttons = 0,bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
// ~CComponentsHeader(); //inherited from CComponentsForm ~CComponentsHeader();
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
void setHeaderText(const std::string& caption); void setHeaderText(const std::string& caption);

View File

@@ -68,26 +68,33 @@ CComponentsForm::~CComponentsForm()
void CComponentsForm::cleanCCForm() void CComponentsForm::cleanCCForm()
{ {
#ifdef DEBUG_CC #ifdef DEBUG_CC
printf("[CComponents] calling %s...\n", __FUNCTION__); printf("[CComponentsForm] [%s - %d] clean up...\n", __FUNCTION__, __LINE__);
#endif #endif
hide(); // hide();
clearSavedScreen();
clearCCItems(); clearCCItems();
clearSavedScreen();
clear(); clear();
} }
void CComponentsForm::clearCCItems() void CComponentsForm::clearCCItems()
{ {
if (v_cc_items.empty()) if (v_cc_items.empty())
return; return;
#ifdef DEBUG_CC #ifdef DEBUG_CC
printf("[CComponentsForm] %s... cleanup %d form cc-items\n", __FUNCTION__, v_cc_items.size()); printf(" [CComponentsForm] %s... delete %d cc-item(s) \n", __FUNCTION__, v_cc_items.size());
#endif #endif
for(size_t i=0; i<v_cc_items.size(); i++) { for(size_t i=0; i<v_cc_items.size(); i++) {
if (v_cc_items[i]) if (v_cc_items[i]){
#ifdef DEBUG_CC
printf(" [CComponentsForm] %s... delete form cc-item %d of %d (type=%d)\n", __FUNCTION__, i+1, v_cc_items.size(), v_cc_items[i]->getItemType());
#endif
delete v_cc_items[i]; delete v_cc_items[i];
v_cc_items[i] = NULL; v_cc_items[i] = NULL;
} }
}
v_cc_items.clear(); v_cc_items.clear();
} }
@@ -118,8 +125,17 @@ void CComponentsForm::initVarForm()
void CComponentsForm::addCCItem(CComponentsItem* cc_Item) void CComponentsForm::addCCItem(CComponentsItem* cc_Item)
{ {
if (cc_Item){
#ifdef DEBUG_CC
printf(" [CComponentsForm] %s-%d add cc_Item [type %d] [current count %d] \n", __FUNCTION__, __LINE__, cc_Item->getItemType(), v_cc_items.size());
#endif
v_cc_items.push_back(cc_Item); v_cc_items.push_back(cc_Item);
} }
#ifdef DEBUG_CC
else
printf(" [CComponentsForm] %s-%d tried to add an empty or invalide cc_item !!!\n", __FUNCTION__, __LINE__);
#endif
}
int CComponentsForm::getCCItemId(CComponentsItem* cc_Item) int CComponentsForm::getCCItemId(CComponentsItem* cc_Item)
{ {
@@ -191,15 +207,20 @@ void CComponentsForm::removeCCItem(const uint& cc_item_id)
#endif #endif
} }
void CComponentsForm::paint(bool do_save_bg) void CComponentsForm::paintForm(bool do_save_bg)
{ {
//paint body //paint body
paintInit(do_save_bg); paintInit(do_save_bg);
//paint items //paint
paintCCItems(); paintCCItems();
} }
void CComponentsForm::paint(bool do_save_bg)
{
paintForm(do_save_bg);
}
void CComponentsForm::paintCCItems() void CComponentsForm::paintCCItems()
{ {
size_t items_count = v_cc_items.size(); size_t items_count = v_cc_items.size();

View File

@@ -82,11 +82,11 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in
cch_locale_text = caption_locale; cch_locale_text = caption_locale;
cch_icon_name = icon_name; cch_icon_name = icon_name;
cch_buttons = buttons; cch_buttons = buttons;
initCCHDefaultButtons(); initCCHDefaultButtons();
initCCHItems(); initCCHItems();
} }
void CComponentsHeader::initVarHeader() void CComponentsHeader::initVarHeader()
{ {
//CComponentsHeader //CComponentsHeader
@@ -116,6 +116,15 @@ void CComponentsHeader::initVarHeader()
corner_type = CORNER_TOP; corner_type = CORNER_TOP;
} }
CComponentsHeader::~CComponentsHeader()
{
#ifdef DEBUG_CC
printf("[~CComponentsHeader] [%s - %d] delete...\n", __FUNCTION__, __LINE__);
#endif
v_cch_btn.clear();
cleanCCForm();
}
void CComponentsHeader::setHeaderText(const std::string& caption) void CComponentsHeader::setHeaderText(const std::string& caption)
{ {
cch_text = caption; cch_text = caption;
@@ -133,19 +142,36 @@ void CComponentsHeader::setHeaderIcon(const char* icon_name)
void CComponentsHeader::initCCHeaderIcon() void CComponentsHeader::initCCHeaderIcon()
{ {
//reset cch_icon_w
cch_icon_w = cch_btn_offset;
//init cch_icon_obj only if an icon available
if (cch_icon_name == NULL) { if (cch_icon_name == NULL) {
cch_icon_w = cch_btn_offset; cch_icon_w = cch_btn_offset;
if (cch_icon_obj)
delete cch_icon_obj;
cch_icon_obj = NULL;
return; return;
} }
if (cch_icon_name) //create instance for cch_icon_obj
if (cch_icon_obj == NULL){
#ifdef DEBUG_CC
printf(" [CComponentsHeader]\n [%s - %d] init header icon: %s\n", __FUNCTION__, __LINE__, cch_icon_name);
#endif
cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, cch_icon_name); cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, cch_icon_name);
//add item only one time
addCCItem(cch_icon_obj); //icon
}
//set properties for icon object
if (cch_icon_obj){
cch_icon_obj->setWidth(height-2*fr_thickness); cch_icon_obj->setWidth(height-2*fr_thickness);
cch_icon_obj->setHeight(height); cch_icon_obj->setHeight(height);
cch_icon_obj->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER); cch_icon_obj->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
cch_icon_obj->doPaintBg(false); cch_icon_obj->doPaintBg(false);
//corner of icon item //set corner mode of icon item
cch_icon_obj->setCornerRadius(corner_rad-fr_thickness); cch_icon_obj->setCornerRadius(corner_rad-fr_thickness);
int cc_icon_corner_type = corner_type; int cc_icon_corner_type = corner_type;
if (corner_type == CORNER_TOP_LEFT || corner_type == CORNER_TOP) if (corner_type == CORNER_TOP_LEFT || corner_type == CORNER_TOP)
@@ -157,13 +183,10 @@ void CComponentsHeader::initCCHeaderIcon()
//set width of icon object //set width of icon object
cch_icon_w = cch_icon_obj->getWidth(); cch_icon_w = cch_icon_obj->getWidth();
} }
}
void CComponentsHeader::addHeaderButton(const std::string& button_name) void CComponentsHeader::addHeaderButton(const std::string& button_name)
{ {
if (cch_btn_obj){
delete cch_btn_obj;
cch_btn_obj = NULL;
}
v_cch_btn.push_back(button_name); v_cch_btn.push_back(button_name);
initCCHeaderButtons(); initCCHeaderButtons();
} }
@@ -171,10 +194,9 @@ void CComponentsHeader::addHeaderButton(const std::string& button_name)
void CComponentsHeader::removeHeaderButtons() void CComponentsHeader::removeHeaderButtons()
{ {
v_cch_btn.clear(); v_cch_btn.clear();
if (cch_btn_obj){ cch_btn_obj->removeAllIcons();
delete cch_btn_obj; initCCHeaderButtons();
cch_btn_obj = NULL;
}
} }
void CComponentsHeader::initCCHDefaultButtons() void CComponentsHeader::initCCHDefaultButtons()
@@ -187,6 +209,9 @@ void CComponentsHeader::initCCHDefaultButtons()
v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_INFO); v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_INFO);
if (cch_buttons & CC_BTN_MENU) if (cch_buttons & CC_BTN_MENU)
v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_MENU); v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_MENU);
#ifdef DEBUG_CC
printf("[CComponentsHeader] %s added %d default buttons...\n", __FUNCTION__, v_cch_btn.size());
#endif
} }
// calculate minimal width of icon form // calculate minimal width of icon form
@@ -208,7 +233,17 @@ void CComponentsHeader::initCCHeaderButtons()
initCCButtonFormSize(); initCCButtonFormSize();
if (cch_btn_obj == NULL){
cch_btn_obj = new CComponentsIconForm(); cch_btn_obj = new CComponentsIconForm();
#ifdef DEBUG_CC
printf(" [CComponentsHeader]\n [%s - %d] init header buttons...\n", __FUNCTION__, __LINE__);
#endif
//add button form
addCCItem(cch_btn_obj); //buttons
}
//set button form properties
if (cch_btn_obj){
cch_btn_obj->setDimensionsAll(0+width-ccif_width, 0, ccif_width-cch_btn_offset, height); cch_btn_obj->setDimensionsAll(0+width-ccif_width, 0, ccif_width-cch_btn_offset, height);
cch_btn_obj->doPaintBg(false); cch_btn_obj->doPaintBg(false);
cch_btn_obj->setIconOffset(cch_btn_offset); cch_btn_obj->setIconOffset(cch_btn_offset);
@@ -216,11 +251,25 @@ void CComponentsHeader::initCCHeaderButtons()
cch_btn_obj->removeAllIcons(); cch_btn_obj->removeAllIcons();
cch_btn_obj->addIcon(v_cch_btn); cch_btn_obj->addIcon(v_cch_btn);
} }
}
void CComponentsHeader::initCCHeaderText() void CComponentsHeader::initCCHeaderText()
{ {
//reset header text position first
cch_text_x = cch_icon_x+cch_icon_w; cch_text_x = cch_icon_x+cch_icon_w;
//create cch_text_obj and add to collection
if (cch_text_obj == NULL){
#ifdef DEBUG_CC
printf(" [CComponentsHeader]\n [%s - %d] init header text: %s\n", __FUNCTION__, __LINE__, cch_text.c_str());
#endif
cch_text_obj = new CComponentsText(cch_text_x, cch_items_y, width-cch_icon_w-fr_thickness, height-2*fr_thickness, cch_text.c_str()); cch_text_obj = new CComponentsText(cch_text_x, cch_items_y, width-cch_icon_w-fr_thickness, height-2*fr_thickness, cch_text.c_str());
//add text item
addCCItem(cch_text_obj); //text
}
//set header text properties
if (cch_text_obj){
cch_text_obj->setTextFont(cch_font); cch_text_obj->setTextFont(cch_font);
cch_text_obj->setTextColor(cch_col_text); cch_text_obj->setTextColor(cch_col_text);
cch_text_obj->setColorBody(col_body); cch_text_obj->setColorBody(col_body);
@@ -230,14 +279,10 @@ void CComponentsHeader::initCCHeaderText()
cch_text_obj->setCornerRadius(corner_rad-fr_thickness); cch_text_obj->setCornerRadius(corner_rad-fr_thickness);
cch_text_obj->setCornerType(corner_type); cch_text_obj->setCornerType(corner_type);
} }
}
void CComponentsHeader::initCCHItems() void CComponentsHeader::initCCHItems()
{ {
#if 0
//clean up first possible old item objects, includes delete and clean up vector
clearCCItems();
#endif
//init icon //init icon
initCCHeaderIcon(); initCCHeaderIcon();
@@ -246,22 +291,13 @@ void CComponentsHeader::initCCHItems()
//init buttons //init buttons
initCCHeaderButtons(); initCCHeaderButtons();
//add elements
if (cch_icon_obj)
addCCItem(cch_icon_obj); //icon
if (cch_text_obj)
addCCItem(cch_text_obj); //text
if (cch_btn_obj)
addCCItem(cch_btn_obj); //buttons
} }
void CComponentsHeader::paint(bool do_save_bg) void CComponentsHeader::paint(bool do_save_bg)
{ {
//paint body //prepare items
paintInit(do_save_bg); initCCHItems();
//paint //paint form contents
paintCCItems(); paintForm(do_save_bg);
} }

View File

@@ -40,6 +40,7 @@ CComponentsIconForm::CComponentsIconForm()
initVarIconForm(); initVarIconForm();
} }
CComponentsIconForm::CComponentsIconForm(const int x_pos, const int y_pos, const int w, const int h, const std::vector<std::string> v_icon_names, bool has_shadow, CComponentsIconForm::CComponentsIconForm(const int x_pos, const int y_pos, const int w, const int h, const std::vector<std::string> v_icon_names, bool has_shadow,
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
{ {
@@ -111,9 +112,8 @@ int CComponentsIconForm::getIconId(const std::string& icon_name)
//to remove old items before add new icons, otherwise icons will be appended. //to remove old items before add new icons, otherwise icons will be appended.
void CComponentsIconForm::removeAllIcons() void CComponentsIconForm::removeAllIcons()
{ {
if (!v_icons.empty())
v_icons.clear();
clearCCItems(); clearCCItems();
v_icons.clear();
} }
//get maximal form height depends of biggest icon height, but don't touch defined form height //get maximal form height depends of biggest icon height, but don't touch defined form height
@@ -128,9 +128,6 @@ void CComponentsIconForm::initMaxHeight(int *pheight)
void CComponentsIconForm::initCCIcons() void CComponentsIconForm::initCCIcons()
{ {
//clean up first possible old item objects, includes delete and clean up vector and icons
clearCCItems();
int ccp_y = 0; int ccp_y = 0;
int ccp_h = 0; int ccp_h = 0;
int ccp_w = 0; int ccp_w = 0;
@@ -156,8 +153,7 @@ void CComponentsIconForm::initCCIcons()
for (size_t i= 0; i< i_cnt; i++){ for (size_t i= 0; i< i_cnt; i++){
//create new cc-picture item object //create new cc-picture item object
CComponentsPicture *ccp = NULL; CComponentsPicture *ccp = new CComponentsPicture(ccp_x, ccp_y, ccp_w, h, v_icons[i]);
ccp = new CComponentsPicture(ccp_x, ccp_y, ccp_w, h, v_icons[i]);
ccp->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER); ccp->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
ccp->doPaintBg(false); ccp->doPaintBg(false);
//add item to form //add item to form
@@ -196,9 +192,6 @@ void CComponentsIconForm::paint(bool do_save_bg)
//init and add icons //init and add icons
initCCIcons(); initCCIcons();
//paint body //paint form contents
paintInit(do_save_bg); paintForm(do_save_bg);
//paint
paintCCItems();
} }

View File

@@ -44,8 +44,9 @@ CComponentsWindow::CComponentsWindow()
CComponentsWindow::~CComponentsWindow() CComponentsWindow::~CComponentsWindow()
{ {
if (ccw_head) #ifdef DEBUG_CC
delete ccw_head; printf("[~CComponentsWindow] [%s - %d] delete...\n", __FUNCTION__, __LINE__);
#endif
cleanCCForm(); cleanCCForm();
} }
@@ -75,25 +76,29 @@ void CComponentsWindow::setWindowCaption(neutrino_locale_t locale_text)
void CComponentsWindow::initHeader() void CComponentsWindow::initHeader()
{ {
if (ccw_head){ if (ccw_head == NULL){
delete ccw_head;
ccw_head = NULL;
}
ccw_head = new CComponentsHeader(); ccw_head = new CComponentsHeader();
initHeader();
//add header item only one time
addCCItem(ccw_head);
}
//set header properties
if (ccw_head){
ccw_head->setXPos(0); ccw_head->setXPos(0);
ccw_head->setYPos(0); ccw_head->setYPos(0);
ccw_head->setWidth(width); ccw_head->setWidth(width);
ccw_head->setHeaderIcon(ccw_icon_name); ccw_head->setHeaderIcon(ccw_icon_name);
ccw_head->setHeaderText(ccw_caption); ccw_head->setHeaderText(ccw_caption);
} }
}
void CComponentsWindow::initCCWItems() void CComponentsWindow::initCCWItems()
{ {
#ifdef DEBUG_CC
printf("[CComponentsWindow] [%s - %d] init items...\n", __FUNCTION__, __LINE__);
#endif
initHeader(); initHeader();
if (ccw_head)
addCCItem(ccw_head);
} }
void CComponentsWindow::paint(bool do_save_bg) void CComponentsWindow::paint(bool do_save_bg)
@@ -101,9 +106,6 @@ void CComponentsWindow::paint(bool do_save_bg)
//prepare items before paint //prepare items before paint
initCCWItems(); initCCWItems();
//paint body //paint form contents
paintInit(do_save_bg); paintForm(do_save_bg);
//paint
paintCCItems();
} }