复合控件的练习
练习了一下复合控件,其实就是用传统编程模式下添加 CEikLable ,CEikEdwin,CEikTextListBox 控件
对于 CEikLable和CEikTextListBox 没有用到资源文件,CEikEdwin 用的是资源文件,对于读写 CEikTextListBox 是新的知识,及移动
CEikEdwin 与 CEikTextListBox 控件的焦点
代码:头文件
#ifndef STACKCONTAINER_H
#define STACKCONTAINER_H
// INCLUDES
#include <coecntrl.h>
// FORWARD DECLARATIONS
class CEikLabel; // for example labels
class CEikEdwin;
class CEikTextListBox;
// CLASS DECLARATION
/**
* CStackContainer container control class.
*
*/
class CStackContainer : public CCoeControl, MCoeControlObserver
{
public: // Constructors and destructor
/**
* EPOC default constructor.
* @param aRect Frame rectangle for container.
*/
void ConstructL(const TRect& aRect);
/**
* Destructor.
*/
~CStackContainer();
public: // New functions
public: // Functions from base classes
private: // Functions from base classes
/**
* From CoeControl,SizeChanged.
*/
void SizeChanged();
/**
* From CoeControl,CountComponentControls.
*/
TInt CountComponentControls() const;
/**
* From CCoeControl,ComponentControl.
*/
CCoeControl* ComponentControl(TInt aIndex) const;
/**
* From CCoeControl,Draw.
*/
void Draw(const TRect& aRect) const;
/**
* From MCoeControlObserver
* Acts upon changes in the hosted control's state.
*
* @param aControl The control changing its state
* @param aEventType The type of control event
*/
void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
public:
void HandleCommandL(TInt aCommand);
private: //data
CEikLabel* iLPop; // example label
CEikLabel* iLPush; // example label
CEikLabel* iLContent;
CEikEdwin* iPushNumber;
CEikTextListBox* iListBox;
};
#endif
// End of File |
代码文件:
/*
* ============================================================================
* Name : CStackContainer from StackContainer.h
* Part of : Stack
* Created : 11.05.2010 by
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version :
* Copyright:
* ============================================================================
*/
// INCLUDE FILES
#include "StackContainer.h"
#include <eiklabel.h> // for example label control
#include <eikedwin.h>
#include <Stack.rsg>
#include <coemain.h>
#include <aknlists.h>
#include <barsread.h>
#include <badesca.h> // CDesCArrayFlat
#include <e32keys.h>
#include <eikmsg.h> // iEikonEnv
#include <Stack.hrh>
#include <eiklbv.h>
#define push_label TPoint(5,5)
#define pop_label TPoint(5,35)
#define push_edit TPoint(88,5)
#define pop_content TPoint(88,35)
#define list_pos TPoint(0,60)
#define text_size TSize(60,20)
#define listbox_size TSize(176,80)
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CStackContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CStackContainer::ConstructL(const TRect& aRect)
{
}
// Destructor
CStackContainer::~CStackContainer()
{
}
// ---------------------------------------------------------
// CStackContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CStackContainer::SizeChanged()
{
}
// ---------------------------------------------------------
// CStackContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CStackContainer::CountComponentControls() const
{
return 5; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CStackContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CStackContainer::ComponentControl(TInt aIndex) const
{
}
// ---------------------------------------------------------
// CStackContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CStackContainer::Draw(const TRect& aRect) const
{
}
// ---------------------------------------------------------
// CStackContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CStackContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
TKeyResponse CStackContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (aType != EEventKey )
{
return EKeyWasNotConsumed;
}
}
return EKeyWasNotConsumed;
}
void CStackContainer::HandleCommandL(TInt aCommand)
{
}
// End of File
|
其中对于 HandleCommand 是要在 AppUi 中的 handleCommand 来调用的
如下所示:
void CStackAppUi::HandleCommandL(TInt aCommand)
{
}
|
安平2009@原创
qi_jianzhou@126.com