⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppnanalistbase.cpp

📁 基于ARM平台的控制系统,自己带有MINIGUI,可以直接在VC下运行界面演示程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    int nTextStartPosition;
    
    NANARect    TitleRc;
    if(w_style & LIST_STYLE_ICON) return;
    TitleRc.w_nX1  = rc.w_nX1 ;
    TitleRc.w_nY1 = rc.w_nY1 ;
    TitleRc.w_nY2 = w_Font->GBFontSize ;
    for(i=0;i<w_nColumnCount;i++)
    {
        DEBUG_Assert( w_cTitle[i] != -1 );
        // Get Title string by ID
        pTitleString = (char *)GetStringResource((STRINGID)w_cTitle[i]);
        DEBUG_Assert( pTitleString != NULL );
        // Get column Title  rec
        TitleRc.w_nX2 = TitleRc.w_nX1 + w_nColumnWidth[i] ;
        nStringWidth = GetTextWidth(pTitleString,w_Font,-1);
        nTextStartPosition = TitleRc.w_nX1 + (TitleRc.GetWidth () - nStringWidth) / 2;
        TextPrint(pTitleString,nTextStartPosition,
                  TitleRc.w_nY1 ,w_Font,1);
        TitleRc.w_nX1 = TitleRc.w_nX2 + 1;
    }
}




/////////////////////////////////////////////////////////////////////////////
////////////////////   NANAListItemBase     /////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
NANAListItemBase::~NANAListItemBase(){
}

NANAListItemBase::NANAListItemBase()
{
}
//called by NANAListView to draw item at specified location
void NANAListItemBase::Draw(NANARect rc,int bState,int nStyle)
{
}

//called by NANAListView to calculate rectangle area of item
//differnt styles of item will have different size
//
// (*p_width) 
//			>0:means item will take width of (*p_width) 
//			<0:means item will take whole line
// (*p_height)
//			must be >0
//
void NANAListItemBase::GetSize(int *p_width,int *p_height)
{
}


void NANAListItemBase::SetParentList(NANAListBase * pList)
{
    w_ParentList = pList;
}
//////////////////////////////////////////////////////////////////////////
//////////////    NANAListIconItem     ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void    NANAListIconItem::SetItemFont(NANA_FONT font)
{
    w_IconData.w_Font = font;
}
void    NANAListIconItem::SetItemIcon(int nIconID)
{
    w_IconData.w_nIcon = nIconID;
}

void    NANAListIconItem::SetItemText(char * pTxt)
{
    if(NULL != w_IconData.w_strText )
    {
        delete w_IconData.w_strText;
    }
    w_IconData.w_strText = new char[strlen(pTxt)];
    DEBUG_Assert(NULL != w_IconData.w_strText);
    strcpy(w_IconData.w_strText,pTxt);
}
void    NANAListIconItem::SetItemTextID(int nStringID)
{
    w_IconData.w_strID = nStringID;
}

// Set Item data
void    NANAListIconItem::SetItemData(int nData)
{
    w_IconData.w_nData = nData;
}

// Get a icon item's size,include icon and text
void NANAListIconItem::GetSize(int *p_width,int *p_height)
{
    int nTxtHeight;
    int nTxtWidth;
    char * pTxt;
    pTxt = NULL;
    if(-1 != w_IconData.w_strID)
    {
        pTxt = (char *)GetStringResource((STRINGID)w_IconData.w_strID);
    }
    else 
    {
        pTxt = w_IconData.w_strText;
    }
    if(NULL != pTxt)
    {
        TextBlockPrint(pTxt,0,0,&nTxtWidth,&nTxtHeight,
                        w_IconData.w_Font,0,ALIGN_MIDDLE,0,1);
    }
    if(w_ParentList->w_style & LIST_STYLE_ICON)
    {
        *p_width = GetIcon(w_IconData.w_nIcon)->width * 2;
        *p_height = GetIcon(w_IconData.w_nIcon)->height + 
            nTxtHeight;
    }
    if(w_ParentList->w_style & LIST_STYLE_REPORT)
    {
        *p_width = -1;
        *p_height = nTxtHeight;
    }
    *p_width += ItemFrameMargin * 2;
    *p_height += ItemFrameMargin * 2;
}
 
// Draw bitmap and text in the rc
void NANAListIconItem::Draw(NANARect rc,int bState,int nStyle)
{
    int nX;
    int nY;
    ICON * pIcon;
    char * pTxt;
    int nTxtHeight;
    int nTxtWidth;
    RectangleBlock(rc.w_nX1,rc.w_nY1,rc.GetWidth(),rc.GetHeight(),
        ((bState & ITEMSTATE_SELECTED) == ITEMSTATE_SELECTED)?0:1);
    rc.w_nX1 += ItemFrameMargin;
    rc.w_nX2 -= ItemFrameMargin;
    rc.w_nY1 += ItemFrameMargin;
    rc.w_nY2 -= ItemFrameMargin;
    if(w_IconData.w_nIcon != -1)
    {
        // Icon is initialized
        pIcon = GetIcon(w_IconData.w_nIcon);
        if(NULL != pIcon)
        {
            // Icon is valiabled
            nX = rc.w_nX1 + ((rc.GetWidth() - pIcon->width) / 2);
            DrawICON(w_IconData.w_nIcon,nX,rc.w_nY1,
                (bState & ITEMSTATE_SELECTED)?1:0);
        }
    }
    nY = rc.w_nY1 + pIcon->height;
    pTxt = NULL;
    if( w_IconData.w_strID != -1 )
    {
        pTxt = (char *)GetStringResource((STRINGID)w_IconData.w_strID);
    }else if(NULL != w_IconData.w_strText )
    {
        pTxt = w_IconData.w_strText ;
    }

    if(NULL != pTxt)
    {
        nTxtWidth = rc.GetWidth();
        nTxtHeight = rc.GetHeight() - pIcon->height;
        TextBlockPrint(pTxt,rc.w_nX1,nY,&nTxtWidth,&nTxtHeight,
                        w_IconData.w_Font,
                        (bState & ITEMSTATE_SELECTED)?1:0,
                        ALIGN_MIDDLE,0,0);
    }
}


//////////////////////////////////////////////////////////////////////////
//////////////    NANAListTextItem     ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void NANAListTextItem::Draw(NANARect rc,int bState,int nStyle)
{
    NANARect GridBoxRc;
    int i;
    char pTxt[100];
    RectangleBlock(rc.w_nX1,rc.w_nY1,rc.GetWidth(),rc.GetHeight(),
    ((bState & ITEMSTATE_SELECTED) == ITEMSTATE_SELECTED)?COLOR_BKGROUND:COLOR_BORDER);
    
    GridBoxRc.w_nX1 = rc.w_nX1 ;
    GridBoxRc.w_nY1 = rc.w_nY1 ;
    GridBoxRc.w_nY2 = rc.w_nY2 ;
    for( i = 0 ; i < w_nSubItemNum ; i++)
    {
        GridBoxRc.w_nX2 = GridBoxRc.w_nX1 +  w_ParentList->GetColumnWidth(i);
        w_pSubItem[i].GetItemText(pTxt,sizeof(pTxt));
        TextPrint(pTxt,GridBoxRc.w_nX1, GridBoxRc.w_nY1 ,w_pSubItem[i].w_Font ,
            ((bState & ITEMSTATE_SELECTED) == ITEMSTATE_SELECTED)?COLOR_BORDER:COLOR_BKGROUND);
        GridBoxRc.w_nX1 = GridBoxRc.w_nX2 + 1;
    }
    
}

void NANAListTextItem::GetSize(int *p_width,int *p_height)
{
    if(w_pSubItem != NULL)
    {
        *p_width = -1;
        *p_height = w_pSubItem[0].w_Font->ASCIIFontHeight;
    }else
    {
        *p_width = 0;
        *p_height = 0;
    }
}

void NANAListTextItem::SetItemFont(NANA_FONT font)
{
    int i;
    for(i=0;i<w_nSubItemNum;i++)
    {
        w_pSubItem[i].w_Font = font;
    }
}

void NANAListTextItem::SetTextStyle(int nSubItem , int nTextStyle)
{
    DEBUG_Assert(nSubItem < w_nSubItemNum);
    w_pSubItem[nSubItem].w_nTextStyle = nTextStyle;
}


void NANAListTextItem::SetItemText(int nSubItem, char * pTxt)
{
    DEBUG_Assert(nSubItem < w_nSubItemNum);
    if(w_pSubItem[nSubItem].w_strText != NULL)
    {
        delete []w_pSubItem[nSubItem].w_strText;
    }
    w_pSubItem[nSubItem].w_strText = new char[strlen(pTxt) + 1];
    DEBUG_Assert(nSubItem < w_nSubItemNum);
    strcpy(w_pSubItem[nSubItem].w_strText,pTxt); 
}

void NANAListTextItem::SetItemTextID(int nSubItem, int nStringID)
{
    DEBUG_Assert(nSubItem < w_nSubItemNum);
    w_pSubItem[nSubItem].w_strID  = nStringID;
}

// Realloc the sub item
void NANAListTextItem::SetSubItemNum(int nSubItemNum)
{
    int i;
    if(NULL != w_pSubItem)
    {
        delete []w_pSubItem;
    }
    w_nSubItemNum = nSubItemNum;
    w_pSubItem = new TextItem[nSubItemNum];
    for(i=0;i<w_nSubItemNum;i++)
    {
        w_pSubItem[i].w_strText = NULL;    
        w_pSubItem[i].w_strID = -1;    
        w_pSubItem[i].w_Font = &NANA_FONT16x;
        w_pSubItem[i].w_nTextStyle = w_nTextStyle;
    }
}


//////////////////////////////////////////////////////////////////////////
//////////////    NANAListTextItem     ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////



void TextItem::GetItemText(char * pTxt ,int nBufferSize)
{
    sprintf(pTxt,"");
    switch(w_nTextStyle)
    {
    case ICONITEM_TXT_STYLE_AUTO:
        if(-1 != w_strID)
        {
            sprintf(pTxt,"%s",(char *)GetStringResource((STRINGID)w_strID));
        }
        else 
        {
            sprintf(pTxt,"%s",w_strText);
        }
        break;
    case ICONITEM_TXT_STYLE_ONLYSTR:
        sprintf(pTxt,"%s",w_strText);
        break;
    case ICONITEM_TXT_STYLE_ONLYID:
        sprintf(pTxt,"%s",(char *)GetStringResource((STRINGID)w_strID));
        break;
    case ICONITEM_TXT_STYLE_STR_ID:
        sprintf(pTxt,"%s%s",w_strText,
            (char *)GetStringResource((STRINGID)w_strID));
        break;
    case ICONITEM_TXT_STYLE_ID_STR:
        sprintf(pTxt,"%s%s",
            (char *)GetStringResource((STRINGID)w_strID),w_strText);
        break;
    default:
        break;
    }
    DEBUG_Assert( nBufferSize > (int)strlen(pTxt));
}












⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -