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

📄 bookinfocontainer.cpp

📁 symbian系统上的记事本程序
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CBookInfoContainer from CCoeControl, MCoeControlObserver
*  Part of  : Hello
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES

#include <EveryDay.rsg>
#include "EveryDay.hrh"
#include "BookInfoContainer.h"
#include "BookInfoView.h"
#include <eiklabel.h>
#include <eikedwin.h>
#include <barsread.h>//资源中定义
#include <aknnotewrappers.h>//
#include <aknviewappui.h>  //for iEikonEnv
#include "EveryDayAppUi.h"
#include <aknnumseced.h> 

CBookInfoContainer::CBookInfoContainer()
{
	m_pFirstnameLabel = NULL;
	m_pLastnameLabel = NULL;
	m_TelephoneLabel = NULL;
	m_pFirstnameEdwin = NULL;
	m_pLastnameEdwin = NULL;
	m_pTelephoneEdwin = NULL;
	
}

void CBookInfoContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
	TBuf<32> nInfo1;
	CEikonEnv::Static()->ReadResource(nInfo1, R_BOOK_FIRST);
	TBuf<32> nInfo2;
	CEikonEnv::Static()->ReadResource(nInfo2, R_BOOK_LAST);
	TBuf<32> nInfo3;
	CEikonEnv::Static()->ReadResource(nInfo3, R_BOOK_TELEPHONE);
	
	m_pFirstnameLabel = new(ELeave)CEikLabel;
	m_pFirstnameLabel->SetContainerWindowL(*this);
	m_pFirstnameLabel->SetTextL(nInfo1);
	m_pFirstnameLabel->SetExtent(TPoint(10,20), m_pFirstnameLabel->MinimumSize());
	
	m_pLastnameLabel = new(ELeave)CEikLabel;
	m_pLastnameLabel->SetContainerWindowL(*this);
	m_pLastnameLabel->SetTextL(nInfo2);
	m_pLastnameLabel->SetExtent(TPoint(10,60), m_pLastnameLabel->MinimumSize());
	
	m_TelephoneLabel = new(ELeave)CEikLabel;
	m_TelephoneLabel->SetContainerWindowL(*this);
	m_TelephoneLabel->SetTextL(nInfo3);
	m_TelephoneLabel->SetExtent(TPoint(10,100), m_TelephoneLabel->MinimumSize());
	
	TResourceReader ReadFirstname;
	iCoeEnv->CreateResourceReaderLC(ReadFirstname, R_BOOK_FIRST_EDWIN);
	m_pFirstnameEdwin = new(ELeave)CEikEdwin;
	m_pFirstnameEdwin->SetContainerWindowL(*this);
	m_pFirstnameEdwin->ConstructFromResourceL(ReadFirstname);
	CleanupStack::PopAndDestroy();
	m_pFirstnameEdwin->SetExtent(TPoint(70,20), TSize(80,18));
	m_pFirstnameEdwin->SetBorder(ENone);	
	m_pFirstnameEdwin->SetFocus(ETrue);
	TResourceReader ReadLastname;
	
	iCoeEnv->CreateResourceReaderLC(ReadLastname, R_BOOK_FIRST_EDWIN);
	m_pLastnameEdwin = new(ELeave)CEikEdwin;
	m_pLastnameEdwin->SetContainerWindowL(*this);
	m_pLastnameEdwin->ConstructFromResourceL(ReadLastname);
	CleanupStack::PopAndDestroy();
	m_pLastnameEdwin->SetExtent(TPoint(70,60), TSize(80,18));
	m_pFirstnameEdwin->SetBorder(ENone);
	
	TResourceReader ReadTelephone;
	iCoeEnv->CreateResourceReaderLC(ReadTelephone, R_BOOK_TEL_EDWIN);
	m_pTelephoneEdwin = new(ELeave)CEikEdwin;
	m_pTelephoneEdwin->SetContainerWindowL(*this);
	m_pTelephoneEdwin->ConstructFromResourceL(ReadTelephone);
	CleanupStack::PopAndDestroy();
	m_pTelephoneEdwin->SetExtent(TPoint(70,100), TSize(80,18));
	m_pFirstnameEdwin->SetBorder(ENone);
	
    SetRect(aRect);
    ActivateL();
}

CBookInfoContainer::~CBookInfoContainer()
{
	MEM_FREE(m_pFirstnameLabel);
	MEM_FREE(m_pFirstnameEdwin);
	MEM_FREE(m_pLastnameLabel);
	MEM_FREE(m_pLastnameEdwin);
	MEM_FREE(m_TelephoneLabel);
	MEM_FREE(m_pTelephoneEdwin);
}

void CBookInfoContainer::FocusTo(TInt aCommand)
{
}

void CBookInfoContainer::SizeChanged()
{
}

TInt CBookInfoContainer::CountComponentControls() const
{
	return 6; // return nbr of controls inside this container
}

