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

📄 mulslistcontainer.cpp

📁 《基于Symbian OS的手机开发与应用实践》这本书的配套源码。
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CMulsListContainer from MulsListContainer.h
*  Part of  : MulsList
*  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 <MulsList.mbg>     // for EMbmMulsListStar
#include <MulsList.rsg>

#include "MulsListContainer.h"

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

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

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

    // Load items
    CTextListBoxModel* model = iListBox->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    _LIT(KItemFormat, "1\tRecord%d\t%d\t2"); // "1\tLabel1\tLabel2\tIcon1"
    TBuf<32> record;
    TInt i = 1;
    for (i = 1; i<9 ; i++)
        {
        record.Format(KItemFormat(), i, 100-i);
        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, EMbmMulslistCheck, EMbmMulslistCheckmask));
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmMulslistUncheck, EMbmMulslistUncheckmask));
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmMulslistStar, EMbmMulslistStarmask));
    CleanupStack::Pop(icons);
    iListBox->ItemDrawer()->FormattedCellData()->SetIconArray(icons);

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

    SetRect(aRect);
    ActivateL();
    }

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

// New methods

TInt CMulsListContainer::SelectionCount()
    {
    return iListBox->SelectionIndexes()->Count();
    }

void CMulsListContainer::AddRecordL(const TDesC& aDesC)
    {
    CTextListBoxModel* model = iListBox->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    _LIT(KItemFormat, "1\t%S\t?\t2");
    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 CMulsListContainer::DeleteRecordL()
    {
    CTextListBoxModel* model = iListBox->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    TInt index = iListBox->CurrentItemIndex();
    TBool deleted = iListBox->View()->ItemIsSelected(index);
    const CListBoxView::CSelectionIndexArray* selection = iListBox->SelectionIndexes();
    TInt i = selection->Count()-1;
    for(i;i>=0;i--)
        {
        if(index>=(*selection)[i])
            {
            index--;
            }
        array->Delete((*selection)[i]);
        }
    if(index<0)
        {
        index=0;
        }
    AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iListBox, index, deleted);
    }


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

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

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

// ---------------------------------------------------------
// CMulsListContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CMulsListContainer::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 );
    }

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

// End of File  

⌨️ 快捷键说明

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