CComponentsText: fix possible segfault

segfault happens on left empty text

CComponentsInfoBox: inherit ct_textbox

CComponentsInfoBox: inherit ct_box

CComponentsInfoBox: inherit ct_box
This commit is contained in:
2012-10-23 21:25:20 +02:00
parent bb39d1f64f
commit d970c5303f
2 changed files with 53 additions and 42 deletions

View File

@@ -218,17 +218,19 @@ class CComponentsPicture : public CComponentsItem
class CComponentsText : public CComponentsItem class CComponentsText : public CComponentsItem
{ {
private: protected:
Font* ct_font; CTextBox * ct_textbox;
CBox * ct_box; CBox * ct_box;
CTextBox * ct_textbox; Font * ct_font;
void initVarText();
private:
const char* ct_text; const char* ct_text;
int ct_text_mode; //see textbox.h for possible modes int ct_text_mode; //see textbox.h for possible modes
fb_pixel_t ct_col_text; fb_pixel_t ct_col_text;
bool ct_text_sended; bool ct_text_sended;
void initVarText();
void initText(); void initText();
public: public:
@@ -249,9 +251,7 @@ class CComponentsInfoBox : public CComponentsText
const char* text; const char* text;
int text_mode; //see textbox.h for possible modes int text_mode; //see textbox.h for possible modes
int x_text, x_offset; int x_text, x_offset;
Font* font;
CBox * box;
CTextBox * textbox;
CComponentsPicture * pic; CComponentsPicture * pic;
std::string pic_default_name; std::string pic_default_name;
@@ -269,11 +269,11 @@ class CComponentsInfoBox : public CComponentsText
~CComponentsInfoBox(); ~CComponentsInfoBox();
inline void setText(const char* info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text; text_mode = mode, font = font_text;}; inline void setText(const char* info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text; text_mode = mode, ct_font = font_text;};
inline void setText(const std::string& info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text.c_str(); text_mode = mode, font = font_text;}; inline void setText(const std::string& info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text.c_str(); text_mode = mode, ct_font = font_text;};
void setText(neutrino_locale_t locale_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL); void setText(neutrino_locale_t locale_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL);
inline void setTextMode(const int mode){text_mode = mode;};//see textbox.h for possible modes inline void setTextMode(const int mode){text_mode = mode;};//see textbox.h for possible modes
inline void setTextFont(Font* font_text){font = font_text;}; inline void setTextFont(Font* font_text){ct_font = font_text;};
inline void setTextColor(fb_pixel_t color_text){ ibox_col_text = color_text;}; inline void setTextColor(fb_pixel_t color_text){ ibox_col_text = color_text;};
inline void setSpaceOffset(const int offset){x_offset = offset;}; inline void setSpaceOffset(const int offset){x_offset = offset;};
inline void setPicture(const std::string& picture_name){pic_name = picture_name;}; inline void setPicture(const std::string& picture_name){pic_name = picture_name;};

View File

@@ -274,9 +274,15 @@ CComponentsText::~CComponentsText()
{ {
hide(); hide();
clearSavedScreen(); clearSavedScreen();
delete ct_font;
delete ct_box; if (ct_box)
delete ct_textbox; delete ct_box;
ct_box = NULL;
if (ct_textbox)
delete ct_textbox;
ct_textbox = NULL;
clear(); clear();
} }
@@ -343,7 +349,8 @@ void CComponentsText::paint(bool do_save_bg)
void CComponentsText::hide(bool no_restore) void CComponentsText::hide(bool no_restore)
{ {
ct_textbox->hide(); if (ct_textbox)
ct_textbox->hide();
hideContainer(no_restore); hideContainer(no_restore);
} }
@@ -351,14 +358,13 @@ void CComponentsText::hide(bool no_restore)
//sub class CComponentsInfoBox from CComponentsItem //sub class CComponentsInfoBox from CComponentsItem
CComponentsInfoBox::CComponentsInfoBox() CComponentsInfoBox::CComponentsInfoBox()
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem, CComponentsText
initVarItem(); initVarText();
//CComponentsInfoBox //CComponentsInfoBox
initVarInfobox(); initVarInfobox();
text = NULL; text = NULL;
text_mode = CTextBox::AUTO_WIDTH; text_mode = CTextBox::AUTO_WIDTH;
font = NULL;
ibox_col_text = COL_MENUCONTENT; ibox_col_text = COL_MENUCONTENT;
} }
@@ -367,8 +373,8 @@ CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const i
bool has_shadow, bool has_shadow,
fb_pixel_t color_text, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) fb_pixel_t color_text, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem, CComponentsText
initVarItem(); initVarText();
x = x_pos; x = x_pos;
y = y_pos; y = y_pos;
@@ -383,7 +389,7 @@ CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const i
initVarInfobox(); initVarInfobox();
text = info_text; text = info_text;
text_mode = mode; text_mode = mode;
font = font_text; ct_font = font_text;
ibox_col_text = color_text; ibox_col_text = color_text;
} }
@@ -391,8 +397,15 @@ CComponentsInfoBox::~CComponentsInfoBox()
{ {
hide(); hide();
clearSavedScreen(); clearSavedScreen();
delete textbox;
delete box; if (ct_textbox)
delete ct_textbox;
ct_textbox = NULL;
if (ct_box)
delete ct_box;
ct_box = NULL;
delete pic; delete pic;
clear(); clear();
} }
@@ -400,11 +413,9 @@ CComponentsInfoBox::~CComponentsInfoBox()
void CComponentsInfoBox::initVarInfobox() void CComponentsInfoBox::initVarInfobox()
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem
initVarItem(); initVarText();
//CComponentsInfoBox //CComponentsInfoBox
box = NULL;
textbox = NULL;
pic = NULL; pic = NULL;
pic_name = ""; pic_name = "";
x_offset = 10; x_offset = 10;
@@ -416,7 +427,7 @@ void CComponentsInfoBox::setText(neutrino_locale_t locale_text, int mode, Font*
{ {
text = g_Locale->getText(locale_text); text = g_Locale->getText(locale_text);
text_mode = mode; text_mode = mode;
font = font_text; ct_font = font_text;
} }
void CComponentsInfoBox::paintPicture() void CComponentsInfoBox::paintPicture()
@@ -439,32 +450,32 @@ void CComponentsInfoBox::paintPicture()
void CComponentsInfoBox::paintText() void CComponentsInfoBox::paintText()
{ {
if (box == NULL) if (ct_box == NULL)
box = new CBox(); ct_box = new CBox();
box->iX = x_text; ct_box->iX = x_text;
box->iY = y+fr_thickness; ct_box->iY = y+fr_thickness;
//text width and height //text width and height
box->iWidth = width-2*fr_thickness-(x_text-x); ct_box->iWidth = width-2*fr_thickness-(x_text-x);
box->iHeight = height-2*fr_thickness; ct_box->iHeight = height-2*fr_thickness;
//init textbox //init textbox
if (textbox == NULL) { if (ct_textbox == NULL) {
textbox = new CTextBox(text, font, text_mode, box, col_body); ct_textbox = new CTextBox(text, ct_font, text_mode, ct_box, col_body);
textbox->setTextBorderWidth(0); ct_textbox->setTextBorderWidth(0);
textbox->enableBackgroundPaint(false); ct_textbox->enableBackgroundPaint(false);
} }
//set properties //set properties
textbox->setTextFont(font); ct_textbox->setTextFont(ct_font);
textbox->setWindowPos(box); ct_textbox->setWindowPos(ct_box);
textbox->setTextColor(ibox_col_text); ct_textbox->setTextColor(ibox_col_text);
//set text //set text
string new_text = static_cast <string> (text); string new_text = static_cast <string> (text);
if (textbox->setText(&new_text)) if (ct_textbox->setText(&new_text))
textbox->paint(); ct_textbox->paint();
} }
void CComponentsInfoBox::paint(bool do_save_bg) void CComponentsInfoBox::paint(bool do_save_bg)