EmailExampleViews.cpp
上传用户:sempras
上传日期:2007-03-04
资源大小:821k
文件大小:5k
- /*
- * ============================================================================
- * Name : CEmailView from EmailExampleViews.cpp
- * Part of : EmailExample
- * Created : 09/11/2003 by Forum Nokia
- * Implementation notes:
- *
- * Version : 1.0
- * Copyright: Nokia Corporation
- * ============================================================================
- */
- #include "EmailExampleViews.h"
- #include "EmailExampleEngine.h"
- #include "EmailExampleWin.h"
- #include <eikenv.h>
- #include <eikclb.h>
- #include <eikclbd.h>
- #include <eiktxlbm.h>
- #include <ckntitle.h>
- #include "EmailExample.hrh"
- #include <EmailExample.rsg>
- CEmailView::CEmailView(CEmailMainWindow& aParent):
- iParent(aParent)
- {
- }
- CEmailView::~CEmailView()
- {
- delete iListBox;
- delete iTitle;
- }
- void CEmailView::ConstructL(TInt aTitleRes)
- {
- SetContainerWindowL(iParent);
- // create our listbox
- iListBox=new(ELeave) CEikColumnListBox;
- iListBox->ConstructL(this);
- // setup columns
- CColumnListBoxData* columnData=static_cast<CColumnListBoxItemDrawer*>(iListBox->View()->ItemDrawer())->ColumnData();
- columnData->SetColumnFontL(0,iEikonEnv->NormalFont());
- columnData->SetColumnFontL(1,iEikonEnv->NormalFont());
- columnData->SetColumnFontL(2,iEikonEnv->NormalFont());
- iListBox->Model()->SetItemTextArray(this);
- iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
- iListBox->SetListBoxObserver(this);
- iListBox->CreateScrollBarFrameL()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
- iListBox->SetFocus(ETrue);
- // create title but do not activate it
- iTitle=CCknAppTitle::NewL();
- iTitle->SetContainerWindowL(*this);
- TBuf<128> title;
- iEikonEnv->ReadResource(title,aTitleRes);
- iTitle->SetTextL(title,CCknAppTitle::EMainTitle);
- iTitle->SetFocus(ETrue);
- }
- void CEmailView::SizeChanged()
- {
- TRect rect(Rect());
- TInt botY=rect.iBr.iY;
- TSize size=iTitle->MinimumSize();
- rect.iBr.iY=rect.iTl.iY+size.iHeight;
- iTitle->SetRect(rect);
- rect.iTl.iY=rect.iBr.iY;
- rect.iBr.iY=botY;
- iListBox->SetRect(rect);
- CColumnListBoxData* columnData= static_cast<CColumnListBoxItemDrawer*> ( iListBox->View()->ItemDrawer() )->ColumnData();
- columnData->SetColumnWidthPixelL( 0,rect.Width()/3-10 );
- columnData->SetColumnWidthPixelL( 1,20);
- columnData->SetColumnWidthPixelL( 2,2*rect.Width()/3-10 );
- }
- CCoeControl* CEmailView::ComponentControl(TInt aIndex) const
- {
- switch(aIndex)
- {
- case 0:
- return iListBox;
- case 1:
- return iTitle;
- }
- return 0;
- }
- TInt CEmailView::CountComponentControls() const
- {
- return 2;
- }
- void CEmailView::Draw(const TRect& aRect) const
- {
- CWindowGc& gc=SystemGc();
- gc.Clear(aRect);
- }
- TKeyResponse CEmailView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
- {
- if(aType!=EEventKey)
- return EKeyWasNotConsumed;
- return iListBox->OfferKeyEventL(aKeyEvent,aType);
- }
- void CEmailView::MailCountChange()
- {
- iListBox->HandleItemAdditionL();
- }
- /*
- * ============================================================================
- * Name : CRemoteView from EmailExampleViews.cpp
- * Part of : EmailExample
- * Created : 09/11/2003 by Forum Nokia
- * Implementation notes:
- *
- * Version : 1.0
- * Copyright: Nokia Corporation
- * ============================================================================
- */
- CRemoteView::CRemoteView(CEmailMainWindow& aParent)
- :CEmailView(aParent)
- {}
- CRemoteView* CRemoteView::NewL(CEmailMainWindow& aParent)
- {
- CRemoteView* self = new (ELeave)CRemoteView(aParent);
- CleanupStack::PushL(self);
- self->ConstructL(R_EMAILEXAMPLEAPP_APP_TITLE_REMOTE);
- CleanupStack::Pop(self);
- return self;
- }
- CRemoteView::~CRemoteView()
- {}
- void CRemoteView::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
- {
- if(aListBox==iListBox && aEventType==MEikListBoxObserver::EEventEnterKeyPressed)
- {
- OpenEmailL();
- }
- }
- TInt CRemoteView::MdcaCount() const
- {
- return iParent.Engine()->RemoteEmailCount();
- }
- TPtrC CRemoteView::MdcaPoint(TInt aIndex) const
- {
- DoGetFormatedText(aIndex);
- return iText;
- }
- void CRemoteView::DoGetFormatedText(TInt aIndex) const
- {
- TPtrC from;
- TPtrC subject;
- TRAPD(error,from.Set(iParent.Engine()->RemoteEmailSenderL(aIndex)));
- if(error == KErrNone)
- {
- TRAP(error,subject.Set(iParent.Engine()->RemoteEmailTextL(aIndex)));
- if(error == KErrNone)
- {
- iText.Format(_L("%Stt%S"),&from,&subject);
- }
- else
- {
- iText.Zero();
- }
- }
- else
- iText.Zero();
- }
- void CRemoteView::HandleCommandL(TInt aCommand)
- {
- switch(aCommand)
- {
- case EEmailExampleCmdOpenEmail:
- OpenEmailL();
- break;
- case EEmailExampleCmdRemoteFetch:
- iParent.Engine()->HandleCmdRemoteFetchL();
- break;
- case EEmailExampleCmdSettings:
- iParent.Engine()->Settings();
- break;
- }
- }
- void CRemoteView::OpenEmailL()
- {
- TInt currentItem=iListBox->CurrentItemIndex();
- if(currentItem>=0 && currentItem<iParent.Engine()->RemoteEmailCount())
- {
- iParent.Engine()->RemoteOpenEmailL(currentItem);
- }
- }