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

📄 logincontainer.cpp

📁 symbian控件的利用
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CLoginContainer from CCoeControl, MCoeControlObserver
*  Part of  : Login
*  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 <AknNumSecEd.h>    // for numeric secret editor

#include <LDMCM8.rsg>
#include "LDMCM8.hrh"
#include "LoginContainer.h"

// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CLoginContainer::CLoginContainer():iLabelName(NULL), iLabelPWD(NULL), iEdwinName(NULL), iEdwinPWD(NULL)
    {
    }

// EPOC default constructor can leave.
void CLoginContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

	TBuf<50> text1;	
    iCoeEnv->ReadResource(text1, R_QTN_MCM_CLIENTNAME);
    iLabelName = new (ELeave) CEikLabel;
    iLabelName->SetContainerWindowL(*this);
    iLabelName->SetTextL(text1);
    iLabelName->SetExtent(TPoint(20, 30), iLabelName->MinimumSize());
	
	iEdwinName = new (ELeave) CEikEdwin(/*TGulBorder::ESingleBlack*/);
	iEdwinName->SetContainerWindowL(*this);
	iEdwinName->ConstructL(EEikEdwinNoAutoSelection | EEikEdwinIgnoreVirtualCursor, 10, 10, 1);
	iEdwinName->SetExtent(TPoint(80, 25), TSize(70, 20));

    TBuf<50> text2;
    iCoeEnv->ReadResource(text2, R_QTN_MCM_CLIENTPWD);
    iLabelPWD = new (ELeave) CEikLabel;
    iLabelPWD->SetContainerWindowL(*this);
    iLabelPWD->SetTextL(text2);
    iLabelPWD->SetExtent(TPoint(20, 60), iLabelPWD->MinimumSize());

	/******************************************
	 *
	 * NumericSecretEditor for pwd input 
	 * @ 2008-5-23 10:38 by Miserce
	 * @ ex from editor container23
	 *
	 ******************************************/
    TResourceReader reader1;
    iCoeEnv->CreateResourceReaderLC(reader1,
                                     R_QTN_MCM_NUMSECTET_COUNT);
    iEdwinPWD = new (ELeave) CAknNumericSecretEditor();
    iEdwinPWD->SetContainerWindowL(*this);
    iEdwinPWD->ConstructFromResourceL(reader1);
    CleanupStack::PopAndDestroy();  // Resource reader
    iEdwinPWD->SetExtent(TPoint(80, 55), TSize(70, 20));
	
	iEdwinName->SetFocus(ETrue);
	
// 
//     TBuf<KBufLength> text;
// 
//     iCoeEnv->ReadResource(text, R_AKNEXEDITOR_VIEW1_LABEL1);
//     iLabel1 = new (ELeave) CEikLabel;
//     iLabel1->SetContainerWindowL(*this);
//     iLabel1->SetTextL(text);
//     iLabel1->SetExtent(EDWIN_LABEL_POS, iLabel1->MinimumSize());
// 
//     iCoeEnv->ReadResource(text, R_AKNEXEDITOR_VIEW1_LABEL2);
//     iLabel2 = new (ELeave) CEikLabel;
//     iLabel2->SetContainerWindowL(*this);
//     iLabel2->SetTextL(text);
//     iLabel2->SetExtent(GTEXTED_LABEL_POS, iLabel1->MinimumSize());
// 
//     TResourceReader reader;
//     iCoeEnv->CreateResourceReaderLC(reader, R_AKNEXEDITOR_VIEW1_EDWIN);
//     iEdwin = new (ELeave) CEikEdwin;
//     iEdwin->SetContainerWindowL(*this);
//     iEdwin->ConstructFromResourceL(reader);
//     CleanupStack::PopAndDestroy();  // Resource reader
//     iEdwin->SetExtent(EDWIN_POS, iEdwin->MinimumSize());
// 
//     iCoeEnv->CreateResourceReaderLC(reader, R_AKNEXEDITOR_VIEW1_GTEXTED);
//     iGTextEd = new (ELeave) CEikGlobalTextEditor;
//     iGTextEd->SetContainerWindowL(*this);
//     iGTextEd->ConstructFromResourceL(reader);
//     CleanupStack::PopAndDestroy();  // Resource reader
//     iGTextEd->SetExtent(GTEXTED_POS, iGTextEd->MinimumSize());
// 
//     iEdwin->SetFocus(ETrue);

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CLoginContainer::~CLoginContainer()
    {
		if (iLabelName != NULL)
		{
			delete iLabelName;
		}
		if (iLabelPWD != NULL)
		{
			delete iLabelPWD;
		}
		if (iEdwinName != NULL)
		{
			delete iEdwinName;
		}
		if (iEdwinPWD != NULL)
		{
			delete iEdwinPWD;
		}
    }

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

void CLoginContainer::FocusTo(TInt aCommand)
    {
//     switch(aCommand)
//         {
//         case ELoginCmdSelectEdwin1:
//             iGTextEd->SetFocus(EFalse);
//             iEdwin->SetFocus(ETrue);
//             break;
//         case ELoginCmdSelectGTextEd1:
//             iEdwin->SetFocus(EFalse);
//             iGTextEd->SetFocus(ETrue);
//             break;
//         default:
//             break;
//         }
    }

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

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

// ---------------------------------------------------------
// CLoginContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CLoginContainer::ComponentControl(TInt aIndex) const
    {
	switch (aIndex)
	{
	case 0:
		return iLabelName;
 	case 1:
 		return iEdwinName;
 	case 2:
 		return iLabelPWD;
 	case 3:
 		return iEdwinPWD;
    default:
             return NULL;
         }
    }

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

// ---------------------------------------------------------
// CLoginContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CLoginContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType)
    {
	if (iEdwinName)
	{
		if (iEdwinName->IsFocused())
		{
			if ((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
			{
				iEdwinName->SetFocus(EFalse);
				iEdwinPWD->SetFocus(ETrue);
				return EKeyWasConsumed;
			}
			return iEdwinName->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	if (iEdwinPWD)
	{
		if (iEdwinPWD->IsFocused())
		{
			if ((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				iEdwinPWD->SetFocus(EFalse);
				iEdwinName->SetFocus(ETrue);
				return EKeyWasConsumed;
			}
			return iEdwinPWD->OfferKeyEventL(aKeyEvent, aType);
		}
	}
//     if (iEdwin)
//         {
//         if (iEdwin->IsFocused())
//             {
//             return iEdwin->OfferKeyEventL(aKeyEvent, aType);
//             }
//         }
//     if (iGTextEd)
//         {
//         if (iGTextEd->IsFocused())
//             {
//             return iGTextEd->OfferKeyEventL(aKeyEvent, aType);
//             }
//         }
    }

/*******************************
 * get editor info
 *******************************/
void CLoginContainer::GetInput(TDes& aBuf, TInt aType)
{
	switch(aType)
	{
	case 1:
		iEdwinName->GetText(aBuf);
		break;
	case 2:
		iEdwinPWD->GetText(aBuf);
	    break;
	}
}



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

// End of File  

⌨️ 快捷键说明

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