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