Class CEikTextButton provides functionality to create button on S60 3rd Edition phones. This is a simple control like CEikEdwin and CEikLabel and you can implement it in your container as follows.
Header Required:
#include <eikcmbut.h>
Library needed:
LIBRARY avkon.lib eikcoctl.lib
Required capabilities:
None
Change in header file.
//Derive your container/View class from MCoeControlObserver.
//override following functions.
protected:
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
protected: // MCoeControlObserver
void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
Change in .cpp file.
void CHelloWorldAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
// iButtonControl is pointer of type CEikTextButton;
iButtonControl = new(ELeave) CEikTextButton;
iButtonControl->SetContainerWindowL(*this);
_LIT(KText, "Testing Button");
iButtonControl->SetTextL(KText);
iButtonControl->SetFocus(ETrue);
iButtonControl->SetObserver(this);
iButtonControl->SetRect(TRect(5,5,250,50)); //or u can set it in your SizeChanged() method.
SetRect(aRect);
ActivateL();
}
TInt CHelloWorldAppView::CountComponentControls() const
{
return 1;
}
CCoeControl* CHelloWorldAppView::ComponentControl(TInt aIndex) const
{
switch(aIndex)
{
case 0:
{
return iButtonControl;
break;
}
default:
{
break;
}
}
}
TKeyResponse CHelloWorldAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
TKeyResponse response = EKeyWasNotConsumed;
if((iButtonControl)&&(aKeyEvent.iScanCode==167))
{
response = EKeyWasConsumed;
CEikButtonBase::TState state = CEikButtonBase::ESet;
if(aType==EEventKeyDown)
{
state = CEikButtonBase::ESet;
}
else if(aType==EEventKeyUp)
{
state = CEikButtonBase::EClear;
}
iButtonControl->SetState(state);
iButtonControl->DrawDeferred();
}
if(response == EKeyWasNotConsumed)
{
response = CCoeControl::OfferKeyEventL(aKeyEvent, aType);
}
return response;
}
// MCoeControlObserver
void CHelloWorldAppView::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
if((aControl==iButtonControl)&&(aEventType==EEventStateChanged))
{
CEikButtonBase::TState state = iButtonControl->State();
}
}
Source Code:
Full example: Helloworldbasic(CEikTextButton).zip
Note: the CEikTextButton seems not working well with touch operations, so I extended it a little bit to support both confirm key events and pointer events, see the new example: Helloworldbasic(MyTextButton).zip
Screenshots:
No related wiki articles found