examples/ForumNokia/CalendarExample/src/CalendarAPIexampleSearchContainer.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 // INCLUDE FILES
00006 #include <barsread.h> //TResourceReader
00007 #include <CalendarAPIexample.rsg>
00008 #include "CalendarAPIexampleSearchContainer.h"
00009 #include "CalendarAPIexample.pan"
00010 #include "CalendarAPIexampleAppUi.h"
00011 #include "CalendarAPIexampleSearchView.h"
00012 
00013 // CONSTANTS
00014 const TInt KPoint = 5;
00015 
00016 // ================= MEMBER FUNCTIONS =======================
00017 
00018 // constructor
00019 CCalendarAPIexampleSearchContainer::CCalendarAPIexampleSearchContainer(CCalendarAPIexampleSearchView& aView)
00020     :   iSearchView(aView)
00021         {
00022         }
00023         
00024 // destructor
00025 CCalendarAPIexampleSearchContainer::~CCalendarAPIexampleSearchContainer()
00026     {
00027     }
00028     
00029 // Two-phased constructor.  
00030 CCalendarAPIexampleSearchContainer* CCalendarAPIexampleSearchContainer::NewL(const TRect& aRect,
00031                                                                             CCalendarAPIexampleSearchView& aView)
00032     {
00033     CCalendarAPIexampleSearchContainer* self = new (ELeave) CCalendarAPIexampleSearchContainer(aView);
00034     CleanupStack::PushL(self);
00035     self->ConstructL(aRect);
00036     CleanupStack::Pop(self);
00037     return self;
00038     }
00039 
00040 // Symbian OS default constructor can leave.    
00041 void CCalendarAPIexampleSearchContainer::ConstructL(const TRect& aRect)
00042     {
00043     CreateWindowL();    
00044 
00045     // Initialize component array
00046     InitComponentArrayL();
00047     
00048     iSearchListBox = new (ELeave) CAknSingleStyleListBox;
00049     iSearchListBox->SetContainerWindowL(*this); 
00050 
00051     TResourceReader reader; 
00052     CEikonEnv::Static()->CreateResourceReaderLC(reader, R_CALENDARAPIEXAMPLE_SEARCH_LIST); 
00053     iSearchListBox->ConstructFromResourceL(reader); 
00054     CleanupStack::PopAndDestroy(); //reader
00055 
00056     iSearchListBox->SetListBoxObserver(this);
00057     iSearchListBox->CreateScrollBarFrameL(ETrue);
00058     iSearchListBox->ScrollBarFrame()->SetScrollBarVisibilityL(  CEikScrollBarFrame::EOff,
00059                                                                 CEikScrollBarFrame::EAuto);
00060     
00061     Components().AppendLC(iSearchListBox,1);
00062     CleanupStack::Pop( iSearchListBox );
00063     
00064     SetRect(aRect);
00065     ActivateL();
00066     }
00067 
00068 // ----------------------------------------------------
00069 // CCalendarAPIexampleSearchContainer::SizeChanged()
00070 // Responds to size changes to set the size and 
00071 // position of the contents of this control. 
00072 // ----------------------------------------------------
00073 //      
00074 void CCalendarAPIexampleSearchContainer::SizeChanged()
00075     {
00076     if (iSearchListBox)
00077         {
00078         iSearchListBox->SetRect(Rect());
00079         }
00080     }
00081 
00082 void CCalendarAPIexampleSearchContainer::HandleResourceChange(TInt aType)
00083     {
00084     CCoeControl::HandleResourceChange(aType);
00085     if ( aType==KEikDynamicLayoutVariantSwitch )
00086         {
00087         TRect rect;
00088         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00089         SetRect(rect);
00090         }
00091     }
00092 
00093     
00094 // ----------------------------------------------------
00095 // CCalendarAPIexampleSearchContainer::OfferKeyEventL()
00096 // When a key event occurs, the control framework calls 
00097 // this function for each control on the control stack, 
00098 // until one of them can process the key event 
00099 // (and returns EKeyWasConsumed).
00100 // ----------------------------------------------------
00101 //      
00102 TKeyResponse CCalendarAPIexampleSearchContainer::OfferKeyEventL(
00103                                   const TKeyEvent& aKeyEvent,TEventCode aType)
00104     {
00105     if(aType != EEventKey)
00106         {
00107         return EKeyWasNotConsumed;
00108         }    
00109     else if(iSearchListBox)
00110         {
00111         return iSearchListBox->OfferKeyEventL( aKeyEvent, aType );
00112         }
00113     else
00114         {
00115         return EKeyWasNotConsumed;
00116         }
00117     }
00118 
00119 
00120 // ----------------------------------------------------
00121 // CCalendarAPIexampleSearchContainer::Draw()
00122 // This function is used for window server-initiated 
00123 // redrawing of controls, and for some 
00124 // application-initiated drawing.
00125 // ----------------------------------------------------
00126 //              
00127 void CCalendarAPIexampleSearchContainer::Draw(const TRect& aRect) const
00128     {
00129     
00130     CWindowGc& gc = SystemGc();
00131     gc.SetPenStyle( CGraphicsContext::ENullPen );
00132     gc.SetBrushColor( KRgbWhite );
00133     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00134     gc.DrawRect( aRect );
00135     
00136     }
00137     
00138 // ----------------------------------------------------
00139 // CCalendarAPIexampleSearchContainer::SearchType()
00140 // Returns the selected search range (week, month,...)
00141 // ----------------------------------------------------
00142 //          
00143 TSearchType CCalendarAPIexampleSearchContainer::SearchType() const
00144     {
00145     switch (iSearchListBox->CurrentItemIndex())
00146         {
00147         case 0:
00148             return EWeek;
00149         case 1:
00150             return EMonth;
00151         case 2:
00152             return ESixMonths;
00153         case 3:
00154             return EYear;
00155         default:
00156             Panic(EUnSupportedSearchType);
00157             break;
00158         }
00159     return EWeek;
00160     }    
00161 
00162 // ----------------------------------------------------
00163 // CCalendarAPIexampleSearchContainer::HandleListBoxEventL()
00164 // Handles listbox events.
00165 // ----------------------------------------------------
00166 //  
00167 
00168 void CCalendarAPIexampleSearchContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
00169     {
00170     if (aEventType == EEventEnterKeyPressed  || aEventType == EEventItemSingleClicked)
00171         {
00172         iSearchView.HandleCommandL(ECalendarAPIexampleCmdSearch);
00173         }   
00174     }
00175 
00176 
00177 // end of file

Generated by  doxygen 1.6.2