bookeditcontainer.cpp
来自「symbian 2rd 备忘录」· C++ 代码 · 共 582 行
CPP
582 行
#include <gulicon.h>
#include <aknutils.h> // definition of AKN_LAF_COLOR()
#include <avkon.hrh>
#include <akntitle.h>
#include <aknnotewrappers.h>
#include "BookEditContainer.h"
#include "Assistant.rsg"
#include "BookInfo.h"
#include "Assistant.hrh"
//////////////////////////////////////////////////////////////////////////
CBookEditContainer::CBookEditContainer()
{
m_pLabel1 = NULL;
m_pLabel2 = NULL;
m_pLabel3 = NULL;
m_pEdwin1 = NULL;
m_pEdwin2 = NULL;
m_pEdwin3 = NULL;
m_pBookInfo = NULL;
m_nCount = 0;
}
// EPOC default constructor can leave.
void CBookEditContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
TBuf<32> sTmpLabel;
//create name label
m_pLabel1 = new( ELeave ) CEikLabel;
m_pLabel1->SetContainerWindowL( *this );
m_pLabel1->SetExtent(TPoint(10,5), TSize(100, 18));
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_LASTNAME);
m_pLabel1->SetTextL(sTmpLabel);
m_pLabel2 = new( ELeave ) CEikLabel;
m_pLabel2->SetContainerWindowL( *this );
m_pLabel2->SetExtent(TPoint(10,48), TSize(100, 18));
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_FIRSTNAME);
m_pLabel2->SetTextL(sTmpLabel);
m_pLabel3 = new( ELeave ) CEikLabel;
m_pLabel3->SetContainerWindowL( *this );
m_pLabel3->SetExtent(TPoint(10,98), TSize(100, 18));
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_TELEPHONE);
m_pLabel3->SetTextL(sTmpLabel);
m_pEdwin1 = new (ELeave) CEikEdwin;
m_pEdwin1->SetContainerWindowL(*this);
m_pEdwin1->ConstructL(EAknEditorFlagDefault, 10, 50, 1);
m_pEdwin1->SetExtent(TPoint(25, 24), TSize(145, 18));
m_pEdwin1->SetFocus(ETrue);
m_pEdwin2 = new (ELeave) CEikEdwin;
m_pEdwin2->SetContainerWindowL(*this);
m_pEdwin2->ConstructL(EAknEditorFlagDefault, 10, 50, 1);
m_pEdwin2->SetExtent(TPoint(25, 72), TSize(145, 18));
m_pEdwin2->SetFocus(EFalse);
m_pEdwin3 = new (ELeave) CEikEdwin;
m_pEdwin3->SetContainerWindowL(*this);
m_pEdwin3->ConstructL(EAknEditorFlagDefault, 10, 50, 1);
m_pEdwin3->SetExtent(TPoint(25, 120), TSize(145, 18));
m_pEdwin3->SetFocus(EFalse);
m_pBookInfo = CBookInfo::NewL();
SetRect( aRect );
ActivateL();
}
// destructor
CBookEditContainer::~CBookEditContainer()
{
MEMORY_FREE(m_pEdwin1);
MEMORY_FREE(m_pEdwin2);
MEMORY_FREE(m_pEdwin3);
MEMORY_FREE(m_pLabel1);
MEMORY_FREE(m_pLabel2);
MEMORY_FREE(m_pLabel3);
MEMORY_FREE(m_pBookInfo);
}
void CBookEditContainer::SizeChanged()
{
}
// ---------------------------------------------------------
// CBookEditContainer::CountComponentControls() const
// return the number of controls
// ---------------------------------------------------------
//
TInt CBookEditContainer::CountComponentControls() const
{
// return number of controls inside this container
return 6;
}
// ---------------------------------------------------------
// CBookEditContainer::ComponentControl(TInt aIndex) const
// return the pointer to specified control.
// ---------------------------------------------------------
//
CCoeControl* CBookEditContainer::ComponentControl( TInt aIndex ) const
{
switch (aIndex)
{
case 0:
return m_pEdwin1;
break;
case 1:
return m_pEdwin2;
break;
case 2:
return m_pEdwin3;
break;
case 3:
return m_pLabel1;
break;
case 4:
return m_pLabel2;
break;
case 5:
return m_pLabel3;
break;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CBookEditContainer::Draw(const TRect& aRect) const
// handle the Book when client region must be redrawn.
// ---------------------------------------------------------
//
void CBookEditContainer::Draw( const TRect& aRect ) const
{
CWindowGc& gc = SystemGc();
// gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
// gc.SetBrushColor(KRgbWhite);
// gc.DrawRect(Rect());
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenColor(KRgbGray);
//gc.SetPenStyle(CGraphicsContext::ESolidPen);
TRect rect1(m_pEdwin1->Rect());
// rect1.Shrink(-1, -1);
gc.DrawRect(rect1);
// gc.SetPenStyle(CGraphicsContext::ESolidPen);
TRect rect2(m_pEdwin2->Rect());
// rect2.Shrink(-1, -1);
gc.DrawRect(rect2);
// gc.SetPenStyle(CGraphicsContext::ESolidPen);
TRect rect3(m_pEdwin3->Rect());
// rect3.Shrink(-1, -1);
gc.DrawRect(rect3);
}
// ---------------------------------------------------------
// CAknExGridContainer::OfferKeyEventL(
// const TKeyEvent& aKeyEvent, TEventCode aType )
// Handles the key events.
// ---------------------------------------------------------
//
TKeyResponse CBookEditContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
HBufC* content = HBufC::NewL(50);
TBuf<32> sTmpLabel;
if (m_pEdwin1)
{
if (m_pEdwin1->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
{
m_pEdwin1->SetFocus(EFalse);
m_pEdwin2->SetFocus(ETrue);
DrawDeferred();
m_pEdwin1->GetText(content->Des());
switch(m_nCount)
{
case 0:
{
m_pBookInfo->SetLastName(content->Des());
}
break;
case 1:
{
m_pBookInfo->SetFirstName(content->Des());
}
break;
case 2:
{
m_pBookInfo->SetTelephone(content->Des());
}
break;
case 3:
{
m_pBookInfo->SetEmail(content->Des());
}
break;
}
delete content;
return EKeyWasConsumed;
}
else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow) && m_nCount >0)
{
// m_pEdwin1->SetFocus(ETrue);
// m_pEdwin2->SetFocus(EFalse);
DrawDeferred();
m_pEdwin1->GetText(content->Des());
if(m_nCount == 1)
{
m_pBookInfo->SetFirstName(content->Des());
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_TELEPHONE);
m_pLabel3->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_FIRSTNAME);
m_pLabel2->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_LASTNAME);
m_pLabel1->SetTextL(sTmpLabel);
m_pEdwin1->SetTextL(m_pBookInfo->GetLastName());
m_pEdwin2->SetTextL(m_pBookInfo->GetFirstName());
m_pEdwin3->SetTextL(m_pBookInfo->GetTelephone());
}
else if(m_nCount == 2)
{
m_pBookInfo->SetTelephone(content->Des());
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_EMAIL);
m_pLabel3->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_TELEPHONE);
m_pLabel2->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_FIRSTNAME);
m_pLabel1->SetTextL(sTmpLabel);
m_pEdwin1->SetTextL(m_pBookInfo->GetFirstName());
m_pEdwin2->SetTextL(m_pBookInfo->GetTelephone());
m_pEdwin3->SetTextL(m_pBookInfo->GetEmail());
}
else if(m_nCount == 3)
{
m_pBookInfo->SetEmail(content->Des());
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_COMPANY);
m_pLabel3->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_EMAIL);
m_pLabel2->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_TELEPHONE);
m_pLabel1->SetTextL(sTmpLabel);
m_pEdwin1->SetTextL(m_pBookInfo->GetTelephone());
m_pEdwin2->SetTextL(m_pBookInfo->GetEmail());
m_pEdwin3->SetTextL(m_pBookInfo->GetCompany());
}
m_nCount--;
delete content;
return EKeyWasConsumed;
}
delete content;
return m_pEdwin1->OfferKeyEventL(aKeyEvent, aType);
}
}
if (m_pEdwin2)
{
if (m_pEdwin2->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
{
m_pEdwin1->SetFocus(ETrue);
m_pEdwin2->SetFocus(EFalse);
}
else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
{
m_pEdwin2->SetFocus(EFalse);
m_pEdwin3->SetFocus(ETrue);
}
else
{
delete content;
return m_pEdwin2->OfferKeyEventL(aKeyEvent, aType);
}
DrawDeferred();
m_pEdwin2->GetText(content->Des());
switch(m_nCount)
{
case 0:
{
m_pBookInfo->SetFirstName(content->Des());
}
break;
case 1:
{
m_pBookInfo->SetTelephone(content->Des());
}
break;
case 2:
{
m_pBookInfo->SetEmail(content->Des());
}
break;
case 3:
{
m_pBookInfo->SetCompany(content->Des());
}
break;
}
delete content;
return EKeyWasConsumed;
}
}
if (m_pEdwin3)
{
if (m_pEdwin3->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
{
m_pEdwin2->SetFocus(ETrue);
m_pEdwin3->SetFocus(EFalse);
DrawDeferred();
m_pEdwin3->GetText(content->Des());
switch(m_nCount)
{
case 0:
{
m_pBookInfo->SetTelephone(content->Des());
}
break;
case 1:
{
m_pBookInfo->SetEmail(content->Des());
}
break;
case 2:
{
m_pBookInfo->SetCompany(content->Des());
}
break;
case 3:
{
m_pBookInfo->SetAddress(content->Des());
}
break;
}
delete content;
return EKeyWasConsumed;
}
else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow) && (m_nCount < 3))
{
DrawDeferred();
m_pEdwin3->GetText(content->Des());
if(m_nCount == 0)
{
m_pBookInfo->SetTelephone(content->Des());
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_EMAIL);
m_pLabel3->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_TELEPHONE);
m_pLabel2->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_FIRSTNAME);
m_pLabel1->SetTextL(sTmpLabel);
m_pEdwin3->SetTextL(m_pBookInfo->GetEmail());
m_pEdwin2->SetTextL(m_pBookInfo->GetTelephone());
m_pEdwin1->SetTextL(m_pBookInfo->GetFirstName());
}
else if(m_nCount == 1)
{
m_pBookInfo->SetEmail(content->Des());
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_COMPANY);
m_pLabel3->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_EMAIL);
m_pLabel2->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_TELEPHONE);
m_pLabel1->SetTextL(sTmpLabel);
m_pEdwin3->SetTextL(m_pBookInfo->GetCompany());
m_pEdwin2->SetTextL(m_pBookInfo->GetEmail());
m_pEdwin1->SetTextL(m_pBookInfo->GetTelephone());
}
else if(m_nCount == 2)
{
m_pBookInfo->SetCompany(content->Des());
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_ADDRESS);
m_pLabel3->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_COMPANY);
m_pLabel2->SetTextL(sTmpLabel);
CEikonEnv::Static()->ReadResource(sTmpLabel, R_QTN_ASSISTANT_EMAIL);
m_pLabel1->SetTextL(sTmpLabel);
m_pEdwin3->SetTextL(m_pBookInfo->GetAddress());
m_pEdwin2->SetTextL(m_pBookInfo->GetCompany());
m_pEdwin1->SetTextL(m_pBookInfo->GetEmail());
}
m_nCount++;
delete content;
return EKeyWasConsumed;
}
delete content;
return m_pEdwin3->OfferKeyEventL(aKeyEvent, aType);
}
}
}
void CBookEditContainer::SetData(TInt aStatus,CBookInfo* aBookInfo)
{
if(aBookInfo->GetLastName())
{
m_pBookInfo->SetLastName(aBookInfo->GetLastName()->Des());
}
else
{
m_pBookInfo->SetLastName(_L(""));
}
if(aBookInfo->GetFirstName())
{
m_pBookInfo->SetFirstName(aBookInfo->GetFirstName()->Des());
}
else
{
m_pBookInfo->SetFirstName(_L(""));
}
if(aBookInfo->GetTelephone())
{
m_pBookInfo->SetTelephone(aBookInfo->GetTelephone()->Des());
}
else
{
m_pBookInfo->SetTelephone(_L(""));
}
if(aBookInfo->GetEmail())
{
m_pBookInfo->SetEmail(aBookInfo->GetEmail()->Des());
}
else
{
m_pBookInfo->SetEmail(_L(""));
}
if(aBookInfo->GetCompany())
{
m_pBookInfo->SetCompany(aBookInfo->GetCompany()->Des());
}
else
{
m_pBookInfo->SetCompany(_L(""));
}
if(aBookInfo->GetAddress())
{
m_pBookInfo->SetAddress(aBookInfo->GetAddress()->Des());
}
else
{
m_pBookInfo->SetAddress(_L(""));
}
m_pEdwin1->SetTextL(m_pBookInfo->GetLastName());
m_pEdwin2->SetTextL(m_pBookInfo->GetFirstName());
m_pEdwin3->SetTextL(m_pBookInfo->GetTelephone());
ChangeReadOnly(aStatus);
}
CBookInfo* CBookEditContainer::GetData()
{
HBufC* content = HBufC::NewLC(50);
if(m_pEdwin1->IsFocused())
{
m_pEdwin1->GetText(content->Des());
switch (m_nCount)
{
case 0:
m_pBookInfo->SetLastName(content->Des());
break;
case 1:
m_pBookInfo->SetFirstName(content->Des());
break;
case 2:
m_pBookInfo->SetTelephone(content->Des());
break;
case 3:
m_pBookInfo->SetEmail(content->Des());
break;
}
}
else if(m_pEdwin2->IsFocused())
{
m_pEdwin2->GetText(content->Des());
switch (m_nCount)
{
case 0:
m_pBookInfo->SetFirstName(content->Des());
break;
case 1:
m_pBookInfo->SetTelephone(content->Des());
break;
case 2:
m_pBookInfo->SetEmail(content->Des());
break;
case 3:
m_pBookInfo->SetCompany(content->Des());
break;
}
}
else if(m_pEdwin3->IsFocused())
{
m_pEdwin3->GetText(content->Des());
switch (m_nCount)
{
case 0:
m_pBookInfo->SetTelephone(content->Des());
break;
case 1:
m_pBookInfo->SetEmail(content->Des());
break;
case 2:
m_pBookInfo->SetCompany(content->Des());
break;
case 3:
m_pBookInfo->SetAddress(content->Des());
break;
}
}
CleanupStack::PopAndDestroy();
return m_pBookInfo;
}
void CBookEditContainer::ChangeReadOnly(TInt aStatus)
{
if(aStatus == EAssistantStatusOpen)
{
m_pEdwin1->SetReadOnly(ETrue);
m_pEdwin2->SetReadOnly(ETrue);
m_pEdwin3->SetReadOnly(ETrue);
}
else if(aStatus == EAssistantStatusModify)
{
m_pEdwin1->SetReadOnly(EFalse);
m_pEdwin2->SetReadOnly(EFalse);
m_pEdwin3->SetReadOnly(EFalse);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?