examples/ForumNokia/InternetEmail/src/InternetEmailContainer.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 
00006 // INCLUDE FILES
00007 #include "InternetEmailContainer.h"
00008 
00009 #include <eiklabel.h>  // for example label control
00010 #include <aknutils.h>  // for Fonts.
00011 #include <aknlists.h>  // for listbox
00012 #include <barsread.h>  // for resource reader
00013 #include <avkon.hrh>
00014 
00015 #include "Internetemail.hrh"
00016 #include "InternetEmailEngine.h"
00017 #include <Internetemail.rsg>
00018 
00019 
00020 // ================= MEMBER FUNCTIONS =======================
00021 
00022 // -------------------------------------------------------
00023 // CInternetEmailContainer::ConstructL(const TRect& aRect)
00024 //  EPOC two phased constructor
00025 // -------------------------------------------------------
00026 //
00027 void CInternetEmailContainer::ConstructL(const TRect& aRect, CInternetEmailAppUi* aParent )
00028     {
00029     iParent=aParent;
00030     CreateWindowL();
00031 
00032     iListBox = new (ELeave) CAknDoubleStyleListBox;
00033     iListBox->SetContainerWindowL(*this);
00034     iListBox->ConstructL(this, EAknListBoxSelectionList);
00035 
00036     iListBox->Model()->SetItemTextArray(this); //we make ourself to be the array
00037     iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); //thus lb doesnt control our deletion
00038 
00039     iListBox->SetListBoxObserver( this );
00040     iListBox->CreateScrollBarFrameL(ETrue); //we set automatic scrollbar
00041     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
00042         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
00043 
00044     iListBox->SetRect( aRect );
00045     iListBox->ActivateL();
00046 
00047     // set window size
00048     SetRect(aRect);
00049 
00050     // activate window
00051     ActivateL();
00052     }
00053 
00054 // ---------------------------------------------------
00055 // CInternetEmailContainer::~CInternetEmailContainer()
00056 // ---------------------------------------------------
00057 //
00058 CInternetEmailContainer::~CInternetEmailContainer()
00059     {
00060     delete iListBox;
00061     }
00062 
00063 
00064 // --------------------------------------------------
00065 // CInternetEmailContainer::SizeChanged()
00066 //  Called by framework when the view size is changed
00067 // --------------------------------------------------
00068 //
00069 void CInternetEmailContainer::SizeChanged()
00070     {
00071     iListBox->SetRect( Rect() );
00072     }
00073 
00074 // -------------------------------------------------------
00075 // CInternetEmailContainer::CountComponentControls() const
00076 // -------------------------------------------------------
00077 //
00078 TInt CInternetEmailContainer::CountComponentControls() const
00079     {
00080     return 1;
00081     }
00082 
00083 // ------------------------------------------------------------
00084 // CInternetEmailContainer::ComponentControl(TInt aIndex) const
00085 // ------------------------------------------------------------
00086 //
00087 CCoeControl* CInternetEmailContainer::ComponentControl(TInt aIndex) const
00088     {
00089     switch ( aIndex )
00090         {
00091         case 0:
00092             return iListBox;
00093         default:
00094             return NULL;
00095         }
00096     }
00097 
00098 void CInternetEmailContainer::HandleResourceChange(TInt aType)
00099     {
00100     CCoeControl::HandleResourceChange(aType);
00101     if ( aType==KEikDynamicLayoutVariantSwitch )
00102         {
00103         TRect rect;
00104         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00105         SetRect(rect);
00106         }
00107     }
00108 
00109 // -------------------------------------------------------
00110 // CInternetEmailContainer::Draw(const TRect& aRect) const
00111 // -------------------------------------------------------
00112 //
00113 void CInternetEmailContainer::Draw(const TRect& aRect) const
00114     {
00115     CWindowGc& gc = SystemGc();
00116     gc.SetPenStyle(CGraphicsContext::ENullPen);
00117     gc.SetBrushColor(KRgbGray);
00118     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00119     gc.DrawRect(aRect);
00120     }
00121 
00122 // ------------------------------------------------------
00123 // TKeyResponse CInternetEmailContainer::OfferKeyEventL(
00124 //      const TKeyEvent& aKeyEvent, TEventCode aType)
00125 //  This function is used to pick subset of keyevents for
00126 //  our custom handler.
00127 // ------------------------------------------------------
00128 //
00129 TKeyResponse CInternetEmailContainer::OfferKeyEventL(
00130     const TKeyEvent& aKeyEvent, TEventCode aType)
00131     {
00132     if ( aType != EEventKey )
00133         {
00134         return EKeyWasNotConsumed;
00135         }
00136 
00137     switch ( aKeyEvent.iCode )
00138         {
00139         // Up & Down & enter arrow key's event transfer to list box
00140         case EKeyOK:
00141         case EKeyUpArrow:
00142         case EKeyDownArrow:
00143             if ( iListBox )
00144                 {
00145                 return iListBox->OfferKeyEventL( aKeyEvent, aType );
00146                 }
00147             break;
00148 
00149         default:
00150             break;
00151         }
00152 
00153     return EKeyWasNotConsumed;
00154     }
00155 
00156 // -----------------------------------------------
00157 // CInternetEmailContainer::HandleControlEventL(
00158 //   CCoeControl* aControl,TCoeEvent aEventType)
00159 // -----------------------------------------------
00160 //
00161 void CInternetEmailContainer::HandleControlEventL(
00162     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
00163     {
00164     // TODO: Add your control event handler code here
00165     }
00166 
00167 
00168 // ------------------------------------------------
00169 // CInternetEmailContainer::HandleListBoxEventL(
00170 //  CEikListBox* aListBox,TListBoxEvent aEventType)
00171 //  Custom event handler.
00172 // ------------------------------------------------
00173 //
00174 void CInternetEmailContainer::HandleListBoxEventL(
00175     CEikListBox* aListBox,TListBoxEvent aEventType)
00176     {
00177     if(aListBox==iListBox &&
00178     ( aEventType==MEikListBoxObserver::EEventEnterKeyPressed ||
00179       aEventType == MEikListBoxObserver::EEventItemClicked || 
00180       aEventType == MEikListBoxObserver::EEventItemDoubleClicked))
00181         {
00182         OpenEmailL(); // opens selected entry using generic framework
00183         }
00184     }
00185 
00186 // ----------------------------------------------------
00187 // void CInternetEmailContainer::OpenEmailL()
00188 //  function to call engine interface method
00189 // ----------------------------------------------------
00190 //
00191 void CInternetEmailContainer::OpenEmailL()
00192     {
00193     TInt currentItem=iListBox->CurrentItemIndex();
00194     if(currentItem>=0 && currentItem<iParent->Model()->RemoteEmailCount())
00195         {
00196         iParent->Model()->RemoteOpenEmailL(currentItem);
00197         }
00198     }
00199 
00200 // ---------------------------------------------------------------
00201 // void CInternetEmailContainer::EntryToListbox(TInt aIndex) const
00202 //  Gets header message entry header information from model
00203 //  if model is suddenly cancelled traps and draws blanco.
00204 // ---------------------------------------------------------------
00205 //
00206 void CInternetEmailContainer::EntryToListbox(TInt aIndex) const
00207     {
00208     TPtrC from;
00209     TPtrC subject;
00210 
00211     TRAPD(error,from.Set(iParent->Model()->RemoteEmailSenderL(aIndex)));
00212     if(error == KErrNone)
00213         {
00214         TRAP(error,subject.Set(iParent->Model()->RemoteEmailTextL(aIndex)));
00215         if(error == KErrNone)
00216             {
00217             iText.Format(_L("\t%S\t%S"),&subject,&from);
00218             }
00219         else
00220             {
00221             iText.Zero();
00222             }
00223         }
00224     else
00225         {
00226         iText.Zero();
00227         }
00228     }
00229 
00230 // ------------------------------------------------------------
00231 // TInt CInternetEmailContainer::MdcaCount() const
00232 //  From MDesCArray. Handles counting of array items from model
00233 // ------------------------------------------------------------
00234 //
00235 TInt CInternetEmailContainer::MdcaCount() const
00236     {
00237     return iParent->Model()->RemoteEmailCount();
00238     }
00239 
00240 // -----------------------------------------------------------
00241 // TPtrC CInternetEmailContainer::MdcaPoint(TInt aIndex) const
00242 //  From MDesCArray. Handles the insertion of needed text from
00243 //  model to pointed member of array.
00244 // -----------------------------------------------------------
00245 //
00246 TPtrC CInternetEmailContainer::MdcaPoint(TInt aIndex) const
00247     {
00248     EntryToListbox(aIndex);
00249     return iText;
00250     }
00251 
00252 // -------------------------------------------------
00253 // void CInternetEmailContainer::MailCountChange()
00254 //  Public funtion called from engine observer
00255 //  callback handlers when model changes are
00256 //  occurring.
00257 // -------------------------------------------------
00258 //
00259 void CInternetEmailContainer::MailCountChange()
00260     {
00261     iListBox->HandleItemAdditionL();
00262 
00263     //a trick to set default selection when model changes from N to 1
00264     TInt currentItem = iListBox->CurrentItemIndex();
00265     if(currentItem>=0 && currentItem<iParent->Model()->RemoteEmailCount())
00266         {
00267         if( iListBox->ScrollBarFrame() )
00268             {
00269             iListBox->ScrollBarFrame()->MoveVertThumbTo( currentItem );
00270             }
00271         }
00272     }
00273 
00274 
00275 // End of File

Generated by  doxygen 1.6.2