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

📄 worldcontainer.cpp

📁 symbian电话簿引擎的经典例子
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CWorldContainer from CCoeControl, MCoeControlObserver
*  Part of  : World
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <LDN02.rsg>
#include "LDN02.hrh"
#include "WorldContainer.h"
#include <eikenv.h>
#include "common.h"
#include <eiklabel.h>	//for CEikLabel
#include <eikedwin.h> //for CEikEdwin
#include  <barsread.h>
#include <aknviewappui.h>
#include "HelloView.h"

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

// C++ default constructor can NOT contain any code, that
// might leave.
//
CWorldContainer::CWorldContainer()
    {
	m_pWorldEditSurName = NULL;
	m_pWorldEditName	= NULL;
	m_pWorldEditNumber  = NULL;
	m_pWorldLabelSurName= NULL;
	m_pWorldLabelName	= NULL;
	m_pWorldLabelNumber = NULL;
	mFlag = 0;
	}
//---------------------------------------------------------
//
// 测试加函数  SetData
//
//--------------------------------------------------------
void CWorldContainer::SetData(TDesC& aSurName, TDesC& aName, TDesC& aNum, TInt aFlag)
{
	mFlag = 0;
	m_SurName.Copy(aSurName);
	m_Name.Copy(aName);
	m_Number.Copy(aNum);
	mFlag = aFlag;
}

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

	//m_pHelloView = CHelloView::NewL();
	
	//label surname
	m_pWorldLabelSurName = new(ELeave) CEikLabel;
	m_pWorldLabelSurName->SetContainerWindowL(*this);
	TBuf<32> sTmpTitle;
	CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_LD_WORLD_LABEL_SURNAME);
	m_pWorldLabelSurName->SetTextL(sTmpTitle);
	m_pWorldLabelSurName->SetExtent(TPoint(30,25), m_pWorldLabelSurName->MinimumSize());
    
	//edit surname
    m_pWorldEditSurName = new(ELeave) CEikEdwin;
	m_pWorldEditSurName->SetContainerWindowL(*this);
	m_pWorldEditSurName->ConstructL(EAknEditorFlagDefault, 10, 6, 1);
	m_pWorldEditSurName->SetExtent(TPoint(60,20), TSize(100,20));
	if (mFlag == 3 || mFlag == 2)
	{
	m_pWorldEditSurName->SetTextL(&m_SurName);
	}
	//当为查看时不设置焦点
	if (mFlag != 2)
	{
	m_pWorldEditSurName->SetFocus(ETrue);
	}
	
   	
	//label name
	m_pWorldLabelName = new(ELeave) CEikLabel;
	m_pWorldLabelName->SetContainerWindowL(*this);
	CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_LD_WORLD_LABEL_NAME);
	m_pWorldLabelName->SetTextL(sTmpTitle);
	m_pWorldLabelName->SetExtent(TPoint(30,55), m_pWorldLabelName->MinimumSize());

	//edit name
	m_pWorldEditName = new(ELeave) CEikEdwin;
	m_pWorldEditName->SetContainerWindowL(*this);
	m_pWorldEditName->ConstructL(EAknEditorFlagDefault, 10, 6, 1);
	m_pWorldEditName->SetExtent(TPoint(60,50), TSize(100,20));
	if (mFlag == 3 || mFlag == 2)
	{
	m_pWorldEditName->SetTextL(&m_Name);
	}

	//label number
	m_pWorldLabelNumber = new(ELeave) CEikLabel;
	m_pWorldLabelNumber->SetContainerWindowL(*this);
	CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_LD_WORLD_LABEL_NUMBER);
	m_pWorldLabelNumber->SetTextL(sTmpTitle);
	m_pWorldLabelNumber->SetExtent(TPoint(30,85), m_pWorldLabelNumber->MinimumSize());

	//edit number
	m_pWorldEditNumber = new(ELeave) CEikEdwin;
	m_pWorldEditNumber->SetContainerWindowL(*this);
	m_pWorldEditNumber->ConstructL(EAknEditorFlagDefault, 10, 11, 1);
	m_pWorldEditNumber->SetAknEditorCurrentInputMode(EAknEditorNumericInputMode);//only Input number.
	m_pWorldEditNumber->SetExtent(TPoint(60,80), TSize(100,20));
	if (mFlag == 3 || mFlag == 2)
	{
	m_pWorldEditNumber->SetTextL(&m_Number);
	}

	
    SetRect(aRect);
    ActivateL();
    }

