|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : CCEGroupContainer.cpp 00004 * Part of : Content Listing Framework Sample Application 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 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 00017 // INCLUDE FILES 00018 #include "CCEGroupContainer.h" 00019 00020 #include "CCEGroupView.h" 00021 #include "CLFExample.hrh" 00022 #include "CLFExampleConsts.h" 00023 00024 #include <aknlists.h> 00025 #include <barsread.h> 00026 #include <stringloader.h> 00027 #include <CLFExample.rsg> 00028 00029 // ============================ MEMBER FUNCTIONS =============================== 00030 00031 // ----------------------------------------------------------------------------- 00032 // C++ constructor 00033 // C++ default constructor can NOT contain any code, that 00034 // might leave. 00035 // ----------------------------------------------------------------------------- 00036 // 00037 CCEGroupContainer::CCEGroupContainer( CAknView* aParent ) 00038 : iParent( aParent ) 00039 { 00040 } 00041 00042 // ----------------------------------------------------------------------------- 00043 // CCEGroupContainer::ConstructL 00044 // Symbian 2nd phase constructor can leave. 00045 // ----------------------------------------------------------------------------- 00046 // 00047 void CCEGroupContainer::ConstructL() 00048 { 00049 // Create a window for the group view 00050 CreateWindowL(); 00051 00052 // Create a label for info text 00053 HBufC* labelText = StringLoader::LoadLC( R_CE_INFO_LABEL_TEXT ); 00054 iInfoLabel = new (ELeave) CEikLabel; 00055 iInfoLabel->SetContainerWindowL( *this ); 00056 iInfoLabel->SetAlignment( EHCenterVCenter ); 00057 iInfoLabel->SetTextL( *labelText ); 00058 iInfoLabel->SetExtentToWholeScreen(); 00059 CleanupStack::PopAndDestroy( labelText ); 00060 00061 // Create a list box for listing the groups of music files 00062 iListBox = new (ELeave) CAknSingleStyleListBox; 00063 iListBox->MakeVisible( EFalse ); 00064 iListBox->SetContainerWindowL( *this ); 00065 iListBox->ConstructL( this, NULL ); 00066 iListBox->CreateScrollBarFrameL( ETrue ); 00067 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 00068 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); 00069 HBufC* emptyText = StringLoader::LoadLC( R_CE_NO_GROUPS ); 00070 iListBox->View()->SetListEmptyTextL( *emptyText ); 00071 CleanupStack::PopAndDestroy( emptyText ); 00072 00073 // Create a text array for items of the list box 00074 iItemList = new (ELeave) CDesCArraySeg( KCEArrayGranularity ); 00075 iListBox->Model()->SetItemTextArray( iItemList ); 00076 iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); 00077 00078 // Set size of the window and activate it 00079 SetRect( iAvkonAppUi->ClientRect() ); 00080 ActivateL(); 00081 } 00082 00083 // Destructor 00084 CCEGroupContainer::~CCEGroupContainer() 00085 { 00086 delete iItemList; 00087 delete iListBox; 00088 delete iInfoLabel; 00089 } 00090 00091 // ----------------------------------------------------------------------------- 00092 // CCEGroupContainer::AppendListBoxItemL 00093 // Append new item to list box of group listing. 00094 // ----------------------------------------------------------------------------- 00095 // 00096 void CCEGroupContainer::AppendListBoxItemL( const TDesC& aItem ) 00097 { 00098 // Load a string from the resource. The string is used to generate 00099 // the item that will be added to the list box. 00100 HBufC* listItem = StringLoader::LoadLC( R_CE_GROUP_LIST_ITEM, aItem ); 00101 00102 // Append the item to the list box and refresh it 00103 iItemList->AppendL( *listItem ); 00104 iListBox->HandleItemAdditionL(); 00105 CleanupStack::PopAndDestroy( listItem ); 00106 00107 // Make the list box visible, if needed 00108 if( !iListBox->IsVisible() ) 00109 { 00110 iListBox->MakeVisible( ETrue ); 00111 } 00112 } 00113 00114 // ----------------------------------------------------------------------------- 00115 // CCEGroupContainer::CurrentItemIndex 00116 // Get index of the item that is currently selected in the list box. 00117 // ----------------------------------------------------------------------------- 00118 // 00119 TInt CCEGroupContainer::CurrentItemIndex() 00120 { 00121 return iListBox->CurrentItemIndex(); 00122 } 00123 00124 // ----------------------------------------------------------------------------- 00125 // CCEGroupContainer::ResetListBoxL 00126 // Reset list box of group listing. 00127 // ----------------------------------------------------------------------------- 00128 // 00129 void CCEGroupContainer::ResetListBoxL() 00130 { 00131 // Clear the list box model, refresh the list box and make it invisible 00132 iItemList->Reset(); 00133 iListBox->HandleItemRemovalL(); 00134 } 00135 00136 // ----------------------------------------------------------------------------- 00137 // CCEGroupContainer::SetCurrentItemIndex 00138 // Selects specified item of the list box. 00139 // ----------------------------------------------------------------------------- 00140 // 00141 void CCEGroupContainer::SetCurrentItemIndex( TInt aIndex ) 00142 { 00143 iListBox->SetCurrentItemIndexAndDraw( aIndex ); 00144 } 00145 00146 // ----------------------------------------------------------------------------- 00147 // CCEGroupContainer::Draw 00148 // Draw the screen. 00149 // ----------------------------------------------------------------------------- 00150 // 00151 void CCEGroupContainer::Draw( const TRect& aRect ) const 00152 { 00153 // Get the graphics content, set background color and clear the screen 00154 CWindowGc& gc = SystemGc(); 00155 gc.SetPenStyle( CGraphicsContext::ENullPen ); 00156 gc.SetBrushColor( AKN_LAF_COLOR( KCEBackgroundColor ) ); 00157 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00158 gc.Clear( aRect ); 00159 } 00160 00161 // ----------------------------------------------------------------------------- 00162 // CCEGroupContainer::OfferKeyEventL 00163 // Handle user's key event 00164 // ----------------------------------------------------------------------------- 00165 // 00166 TKeyResponse CCEGroupContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 00167 TEventCode aType ) 00168 { 00169 if( aType == EEventKey ) 00170 { 00171 switch( aKeyEvent.iScanCode ) 00172 { 00173 case EStdKeyUpArrow: 00174 case EStdKeyDownArrow: 00175 { 00176 // Send arrow key events to the list box for moving the focus 00177 iListBox->OfferKeyEventL( aKeyEvent, aType ); 00178 return EKeyWasConsumed; 00179 } 00180 00181 case EStdKeyDevice3: 00182 { 00183 // Send selection event to parent view 00184 iParent->HandleCommandL( ECECmdSelect ); 00185 return EKeyWasConsumed; 00186 } 00187 00188 default: 00189 { 00190 break; 00191 } 00192 } 00193 } 00194 return EKeyWasNotConsumed; 00195 } 00196 00197 // ----------------------------------------------------------------------------- 00198 // CCEGroupContainer::CountComponentControls 00199 // Get count of component controls in the container. 00200 // ----------------------------------------------------------------------------- 00201 // 00202 TInt CCEGroupContainer::CountComponentControls() const 00203 { 00204 return KCENumberOfComponentsInGroupContainer; 00205 } 00206 00207 // ----------------------------------------------------------------------------- 00208 // CCEGroupContainer::ComponentControl 00209 // Get component control by its index. 00210 // ----------------------------------------------------------------------------- 00211 // 00212 CCoeControl* CCEGroupContainer::ComponentControl( TInt aIndex ) const 00213 { 00214 switch( aIndex ) 00215 { 00216 case 0: 00217 { 00218 return iInfoLabel; 00219 } 00220 case 1: 00221 { 00222 return iListBox; 00223 } 00224 default: 00225 { 00226 return NULL; 00227 } 00228 } 00229 } 00230 00231 // ----------------------------------------------------------------------------- 00232 // CCEGroupContainer::HandleResourceChange 00233 // Handle change of the screen resolution. 00234 // ----------------------------------------------------------------------------- 00235 // 00236 void CCEGroupContainer::HandleResourceChange( TInt aType ) 00237 { 00238 if ( aType == KEikDynamicLayoutVariantSwitch ) 00239 { 00240 ( static_cast <CCEGroupView *> ( iParent ) )->HandleClientRectChange(); 00241 } 00242 } 00243 00244 // ----------------------------------------------------------------------------- 00245 // CCEGroupContainer::SizeChanged 00246 // Responds to size changes to sets the size and position of the contents of 00247 // this control. 00248 // ----------------------------------------------------------------------------- 00249 // 00250 void CCEGroupContainer::SizeChanged() 00251 { 00252 if( iListBox ) 00253 { 00254 iListBox->SetRect( Rect() ); 00255 } 00256 if( iInfoLabel ) 00257 { 00258 iInfoLabel->SetRect( Rect() ); 00259 } 00260 } 00261 00262 // End of File
|
© Nokia 2009 |