📄 titlepaneappui.cpp
字号:
/**
*
* @brief Definition of CTitlePaneAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "TitlePaneAppUi.h"
// System includes
#include <avkon.rsg>
#include <TitlePane.rsg>
#include <akntitle.h>
#include <akncontext.h>
#include <stringloader.h>
#include <aknnavi.h>
#include <akntabgrp.h>
#include <aknnavide.h>
#include <TitlePane.mbg> // icons
// User includes
#include "TitlePane.hrh" // TTitlePaneViewNumber
#include "TitlePaneView1.h" // CTitlePaneView1
_LIT(KTitleBitMapFile, "\\system\\apps\\titlepane\\titlepane.mbm");
// ================= MEMBER FUNCTIONS =======================
CTitlePaneAppUi::CTitlePaneAppUi()
: iNaviDecorator(NULL)
{
}
CTitlePaneAppUi::~CTitlePaneAppUi()
{
delete iNaviDecorator;
}
/**
* Symbian OS 2nd phase constructor. Constructs the application's views,
* transferring ownership of them to the superclass.
* Sets view 1 as the default and remembers that this is the current view id.
*/
void CTitlePaneAppUi::ConstructL()
{
BaseConstructL();
iView1 = CTitlePaneView1::NewL();
AddViewL(iView1); // transfer ownership
}
/**
* From CEikAppUi, takes care of command handling for application views.
*
* @param aCommand command to be handled
*/
void CTitlePaneAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
// change the title pane text
case ETitlePaneSetTitleText:
{
TUid titlePaneUid;
titlePaneUid.iUid = EEikStatusPaneUidTitle;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(titlePaneUid);
// if we can access the title pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(titlePaneUid);
// read the title text from the resource file
HBufC* titleText = StringLoader::LoadLC(R_TITLE_TEXT);
// set the title pane's text
titlePane->SetTextL(*titleText);
CleanupStack::PopAndDestroy(titleText);
}
break;
}
// reset the title pane back to its default text
case ETitlePaneSetTitleDefault:
{
TUid titlePaneUid;
titlePaneUid.iUid = EEikStatusPaneUidTitle;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(titlePaneUid);
// if we can access the title pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(titlePaneUid);
// set the title text back to its default
titlePane->SetTextToDefaultL();
}
break;
}
// display a bitmap in the title pane
case ETitlePaneSetTitleImage:
{
TUid titlePaneUid;
titlePaneUid.iUid = EEikStatusPaneUidTitle;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(titlePaneUid);
// if we can access the title pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(titlePaneUid);
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(KTitleBitMapFile, EMbmTitlepaneTitle);
// set the title pane's image
titlePane->SetPicture(bitmap);
}
break;
}
// display a bitmap in the context pane
case ETitlePaneSetContextImage:
{
TUid contextPaneUid;
contextPaneUid.iUid = EEikStatusPaneUidContext;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(contextPaneUid);
// if we can access the context pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CEikStatusPane* statusPane = StatusPane();
CAknContextPane* contextPane = (CAknContextPane*) statusPane->ControlL(contextPaneUid);
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(KTitleBitMapFile, EMbmTitlepaneContext);
// set the context pane's image
contextPane->SetPicture(bitmap);
}
break;
}
// display two tabs in the navigation pane
case ETitlePaneSetNaviPane:
{
TUid naviPaneUid;
naviPaneUid.iUid = EEikStatusPaneUidNavi;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(naviPaneUid);
// if we can access the navigation pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknNavigationControlContainer* naviPane =
(CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
delete iNaviDecorator;
iNaviDecorator = NULL;
// ownership is transferred to us here
iNaviDecorator = naviPane->CreateTabGroupL();
// ownership not transferred
CAknTabGroup* tabGroup = (CAknTabGroup*) iNaviDecorator->DecoratedControl();
// Display two tabs of normal length on the navigation pane at a time
tabGroup->SetTabFixedWidthL(KTabWidthWithTwoTabs);
TInt tabId = 0;
// load the text to be displayed in the tabs
HBufC* tab1Text = StringLoader::LoadLC(R_TAB1_TEXT);
tabGroup->AddTabL(tabId++, *tab1Text);
CleanupStack::PopAndDestroy(tab1Text);
HBufC* tab2Text = StringLoader::LoadLC(R_TAB2_TEXT);
tabGroup->AddTabL(tabId++, *tab2Text);
CleanupStack::PopAndDestroy(tab2Text);
// highlight the first tab
tabGroup->SetActiveTabByIndex(0);
naviPane->PushL(*iNaviDecorator);
}
break;
}
// display a tab with an image in the navigation pane
case ETitlePaneSetNaviPaneTabImage:
{
TUid naviPaneUid;
naviPaneUid.iUid = EEikStatusPaneUidNavi;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(naviPaneUid);
// if we can access the navigation pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknNavigationControlContainer* naviPane =
(CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
delete iNaviDecorator;
iNaviDecorator = NULL;
// ownership is transferred to us here
iNaviDecorator = naviPane->CreateTabGroupL();
// ownership not transferred
CAknTabGroup* tabGroup = (CAknTabGroup*) iNaviDecorator->DecoratedControl();
// Display two tabs of normal length on the navigation pane at a time
tabGroup->SetTabFixedWidthL(KTabWidthWithTwoTabs);
TInt tabId = 0;
// load the bitmap to be displayed in the tabs
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(KTitleBitMapFile, EMbmTitlepaneTab);
// display a bitmap in the tab
tabGroup->AddTabL(tabId++, bitmap);
// highlight the first tab
tabGroup->SetActiveTabByIndex(0);
naviPane->PushL(*iNaviDecorator);
}
break;
}
// display a label in the navigation pane
case ETitlePaneSetNaviPaneLabel:
{
TUid naviPaneUid;
naviPaneUid.iUid = EEikStatusPaneUidNavi;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(naviPaneUid);
// if we can access the navigation pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknNavigationControlContainer* naviPane =
(CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
delete iNaviDecorator;
iNaviDecorator = NULL;
HBufC* labelText = StringLoader::LoadLC(R_NAVIGATION_LABEL_TEXT);
// set the navigation pane's label
iNaviDecorator = naviPane->CreateNavigationLabelL(*labelText);
CleanupStack::PopAndDestroy(labelText);
naviPane->PushL(*iNaviDecorator);
}
break;
}
// display a volume control in the navigation pane
case ETitlePaneSetNaviPaneIndicator:
{
TUid naviPaneUid;
naviPaneUid.iUid = EEikStatusPaneUidNavi;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(naviPaneUid);
// if we can access the navigation pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknNavigationControlContainer* naviPane =
(CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
delete iNaviDecorator;
iNaviDecorator = NULL;
// create a volume indicator on the navigation pane
iNaviDecorator = naviPane->CreateVolumeIndicatorL(R_AVKON_NAVI_PANE_VOLUME_INDICATOR);
naviPane->PushL(*iNaviDecorator);
}
CAknVolumeControl* volumeControl = (CAknVolumeControl*) iNaviDecorator->DecoratedControl();
// Get the current volume level
TInt curVolume = volumeControl->Value();
// Increase the volume level by one
volumeControl->SetValue(++curVolume);
break;
}
// display an image in the navigation pane
case ETitlePaneSetNaviPaneImage:
{
TUid naviPaneUid;
naviPaneUid.iUid = EEikStatusPaneUidNavi;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(naviPaneUid);
// if we can access the navigation pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknNavigationControlContainer* naviPane =
(CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
delete iNaviDecorator;
iNaviDecorator = NULL;
// Create a bitmap to display
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(KTitleBitMapFile, EMbmTitlepaneNavigation);
// create an image on the navigation pane
iNaviDecorator = naviPane->CreateNavigationImageL(bitmap);
naviPane->PushL(*iNaviDecorator);
}
}
break;
case EEikCmdExit:
{
Exit();
break;
}
default:
break;
}
}
/**
* Handle key presses, and pass them to the navigation decorator if it exists
*
* @param aKeyEvent key pressed information
* @param aType type of key event
*/
TKeyResponse CTitlePaneAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (iNaviDecorator == NULL)
{
return EKeyWasNotConsumed;
}
CAknTabGroup* tabGroup = (CAknTabGroup*) iNaviDecorator->DecoratedControl();
if (tabGroup == NULL)
{
return EKeyWasNotConsumed;
}
// if we've got a tab group, then offer the key event to it.
return tabGroup->OfferKeyEventL(aKeyEvent, aType);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -