mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-28 07:51:11 +02:00
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:
@@ -377,6 +377,7 @@ class CComponentsForm : public CComponentsItem
|
||||
std::vector<CComponentsItem*> v_cc_items;
|
||||
void initVarForm();
|
||||
void clearCCItems();
|
||||
void paintForm(bool do_save_bg);
|
||||
public:
|
||||
|
||||
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);
|
||||
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);
|
||||
// ~CComponentsHeader(); //inherited from CComponentsForm
|
||||
~CComponentsHeader();
|
||||
|
||||
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
|
||||
void setHeaderText(const std::string& caption);
|
||||
|
@@ -68,26 +68,33 @@ CComponentsForm::~CComponentsForm()
|
||||
void CComponentsForm::cleanCCForm()
|
||||
{
|
||||
#ifdef DEBUG_CC
|
||||
printf("[CComponents] calling %s...\n", __FUNCTION__);
|
||||
printf("[CComponentsForm] [%s - %d] clean up...\n", __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
hide();
|
||||
clearSavedScreen();
|
||||
// hide();
|
||||
clearCCItems();
|
||||
clearSavedScreen();
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CComponentsForm::clearCCItems()
|
||||
{
|
||||
if (v_cc_items.empty())
|
||||
return;
|
||||
#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
|
||||
|
||||
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];
|
||||
v_cc_items[i] = NULL;
|
||||
}
|
||||
}
|
||||
v_cc_items.clear();
|
||||
}
|
||||
|
||||
@@ -118,7 +125,16 @@ void CComponentsForm::initVarForm()
|
||||
|
||||
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);
|
||||
}
|
||||
#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)
|
||||
@@ -191,15 +207,20 @@ void CComponentsForm::removeCCItem(const uint& cc_item_id)
|
||||
#endif
|
||||
}
|
||||
|
||||
void CComponentsForm::paint(bool do_save_bg)
|
||||
void CComponentsForm::paintForm(bool do_save_bg)
|
||||
{
|
||||
//paint body
|
||||
paintInit(do_save_bg);
|
||||
|
||||
//paint items
|
||||
//paint
|
||||
paintCCItems();
|
||||
}
|
||||
|
||||
void CComponentsForm::paint(bool do_save_bg)
|
||||
{
|
||||
paintForm(do_save_bg);
|
||||
}
|
||||
|
||||
void CComponentsForm::paintCCItems()
|
||||
{
|
||||
size_t items_count = v_cc_items.size();
|
||||
|
@@ -82,11 +82,11 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in
|
||||
cch_locale_text = caption_locale;
|
||||
cch_icon_name = icon_name;
|
||||
cch_buttons = buttons;
|
||||
|
||||
initCCHDefaultButtons();
|
||||
initCCHItems();
|
||||
}
|
||||
|
||||
|
||||
void CComponentsHeader::initVarHeader()
|
||||
{
|
||||
//CComponentsHeader
|
||||
@@ -116,6 +116,15 @@ void CComponentsHeader::initVarHeader()
|
||||
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)
|
||||
{
|
||||
cch_text = caption;
|
||||
@@ -133,19 +142,36 @@ void CComponentsHeader::setHeaderIcon(const char* icon_name)
|
||||
|
||||
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) {
|
||||
cch_icon_w = cch_btn_offset;
|
||||
if (cch_icon_obj)
|
||||
delete cch_icon_obj;
|
||||
cch_icon_obj = NULL;
|
||||
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);
|
||||
//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->setHeight(height);
|
||||
cch_icon_obj->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
|
||||
cch_icon_obj->doPaintBg(false);
|
||||
|
||||
//corner of icon item
|
||||
//set corner mode of icon item
|
||||
cch_icon_obj->setCornerRadius(corner_rad-fr_thickness);
|
||||
int cc_icon_corner_type = corner_type;
|
||||
if (corner_type == CORNER_TOP_LEFT || corner_type == CORNER_TOP)
|
||||
@@ -156,14 +182,11 @@ void CComponentsHeader::initCCHeaderIcon()
|
||||
|
||||
//set width of icon object
|
||||
cch_icon_w = cch_icon_obj->getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
initCCHeaderButtons();
|
||||
}
|
||||
@@ -171,10 +194,9 @@ void CComponentsHeader::addHeaderButton(const std::string& button_name)
|
||||
void CComponentsHeader::removeHeaderButtons()
|
||||
{
|
||||
v_cch_btn.clear();
|
||||
if (cch_btn_obj){
|
||||
delete cch_btn_obj;
|
||||
cch_btn_obj = NULL;
|
||||
}
|
||||
cch_btn_obj->removeAllIcons();
|
||||
initCCHeaderButtons();
|
||||
|
||||
}
|
||||
|
||||
void CComponentsHeader::initCCHDefaultButtons()
|
||||
@@ -187,6 +209,9 @@ void CComponentsHeader::initCCHDefaultButtons()
|
||||
v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_INFO);
|
||||
if (cch_buttons & CC_BTN_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
|
||||
@@ -208,19 +233,43 @@ void CComponentsHeader::initCCHeaderButtons()
|
||||
|
||||
initCCButtonFormSize();
|
||||
|
||||
if (cch_btn_obj == NULL){
|
||||
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->doPaintBg(false);
|
||||
cch_btn_obj->setIconOffset(cch_btn_offset);
|
||||
cch_btn_obj->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT);
|
||||
cch_btn_obj->removeAllIcons();
|
||||
cch_btn_obj->addIcon(v_cch_btn);
|
||||
}
|
||||
}
|
||||
|
||||
void CComponentsHeader::initCCHeaderText()
|
||||
{
|
||||
//reset header text position first
|
||||
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());
|
||||
//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->setTextColor(cch_col_text);
|
||||
cch_text_obj->setColorBody(col_body);
|
||||
@@ -229,15 +278,11 @@ void CComponentsHeader::initCCHeaderText()
|
||||
//corner of text item
|
||||
cch_text_obj->setCornerRadius(corner_rad-fr_thickness);
|
||||
cch_text_obj->setCornerType(corner_type);
|
||||
}
|
||||
}
|
||||
|
||||
void CComponentsHeader::initCCHItems()
|
||||
{
|
||||
#if 0
|
||||
//clean up first possible old item objects, includes delete and clean up vector
|
||||
clearCCItems();
|
||||
#endif
|
||||
|
||||
//init icon
|
||||
initCCHeaderIcon();
|
||||
|
||||
@@ -246,22 +291,13 @@ void CComponentsHeader::initCCHItems()
|
||||
|
||||
//init buttons
|
||||
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)
|
||||
{
|
||||
//paint body
|
||||
paintInit(do_save_bg);
|
||||
//prepare items
|
||||
initCCHItems();
|
||||
|
||||
//paint
|
||||
paintCCItems();
|
||||
//paint form contents
|
||||
paintForm(do_save_bg);
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ CComponentsIconForm::CComponentsIconForm()
|
||||
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,
|
||||
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.
|
||||
void CComponentsIconForm::removeAllIcons()
|
||||
{
|
||||
if (!v_icons.empty())
|
||||
v_icons.clear();
|
||||
clearCCItems();
|
||||
v_icons.clear();
|
||||
}
|
||||
|
||||
//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()
|
||||
{
|
||||
//clean up first possible old item objects, includes delete and clean up vector and icons
|
||||
clearCCItems();
|
||||
|
||||
int ccp_y = 0;
|
||||
int ccp_h = 0;
|
||||
int ccp_w = 0;
|
||||
@@ -156,8 +153,7 @@ void CComponentsIconForm::initCCIcons()
|
||||
|
||||
for (size_t i= 0; i< i_cnt; i++){
|
||||
//create new cc-picture item object
|
||||
CComponentsPicture *ccp = NULL;
|
||||
ccp = new CComponentsPicture(ccp_x, ccp_y, ccp_w, h, v_icons[i]);
|
||||
CComponentsPicture *ccp = new CComponentsPicture(ccp_x, ccp_y, ccp_w, h, v_icons[i]);
|
||||
ccp->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
|
||||
ccp->doPaintBg(false);
|
||||
//add item to form
|
||||
@@ -196,9 +192,6 @@ void CComponentsIconForm::paint(bool do_save_bg)
|
||||
//init and add icons
|
||||
initCCIcons();
|
||||
|
||||
//paint body
|
||||
paintInit(do_save_bg);
|
||||
|
||||
//paint
|
||||
paintCCItems();
|
||||
//paint form contents
|
||||
paintForm(do_save_bg);
|
||||
}
|
||||
|
@@ -44,8 +44,9 @@ CComponentsWindow::CComponentsWindow()
|
||||
|
||||
CComponentsWindow::~CComponentsWindow()
|
||||
{
|
||||
if (ccw_head)
|
||||
delete ccw_head;
|
||||
#ifdef DEBUG_CC
|
||||
printf("[~CComponentsWindow] [%s - %d] delete...\n", __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
cleanCCForm();
|
||||
}
|
||||
|
||||
@@ -75,25 +76,29 @@ void CComponentsWindow::setWindowCaption(neutrino_locale_t locale_text)
|
||||
|
||||
void CComponentsWindow::initHeader()
|
||||
{
|
||||
if (ccw_head){
|
||||
delete ccw_head;
|
||||
ccw_head = NULL;
|
||||
}
|
||||
if (ccw_head == NULL){
|
||||
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->setYPos(0);
|
||||
ccw_head->setWidth(width);
|
||||
ccw_head->setHeaderIcon(ccw_icon_name);
|
||||
ccw_head->setHeaderText(ccw_caption);
|
||||
}
|
||||
}
|
||||
|
||||
void CComponentsWindow::initCCWItems()
|
||||
{
|
||||
#ifdef DEBUG_CC
|
||||
printf("[CComponentsWindow] [%s - %d] init items...\n", __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
initHeader();
|
||||
|
||||
if (ccw_head)
|
||||
addCCItem(ccw_head);
|
||||
}
|
||||
|
||||
void CComponentsWindow::paint(bool do_save_bg)
|
||||
@@ -101,9 +106,6 @@ void CComponentsWindow::paint(bool do_save_bg)
|
||||
//prepare items before paint
|
||||
initCCWItems();
|
||||
|
||||
//paint body
|
||||
paintInit(do_save_bg);
|
||||
|
||||
//paint
|
||||
paintCCItems();
|
||||
//paint form contents
|
||||
paintForm(do_save_bg);
|
||||
}
|
||||
|
Reference in New Issue
Block a user