📄 hellocontainer.cpp
字号:
/*
* ============================================================================
* Name : CHelloContainer from CCoeControl, MCoeControlObserver
* Part of : Hello
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <MyHello.rsg>
#include "MyHello.hrh"
#include "HelloContainer.h"
#include <eiklabel.h> //for CEikLabel
#include <eikedwin.h> //for CEikEdit
#include <barsread.h> //for resource reader
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CHelloContainer::CHelloContainer()
{
m_pLabel = NULL;
m_pEdit = NULL;
m_pRssEdit = NULL;
}
// EPOC default constructor can leave.
void CHelloContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//Label
m_pLabel = new(ELeave) CEikLabel;
m_pLabel->SetContainerWindowL(*this);
m_pLabel->SetTextL(_L("User Name :"));
m_pLabel->SetExtent(TPoint(10,20), m_pLabel->MinimumSize());
//Edit
m_pEdit = new(ELeave) CEikEdwin;
m_pEdit->SetContainerWindowL(*this);
m_pEdit->ConstructL(EAknEditorFlagDefault, 10, 10, 1);
m_pEdit->SetExtent(TPoint(70,20), TSize(80,20));
m_pEdit->SetTextL(&_L("Input User Name!"));
m_pEdit->SetFocus(ETrue);
//Edit from RSS
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_AKNEXEDITOR_HELLO_VIEW_EDWIN);
m_pRssEdit = new(ELeave) CEikEdwin;
m_pRssEdit->SetContainerWindowL(*this);
m_pRssEdit->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy();
m_pRssEdit->SetAknEditorCurrentInputMode(EAknEditorNumericInputMode);//only Input number.
m_pRssEdit->SetExtent(TPoint(70,60), TSize(80,20));
m_pRssEdit->SetTextL(&_L("Edit from Rss: Pass Word!"));
SetRect(aRect);
ActivateL();
}
// Destructor
CHelloContainer::~CHelloContainer()
{
MEM_FREE(m_pLabel);
MEM_FREE(m_pEdit);
MEM_FREE(m_pRssEdit);
}
// ---------------------------------------------------------
// CHelloContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CHelloContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CHelloContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CHelloContainer::SizeChanged()
{
}
// ---------------------------------------------------------
// CHelloContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CHelloContainer::CountComponentControls() const
{
//return 0; // return nbr of controls inside this container
return 3;
}
// ---------------------------------------------------------
// CHelloContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CHelloContainer::ComponentControl(TInt aIndex) const
{
//return NULL;
switch (aIndex)
{
case 0:
{
return m_pLabel;
break;
}
case 1:
{
return m_pEdit;
break;
}
case 2:
{
return m_pRssEdit;
break;
}
default:
{
return NULL;
break;
}
}
}
// ---------------------------------------------------------
// CHelloContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CHelloContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
//gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenColor(KRgbRed);
gc.DrawLine(TPoint(50,50), TPoint(100,90));
}
// ---------------------------------------------------------
// CHelloContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CHelloContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
//return EKeyWasNotConsumed;
if (m_pEdit)
{
if (m_pEdit->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
{
m_pEdit->SetFocus(EFalse);
m_pRssEdit->SetFocus(ETrue);
return EKeyWasConsumed;
}
return m_pEdit->OfferKeyEventL(aKeyEvent, aType);
}
}
if (m_pRssEdit)
{
if (m_pRssEdit->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
{
m_pEdit->SetFocus(ETrue);
m_pRssEdit->SetFocus(EFalse);
return EKeyWasConsumed;
}
return m_pRssEdit->OfferKeyEventL(aKeyEvent, aType);
}
}
return EKeyWasNotConsumed;
}
// ---------------------------------------------------------
// CHelloContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CHelloContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
void CHelloContainer::GetLoginName(TDes &aName)
{
m_pEdit->GetText(aName);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -