examples/SFExamples/Wikipedia/src/RecCountContainer.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 "RecCountContainer.h"
00021 #include "SearchView.h"
00022 #include "SqlSrvDemoAppUi.h"
00023 #include "WikiDb.h"
00024 #include <aknutils.h>
00025 #include <aknsutils.h> 
00026 #include <aknsskininstance.h>
00027 #include <aknsbasicbackgroundcontrolcontext.h>
00028 #include <aknsdrawutils.h>
00029 
00030 const TInt KFormatLen = 10;
00031 const TInt KRecBaseFactor = 3;
00032 
00033 _LIT( KNullString, "" );
00034 _LIT( KMultipleRecords, "%D articles found" );
00035 _LIT( KOneRecord, "%D article found" );
00036 
00037 // ========================= MEMBER FUNCTIONS ==================================
00038 
00039 
00040 // -----------------------------------------------------------------------------
00041 // CRecCountContainer::NewL()
00042 // Two-phased constructor.
00043 // -----------------------------------------------------------------------------
00044 //
00045 CRecCountContainer* CRecCountContainer::NewL( const TRect& aRect, CSearchView& aView )
00046     {
00047     CRecCountContainer* self = CRecCountContainer::NewLC( aRect, aView );
00048     CleanupStack::Pop( self );
00049     return self;
00050     }
00051 
00052 // -----------------------------------------------------------------------------
00053 // CRecCountContainer::NewLC()
00054 // Two-phased constructor.
00055 // -----------------------------------------------------------------------------
00056 //
00057 CRecCountContainer* CRecCountContainer::NewLC( const TRect& aRect, CSearchView& aView )
00058     {
00059     CRecCountContainer* self = new ( ELeave ) CRecCountContainer( aView );
00060     CleanupStack::PushL( self );
00061     self->ConstructL( aRect );
00062     return self;
00063     }
00064 
00065 // -----------------------------------------------------------------------------
00066 // CRecCountContainer::ConstructL()
00067 // Symbian 2nd phase constructor can leave.
00068 // -----------------------------------------------------------------------------
00069 //
00070 void CRecCountContainer::ConstructL( const TRect& aRect )
00071     {
00072     iText = KNullString().AllocL();
00073     iBackground = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), ETrue );    
00074     
00075     CreateWindowL();
00076     SetRect( aRect );
00077     ActivateL();
00078     DrawNow();
00079     }
00080 
00081 CRecCountContainer::~CRecCountContainer()
00082         {
00083         delete iText;
00084         delete iBackground;
00085         }
00086 
00087 CRecCountContainer::CRecCountContainer( CSearchView& aView ) :
00088         iView( aView ), iWikiEngine( CSqlSrvDemoAppUi::WikiEngine() )
00089         {
00090         // No implementation required
00091         }
00092 
00093 void CRecCountContainer::Draw( const TRect& /* aRect */ ) const
00094         {
00095         CWindowGc& gc = SystemGc();     
00096     if ( iBackground )
00097         {
00098         MAknsSkinInstance* skin = AknsUtils::SkinInstance();      
00099         if ( !AknsDrawUtils::Background( skin, iBackground, gc, Rect() ) )
00100                 {
00101                 // No background drawn
00102                 }       
00103         }
00104 
00105     const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont );
00106     TRect textRect( Rect().iTl.iX, Rect().iBr.iY - KRecCountHeight, Rect().iBr.iX, ( Rect().iBr.iY ) );
00107     TInt textBaseline = KRecCountHeight - ( KRecCountHeight / KRecBaseFactor );
00108     gc.UseFont( font );
00109     gc.SetPenColor( KRgbWhite );
00110     gc.DrawText( *iText, textRect, textBaseline, CGraphicsContext::ECenter );
00111     gc.DiscardFont();
00112         }
00113 
00114 // -----------------------------------------------------------------------------
00115 // CRecCountContainer::CountComponentControls() const
00116 // returns number of controls inside this container.
00117 // -----------------------------------------------------------------------------
00118 //
00119 TInt CRecCountContainer::CountComponentControls() const
00120     {
00121     return 0;
00122     }
00123 
00124 
00125 // -----------------------------------------------------------------------------
00126 // CRecCountContainer::ComponentControl() const
00127 // returns pointer of controls inside this container
00128 // -----------------------------------------------------------------------------
00129 //
00130 CCoeControl* CRecCountContainer::ComponentControl( TInt aIndex ) const
00131     {
00132     switch ( aIndex )
00133             {
00134             default:
00135                 return NULL;
00136             }
00137     }
00138 
00139 // -----------------------------------------------------------------------------
00140 // CRecCountContainer::SizeChanged
00141 // 
00142 // (other items were commented in a header).
00143 // -----------------------------------------------------------------------------
00144 //
00145 void CRecCountContainer::SizeChanged()
00146     {    
00147     if ( iBackground )
00148         {
00149         iBackground->SetRect( Rect() );
00150         }    
00151     }
00152 
00153 // -----------------------------------------------------------------------------
00154 // CRecCountContainer::HandleResourceChange
00155 // 
00156 // (other items were commented in a header).
00157 // -----------------------------------------------------------------------------
00158 //
00159 void CRecCountContainer::HandleResourceChange( TInt aType )
00160     {
00161 //    // TODO - Handle new rect correctly
00162     CCoeControl::HandleResourceChange( aType );
00163     if ( aType == KEikDynamicLayoutVariantSwitch )
00164         {
00165         SetRect( iView.RecCountRect() );
00166         }
00167     }  
00168 
00169 TTypeUid::Ptr CRecCountContainer::MopSupplyObject( TTypeUid aId )
00170     {
00171     if ( aId.iUid == MAknsControlContext::ETypeId && iBackground )
00172         {
00173         return MAknsControlContext::SupplyMopObject( aId, iBackground );
00174         }
00175 
00176     return CCoeControl::MopSupplyObject( aId );
00177     }
00178 
00179 void CRecCountContainer::SetTextL( TInt aNumRecords )
00180         {
00181         delete iText;
00182         switch ( aNumRecords )
00183                 {
00184                 case -1:
00185                 iText = KNullString().AllocL();
00186                         break;
00187                 
00188                 case 1:
00189                         iText = FormatStringL( KOneRecord, aNumRecords );                       
00190                         break;
00191                         
00192                 default:
00193                         iText = FormatStringL( KMultipleRecords(), aNumRecords );                       
00194                         break;
00195                 }
00196         }
00197 
00198 HBufC* CRecCountContainer::FormatStringL( const TDesC& aString, const TInt aNumber )
00199         {
00200     HBufC* string = HBufC::NewL( aString.Length() + KFormatLen );
00201     string->Des().Format( aString, aNumber );   
00202     return string;
00203         }
00204 
00205 // End of File

Generated by  doxygen 1.6.2