00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <eiklabel.h>
00032 #include <barsread.h>
00033
00034 #include "OandXDefs.h"
00035 #include "OandXAppUi.h"
00036 #include "OandXApplication.h"
00037 #include "OandXController.h"
00038 #include "OandXHistView.h"
00039 #include "OandX.hrh"
00040 #include "OandX.pan"
00041 #include <OandX.rsg>
00042
00043
00044
00045 COandXHistoryView* COandXHistoryView::NewLC()
00046 {
00047 COandXHistoryView* self=new(ELeave) COandXHistoryView();
00048 CleanupStack::PushL(self);
00049 self->ConstructL();
00050 return self;
00051 }
00052
00053 COandXHistoryView::COandXHistoryView()
00054 {
00055 }
00056
00060 COandXHistoryView::~COandXHistoryView()
00061 {
00062 if (iHistViewStacked)
00063 {
00064 AppUi()->RemoveFromViewStack( *this, iContainer );
00065 }
00066 delete iContainer;
00067 }
00068
00069 void COandXHistoryView::ConstructL()
00070 {
00071 BaseConstructL( R_OANDX_HISTORY_VIEW );
00072 iContainer = COandXHistViewContainer::NewL(ClientRect()) ;
00073 }
00074
00075
00079 TUid COandXHistoryView::Id() const
00080 {
00081 return KUidOandXHistoryView;
00082 }
00083
00084
00085
00086
00087 void COandXHistoryView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
00088 {
00089 if (aResourceId == R_OANDX_HISTORY_MENU)
00090 {
00091 if (IsDisplayingHistory())
00092 {
00093 aMenuPane->DeleteMenuItem(EOandXDisplayHistory);
00094 }
00095 else
00096 {
00097 aMenuPane->DeleteMenuItem(EOandXDisplayStats);
00098 }
00099 }
00100 }
00101
00102 COandXHistViewContainer* COandXHistoryView::Container()
00103 {
00104 return iContainer;
00105 }
00106
00107
00108
00109
00110
00111
00112 void COandXHistoryView::HandleCommandL(TInt aCommand)
00113 {
00114 switch ( aCommand )
00115 {
00116
00117 case EAknSoftkeyBack:
00118 {
00119 AppUi()->HandleCommandL( EEikCmdExit );
00120 break;
00121 }
00122
00123 default:
00124 {
00125 AppUi()->HandleCommandL( aCommand );
00126 break;
00127 }
00128 }
00129 }
00130
00131 void COandXHistoryView::HandleViewRectChange()
00132 {
00133 if ( iContainer )
00134 {
00135 iContainer->SetRect(ClientRect());
00136 }
00137 }
00138
00139
00140
00141
00142
00143
00144 void COandXHistoryView::DoActivateL(const TVwsViewId& ,
00145 TUid aCustomMessageId,
00146 const TDesC8& )
00147 {
00148 __ASSERT_ALWAYS(!iHistViewStacked, Panic(EOandXControlAlreadyStacked));
00149 AppUi()->AddToStackL( *this, iContainer );
00150 iHistViewStacked = ETrue;
00151
00152 switch ( aCustomMessageId.iUid )
00153 {
00154
00155 case EHistoryViewDisplayHistory:
00156 ChangeDisplayL( ETrue );
00157 break;
00158 case EHistoryViewDisplayStats:
00159 ChangeDisplayL( EFalse );
00160 break;
00161 default:
00162
00163 ChangeDisplayL( iDisplayingHistory );
00164 break ;
00165 }
00166 iActivated = ETrue;
00167 }
00168
00169
00170
00171
00172
00173
00174 void COandXHistoryView::DoDeactivate()
00175 {
00176 __ASSERT_ALWAYS(iHistViewStacked, Panic(EOandXControlNotStacked));
00177 AppUi()->RemoveFromViewStack( *this, iContainer );
00178 iHistViewStacked = EFalse;
00179
00180 iContainer->MakeVisible(EFalse);
00181 iActivated = EFalse;
00182 }
00183
00184
00185
00186
00187 void COandXHistoryView::ChangeDisplayL( TBool aDisplayHistory )
00188 {
00189 iDisplayingHistory = aDisplayHistory;
00190 iContainer->SetContentL(aDisplayHistory);
00191 iContainer->MakeVisible(ETrue);
00192 }
00193
00194
00195
00196
00197 COandXHistViewContainer* COandXHistViewContainer::NewL(const TRect& aRect)
00198 {
00199 COandXHistViewContainer* self = new (ELeave) COandXHistViewContainer();
00200 CleanupStack::PushL( self );
00201 self->ConstructL(aRect);
00202 CleanupStack::Pop();
00203 return self;
00204 }
00205
00206 COandXHistViewContainer::~COandXHistViewContainer()
00207 {
00208 delete iTitle;
00209 for (TInt i=0; i< KNumDataLines; i++)
00210 {
00211 delete iDataLines[i];
00212 }
00213 }
00214
00215 COandXHistViewContainer::COandXHistViewContainer()
00216 {
00217 }
00218
00219 void COandXHistViewContainer::ConstructL(const TRect& aRect)
00220 {
00221
00222 CreateWindowL();
00223
00224
00225 TResourceReader reader;
00226 iTitle = new (ELeave) CEikLabel();
00227 iTitle->SetContainerWindowL( *this );
00228 iEikonEnv->CreateResourceReaderLC(reader, R_HISTORY_VIEW_LABEL);
00229 iTitle->ConstructFromResourceL(reader);
00230 CleanupStack::PopAndDestroy();
00231
00232 for (TInt i=0; i< KNumDataLines; i++)
00233 {
00234 iDataLines[i] = new (ELeave) CEikLabel();
00235 iDataLines[i]->SetContainerWindowL( *this );
00236 iEikonEnv->CreateResourceReaderLC(reader, R_HISTORY_VIEW_LABEL);
00237 iDataLines[i]->ConstructFromResourceL(reader);
00238 CleanupStack::PopAndDestroy();
00239 iDataLines[i]->SetLabelAlignment(ELayoutAlignLeft);
00240 }
00241
00242 iEikonEnv->ReadResourceL(iNumGamesText, R_HISTORY_VIEW_GAMES_TEXT);
00243 iEikonEnv->ReadResourceL(iNumOWinsText, R_HISTORY_VIEW_OWINS_TEXT);
00244 iEikonEnv->ReadResourceL(iNumXWinsText, R_HISTORY_VIEW_XWINS_TEXT);
00245 iEikonEnv->ReadResourceL(iNumDrawsText, R_HISTORY_VIEW_DRAWN_TEXT);
00246 iEikonEnv->ReadResourceL(iStatOWonText, R_HISTORY_VIEW_O_WINNER_TEXT);
00247 iEikonEnv->ReadResourceL(iStatXWonText, R_HISTORY_VIEW_X_WINNER_TEXT);
00248 iEikonEnv->ReadResourceL(iStatDrawText, R_HISTORY_VIEW_NO_WINNER_TEXT);
00249 iEikonEnv->ReadResourceL(iHistoryTitle, R_HISTORY_VIEW_HISTORY_TITLE);
00250 iEikonEnv->ReadResourceL(iStatsTitle, R_HISTORY_VIEW_STATS_TITLE);
00251
00252
00253 SetRect(aRect);
00254
00255
00256 ActivateL();
00257 }
00258
00259 void COandXHistViewContainer::SizeChanged()
00260 {
00261 TRect rect = Rect();
00262
00263 TInt labelHeight = (rect.iBr.iY - rect.iTl.iY)/(KNumDataLines+1);
00264 rect.iBr.iY = labelHeight;
00265 iTitle->SetRect(rect);
00266 for (TInt i=0; i<KNumDataLines; i++)
00267 {
00268 rect.iTl.iY += labelHeight;
00269 rect.iBr.iY += labelHeight;
00270 iDataLines[i]->SetRect(rect);
00271 }
00272 }
00273
00274 void COandXHistViewContainer::Draw(const TRect& ) const
00275 {
00276 CWindowGc& gc = SystemGc();
00277 gc.Clear();
00278 }
00279
00280 void COandXHistViewContainer::SetContentL( TBool aDisplayHistory )
00281 {
00282 CreateNewItemsL(aDisplayHistory);
00283 DrawNow();
00284 }
00285
00286 void COandXHistViewContainer::CreateNewItemsL(TBool aDisplayHistory)
00287 {
00288
00289 TBuf<KFormatBufSize> itemName;
00290 iEikonEnv->ReadResourceL(itemName, R_HISTORY_VIEW_NO_DATA_TEXT);
00291 for (TInt i=0; i<KNumDataLines; i++)
00292 {
00293 iDataLines[i]->SetTextL(itemName);
00294 }
00295
00296
00297 TUint played = Controller().GamesPlayed();
00298
00299 if (aDisplayHistory)
00300 {
00301
00302 iTitle->SetTextL(iHistoryTitle);
00303
00304 for (TInt i=0; i<KNumHistoryRecords; i++)
00305 {
00306 switch (Controller().GameRecord(i))
00307 {
00308 case ETileNought:
00309 itemName.Format(iStatOWonText, played - i);
00310 break;
00311 case ETileCross:
00312 itemName.Format(iStatXWonText, played - i);
00313 break;
00314 case ETileDraw:
00315 itemName.Format(iStatDrawText, played - i);
00316 break;
00317 default:
00318 iEikonEnv->ReadResourceL(itemName, R_HISTORY_VIEW_NO_DATA_TEXT);
00319 break;
00320 }
00321 iDataLines[i]->SetTextL(itemName);
00322 }
00323 }
00324 else
00325 {
00326
00327 iTitle->SetTextL(iStatsTitle);
00328
00329
00330 itemName.Format(iNumGamesText, played);
00331 iDataLines[0]->SetTextL(itemName);
00332
00333
00334 TUint oWins = Controller().WonByO();
00335 itemName.Format(iNumOWinsText, oWins);
00336 iDataLines[1]->SetTextL(itemName);
00337
00338
00339 TUint xWins = Controller().WonByX();
00340 itemName.Format(iNumXWinsText, xWins);
00341 iDataLines[2]->SetTextL(itemName);
00342
00343
00344 itemName.Format(iNumDrawsText, played - oWins - xWins);
00345 iDataLines[3]->SetTextL(itemName);
00346 }
00347 }
00348
00349 TInt COandXHistViewContainer::CountComponentControls() const
00350 {
00351 return KNumDataLines+1;
00352 }
00353
00354 CCoeControl* COandXHistViewContainer::ComponentControl(TInt aIndex) const
00355 {
00356 if (aIndex==0)
00357 {
00358 return iTitle;
00359 }
00360 else
00361 {
00362 return iDataLines[aIndex-1];
00363 }
00364 }