S60 3rd Edition SDK for Symbian OS
Example Applications Guide

HWRMTestAppContainer.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : HWRMTestAppContainer.h
00004 *  Part of     : HWRMTestApp
00005 *  Interface   : 
00006 *  Description : HWRM Test application container implementation
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2002-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation. 
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <eiklabel.h>  // for example label control
00018 #include <aknlists.h>
00019 #include <HWRMTestApp.rsg>
00020 #include "HWRMTestAppContainer.h"
00021 
00022 
00023 // CONSTANTS
00024 const TInt KMaxLineLength(18);
00025 
00026 // ============================ MEMBER FUNCTIONS ===============================
00027 
00028 // -----------------------------------------------------------------------------
00029 // CHWRMTestAppContainer::ConstructL
00030 // Symbian 2nd phase constructor can leave.
00031 // -----------------------------------------------------------------------------
00032 //
00033 void CHWRMTestAppContainer::ConstructL(const TRect& aRect)
00034     {
00035     CreateWindowL();
00036 
00037     iListBox = new(ELeave) CAknSingleStyleListBox();
00038     iListBox->ConstructL( this, EEikListBoxMultipleSelection );
00039     
00040     iListBox->CreateScrollBarFrameL(ETrue);
00041     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,
00042                                                         CEikScrollBarFrame::EAuto);
00043     
00044     iLabel = new (ELeave) CEikLabel;
00045     iLabel->SetContainerWindowL( *this );
00046     _LIT( KLabel, "HWRM Test:");
00047     iLabel->SetTextL( KLabel );
00048 
00049     SetRect(aRect);
00050     ActivateL();
00051     }
00052 
00053 // -----------------------------------------------------------------------------
00054 // CHWRMTestAppContainer::~CHWRMTestAppContainer
00055 // Destructor
00056 // -----------------------------------------------------------------------------
00057 //
00058 CHWRMTestAppContainer::~CHWRMTestAppContainer()
00059     {
00060     delete iListBox;
00061     delete iLabel;
00062     }
00063 
00064 // -----------------------------------------------------------------------------
00065 // CHWRMTestAppContainer::SizeChanged
00066 // Called by framework when the view size is changed
00067 // -----------------------------------------------------------------------------
00068 //
00069 void CHWRMTestAppContainer::SizeChanged()
00070     {
00071     // set the label position
00072     iLabel->SetExtent( TPoint(0,0), iLabel->MinimumSize() );
00073     
00074     // get the label height so we can position listbox correctly
00075     TInt labelHeight = iLabel->Rect().Height();
00076 
00077     // create a fixed border size
00078     TInt border(5);
00079     // create the listbox size taking into account the border and label size
00080     TSize listBoxSize( Rect().Width() - (2 * border),
00081                        Rect().Height() - labelHeight - (2 * border));
00082     // set the listbox position
00083     iListBox->SetExtent( TPoint(border,labelHeight + border), listBoxSize );
00084     }
00085 
00086 // -----------------------------------------------------------------------------
00087 // CHWRMTestAppContainer::CountComponentControls
00088 // Return number of controls in container
00089 // -----------------------------------------------------------------------------
00090 //
00091 TInt CHWRMTestAppContainer::CountComponentControls() const
00092     {
00093     return 2; // return nbr of controls inside this container
00094     }
00095 
00096 // -----------------------------------------------------------------------------
00097 // CHWRMTestAppContainer::ComponentControl
00098 // Return component control
00099 // -----------------------------------------------------------------------------
00100 //
00101 CCoeControl* CHWRMTestAppContainer::ComponentControl(TInt aIndex) const
00102     {
00103     switch ( aIndex )
00104         {
00105         case 0:
00106             return iListBox;
00107         case 1:
00108             return iLabel;
00109         default:
00110             return NULL;
00111         }
00112     }
00113 
00114 // -----------------------------------------------------------------------------
00115 // CHWRMTestAppContainer::Draw
00116 // -----------------------------------------------------------------------------
00117 //
00118 void CHWRMTestAppContainer::Draw(const TRect& aRect) const
00119     {
00120     CWindowGc& gc = SystemGc();
00121     gc.SetPenStyle(CGraphicsContext::ENullPen);
00122     gc.SetBrushColor(KRgbGray);
00123     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00124     gc.DrawRect(aRect);
00125     }
00126 
00127 // -----------------------------------------------------------------------------
00128 // CHWRMTestAppContainer::HandleControlEventL
00129 // -----------------------------------------------------------------------------
00130 //
00131 void CHWRMTestAppContainer::HandleControlEventL(
00132     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
00133     {
00134     }
00135 
00136 // -----------------------------------------------------------------------------
00137 // CHWRMTestAppContainer::AddMessageL
00138 // Add message to list box in the container
00139 // -----------------------------------------------------------------------------
00140 //
00141 void CHWRMTestAppContainer::AddMessageL( const TDesC& aMsg ) const
00142     {
00143     // buffer for message string to take the line and a single \t character
00144     _LIT( KTab, "\t" );
00145     TBuf<KMaxLineLength+1> msgBuf;
00146     
00147     CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
00148     TInt pos(0);
00149     
00150     while( aMsg.Length() > pos+KMaxLineLength )
00151         {
00152         // add the \t to the string for the Avkon listbox
00153         msgBuf = ( KTab );
00154         msgBuf.Append( aMsg.Mid( pos, KMaxLineLength ) );
00155         list->AppendL( msgBuf );
00156         
00157         pos += KMaxLineLength;
00158         }
00159     
00160     msgBuf = ( KTab );
00161     msgBuf.Append( aMsg.Mid( pos ) );
00162     list->AppendL( msgBuf );
00163     
00164     iListBox->HandleItemAdditionL();
00165     // Select the last item added
00166     iListBox->SetCurrentItemIndexAndDraw( iListBox->Model()->NumberOfItems() - 1 );
00167 
00168     iListBox->SetFocus( ETrue );
00169     }
00170 
00171 // -----------------------------------------------------------------------------
00172 // CHWRMTestAppContainer::OfferKeyEventL
00173 // Pass key event to appropriate controls
00174 // -----------------------------------------------------------------------------
00175 //
00176 TKeyResponse CHWRMTestAppContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType )
00177     {
00178     return iListBox->OfferKeyEventL( aKeyEvent, aType );    
00179     }
00180 
00181 // ---------------------------------------------------------
00182 // CHWRMTestAppContainer::HandleResourceChange()
00183 // Called by framework when layout is changed.
00184 // ---------------------------------------------------------
00185 //
00186 void CHWRMTestAppContainer::HandleResourceChange(TInt aType)
00187     {
00188     CCoeControl::HandleResourceChange(aType);
00189 
00190     // ADDED FOR SCALABLE UI SUPPORT
00191     // *****************************
00192     if ( aType==KEikDynamicLayoutVariantSwitch )
00193         {
00194         TRect rect;
00195         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00196         SetRect(rect);
00197         }
00198     
00199     // Redraw the listbox
00200     iListBox->DrawNow();
00201     }
00202 
00203 // End of File  
00204 

© Nokia 2006

Back to top