worldcontainer.cpp

来自「symbian 二版本的自定义控件」· C++ 代码 · 共 119 行

CPP
119
字号

#include <gulicon.h>
#include <aknutils.h>    // definition of AKN_LAF_COLOR()
#include <avkon.hrh>
#include <akntitle.h>
#include <aknnotewrappers.h>
#include "TreeAppUi.h"
#include "WorldContainer.h"


//////////////////////////////////////////////////////////////////////////
CWorldContainer::CWorldContainer()
{
}

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

	iTree = new(ELeave) CNDTree;
	iTree->SetContainerWindowL(*this);

	CTreeAppUi* pApp = (CTreeAppUi*)CEikonEnv::Static()->AppUi();
	CFbsBitmap* fold = pApp->LoadGraphicsL(0);
	CFbsBitmap* spread = pApp->LoadGraphicsL(1);
	CFbsBitmap* shrink = pApp->LoadGraphicsL(2);
	iTree->ConstructL(fold,spread,shrink);

	CTreeNode* node = CTreeNode::NewL();
	node->SetContent(_L("root1"));
	iTreeArray.Append(node);

	node = CTreeNode::NewL();
	node->SetContent(_L("root2"));
	iTreeArray.Append(node);

	node = CTreeNode::NewL();
	node->SetContent(_L("root3"));
	iTreeArray.Append(node);

	node = CTreeNode::NewL();
	node->SetContent(_L("root4"));
	iTreeArray.Append(node);

	iTree->SetNodeArray(iTreeArray);

    SetRect( aRect );
    ActivateL();
}

// destructor
CWorldContainer::~CWorldContainer()
{
	if (iTree)
	{
		delete iTree;
		iTree = NULL;
	}
	iTreeArray.ResetAndDestroy();
}

void CWorldContainer::SizeChanged()
{
	if(iTree)
	{
		iTree->SetRect(Rect());
	}
}

// ---------------------------------------------------------
// CWorldContainer::CountComponentControls() const
// return the number of controls
// ---------------------------------------------------------
//
TInt CWorldContainer::CountComponentControls() const
{
	// return number of controls inside this container
	return 1; 
}

// ---------------------------------------------------------
// CWorldContainer::ComponentControl(TInt aIndex) const
// return the pointer to specified control.
// ---------------------------------------------------------
//
CCoeControl* CWorldContainer::ComponentControl( TInt /*aIndex*/ ) const
{
	return iTree;
}

// ---------------------------------------------------------
// CWorldContainer::Draw(const TRect& aRect) const
// handle the message when client region must be redrawn.
// ---------------------------------------------------------
//
void CWorldContainer::Draw( const TRect& /*aRect*/ ) const
{
	CWindowGc& gc = SystemGc();
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.SetBrushColor(KRgbBlack);
	gc.DrawRect(Rect());
}

// ---------------------------------------------------------
// CAknExGridContainer::OfferKeyEventL(
//           const TKeyEvent& aKeyEvent, TEventCode aType )
// Handles the key events.
// ---------------------------------------------------------
//
TKeyResponse CWorldContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
	return iTree->OfferKeyEventL(aKeyEvent,aType);
	return EKeyWasConsumed;
}



⌨️ 快捷键说明

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