newmemocontainer.cpp

来自「一个比较完整的有关移动开发的例子 vc++6.0下编译通过」· C++ 代码 · 共 245 行

CPP
245
字号
/*
* ============================================================================
*  Name     : CNewMemoContainer from CCoeControl, MCoeControlObserver
*  Part of  : NewMemo
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
#define MEM_FREE(p) if (NULL!=p){delete p; p = NULL;}
// INCLUDE FILES

#include "NewMemoContainer.h"
#include <FairyLand.rsg>
#include "FairyLand.hrh"
#include <eikenv.h>
#include <FairyLand.rsg>
#include <eiklabel.h>
#include <eikedwin.h> //for CEikEdwin
// #include <aknsdrawutils.h>
// #include <aknsbasicbackgroundcontrolcontext.h>


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

// C++ default constructor can NOT contain any code, that
// might leave.
//
CNewMemoContainer::CNewMemoContainer()
{
	iLabel1=NULL;
	iLabel2=NULL;
	iEdit1=NULL;
	iEdit2=NULL;
}

// EPOC default constructor can leave.
void CNewMemoContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
    
    		//Label
	iLabel1=new(ELeave) CEikLabel;
	iLabel1->SetContainerWindowL(*this);
	TBuf<20> buf1;
	CEikonEnv::Static()->ReadResource(buf1, R_QTN_MH_TITLE);
	iLabel1->SetTextL(buf1);
	iLabel1->SetExtent(TPoint(10,10), iLabel1->MinimumSize());
	//Labe2
	iLabel2=new(ELeave) CEikLabel;
	iLabel2->SetContainerWindowL(*this);
	TBuf<20> buf2;
	CEikonEnv::Static()->ReadResource(buf2, R_QTN_MH_CONTENT);
	iLabel2->SetTextL(buf2);
	iLabel2->SetExtent(TPoint(10,40), iLabel2->MinimumSize());
		//Edit1
	iEdit1 = new(ELeave) CEikEdwin;
	iEdit1->SetContainerWindowL(*this);
	iEdit1->ConstructL(EAknEditorFlagDefault, 10, 10, 1);
	iEdit1->SetExtent(TPoint(50,10), TSize(110,20));
	iEdit1->SetFocus(ETrue);

		//Edit2
	iEdit2 = new(ELeave) CEikEdwin;
	iEdit2->SetContainerWindowL(*this);
	iEdit2->ConstructL(EAknEditorFlagDefault, 10, 500, 1);
	iEdit2->SetExtent(TPoint(50,40), TSize(110,90));
//	iEdit2->SetTextL(&_L("Input Your Pass!"));
	iEdit2->SetFocus(EFalse);
    SetRect(aRect);


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

// Destructor
CNewMemoContainer::~CNewMemoContainer()
{
	MEM_FREE(iLabel1);
	MEM_FREE(iLabel2);
	MEM_FREE(iEdit1);
	MEM_FREE(iEdit2);
//	delete iBackGround;
}

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

void CNewMemoContainer::FocusTo(TInt aCommand)
{
}

// ---------------------------------------------------------
// CNewMemoContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CNewMemoContainer::SizeChanged()
{
}

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

// ---------------------------------------------------------
// CNewMemoContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CNewMemoContainer::ComponentControl(TInt aIndex) const
{
			switch(aIndex)
	{
	case 0:
		{
			return iLabel1;
			break;
		}
	case 1:
		{
			return iLabel2;
			break;
		}
	case 2:
		{
			return iEdit1;
			break;
		}
	case 3:
		{
			return iEdit2;
			break;
		}
	default:
		{
			return NULL;
			break;
		}
	};
}

// ---------------------------------------------------------
// CNewMemoContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CNewMemoContainer::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(KNewMemo,R_QTN_MH_NewMemo_CONTENT);
//	TBuf<20> buf;
//	CEikonEnv::Static()->ReadResource(buf, R_QTN_MH_NewMemo_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);
}

// ---------------------------------------------------------
// CNewMemoContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CNewMemoContainer::OfferKeyEventL(
											 const TKeyEvent& aKeyEvent, TEventCode aType)
{
				if (iEdit1)
	{
		if (iEdit1->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
			{
				iEdit1->SetFocus(EFalse);
				iEdit2->SetFocus(ETrue);
				return EKeyWasConsumed;
			}
			return iEdit1->OfferKeyEventL(aKeyEvent, aType);
		}
	}
			if (iEdit2)
	{
		if (iEdit2->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow)|| (aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				iEdit2->SetFocus(EFalse);
				iEdit1->SetFocus(ETrue);
				return EKeyWasConsumed;
			}
			return iEdit2->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	return EKeyWasNotConsumed;
}

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

// ---------------------------------------------------------
// CNewMemoContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CNewMemoContainer::HandleControlEventL(
										  CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
void CNewMemoContainer::GetTitle(TDes &aTitle)
{
	iEdit1->GetText(aTitle);
}
void CNewMemoContainer::GetContent(TDes &aContent)
{
	iEdit2->GetText(aContent);
}

⌨️ 快捷键说明

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