examples/SFExamples/Wikipedia/src/SearchView.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 
00018 
00019 // INCLUDE FILES
00020 #include <aknviewappui.h>
00021 #include <aknconsts.h>
00022 #include <aknutils.h> 
00023 #include <SqlSrvDemo.rsg>
00024 
00025 #include "SearchView.h"
00026 #include "SearchContainer.h"
00027 #include "RecCountContainer.h"
00028 #include "SqlSrvDemo.hrh"
00029 
00030 
00031 // ========================= MEMBER FUNCTIONS ==================================
00032 
00033 // -----------------------------------------------------------------------------
00034 // CSearchView::CSearchView()
00035 // C++ default constructor can NOT contain any code, that might leave.
00036 // -----------------------------------------------------------------------------
00037 //
00038 CSearchView::CSearchView()
00039     {
00040     // No implementation required
00041     }
00042 
00043 
00044 // -----------------------------------------------------------------------------
00045 // CSearchView::NewL()
00046 // Two-phased constructor.
00047 // -----------------------------------------------------------------------------
00048 //
00049 CSearchView* CSearchView::NewL()
00050     {
00051     CSearchView* self = CSearchView::NewLC();
00052     CleanupStack::Pop( self );
00053     return self;
00054     }
00055 
00056 // -----------------------------------------------------------------------------
00057 // CSearchView::NewLC()
00058 // Two-phased constructor.
00059 // -----------------------------------------------------------------------------
00060 //
00061 CSearchView* CSearchView::NewLC()
00062     {
00063     CSearchView* self = new ( ELeave ) CSearchView();
00064     CleanupStack::PushL( self );
00065     self->ConstructL();
00066     return self;
00067     }
00068 
00069 // -----------------------------------------------------------------------------
00070 // CSearchView::ConstructL()
00071 // Symbian 2nd phase constructor can leave.
00072 // -----------------------------------------------------------------------------
00073 //
00074 void CSearchView::ConstructL()
00075     {
00076     BaseConstructL( R_SEARCH_VIEW );
00077     }
00078 
00079 // -----------------------------------------------------------------------------
00080 // CSearchView::~CSearchView()
00081 // Destructor.
00082 // -----------------------------------------------------------------------------
00083 //
00084 CSearchView::~CSearchView()
00085     {
00086     delete iContainer;
00087     iContainer = NULL;
00088     delete iRecCountContainer;
00089     iRecCountContainer = NULL;
00090     }
00091 
00092 // -----------------------------------------------------------------------------
00093 // CSearchView::Id()
00094 // Returns View's ID.
00095 // -----------------------------------------------------------------------------
00096 //
00097 TUid CSearchView::Id() const
00098     {
00099     return TUid::Uid( ESearchViewId );
00100     }
00101 
00102 // -----------------------------------------------------------------------------
00103 // CSearchView::DoActivateL()
00104 // Activate a CSearchView
00105 // -----------------------------------------------------------------------------
00106 //
00107 void CSearchView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
00108                                     TUid /*aCustomMessageId*/,
00109                                     const TDesC8& /*aCustomMessage*/)
00110     {
00111     if ( !iRecCountContainer )
00112         {
00113         iRecCountContainer = CRecCountContainer::NewL( RecCountRect(), *this );    
00114         }
00115     AppUi()->AddToStackL( iRecCountContainer ); 
00116     
00117     if ( !iContainer )
00118         {       
00119         iContainer = CSearchContainer::NewL( SearchRect(), *this, *iRecCountContainer );    
00120         }
00121     AppUi()->AddToStackL( iContainer );
00122     iContainer->RefreshL();   
00123     }
00124 
00125 // -----------------------------------------------------------------------------
00126 // CSearchView::DoDeactivate()
00127 // DeActivate a CSearchView
00128 // -----------------------------------------------------------------------------
00129 //
00130 void CSearchView::DoDeactivate()
00131     {
00132     if ( iRecCountContainer )
00133         {
00134         // Remove search view's container form controllStack
00135         AppUi()->RemoveFromStack( iRecCountContainer );
00136         } 
00137     if ( iContainer )
00138         {
00139         // Remove search view's container form controllStack
00140         AppUi()->RemoveFromStack( iContainer );
00141         }
00142     }
00143 
00144 // -----------------------------------------------------------------------------
00145 // CSearchView::DynInitMenuPaneL()
00146 // Dynamically initialises a menu pane
00147 // -----------------------------------------------------------------------------
00148 //
00149 void CSearchView::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane *aMenuPane )
00150         {
00151     if ( aResourceId == R_SQLSRVDEMO_SEARCH_MENU  )
00152         {
00153         aMenuPane->SetItemDimmed( ESqlSrvDemoCmdOpenArticle, iContainer->ZeroItemsInList() );
00154         }       
00155         }
00156 
00157 // -----------------------------------------------------------------------------
00158 // CSearchView::HandleCommandL()
00159 // Takes care of Command handling.
00160 // -----------------------------------------------------------------------------
00161 //
00162 void CSearchView::HandleCommandL( TInt aCommand )
00163     {
00164     switch ( aCommand )
00165             {           
00166             case ESqlSrvDemoCmdOpenArticle:
00167                 iContainer->HandleSelectCommandL();
00168                 break;
00169                 
00170             case ESqlSrvDemoCmdAbout:
00171                 iContainer->RefreshL(ETrue);
00172                 OpenAboutViewL();
00173                 break;
00174         
00175             default:
00176                 AppUi()->HandleCommandL( aCommand );    
00177                 break;
00178             }
00179     }
00180 
00181 // -----------------------------------------------------------------------------
00182 // CSearchView::HandleSizeChange()
00183 // Called by HandleResourceChangeL() from CSqlSrvDemoAppUi when layout is 
00184 // changed.
00185 // -----------------------------------------------------------------------------
00186 //
00187 void CSearchView::HandleSizeChange( TInt aType )
00188     {
00189     if( iContainer )
00190         {
00191         iContainer->HandleResourceChange( aType );
00192         
00193         if ( aType==KEikDynamicLayoutVariantSwitch )
00194             {        
00195             TRect rect;
00196             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
00197             iContainer->SetRect( SearchRect() /* rect */);
00198             }
00199         }     
00200     
00201     if( iRecCountContainer )
00202         {
00203         iRecCountContainer->HandleResourceChange( aType );
00204         
00205         if ( aType==KEikDynamicLayoutVariantSwitch )
00206             {        
00207             TRect rect;
00208             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
00209             iRecCountContainer->SetRect( RecCountRect() /* rect */);
00210             }
00211         }     
00212     }
00213     
00214 void CSearchView::OpenDetailViewL()
00215         {
00216     AppUi()->ActivateLocalViewL( TUid::Uid( EDetailViewId ) );
00217         }
00218 
00219 void CSearchView::OpenAboutViewL()
00220         {
00221     AppUi()->ActivateLocalViewL( TUid::Uid( EAboutViewId ) );   
00222         }
00223 
00224 TRect CSearchView::SearchRect()
00225         {
00226         return TRect( ClientRect().iTl.iX, ClientRect().iTl.iY, ClientRect().iBr.iX, ClientRect().iBr.iY - KRecCountHeight );
00227 
00228         }
00229 
00230 TRect CSearchView::RecCountRect()
00231         {
00232         return ClientRect();
00233         }
00234 
00235 // End of File

Generated by  doxygen 1.6.2