⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 markgridcontainer.cpp

📁 《基于Symbian OS的手机开发与应用实践》这本书的配套源码。
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CMarkGridContainer from MarkGridContainer.h
*  Part of  : MarkGrid
*  Created  : 16.03.2006 by ToBeReplacedByAuthor
*  Implementation notes:
*     Initial content was generated by Series 60 Application Wizard.
*  Version  :
*  Copyright: ToBeReplacedByCopyright
* ============================================================================
*/

// INCLUDE FILES
#include <apgcli.h>             // for RApaLsSession
#include <eikapp.h>             // for CEikApplication
#include <akniconarray.h>       // for CAknIconArray
#include <akngmsstylegrid.h>           // for CAknGrid
#include <MarkGrid.mbg>         // for EMbmMarkgridPinb1
#include <MarkGrid.rsg>
#include <aknsconstants.hrh>    // for EAknsMajorCalendar


#include "MarkGridContainer.h"

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

// ---------------------------------------------------------
// CMarkGridContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CMarkGridContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    // Create the grid
    iGrid = new(ELeave) CAknGMSStyleGrid;
    iGrid->SetContainerWindowL(*this);
    iGrid->ConstructL(this, EAknListBoxMarkableGrid);
    iGrid->SetListBoxObserver(this);

    // Add items
    CTextListBoxModel* model = iGrid->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    _LIT(KItemFormat, "%d\t1");
    TBuf<32> item;
    TInt i=0;
    for(i=2; i<10; i++)
        {
        item.Format(KItemFormat(), i);
        array->AppendL(item);
        }

    // Create an array of icons, reading them from the file
    CEikonEnv* eikonEnv = CEikonEnv::Static();
    TFileName mbmFile = eikonEnv->EikAppUi()->Application()->BitmapStoreName();
    CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(3);
    CleanupStack::PushL(icons);
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmMarkgridCheck, EMbmMarkgridCheckmask));
    icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmMarkgridUncheck, EMbmMarkgridUncheckmask));
    for(i=EMbmMarkgridGms1; i<=EMbmMarkgridGms8; i++)
        {
        icons->AppendL(eikonEnv->CreateIconL(mbmFile, i));
        }
    CleanupStack::Pop(icons);
    // Transfer ownership
    iGrid->ItemDrawer()->FormattedCellData()->SetIconArray(icons);

    // Setup layout
    iGrid->SetupLayout();

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CMarkGridContainer::~CMarkGridContainer()
    {
    delete iGrid;
    }

// New methods
/**
* Handles marking commands for all currently selected games, by passing them 
* to the AknSelectionService
*/
void CMarkGridContainer::HandleMarkCommandL(TInt aCommand)
    {
    AknSelectionService::HandleMarkableListProcessCommandL(aCommand, iGrid);
    }

TInt CMarkGridContainer::RecordCount()
    {
    return iGrid->Model()->NumberOfItems();
    }

void CMarkGridContainer::DeleteRecordL()
    {
    CTextListBoxModel* model = iGrid->Model();
    CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
    TInt index = iGrid->CurrentItemIndex();
    TBool deleted = iGrid->View()->ItemIsSelected(index);
    const CListBoxView::CSelectionIndexArray* selection = iGrid->SelectionIndexes();
    TInt i = selection->Count()-1;
    for(i;i>=0;i--)
        {
        if(index>=(*selection)[i])
            {
            index--;
            }
        array->Delete((*selection)[i]);
        }
    if(index>=0)
        {
        iGrid->SetCurrentDataIndex(index);
        }
    iGrid->HandleItemRemovalL();
    HandleMarkCommandL(EAknUnmarkAll);
    }


// ---------------------------------------------------------
// CMarkGridContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CMarkGridContainer::SizeChanged()
    {
    iGrid->SetRect(Rect());
    // Apply layout
    TRAPD(err, iGrid->SetLayoutL(EFalse, ETrue, ETrue, 2, 4, TSize(80,34), 1, 1));
    AknLayoutUtils::LayoutControl(iGrid, Rect(), 0, 8, 2, ELayoutEmpty, ELayoutEmpty, 2, 4);
    }

// ---------------------------------------------------------
// CMarkGridContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CMarkGridContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CMarkGridContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CMarkGridContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iGrid;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// CMarkGridContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CMarkGridContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

// ---------------------------------------------------------
// CMarkGridContainer::OfferKeyEventL()
// @param aKeyEvent Event to handled.
// @param aType Type of the key event. 
// @return Response code (EKeyWasConsumed, EKeyWasNotConsumed). 
// ---------------------------------------------------------
//
TKeyResponse CMarkGridContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    return iGrid->OfferKeyEventL(aKeyEvent, aType);
    }

// ---------------------------------------------------------
// CMarkGridContainer::HandleListBoxEventL(
//     CEikListBox* aListBox, TListBoxEvent aListBoxEvent)
// ---------------------------------------------------------
//
void CMarkGridContainer::HandleListBoxEventL(CEikListBox*/*aListBox*/, TListBoxEvent aListBoxEvent)
    {
    if((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
       (aListBoxEvent == MEikListBoxObserver::EEventItemClicked)) // for emulator
        {
        CEikonEnv::Static()->InfoWinL(R_QTN_APP_NODETAIL);
        }
    }

// End of File  

⌨️ 快捷键说明

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