×
Namespaces

Variants
Actions

Archived:How to use CEikTextButton

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Code ExampleCompatibilityArticle
Created: savaj (10 Mar 2009)
Last edited: hamishwillee (29 Jun 2012)

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:

CEikTextButton(Clear).PNG CEikTextButton(Set).PNG

This page was last modified on 29 June 2012, at 04:53.
23 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×