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

📄 listcontainer.cpp

📁 《基于symbian手机开发与应用》一书的源代码
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CListContainer from ListContainer.h
*  Part of  : List
*  Created  : 2006-4-15 by LiuLiping
*  Implementation notes:
*     Initial content was generated by Series 60 AppWizard.
*  Version  :
*  Copyright: 
* ============================================================================
*/

// INCLUDE FILES
#include "ListContainer.h"
#include <list.rsg>
#include <list.mbg>

#include <barsread.h>		//TResourceReader
#include <stringloader.h>	//StringLoader
#include <e32base.h>		//CArrayPtr
#include <akniconarray.h>	//CAknIconArray 
#include <eikclbd.h>		//CColumnListBoxData
#include <aknnotedialog.h>	//CAknNoteDialog 
#include <eikmenub.h>		//CEikMenuBar


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

// ---------------------------------------------------------
// CListContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CListContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    
	CreateListBoxL();
	iListBox->SetListBoxObserver(this);
	SetupListIconsL();
	SetupScrollBarsL();

    SetRect(aRect);
    ActivateL();
    }

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

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

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

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

// ---------------------------------------------------------
// CListContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CListContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
	gc.Clear(aRect);
    }

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

void CListContainer::CreateListBoxL()
{
	iListBox = new (ELeave) CAknSingleGraphicStyleListBox;;
	iListBox->SetContainerWindowL(*this);					
	TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader,R_LIST);
	iListBox->ConstructFromResourceL(reader);	
	CleanupStack::PopAndDestroy();
}

void CListContainer::SetupListIconsL()
{
	HBufC* iconFileName;
	iconFileName=StringLoader::LoadLC(R_PICTURE_FILENAME);
	CArrayPtr<CGulIcon>* icons=new(ELeave) CAknIconArray(2);
	CleanupStack::PushL(icons);
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName,EMbmListList,EMbmListList_m));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName,EMbmListList,EMbmListList_m));
	CleanupStack::Pop(icons);
	CleanupStack::PopAndDestroy(iconFileName);
    iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
}

void CListContainer::SetupScrollBarsL()
{
	iListBox->CreateScrollBarFrameL(ETrue);
	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

}

TKeyResponse CListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	TBool selectKeyPressed=(aType==EEventKey)&&(aKeyEvent.iCode== EKeyOK);
    TBool ListBoxNotEmpty=(iListBox)&&(iListBox->Model()->NumberOfItems()>0);
	TInt currentList = iListBox->CurrentItemIndex();
    if(selectKeyPressed&&ListBoxNotEmpty)
	{

	    if(currentList == 0 )
		{
		  CAknNoteDialog* note=new(ELeave)CAknNoteDialog
		 (CAknNoteDialog::EConfirmationTone,CAknNoteDialog::EShortTimeout);	
          note->PrepareLC(R_SELFDIALOG);	
          note->SetTextPluralityL(ETrue);					
	      note->RunLD();
		}
	    else if(currentList == 1)
		{

	        CEikMenuBar* parentMenuBar=iEikonEnv->AppUiFactory()->MenuBar();
            parentMenuBar->SetMenuTitleResourceId(R_LIST_CONTEXTLIST_MENUBAR);
	        if(parentMenuBar)
			{
		         parentMenuBar->TryDisplayMenuBarL();
			}
            parentMenuBar->SetMenuTitleResourceId(R_LIST_MENUBAR);
	        
		}
		return EKeyWasConsumed;
	}
	else if (iListBox)
		return iListBox->OfferKeyEventL (aKeyEvent, aType);
	else
		return EKeyWasNotConsumed;
	}

MDesCArray * CListContainer::GetListDialogItemL()
{
	iListDialogItemArray =  new (ELeave) CDesCArrayFlat(3);
	_LIT (KListDialog1, "InfDlg");
	_LIT (KListDialog2, "WarningDlg");
	_LIT (KListDialog3, "TextDlg");
	TBuf <16> aString;
	for (TInt i = 1; i<= 3; i++)
		{
		if(i==1)
		{
			aString.Format(KListDialog1);
		    iListDialogItemArray->AppendL (aString);
		}
		if(i==2)
		{
			aString.Format(KListDialog2);
		    iListDialogItemArray->AppendL (aString);
		}
		if(i==3)
		{
			aString.Format(KListDialog3);
		    iListDialogItemArray->AppendL (aString);
		}
		}
    return iListDialogItemArray;
}
// End of File  

⌨️ 快捷键说明

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