Tabs API: Using Tabs API
来源:互联网 发布:手机跟踪定位器软件 编辑:程序博客网 时间:2024/06/13 23:58
Tabs API: Using Tabs API - Creating tab group control from resource
- Accessing tab group control created from resource
- Creating tab group control dynamically from resource
- Creating tab group control dynamically
- Creating a pre-implemented tab group
- Modifying tabs of tab group control
- Observing tab group control events
- Tab events
- Tab navigation events
- Error handling
- Memory overhead
- Limitations of the API
- Accessing tab group control created from resource
- Tab events
- Tab navigation events
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 resourceiDecorator = iNaviPane->ResourceDecorator();// Get the tab group from decoratoriTabGroup = (CAknTabGroup*)iDecorator->DecoratedControl();// Add new tab to tabbgroupiTabGroup->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 resourceiEikonEnv->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 paneiNaviPane->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 groupiTabGroup = CAknTabGroup::NewL( *iNaviPane );// Set tab widthiTabGroup->SetTabFixedWidthL ( EAknTabWidthWithTwoLongTabs );// Add tabs to tab groupiTabGroup->AddTabL(0,_L("Tab1") );iTabGroup->AddTabL(1,_L("Tab2") );// Create a navipane decorator containing the tab groupiDecorator = CAknNavigationDecorator::NewL( iNaviPane, iTabGroup, CAknNavigationDecorator::ETabGroup );iNaviPane->PushL( *iDecorator );// Activate the first tabiTabGroup->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 controliDecorator = iNaviPane->CreateTabGroupL(this);iTabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl();// Set tab widthiTabGroup->SetTabFixedWidthL ( EAknTabWidthWithTwoLongTabs );// Add tabs to tab groupiTabGroup->AddTabL(0,_L("Tab1") );iTabGroup->AddTabL(1,_L("Tab2") );// Activate the first tabiTabGroup->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.
- Tabs API: Using Tabs API
- Using Tabs API
- Tabs
- Tabs
- Tabs
- API Demos 2.3 学习笔记 (17)-- Views->Tabs
- jQuery EasyUI API 中文文档 - Tabs标签页/选项卡
- Android Api Demos登顶之路(二十六)Action Bar Tabs
- Android Api Demos登顶之路(四十二)Fragment-->Nesting Tabs
- 关于决解EasyUI中Tabs标签页下使用百度地图API异常
- OfficeMDI Tabs
- tabs indent
- jqueryui-tabs
- easyUI Tabs
- Fragment tabs
- Jquery tabs
- tabs 切换
- 自定义Tabs
- 结构体内存对齐、sizeof与strlen、数据名当作参数传递
- window权限 及c++实现 【网摘】
- 天蝎星座特性大全
- VC 和 Microsoft 运行库
- 十一、从头到尾解析Hash表算法
- Tabs API: Using Tabs API
- 人生感悟:人生的二十件奢侈品
- [转]Google Protocol Buffers 2.4
- 暴雪总裁总结游戏十条经验
- 如何查看及修改oracle编码格式方法
- 开发适应中国网络的J2ME连网程序
- 概述C# Cast
- oracle编码
- SqlHelper使用指南