⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registercontainer.cpp

📁 symbian 3nd 实现短信息收发
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CRegisterContainer from CCoeControl, MCoeControlObserver
*  Part of  : Register
*  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 "RegisterContainer.h"

#include <eikseced.h>       // for secret editor
#include <AknNumSecEd.h>    // for numeric secret editor

const TInt KNumberOfStepsToSaveGame(10);
const TInt KNumberBack = 200;
// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CRegisterContainer::CRegisterContainer()
{
	m_pLabelName = NULL;
	m_pLabelCode = NULL;
	m_pLabelConfirm = NULL;
	
	m_pEditName = NULL;
	m_pEditCode = NULL;
	m_pEditConfirm = NULL;
	m_nStepsCompleted = 0;
	m_nRes = 0;
}

// EPOC default constructor can leave.
void CRegisterContainer::ConstructL(const TRect& aRect)
{
	m_TimeWaster.CreateLocal();
	CreateWindowL();
	
	//label sName
	TBuf<32> sName;	
	iCoeEnv->ReadResource(sName, R_QTN_FRMES_LABEL_RVIEW_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));
	
	//label sConfirm
	TBuf<32> sConfirm;	
	iCoeEnv->ReadResource(sConfirm, R_QTN_FRMES_LABEL_VIEW_CPWD);
	m_pLabelConfirm = new (ELeave) CEikLabel;
	m_pLabelConfirm->SetContainerWindowL(*this);
	m_pLabelConfirm->SetTextL(sConfirm);
	m_pLabelConfirm->SetExtent(TPoint(10, 90), m_pLabelConfirm->MinimumSize());
	
	//edit sConfirm rss
	TResourceReader readerConfirm;
	iCoeEnv->CreateResourceReaderLC(readerConfirm,
		R_QTN_FRMES_NUM_CODE_COUNT);
	m_pEditConfirm = new (ELeave) CAknNumericSecretEditor();
	m_pEditConfirm->SetContainerWindowL(*this);
	m_pEditConfirm->ConstructFromResourceL(readerConfirm);
	CleanupStack::PopAndDestroy();  // Resource reader
	m_pEditConfirm->SetExtent(TPoint(80, 85), TSize(70, 20));
	
	m_pEditName->SetFocus(ETrue);
	SetRect(aRect);
	ActivateL();
}

// Destructor
CRegisterContainer::~CRegisterContainer()
{
	if(m_pLabelName)
	{
		delete m_pLabelName;
		m_pLabelName = NULL;
	}
	if(m_pLabelCode)
	{
		delete m_pLabelCode;
		m_pLabelCode = NULL;
	}
	if(m_pLabelConfirm)
	{
		delete m_pLabelConfirm;
		m_pLabelConfirm = NULL;
	}
	if(m_pEditName)
	{
		delete m_pEditName;
		m_pEditName = NULL;
	}
	if(m_pEditCode)
	{
		delete m_pEditCode;
		m_pEditCode = NULL;
	}
	if(m_pEditConfirm)
	{
		delete m_pEditConfirm;
		m_pEditConfirm = NULL;
	}
	m_TimeWaster.Close();
}

// ---------------------------------------------------------
// CRegisterContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//

void CRegisterContainer::FocusTo(TInt aCommand)
{
}

// ---------------------------------------------------------
// CRegisterContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CRegisterContainer::SizeChanged()
{
}

// ---------------------------------------------------------
// CRegisterContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CRegisterContainer::CountComponentControls() const
{
    return 6; // return nbr of controls inside this container
}

// ---------------------------------------------------------
// CRegisterContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CRegisterContainer::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;
				
			case 4:
				return m_pLabelConfirm;
				break;
				
			case 5:
				return m_pEditConfirm;
				break;
				
			default:
				return NULL;
				break;
	}
}

// ---------------------------------------------------------
// CRegisterContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CRegisterContainer::Draw(const TRect& aRect) const
{
	CWindowGc& gc = SystemGc();
	gc.SetPenStyle(CGraphicsContext::ENullPen);
	gc.SetBrushColor(KRgbRed);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.DrawRect(aRect);
}

// ---------------------------------------------------------
// CRegisterContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CRegisterContainer::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)
			{
				if(aKeyEvent.iCode == EKeyUpArrow)
				{
					m_pEditCode->SetFocus(EFalse);
					m_pEditName->SetFocus(ETrue);
					return EKeyWasConsumed;	
				}
				if(aKeyEvent.iCode == EKeyDownArrow)
				{
					m_pEditCode->SetFocus(EFalse);
					m_pEditConfirm->SetFocus(ETrue);
					return EKeyWasConsumed;	
				}
			}
			return m_pEditCode->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	
	if (m_pEditConfirm)
	{
		if (m_pEditConfirm->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				m_pEditConfirm->SetFocus(EFalse);
				m_pEditCode->SetFocus(ETrue);
				return EKeyWasConsumed;
			}
			return m_pEditConfirm->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	return EKeyWasNotConsumed;	
	
}


// ---------------------------------------------------------
// CRegisterContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CRegisterContainer::HandleControlEventL(
											 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}

void CRegisterContainer::GetInput (TDes& aBuf, TInt aType)
{
	switch(aType)
	{
	case 1:
		m_pEditName->GetText(aBuf);
		break;
	case 2:
		m_pEditCode->GetText(aBuf);
		break;
	case 3:
		m_pEditConfirm->GetText(aBuf);
		break;
	}
}

TBool CRegisterContainer::IsConnectNet()	
{
	// NoteDialog
	CAknQueryDialog* pdialog = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
	TBool aResult=pdialog->ExecuteLD( R_QTN_FRMES_SHOW_CONNECT);
	return(aResult);
}

TBool CRegisterContainer::IsWaitRegister()
{
	//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(CancelWaitRegister())
		{
			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 CRegisterContainer::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 CRegisterContainer::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 CRegisterContainer::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 CRegisterContainer::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 CRegisterContainer::CancelWaitRegister()
{
	if (m_nStepsCompleted != KNumberOfStepsToSaveGame)
	{
		return true;
	}
	else
	{
		return false;
	}
}

void CRegisterContainer::SetRes(TInt aRes)
{
	m_nRes = aRes;
}



// End of File  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -