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

📄 selelistcontainer.cpp

📁 《基于Symbian OS的手机开发与应用实践》这本书的配套源码。
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CSeleListContainer from SeleListContainer.h
*  Part of  : SeleList
*  Created  : 16.03.2006 by ToBeReplacedByAuthor
*  Implementation notes:
*     Initial content was generated by Series 60 Application Wizard.
*  Version  :
*  Copyright: ToBeReplacedByCopyright
* ============================================================================
*/

// INCLUDE FILES
#include <eikapp.h>         // for CEikApplication
#include <eikfrlbd.h>       // for CFormattedCellListBoxData
#include <eikfrlb.h>        // for CEikFormattedCellListBox
#include <akniconarray.h>   // for CAknIconArray
#include <aknlists.h>       // for CAknDoubleStyleListBox
#include <SeleList.mbg>     // for EMbmSeleListStar
#include <SeleList.rsg>

#include "SeleListContainer.h"

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CSeleListContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSeleListContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    // Create listbox
    iListBox = new(ELeave) CAknDoubleGraphicStyleListBox;
    iListBox->SetContainerWindowL( *this );
    iListBox->ConstructL(this, EAknListBoxSelectionList);
    iListBox->SetListBoxObserver(this);

    // Load items
    CTextListBoxModel* model = iListBox->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    _LIT(KItemFormat, "%d\tRecord%d\t%d"); // "Icon1\tLabel1\tLabel2"
    TBuf<32> record;
    TInt i = 1;
    for (i = 1; i<9 ; i++)
        {
        record.Format(KItemFormat(), 0, i, 100-i, 0, 0);
        array->AppendL(record);
        }

    // Load icons
    CEikonEnv* eikonEnv = CEikonEnv::Static();
    TFileName mbmFile = eikonEnv->EikAppUi()->Application()->BitmapStoreName();
    CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(3);
    CleanupStack::PushL(icons);
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmSelelistStar, EMbmSelelistStarmask));
    CleanupStack::Pop(icons);
    iListBox->ItemDrawer()->FormattedCellData()->SetIconArray(icons);

    // Create scrollbar
    iListBox->CreateScrollBarFrameL(ETrue);
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
        CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CSeleListContainer::~CSeleListContainer()
    {
    delete iListBox;
    }

// New methods

TInt CSeleListContainer::RecordCount()
    {
    return iListBox->Model()->NumberOfItems();
    }

void CSeleListContainer::AddRecordL(const TDesC& aDesC)
    {
    CTextListBoxModel* model = iListBox->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    _LIT(KItemFormat, "0\t%S\t?");
    TBuf<32> record;
    record.Format(KItemFormat(), &aDesC);
    TInt index = iListBox->CurrentItemIndex();
    if(index<0)
        array->AppendL(record);
    else
        array->InsertL(index, record);
    iListBox->HandleItemAdditionL();
    }

void CSeleListContainer::DeleteRecordL()
    {
    CTextListBoxModel* model = iListBox->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    TInt index = iListBox->CurrentItemIndex();
    if(index>=0)
        {
        array->Delete(index);
        AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iListBox, index, ETrue);
        }
    }


// ---------------------------------------------------------
// CSeleListContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSeleListContainer::SizeChanged()
    {
    // TODO: Add here control resize code etc.
    iListBox->SetRect(Rect());
    }

// ---------------------------------------------------------
// CSeleListContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSeleListContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CSeleListContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSeleListContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iListBox;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// CSeleListContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSeleListContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

// ---------------------------------------------------------
// CSeleListContainer::OfferKeyEventL()
// @param aKeyEvent Event to handled.
// @param aType Type of the key event. 
// @return Response code (EKeyWasConsumed, EKeyWasNotConsumed). 
// ---------------------------------------------------------
//
TKeyResponse CSeleListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    return iListBox->OfferKeyEventL(aKeyEvent, aType);
    }

// ---------------------------------------------------------
// CSeleListContainer::HandleListBoxEventL(
//     CEikListBox* aListBox, TListBoxEvent aListBoxEvent)
// ---------------------------------------------------------
//
void CSeleListContainer::HandleListBoxEventL(CEikListBox*/*aListBox*/, TListBoxEvent aListBoxEvent)
    {
    if((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
       (aListBoxEvent == MEikListBoxObserver::EEventItemClicked)) // for emulator
        {
        CEikonEnv::Static()->InfoWinL(R_QTN_APP_NODETAIL);
        }
    }

// End of File  

⌨️ 快捷键说明

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