|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================ 00003 * Name : CFindItemTestAppContainer from FindItemTestAppContainer.h 00004 * Part of : FindItemTestApp 00005 * Interface : 00006 * Description : Find Item 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 <barsread.h> // for TResourceReader 00020 #include <FindItemTestApp.rsg> 00021 #include "FindItemTestAppContainer.h" 00022 00023 00024 // CONSTANTS 00025 const TInt KMaxLineLength(23); 00026 00027 // ================= MEMBER FUNCTIONS ======================= 00028 00029 // --------------------------------------------------------- 00030 // CFindItemTestAppContainer::ConstructL 00031 // Symbian 2nd phase constructor can leave. 00032 // --------------------------------------------------------- 00033 // 00034 void CFindItemTestAppContainer::ConstructL(const TRect& aRect) 00035 { 00036 CreateWindowL(); 00037 00038 iListBox = new(ELeave) CEikTextListBox(); 00039 iListBox->SetContainerWindowL( *this ); 00040 TResourceReader reader; 00041 iEikonEnv->CreateResourceReaderLC(reader, R_FINDITEMTESTAPP_LIST); 00042 iListBox->ConstructFromResourceL(reader); 00043 CleanupStack::PopAndDestroy(); 00044 iListBox->CreateScrollBarFrameL(ETrue); 00045 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EOn); 00046 00047 iLabel = new (ELeave) CEikLabel; 00048 iLabel->SetContainerWindowL( *this ); 00049 _LIT(KFindItemTest, "Find Item Test"); 00050 iLabel->SetTextL( KFindItemTest ); 00051 00052 SetRect(aRect); 00053 ActivateL(); 00054 } 00055 00056 // ----------------------------------------------------------------------------- 00057 // CFindItemTestAppContainer::~CFindItemTestAppContainer 00058 // Destructor 00059 // ----------------------------------------------------------------------------- 00060 // 00061 CFindItemTestAppContainer::~CFindItemTestAppContainer() 00062 { 00063 delete iListBox; 00064 delete iLabel; 00065 } 00066 00067 // --------------------------------------------------------- 00068 // CFindItemTestAppContainer::SizeChanged 00069 // Called by framework when the view size is changed 00070 // --------------------------------------------------------- 00071 // 00072 void CFindItemTestAppContainer::SizeChanged() 00073 { 00074 TRect parentRect(Rect()); 00075 TSize listBoxSize(parentRect.Width(), parentRect.Height()); 00076 iListBox->SetExtent( TPoint(0,0), listBoxSize ); 00077 } 00078 00079 // --------------------------------------------------------- 00080 // CFindItemTestAppContainer::CountComponentControls 00081 // Return number of controls in container 00082 // --------------------------------------------------------- 00083 // 00084 TInt CFindItemTestAppContainer::CountComponentControls() const 00085 { 00086 return 2; // return nbr of controls inside this container 00087 } 00088 00089 // --------------------------------------------------------- 00090 // CFindItemTestAppContainer::ComponentControl 00091 // Return component control 00092 // --------------------------------------------------------- 00093 // 00094 CCoeControl* CFindItemTestAppContainer::ComponentControl(TInt aIndex) const 00095 { 00096 switch ( aIndex ) 00097 { 00098 case 0: 00099 return iListBox; 00100 case 1: 00101 return iLabel; 00102 default: 00103 return NULL; 00104 } 00105 } 00106 00107 // --------------------------------------------------------- 00108 // CFindItemTestAppContainer::Draw 00109 // --------------------------------------------------------- 00110 // 00111 void CFindItemTestAppContainer::Draw(const TRect& aRect) const 00112 { 00113 CWindowGc& gc = SystemGc(); 00114 gc.SetPenStyle(CGraphicsContext::ENullPen); 00115 gc.SetBrushColor(KRgbWhite); 00116 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); 00117 gc.DrawRect(aRect); 00118 } 00119 00120 // --------------------------------------------------------- 00121 // CFindItemTestAppContainer::HandleControlEventL 00122 // --------------------------------------------------------- 00123 // 00124 void CFindItemTestAppContainer::HandleControlEventL( 00125 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) 00126 { 00127 } 00128 00129 // ----------------------------------------------------------------------------- 00130 // CFindItemTestAppContainer::AddMessageL 00131 // Add message to list box in the container 00132 // ----------------------------------------------------------------------------- 00133 // 00134 void CFindItemTestAppContainer::AddMessageL( const TDesC& aMsg ) 00135 { 00136 CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() ); 00137 TInt pos(0); 00138 00139 while( aMsg.Length() > pos+KMaxLineLength ) 00140 { 00141 list->AppendL( aMsg.Mid( pos, KMaxLineLength ) ); 00142 pos += KMaxLineLength; 00143 } 00144 list->AppendL( aMsg.Mid( pos ) ); 00145 00146 00147 iListBox->HandleItemAdditionL(); 00148 // Select the last item added 00149 iListBox->SetCurrentItemIndexAndDraw( iListBox->Model()->NumberOfItems() - 1 ); 00150 iListBox->SetFocus( ETrue ); 00151 } 00152 00153 // ----------------------------------------------------------------------------- 00154 // CFindItemTestAppContainer::ResetMessage 00155 // Reset messages of list box in the container 00156 // ----------------------------------------------------------------------------- 00157 // 00158 void CFindItemTestAppContainer::ResetMessage() 00159 { 00160 CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() ); 00161 // remove all items from the text array 00162 list->Reset(); 00163 // Redraw the listbox 00164 iListBox->DrawNow(); 00165 // Set keyboard focus to listbox if you want 00166 iListBox->SetFocus( ETrue ); 00167 } 00168 00169 // ----------------------------------------------------------------------------- 00170 // CFindItemTestAppContainer::OfferKeyEventL 00171 // Pass key event to appropriate controls 00172 // ----------------------------------------------------------------------------- 00173 // 00174 TKeyResponse CFindItemTestAppContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType ) 00175 { 00176 return iListBox->OfferKeyEventL( aKeyEvent, aType ); 00177 } 00178 00179 // --------------------------------------------------------- 00180 // CFindItemTestAppContainer::HandleResourceChange() 00181 // Called by framework when layout is changed. 00182 // --------------------------------------------------------- 00183 // 00184 void CFindItemTestAppContainer::HandleResourceChange(TInt aType) 00185 { 00186 CCoeControl::HandleResourceChange(aType); 00187 00188 if ( aType==KEikDynamicLayoutVariantSwitch ) 00189 { 00190 TRect rect; 00191 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect); 00192 SetRect(rect); 00193 } 00194 // Redraw the listbox 00195 iListBox->DrawNow(); 00196 } 00197 00198 // End of File
|
© Nokia 2006 |