S60 3rd Edition SDK for Symbian OS
Example Applications Guide

IMOpenAPIExampleContainer.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : IMOpenAPIExampleContainer.cpp
00004 *  Part of     : IMOpenAPIExample
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2005-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include "IMOpenAPIExampleContainer.h"
00018 #include "IMOpenAPIExampleImg.h"
00019 #include "IMOpenAPIExampleGrid.h"
00020 #include "IMOpenAPIExamplemodel.h"
00021 
00022 #include <eiklabel.h>
00023 #include <e32base.h> 
00024 #include <stringloader.h>
00025 #include <e32des16.h>
00026 #include <akniconutils.h>
00027 #include <barsread.h>
00028 #include <COECNTRL.H>
00029 #include <AknAppUi.h>
00030 #include <IMOpenAPIExample.rsg>
00031 
00032 // CONSTANTS
00033 
00034 // This is the file where we have our bitmaps
00035 _LIT (KImageFileName, "mysigns.mbm");
00036 
00037 // The location of the above file changes in the emulator and target builds.
00038 #if defined(__WINS__) && defined(_DEBUG)
00039         _LIT( KImageFilePath, "z:\\resource\\apps\\" );
00040 #else
00041 // drive-neutral path (MMC-installations safe)
00042         _LIT( KImageFilePath, "\\resource\\apps\\");
00043 #endif
00044 
00045 // ================= MEMBER FUNCTIONS =======================
00046 
00047 // ---------------------------------------------------------
00048 // CIMOpenAPIExampleContainer::ConstructL(const TRect& aRect)
00049 // EPOC two phased constructor
00050 // ---------------------------------------------------------
00051 //
00052 void CIMOpenAPIExampleContainer::ConstructL(const TRect& aRect)
00053     {
00054     CreateWindowL();
00055 
00056 
00057         iMySign = EZeroSign;
00058 
00059     iTurnIndicator = new (ELeave) CEikLabel;
00060     iTurnIndicator->SetContainerWindowL( *this );
00061     iTurnIndicator->SetTextL(KNullDesC);
00062 
00063     iSignIndicator = new (ELeave) CEikLabel;
00064     iSignIndicator->SetContainerWindowL( *this );
00065     iSignIndicator->SetTextL(KNullDesC);
00066 
00067         
00068         iCrossSign = new (ELeave) CFbsBitmap;
00069         iZeroSign = new (ELeave) CFbsBitmap;
00070         iEmptySign = new (ELeave) CFbsBitmap;
00071         iMySignBMP = new (ELeave) CFbsBitmap;
00072         
00073     iImageFileName = KImageFilePath;
00074     iImageFileName.Append(KImageFileName);
00075         LoadMySignBMPL(iImageFileName);
00076         
00077         // Construct the grid
00078         iGamesGrid = new (ELeave)CIMOpenAPIExampleGrid;
00079         iGamesGrid->SetContainerWindowL(*this);
00080         iGamesGrid->ConstructL(R_IMOPENAPIEXAMPLE_GRID, iImageFileName);
00081         
00082 
00083         SetRect(aRect);
00084     ActivateL();
00085     }
00086 
00087 // ---------------------------------------------------------
00088 // CIMOpenAPIExampleContainer::~CIMOpenAPIExampleContainer()
00089 // Destructor
00090 // ---------------------------------------------------------
00091 //
00092 CIMOpenAPIExampleContainer::~CIMOpenAPIExampleContainer()
00093     {
00094     delete iTurnIndicator;
00095     iTurnIndicator = NULL;
00096     
00097     delete iSignIndicator;
00098     iSignIndicator = NULL;
00099         
00100     delete iCrossSign;
00101     iCrossSign = NULL;
00102 
00103         delete iMySignBMP;
00104     iMySignBMP = NULL;
00105         
00106     delete iZeroSign;
00107     iZeroSign = NULL;
00108     
00109     delete iEmptySign;
00110     iEmptySign = NULL;
00111         
00112     delete iGamesGrid;
00113     iGamesGrid = NULL;
00114     
00115     }
00116 
00117 // ---------------------------------------------------------
00118 // CIMOpenAPIExampleContainer::SizeChanged()
00119 // Called by framework when the view size is changed
00120 // ---------------------------------------------------------
00121 //
00122 void CIMOpenAPIExampleContainer::SizeChanged()
00123     {
00124     TSize selectedImageSize( 91, 91);
00125     TPoint selectedImageTopLeft( 70, 80 );
00126         
00127         iTurnIndicator->SetExtent( TPoint(1,2), iTurnIndicator->MinimumSize() );
00128     iSignIndicator->SetExtent( TPoint(1,30), iSignIndicator->MinimumSize() );
00129         
00130     if (iGamesGrid)
00131                 {
00132                 iGamesGrid->SetExtent (selectedImageTopLeft,selectedImageSize);
00133                 }
00134 
00135     }
00136 
00137 // ---------------------------------------------------------
00138 // CIMOpenAPIExampleContainer::CountComponentControls() const
00139 // ---------------------------------------------------------
00140 //
00141 TInt CIMOpenAPIExampleContainer::CountComponentControls() const
00142     {
00143     return 3; // return nbr of controls inside this container
00144     }
00145 
00146 // ---------------------------------------------------------
00147 // CIMOpenAPIExampleContainer::ComponentControl(TInt aIndex) const
00148 // ---------------------------------------------------------
00149 //
00150 CCoeControl* CIMOpenAPIExampleContainer::ComponentControl(TInt aIndex) const
00151     {
00152     switch ( aIndex )
00153         {
00154         case 0:
00155             return iTurnIndicator;
00156         case 1:
00157             return iSignIndicator;
00158         case 2:
00159                         return iGamesGrid;
00160         default:
00161             return NULL;
00162         }
00163     }
00164 
00165 // ---------------------------------------------------------
00166 // CIMOpenAPIExampleContainer::Draw(const TRect& aRect) const
00167 // ---------------------------------------------------------
00168 //
00169 void CIMOpenAPIExampleContainer::Draw(const TRect& aRect) const
00170     {
00171     CWindowGc& gc = SystemGc();
00172 
00173     gc.SetPenStyle( CGraphicsContext::ESolidPen );
00174     gc.SetBrushColor( KRgbGreen );
00175     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00176     gc.DrawRect( aRect );
00177 
00178         // Drawing my sign
00179         TSize selectedImageSize( 15, 15 );
00180     TPoint selectedImageTopLeft( 160, 35 );
00181         TRect mySignPlace( selectedImageTopLeft, selectedImageSize );
00182     gc.DrawBitmap( mySignPlace, iMySignBMP );
00183 
00184 
00185     }
00186 
00187 // ---------------------------------------------------------
00188 // CIMOpenAPIExampleContainer::HandleControlEventL(
00189 //     CCoeControl* aControl,TCoeEvent aEventType)
00190 // ---------------------------------------------------------
00191 //
00192 void CIMOpenAPIExampleContainer::HandleControlEventL(
00193     CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/)
00194     {
00195     }
00196 
00197 // ---------------------------------------------------------
00198 // CIMOpenAPIExampleContainer::LoadMySignBMP()
00199 // Loads BMP required to display my sign, 1=*, 0=0
00200 // ---------------------------------------------------------
00201 //
00202 void CIMOpenAPIExampleContainer::LoadMySignBMPL(const TDesC& aImageFile)
00203         {
00204         TInt err;
00205 
00206     err = iCrossSign->Load( aImageFile, 0, ETrue);
00207         User::LeaveIfError(err);
00208 
00209     err = iZeroSign->Load( aImageFile, 1, ETrue);
00210         User::LeaveIfError(err);
00211 
00212     err = iEmptySign->Load( aImageFile, 2, ETrue);
00213         User::LeaveIfError(err);
00214 
00215     err = iMySignBMP->Load( aImageFile, iMySign, ETrue);
00216         User::LeaveIfError(err);
00217 
00218         }
00219         
00220 // ---------------------------------------------------------
00221 // CIMOpenAPIExampleContainer::OfferKeyEventL
00222 // ---------------------------------------------------------
00223 //
00224 TKeyResponse CIMOpenAPIExampleContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
00225         {
00226         
00227         // if it's not an event key we're not interested so return not consumed
00228         if (aType != EEventKey)
00229                 return EKeyWasNotConsumed;
00230         
00231         TInt code = aKeyEvent.iCode;
00232 
00233     if ( iGamesGrid && ( !iGamesGrid->IsDimmed() ) ) //&& iGamesGrid->IsFocused()) 
00234         {
00235         if ( code == EKeyOK)
00236             {
00237             PlayMove();
00238             return( EKeyWasConsumed );
00239             }
00240                 else
00241                     {
00242                         TKeyResponse returnValue = iGamesGrid->OfferKeyEventL( aKeyEvent, aType );
00243                     DrawNow();
00244                     return returnValue;
00245             }
00246         }
00247         
00248         return EKeyWasNotConsumed;
00249         }
00250         
00251 // ---------------------------------------------------------
00252 // CIMOpenAPIExampleContainer::PlayMove
00253 // ---------------------------------------------------------
00254 //
00255 void CIMOpenAPIExampleContainer::PlayMove()
00256     {
00257     TInt currentIndex = iGamesGrid->CurrentDataIndex();
00258     if ( iModel->IsIndexPositionEmpty(currentIndex) )
00259         {
00260         SetCellSign(iMySign, currentIndex);
00261         iModel->SendPlayedIndex(currentIndex);
00262         }
00263     }
00264     
00265 // ---------------------------------------------------------
00266 // CIMOpenAPIExampleContainer::SetCellSign
00267 // ---------------------------------------------------------
00268 //
00269 void CIMOpenAPIExampleContainer::SetCellSign(TGameSign aCellSign, TInt aCellIndex)
00270         {
00271     iGamesGrid->SetCellSign(aCellSign, aCellIndex);
00272     DrawNow();
00273         }
00274         
00275 // ---------------------------------------------------------
00276 // CIMOpenAPIExampleContainer::SetMySign
00277 // ---------------------------------------------------------
00278 //
00279 void CIMOpenAPIExampleContainer::SetMySign(const TGameSign mysign)
00280         {
00281         iMySign = mysign;
00282         LoadMySignBMPL(iImageFileName);
00283         DrawNow();      
00284         }
00285         
00286 // ---------------------------------------------------------
00287 // CIMOpenAPIExampleContainer::SetGameView
00288 // ---------------------------------------------------------
00289 //
00290 void CIMOpenAPIExampleContainer::SetGameView(const TGameState desiredView)
00291         {
00292     TBuf<25> iTurnIndicatorString(KNullDesC);
00293         TBuf<25> iSignIndicatorString(KNullDesC);
00294     
00295         switch (desiredView)
00296                 {
00297                 case EStateNotLogin:
00298                         iGamesGrid->MakeVisible(EFalse);
00299                         iSignIndicator->MakeVisible(EFalse);
00300                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_NOT_LOGGEDIN );
00301                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00302                         break;
00303 
00304                 case EStateLoginIdle:
00305                         iGamesGrid->MakeVisible(EFalse);
00306                         iSignIndicator->MakeVisible(EFalse);
00307                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_LOGIN_SUCCESS );
00308                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00309                         break;
00310 
00311                 case EStateChallenged:
00312                         iGamesGrid->MakeVisible(EFalse);
00313                         iSignIndicator->MakeVisible(EFalse);
00314                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_WAITING_FOR_REPLY );
00315                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00316                         break;
00317 
00318                 case EStateReadytoStart:
00319             {
00320                         iGamesGrid->MakeVisible(ETrue);
00321             iGamesGrid->SetDimmed(ETrue);
00322                         iSignIndicator->MakeVisible(ETrue);
00323                         StringLoader::Load ( iSignIndicatorString, R_INFO_MSG_YOUR_SIGN_IS );
00324                         iSignIndicator->SetTextL(iSignIndicatorString);
00325             if (iMySign == ECrossSign)
00326                 StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_START_GAME );
00327             else
00328                 StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_WAITING_OPP_TO_START );
00329                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00330                         iGamesGrid->ResetGrid();
00331                         break;
00332             }
00333 
00334                 case EStateWaitingForOppMove:
00335                         iGamesGrid->MakeVisible(ETrue);
00336                         iGamesGrid->SetDimmed(ETrue);
00337                         iSignIndicator->MakeVisible(ETrue);
00338                         StringLoader::Load ( iSignIndicatorString, R_INFO_MSG_YOUR_SIGN_IS );
00339                         iSignIndicator->SetTextL(iSignIndicatorString);
00340                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_OPPONENT_MOVE );
00341                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00342                         break;
00343 
00344 
00345                 case EStateWaitingForOwnMove:
00346                         iGamesGrid->MakeVisible(ETrue);
00347                         iGamesGrid->SetDimmed(EFalse);
00348                         iSignIndicator->MakeVisible(ETrue);
00349                         StringLoader::Load ( iSignIndicatorString, R_INFO_MSG_YOUR_SIGN_IS );
00350                         iSignIndicator->SetTextL(iSignIndicatorString);
00351                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_YOUR_MOVE );
00352                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00353                         break;
00354 
00355                 default:
00356                         break;
00357                 }
00358 
00359         SizeChanged();
00360         DrawNow();
00361         return;
00362         }
00363         
00364 // ---------------------------------------------------------
00365 // CIMOpenAPIExampleContainer::SetModel
00366 // ---------------------------------------------------------
00367 //      
00368 void CIMOpenAPIExampleContainer::SetModel(CIMOpenAPIExamplemodel* aModel)
00369     {
00370     iModel = aModel;
00371     }
00372     
00373 // ---------------------------------------------------------
00374 // CIMOpenAPIExampleContainer::ActivateL
00375 // ---------------------------------------------------------
00376 //      
00377 void CIMOpenAPIExampleContainer::ActivateL()
00378         {
00379         CCoeControl::ActivateL();
00380         if(iCba)
00381                 {
00382                 iCba->DrawableWindow()->SetOrdinalPosition(0);
00383                 }
00384         else
00385                 {
00386                 iAvkonAppUi->Cba()->DrawableWindow()->SetOrdinalPosition(0);
00387                 }
00388         }
00389     
00390 // End of File  
00391 

© Nokia 2006

Back to top