Статья базируется на материалах англоязычной части Wiki, все они перечислены в разделе ссылки.
Generic Button API это новый компонент пользовательского интерфейса S60 5-го издания, представляющий собой кнопку произвольных размеров с поддержкой функционала сенсорного интерфейса. В данной статье мы рассмотрим пример работы с этим API.
...
#include <avkon.mbg>
//Ресурсы, описывающие кнопки
RESOURCE AVKON_BUTTON r_first_button
{
flags = KAknButtonTextInsideFrame;
states =
{
AVKON_BUTTON_STATE
{
helptxt = "First";
bmpfile = AVKON_BITMAP_FILE;
bmpid = EMbmAvkonQgn_note_query;
bmpmask = EMbmAvkonQgn_note_query_mask;
},
AVKON_BUTTON_STATE
{
flags = KAknButtonStateHasLatchedFrame;
bmpfile = AVKON_BITMAP_FILE;
bmpid = EMbmAvkonQgn_note_query;
bmpmask = EMbmAvkonQgn_note_query_mask;
}
};
}
RESOURCE AVKON_BUTTON r_second_button
{
flags = KAknButtonTextInsideFrame;
states =
{
AVKON_BUTTON_STATE
{
txt = "NoIcon";
helptxt = "Second";
},
AVKON_BUTTON_STATE
{
flags = KAknButtonStateHasLatchedFrame;
txt = "Pressed!";
helptxt = "Second";
}
};
}
...
#include <aknbutton.h>
class CUsingButtonsAPIAppView : public CCoeControl, public MCoeControlObserver
{
....
....
//From MCoeControlObserver
virtual void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
void CreateButtonUsingResourceL();
void CreateButtonRuntimeL();
private:
CAknButton* iFirstButton;
CAknButton* iSecondButton;
};
// -----------------------------------------------------------------------------
// CUsingButtonsAPIAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CUsingButtonsAPIAppView::ConstructL(const TRect& aRect)
{
// Создаем окно
CreateWindowL();
// Устанавливаем размеры окна
SetRect(aRect);
CreateButtonUsingResourceL();
// CreateButtonRuntimeL();
// Активизируем окно
ActivateL();
}
void CUsingButtonsAPIAppView::CreateButtonUsingResourceL()
{
iFirstButton = CAknButton::NewL();
iFirstButton->ConstructFromResourceL(R_FIRST_BUTTON);
iFirstButton->SetContainerWindowL(*this);
iFirstButton->SetRect(TRect ( TPoint(20,180), TSize(150,100) ) );
iFirstButton->SetObserver(this);
iFirstButton->MakeVisible(ETrue);
iFirstButton->ActivateL();
iSecondButton = CAknButton::NewL();
iSecondButton->ConstructFromResourceL(R_SECOND_BUTTON);
iSecondButton->SetContainerWindowL(*this);
iSecondButton->SetRect(TRect ( TPoint(160,180), TSize(150,100) ) );
iSecondButton->SetObserver(this);
iSecondButton->MakeVisible(ETrue);
iSecondButton->ActivateL();
}
void CUsingButtonsAPIAppView::HandleControlEventL( CCoeControl* aControl,
TCoeEvent aEventType )
{
switch ( aEventType )
{
case EEventStateChanged:
{
if(aControl == iFirstButton)
{
if(iSecondButton->State()->Flags()==KAknButtonStateHasLatchedFrame)
{
iSecondButton->SetCurrentState(KAknButtonTextInsideFrame,ETrue);
}
}
else if(aControl ==iSecondButton)
{
if(iFirstButton->State()->Flags()==KAknButtonStateHasLatchedFrame)
{
iFirstButton->SetCurrentState(KAknButtonTextInsideFrame,ETrue);
}
}
}
break;
default:
break;
}
}
TInt CUsingButtonsAPIAppView::CountComponentControls() const
{
return 2; // возвращаем число компонентов в контейнере
}
CCoeControl* CUsingButtonsAPIAppView::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iFirstButton;
case 1:
return iSecondButton;
default:
return NULL;
}
}
// -----------------------------------------------------------------------------
// CUsingButtonsAPIAppView::~CUsingButtonsAPIAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CUsingButtonsAPIAppView::~CUsingButtonsAPIAppView()
{
delete iFirstButton;
delete iSecondButton;
....
....
}
void CUsingButtonsAPIAppView::CreateButtonRuntimeL()
{
_LIT(KFirstButtonText,"First");
_LIT(KFirstButtonHelpText,"Help First Button");
iFirstButton = CAknButton::NewL(NULL,NULL,NULL,NULL,KFirstButtonText,KFirstButtonHelpText,0,0);
iFirstButton->SetContainerWindowL(*this);
iFirstButton->SetRect(TRect ( TPoint(20,180), TSize(150,100) ) );
iFirstButton->SetObserver(this);
iFirstButton->MakeVisible(ETrue);
iFirstButton->ActivateL();
_LIT(KSecondButtonText,"Second");
_LIT(KSecondButtonHelpText,"Help Second Button");
iSecondButton = CAknButton::NewL(NULL,NULL,NULL,NULL,KSecondButtonText,KSecondButtonHelpText,0,0);
iSecondButton->SetContainerWindowL(*this);
iSecondButton->SetRect(TRect ( TPoint(160,180), TSize(150,100) ) );
iSecondButton->SetObserver(this);
iSecondButton->MakeVisible(ETrue);
iSecondButton->ActivateL();
}
При подготовке статьи использованы следующие материалы:
No related wiki articles found