www.pudn.com > LDFUCK.rar > TempContainer.cpp
#include#include #include #include #include #include #include //#include // TKeyCode #defines #include #include "TempContainer.h" #include "LDFUCKAppUi.h" CTempContainer::CTempContainer() { m_pListBoxArray=NULL; aListBox=NULL; } // EPOC default constructor can leave. void CTempContainer::ConstructL(const TRect& aRect) { CreateWindowL(); //create SingleListBox aListBox = new( ELeave ) CAknSingleNumberStyleListBox(); //创建列表对象指针 CleanupStack::PushL(aListBox); aListBox->ConstructL(this, EAknListBoxMarkableList | EAknListBoxMultiselectionList); aListBox->SetContainerWindowL( *this ); aListBox->SetRect(aRect); //启动列表的滚动条 aListBox->CreateScrollBarFrameL( ETrue ); aListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); // TResourceReader reader; // CEikonEnv::Static()->CreateResourceReaderLC( reader, R_SINGLE_TEMP_LISTBOX ); // aListBox->ConstructFromResourceL( reader ); // CleanupStack::PopAndDestroy(); // resource stuffs. // 添加新图标列表 // CLDFUCKAppUi* pApp = (CLDFUCKAppUi*)CEikonEnv::Static()->AppUi(); // CArrayPtr * icons = new( ELeave ) CAknIconArray(1); // CleanupStack::PushL( icons ); // icons->AppendL(pApp->LoadGraphicsL(0)); // aListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); // 添加项目列表 m_pListBoxArray = new (ELeave) CDesCArrayFlat(10); CleanupStack::PushL(m_pListBoxArray); CTextListBoxModel* model = aListBox->Model(); model->SetItemTextArray( m_pListBoxArray ); model->SetOwnershipType(ELbmDoesNotOwnItemArray); CleanupStack::Pop(2); // // Observe the list // aListBox->SetListBoxObserver(this); SetRect( aRect ); ActivateL(); } // destructor CTempContainer::~CTempContainer() { if (aListBox) { delete aListBox; aListBox=NULL; } if (m_pListBoxArray) { delete m_pListBoxArray; m_pListBoxArray=NULL; } } void CTempContainer::SizeChanged() { if(aListBox) { aListBox->SetRect(Rect()); } } // --------------------------------------------------------- // CTempContainer::CountComponentControls() const // return the number of controls // --------------------------------------------------------- // TInt CTempContainer::CountComponentControls() const { // return number of controls inside this container return 1; } // --------------------------------------------------------- // CTempContainer::ComponentControl(TInt aIndex) const // return the pointer to specified control. // --------------------------------------------------------- // CCoeControl* CTempContainer::ComponentControl( TInt /*aIndex*/ ) const { return aListBox; // return NULL; } // --------------------------------------------------------- // CTempContainer::Draw(const TRect& aRect) const // handle the message when client region must be redrawn. // --------------------------------------------------------- // void CTempContainer::Draw( const TRect& /*aRect*/ ) const { CWindowGc& gc = SystemGc(); gc.Clear(Rect()); // gc.DrawRect(TRect(TPoint(10, 10), TSize(20, 20))); } // --------------------------------------------------------- // CAknExGridContainer::OfferKeyEventL( // const TKeyEvent& aKeyEvent, TEventCode aType ) // Handles the key events. // --------------------------------------------------------- // TKeyResponse CTempContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType ) { if(aKeyEvent.iScanCode ==167) { return EKeyWasConsumed; } if (aListBox) return aListBox->OfferKeyEventL (aKeyEvent, aType); else return EKeyWasNotConsumed; } void CTempContainer::addInfotolist( const TDesC& aFlag, const TDesC& aName) { TBuf<64> sTmpBuf; sTmpBuf.Copy(aFlag); sTmpBuf.Append(_L("\t")); sTmpBuf.Append(aName); m_pListBoxArray->AppendL(sTmpBuf); aListBox->HandleItemAdditionL(); } //void CTempContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent) //{ // // if the Select Key has been pressed // if ( aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed ) // { // TInt currentItem( this->aListBox->CurrentItemIndex() ); // // if(currentItem == 1) // { // // } // } // } TInt CTempContainer::getListBoxIndex() { TInt currentItem( this->aListBox->CurrentItemIndex() ); listIndex = currentItem; return listIndex; } // End of File