Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2108739
  • 博文数量: 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:34:17

Creating tab group control from resource

The first step of creating a tab group is to specify the status pane and the navigation pane decorator resources. Status pane's ID and type field values are defined in avkon.hrh. Decorator's resource type is defined as ENaviDecoratorControlTabGroup since the decorator will contain a label control, tab_width field specifies how many tabs are visible on the tab group. This value can be:

  • EAknTabWidthWithTwoTabs
  • EAknTabWidthWithTwoLongTabs
  • EAknTabWidthWithThreeTabs
  • EAknTabWidthWithThreeLongTabs
  • EAknTabWidthWithFourTabs
  • EAknTabWidthWithOneTab

The id field of TAB is defined in the application's HRH file.

RESOURCE EIK_APP_INFO
{
status_pane = r_app_status_pane;
}

RESOURCE STATUS_PANE_APP_MODEL r_app_status_pane
{
panes=
{
SPANE_PANE
{
id = EEikStatusPaneUidNavi;
type = EAknCtNaviPane;
resource = r_navi_decorator;
}
};
}

RESOURCE NAVI_DECORATOR r_navi_decorator
{
type = ENaviDecoratorControlTabGroup;
control = TAB_GROUP
{
tab_width = EAknTabWidthWithTwoTabs;
active = 0;
tabs = {
TAB
{
id = EAppView1Tab;
txt = "View1";
},
TAB
{
id = EAView2Tab;
txt = "View2";
}
};
};
}

Accessing tab group control created from resource

This example shows how to get the tab group object that was constructed from resources as described earlier. iDecorator is a pointer to CAknNavigationDecorator, iTabGroup is a pointer to CAknTabGroup.

// Get the decorator constructed from resource
iDecorator = iNaviPane->ResourceDecorator();
// Get the tab group from decorator
iTabGroup = (CAknTabGroup*)iDecorator->DecoratedControl();
// Add new tab to tabbgroup
iTabGroup->AddTabL(1,_L("NewTab") );

Creating tab group control dynamically from resource

You need to define tab group control in the resource file as follows.

