EmailExampleViews.cpp
上传用户:sempras
上传日期:2007-03-04
资源大小:821k
文件大小:5k
源码类别:

Symbian

开发平台:

C/C++

  1. /*
  2. * ============================================================================
  3. *  Name     : CEmailView from EmailExampleViews.cpp
  4. *  Part of  : EmailExample
  5. *  Created  : 09/11/2003 by Forum Nokia
  6. *  Implementation notes:
  7. *
  8. *  Version  : 1.0
  9. *  Copyright: Nokia Corporation
  10. * ============================================================================
  11. */
  12. #include "EmailExampleViews.h"
  13. #include "EmailExampleEngine.h"
  14. #include "EmailExampleWin.h"
  15. #include <eikenv.h>
  16. #include <eikclb.h>
  17. #include <eikclbd.h>
  18. #include <eiktxlbm.h>
  19. #include <ckntitle.h>
  20. #include "EmailExample.hrh"
  21. #include <EmailExample.rsg>
  22. CEmailView::CEmailView(CEmailMainWindow& aParent):
  23. iParent(aParent)
  24. {
  25. }
  26. CEmailView::~CEmailView()
  27. {
  28. delete iListBox;
  29. delete iTitle;
  30. }
  31. void CEmailView::ConstructL(TInt aTitleRes)
  32. {
  33. SetContainerWindowL(iParent);
  34. // create our listbox
  35. iListBox=new(ELeave) CEikColumnListBox;
  36. iListBox->ConstructL(this);
  37. // setup columns
  38. CColumnListBoxData* columnData=static_cast<CColumnListBoxItemDrawer*>(iListBox->View()->ItemDrawer())->ColumnData();
  39. columnData->SetColumnFontL(0,iEikonEnv->NormalFont());
  40. columnData->SetColumnFontL(1,iEikonEnv->NormalFont());
  41. columnData->SetColumnFontL(2,iEikonEnv->NormalFont());
  42. iListBox->Model()->SetItemTextArray(this);
  43. iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
  44. iListBox->SetListBoxObserver(this);
  45. iListBox->CreateScrollBarFrameL()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
  46. iListBox->SetFocus(ETrue);
  47. // create title but do not activate it
  48. iTitle=CCknAppTitle::NewL();
  49. iTitle->SetContainerWindowL(*this);
  50. TBuf<128> title;
  51. iEikonEnv->ReadResource(title,aTitleRes);
  52. iTitle->SetTextL(title,CCknAppTitle::EMainTitle);
  53. iTitle->SetFocus(ETrue);
  54. }
  55. void CEmailView::SizeChanged()
  56. {
  57. TRect rect(Rect());
  58. TInt botY=rect.iBr.iY;
  59. TSize size=iTitle->MinimumSize();
  60. rect.iBr.iY=rect.iTl.iY+size.iHeight;
  61. iTitle->SetRect(rect);
  62. rect.iTl.iY=rect.iBr.iY;
  63. rect.iBr.iY=botY;
  64. iListBox->SetRect(rect);
  65. CColumnListBoxData* columnData= static_cast<CColumnListBoxItemDrawer*> ( iListBox->View()->ItemDrawer() )->ColumnData();
  66. columnData->SetColumnWidthPixelL( 0,rect.Width()/3-10 );
  67. columnData->SetColumnWidthPixelL( 1,20);
  68. columnData->SetColumnWidthPixelL( 2,2*rect.Width()/3-10 );
  69. }
  70. CCoeControl* CEmailView::ComponentControl(TInt aIndex) const
  71. {
  72. switch(aIndex)
  73. {
  74. case 0:
  75. return iListBox;
  76. case 1:
  77. return iTitle;
  78. }
  79. return 0;
  80. }
  81. TInt CEmailView::CountComponentControls() const
  82. {
  83.     return 2;
  84. }
  85. void CEmailView::Draw(const TRect& aRect) const
  86. {
  87. CWindowGc& gc=SystemGc();
  88. gc.Clear(aRect);
  89. }
  90. TKeyResponse CEmailView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
  91. {
  92. if(aType!=EEventKey)
  93. return EKeyWasNotConsumed;
  94. return iListBox->OfferKeyEventL(aKeyEvent,aType);
  95. }
  96. void CEmailView::MailCountChange()
  97. {
  98. iListBox->HandleItemAdditionL();
  99. }
  100. /*
  101. * ============================================================================
  102. *  Name     : CRemoteView from EmailExampleViews.cpp
  103. *  Part of  : EmailExample
  104. *  Created  : 09/11/2003 by Forum Nokia
  105. *  Implementation notes:
  106. *
  107. *  Version  : 1.0
  108. *  Copyright: Nokia Corporation
  109. * ============================================================================
  110. */
  111. CRemoteView::CRemoteView(CEmailMainWindow& aParent)
  112. :CEmailView(aParent)
  113. {}
  114. CRemoteView* CRemoteView::NewL(CEmailMainWindow& aParent)
  115. {
  116. CRemoteView* self = new (ELeave)CRemoteView(aParent);
  117. CleanupStack::PushL(self);
  118. self->ConstructL(R_EMAILEXAMPLEAPP_APP_TITLE_REMOTE);
  119. CleanupStack::Pop(self);
  120. return self;
  121. }
  122. CRemoteView::~CRemoteView()
  123. {}
  124. void CRemoteView::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
  125. {
  126. if(aListBox==iListBox && aEventType==MEikListBoxObserver::EEventEnterKeyPressed)
  127. {
  128. OpenEmailL();
  129. }
  130. }
  131. TInt CRemoteView::MdcaCount() const
  132. {
  133. return iParent.Engine()->RemoteEmailCount();
  134. }
  135. TPtrC CRemoteView::MdcaPoint(TInt aIndex) const
  136. {
  137. DoGetFormatedText(aIndex);
  138. return iText;
  139. }
  140. void CRemoteView::DoGetFormatedText(TInt aIndex) const
  141. {
  142. TPtrC from;
  143. TPtrC subject;
  144. TRAPD(error,from.Set(iParent.Engine()->RemoteEmailSenderL(aIndex)));
  145. if(error == KErrNone)
  146. {
  147. TRAP(error,subject.Set(iParent.Engine()->RemoteEmailTextL(aIndex)));
  148. if(error == KErrNone)
  149. {
  150. iText.Format(_L("%Stt%S"),&from,&subject);
  151. }
  152. else
  153. {
  154. iText.Zero();
  155. }
  156. }
  157. else
  158. iText.Zero();
  159. }
  160. void CRemoteView::HandleCommandL(TInt aCommand)
  161. {
  162. switch(aCommand)
  163. {
  164. case EEmailExampleCmdOpenEmail:
  165. OpenEmailL();
  166. break;
  167. case EEmailExampleCmdRemoteFetch:
  168.     iParent.Engine()->HandleCmdRemoteFetchL();
  169. break;
  170. case EEmailExampleCmdSettings:
  171. iParent.Engine()->Settings();
  172. break;
  173. }
  174. }
  175. void CRemoteView::OpenEmailL()
  176. {
  177. TInt currentItem=iListBox->CurrentItemIndex();
  178. if(currentItem>=0 && currentItem<iParent.Engine()->RemoteEmailCount())
  179. {
  180. iParent.Engine()->RemoteOpenEmailL(currentItem);
  181. }
  182. }