From ad102b69fdebdd3c4e54f28615ce79af7885138e Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 22 Oct 2013 19:57:03 +0200 Subject: [PATCH] CComponentsHeader: use isAdded() to avoid add multiple items --- src/gui/components/cc_frm_header.cpp | 30 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index 554601fb9..11bc47731 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -168,10 +168,12 @@ void CComponentsHeader::initIcon() 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 } + //add item only one time + if (!cch_icon_obj->isAdded()) + addCCItem(cch_icon_obj); //icon + //get dimensions of header icon int iw, ih; frameBuffer->getIconSize(cch_icon_name, &iw, &ih); @@ -242,6 +244,10 @@ void CComponentsHeader::initButtonFormSize() { cch_buttons_w = 0; cch_buttons_h = 0; + + if (cch_btn_obj == NULL) + return; + for(size_t i=0; igetIconSize(v_cch_btn[i].c_str(), &bw, &bh); @@ -254,9 +260,13 @@ void CComponentsHeader::initButtonFormSize() void CComponentsHeader::initButtons() { //exit if no button defined - if (v_cch_btn.empty()) + if (v_cch_btn.empty()){ + if (cch_btn_obj) + delete cch_btn_obj; + cch_btn_obj = NULL; return; - + } + initButtonFormSize(); if (cch_btn_obj == NULL){ @@ -264,10 +274,12 @@ void CComponentsHeader::initButtons() #ifdef DEBUG_CC printf(" [CComponentsHeader]\n [%s - %d] init header buttons...\n", __FUNCTION__, __LINE__); #endif - //add button form - addCCItem(cch_btn_obj); //buttons } + //add button form only one time + if (!cch_btn_obj->isAdded()) + addCCItem(cch_btn_obj); //buttons + //set button form properties if (cch_btn_obj){ cch_btn_obj->setDimensionsAll(width-cch_offset-cch_buttons_w, cch_items_y, cch_buttons_w, cch_buttons_h); @@ -315,10 +327,12 @@ void CComponentsHeader::initCaption() printf(" [CComponentsHeader]\n [%s - %d] init header text: %s [ x %d w %d ]\n", __FUNCTION__, __LINE__, cch_text.c_str(), cch_text_x, cc_text_w); #endif cch_text_obj = new CComponentsText(); - //add text item - addCCItem(cch_text_obj); //text } + //add text item + if (!cch_text_obj->isAdded()) + addCCItem(cch_text_obj); //text + //set header text properties if (cch_text_obj){ cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height);