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

📄 aknexgridcontainerasgms.cpp

📁 symbian 格子的生成和使用源代码 让你明白九宫格生成原理 适合游戏开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                KPathAppMbm,
                                EMbmAknexgridWhitetextonblack_ota );
    CleanupStack::PushL( newIcon5 );

    CGulIcon* onImage = CEikonEnv::Static()->CreateIconL(
                                KPathAppMbm,
                                EMbmAknexgridMarkon,
                                EMbmAknexgridMarkm );
    CleanupStack::PushL( onImage );

    CGulIcon* offImage = CEikonEnv::Static()->CreateIconL(
                                KPathAppMbm,
                                EMbmAknexgridMarkoff,
                                EMbmAknexgridMarkm );
    CleanupStack::PushL( offImage );

    icons->AppendL( onImage );
    icons->AppendL( offImage );
    icons->AppendL( newIcon1 );
    icons->AppendL( newIcon2 );
    icons->AppendL( newIcon3 );
    icons->AppendL( newIcon4 );
    icons->AppendL( newIcon5 );

    GMSGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );

    CleanupStack::Pop(); // offImage
    CleanupStack::Pop(); // onImage
    CleanupStack::Pop(); // newIcon5
    CleanupStack::Pop(); // newIcon4
    CleanupStack::Pop(); // newIcon3
    CleanupStack::Pop(); // newIcon2
    CleanupStack::Pop(); // newIcon1
    CleanupStack::Pop(); // icons

    TBuf < KLengthOfTitle > text;
    iCoeEnv->ReadResource( text, R_EXGR_TEXT_POPUPGMS_TITLE );
    popupGMSGrid->SetTitleL( text );

    // Show popup grid
    TInt popupOk = popupGMSGrid->ExecuteLD();
    CleanupStack::Pop(); // popupGMSGrid
    if ( popupOk )
        {
        TInt index = GMSGrid->CurrentItemIndex();
        iCoeEnv->ReadResource( format, R_EXGR_TEXT_ACT_ONE_ITEM );
        text.Format( format, index );
        iEikonEnv->AlertWin( text );
        }
    else
        {
        iCoeEnv->ReadResource( text, R_EXGR_TEXT_POPUPGMS_CANCEL );
        iEikonEnv->AlertWin( text );
        }

    CleanupStack::PopAndDestroy(); // GMSGrid
    }

// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::CheckIndex()
// Shows current index.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsGMS::CheckIndex()
    {
    // Counter of the number of marked item
    TInt selectedItemCount = 0;

    // Load message.
    TBuf< KLengthOfStringToShowIndex > number;
    TBuf< KLengthOfStringToShowIndex > format;
    iCoeEnv->ReadResource( format, R_EXGR_FORMATSTRING_CURRENTINDEX );

    // The number of items.
    TInt numberOfData = iGridGMS->GridModel()->NumberOfData();

    // Check marked item. And if the item is marked,display dialog.
    for ( TInt checkData = 0; checkData < numberOfData; checkData++ )
        {
        CListBoxView* view = iGridGMS->View();

        if ( view->ItemIsSelected( checkData ) )
            {
            selectedItemCount++;

            // display dialog.
            number.Format( format, checkData );
            iEikonEnv->AlertWin( number );
            }
        }

    if ( selectedItemCount == 0 )
        {
        number.Format( format, selectedItemCount - 1 );
        iEikonEnv->AlertWin( number );
        }
    }

// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsGMS::SizeChanged()
    {
    if( iGridGMS )
        {
        AknLayoutUtils::LayoutControl( iGridGMS, Rect(), KGMSColorIndex,
            KLeftOfGMSGrid, KTopOfGMSGrid, ELayoutEmpty, ELayoutEmpty,
            KWidthOfGMSGrid, KHeightOfGMSGrid );
        }
    }

// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::CountComponentControls()
// Returns the number of components owned by this container.
// -----------------------------------------------------------------------------
//
TInt CAknExGridContainerAsGMS::CountComponentControls() const
    {
    // return number of controls inside this container
    return KNumberOfComponentGMS;
    }

// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::ComponentControl()
// Returns the pointer to the specified control.
// -----------------------------------------------------------------------------
//
CCoeControl* CAknExGridContainerAsGMS::ComponentControl( TInt aIndex ) const
    {
    switch ( aIndex )
        {
        case EGmsGrid:
            return iGridGMS;
        default:
            return NULL;
        }
    }

// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::Draw()
// Draws this container to the screen.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsGMS::Draw( const TRect& aRect ) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbDarkCyan );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }


// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::OfferKeyEventL()
// Handles key events.
// -----------------------------------------------------------------------------
//
TKeyResponse CAknExGridContainerAsGMS::OfferKeyEventL(
                       const TKeyEvent& aKeyEvent, TEventCode aType )
    {
    TInt code = aKeyEvent.iCode;

    if ( iGridGMS )
        {
        if ( code == EKeyEnter || code == EKeyOK )
            {
            TBool shiftKeyPressed = ( aKeyEvent.iModifiers & EModifierShift );
            if ( !shiftKeyPressed )
                {
                CheckIndex();   // show the current index
                return( EKeyWasConsumed );
                }
            else
                {
                return iGridGMS->OfferKeyEventL( aKeyEvent, aType );
                }
            }
        else
            {
            return iGridGMS->OfferKeyEventL( aKeyEvent, aType );
            }
        }

    return( EKeyWasNotConsumed );
    }

// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::HandleControlEventL()
// Handles an event of type aEventType reported
// by the control aControl to this observer.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsGMS::HandleControlEventL(
        CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/ )
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// CAknExGridContainerAsGMS::AutoTestL()
// Runs different tests.
// -----------------------------------------------------------------------------
//
TBool CAknExGridContainerAsGMS::AutoTestL()
    {
    CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
    CAknTitlePane* titlePane = static_cast<CAknTitlePane*>
        (sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );

    iTestNumber++;

    switch( iTestNumber )
        {
        case EGMSTest1:
            titlePane->SetTextL( ( *iTitles )[EGMSTest1] );
            break;

        case EGMSTest2:
            titlePane->SetTextL( ( *iTitles )[EGMSTest2] );
            ShowPopupGMSGridL();
            break;

        default:
            return ETrue;
        }

    return EFalse;
    }

// End of File

⌨️ 快捷键说明

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