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

📄 messagecontainer.cpp

📁 symbian 3nd 实现短信息收发
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CMessageContainer from CCoeControl, MCoeControlObserver
*  Part of  : Message
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <eiklabel.h>  // for example label control
#include <barsread.h>  // for resource reader
#include <eikedwin.h>  // for CEikEdwin
#include <eikgted.h>   // for CEikGlobalTextEditor
#include <eikclbd.h>   // for CColumnListBoxData
#include <FrMes.rsg>
#include "FrMes.hrh"
#include "MessageContainer.h"
#include <aknlists.h>
#include <akniconarray.h>
#include "FrMesAppUi.h"


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

// C++ default constructor can NOT contain any code, that
// might leave.
//
CMessageContainer::CMessageContainer()
{
	m_pListBox	= NULL;
	m_pListBoxArray = NULL;
}

// EPOC default constructor can leave.
void CMessageContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
//listbox
	m_pListBox = new( ELeave ) CAknSingleLargeStyleListBox();
	CleanupStack::PushL(m_pListBox);
	m_pListBox->ConstructL(this, EAknListBoxSelectionList);	
	m_pListBox->SetContainerWindowL( *this );
	m_pListBox->SetRect(aRect);
    m_pListBox->CreateScrollBarFrameL( ETrue );
    m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	
	//Add Item List
	m_pListBoxArray = new (ELeave) CDesCArrayFlat(4);
	CleanupStack::PushL(m_pListBoxArray);
	CTextListBoxModel* model = m_pListBox->Model();
	model->SetItemTextArray( m_pListBoxArray );
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	CleanupStack::Pop(2);
	m_pListBox->SetFocus( ETrue );
	
	LoadGraphicsL();
	AddDataL();	

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CMessageContainer::~CMessageContainer()
{
	if(m_pListBox)
	{
		delete m_pListBox;
		m_pListBox = NULL;
	}
	if(m_pListBoxArray)
	{
		delete m_pListBoxArray;
		m_pListBoxArray = NULL;
	} 
}

// ---------------------------------------------------------
// CMessageContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//

void CMessageContainer::FocusTo(TInt aCommand)
    {
 
    }

// ---------------------------------------------------------
// CMessageContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMessageContainer::SizeChanged()
{
	if (m_pListBox)
	{
		m_pListBox->SetRect(Rect());
	}
}

// ---------------------------------------------------------
// CMessageContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CMessageContainer::CountComponentControls() const
{
    return 1; // return nbr of controls inside this container
}

// ---------------------------------------------------------
// CMessageContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CMessageContainer::ComponentControl(TInt aIndex) const
{
	switch(aIndex)
	{
	case 0:
		return m_pListBox;
	default:
		return NULL;
	}
}

// ---------------------------------------------------------
// CMessageContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMessageContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbRed);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
    }

// ---------------------------------------------------------
// CMessageContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CMessageContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType)
{
    if (m_pListBox)
		return m_pListBox->OfferKeyEventL (aKeyEvent, aType);
	else
		return EKeyWasNotConsumed;
	
}


// ---------------------------------------------------------
// CMessageContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMessageContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    }

TInt CMessageContainer::GetCurrentItemIndex()
{
	return m_pListBox->CurrentItemIndex();
}

void CMessageContainer::LoadGraphicsL()
{
	CFrMesAppUi* pApp = (CFrMesAppUi*)CEikonEnv::Static()->AppUi();
    CArrayPtr< CGulIcon >* icons = new(ELeave) CAknIconArray(5);
    CleanupStack::PushL( icons );
    // Create icon bitmap and mask.
	icons->AppendL(pApp->LoadGraphicsL(4));
	icons->AppendL(pApp->LoadGraphicsL(5));
	icons->AppendL(pApp->LoadGraphicsL(6));
	icons->AppendL(pApp->LoadGraphicsL(7));
	icons->AppendL(pApp->LoadGraphicsL(8));
    // Set icon array.
	m_pListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
    CleanupStack::Pop(); // icons array
}


void CMessageContainer::AddDataL()
{
	MDesCArray* array = m_pListBox->Model()->ItemTextArray();
    CDesCArray* cArray = ( CDesCArray* )array;
	
	TBuf<32> sBuf;
	//CREATEMES
	sBuf.Copy(_L("0\t"));
	TBuf<32> item0;
	iCoeEnv->ReadResource(item0, R_FRMES_MESSAGE_CREATEMES);
	sBuf.Append(item0);
	cArray->AppendL(sBuf);
	//RECEIVEMES
	sBuf.Copy(_L("1\t"));
	TBuf<32> item1;
	iCoeEnv->ReadResource(item1, R_FRMES_MESSAGE_RECEIVEMES);
	sBuf.Append(item1);
	cArray->AppendL(sBuf);
	//NOTEBOOK
	sBuf.Copy(_L("2\t"));
	TBuf<32> item2;
	iCoeEnv->ReadResource(item2, R_FRMES_MESSAGE_NOTEBOOK);
	sBuf.Append(item2);
	cArray->AppendL(sBuf);
	//SENDMES
	sBuf.Copy(_L("3\t"));
	TBuf<32> item3;
	iCoeEnv->ReadResource(item3, R_FRMES_MESSAGE_SENDMES);
	sBuf.Append(item3);
	cArray->AppendL(sBuf);
	//SENDINGMES
	sBuf.Copy(_L("4\t"));
	TBuf<32> item4;
	iCoeEnv->ReadResource(item4, R_FRMES_MESSAGE_SENDINGMES);
	sBuf.Append(item4);
	cArray->AppendL(sBuf);
	
	
	// const CFont* fontText = ApacPlain12();
    m_pListBox->HandleItemAdditionL();
}


// End of File  

⌨️ 快捷键说明

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