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

Generated by  doxygen 1.6.2