// Destructor
CWorldContainer::~CWorldContainer()
    {
	MEM_FREE(m_pWorldLabelSurName);
	MEM_FREE(m_pWorldLabelName);
	MEM_FREE(m_pWorldLabelNumber);
	MEM_FREE(m_pWorldEditSurName);
	MEM_FREE(m_pWorldEditName);
	MEM_FREE(m_pWorldEditNumber);
	mFlag = 0;
    }

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

void CWorldContainer::FocusTo(TInt aCommand)
    {
    }

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



//-----------------------------------------------------------
//
//-----------------------------------------------------------
void CWorldContainer::SizeChanged()
    {
    }

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

// ---------------------------------------------------------
// CWorldContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CWorldContainer::ComponentControl(TInt aIndex) const
    {
		switch (aIndex)
	{
	case 0:
		{
			return m_pWorldLabelSurName;
			break;
		}
	case 1:
		{
			return m_pWorldLabelName;
			break;
		}
	case 2:
		{
			return m_pWorldLabelNumber;
			break;
		}
	case 3:
		{
			return m_pWorldEditSurName;
			break;
		}
	case 4:
		{
			return m_pWorldEditName;
			break;
		}
	case 5:
		{
            return m_pWorldEditNumber;
			break;
		}

	default:
		{
			return NULL;
			break;
		}
	}	

    }

// ---------------------------------------------------------
// CWorldContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CWorldContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbBlue);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
/*
	const CFont* font = CEikonEnv::Static()->TitleFont();
	gc.UseFont(font);
	gc.Clear();
	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	gc.SetPenColor(KRgbWhite);
	_LIT(Str,"Thank you!");
	TBuf<10> buf(Str);
	
	gc.DrawText(buf,TPoint(20,60));
	gc.DiscardFont();*/
    }

// ---------------------------------------------------------
// CWorldContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CWorldContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType)
    {
	//当为查看时不设置按键响应
	if (mFlag ==2)
	{
		return EKeyWasConsumed;
	}
    if (m_pWorldEditSurName)
	{
		if (m_pWorldEditSurName->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
			{
				m_pWorldEditSurName->SetFocus(EFalse);
				m_pWorldEditNumber->SetFocus(EFalse);
				m_pWorldEditName->SetFocus(ETrue);
				m_pWorldEditName->SetCursorPosL(1,ETrue);
				return EKeyWasConsumed;
			}
			return m_pWorldEditSurName->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	
	
	if (m_pWorldEditName)
	{
		if (m_pWorldEditName->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				m_pWorldEditSurName->SetFocus(ETrue);
				m_pWorldEditSurName->SetCursorPosL(1,ETrue);
				m_pWorldEditName->SetFocus(EFalse);
				m_pWorldEditNumber->SetFocus(EFalse);
				return EKeyWasConsumed;
			}
			else
			{
				if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
				{
				m_pWorldEditNumber->SetFocus(ETrue);
				m_pWorldEditNumber->SetCursorPosL(1,ETrue);
				m_pWorldEditName->SetFocus(EFalse);
				m_pWorldEditSurName->SetFocus(EFalse);
				return EKeyWasConsumed;
				}
			}

			return m_pWorldEditName->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	
	if (m_pWorldEditNumber)
	{
		if (m_pWorldEditNumber->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				m_pWorldEditName->SetFocus(ETrue);
				m_pWorldEditNumber->SetFocus(EFalse);
				return EKeyWasConsumed;
			}
			return m_pWorldEditNumber->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	
	return EKeyWasNotConsumed;
    }


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

void CWorldContainer::GetSurName(TDes &aSurName)
{
     m_pWorldEditSurName->GetText(aSurName);
}

void CWorldContainer::GetName(TDes &aName)
{
    m_pWorldEditName->GetText(aName);
	
}
void CWorldContainer::GetNumber(TDes &aNum)
{
     m_pWorldEditNumber->GetText(aNum);
}
// End of File  

⌨️ 快捷键说明

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