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

📄 allpopuplistscontainer2.cpp

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

// INCLUDE FILES
#include <eikfrlbd.h>       // for CFormattedCellListBoxData
#include <eikfrlb.h>        // for CEikFormattedCellListBox
#include <eikapp.h>
#include <eiklabel.h>       // for example label control
#include <akngrid.h>
#include <akniconarray.h>
#include <aknpopup.h>       // for CAknPopupList
#include <aknpopuplayout.h> // for AknPopupLayouts
#include <AllPopuplists.rsg>
#include <AllPopuplists.mbg>

#include "AllPopuplistsContainer2.h"
#include "MyGrid.h"



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

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

    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    iLabel->SetTextL( _L("Example View 2") );

    iToDoLabel = new (ELeave) CEikLabel;
    iToDoLabel->SetContainerWindowL( *this );
    iToDoLabel->SetTextL( _L("Add Your controls\n here") );

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CAllPopuplistsContainer2::~CAllPopuplistsContainer2()
    {
    delete iLabel;
    delete iToDoLabel;
    }

void CAllPopuplistsContainer2::ShowPopupGridL()
    {
    // Create grid
    CAknGrid* grid=new(ELeave) CMyGrid;
    CleanupStack::PushL(grid);

    // Create popup list
    CAknPopupList* popup = CAknPopupList::NewL(grid, R_AVKON_SOFTKEYS_SELECT_BACK);
    CleanupStack::PushL(popup);

    // Construct the listbox
    grid->SetContainerWindowL(*popup);
    grid->ConstructL(popup, CEikListBox::ELeftDownInViewRect);

    // Add items
    CTextListBoxModel* model = grid->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    _LIT(KItemFormat, "0\tItem%d%d\t1");
    TBuf<32> item;
    TInt i=0;
    TInt j=0;
    for(i=0; i<3; i++)
        {
        for(j=0; j<3; j++)
            {
            item.Format(KItemFormat(), i, j);
            array->AppendL(item);
            }
        }

    // Create an array of icons, reading them from the file
    CEikonEnv* eikonEnv = CEikonEnv::Static();
    TFileName mbmFile = eikonEnv->EikAppUi()->Application()->BitmapStoreName();
    CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(4);
    CleanupStack::PushL(icons);
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmAllpopuplistsG1, EMbmAllpopuplistsGm1));
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmAllpopuplistsG2, EMbmAllpopuplistsGm2));
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmAllpopuplistsG3, EMbmAllpopuplistsGm3));
    CleanupStack::Pop(icons);
     // Transfer ownership
    grid->ItemDrawer()->ColumnData()->SetIconArray(icons);

    // Show the popup list
    popup->ExecuteLD();

    CleanupStack::Pop(); // popup
    CleanupStack::PopAndDestroy(); // grid
    }

// ---------------------------------------------------------
// CAllPopuplistsContainer2::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CAllPopuplistsContainer2::SizeChanged()
    {
    // TODO: Add here control resize code etc.
    iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
    iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
    }

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

// ---------------------------------------------------------
// CAllPopuplistsContainer2::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CAllPopuplistsContainer2::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iLabel;
        case 1:
            return iToDoLabel;
        default:
            return NULL;
        }
    }

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

// ---------------------------------------------------------
// CAllPopuplistsContainer2::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CAllPopuplistsContainer2::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    // TODO: Add your control event handler code here
    }


// End of File  

⌨️ 快捷键说明

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