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

📄 smslistcontainer.cpp

📁 一个比较完整的有关移动开发的例子 vc++6.0下编译通过
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CSMSListContainer from CCoeControl, MCoeControlObserver
*  Part of  : SMSDraft
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <FairyLand.rsg>
#include "FairyLand.hrh"
#include <FairyLand.mbg>
#include "FairyLandAppUi.h"
#include "SMSListContainer.h"

#include <aknlists.h>
#include <akniconarray.h>
#include <aknquerydialog.h>
#include <eikapp.h>
#include <stringloader.h>
#include <gulicon.h>


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

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

// EPOC default constructor can leave.
void CSMSListContainer::ConstructL(const TRect& aRect)
{
	CreateWindowL();
	
	// Create the list
	CreateListL();	
	
	CreateItemsL();
	// Observe the list
	/*	m_pListBox->SetContainerWindowL(*this);*/
	
	// Set the icons in the list's drawer
	SetupListIconsL();
	
	// Set up scroll bars
	SetupScrollBarsL();
	
	SetRect(aRect);
	ActivateL();
}

// Destructor
CSMSListContainer::~CSMSListContainer()
{
	if (m_pListBox)
	{
		delete m_pListBox;
		m_pListBox = NULL;
	}
	
	if (m_pListBoxItems)
	{
		delete m_pListBoxItems;
		m_pListBoxItems = NULL;
	}
}

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

void CSMSListContainer::FocusTo(TInt /*aCommand*/)
{
	
}

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

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

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

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

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


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


TInt CSMSListContainer::MessageBoxByYesNO(const TDesC& aMes)
{
	CAknQueryDialog* pDlog = new(ELeave)CAknQueryDialog;
	pDlog->PrepareLC(R_SMSIB_QUERY);//显示messagebox
	pDlog->SetPromptL(aMes);
	return pDlog->RunLD();
}


void CSMSListContainer::CreateListL()
{
	m_pListBox = new(ELeave) CAknDoubleGraphicStyleListBox;
	m_pListBox->ConstructL(this,EAknListBoxSelectionList);
	m_pListBox->SetContainerWindowL(*this);
	m_pListBox->SetFocus(ETrue);
}

void CSMSListContainer::SetupListIconsL()
{
	// Get the name of the file containing the icons	
	//set path of *.mbm
	TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
	pathMbm.Copy(_L("z:\\system\\apps\\fairyland\\fairyland.mbm"));
#else
	CFairyLandAppUi* pApp = (CFairyLandAppUi*)CEikonEnv::Static()->AppUi();
	pApp->GetAppPath(pathMbm);
	//GetApplicationPath(pathMbm);
	pathMbm.Append(_L("fairyland.mbm"));
#endif

	// Create an array of icons, reading them from the file
	CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(2);
	CleanupStack::PushL(icons);
//	icons->AppendL(iEikonEnv->CreateIconL(pathMbm, EMbmMyhelloSms_recvbox, EMbmMyhelloSms_recvbox_mask));
	icons->AppendL(iEikonEnv->CreateIconL(pathMbm, EMbmFairylandSms_icon, EMbmFairylandSms_icon_mask));
	CleanupStack::Pop(icons);
	
	m_pListBox->ItemDrawer()->FormattedCellData()->SetIconArray(icons); // passing ownership of icons
	
}

void CSMSListContainer::SetupScrollBarsL()
{
	m_pListBox->CreateScrollBarFrameL(ETrue);
	m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
}

void CSMSListContainer::GetApplicationPath(TDes& aszPath)
{
	CFairyLandAppUi* pAppui = (CFairyLandAppUi*)(iEikonEnv->Static()->AppUi()); 
	TFullName szFullName;
	szFullName = pAppui->Application()->AppFullName();
	TParsePtr pare(szFullName);
	aszPath.Copy(pare.DriveAndPath());
} 

void CSMSListContainer::CreateItemsL()
{
	m_pListBoxItems = new(ELeave) CDesCArrayFlat(10);
	CTextListBoxModel* model = m_pListBox->Model();
	model->SetItemTextArray(m_pListBoxItems);
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
}

void CSMSListContainer::AddSingleItemL(TInt anIndex, TDesC& aszName, TDesC& aszContent)
{
	TBuf<KMaxPath> szTemp;
	szTemp.AppendNum(anIndex);
	szTemp.Append(_L("\t"));
	szTemp.Append(aszName);
	szTemp.Append(_L("\t"));
	szTemp.Append(aszContent);	
	m_pListBoxItems->AppendL(szTemp);
	m_pListBox->HandleItemAdditionL(/*m_pListItems*/);
	m_pListBox->SetCurrentItemIndexAndDraw(0);
}


void CSMSListContainer::SetEmptyListBox()
{
	if (m_pListBoxItems)
	{
		m_pListBoxItems->Reset();
	}
}

TInt CSMSListContainer::GetCurrentIndex()
{
	return m_pListBox->CurrentItemIndex();
}

// End of File  

⌨️ 快捷键说明

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