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

📄 markablegridcontainer.cpp

📁 series60 应用程序开发的源代码 series60 应用程序开发的源代码
💻 CPP
字号:
/**
* 
* @brief Definition of CMarkableGridContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "MarkableGridContainer.h"

// System includes
#include <aknlists.h> // AknListBoxUtils
#include <MarkableGrid.rsg> // R_MARKABLEGRID_GAMES_GRID, R_ICON_FILE_NAME

// User includes
#include "MarkableGridGamesGrid.h"//CMarkableGridGamesGrid

// CONSTANTS

// #defined as DLL cannot contain writable static data
#define KGridPosition TPoint(0,0)

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

/**
* Symbian OS 2nd phase constructor.  Creates a Window for the controls, which it contains.
* Constructs a grid and adds it to the window, which it then activates.
* @param aRect The rectangle for this window
*/    
void CMarkableGridContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
    
    // Construct the grid
    iGamesGrid = new (ELeave)CMarkableGridGamesGrid;
    iGamesGrid->SetContainerWindowL(*this);
    iGamesGrid->ConstructL(R_MARKABLEGRID_GAMES_GRID, R_ICON_FILE_NAME);
    
    // Observe the grid
    iGamesGrid->SetListBoxObserver(this);
    
    SetRect(aRect);
    ActivateL();
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CMarkableGridContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @return The newly constructed CMarkableGridContainer
*/
CMarkableGridContainer* CMarkableGridContainer::NewL(const TRect& aRect)
{
    CMarkableGridContainer* self = CMarkableGridContainer::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CMarkableGridContainer using the constructor and ConstructL 
* method, leaving the constructed object on the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @return The newly constructed CMarkableGridContainer
*/
CMarkableGridContainer* CMarkableGridContainer::NewLC(const TRect& aRect)
{
    CMarkableGridContainer* self = new (ELeave) CMarkableGridContainer;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
}

/** 
* Destructor.  Frees up memory for the iGamesGrid.
*/
CMarkableGridContainer::~CMarkableGridContainer()
{
    delete iGamesGrid;
}

/**
*    
* Called by framework when the view size is changed.  Resizes the
* iGamesGrid accordingly.
*
*/
void CMarkableGridContainer::SizeChanged()
{
    // Do not use MinimumSize() here as it does not work when scrolling
    // through the grid
    if (iGamesGrid)
    {
        iGamesGrid->SetExtent (KGridPosition,Rect().Size());
    }
}

/**
* Called by the framework in compound controls    
* @return The number of controls in this CMarkableGridContainer
*/
TInt CMarkableGridContainer::CountComponentControls() const
{
    return 1; // return number of controls inside this container
}

/**
* Called by the framework in compound controls    
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CMarkableGridContainer::ComponentControl(TInt aIndex) const
{
    switch (aIndex)
    {
        case 0:
            return iGamesGrid;
        default:
            return NULL;
    }
}

/**
* Called by the framework to draw this control.  Clears the area in 
* aRect.
* @param aRect in which to draw
*/
void CMarkableGridContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.Clear(aRect);
}

/**
* Called by the framework whenever a key event occurs.    
* Passes the key event to the games grid if it is not null, otherwise returns
* EKeyWasNotConsumed
* @param aKeyEvent the Key event which occured, e.g. select key pressed
* @param aType the type of Key event which occurred, e.g. key up, key down
* @return TKeyResponse EKeyWasNotConsumed if the key was not processed, EKeyWasConsumed if it was
*/
TKeyResponse CMarkableGridContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
    
    // if it's not an event key we're not interested so return not consumed
    if (aType != EEventKey)
        return EKeyWasNotConsumed;
    
    if (iGamesGrid)
    {
        return iGamesGrid->OfferKeyEventL (aKeyEvent, aType);
    }
    else
        return EKeyWasNotConsumed;
}

/**
* Plays the currently select game in the iGamesGrid, if one exists.  
* This is an empty implementation of this method
*/
void CMarkableGridContainer::PlaySelectedGame()
{
}

/**
* Called by the framework whenever a grid event occurs for which this container
* is an observer.
* @param aListBoxEvent The type of event which occured
*
*/
void CMarkableGridContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
{
    // if the Select Key has been pressed
    if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
        (aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
    {
        PlaySelectedGame();
    }
}

/**
*    
* Deletes any marked items
*
*/
void CMarkableGridContainer::DeleteSelectedL()
{
    if (iGamesGrid)
    {
        CTextListBoxModel* model = iGamesGrid->Model();
        
        if (model->NumberOfItems() > 0)
        {
            
            // Create a copy of the currently selected items (copyIndices) in numeric order
            const CListBoxView::CSelectionIndexArray* selectionIndices = iGamesGrid->SelectionIndexes();
            
            RArray<TInt> copyIndices; 
            CleanupClosePushL(copyIndices);
            TInt numberSelectedGames = selectionIndices->Count();
            for (TInt i=0; i< numberSelectedGames; i++)
            {
                copyIndices.InsertInOrder ((*selectionIndices)[i]);
            }    
            
            // Iterate through the copyIndices in reverse order, deleting them
            // from the list's item array
            TInt currentItem(0);
            CDesCArray* itemArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
            for (TInt j=numberSelectedGames-1; j>=0; j--)
            {
                currentItem = copyIndices[j];
                itemArray->Delete(currentItem);
            }
            CleanupStack::PopAndDestroy(); // Close copyIndices and free memory
            
            
            // Redraw the list following removal
            AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
                iGamesGrid, 
                currentItem, 
                ETrue);
            
        }
    }
    
    
}

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



// End of File    

⌨️ 快捷键说明

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