helloworldloccontainer.cpp

来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 134 行

CPP
134
字号
/**
* 
* @brief Definition of CHelloWorldLocContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "HelloWorldLocContainer.h"

// System includes
#include <eiklabel.h> // CEikLabel
#include <HelloWorldLoc.rsg> // Resource IDs
#include <stringloader.h> // StringLoader

// CONSTANTS

// N.B. #define'd as DLL cannot contain writeable static data
#define KLabelPosition TPoint(10,10) 

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

/**
* Symbian OS 2nd phase constructor.  Creates a Window for the controls, which it contains.
* Constructs a label and adds it to the window, which it then activates.
* @param aRect The rectangle for this window
*/        
void CHelloWorldLocContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
    
    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL(*this);
    
    HBufC* labelText;
    labelText = StringLoader::LoadLC(R_LABEL_TEXT);    // Pushes labelText onto the Cleanup Stack.
    iLabel->SetTextL(*labelText);
    CleanupStack::PopAndDestroy(labelText);
    
    SetRect(aRect);
    ActivateL();
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CHelloWorldLocContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @return The newly constructed CHelloWorldLocContainer
*/
CHelloWorldLocContainer* CHelloWorldLocContainer::NewL(const TRect& aRect)
{
    CHelloWorldLocContainer* self = CHelloWorldLocContainer::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CHelloWorldLocContainer using the constructor and ConstructL 
* method, leaving the constructed object on the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @return The newly constructed CHelloWorldLocContainer
*/
CHelloWorldLocContainer* CHelloWorldLocContainer::NewLC(const TRect& aRect)
{
    CHelloWorldLocContainer* self = new (ELeave) CHelloWorldLocContainer;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
}

/** 
* Destructor.  Frees up memory for the iLabel.
*/
CHelloWorldLocContainer::~CHelloWorldLocContainer()
{
    delete iLabel;
}

/**
*    
* Called by framework when the view size is changed.  Resizes the
* iLabel accordingly.
*
*/
void CHelloWorldLocContainer::SizeChanged()
{
    iLabel->SetExtent(KLabelPosition, iLabel->MinimumSize());
}

/**
* Called by the framework in compound controls    
* @return The number of controls in this CHelloWorldLocContainer
*/
TInt CHelloWorldLocContainer::CountComponentControls() const
{
    return 1; // return number of controls inside this container
}

/**
* Called by the framework in compound controls    
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CHelloWorldLocContainer::ComponentControl(TInt aIndex) const
{
    switch (aIndex)
    {
        case 0:
            return iLabel;
        default:
            return NULL;
    }
}

/**
* Called by the framework to draw this control.  Clears the area in 
* aRect.
* @param aRect in which to draw
*/
void CHelloWorldLocContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.Clear(aRect);
}

// End of File    

⌨️ 快捷键说明

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