Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2091299
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类:

2008-03-17 12:38:28


Tabs example

From Forum Nokia Wiki

The CTabsContainer illustrates how to use tabs to handle controls inside your container. This example implements two tabs. The arrow keys switch between the two tabs and the rest of the methods are handling the controls according to the tab's active index. You can modify the looks of the tabs by defining one of the following tab styles:

  • KTabWidthWithOneTab
  • KTabWidthWithThreeTabs
  • KTabWidthWithFourTabs
  • KTabWidthWithTwoLongTabs
  • KTabWidthWithThreeLongTabs

The SetMenuL() method shows how to swap between different menus according to the active tab.

Note that you need to add construction code for the iFirstControl & iSecondControl. You can implement them for example as , or .

Tabs_Container.cpp

CTabsContainer* CTabsContainer::NewL(CEikButtonGroupContainer* aCba)
{
CTabsContainer* self = CTabsContainer::NewLC(aCba);
CleanupStack::Pop();
return self;
}
 
CTabsContainer* CTabsContainer::NewLC(CEikButtonGroupContainer* aCba)
{
CTabsContainer* self = new (ELeave) CTabsContainer(aCba);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
CTabsContainer::CTabsContainer(CEikButtonGroupContainer* aCba) : iCba(aCba)
{
 
}
 
 
CTabsContainer::~CTabsContainer()
{
iTabGroup = NULL;

if (!iNaviPane)
{
CEikStatusPane *sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
iNaviPane = (CAknNavigationControlContainer*)
sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
}
 
if(iNaviPane)
iNaviPane->Pop(NULL);

iNaviPane = NULL;

delete iNaviDecoratorForTabs;
iNaviDecoratorForTabs = NULL;
delete iNaviDecorator;
iNaviDecorator = NULL;

delete iFirstControl;
delete iSecondControl;
}
 
void CTabsContainer::ConstructL(void)
{
CreateWindowL();
SetRect(CEikonEnv::Static()->EikAppUi()->ClientRect());

MakeNavipanelL();

// construct iFirstControl & iSecondControl in here..

ActivateL();
SetMenuL();
DrawNow();
}
 
_LIT(KtxTabText1 ,"Tab 1");
_LIT(KtxTabText2 ,"Tab 2");

void CTabsContainer::MakeNavipanelL(void)
{
CEikStatusPane *sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
iNaviPane = (CAknNavigationControlContainer*)
sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
 
CAknNavigationDecorator* iNaviDecoratorForTabsTemp;
iNaviDecoratorForTabsTemp = iNaviPane->CreateTabGroupL();
delete iNaviDecoratorForTabs;
iNaviDecoratorForTabs = NULL;
iNaviDecoratorForTabs = iNaviDecoratorForTabsTemp;
iTabGroup = STATIC_CAST(CAknTabGroup*,
iNaviDecoratorForTabs->DecoratedControl());
iTabGroup->SetTabFixedWidthL(KTabWidthWithTwoTabs);
 
iTabGroup->AddTabL(0,KtxTabText1);
iTabGroup->AddTabL(1,KtxTabText2);
 
iTabGroup->SetActiveTabByIndex(0);
iNaviPane->PushL(*iNaviDecoratorForTabs);
}
 
 
void CTabsContainer::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.Clear(Rect());
}
 
 
TKeyResponse CTabsContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aEventCode)
{
TKeyResponse Ret = EKeyWasNotConsumed;

switch (aKeyEvent.iCode)
{
case EKeyRightArrow:
if(iTabGroup)
{
TInt IndexNum = iTabGroup->ActiveTabIndex();
IndexNum = IndexNum + 1;

if(IndexNum > 1)
IndexNum = 1;

iTabGroup->SetActiveTabByIndex(IndexNum);

SetMenuL();
DrawNow();
}
break;
 
case EKeyLeftArrow:
if(iTabGroup)
{
TInt IndexNum = iTabGroup->ActiveTabIndex();
IndexNum = IndexNum - 1;

if(IndexNum < 0)
IndexNum = 0;

iTabGroup->SetActiveTabByIndex(IndexNum);

SetMenuL();
DrawNow();
}
break;
 
default:
if(iTabGroup)
{
switch(iTabGroup->ActiveTabIndex())
{
case 1:
if(iSecondControl)
{
Ret = iSecondControl->OfferKeyEventL(aKeyEvent,aEventCode);
}
break;
default:
if(iFirstControl)
{
Ret = iFirstControl->OfferKeyEventL(aKeyEvent,aEventCode);
}
break;
}
}
break;
}

return Ret;
}
 
 
void CTabsContainer::SetMenuL(void)
{
CEikonEnv::Static()->AppUiFactory()->MenuBar()->StopDisplayingMenuBar();
 
TInt MenuRes(R_MAIN_1_MENUBAR);
TInt ButtomRes(R_MAIN_1_CBA);
 
if(iTabGroup)
{
switch(iTabGroup->ActiveTabIndex())
{
case 1:
MenuRes = R_MAIN_1_MENUBAR;
ButtomRes(R_MAIN_1_CBA);
break;
case 2:
MenuRes = R_MAIN_2_MENUBAR;
ButtomRes(R_MAIN_2_CBA);
break;
default:
//R_MAIN_MENUBAR
break;
}
}

CEikonEnv::Static()->AppUiFactory()->MenuBar()->
SetMenuTitleResourceId(MenuRes);
 
if(iCba)
{
iCba->SetCommandSetL(ButtomRes);
iCba->DrawDeferred();
}
}
 
 
CCoeControl* CTabsContainer::ComponentControl( TInt /*aIndex*/) const
{
CCoeControl* RetCont(NULL);
 
if(iTabGroup)
{
switch(iTabGroup->ActiveTabIndex())
{
case 1:
RetCont = iSecondControl;
break;
default:
RetCont = iFirstControl;
break;
}
}

return RetCont;
}
 
TInt CTabsContainer::CountComponentControls() const
{
TInt RetCount(0);

if(iTabGroup)
{
switch(iTabGroup->ActiveTabIndex())
{
case 1:
if(iSecondControl)
{
RetCount = 1;
}
break;
default:
if(iFirstControl)
{
RetCount = 1;
}
break;
}
}
 
return RetCount;
}

Tabs_Container.h

class CTabsContainer : public CCoeControl
{
public:
static CTabsContainer* NewL(CEikButtonGroupContainer* aCba);
static CTabsContainer* NewLC(CEikButtonGroupContainer* aCba);
~CTabsContainer();
public:
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType);
CCoeControl* ComponentControl( TInt aIndex) const;
TInt CountComponentControls() const;
private:
void SetMenuL(void);
void MakeNavipanelL(void);
CTabsContainer(CEikButtonGroupContainer* aCba);
void ConstructL(void);
void Draw(const TRect& aRect) const;
private:
CEikButtonGroupContainer* iCba;
CAknTabGroup* iTabGroup;
CAknNavigationControlContainer* iNaviPane;
CAknNavigationDecorator* iNaviDecorator;
CAknNavigationDecorator* iNaviDecoratorForTabs;
CCoeControl* iFirstControl;
CCoeControl* iSecondControl;
};

Also see


from ""
阅读(2193) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~