📄 editcontainer.cpp
字号:
#include <gulicon.h>
#include <aknutils.h>
#include <avkon.hrh>
#include <akntitle.h>
#include <eiklabel.h>
#include "LDFUCK.rsg"
#include <e32des16.h>//TDesC
#include "EditContainer.h"
//#include <coemain.h>
#include <eikedwin.h>
#include <barsread.h>// TResourceReader
#include <aknnotewrappers.h>
CEditContainer::CEditContainer()
{
m_ptext = NULL;
m_ptitle = NULL;
}
// EPOC default constructor can leave.
void CEditContainer::ConstructL(const TRect& aRect, const TDesC& aNumber, const TDesC& aContent)
{
CreateWindowL();
//添加标签手机
b_plablename = new (ELeave) CEikLabel;
b_plablename->SetContainerWindowL( *this );
TBuf<32> buf;
CEikonEnv::Static()->ReadResource(buf, R_QTN_LF_EDITNUM);
b_plablename->SetTextL(buf);
b_plablename->SetExtent( TPoint(10,12), b_plablename->MinimumSize() );
//添加标签内容
b_plablecontent = new (ELeave) CEikLabel;
b_plablecontent->SetContainerWindowL( *this );
// TBuf<32> buf;
CEikonEnv::Static()->ReadResource(buf, R_QTN_LF_EDITCON);
b_plablecontent->SetTextL(buf);
b_plablecontent->SetExtent( TPoint(10,40), b_plablecontent->MinimumSize() );
//添加手机号码输入
m_ptext = new (ELeave) CEikEdwin(TGulBorder::ESingleBlack);
m_ptext->SetContainerWindowL(*this);
//add tempNumber
// m_ptext->ConstructL(EAknEditorFlagLatinInputModesOnly);
m_ptext->ConstructL(EEikEdwinNoAutoSelection | EEikEdwinIgnoreVirtualCursor, 11, 11, 1);
m_ptext->SetAknEditorCurrentInputMode(EAknEditorNumericInputMode);
m_ptext->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode);
m_ptext->SetAknEditorFlags(EAknEditorFlagLatinInputModesOnly);
// m_ptext->SetAknEditorNumericKeymap(EAknEditorPlainNumberModeKeyMap);
m_ptext->SetExtent(TPoint(50, 10), TSize(110, 20));
// TResourceReader reader;
// iCoeEnv->CreateResourceReaderLC(reader, R_EDITVIEW_NUMBEREDIT);
// CleanupStack::PopAndDestroy(); // reader
//set Focus
m_ptext->SetFocus(EFalse);
//添加内容输入
m_ptitle = new (ELeave) CEikEdwin(TGulBorder::ESingleBlack);
m_ptitle->SetContainerWindowL(*this);
m_ptitle->ConstructL(EEikEdwinNoAutoSelection | EEikEdwinIgnoreVirtualCursor|EEikEdwinJustAutoCurEnd, 15, 77, 7);
m_ptitle->SetExtent(TPoint(50, 40), TSize(110, 90));
//add TempContent
this->addTemp(aNumber,aContent);
//set Focus
m_ptitle->SetFocus(ETrue);
SetRect( aRect );
ActivateL();
}
// destructor
CEditContainer::~CEditContainer()
{
if(m_ptext)
{
delete m_ptext;
m_ptext = NULL;
}
if(m_ptitle)
{
delete m_ptitle;
m_ptitle = NULL;
}
if (b_plablename) {
delete b_plablename;
b_plablename=NULL;
}
if (b_plablecontent) {
delete b_plablecontent;
b_plablecontent=NULL;
}
}
void CEditContainer::SizeChanged()
{
}
// ---------------------------------------------------------
// CEditContainer::CountComponentControls() const
// return the number of controls
// ---------------------------------------------------------
//
TInt CEditContainer::CountComponentControls() const
{
// return number of controls inside this container
return 4;
}
// ---------------------------------------------------------
// CEditContainer::ComponentControl(TInt aIndex) const
// return the pointer to specified control.
// ---------------------------------------------------------
//
CCoeControl* CEditContainer::ComponentControl( TInt aIndex ) const
{
switch(aIndex) {
case 0 :
return m_ptext;
break;
case 1 :
return m_ptitle;
break;
case 2 :
return b_plablename;
break;
case 3 :
return b_plablecontent;
break;
default:
return NULL;
break;
}
}
// ---------------------------------------------------------
// CEditContainer::Draw(const TRect& aRect) const
// handle the message when client region must be redrawn.
// ---------------------------------------------------------
//
void CEditContainer::Draw( const TRect& aRect ) const
{
CWindowGc& gc = SystemGc();
//设置背景颜色为灰色
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
gc.Clear(Rect());
// gc.DrawRect(TRect(TPoint(10, 10), TSize(20, 20)));
}
// ---------------------------------------------------------
// CAknExGridContainer::OfferKeyEventL(
// const TKeyEvent& aKeyEvent, TEventCode aType )
// Handles the key events.
// ---------------------------------------------------------
//
TKeyResponse CEditContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
if (m_ptitle)
{
if (m_ptitle->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
{
m_ptitle->SetFocus(EFalse);
m_ptext->SetFocus(ETrue);
return EKeyWasConsumed;
}
return m_ptitle->OfferKeyEventL(aKeyEvent, aType);
}
}
if (m_ptext)
{
if (m_ptext->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
{
m_ptext->SetFocus(EFalse);
m_ptitle->SetFocus(ETrue);
return EKeyWasConsumed;
}
return m_ptext->OfferKeyEventL(aKeyEvent, aType);
}
if (m_ptext)
return m_ptext->OfferKeyEventL(aKeyEvent, aType);
else
return CCoeControl::OfferKeyEventL(aKeyEvent, aType);
}
return EKeyWasNotConsumed;
}
TBool CEditContainer::TextJudge()
{
TBuf<128> ztext;
getText(ztext);
TBuf<32> buf;
if(ztext.Length() > 50)
{
CEikonEnv::Static()->ReadResource(buf, R_QTN_LF_ALERT_CON);//内容不得超过50字
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(buf);
return EFalse;
}
else
return ETrue;
}
TBool CEditContainer::NumJudge()
{
TBuf<16> znumber;
getNumber(znumber);
TBuf<32> buf;
if(znumber.Length() != 11)
{
CEikonEnv::Static()->ReadResource(buf, R_QTN_LF_ALERT_NUM);//请输入11位手机号
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(buf);
return EFalse;
}
else
return ETrue;
}
void CEditContainer::getNumber( TDes& aNumber )
{
m_ptext->GetText(aNumber);
}
void CEditContainer::getText( TDes& aText )
{
m_ptitle->GetText(aText);
}
void CEditContainer::addTemp(const TDesC& aNumber,const TDesC& aContent)
{
TBuf<128> zCon;
m_ptitle->GetText(zCon);
zCon.Append(aContent);
m_ptitle->SetTextL(&zCon);
TBuf<128> zNum;
zNum.Append(aNumber);
m_ptext->SetTextL(&zNum);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -