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

📄 doublelistbox.cpp

📁 0S9.平台任务管理.内存监控示例.还sign后才可以安装
💻 CPP
字号:
#include "ListBoxProxy.h"

#include <coemain.h>    // CCoeEnv
#include <eikenv.h>     // CEikonEnv
#include <eiklbi.h>     // CListItemDrawer
#include <eiktxlbm.h>   // CTextListBoxModel

class CDoubleListBoxItemDrawer : public CListItemDrawer
{
public:
    CDoubleListBoxItemDrawer(MTextListBoxModel* aTextListBoxModel);
    ~CDoubleListBoxItemDrawer();

    void SetIconArray(CArrayPtr<CGulIcon>* aIconArray);

protected:
    void DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect, TBool aItemIsCurrent, TBool aViewIsEmphasized, TBool aViewIsDimmed, TBool aItemIsSelected) const;
    void DeleteIconArray();

private:
    MTextListBoxModel* iModel;
    CArrayPtr<CGulIcon>* iIconArray;
};

CDoubleListBoxItemDrawer::CDoubleListBoxItemDrawer(MTextListBoxModel* aTextListBoxModel)
    : iModel(aTextListBoxModel)
{
    SetGc(&CCoeEnv::Static()->SystemGc());
}

CDoubleListBoxItemDrawer::~CDoubleListBoxItemDrawer()
{
    DeleteIconArray();
}

void CDoubleListBoxItemDrawer::SetIconArray(CArrayPtr<CGulIcon>* aIconArray)
{
    DeleteIconArray();
    iIconArray = aIconArray;
}


/*
 * Item consists of the following fields: "IconIndex\tTitleText\tSecondaryText\tSecondaryIcon1Index\tSecondaryIcon2Index"
 * Both secondary text and icons are optional
 * 
 * Example: "0\tTitle\tDescription\t1\t2"
 *          "1\tTitle\tDescription"
 *          "2\tTitle"
 */

void CDoubleListBoxItemDrawer::DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect, TBool aItemIsCurrent, TBool /*aViewIsEmphasized*/, TBool /*aViewIsDimmed*/, TBool aItemIsSelected) const
{
    // Get item text string
    TPtrC itemText = iModel->ItemText(aItemIndex);

    // Only first tab is mandatory
    TInt tabPos1 = itemText.Locate('\t');
    TInt tabPos2 = itemText.Mid(tabPos1 + 1).Locate('\t');

    // Make tabPos2 value absolute with respect to itemText
    if (tabPos2 > 0)
        tabPos2 += tabPos1 + 1;

    TInt iconIndex = 0;
    TLex(itemText.Mid(0, tabPos1)).Val(iconIndex);

    // Sets the attributes to draw the icon.
    iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
    if (aItemIsCurrent || aItemIsSelected)
    {
        iGc->SetPenColor(iHighlightedTextColor);
        iGc->SetBrushColor(iHighlightedBackColor);
    }
    else
    {
        iGc->SetPenColor(iTextColor);
        iGc->SetBrushColor(iBackColor);
    }

    // Clear item rectangle
    iGc->Clear(aActualItemRect);


#if   defined(__S80__)
    const TSize KIconSize(44, 44);
#elif defined(__S90__)
    const TSize KIconSize(64, 50);
#elif defined(__UIQ__)
    const TSize KIconSize(32, 32);
#endif

    // Draws the icon.
    CFbsBitmap* bitmap = (*iIconArray)[iconIndex]->Bitmap();
    iGc->BitBltMasked(aActualItemRect.iTl, bitmap, TRect(TPoint(0, 0), KIconSize), (*iIconArray)[iconIndex]->Mask(), ETrue);

    // Draws surrounding rectangle, in case there are some icons that are smaller
    iGc->SetPenStyle(CGraphicsContext::ENullPen);
    if (bitmap->Header().iSizeInPixels.iHeight < aActualItemRect.Height())
    {
        TRect rect (aActualItemRect.iTl.iX, 
                    aActualItemRect.iTl.iY + bitmap->Header().iSizeInPixels.iHeight, 
                    aActualItemRect.iTl.iX + KIconSize.iWidth, 
                    aActualItemRect.iBr.iY);
        iGc->DrawRect(rect);
    }

    if (bitmap->Header().iSizeInPixels.iWidth < KIconSize.iWidth)
    {
        TRect rect (aActualItemRect.iTl.iX + bitmap->Header().iSizeInPixels.iWidth,
                    aActualItemRect.iTl.iY,
                    aActualItemRect.iTl.iX + KIconSize.iWidth,
                    aActualItemRect.iBr.iY);
        iGc->DrawRect(rect);
    }


#if   defined(__S80__)
    const CFont* font = CEikonEnv::Static()->TitleFont();
#elif defined(__S90__)
    const CFont* font = CEikonEnv::Static()->DenseFont();
#elif defined(__UIQ__)
    const CFont* font = CEikonEnv::Static()->TitleFont();
#endif
    iGc->UseFont(font);

    iGc->SetPenStyle(CGraphicsContext::ESolidPen);
    iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);

    TRect textRect(TPoint(aActualItemRect.iTl.iX + KIconSize.iWidth, aActualItemRect.iTl.iY), aActualItemRect.iBr);
    textRect.iBr.iY -= aActualItemRect.Height() / 2;

    TInt baseline = (textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2 + font->AscentInPixels();

    // Display text
    if (tabPos2 < 0)
    {
        // Display title only
        TPtrC titleText = itemText.Mid(tabPos1 + 1);
        iGc->DrawText(titleText, textRect, baseline, CGraphicsContext::ELeft, 1);
    }
    else
    {
        // Text can still contain further icons
        TPtrC titleText = itemText.Mid(tabPos1 + 1, tabPos2 - tabPos1 - 1);
        iGc->DrawText(titleText, textRect, baseline, CGraphicsContext::ELeft, 1);

        font = CCoeEnv::Static()->NormalFont();
        iGc->UseFont(font);

        textRect.Move(0, aActualItemRect.Height() / 2);
        baseline = (textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2 + font->AscentInPixels();
        iGc->DrawText(itemText.Mid(tabPos2 + 1), textRect, baseline, CGraphicsContext::ELeft, 1);
    }
}

void CDoubleListBoxItemDrawer::DeleteIconArray()
{
    if (iIconArray)
    {
        iIconArray->ResetAndDestroy();
        delete iIconArray;
        iIconArray = 0;
    }
}

void CDoubleListBox::ConstructL(CCoeControl* aParent, TInt /*aFlags*/)
{
    CEikTextListBox::ConstructL(aParent);
}

TInt CDoubleListBox::CurrentItemIndex() const
{
    return CEikTextListBox::CurrentItemIndex();
}

TKeyResponse CDoubleListBox::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
    return CEikTextListBox::OfferKeyEventL(aKeyEvent, aType);
}

void CDoubleListBox::RefreshL()
{
    CEikTextListBox::HandleItemRemovalL();
    CEikTextListBox::HandleItemAdditionL();
    CEikTextListBox::SetCurrentItemIndex(0);
    CEikTextListBox::SetFocus(ETrue);
}

void CDoubleListBox::SetContainerWindowL(const CCoeControl& aContainer)
{
    CEikTextListBox::SetContainerWindowL(aContainer);
}

void CDoubleListBox::SetItemList(MDesCArray* aTextArray, CArrayPtr<CGulIcon>* aIconArray)
{
    Model()->SetItemTextArray(aTextArray);
    Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);

    static_cast<CDoubleListBoxItemDrawer*>(View()->ItemDrawer())->SetIconArray(aIconArray);

/*
    CColumnListBoxData* cd = ItemDrawer()->ColumnData();
    cd->SetIconArray(aIconArray);

    cd->SetGraphicsColumnL(0, ETrue);
    cd->SetColumnWidthPixelL(0, 20);
    cd->SetColumnAlignmentL(0, CGraphicsContext::ECenter);

    cd->SetColumnWidthPixelL(1, 120);
    cd->SetColumnAlignmentL(1, CGraphicsContext::ELeft);

    cd->SetColumnWidthPixelL(2, 50);
    cd->SetColumnAlignmentL(2, CGraphicsContext::ELeft);
*/
}

void CDoubleListBox::SetListBoxObserver(MEikListBoxObserver* aObserver)
{
    CEikTextListBox::SetListBoxObserver(aObserver);
}

void CDoubleListBox::SetMopParent(MObjectProvider* /*aParent*/)
{}

void CDoubleListBox::SetRect(const TRect& aRect)
{
    TInt rectHeight = aRect.Height();
#if   defined(__S80__)
    const TInt height(rectHeight / 3);      // 3 items per screen
#elif defined(__S90__)
    const TInt height(rectHeight / 5);
#elif defined(__UIQ__)
    const TInt height(rectHeight / 6);
#endif

    CEikTextListBox::SetItemHeightL(height);
    CEikTextListBox::SetRect(aRect);
}

void CDoubleListBox::SetScrollBarL()
{
    CEikTextListBox::CreateScrollBarFrameL();
}

void CDoubleListBox::ShowScrollBarL(TBool aShow)
{
    if (CEikTextListBox::ScrollBarFrame())
    {
        if (aShow)
            CEikTextListBox::ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
        else
            CEikTextListBox::ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff);

        CEikTextListBox::UpdateScrollBarsL();
    }
}


CEikListBox* CDoubleListBox::This()
{
    return this;
}

void CDoubleListBox::CreateItemDrawerL()
{
    iItemDrawer = new(ELeave) CDoubleListBoxItemDrawer(Model());
}

⌨️ 快捷键说明

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