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