examples/ForumNokia/CalendarExample/src/CalendarAPIexampleEntriesContainer.cpp

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 // INCLUDE FILES
00031 #include "CalendarAPIexampleEntriesContainer.h"
00032 #include "CalendarAPIexampleEngine.h"
00033 #include "CalendarAPIexampleAppUi.h"
00034 #include "CalendarAPIexampleSearchView.h"
00035 
00036 // CONSTANTS
00037 const TInt KMaxEntryItemLength = KMaxNameLength + 25;
00038 const TInt KMaxDateLength = 12;
00039 
00040 // ================= MEMBER FUNCTIONS =======================
00041 
00042 // constructor
00043 CCalendarAPIexampleEntriesContainer::CCalendarAPIexampleEntriesContainer(
00044         CCalendarAPIexampleEntriesView& aView, 
00045         MCalendarEngineCommandsInterface& aEngine) :
00046         iEntriesView(aView), iEngine(aEngine)
00047         {
00048         }
00049         
00050 // destructor
00051 CCalendarAPIexampleEntriesContainer::~CCalendarAPIexampleEntriesContainer()
00052     {
00053     delete iEntryListBox;
00054     iEntryListBox=NULL;
00055     }
00056     
00057 // Two-phased constructor.
00058 CCalendarAPIexampleEntriesContainer* CCalendarAPIexampleEntriesContainer::NewL(
00059                                         const TRect& aRect,
00060                                         CCalendarAPIexampleEntriesView& aView,
00061                                         MCalendarEngineCommandsInterface& aEngine)
00062     {
00063     CCalendarAPIexampleEntriesContainer* self = 
00064         new (ELeave) CCalendarAPIexampleEntriesContainer(aView, aEngine);
00065     CleanupStack::PushL(self);
00066     self->ConstructL(aRect);
00067     CleanupStack::Pop(self);
00068     return self;
00069     }
00070     
00071 // Symbian OS default constructor can leave.    
00072 void CCalendarAPIexampleEntriesContainer::ConstructL(const TRect& aRect)
00073     {
00074     CreateWindowL();    
00075 
00076     iEntryListBox = new (ELeave) CAknDoubleNumberStyleListBox;
00077     iEntryListBox->SetContainerWindowL(*this);  
00078     iEntryListBox->ConstructL(this, EAknListBoxSelectionList);
00079     // To get event in HandleListBoxEventL()
00080     iEntryListBox->SetListBoxObserver(this);
00081     iEntryListBox->CreateScrollBarFrameL(ETrue);
00082     iEntryListBox->ScrollBarFrame()->SetScrollBarVisibilityL(   
00083                                             CEikScrollBarFrame::EOff,
00084                                             CEikScrollBarFrame::EAuto);
00085     PopulateListBoxL();
00086     SetRect(aRect);
00087     ActivateL();    
00088     }
00089     
00090 
00091     
00092 // ----------------------------------------------------
00093 // CCalendarAPIexampleEntriesContainer::CountComponentControls()
00094 // Gets the number of controls contained in a compound 
00095 // control. 
00096 // ----------------------------------------------------
00097 //
00098 TInt CCalendarAPIexampleEntriesContainer::CountComponentControls() const
00099     {
00100     TInt count = 0;
00101     if (iEntryListBox)
00102         count++;
00103     return count;
00104     }
00105     
00106 // ----------------------------------------------------
00107 // CCalendarAPIexampleEntriesContainer::ComponentControl()
00108 // Gets the specified component of a compound control.
00109 // ----------------------------------------------------
00110 //  
00111 CCoeControl* CCalendarAPIexampleEntriesContainer::ComponentControl(
00112                                                         TInt /*aIndex*/) const
00113     {
00114     return iEntryListBox;
00115     }
00116     
00117 // ----------------------------------------------------
00118 // CCalendarAPIexampleEntriesContainer::OfferKeyEventL()
00119 // When a key event occurs, the control framework calls 
00120 // this function for each control on the control stack, 
00121 // until one of them can process the key event 
00122 // (and returns EKeyWasConsumed).
00123 // ----------------------------------------------------
00124 //      
00125 TKeyResponse CCalendarAPIexampleEntriesContainer::OfferKeyEventL(   
00126                                                     const TKeyEvent& aKeyEvent,
00127                                                     TEventCode aType )
00128     {
00129     if(aType != EEventKey)
00130         {
00131         return EKeyWasNotConsumed;
00132         }    
00133     else if(iEntryListBox)
00134         {
00135         return iEntryListBox->OfferKeyEventL( aKeyEvent, aType );
00136         }
00137     else
00138         {
00139         return EKeyWasNotConsumed;
00140         }   
00141     }   
00142     
00143 // ----------------------------------------------------
00144 // CCalendarAPIexampleEntriesContainer::PopulateListBoxL()
00145 // Get all found entries from model, format their data
00146 // for listbox and show them.
00147 // ----------------------------------------------------
00148 //  
00149 void CCalendarAPIexampleEntriesContainer::PopulateListBoxL()
00150     {
00151     CDesCArray* entryArray = static_cast<CDesCArray*>(
00152         iEntryListBox->Model()->ItemTextArray()
00153         );
00154         
00155     entryArray->Reset();
00156 
00157     TInt entryCount = iEngine.EntryCount();
00158     
00159     for (TInt i = 0; i < entryCount; i++)
00160         {
00161         const CCalHelperEntry& entry = iEngine.Entry(i);
00162         
00163         
00164         
00165         TBuf<KMaxDateLength> entryDate;
00166         _LIT(KDateFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3");
00167         TTime date(entry.Date());
00168         date.FormatL(entryDate, KDateFormat);
00169         
00170         _LIT(KEntryFormat, "%d\t%S\t%S \t");
00171         TBuf<KMaxEntryItemLength> entryItem;
00172         TBuf<KMaxNameLength> name = entry.Name();
00173         
00174         entryItem.Format(KEntryFormat, i+1, &name, &entryDate);
00175         entryArray->AppendL(entryItem);
00176         }
00177         
00178     iEntryListBox->HandleItemAdditionL();
00179     iEntryListBox->SetCurrentItemIndex(0);
00180     }
00181     
00182 // ----------------------------------------------------
00183 // CCalendarAPIexampleEntriesContainer::CurrentItemIndex()
00184 // Returns the index of the entry currently selected on 
00185 // the listbox.
00186 // ----------------------------------------------------
00187 //  
00188 TInt CCalendarAPIexampleEntriesContainer::CurrentItemIndex() const
00189     {
00190     return iEntryListBox->CurrentItemIndex();
00191     }
00192     
00193 // ----------------------------------------------------
00194 // CCalendarAPIexampleEntriesContainer::HandleListBoxEventL()
00195 // Handles listbox events.
00196 // ----------------------------------------------------
00197 //  
00198 void CCalendarAPIexampleEntriesContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
00199     {
00200     if (aEventType == EEventEnterKeyPressed  || aEventType == EEventItemDoubleClicked)
00201         {
00202         iEntriesView.HandleCommandL(ECalendarAPIexampleCmdEdit);
00203         }
00204     }
00205 
00206 // ----------------------------------------------------
00207 // CCalendarAPIexampleEntriesContainer::SizeChanged()
00208 // Responds to size changes to sets the size and 
00209 // position of the contents of this control. 
00210 // ----------------------------------------------------
00211 //              
00212 void CCalendarAPIexampleEntriesContainer::SizeChanged()
00213     {
00214     iEntryListBox->SetRect(Rect());
00215     }
00216 
00217 void CCalendarAPIexampleEntriesContainer::HandleResourceChange(TInt aType)
00218     {
00219     CCoeControl::HandleResourceChange(aType);
00220     if ( aType==KEikDynamicLayoutVariantSwitch )
00221         {
00222         TRect rect;
00223         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00224         SetRect(rect);
00225         }
00226     }
00227 
00228 // End of File

Generated by  doxygen 1.6.2