examples/ForumNokia/ContactsModel/src/ContactsModelContainer.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 // INCLUDE FILES
00006 #include "ContactsModelDocument.h"
00007 #include "ContactsModelContainer.h"
00008 
00009 const TInt KGranularityOfArray = 10;
00010 
00011 const TInt KBufferSize = 256;
00012 // ================= MEMBER FUNCTIONS =======================
00013 
00014 // ---------------------------------------------------------
00015 // CContactsModelContainer::ConstructL(const TRect& aRect)
00016 // EPOC two phased constructor
00017 // ---------------------------------------------------------
00018 //
00019 void CContactsModelContainer::ConstructL(const TRect& aRect, CContactsModelDocument* aDocument)
00020     {
00021         iDocument = aDocument;
00022     CreateWindowL();
00023     SetRect(aRect);
00024 
00025         // create listbox control
00026     iListBox = new (ELeave) CAknSingleStyleListBox;
00027     iListBox->ConstructL(this, 0);
00028         iListBox->SetContainerWindowL(*this);
00029     iListBox->SetRect(aRect.Size());
00030 
00031         iListBoxRows = new (ELeave) CDesCArrayFlat( KGranularityOfArray );
00032         iListBox->Model()->SetItemTextArray( iListBoxRows );
00033         iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
00034 
00035     iListBox->ActivateL();
00036     iListBox->CreateScrollBarFrameL(ETrue);
00037     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,
00038         CEikScrollBarFrame::EAuto);
00039 
00040     ActivateL();
00041         MakeVisible(ETrue);
00042     }
00043 
00044 // Destructor
00045 CContactsModelContainer::~CContactsModelContainer()
00046     {
00047         delete iListBox;
00048         iListBox = NULL;
00049 
00050         if( iListBoxRows )
00051                 {
00052                 iListBoxRows->Reset();
00053                 }
00054         delete iListBoxRows;
00055         iListBoxRows= NULL;
00056     }
00057 
00058 // ---------------------------------------------------------
00059 // CContactsModelContainer::SizeChanged()
00060 // Called by framework when the view size is changed
00061 // ---------------------------------------------------------
00062 //
00063 void CContactsModelContainer::SizeChanged()
00064     {
00065     }
00066 
00067 // ---------------------------------------------------------
00068 // CContactsModelContainer::CountComponentControls() const
00069 // ---------------------------------------------------------
00070 //
00071 TInt CContactsModelContainer::CountComponentControls() const
00072     {
00073     return 1; // return nbr of controls inside this container
00074     }
00075 
00076 // ---------------------------------------------------------
00077 // CContactsModelContainer::ComponentControl(TInt aIndex) const
00078 // ---------------------------------------------------------
00079 //
00080 CCoeControl* CContactsModelContainer::ComponentControl(TInt aIndex) const
00081     {
00082         if( aIndex > 0 )
00083                 {
00084                 return NULL;
00085                 }
00086     return iListBox;
00087     }
00088 
00089 // ---------------------------------------------------------
00090 // CContactsModelContainer::Draw(const TRect& aRect) const
00091 // ---------------------------------------------------------
00092 //
00093 void CContactsModelContainer::Draw(const TRect& /*aRect*/) const
00094     {
00095     CWindowGc& gc = SystemGc();
00096     TRect rect = Rect();
00097     gc.Clear(rect);
00098     }
00099 
00100 // ---------------------------------------------------------
00101 // CContactsModelContainer::HandleControlEventL(
00102 //     CCoeControl* aControl,TCoeEvent aEventType)
00103 // ---------------------------------------------------------
00104 //
00105 void CContactsModelContainer::HandleControlEventL(
00106     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
00107     {
00108     // TODO: Add your control event handler code here
00109     }
00110 
00111 void CContactsModelContainer::UpdateL()
00112     {
00113         iListBoxRows->Reset();
00114         if( iDocument->ItemCount() > 0 )
00115                 {
00116                 //add items to the list box
00117                 for( TInt i = 0; i < iDocument->ItemCount(); ++i )
00118                         {
00119 
00120                         HBufC* row = iDocument->GetItemL(i);
00121                         CleanupStack::PushL(row);
00122 
00123                         TBuf<KBufferSize> buf;
00124                         buf.Format(_L("\t%S"), row);
00125                         iListBoxRows->AppendL(buf);
00126 
00127                         CleanupStack::PopAndDestroy();
00128                         }
00129                 //update the control
00130                 iListBox->HandleItemAdditionL();
00131                 }
00132         }
00133 
00134 // return contacts items number
00135 TInt CContactsModelContainer::ItemCount()
00136 {
00137         return iDocument->ItemCount();
00138 }
00139 
00140 TKeyResponse CContactsModelContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
00141     {
00142     return iListBox->OfferKeyEventL(aKeyEvent, aType);
00143     }
00144 
00145 TInt CContactsModelContainer::GetSelectedItem()
00146         {
00147         return iListBox->CurrentItemIndex();
00148         }
00149 
00150 // End of File

Generated by  doxygen 1.6.2