00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
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 
00038 
00039 
00040 
00041 
00042 
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 
00054 
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 
00067 
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         
00091         }
00092 
00093 void CRecCountContainer::Draw( const TRect&  ) 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                 
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 
00116 
00117 
00118 
00119 TInt CRecCountContainer::CountComponentControls() const
00120     {
00121     return 0;
00122     }
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 CCoeControl* CRecCountContainer::ComponentControl( TInt aIndex ) const
00131     {
00132     switch ( aIndex )
00133             {
00134             default:
00135                 return NULL;
00136             }
00137     }
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 void CRecCountContainer::SizeChanged()
00146     {    
00147     if ( iBackground )
00148         {
00149         iBackground->SetRect( Rect() );
00150         }    
00151     }
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 void CRecCountContainer::HandleResourceChange( TInt aType )
00160     {
00161 
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