📄 logoncontainer.cpp
字号:
/*
* ============================================================================
* Name : CLogonContainer from CCoeControl, MCoeControlObserver
* Part of : Logon
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <eiklabel.h> // for example label control
#include <barsread.h> // for resource reader
#include <eikedwin.h> // for CEikEdwin
#include <eikgted.h> // for CEikGlobalTextEditor
#include <aknnotedialog.h> // CAknWaitNoteWrapper
#include <AknQueryDialog.h> //CAknQueryDialog
#include <FrMes.rsg>
#include "FrMes.hrh"
#include "LogonContainer.h"
#include <eikseced.h> // for secret editor
#include <AknNumSecEd.h> // for numeric secret editor
const TInt KNumberOfStepsToSaveGame(20);
const TInt KNumberBack = 200;
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CLogonContainer::CLogonContainer()
{
m_pLabelName = NULL;
m_pLabelCode = NULL;
m_pEditName = NULL;
m_pEditCode = NULL;
m_nStepsCompleted = 0;
m_nRes = 0;
}
// EPOC default constructor can leave.
void CLogonContainer::ConstructL(const TRect& aRect)
{
m_TimeWaster.CreateLocal();
CreateWindowL();
//label sName
TBuf<32> sName;
iCoeEnv->ReadResource(sName, R_QTN_FRMES_LABEL_LVIEW_NAME);
m_pLabelName = new (ELeave) CEikLabel;
m_pLabelName->SetContainerWindowL(*this);
m_pLabelName->SetTextL(sName);
m_pLabelName->SetExtent(TPoint(20, 30), m_pLabelName->MinimumSize());
//edit sName new
m_pEditName = new (ELeave) CEikEdwin(/*TGulBorder::ESingleBlack*/);
m_pEditName->SetContainerWindowL(*this);
m_pEditName->ConstructL(EEikEdwinNoAutoSelection | EEikEdwinIgnoreVirtualCursor, 10, 10, 1);
m_pEditName->SetExtent(TPoint(80, 25), TSize(70, 20));
//label sCode
TBuf<32> sCode;
iCoeEnv->ReadResource(sCode, R_QTN_FRMES_LABEL_VIEW_PWD);
m_pLabelCode = new (ELeave) CEikLabel;
m_pLabelCode->SetContainerWindowL(*this);
m_pLabelCode->SetTextL(sCode);
m_pLabelCode->SetExtent(TPoint(20, 60), m_pLabelCode->MinimumSize());
//edit sCode rss
TResourceReader readercode;
iCoeEnv->CreateResourceReaderLC(readercode,
R_QTN_FRMES_NUM_CODE_COUNT);
m_pEditCode = new (ELeave) CAknNumericSecretEditor();
m_pEditCode->SetContainerWindowL(*this);
m_pEditCode->ConstructFromResourceL(readercode);
CleanupStack::PopAndDestroy(); // Resource reader
m_pEditCode->SetExtent(TPoint(80, 55), TSize(70, 20));
m_pEditName->SetFocus(ETrue);
SetRect(aRect);
ActivateL();
}
// Destructor
CLogonContainer::~CLogonContainer()
{
if(m_pLabelName)
{
delete m_pLabelName;
m_pLabelName = NULL;
}
if(m_pLabelCode)
{
delete m_pLabelCode;
m_pLabelCode = NULL;
}
if(m_pEditName)
{
delete m_pEditName;
m_pEditName = NULL;
}
if(m_pEditCode)
{
delete m_pEditCode;
m_pEditCode = NULL;
}
m_TimeWaster.Close();
}
// ---------------------------------------------------------
// CLogonContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLogonContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CLogonContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLogonContainer::SizeChanged()
{
}
// ---------------------------------------------------------
// CLogonContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CLogonContainer::CountComponentControls() const
{
return 4; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CLogonContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CLogonContainer::ComponentControl(TInt aIndex) const
{
switch(aIndex)
{
case 0:
return m_pLabelName;
break;
case 1:
return m_pEditName;
break;
case 2:
return m_pLabelCode;
break;
case 3:
return m_pEditCode;
break;
default:
return NULL;
break;
}
}
// ---------------------------------------------------------
// CLogonContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLogonContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbRed);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CLogonContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CLogonContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (m_pEditName)
{
if (m_pEditName->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
{
m_pEditName->SetFocus(EFalse);
m_pEditCode->SetFocus(ETrue);
return EKeyWasConsumed;
}
return m_pEditName->OfferKeyEventL(aKeyEvent, aType);
}
}
if (m_pEditCode)
{
if (m_pEditCode->IsFocused())
{
if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
{
m_pEditCode->SetFocus(EFalse);
m_pEditName->SetFocus(ETrue);
return EKeyWasConsumed;
}
return m_pEditCode->OfferKeyEventL(aKeyEvent, aType);
}
}
return EKeyWasNotConsumed;
}
// ---------------------------------------------------------
// CLogonContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLogonContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
void CLogonContainer::GetInput (TDes& aBuf, TInt aType)
{
switch(aType)
{
case 1:
m_pEditName->GetText(aBuf);
break;
case 2:
m_pEditCode->GetText(aBuf);
break;
}
}
TBool CLogonContainer::IsConnectNet()
{
// NoteDialog
CAknQueryDialog* pdialog = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
TBool aResult=pdialog->ExecuteLD( R_QTN_FRMES_SHOW_CONNECT);
return(aResult);
}
TBool CLogonContainer::IsWaitLogin()
{
//waitDialog
TInt nmark = 0;
CAknWaitNoteWrapper* waitNoteWrapper = CAknWaitNoteWrapper::NewL();
CleanupStack::PushL(reinterpret_cast<CBase*>(waitNoteWrapper)); // Required reinterpret_cast as CAknWaitNoteWrapper inherits privately from CActive
if ( waitNoteWrapper->ExecuteL(R_FRMES_REGIST_DIALOG_WAIT, *this)) // this is a blocking call, remember the wrapper isn't a dialog, so it doesn't need the EEikDialogFlagWait flag to make it blocking
{
if(CancelWaitLogin())
{
nmark = 1;
}
}
CleanupStack::PopAndDestroy(waitNoteWrapper);
return (nmark == 1);
}
/**
* Called by the wait note wrapper when the note is dismissed.
* This is as a result of either the user cancelling the note,
* or the process finishing.
*/
void CLogonContainer::DialogDismissedL(TInt /*aButtonId*/)
{
}
/**
* Called by the wait note wrapper following StepL. Unless the user has cancelled the note,
* if this returns EFalse, it will call StepL again, otherwise, it will call ProcessFinished.
* @return ETrue if processing is complete, EFalse otherwise
*/
TBool CLogonContainer::IsProcessDone() const
{
if (m_nRes != KNumberBack) //是否收到成功的返回值
{
return (m_nStepsCompleted == KNumberOfStepsToSaveGame);
}
else
{
return TRUE;
}
/* return (m_nStepsCompleted == KNumberOfStepsToSaveGame);*/
}
/**
* Called by the wait note wrapper if the process is complete or if the user cancelled the note.
* Completes the game save and resets the steps completed counter.
*/
void CLogonContainer::ProcessFinished()
{
m_TimeWaster.Cancel();
m_nStepsCompleted = 0;
}
/**
* Called by the wait note wrapper if the processing is not yet complete.
* Completes a step in the processing, by saving part of the game to a file, and incrementing the
* number of steps completed. This is a synchronous method.
*/
void CLogonContainer::StepL()
{
// Use an arbitrary delay to simulate saving part of the game
TRequestStatus status;
TInt delay = 1000000; // 1 second
m_TimeWaster.After(status, delay);
User::WaitForRequest(status);
// Note that we have completed a step
m_nStepsCompleted++;
}
/**
* Dummy method which could be used to cancel a partially saved game, e.g.
* by resetting values and deleting the partially created file.
*/
TBool CLogonContainer::CancelWaitLogin()
{
if (m_nStepsCompleted != KNumberOfStepsToSaveGame)
{
return true;
}
else
{
return false;
}
}
void CLogonContainer::SetRes(TInt aRes)
{
m_nRes = aRes;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -