examples/ForumNokia/InternetEmail/src/InternetEmailContainer.cpp

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 
00031 // INCLUDE FILES
00032 #include "InternetEmailContainer.h"
00033 
00034 #include <eiklabel.h>  // for example label control
00035 #include <aknutils.h>  // for Fonts.
00036 #include <aknlists.h>  // for listbox
00037 #include <barsread.h>  // for resource reader
00038 #include <avkon.hrh>
00039 
00040 #include "Internetemail.hrh"
00041 #include "InternetEmailEngine.h"
00042 #include <Internetemail.rsg>
00043 
00044 
00045 // ================= MEMBER FUNCTIONS =======================
00046 
00047 // -------------------------------------------------------
00048 // CInternetEmailContainer::ConstructL(const TRect& aRect)
00049 //  EPOC two phased constructor
00050 // -------------------------------------------------------
00051 //
00052 void CInternetEmailContainer::ConstructL(const TRect& aRect, CInternetEmailAppUi* aParent )
00053     {
00054     iParent=aParent;
00055     CreateWindowL();
00056 
00057     iListBox = new (ELeave) CAknDoubleStyleListBox;
00058     iListBox->SetContainerWindowL(*this);
00059     iListBox->ConstructL(this, EAknListBoxSelectionList);
00060 
00061     iListBox->Model()->SetItemTextArray(this); //we make ourself to be the array
00062     iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); //thus lb doesnt control our deletion
00063 
00064     iListBox->SetListBoxObserver( this );
00065     iListBox->CreateScrollBarFrameL(ETrue); //we set automatic scrollbar
00066     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
00067         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
00068 
00069     iListBox->SetRect( aRect );
00070     iListBox->ActivateL();
00071 
00072     // set window size
00073     SetRect(aRect);
00074 
00075     // activate window
00076     ActivateL();
00077     }
00078 
00079 // ---------------------------------------------------
00080 // CInternetEmailContainer::~CInternetEmailContainer()
00081 // ---------------------------------------------------
00082 //
00083 CInternetEmailContainer::~CInternetEmailContainer()
00084     {
00085     delete iListBox;
00086     }
00087 
00088 
00089 // --------------------------------------------------
00090 // CInternetEmailContainer::SizeChanged()
00091 //  Called by framework when the view size is changed
00092 // --------------------------------------------------
00093 //
00094 void CInternetEmailContainer::SizeChanged()
00095     {
00096     iListBox->SetRect( Rect() );
00097     }
00098 
00099 // -------------------------------------------------------
00100 // CInternetEmailContainer::CountComponentControls() const
00101 // -------------------------------------------------------
00102 //
00103 TInt CInternetEmailContainer::CountComponentControls() const
00104     {
00105     return 1;
00106     }
00107 
00108 // ------------------------------------------------------------
00109 // CInternetEmailContainer::ComponentControl(TInt aIndex) const
00110 // ------------------------------------------------------------
00111 //
00112 CCoeControl* CInternetEmailContainer::ComponentControl(TInt aIndex) const
00113     {
00114     switch ( aIndex )
00115         {
00116         case 0:
00117             return iListBox;
00118         default:
00119             return NULL;
00120         }
00121     }
00122 
00123 void CInternetEmailContainer::HandleResourceChange(TInt aType)
00124     {
00125     CCoeControl::HandleResourceChange(aType);
00126     if ( aType==KEikDynamicLayoutVariantSwitch )
00127         {
00128         TRect rect;
00129         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00130         SetRect(rect);
00131         }
00132     }
00133 
00134 // -------------------------------------------------------
00135 // CInternetEmailContainer::Draw(const TRect& aRect) const
00136 // -------------------------------------------------------
00137 //
00138 void CInternetEmailContainer::Draw(const TRect& aRect) const
00139     {
00140     CWindowGc& gc = SystemGc();
00141     gc.SetPenStyle(CGraphicsContext::ENullPen);
00142     gc.SetBrushColor(KRgbGray);
00143     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00144     gc.DrawRect(aRect);
00145     }
00146 
00147 // ------------------------------------------------------
00148 // TKeyResponse CInternetEmailContainer::OfferKeyEventL(
00149 //      const TKeyEvent& aKeyEvent, TEventCode aType)
00150 //  This function is used to pick subset of keyevents for
00151 //  our custom handler.
00152 // ------------------------------------------------------
00153 //
00154 TKeyResponse CInternetEmailContainer::OfferKeyEventL(
00155     const TKeyEvent& aKeyEvent, TEventCode aType)
00156     {
00157     if ( aType != EEventKey )
00158         {
00159         return EKeyWasNotConsumed;
00160         }
00161 
00162     switch ( aKeyEvent.iCode )
00163         {
00164         // Up & Down & enter arrow key's event transfer to list box
00165         case EKeyOK:
00166         case EKeyUpArrow:
00167         case EKeyDownArrow:
00168             if ( iListBox )
00169                 {
00170                 return iListBox->OfferKeyEventL( aKeyEvent, aType );
00171                 }
00172             break;
00173 
00174         default:
00175             break;
00176         }
00177 
00178     return EKeyWasNotConsumed;
00179     }
00180 
00181 // -----------------------------------------------
00182 // CInternetEmailContainer::HandleControlEventL(
00183 //   CCoeControl* aControl,TCoeEvent aEventType)
00184 // -----------------------------------------------
00185 //
00186 void CInternetEmailContainer::HandleControlEventL(
00187     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
00188     {
00189     // TODO: Add your control event handler code here
00190     }
00191 
00192 
00193 // ------------------------------------------------
00194 // CInternetEmailContainer::HandleListBoxEventL(
00195 //  CEikListBox* aListBox,TListBoxEvent aEventType)
00196 //  Custom event handler.
00197 // ------------------------------------------------
00198 //
00199 void CInternetEmailContainer::HandleListBoxEventL(
00200     CEikListBox* aListBox,TListBoxEvent aEventType)
00201     {
00202     if(aListBox==iListBox &&
00203     ( aEventType==MEikListBoxObserver::EEventEnterKeyPressed ||
00204       aEventType == MEikListBoxObserver::EEventItemClicked || 
00205       aEventType == MEikListBoxObserver::EEventItemDoubleClicked))
00206         {
00207         OpenEmailL(); // opens selected entry using generic framework
00208         }
00209     }
00210 
00211 // ----------------------------------------------------
00212 // void CInternetEmailContainer::OpenEmailL()
00213 //  function to call engine interface method
00214 // ----------------------------------------------------
00215 //
00216 void CInternetEmailContainer::OpenEmailL()
00217     {
00218     TInt currentItem=iListBox->CurrentItemIndex();
00219     if(currentItem>=0 && currentItem<iParent->Model()->RemoteEmailCount())
00220         {
00221         iParent->Model()->RemoteOpenEmailL(currentItem);
00222         }
00223     }
00224 
00225 // ---------------------------------------------------------------
00226 // void CInternetEmailContainer::EntryToListbox(TInt aIndex) const
00227 //  Gets header message entry header information from model
00228 //  if model is suddenly cancelled traps and draws blanco.
00229 // ---------------------------------------------------------------
00230 //
00231 void CInternetEmailContainer::EntryToListbox(TInt aIndex) const
00232     {
00233     TPtrC from;
00234     TPtrC subject;
00235 
00236     TRAPD(error,from.Set(iParent->Model()->RemoteEmailSenderL(aIndex)));
00237     if(error == KErrNone)
00238         {
00239         TRAP(error,subject.Set(iParent->Model()->RemoteEmailTextL(aIndex)));
00240         if(error == KErrNone)
00241             {
00242             iText.Format(_L("\t%S\t%S"),&subject,&from);
00243             }
00244         else
00245             {
00246             iText.Zero();
00247             }
00248         }
00249     else
00250         {
00251         iText.Zero();
00252         }
00253     }
00254 
00255 // ------------------------------------------------------------
00256 // TInt CInternetEmailContainer::MdcaCount() const
00257 //  From MDesCArray. Handles counting of array items from model
00258 // ------------------------------------------------------------
00259 //
00260 TInt CInternetEmailContainer::MdcaCount() const
00261     {
00262     return iParent->Model()->RemoteEmailCount();
00263     }
00264 
00265 // -----------------------------------------------------------
00266 // TPtrC CInternetEmailContainer::MdcaPoint(TInt aIndex) const
00267 //  From MDesCArray. Handles the insertion of needed text from
00268 //  model to pointed member of array.
00269 // -----------------------------------------------------------
00270 //
00271 TPtrC CInternetEmailContainer::MdcaPoint(TInt aIndex) const
00272     {
00273     EntryToListbox(aIndex);
00274     return iText;
00275     }
00276 
00277 // -------------------------------------------------
00278 // void CInternetEmailContainer::MailCountChange()
00279 //  Public funtion called from engine observer
00280 //  callback handlers when model changes are
00281 //  occurring.
00282 // -------------------------------------------------
00283 //
00284 void CInternetEmailContainer::MailCountChange()
00285     {
00286     iListBox->HandleItemAdditionL();
00287 
00288     //a trick to set default selection when model changes from N to 1
00289     TInt currentItem = iListBox->CurrentItemIndex();
00290     if(currentItem>=0 && currentItem<iParent->Model()->RemoteEmailCount())
00291         {
00292         if( iListBox->ScrollBarFrame() )
00293             {
00294             iListBox->ScrollBarFrame()->MoveVertThumbTo( currentItem );
00295             }
00296         }
00297     }
00298 
00299 
00300 // End of File

Generated by  doxygen 1.6.2