📄 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
#include <eikenv.h> //for CEikonEnv
//用于函数:显示图片SetPicture()
#include "MyHelloAppUi.h"
#include <fbs.h> //for CFbsBitmap
#include <MyHello.mbg>
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CHelloContainer::CHelloContainer()
{
m_pLabel = NULL;
m_pEdit = NULL;
m_pRssEdit = NULL;
m_pLabelPassword = NULL;
m_nDrawEditRectFlag = 0;
}
// EPOC default constructor can leave.
void CHelloContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//load chinese words
TBuf<32> sNameLabel;
CEikonEnv::Static()->ReadResource(sNameLabel, R_QTN_MH_HELLO_NAME_LABEL);
//Label for User Name
m_pLabel = new(ELeave) CEikLabel;
m_pLabel->SetContainerWindowL(*this);
m_pLabel->SetTextL(sNameLabel); //(_L("User Name :"));
m_pLabel->SetExtent(TPoint(10,20), m_pLabel->MinimumSize());
//load chinese words
TBuf<32> sPasswordLabel;
CEikonEnv::Static()->ReadResource(sPasswordLabel, R_QTN_MH_HELLO_PASSWORD_LABEL);
//Label for PassWord
m_pLabelPassword = new(ELeave) CEikLabel;
m_pLabelPassword->SetContainerWindowL(*this);
m_pLabelPassword->SetTextL(sPasswordLabel); //(_L("PassWord :"));
m_pLabelPassword->SetExtent(TPoint(10,60), 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);
MEM_FREE(m_pLabelPassword);
}
// ---------------------------------------------------------
// 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 4;
}
// ---------------------------------------------------------
// 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;
}
case 1:
{
return m_pEdit;
}
case 2:
{
return m_pRssEdit;
}
case 3:
{
return m_pLabelPassword;
}
default:
{
return NULL;
}
}
}
// ---------------------------------------------------------
// CHelloContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CHelloContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
//Draw the Client Area (Rect) by the Brush.
// //gc.SetPenStyle(CGraphicsContext::ENullPen);
// gc.SetBrushColor(KRgbGreen);
// gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
// gc.DrawRect(aRect);
//
// //Draw the Client Area (Rect) by the Pen:
// gc.SetPenStyle(CGraphicsContext::ESolidPen);
// gc.SetPenColor(KRgbBlack);
// gc.SetPenSize(TSize(2,2));
//
// TRect rect;
// rect.SetRect(TPoint(0,0), TSize(176, 144));
// gc.DrawRect(rect);
//Get the path of the mbm.
TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
pathMbm.Copy(_L("z:\\system\\apps\\myhello\\myhello.mbm"));
#else
CMyHelloAppUi* pApp = (CMyHelloAppUi*)CEikonEnv::Static()->AppUi();
pApp->GetAppPath(pathMbm);
pathMbm.Append(_L("myhello.mbm"));
#endif
//Draw the backgroud with a bmp.
//CFbsBitmap* bitmap = new(ELeave) CFbsBitmap();
//bitmap->Load(pathMbm, EMbmMyhelloBack_1_icon);
//gc.BitBlt(TPoint(0, 0), bitmap);
//delete bitmap;
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(pathMbm, EMbmMyhelloBack_1_icon);
gc.BitBlt(TPoint(0, 0), bitmap);
MEM_FREE(bitmap);
//Draw the Rect of the Edit of focus.
switch (m_nDrawEditRectFlag)
{
case 0:
{
gc.DrawRect(TRect(TPoint(69,19), TSize(82,22)));
break;
}
case 1:
{
gc.DrawRect(TRect(TPoint(69,59), TSize(82,22)));
break;
}
}
//gc.DrawLine(TPoint(69,40), TPoint(151,40));
//gc.DrawLine(TPoint(69,80), TPoint(151,80));
}
// 显示图片
// void CHelloContainer::SetPicture(TInt aIndex)
// {
// //获得系统图形场景及控制矩形区域
// CWindowGc& gc = SystemGc();
//
// //建立绘制矩形区
// TRect rect = TRect( TPoint(0, 0), TSize(176, 144));
//
// //激活图形场景
// ActivateGc();
//
// //使窗口失效
// Window().Invalidate( rect );
// Window().BeginRedraw( rect );
//
// //绘制一幅位图
//
// //获取多位图路径
// TBuf<KMaxPath> pathMbm;
// #ifdef __WINS__
// pathMbm.Copy(_L("z:\\system\\apps\\myhello\\myhello.mbm"));
// #else
// CMyHelloAppUi* pApp = (CMyHelloAppUi*)CEikonEnv::Static()->AppUi();
// pApp->GetAppPath(pathMbm);
// pathMbm.Append(_L("myhello.mbm"));
// #endif
//
// //加载一张位图
// CFbsBitmap* bitmap = new(ELeave)CFbsBitmap();
// bitmap->Load(pathMbm, aIndex);
// gc.BitBlt(TPoint(0, 0), bitmap);
// Window().EndRedraw();
//
// //终止图形场景的活动状态
// DeactivateGc();
//
// //释放位图空间
// MEM_FREE(bitmap);
// }
// ---------------------------------------------------------
// 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);
m_nDrawEditRectFlag = 1;
DrawNow();
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);
m_nDrawEditRectFlag = 0;
DrawNow();
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 + -