compoundcontrol.cpp

来自「最新官方例子,图形,描述副,基本控件,通讯协议,等等,」· C++ 代码 · 共 159 行

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

// INCLUDES

//  Class include
#include "CompoundControl.h"

// System includes

// User includes
#include "SimpleControl.h"

// CONSTANTS

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

/**
* Symbian OS 2 phase constructor.
* Constructs the CCompoundControl 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 CCompoundControl
*/
CCompoundControl* CCompoundControl::NewL(const TRect& aRect, const CCoeControl* aParent)
	{
	CCompoundControl* self = CCompoundControl::NewLC(aRect, aParent);
	CleanupStack::Pop(self);
	return self;
	}

/**
* Symbian OS 2 phase constructor.
* Constructs the CCompoundControl 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 CCompoundControl
*/
CCompoundControl* CCompoundControl::NewLC(const TRect& aRect, const CCoeControl* aParent)
	{
	CCompoundControl* self = new (ELeave) CCompoundControl;
	CleanupStack::PushL(self);
	self->ConstructL(aRect, aParent);
	return self;
	}

/**
* 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 CCompoundControl::ConstructL(const TRect& aRect, const CCoeControl* aParent)
	{
    if (aParent == NULL)
        {
    	CreateWindowL();
        }
    else
        {
        SetContainerWindowL(*aParent);
        }

    // Size and construct the two component controls
    CalculateRects();
    iTop = CSimpleControl::NewL(iTopRect, this);
    iBottom = CSimpleControl::NewL(iBottomRect, this);

	SetRect(aRect);
	ActivateL();
	}

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

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

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

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

/**
*
* Called by framework when the view size is changed.  Resizes the
* iLabel accordingly.
*
*/
void CCompoundControl::SizeChanged()
	{
    CalculateRects();
    iTop->SetRect(iTopRect);
    iBottom->SetRect(iBottomRect);
	}


void CCompoundControl::CalculateRects()
    {
    TRect outerRect = Rect();

    // Calculate dimensions of inner rectangles
    const TInt innerRectWidth = outerRect.Width();
    const TInt innerRectHeight = outerRect.Height() / 2;

    // Set rectangle for top control
    iTopRect.SetRect(outerRect.iTl, TSize(innerRectWidth, innerRectHeight));
    
    // Set bottom rectangle. Easiest way is to copy the top
    // rectangle then move it down by innerRectHeight:
    iBottomRect = iTopRect;
    iBottomRect.Move(0, innerRectHeight);
    }


// End of File

⌨️ 快捷键说明

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