examples/SFExamples/symbian_os_communications_programming_book_v2/chapter9/SendWorkBench/SendWorkbenchS60/src/SendWorkbenchAppView.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 
00018 // INCLUDE FILES
00019 #include <coemain.h>
00020 #include <aknlists.h>
00021 #include <eiklbx.h> 
00022 #include <eiklabel.h> 
00023 #include "SendWorkbenchAppView.h"
00024 
00025 #include "SendWorkBenchTypes.h"
00026 #include "SendWorkbench.hrh"
00027 
00028 // ============================ MEMBER FUNCTIONS ===============================
00029 
00030 // -----------------------------------------------------------------------------
00031 // CSendWorkbenchAppView::NewL()
00032 // Two-phased constructor.
00033 // -----------------------------------------------------------------------------
00034 //
00035 CSendWorkbenchAppView* CSendWorkbenchAppView::NewL( const TRect& aRect, CSendWorkbenchAppUi& aAppUI )
00036     {
00037     CSendWorkbenchAppView* self = CSendWorkbenchAppView::NewLC( aRect, aAppUI );
00038     CleanupStack::Pop( self );
00039     return self;
00040     }
00041 
00042 // -----------------------------------------------------------------------------
00043 // CSendWorkbenchAppView::NewLC()
00044 // Two-phased constructor.
00045 // -----------------------------------------------------------------------------
00046 //
00047 CSendWorkbenchAppView* CSendWorkbenchAppView::NewLC( const TRect& aRect, CSendWorkbenchAppUi& aAppUI )
00048     {
00049     CSendWorkbenchAppView* self = new ( ELeave ) CSendWorkbenchAppView(aAppUI);
00050     CleanupStack::PushL( self );
00051     self->ConstructL( aRect );
00052     return self;
00053     }
00054 
00055 // -----------------------------------------------------------------------------
00056 // CSendWorkbenchAppView::ConstructL()
00057 // Symbian 2nd phase constructor can leave.
00058 // -----------------------------------------------------------------------------
00059 //
00060 void CSendWorkbenchAppView::ConstructL( const TRect& aRect )
00061     {
00062     // Create a window for this application view
00063     CreateWindowL();
00064 
00065     iListBox = new(ELeave) CAknSingleStyleListBox();
00066     iListBox->ConstructL( this, EEikListBoxMultipleSelection );
00067     
00068     iListBox->CreateScrollBarFrameL(ETrue);
00069     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,
00070                                                         CEikScrollBarFrame::EAuto);
00071         
00072      _LIT( KLabel, "Items to send:");   
00073     iLabel = new (ELeave) CEikLabel;
00074     iLabel->SetContainerWindowL( *this );
00075     iLabel->SetTextL( KLabel );
00076     
00077         CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
00078  
00079         _LIT(KListItem1, "\tSend short text");
00080         _LIT(KListItem2, "\tSend long text");
00081         _LIT(KListItem3, "\tSend JPG");
00082         _LIT(KListItem4, "\tSend private JPG");
00083         _LIT(KListItem5, "\tUse SendAs to send");
00084         _LIT(KListItem6, "\tUse SendAs to edit & send");
00085         
00086     list->AppendL(KListItem1);
00087     list->AppendL(KListItem2);
00088     list->AppendL(KListItem3);
00089     list->AppendL(KListItem4);
00090     list->AppendL(KListItem5);
00091     list->AppendL(KListItem6);
00092     
00093     iListBox->HandleItemAdditionL();
00094     
00095     // Set up the observer
00096         iListBox->SetListBoxObserver(this);
00097         
00098     // Select the last item added
00099     iListBox->SetCurrentItemIndexAndDraw( iListBox->Model()->NumberOfItems() - 1 );
00100     
00101     // Set the windows size
00102     SetRect( aRect );
00103         
00104     // Activate the window, which makes it ready to be drawn
00105     ActivateL();
00106     }
00107 
00108 // -----------------------------------------------------------------------------
00109 // CSendWorkbenchAppView::CSendWorkbenchAppView()
00110 // C++ default constructor can NOT contain any code, that might leave.
00111 // -----------------------------------------------------------------------------
00112 //
00113 CSendWorkbenchAppView::CSendWorkbenchAppView(CSendWorkbenchAppUi& aAppUI)
00114 : iAppUI(aAppUI)    
00115         {
00116     // No implementation required
00117     }
00118 
00119 
00120 TKeyResponse CSendWorkbenchAppView::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
00121         {
00122         return iListBox->OfferKeyEventL(aKeyEvent, aType);
00123         }
00124 
00125 TInt CSendWorkbenchAppView::CountComponentControls() const
00126         {
00127         return 2;
00128         }
00129 
00130 CCoeControl *CSendWorkbenchAppView::ComponentControl(TInt aIndex) const
00131         {
00132         if(aIndex==0)
00133                 {
00134                 return iLabel;
00135                 }
00136         else
00137                 {
00138                 return iListBox;
00139                 }
00140         
00141         }
00142 
00143 // -----------------------------------------------------------------------------
00144 // CSendWorkbenchAppView::~CSendWorkbenchAppView()
00145 // Destructor.
00146 // -----------------------------------------------------------------------------
00147 //
00148 CSendWorkbenchAppView::~CSendWorkbenchAppView()
00149     {
00150     delete iLabel;
00151     delete iListBox;
00152     
00153     // No implementation required
00154     }
00155 
00156 SendTypes::TSendContentType CSendWorkbenchAppView::CurrentSelection() const
00157         {
00158         return static_cast<SendTypes::TSendContentType>(iListBox->CurrentItemIndex());
00159         }
00160         
00161 // -----------------------------------------------------------------------------
00162 // CSendWorkbenchAppView::Draw()
00163 // Draws the display.
00164 // -----------------------------------------------------------------------------
00165 //
00166 void CSendWorkbenchAppView::Draw( const TRect& /*aRect*/ ) const
00167     {
00168     // Get the standard graphics context
00169     CWindowGc& gc = SystemGc();
00170 
00171     // Gets the control's extent
00172     TRect drawRect( Rect());
00173 
00174     // Clears the screen
00175     gc.Clear( drawRect );
00176     
00177         }
00178 
00179 void CSendWorkbenchAppView::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
00180         {
00181         switch(aEventType)
00182                 {
00183                 case EEventEnterKeyPressed:
00184                 case EEventItemClicked:
00185                         {// An item has been selected
00186                         iAppUI.HandleSendMenuL();
00187                         }
00188                     break;
00189         default: // Nothing to do
00190                     break;
00191     };
00192   }
00193 
00194 // -----------------------------------------------------------------------------
00195 // CSendWorkbenchAppView::SizeChanged()
00196 // Called by framework when the view size is changed.
00197 // -----------------------------------------------------------------------------
00198 //
00199 void CSendWorkbenchAppView::SizeChanged()
00200     {  
00201     // set the label position
00202     iLabel->SetExtent( TPoint(0,0), iLabel->MinimumSize() );
00203     
00204     // get the label height so we can position listbox correctly
00205     TInt labelHeight = iLabel->Rect().Height();
00206 
00207     // create a fixed border size
00208     TInt border(5);
00209     // create the listbox size taking into account the border and label size
00210     TSize listBoxSize( Rect().Width() - (2 * border),
00211                        Rect().Height() - labelHeight - (2 * border));
00212     // set the listbox position
00213     iListBox->SetExtent( TPoint(border,labelHeight + border), listBoxSize );
00214         
00215     DrawNow();
00216     }
00217 // End of File

Generated by  doxygen 1.6.2