navigationpaneappui.cpp

来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 230 行

CPP
230
字号
/**
* 
* @brief Definition of CNavigationPaneAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

//  Class include
#include "NavigationPaneAppUi.h"

// System includes
#include <avkon.rsg>
#include <NavigationPane.rsg>
#include <stringloader.h>
#include <aknnavi.h>
#include <akntabgrp.h>
#include <aknnavide.h>
#include <barsread.h>

// User includes
#include "NavigationPane.hrh" // TNavigationPaneViewNumber
#include "NavigationPaneView1.h" // CNavigationPaneView1


// ================= MEMBER FUNCTIONS =======================

CNavigationPaneAppUi::CNavigationPaneAppUi()
    : iNaviDecorator(NULL)
{
}


CNavigationPaneAppUi::~CNavigationPaneAppUi()
{
    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 CNavigationPaneAppUi::ConstructL()
{
    BaseConstructL();

    iView1 = CNavigationPaneView1::NewL();
    AddViewL(iView1); // transfer ownership

}

/**
* From CEikAppUi, takes care of command handling for application views.
*
* @param aCommand command to be handled
*/
void CNavigationPaneAppUi::HandleCommandL(TInt aCommand)
{
    switch (aCommand)
    {

        // display a tab group in the navigation pane from a resource
        case ENavigationPaneSetNaviPane:
        {
            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);

                // read the tab group resource
                TResourceReader reader;
                iCoeEnv->CreateResourceReaderLC(reader, R_NAVIGATIONPANE_TABGROUP);

                if (iNaviDecorator)
                {
                    delete iNaviDecorator;
                    iNaviDecorator = NULL;
                }

                // set the navigation pane tab group
                iNaviDecorator = naviPane->CreateTabGroupL(reader);
                CleanupStack::PopAndDestroy(); // pushed by CreateResourceReaderLC
                naviPane->PushL(*iNaviDecorator);
            }
            break;
        }

        // display a label in the navigation pane from a resource
        case ENavigationPaneSetNaviPaneLabel:
        {
            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);

                // read the navigation pane text resource
                TResourceReader reader;
                iCoeEnv->CreateResourceReaderLC(reader, R_NAVIGATIONPANE_NAVI_TEXT);

                if (iNaviDecorator)
                {
                    delete iNaviDecorator;
                    iNaviDecorator = NULL;
                }

                // set the navigation pane label
                iNaviDecorator = naviPane->CreateNavigationLabelL(reader);
                CleanupStack::PopAndDestroy(); // pushed by CreateResourceReaderLC
            
                naviPane->PushL(*iNaviDecorator);
            }
            break;
        }

        // display an image in the navigation pane from a resource
        case ENavigationPaneSetNaviPaneImage:
        {
            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);

                // read the navigation pane image resource
                TResourceReader reader;
                iCoeEnv->CreateResourceReaderLC(reader, R_NAVIGATIONPANE_NAVI_IMAGE);

                if (iNaviDecorator)
                {
                    delete iNaviDecorator;
                    iNaviDecorator = NULL;
                }

                // set the navigation pane image
                iNaviDecorator = naviPane->CreateNavigationImageL(reader);
                CleanupStack::PopAndDestroy(); // pushed by CreateResourceReaderLC
            
                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 CNavigationPaneAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{

    CAknNavigationDecorator* navi = iNaviDecorator;
    // if we haven't already got a navigation decorator, then try to get current one
    if (navi == NULL)
    {
        TUid naviPaneUid;
        naviPaneUid.iUid = EEikStatusPaneUidNavi;

        CEikStatusPane* statusPane = StatusPane();

        CAknNavigationControlContainer* naviPane =
            (CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
    
        navi = naviPane->Top();
    }


    if (navi == NULL)
    {
        return EKeyWasNotConsumed;
    }


    CAknTabGroup* tabGroup = (CAknTabGroup*) navi->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 + =
减小字号Ctrl + -
显示快捷键?