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

📄 allpopuplistscontainer.cpp

📁 各种Symbian ListBox的真实案例: 已经齐了
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CAllPopuplistsContainer from AllPopuplistsContainer.h
*  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 <barsread.h>       // for TResourceReader
#include <eikfrlbd.h>       // for CFormattedCellListBoxData
#include <eikfrlb.h>        // for CEikFormattedCellListBox
#include <eikapp.h>
#include <eiklabel.h>       // for example label control
#include <aknlists.h>
#include <akniconarray.h>
#include <aknpopup.h>       // for CAknPopupList
#include <aknpopuplayout.h> // for AknPopupLayouts
#include <AllPopuplists.rsg>
#include <AllPopuplists.mbg>

#include "AllPopuplistsContainer.h"



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

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

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

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

    SetRect(aRect);
    ActivateL();
    }

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

// New functions
void CAllPopuplistsContainer::ShowPopupListL(TInt aResourceId, TBool aWithTitle)
    {
    // Create listbox
    CEikFormattedCellListBox* listbox=NULL;
    AknPopupLayouts::TAknPopupLayouts layout = AknPopupLayouts::EMenuWindow;
    switch(aResourceId)
        {
        case R_ALLPOPUPLISTS_SINGLEGRAPHICPOPUP_LISTBOX:
            {
            listbox = new(ELeave) CAknSingleGraphicPopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuGraphicWindow;
            break;
            }
        case R_ALLPOPUPLISTS_SINGLEGRAPHICPOPUPBT_LISTBOX:
            {
            listbox = new(ELeave) CAknSingleGraphicBtPopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuGraphicWindow;
            break;
            }
        case R_ALLPOPUPLISTS_SINGLEHEADINGPOPUP_LISTBOX:
            {
            listbox = new(ELeave) CAknSingleHeadingPopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuGraphicHeadingWindow;
            break;
            }
        case R_ALLPOPUPLISTS_SINGLEGRAPHICHEADINGPOPUP_LISTBOX:
            {
            listbox = new(ELeave) CAknSingleGraphicHeadingPopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuGraphicHeadingWindow;
            break;
            }
        case R_ALLPOPUPLISTS_DOUBLEPOPUP_LISTBOX:
            {
            listbox = new(ELeave) CAknDoublePopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuDoubleWindow;
            break;
            }
        case R_ALLPOPUPLISTS_DOUBLELARGEGRAPHICPOPUP_LISTBOX:
            {
            listbox = new(ELeave) CAknDoubleLargeGraphicPopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuDoubleLargeGraphicWindow;
            break;
            }
        case R_ALLPOPUPLISTS_DOUBLE2POPUP_LISTBOX:
            {
            listbox = new(ELeave) CAknDouble2PopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuDoubleWindow;
            break;
            }
        case R_ALLPOPUPLISTS_SINGLEPOPUP_LISTBOX:
        default:
            {
            listbox = new(ELeave) CAknSinglePopupMenuStyleListBox;
            layout = AknPopupLayouts::EMenuWindow;
            break;
            }
        }
    CleanupStack::PushL(listbox);

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

    // Construct the listbox
    listbox->SetContainerWindowL(*popup);
    TResourceReader reader;
    CEikonEnv::Static()->CreateResourceReaderLC( reader, aResourceId );
    listbox->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();

    // Creates scrollbar.
    listbox->CreateScrollBarFrameL( ETrue );
    listbox->ScrollBarFrame()->SetScrollBarVisibilityL(
        CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );

    // 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
    listbox->ItemDrawer()->ColumnData()->SetIconArray(icons);


    if(aWithTitle)
        {
        // Set title
        HBufC* title = CCoeEnv::Static()->AllocReadResourceLC(R_QTN_ALLPOPUPLISTS_POPUPTITLE);
        popup->SetTitleL(*title);
        CleanupStack::PopAndDestroy(); // title
        }

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

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

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

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

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

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

// ---------------------------------------------------------
// CAllPopuplistsContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CAllPopuplistsContainer::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 + -