bencoolensettingsview.cpp

来自「Symbian_OS_code 初学Symbian_OS学习代码, 屏幕截图软」· C++ 代码 · 共 179 行

CPP
179
字号
/*
 * BencoolenSettingsView.cpp
 *
 * Copyright 2005 - 2008, Antony Pranata
 * http://www.antonypranata.com
 *
 * Project: Screenshot for Symbian OS.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// INCLUDE FILES
#include <avkon.hrh>
#include <avkon.rsg>
#include <akntitle.h>
#include <aknviewappui.h>
#include <screenshot.rsg>

#include "Bencoolen.hrh"
#include "BencoolenSettingsView.h"
#include "BencoolenAppUi.h"
#include "BencoolenSettingsListBox.h"


// MEMBER FUNCTIONS

// --------------------------------------------------------------------------
// Two-phase contructor.
// --------------------------------------------------------------------------
CBencoolenSettingsView* CBencoolenSettingsView::NewL(
        CScreenShotData* aScreenShotData)
    {
    CBencoolenSettingsView* self = new (ELeave) CBencoolenSettingsView(
        aScreenShotData);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(); // self;
    return self;
    }

// --------------------------------------------------------------------------
// Destructor.
// --------------------------------------------------------------------------
CBencoolenSettingsView::~CBencoolenSettingsView()
    {
    if (iListBox)
        {
        AppUi()->RemoveFromStack(iListBox);
        delete iListBox;
        }
    }

// --------------------------------------------------------------------------
// Returns the identifier of this view.
// --------------------------------------------------------------------------
TUid CBencoolenSettingsView::Id() const
    {
    return TUid::Uid(EBencoolenSettingsViewId);
    }
    
// --------------------------------------------------------------------------
// Handles commands in this view.
// Basically we only need to handle Change menu. If the user selects Change
// menu, we send OK key event to the list box.
// Otherwise, we just pass the command to AppUi().
// --------------------------------------------------------------------------
void CBencoolenSettingsView::HandleCommandL(TInt aCommand)
    {
    switch (aCommand)
        {
        case EAknSoftkeyBack:
            {
            AppUi()->ActivateLocalViewL(TUid::Uid(EBencoolenAppViewId));
            break;
            }

        case EBencoolenCmdChange:
            {
            // Simulates Scroll key.
            TKeyEvent keyEvent = { 63557, EStdKeyDevice3, EModifierAutorepeatable, 0 }; 
            iListBox->OfferKeyEventL(keyEvent, EEventKeyDown);
            break;
            }

        default:
            AppUi()->HandleCommandL(aCommand);
            break;
        }
    }

#if (__S60__ >= 203)

// --------------------------------------------------------------------------
// Called when screen size/resolution is changed. We need to re-adjust
// the size/layout of list box.
// --------------------------------------------------------------------------
void CBencoolenSettingsView::HandleResourceChange(TInt aType)
    {
    if (iListBox)
        {
        iListBox->HandleResourceChange(aType);
        }
    }
    
#endif

// --------------------------------------------------------------------------
// C++ default constructor can NOT contain any code, that might leave.
// --------------------------------------------------------------------------
CBencoolenSettingsView::CBencoolenSettingsView(CScreenShotData* aScreenShotData)
:iScreenShotData(aScreenShotData)
    {
    }

// --------------------------------------------------------------------------
// Second phase constructor.
// --------------------------------------------------------------------------
void CBencoolenSettingsView::ConstructL()
    {
    BaseConstructL(R_BENCOOLEN_SETTINGSVIEW);
    }

// --------------------------------------------------------------------------
// Creates list box control.
// --------------------------------------------------------------------------
void CBencoolenSettingsView::CreateListBoxL(TInt aResourceId)
    {
    iListBox = new (ELeave) CBencoolenSettingsListBox();
    iListBox->SetData(iScreenShotData);
    iListBox->SetMopParent(this);
    iListBox->ConstructFromResourceL(aResourceId);

    AppUi()->AddToStackL(*this, iListBox);
    iListBox->MakeVisible(ETrue);
    iListBox->SetRect(ClientRect());
    iListBox->ActivateL();
    iListBox->DrawNow();
    }

// --------------------------------------------------------------------------
// Creates container class object.
// --------------------------------------------------------------------------
void CBencoolenSettingsView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
                                         TUid /*aCustomMessageId*/,
                                         const TDesC8& /*aCustomMessage*/ )
    {
    CreateListBoxL(R_BENCOOLEN_SETTINGS_ITEM);
    }

// --------------------------------------------------------------------------
// Deletes container class object.
// --------------------------------------------------------------------------
void CBencoolenSettingsView::DoDeactivate()
    {    
    if (iListBox)
        {
        iListBox->UpdateData();
        AppUi()->RemoveFromStack(iListBox);
        delete iListBox;
        iListBox = NULL;
        }

    // Sets the capture key
    static_cast<CBencoolenAppUi*> (AppUi())->SetCaptureKey();
    }
    
// End of File

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?