You Are Here:

Community: Wiki

This page was last modified on 7 October 2009, at 21:53.

How to use CEikTextButton??

From Forum Nokia Wiki

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:

File:CEikTextButton(Clear).PNG File:CEikTextButton(Set).PNG

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia