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

📄 choicelistexcontainer.cpp

📁 symbian touch ChoiceList 示例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    
    for ( TInt k = 0; k < 10; k++ )
        {
        TBuf<32> buf;
        buf.Format( KListItem, k );
        array->AppendL( buf );
        }

    iArraySize = array->Count();
    iSelection = 0;

    // Create a button for the choice list
    CAknButton* button = CAknButton::NewLC( NULL,
                                            NULL,
                                            NULL,
                                            NULL,
                                            KButtonTxt,
                                            KButtonHelpTxt,
                                            KAknButtonSizeFitText,
                                            0 );
    
    // Create a choice list
    iChoiceList = CAknChoiceList::NewL( this, array, 
            CAknChoiceList::EAknChoiceListWithoutCurrentSelection, 
            button );
    CleanupStack::Pop( button );
    CleanupStack::Pop( array );

    iChoiceList->SetObserver( this );
    iChoiceList->SetRect( KListRect );
       
    iLabel->SetTextL( KCreate );
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::CreateResourceChoiceListL
// Deletes previous Choice list if exists and constructs a new one from
// resources defined in resource file ChoiceListEx.rss
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::CreateResourceChoiceListL()
    {
    if ( iChoiceList )
        {
        delete iChoiceList;
        iChoiceList = NULL;
        }

    // Create empty Choice list
    iChoiceList = CAknChoiceList::NewL( this, NULL );

    // Add items from resource
    iChoiceList->SetItemsL( R_CHOICELISTEX_ITEM_ARRAY );
    iArraySize = ArraySizeL( R_CHOICELISTEX_ITEM_ARRAY );
    iSelection = 0;
    
    iChoiceList->SetObserver( this );
    iChoiceList->SetRect( KListRect );
  
    iLabel->SetTextL( KCreate );
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::ShowListL
// Opens the choice list 
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::ShowListL()
    {
    if ( !iChoiceList )
        {
        iLabel->SetTextL( KNoList );
        return;
        }
    iChoiceList->ShowChoiceListL();
    
    iLabel->SetTextL( KShow );
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::AddItemL
// Adds a new item to the choice list
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::AddItemL()
    {
    if ( !iChoiceList )
        {
        iLabel->SetTextL( KNoList );
        return;
        }
            
    TInt index = iChoiceList->AddItemL( &KListItemNew );
    ++iArraySize;
    
    TBuf<32> buf;
    buf.Format( KAdd, index );
    iLabel->SetTextL( buf );
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::InsertItemL
// Inserts a new item in the middle of the list.
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::InsertItemL()
    {
    if ( !iChoiceList )
        {
        iLabel->SetTextL( KNoList );
        return;
        }
    TInt point = TInt ( iArraySize / 2 );
    
    TInt index = iChoiceList->InsertItemL( point, KListItemNew );
    ++iArraySize;
    
    TBuf<32> buf;
    buf.Format( KInsert, index );
    iLabel->SetTextL( buf );
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::RemoveItemL
// Removes the last item from the choice list
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::RemoveItemL()
    {
    if ( !iChoiceList )
        {
        iLabel->SetTextL( KNoList );
        return;
        }
        
    if ( iArraySize < 1 )
        {
        iLabel->SetTextL( KNoItems );
        return;
        }
        
    iArraySize--;
    iChoiceList->RemoveItem( iArraySize );

    TBuf<32> buf;
    buf.Format( KRemove, iArraySize );
    iLabel->SetTextL( buf );
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::SelectItemL
// Sets the last item as selected
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::SelectItemL()
    {
    if ( !iChoiceList )
        {
        iLabel->SetTextL( KNoList );
        return;
        }
    
    if ( iArraySize < 1 )
        {
        iLabel->SetTextL( KNoItems );
        return;
        }
        
    iChoiceList->SetSelectedIndex( iArraySize - 1 );
    
    TBuf<32> buf;
    buf.Format( KSelect, iArraySize-1 );
    iLabel->SetTextL( buf );
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::ChangeListFlagsL
// Changes the choice list flags ( Position )
// ---------------------------------------------------------------------------
//    
void CChoiceListExContainer::ChangeListFlagsL( 
                            CAknChoiceList::TAknChoiceListFlags aFlag )
    {
    if ( !iChoiceList )
        {
        iLabel->SetTextL( KNoList );
        return;
        }
    iChoiceList->SetFlags( aFlag );
    iLabel->SetTextL( KFlag );
    }
    
// ---------------------------------------------------------------------------
// CChoiceListExContainer::ArraySize
// Returns the size of the given array
// ---------------------------------------------------------------------------
//
TInt CChoiceListExContainer::ArraySizeL( TInt aResourceId )
    {
    TResourceReader reader;
    CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId );    
    CDesCArray* array = NULL;    
    array = reader.ReadDesC16ArrayL();
    CleanupStack::PopAndDestroy(); // reader
    
    TInt size = 0;
    size = array->Count();
    delete array;

    return size;
    }
    
// ---------------------------------------------------------------------------
// CChoiceListExContainer::HandleResourceChange
// 
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::HandleResourceChange( TInt aType )
    {
    CCoeControl::HandleResourceChange( aType );
    if  ( aType == KEikDynamicLayoutVariantSwitch )
    	{
        TRect rect;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
        
        iBgContext->SetRect( Rect() );
        iBgContext->SetParentPos( PositionRelativeToScreen() );
        }
    }

// ---------------------------------------------------------------------------
// CChoiceListExContainer::SizeChanged
// 
// ---------------------------------------------------------------------------
//
void CChoiceListExContainer::SizeChanged()
    {
    if( iLabel) 
        {
        iLabel->SetRect( TRect( TPoint(Rect().iTl.iX, Rect().iTl.iY + 35), TPoint(Rect().iBr.iX, Rect().iTl.iY + 75  ) ) );
        }
    if( iChoiceList )
        {
        iChoiceList->SetRect( TRect( TPoint(Rect().iTl.iX, Rect().iTl.iY + 75), TPoint(Rect().iBr.iX, Rect().iTl.iY + 105  ) ) );
        }
    
    }

⌨️ 快捷键说明

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