S60UIExampleInitialView.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:6k
源码类别:

Symbian

开发平台:

C/C++

  1. // Copyright (c) 2006 Nokia Corporation.
  2. #include "S60UIExampleInitialView.h"
  3. #include "S60UIExampleInitialContainer.h"
  4. #include "S60UIExampleModel.h"
  5. #include "S60UIExample.hrh"
  6. #include <aknviewappui.h>
  7. #include <S60UIExample.rsg>
  8. #include <eikmenup.h>         // for CEikMenuPane
  9. // -----------------------------------------------------------------------------
  10. // CS60UIExampleInitialView::CS60UIExampleInitialView()
  11. // C++ default constructor can NOT contain any code, that might leave.
  12. // -----------------------------------------------------------------------------
  13. //
  14. CS60UIExampleInitialView::CS60UIExampleInitialView(CS60UIExampleModel& aModel)
  15.     :iModel(aModel)
  16.     {
  17.     // No implementation required
  18.     }
  19. // -----------------------------------------------------------------------------
  20. // CS60UIExampleInitialView::NewL()
  21. // Two-phased constructor.
  22. // -----------------------------------------------------------------------------
  23. //
  24. CS60UIExampleInitialView* CS60UIExampleInitialView::NewL(
  25.                                                  CS60UIExampleModel& aModel)
  26.     {
  27.     CS60UIExampleInitialView* self = CS60UIExampleInitialView::NewLC(aModel);
  28.     CleanupStack::Pop(self);
  29.     return self;
  30.     }
  31. // -----------------------------------------------------------------------------
  32. // CS60UIExampleInitialView::NewLC()
  33. // Two-phased constructor.
  34. // -----------------------------------------------------------------------------
  35. //
  36. CS60UIExampleInitialView* CS60UIExampleInitialView::NewLC(
  37.                                                  CS60UIExampleModel& aModel)
  38.     {
  39.     CS60UIExampleInitialView* self = 
  40.                           new (ELeave) CS60UIExampleInitialView(aModel);
  41.     CleanupStack::PushL(self);
  42.     self->ConstructL();
  43.     return self;
  44.     }
  45. // -----------------------------------------------------------------------------
  46. // CS60UIExampleInitialView::ConstructL()
  47. // Symbian 2nd phase constructor can leave.
  48. // -----------------------------------------------------------------------------
  49. //
  50. void CS60UIExampleInitialView::ConstructL()
  51.     {
  52.     BaseConstructL(R_S60UIEXAMPLE_INITIALVIEW);
  53.     
  54.     }
  55. // -----------------------------------------------------------------------------
  56. // CS60UIExampleInitialView::~CS60UIExampleInitialView()
  57. // Destructor.
  58. // -----------------------------------------------------------------------------
  59. //
  60. CS60UIExampleInitialView::~CS60UIExampleInitialView()
  61.     {
  62.     }
  63. // -----------------------------------------------------------------------------
  64. // CS60UIExampleInitialView::Id()
  65. // Returns View's ID.
  66. // -----------------------------------------------------------------------------
  67. //
  68. TUid CS60UIExampleInitialView::Id() const
  69.     {
  70.     return TUid::Uid(ES60UIExampleInitialViewId);
  71.     }
  72. // -----------------------------------------------------------------------------
  73. // CS60UIExampleInitialView::DoActivateL()
  74. // Activate an InitialView
  75. // -----------------------------------------------------------------------------
  76. //
  77. void CS60UIExampleInitialView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
  78.                                            TUid /*aCustomMessageId*/,
  79.                                            const TDesC8& /*aCustomMessage*/)
  80.     {
  81.     iContainer = CS60UIExampleInitialContainer::NewL(ClientRect(), iModel);
  82.     AppUi()->AddToStackL(*this, iContainer);
  83.     }
  84. // -----------------------------------------------------------------------------
  85. // CS60UIExampleInitialView::DoDeactivate()
  86. // DeActivate an InitialView
  87. // -----------------------------------------------------------------------------
  88. //
  89. void CS60UIExampleInitialView::DoDeactivate()
  90.     {
  91.     if (iContainer)
  92.         {
  93.         // Remove InitialView's container form control Stack
  94.         AppUi()->RemoveFromStack(iContainer);
  95.         delete iContainer;
  96.         iContainer = NULL;
  97.         }
  98.     }
  99. // -----------------------------------------------------------------------------
  100. // CS60UIExampleInitialView::HandleCommandL()
  101. // Takes care of Command handling.
  102. // -----------------------------------------------------------------------------
  103. //
  104. void CS60UIExampleInitialView::HandleCommandL(TInt aCommand)
  105.     {
  106.     switch (aCommand)
  107.         {
  108.         case ES60UIExampleStartGame:
  109.             {
  110.             iModel.GameStart();
  111.             // Switch to game view
  112.             AppUi()->ActivateLocalViewL(TUid::Uid(ES60UIExamplePlayViewId));
  113.             break;
  114.             }
  115.         case ES60UIExampleContinueGame:
  116.             {
  117.             iModel.GameContinue();
  118.             // Switch to Game view
  119.             AppUi()->ActivateLocalViewL(TUid::Uid(ES60UIExamplePlayViewId));
  120.             break;
  121.             }
  122.         case ES60UIExampleHighscores:
  123.             {
  124.             // Show High Scores
  125.             AppUi()->ActivateLocalViewL(TUid::Uid(ES60UIExampleHighScoreViewId));
  126.             break;
  127.             }
  128.         default:
  129.             // Pass any other commands to the AppUi
  130.             AppUi()->HandleCommandL(aCommand);
  131.         }
  132.     }
  133.     
  134.     
  135. // -----------------------------------------------------------------------------
  136. // CS60UIExampleInitialView::DynInitMenuPaneL()
  137. // Used to remove unwanted options from the options menu
  138. // -----------------------------------------------------------------------------
  139. //
  140. void CS60UIExampleInitialView::DynInitMenuPaneL(TInt aResourceId, 
  141.                                                 CEikMenuPane* aMenuPane)
  142.     {
  143.     if (aResourceId == R_S60UIEXAMPLE_INITIALMENU)
  144.         {
  145.         if (!iModel.IsGameStarted())
  146.             {
  147.             aMenuPane->SetItemDimmed(ES60UIExampleContinueGame, ETrue);
  148.             }
  149.             
  150.         }
  151.         
  152.     }
  153. // End of File