examples/ForumNokia/CalendarExample/src/CalendarAPIexampleEntriesContainer.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 // INCLUDE FILES
00006 #include "CalendarAPIexampleEntriesContainer.h"
00007 #include "CalendarAPIexampleEngine.h"
00008 #include "CalendarAPIexampleAppUi.h"
00009 #include "CalendarAPIexampleSearchView.h"
00010 
00011 // CONSTANTS
00012 const TInt KMaxEntryItemLength = KMaxNameLength + 25;
00013 const TInt KMaxDateLength = 12;
00014 
00015 // ================= MEMBER FUNCTIONS =======================
00016 
00017 // constructor
00018 CCalendarAPIexampleEntriesContainer::CCalendarAPIexampleEntriesContainer(
00019         CCalendarAPIexampleEntriesView& aView, 
00020         MCalendarEngineCommandsInterface& aEngine) :
00021         iEntriesView(aView), iEngine(aEngine)
00022         {
00023         }
00024         
00025 // destructor
00026 CCalendarAPIexampleEntriesContainer::~CCalendarAPIexampleEntriesContainer()
00027     {
00028     delete iEntryListBox;
00029     iEntryListBox=NULL;
00030     }
00031     
00032 // Two-phased constructor.
00033 CCalendarAPIexampleEntriesContainer* CCalendarAPIexampleEntriesContainer::NewL(
00034                                         const TRect& aRect,
00035                                         CCalendarAPIexampleEntriesView& aView,
00036                                         MCalendarEngineCommandsInterface& aEngine)
00037     {
00038     CCalendarAPIexampleEntriesContainer* self = 
00039         new (ELeave) CCalendarAPIexampleEntriesContainer(aView, aEngine);
00040     CleanupStack::PushL(self);
00041     self->ConstructL(aRect);
00042     CleanupStack::Pop(self);
00043     return self;
00044     }
00045     
00046 // Symbian OS default constructor can leave.    
00047 void CCalendarAPIexampleEntriesContainer::ConstructL(const TRect& aRect)
00048     {
00049     CreateWindowL();    
00050 
00051     iEntryListBox = new (ELeave) CAknDoubleNumberStyleListBox;
00052     iEntryListBox->SetContainerWindowL(*this);  
00053     iEntryListBox->ConstructL(this, EAknListBoxSelectionList);
00054     // To get event in HandleListBoxEventL()
00055     iEntryListBox->SetListBoxObserver(this);
00056     iEntryListBox->CreateScrollBarFrameL(ETrue);
00057     iEntryListBox->ScrollBarFrame()->SetScrollBarVisibilityL(   
00058                                             CEikScrollBarFrame::EOff,
00059                                             CEikScrollBarFrame::EAuto);
00060     PopulateListBoxL();
00061     SetRect(aRect);
00062     ActivateL();    
00063     }
00064     
00065 
00066     
00067 // ----------------------------------------------------
00068 // CCalendarAPIexampleEntriesContainer::CountComponentControls()
00069 // Gets the number of controls contained in a compound 
00070 // control. 
00071 // ----------------------------------------------------
00072 //
00073 TInt CCalendarAPIexampleEntriesContainer::CountComponentControls() const
00074     {
00075     TInt count = 0;
00076     if (iEntryListBox)
00077         count++;
00078     return count;
00079     }
00080     
00081 // ----------------------------------------------------
00082 // CCalendarAPIexampleEntriesContainer::ComponentControl()
00083 // Gets the specified component of a compound control.
00084 // ----------------------------------------------------
00085 //  
00086 CCoeControl* CCalendarAPIexampleEntriesContainer::ComponentControl(
00087                                                         TInt /*aIndex*/) const
00088     {
00089     return iEntryListBox;
00090     }
00091     
00092 // ----------------------------------------------------
00093 // CCalendarAPIexampleEntriesContainer::OfferKeyEventL()
00094 // When a key event occurs, the control framework calls 
00095 // this function for each control on the control stack, 
00096 // until one of them can process the key event 
00097 // (and returns EKeyWasConsumed).
00098 // ----------------------------------------------------
00099 //      
00100 TKeyResponse CCalendarAPIexampleEntriesContainer::OfferKeyEventL(   
00101                                                     const TKeyEvent& aKeyEvent,
00102                                                     TEventCode aType )
00103     {
00104     if(aType != EEventKey)
00105         {
00106         return EKeyWasNotConsumed;
00107         }    
00108     else if(iEntryListBox)
00109         {
00110         return iEntryListBox->OfferKeyEventL( aKeyEvent, aType );
00111         }
00112     else
00113         {
00114         return EKeyWasNotConsumed;
00115         }   
00116     }   
00117     
00118 // ----------------------------------------------------
00119 // CCalendarAPIexampleEntriesContainer::PopulateListBoxL()
00120 // Get all found entries from model, format their data
00121 // for listbox and show them.
00122 // ----------------------------------------------------
00123 //  
00124 void CCalendarAPIexampleEntriesContainer::PopulateListBoxL()
00125     {
00126     CDesCArray* entryArray = static_cast<CDesCArray*>(
00127         iEntryListBox->Model()->ItemTextArray()
00128         );
00129         
00130     entryArray->Reset();
00131 
00132     TInt entryCount = iEngine.EntryCount();
00133     
00134     for (TInt i = 0; i < entryCount; i++)
00135         {
00136         const CCalHelperEntry& entry = iEngine.Entry(i);
00137         
00138         
00139         
00140         TBuf<KMaxDateLength> entryDate;
00141         _LIT(KDateFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3");
00142         TTime date(entry.Date());
00143         date.FormatL(entryDate, KDateFormat);
00144         
00145         _LIT(KEntryFormat, "%d\t%S\t%S \t");
00146         TBuf<KMaxEntryItemLength> entryItem;
00147         TBuf<KMaxNameLength> name = entry.Name();
00148         
00149         entryItem.Format(KEntryFormat, i+1, &name, &entryDate);
00150         entryArray->AppendL(entryItem);
00151         }
00152         
00153     iEntryListBox->HandleItemAdditionL();
00154     iEntryListBox->SetCurrentItemIndex(0);
00155     }
00156     
00157 // ----------------------------------------------------
00158 // CCalendarAPIexampleEntriesContainer::CurrentItemIndex()
00159 // Returns the index of the entry currently selected on 
00160 // the listbox.
00161 // ----------------------------------------------------
00162 //  
00163 TInt CCalendarAPIexampleEntriesContainer::CurrentItemIndex() const
00164     {
00165     return iEntryListBox->CurrentItemIndex();
00166     }
00167     
00168 // ----------------------------------------------------
00169 // CCalendarAPIexampleEntriesContainer::HandleListBoxEventL()
00170 // Handles listbox events.
00171 // ----------------------------------------------------
00172 //  
00173 void CCalendarAPIexampleEntriesContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
00174     {
00175     if (aEventType == EEventEnterKeyPressed  || aEventType == EEventItemSingleClicked)
00176         {
00177         iEntriesView.HandleCommandL(ECalendarAPIexampleCmdEdit);
00178         }
00179     }
00180 
00181 // ----------------------------------------------------
00182 // CCalendarAPIexampleEntriesContainer::SizeChanged()
00183 // Responds to size changes to sets the size and 
00184 // position of the contents of this control. 
00185 // ----------------------------------------------------
00186 //              
00187 void CCalendarAPIexampleEntriesContainer::SizeChanged()
00188     {
00189     iEntryListBox->SetRect(Rect());
00190     }
00191 
00192 void CCalendarAPIexampleEntriesContainer::HandleResourceChange(TInt aType)
00193     {
00194     CCoeControl::HandleResourceChange(aType);
00195     if ( aType==KEikDynamicLayoutVariantSwitch )
00196         {
00197         TRect rect;
00198         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00199         SetRect(rect);
00200         }
00201     }
00202 
00203 // End of File

Generated by  doxygen 1.6.2