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

Symbian

开发平台:

C/C++

  1. // Copyright (c) 2006 Nokia Corporation.
  2. #include "S60UIExampleInitialContainer.h"
  3. #include "S60UIExampleModel.h"
  4. #include <akntitle.h>
  5. #include <eikspane.h>
  6. #include <aknViewAppUi.h>
  7. #include <aknutils.h>
  8. #include <akniconutils.h>
  9. #include <S60UIExample.mbg>
  10. #include <S60UIExample.rsg>
  11. #include <stringloader.h>    
  12. // -----------------------------------------------------------------------------
  13. // CS60UIExampleInitialContainer::NewL()
  14. // Two-phased constructor.
  15. // -----------------------------------------------------------------------------
  16. //
  17. CS60UIExampleInitialContainer* CS60UIExampleInitialContainer::NewL(
  18.                                                   const TRect& aRect,
  19.                                                   CS60UIExampleModel& aModel)
  20.     {
  21.     CS60UIExampleInitialContainer* self = 
  22.                      CS60UIExampleInitialContainer::NewLC(aRect, aModel);
  23.     CleanupStack::Pop(self);
  24.     return self;
  25.     }
  26. // -----------------------------------------------------------------------------
  27. // CS60UIExampleInitialContainer::NewLC()
  28. // Two-phased constructor.
  29. // -----------------------------------------------------------------------------
  30. //
  31. CS60UIExampleInitialContainer* CS60UIExampleInitialContainer::NewLC(
  32.                                                    const TRect& aRect,
  33.                                                    CS60UIExampleModel& aModel)
  34.     {
  35.     CS60UIExampleInitialContainer* self = 
  36.                          new (ELeave) CS60UIExampleInitialContainer(aModel);
  37.     CleanupStack::PushL(self);
  38.     self->ConstructL(aRect);
  39.     return self;
  40.     }
  41. // -----------------------------------------------------------------------------
  42. // CS60UIExampleInitialContainer::CS60UIExampleInitialContainer()
  43. // First stage constructor
  44. // -----------------------------------------------------------------------------
  45. //
  46. CS60UIExampleInitialContainer::CS60UIExampleInitialContainer(
  47.                                                  CS60UIExampleModel& aModel)
  48.     :iModel(aModel)
  49.     {
  50.     }
  51.     
  52. // -----------------------------------------------------------------------------
  53. // CS60UIExampleInitialContainer::ConstructL()
  54. // Symbian 2nd phase constructor can leave.
  55. // -----------------------------------------------------------------------------
  56. //
  57. void CS60UIExampleInitialContainer::ConstructL(const TRect& aRect)
  58.     {
  59.     CreateWindowL();
  60.     CEikStatusPane* statusPane = iAvkonViewAppUi->StatusPane();
  61.     CAknTitlePane* titlePane = (CAknTitlePane*)statusPane->ControlL(
  62.                                          TUid::Uid(EEikStatusPaneUidTitle));
  63.     // Set the text string.
  64.     iTitle = StringLoader::LoadL(R_S60UIEXAMPLE_TITLE_TEXT, iCoeEnv);
  65.     titlePane ->SetTextL(*iTitle); 
  66.     
  67.     // Get background graphic
  68.     _LIT(KSvgFile,"z:\resource\apps\S60UIExample.mif");
  69.     iBkgBitmap = 
  70.                AknIconUtils::CreateIconL(KSvgFile, EMbmS60uiexampleStart_bkg);
  71.     SetRect(aRect);
  72.     
  73.     ActivateL();
  74.     }
  75.     
  76.     
  77. // -----------------------------------------------------------------------------
  78. // CS60UIExampleInitialContainer::~CS60UIExampleInitialContainer()
  79. // Destructor
  80. // -----------------------------------------------------------------------------
  81. //
  82. CS60UIExampleInitialContainer::~CS60UIExampleInitialContainer()
  83.     {
  84.     delete iBkgBitmap;
  85.     delete iTitle;
  86.     }
  87.     
  88.     
  89. // -----------------------------------------------------------------------------
  90. // CS60UIExampleInitialContainer::SizeChanged()
  91. // Handles necessary size changes, in this case resizing the bitmap.
  92. // -----------------------------------------------------------------------------
  93. //
  94. void CS60UIExampleInitialContainer::SizeChanged()
  95.     {
  96.     TRect rect = Rect();
  97.     TInt error = AknIconUtils::SetSize(iBkgBitmap, 
  98.                                        rect.Size(), 
  99.                                        EAspectRatioNotPreserved);
  100.     }
  101. // -----------------------------------------------------------------------------
  102. // CS60UIExampleInitialContainer::HandleResourceChange()
  103. // Called by framework when screen size changes. Use to cause necessary
  104. // resizing to be performed.
  105. // -----------------------------------------------------------------------------
  106. //
  107. void CS60UIExampleInitialContainer::HandleResourceChange(TInt aType)
  108.     {
  109.     CCoeControl::HandleResourceChange(aType);
  110.     if (aType == KEikDynamicLayoutVariantSwitch)
  111.         {
  112.         // Screen size has changed. Get the new Main Pane size
  113.         TRect rect;
  114.         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
  115.         // Pass it on. Eventually SizeChanged() performs the necessary
  116.         // resizing
  117.         SetRect(rect);
  118.         }
  119.     }
  120. // -----------------------------------------------------------------------------
  121. // CS60UIExampleInitialContainer::Draw() const
  122. // Draws the display
  123. // -----------------------------------------------------------------------------
  124. //
  125. void CS60UIExampleInitialContainer::Draw(const TRect& aRect) const
  126.     {
  127.     CWindowGc& gc = SystemGc();
  128.     // draw the background
  129.     gc.BitBlt(TPoint(0,0), iBkgBitmap);
  130.     // Overlay the title
  131.     gc.SetPenStyle(CGraphicsContext::ESolidPen);
  132.     gc.SetPenColor(KRgbBlack);
  133.     gc.UseFont(AknLayoutUtils::FontFromId(EAknLogicalFontTitleFont));
  134.     TPoint textPos(aRect.iBr.iX/3, aRect.iBr.iY/3);
  135.     gc.DrawText(*iTitle, textPos);
  136.     gc.DiscardFont();
  137.     }
  138. // End of File