RESOURCE NAVI_DECORATOR r_navi_decorator2
{
type = ENaviDecoratorControlTabGroup;
control = TAB_GROUP
{
tab_width = EAknTabWidthWithTwoTabs;
active = 0;
tabs = {
TAB
{
id = EAhdemoappView1Tab;
txt = "ResView1";
},
TAB
{
id = EAhdemoappView2Tab;
txt = "ResView2";
}
};
};

A tab group resource identifier can directly be passed to CreateResourceReaderLC(), a new navigation pane decorator object is created by ConstructNavigationDecoratorFromResourceL(), and the created decorator, that contains the tab group control is pushed to the navigation pane, so it becomes visible on the pane. In the following example iDecorator is a pointer to CAknNavigationDecorator, and iNaviPane is a pointer to CAknNavigationControlContainer. This way multiple navigation pane decorators can be defined in the resource file, which contains tab group controls.

TResourceReader reader;

// Read the resource
iEikonEnv->CreateResourceReaderLC( reader, R_AHDEMO_NAVI_DECORATOR2 );

// Construct the decorator from resource
iDecorator = iNaviPane->ConstructNavigationDecoratorFromResourceL( reader );
// Destroy the object that was put on CleanupStack by
// CreateResourceReaderLC()
CleanupStack::PopAndDestroy();

// Display the tab group on navigation pane
iNaviPane->PushL( *iDecorator );

Creating tab group control dynamically

First a tab group is created, then navigation pane decorator object is created with the tab group. The decorator must be pushed to the navigator pane. Note: SetActiveTabByIndex() must be called to make tab group visible. In the following example iDecorator is a pointer to CAknNavigationDecorator, iNaviPane is a pointer to CAknNavigationControlContainer and iTabGroup is a pointer to CAknTabGroup.

// Create tab group
iTabGroup = CAknTabGroup::NewL( *iNaviPane );
// Set tab width
iTabGroup->SetTabFixedWidthL ( EAknTabWidthWithTwoLongTabs );
// Add tabs to tab group
iTabGroup->AddTabL(0,_L("Tab1") );
iTabGroup->AddTabL(1,_L("Tab2") );
// Create a navipane decorator containing the tab group
iDecorator = CAknNavigationDecorator::NewL( iNaviPane, iTabGroup, CAknNavigationDecorator::ETabGroup );
iNaviPane->PushL( *iDecorator );
// Activate the first tab
iTabGroup->SetActiveTabByIndex(0);

Creating a pre-implemented tab group

Decorator and the required tab group control can be created easily with method CAknNavigationControlContainer::CreateTabGroupL(). In the following example iDecorator is a pointer to CAknNavigationDecorator, iNaviPane is a pointer to CAknNavigationControlContainer and iTabGroup is a pointer to CAknTabGroup.

// Create the decorator and the tab group control
iDecorator = iNaviPane->CreateTabGroupL(this);
iTabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl();
// Set tab width
iTabGroup->SetTabFixedWidthL ( EAknTabWidthWithTwoLongTabs );
// Add tabs to tab group
iTabGroup->AddTabL(0,_L("Tab1") );
iTabGroup->AddTabL(1,_L("Tab2") );
// Activate the first tab
iTabGroup->SetActiveTabByIndex(0);

Modifying tabs of tab group control

Tabs in tab group can be accessed by ID, or index. Index is the position of the tab in the tab group. Tab indexes are zero based. Tab ID can be any integer value. In the following example iTabGroup is a pointer to CAknTabGroup. Note: SetActiveTabByIndex() or SetActiveTabById() method must be called after adding the tabs, to make the tab group visible.

Adds a tab to a tab group with text.

enum TabId
{
ETabFirst,
ETabSecond,
ETabThird
};

iTabGroup->AddTabL( ETabFirst,_L( "Tab1" ) );
iTabGroup->AddTabL( ETabSecond,_L( "Tab2" ) );
iTabGroup->SetActiveTabByIndex(ETabFirst );

Adds a tab to the tab group with text and image.

CFbsBitmap* bitmap1 = iEikonEnv->CreateBitmapL( _L( "c:\image.mbm" ), 0 );
CFbsBitmap* bitmap2 = iEikonEnv->CreateBitmapL( _L( "c:\image.mbm" ), 1 );
iTabGroup->AddTabL( ETabFirst, _L("tab1" ), bitmap1 );
iTabGroup->AddTabL( ETabSecond, _L("tab2" ), bitmap2 );

Replaces a tab with a new tab at tab with ID: ETabThird.

iTabGroup->ReplaceTabL ( ETabThird, _L( "NewTab" ) );

Deletes a tab at tab with ID: ETabThird.

iTabGroup->ReplaceTabL ( ETabThird, _L( "NewTab" ) );

Activates a tab with ID: ETabThird.

iTabGroup->SetActiveTabById( ETabThird );

Gets the ID of the active tab.

TInt actveTabId = iTabGroup->ActiveTabId();
if ( actveTabId == ETabThird )
{
// your code here…
}

Gets the index of tab with ID: ETabThird.

TInt tabIndex = iTabGroup->TabIndexFromId ( ETabThird );
if (tabIndex == 2 )
{
// your code here…
}

Gets the IDof tab from index.

TInt tabId = iTabGroup->TabIdFromIndex( 2 );
if ( tabId == ETabThird )
{
// your code here…
}

Dims tab with ID: ETabThird.

iTabGroup->DimTab( ETabThird, ETrue );

Gets the number of tabs in tab group.

TInt numOfTabs = iTabGroup-> TabCount();

Observing tab group control events

There are two types of tab group events: tab events, and tab navigation events.

Tab events

This requires that the observing class must be derived from MAknTabObserver, and the observer must implement the method TabChangedL(). This event notifies the observer that the active tab has changed.

In the example, CMyAppUi observes the tab events.

class CMyAppUi : public CAknViewAppUi, MAknTabObserver
{

// From MAknTabObserver
void TabChangedL( TInt aIndex );

};

In the following example, tab group has been defined in resources. So this tab group is accessed and then observer is registered. iDecorator is a pointer to CAknNavigationDecorator and iTabGroup is a pointer to CAknTabGroup.

void CMyAppUi::Construct()
{

// Get the decorator from resource
iDecorator = iNaviPane->ResourceDecorator();
if ( iDecoratedTabGroup )
{
// Get the tab group from decorator
iTabGroup = ( CAknTabGroup* )iDecoratedTabGroup
->DecoratedControl();
}

// Register this object as a tab observer
iTabGroup->SetObserver( this );

}

The TabChangedL() method receives tab events.

void CMyAppUi::TabChangedL( TInt aIndex )
{
// Do event handling code here…
}

Tab navigation events

The observer class must be derived from MCoeControlObserver, and the observer must implement the method HandleControlEventL(). This event notifies the observer about the position of the current tab in the tab group. The events are:

  • ENaviEventHandleNavigation
  • ENaviEventLeftMostItemReached
  • ENaviEventRightMostItemReached
  • ENaviEventOneItemExists
  • ENaviEventRedrawNeeded
  • ENaviEventAlreadyLeftmostItem
  • ENaviEventAlreadyRightmostItem

In the example, CMyAppUi observes the tab events.

class CMyAppUi : public CAknViewAppUi, MCoeControlObserver
{

// From MCoeControlObserver
void HandleControlEventL( CCoeControl* aControl, TCoeEvent aEventType );

};

The following example accesses the tab group defined in resource, and then registers the observer. iDecorator is a pointer to CAknNavigationDecorator and iTabGroup is a pointer to CAknTabGroup. The observer is registered in the base class of the tab group.

void CMyAppUi::Construct()
{

// Get the decorator from resource
iDecorator = iNaviPane->ResourceDecorator();
if ( iDecoratedTabGroup )
{
// Get the tab group from decorator
iTabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl();
}

// Register this object in the base class as a tab event observer
CCoeControl* baseControl = ( CCoeControl* )iTabGroup;
baseControl->SetObserver( ( MCoeControlObserver* )this );

}

HandleControlEventL() receives tab navigation events.

void CMyAppUi:: HandleControlEventL( CCoeControl* /*aControl*/,TCoeEvent aEventType )
{
switch (aEventType)
{
case MAknNavigationObserver::ENaviEventLeftMostItemReached:

// Do event handling code here…

break;
default:
break;
}

Error handling

Tabs API uses the standard Symbian OS error reporting mechanism. Possible panic circumstances and panic codes are indicated in class or method descriptions.

Memory overhead

The amount of reserved memory for application owned tab group controls depend on the application, but despite the application the amount of reserved memory is relatively small.

Limitations of the API

None.


Copyright © Nokia Corporation 2001-2007
阅读(2014) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~