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

📄 memocontainer.cpp

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

// INCLUDE FILES

#define MEM_FREE(p) if(NULL != p){delete p; p = NULL;}

#include <FairyLand.rsg>
#include "FairyLand.hrh"
#include "MemoContainer.h"
#include <eikenv.h>
#include <FairyLand.rsg>
#include <aknlists.h>//for CEikColumnListBox;
// #include <aknsdrawutils.h>
// #include <aknsbasicbackgroundcontrolcontext.h>


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

// C++ default constructor can NOT contain any code, that
// might leave.
//
CMemoContainer::CMemoContainer()
{
 	iSingleListBox=NULL;
 	iListBoxArray=NULL;
}

// EPOC default constructor can leave.
void CMemoContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
	

	//Single ListBox
	iSingleListBox = new( ELeave ) CAknSingleNumberStyleListBox();
//	iSingleListBox = new( ELeave ) CAknDoubleNumberStyleListBox();
	CleanupStack::PushL(iSingleListBox);
	iSingleListBox->ConstructL(this, EAknListBoxMarkableList | EAknListBoxMultiselectionList);	
	iSingleListBox->SetContainerWindowL(*this);
	iSingleListBox->SetRect(aRect);
    iSingleListBox->CreateScrollBarFrameL( ETrue );
    iSingleListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	
	// construct listbox item array
//	iListBoxArray = new (ELeave) CArrayVarFlat<CDataManagemnet>(10);
	iListBoxArray = new (ELeave) CDesCArrayFlat(10);
	CleanupStack::PushL(iListBoxArray);
	
	CTextListBoxModel* model = iSingleListBox->Model();
	// set items and ownership

	model->SetItemTextArray( iListBoxArray );
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	CleanupStack::Pop(2);	// !!! (2);
	
	iSingleListBox->ActivateL();
	// 	m_pListBox->MakeVisible(ETrue);
	iSingleListBox->SetFocus( ETrue );
	//	m_pListBox->DrawNow();	
	//End Single ListBox
    SetRect(aRect);


//	iBackGround=CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgAreaMemo,Rect(),EFalse);
    ActivateL();
}

// Destructor
CMemoContainer::~CMemoContainer()
{
	MEM_FREE(iSingleListBox);
	MEM_FREE(iListBoxArray);
//	delete iBackGround;
}

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

void CMemoContainer::FocusTo(TInt aCommand)
{
}

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

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

// ---------------------------------------------------------
// CMemoContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CMemoContainer::ComponentControl(TInt aIndex) const
{
	return iSingleListBox;
}

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

//	const CFont* fon=CEikonEnv::Static()->TitleFont();	
//	gc.UseFont(fon);
//	_LIT(KMemo,R_QTN_MH_Memo_CONTENT);
//	TBuf<20> buf;
//	CEikonEnv::Static()->ReadResource(buf, R_QTN_MH_Memo_CONTENT);

//	TPoint point(aRect.Width()/2-50,aRect.Height()/2);
//	gc.DrawText(buf,point);
//	gc.DiscardFont();

// 	MAknsSkinInstance* skin=AknsUtils::SkinInstance();
// 	MAknsControlContext* cc=AknsDrawUtils::ControlContext(this);
// 	AknsDrawUtils::Background(skin,cc,this,gc,aRect);
}

// ---------------------------------------------------------
// CMemoContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CMemoContainer::OfferKeyEventL(
											 const TKeyEvent& aKeyEvent, TEventCode aType)
{
	if(NULL != iSingleListBox)
	{
		if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
		{
			return iSingleListBox->OfferKeyEventL(aKeyEvent, aType);
		}
		else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
		{
			return iSingleListBox->OfferKeyEventL(aKeyEvent, aType);
		}
		return EKeyWasConsumed;
	}
	return EKeyWasNotConsumed;
}

// TTypeUid::Ptr CMemoContainer::MopSupplyObject(TTypeUid aId)
// {
// 	if (aId.iUid==MAknsControlContext::ETypeId && iBackGround)
// 	{
// 		return MAknsControlContext::SupplyMopObject(aId,iBackGround);
// 	}
// 	return CCoeControl::MopSupplyObject(aId);
// }

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


void CMemoContainer::AddInfoToList(TBuf<32>& buf)
{
/************************************************************************/
/* single                                                                     */
/************************************************************************/

	
	iListBoxArray->AppendL(buf);
	
	// update listbox
	iSingleListBox->HandleItemAdditionL();

}

TInt CMemoContainer::GetIndex()////////////////////////////////////////////////
{
	return iSingleListBox->CurrentItemIndex();
}

// End of File  

⌨️ 快捷键说明

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