CCoeControl* CBookInfoContainer::ComponentControl(TInt aIndex) const
{
	switch (aIndex)
	{
	case 0:
		{
			return m_pFirstnameLabel;
			break;
		}
	case 1:
		{
			return m_pLastnameLabel;
			break;
		}
	case 2:
		{
			return m_TelephoneLabel;
			break;
		}
	case 3:
		{
			return m_pFirstnameEdwin;
			break;
		}
	case 4:
		{
			return m_pLastnameEdwin;
			break;
		}
	case 5:
		{
			return m_pTelephoneEdwin;
			break;
		}
	default:
		{
			return NULL;
			break;
		}
	}
}

void CBookInfoContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbGray);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
    
    //画三个红色框;
    if(m_pFirstnameEdwin->IsFocused())//获取焦点
	{
		gc.SetPenColor(KRgbRed);
	}
	else
	{
		gc.SetPenColor(KRgbBlack);
	}
    gc.SetPenStyle(CGraphicsContext::ESolidPen);
    TRect RectFirst;
	RectFirst.iTl = TPoint(69,18);
	RectFirst.iBr = TPoint(152,40);
	
	
	gc.DrawRect(RectFirst);
    
    if(m_pLastnameEdwin->IsFocused())//获取焦点
	{
		gc.SetPenColor(KRgbRed);
	}
	else
	{
		gc.SetPenColor(KRgbBlack);
	}
    gc.SetPenStyle(CGraphicsContext::ESolidPen);
    TRect RectLast;
    RectLast.iTl = TPoint(69,58);
    RectLast.iBr = TPoint(152,80);
    gc.DrawRect(RectLast);
    
    if(m_pTelephoneEdwin->IsFocused())//获取焦点
	{
		gc.SetPenColor(KRgbRed);
	}
	else
	{
		gc.SetPenColor(KRgbBlack);
	}
    gc.SetPenStyle(CGraphicsContext::ESolidPen);
    TRect RectTel;
    RectTel.iTl = TPoint(69,99);
    RectTel.iBr = TPoint(152,119);
    gc.DrawRect(RectTel);
    
}

TKeyResponse CBookInfoContainer::OfferKeyEventL(
												const TKeyEvent& aKeyEvent, TEventCode aType)
{
	if (m_pFirstnameEdwin)
	{
		if (m_pFirstnameEdwin->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
			{
				m_pFirstnameEdwin->SetFocus(EFalse);
				m_pLastnameEdwin->SetFocus(ETrue);
				m_pTelephoneEdwin->SetFocus(EFalse);
				DrawNow();
				return EKeyWasConsumed;
			}
			return m_pFirstnameEdwin->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	
	if (m_pLastnameEdwin)
	{
		if (m_pLastnameEdwin->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				m_pFirstnameEdwin->SetFocus(ETrue);
				m_pLastnameEdwin->SetFocus(EFalse);
				m_pTelephoneEdwin->SetFocus(EFalse);
				DrawNow();
				return EKeyWasConsumed;
			}
			else 	if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
			{
				m_pFirstnameEdwin->SetFocus(EFalse);
				m_pLastnameEdwin->SetFocus(EFalse);
				m_pTelephoneEdwin->SetFocus(ETrue);
				DrawNow();
				return EKeyWasConsumed;
			}
			return m_pLastnameEdwin->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	if (m_pTelephoneEdwin)
	{
		if (m_pTelephoneEdwin->IsFocused())
		{
			if ((aType==EEventKey)&&(aKeyEvent.iCode==EKeyUpArrow))
			{
				m_pFirstnameEdwin->SetFocus(EFalse);
				m_pLastnameEdwin->SetFocus(ETrue);
				m_pTelephoneEdwin->SetFocus(EFalse);
				DrawNow();
				return EKeyWasConsumed;
			}
			return m_pTelephoneEdwin->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	return EKeyWasNotConsumed;
}


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

void CBookInfoContainer::GetEditInfo(TDes& afirst,TDes& alast,TDes& atelephone)
{
	m_pFirstnameEdwin->GetText(afirst);
	m_pLastnameEdwin->GetText(alast);
	m_pTelephoneEdwin->GetText(atelephone);
}

void CBookInfoContainer::EditReadonly()
{
	m_pFirstnameEdwin->SetReadOnly(ETrue);
	m_pLastnameEdwin->SetReadOnly(ETrue);
	m_pTelephoneEdwin->SetReadOnly(ETrue);
}

void CBookInfoContainer::SetTxtInfo(TDes& first, TDes& last, TDes& telphone)
{
	m_pFirstnameEdwin->SetTextL(&first);
	m_pLastnameEdwin->SetTextL(&last);
	m_pTelephoneEdwin->SetTextL(&telphone);
}
// End of File  m_pFirstnameLabel = NULL;

⌨️ 快捷键说明

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