CComponentsItem: add members getItemType(), cc_item_type

Small helper for detection of item types.
This could be useful, if it is necessary, to track these at runtime or
debugging, because it's not really detectable, which items just be used.
e.g forms could contain very much items, but many of these items
are inherited from CComponentsItem and an assignment to a certain subclass.
This commit is contained in:
2012-12-04 19:11:01 +01:00
parent 9605d7438f
commit 6175fd989d
2 changed files with 43 additions and 1 deletions

View File

@@ -172,17 +172,35 @@ class CComponents
class CComponentsItem : public CComponents class CComponentsItem : public CComponents
{ {
protected: protected:
int cc_item_type;
void hideCCItem(bool no_restore = false); void hideCCItem(bool no_restore = false);
void paintInit(bool do_save_bg); void paintInit(bool do_save_bg);
void initVarItem(); void initVarItem();
public: public:
enum
{
CC_ITEMTYPE_BASE,
CC_ITEMTYPE_PICTURE,
CC_ITEMTYPE_TEXT,
CC_ITEMTYPE_TEXT_INFOBOX,
CC_ITEMTYPE_SHAPE_SQUARE,
CC_ITEMTYPE_SHAPE_CIRCLE,
CC_ITEMTYPE_PIP,
CC_ITEMTYPE_FRM,
CC_ITEMTYPE_FRM_HERADER,
CC_ITEMTYPE_FRM_ICONFORM,
CC_ITEMTYPE_FRM_WINDOW,
CC_ITEMTYPES
};
CComponentsItem(); CComponentsItem();
virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES) = 0; virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES) = 0;
virtual void hide(bool no_restore = false); virtual void hide(bool no_restore = false);
virtual void kill(); virtual void kill();
virtual int getItemType();
virtual void syncSysColors(); virtual void syncSysColors();
}; };

View File

@@ -171,6 +171,7 @@ CComponentsItem::CComponentsItem()
{ {
//CComponentsItem //CComponentsItem
initVarItem(); initVarItem();
cc_item_type = CC_ITEMTYPE_BASE;
} }
// y // y
@@ -267,6 +268,19 @@ void CComponentsItem::syncSysColors()
col_frame = COL_MENUCONTENT_PLUS_6; col_frame = COL_MENUCONTENT_PLUS_6;
} }
//returns current item element type, if no available, return -1 as unknown type
int CComponentsItem::getItemType()
{
for(int i =0; i< (CC_ITEMTYPES) ;i++){
if (i == cc_item_type)
return i;
}
#ifdef DEBUG_CC
printf("[CComponentsItem] %s: unknown item type requested...\n", __FUNCTION__);
#endif
return -1;
}
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
//sub class CComponentsText from CComponentsItem //sub class CComponentsText from CComponentsItem
@@ -316,6 +330,7 @@ void CComponentsText::initVarText()
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem
initVarItem(); initVarItem();
cc_item_type = CC_ITEMTYPE_TEXT;
//CComponentsText //CComponentsText
ct_font = NULL; ct_font = NULL;
@@ -466,6 +481,7 @@ void CComponentsInfoBox::initVarInfobox()
{ {
//CComponents, CComponentsItem, CComponentsText //CComponents, CComponentsItem, CComponentsText
initVarText(); initVarText();
cc_item_type = CC_ITEMTYPE_TEXT_INFOBOX;
//CComponentsInfoBox //CComponentsInfoBox
pic = NULL; pic = NULL;
@@ -524,6 +540,7 @@ CComponentsShapeSquare::CComponentsShapeSquare(const int x_pos, const int y_pos,
{ {
//CComponentsItem //CComponentsItem
initVarItem(); initVarItem();
cc_item_type = CC_ITEMTYPE_SHAPE_SQUARE;
x = x_pos; x = x_pos;
y = y_pos; y = y_pos;
@@ -549,6 +566,7 @@ CComponentsShapeCircle::CComponentsShapeCircle( int x_pos, int y_pos, int diam,
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem
initVarItem(); initVarItem();
cc_item_type = CC_ITEMTYPE_SHAPE_CIRCLE;
//CComponents //CComponents
x = x_pos; x = x_pos;
@@ -725,6 +743,7 @@ CComponentsPIP::CComponentsPIP( const int x_pos, const int y_pos, const int perc
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem
initVarItem(); initVarItem();
cc_item_type = CC_ITEMTYPE_PIP;
//CComponentsPIP //CComponentsPIP
screen_w = frameBuffer->getScreenWidth(true); screen_w = frameBuffer->getScreenWidth(true);
@@ -784,6 +803,7 @@ void CComponentsPicture::init( int x_pos, int y_pos, const string& image_name, c
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem
initVarItem(); initVarItem();
cc_item_type = CC_ITEMTYPE_PICTURE;
//CComponentsPicture //CComponentsPicture
pic_name = image_name; pic_name = image_name;
@@ -1550,6 +1570,7 @@ void CComponentsForm::initVarForm()
{ {
//CComponentsItem //CComponentsItem
initVarItem(); initVarItem();
//simple default dimensions //simple default dimensions
x = 0; x = 0;
@@ -1801,6 +1822,7 @@ void CComponentsHeader::initVarHeader()
//CComponentsForm //CComponentsForm
initVarForm(); initVarForm();
cc_item_type = CC_ITEMTYPE_FRM_HERADER;
height = cch_font->getHeight(); height = cch_font->getHeight();
col_body = COL_MENUHEAD_PLUS_0; col_body = COL_MENUHEAD_PLUS_0;
corner_rad = RADIUS_LARGE, corner_rad = RADIUS_LARGE,
@@ -1986,6 +2008,7 @@ void CComponentsIconForm::initVarIconForm()
{ {
//CComponentsForm //CComponentsForm
initVarForm(); initVarForm();
cc_item_type = CC_ITEMTYPE_FRM_ICONFORM;
//set default width and height to 0, this causes a dynamic adaptation of width and height of form //set default width and height to 0, this causes a dynamic adaptation of width and height of form
width = 0; width = 0;
@@ -2138,6 +2161,7 @@ void CComponentsWindow::initVarWindow()
{ {
//CComponentsForm //CComponentsForm
initVarForm(); initVarForm();
cc_item_type = CC_ITEMTYPE_FRM_WINDOW;
ccw_head = NULL; ccw_head = NULL;
ccw_caption = ""; ccw_caption = "";