|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <FilelistContainer.h>
Public Member Functions | |
| ~CFilelistContainer () | |
| void | SetGridInitialParametersL () |
| void | CreateGridResourceL () |
| void | LoadGraphicsL () |
| void | AddDataL () |
| void | ApplySelGridGraphicStyle () |
| void | SetIconSizes (CArrayPtr< CGulIcon > *aIconArray) |
| void | CreateFilelist () |
| void | ChangePrivateFolderL (TInt aDestFolder) |
| void | ChangeProtectedFolderL () |
| void | ShowErrorNoteL (TInt aErr) |
Static Public Member Functions | |
| static CFilelistContainer * | NewL (const TRect &aRect) |
| static CFilelistContainer * | NewLC (const TRect &aRect) |
Private Member Functions | |
| void | HandleListBoxEventL (CEikListBox *aListBox, TListBoxEvent aListBoxEvent) |
| void | ConstructL (const TRect &aRect) |
| void | SizeChanged () |
| void | Draw (const TRect &aRect) const |
| TInt | CountComponentControls () const |
| CCoeControl * | ComponentControl (TInt aIndex) const |
| TKeyResponse | OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType) |
| void | SetFolderID (TInt aFolderID) |
| TInt | FolderID () const |
| void | SetEmptyTextL () |
| void | SetNaviPaneTextL () |
Private Attributes | |
| CAknGrid * | iGrid |
| CAknGridM * | iGridM |
| TBool | iVerticalOrientation |
| TBool | iLeftToRight |
| TBool | iTopToBottom |
| TInt | iNumOfColumns |
| TInt | iNumOfRows |
| TInt | iContentType |
| TSize | iSizeOfCell |
| TInt | iNumOfItems |
| CAknGridView::TScrollingType | iVerticalScrollingType |
| CAknGridView::TScrollingType | iHorizontalScrollingType |
| CDir * | iFilelist |
| CFbsBitmap * | iBitmap |
| CFbsBitmap * | iMask |
| TInt | iFolderID |
| CAknNavigationDecorator * | iNaviDecorator |
| CAknNavigationControlContainer * | iNaviPane |
| RFs | iSession |
Definition at line 83 of file FilelistContainer.h.
|
|
Destructor. Definition at line 68 of file FilelistContainer.cpp. References iFilelist, iGrid, iNaviDecorator, and iSession. 00069 { 00070 iSession.Close(); 00071 delete iGrid; 00072 delete iFilelist; 00073 delete iNaviDecorator; 00074 }
|
|
|
NewL. Two-phased constructor. Construct a CFilelistContainer using two phase construction, and return a pointer to the created object
Definition at line 43 of file FilelistContainer.cpp. References NewLC(). 00044 { 00045 CFilelistContainer* self = CFilelistContainer::NewLC( aRect ); 00046 CleanupStack::Pop( self ); 00047 return self; 00048 }
|
|
|
NewLC. Two-phased constructor. Construct a CFilelistContainer using two phase construction, and return a pointer to the created object
Definition at line 55 of file FilelistContainer.cpp. 00056 { 00057 CFilelistContainer* self = new ( ELeave ) CFilelistContainer(); 00058 CleanupStack::PushL( self ); 00059 self->ConstructL( aRect ); 00060 return self; 00061 }
|
|
|
SetGridInitialParameters. Sets initial parameters for the grid. Definition at line 81 of file FilelistContainer.cpp. References iFilelist, iGrid, iHorizontalScrollingType, iLeftToRight, iNumOfColumns, iNumOfItems, iNumOfRows, iSizeOfCell, iTopToBottom, iVerticalOrientation, and iVerticalScrollingType. 00082 { 00083 TSize mpSize; // main pane size 00084 AknLayoutUtils::LayoutMetricsSize( AknLayoutUtils::EMainPane, mpSize ); 00085 00086 iNumOfItems = iFilelist->Count(); 00087 00088 iNumOfColumns = KGridColumns; 00089 iNumOfRows = KGridRows; 00090 00091 // Determinate cell size 00092 iSizeOfCell.iWidth = mpSize.iWidth / iNumOfColumns; 00093 iSizeOfCell.iHeight = mpSize.iHeight / iNumOfRows; 00094 00095 // Determinate scrolling type 00096 iVerticalScrollingType = CAknGridView::EScrollIncrementLineAndLoops; 00097 iHorizontalScrollingType = CAknGridView::EScrollIncrementLineAndLoops; 00098 00099 00100 iVerticalOrientation = EFalse; 00101 iLeftToRight = ETrue; 00102 iTopToBottom = ETrue; 00103 00104 // Set grid layout 00105 iGrid->SetLayoutL( iVerticalOrientation, 00106 iLeftToRight, iTopToBottom, 00107 iNumOfColumns, iNumOfRows, 00108 iSizeOfCell ); 00109 00110 // Set scrolling type 00111 iGrid->SetPrimaryScrollingType( iVerticalScrollingType ); 00112 iGrid->SetSecondaryScrollingType( iHorizontalScrollingType ); 00113 00114 // Set current index in grid 00115 iGrid->SetCurrentDataIndex( 0 ); 00116 }
|
|
|
CreateGridResourceL. Prepares resources for the grid. Definition at line 123 of file FilelistContainer.cpp. References AddDataL(), and LoadGraphicsL(). 00124 { 00125 // Load graphics 00126 LoadGraphicsL(); 00127 00128 // Create data 00129 AddDataL(); 00130 }
|
|
|
LoadGraphicsL. Loads graphic resources. Definition at line 137 of file FilelistContainer.cpp. References iBitmap, iGrid, iMask, and iSizeOfCell. 00138 { 00139 // Create icon array with granularity of 1 icon 00140 CArrayPtr< CGulIcon >* icons = new(ELeave) CAknIconArray( 1 ); 00141 CleanupStack::PushL( icons ); 00142 00143 // Creates bitmap and mask for an icon. 00144 AknIconUtils::CreateIconL( iBitmap, 00145 iMask, 00146 KIconName, 00147 EMbmFilelistQgn_menu_filelist, 00148 EMbmFilelistQgn_menu_filelist_mask ); 00149 00150 // Determinate icon size 00151 TSize iconSize; 00152 iconSize.iWidth = iSizeOfCell.iWidth / 2; 00153 iconSize.iHeight = iSizeOfCell.iHeight / 2; 00154 00155 //Initializes the icon to the given size. 00156 //Note that this call sets the sizes of both bitmap and mask 00157 AknIconUtils::SetSize( iBitmap, iconSize ); 00158 00159 // Append the icon to icon array 00160 icons->AppendL( CGulIcon::NewL( iBitmap, iMask ) ); 00161 00162 // Attach icon array to grid's item drawer 00163 iGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons ); 00164 00165 CleanupStack::Pop( icons ); 00166 }
|
|
|
AddDataL. Adds data to the grid. Definition at line 173 of file FilelistContainer.cpp. References iFilelist, and iGrid. 00174 { 00175 00176 MDesCArray* array = iGrid->Model()->ItemTextArray(); 00177 CDesCArray* cArray = ( CDesCArray* )array; 00178 00179 // The number of items in the grid. 00180 TInt numberOfData = iFilelist->Count(); 00181 00182 // Delete data from array 00183 if ( iGrid->GridModel()->NumberOfData() > 0 ) 00184 { 00185 cArray->Delete( 0, iGrid->GridModel()->NumberOfData() ); 00186 } 00187 iGrid->HandleItemRemovalL(); 00188 00189 // Create text which is added to the grid. 00190 TBuf< KLengthOfItemResourceString > cellText; 00191 TBuf< KLengthOfItemResourceString > cellTextFormat; 00192 00193 iCoeEnv->ReadResourceL( cellTextFormat, R_FILELIST_FORMATSTRING ); 00194 00195 // Add the item to the last index 00196 for ( TInt loop = 0; loop < numberOfData; loop++ ) 00197 { 00198 cellText.Format( cellTextFormat, &(*iFilelist)[loop].iName ); 00199 cArray->AppendL( cellText ); 00200 } 00201 00202 // Inform list box that data was added. 00203 iGrid->HandleItemAdditionL(); 00204 }
|
|
|
ApplySelGridGraphicStyle. Applies the layout to cells in the grid. Definition at line 211 of file FilelistContainer.cpp. References iGrid, iSizeOfCell, and SetIconSizes(). 00212 { 00213 AknListBoxLayouts::SetupStandardGrid( *iGrid ); 00214 00215 // Layout of the graphic 00216 AknListBoxLayouts::SetupFormGfxCell( 00217 *iGrid, // Reference to grid control 00218 iGrid->ItemDrawer(),// Pointer to the item drawer 00219 0, // Column index 00220 0, // Left position 00221 0, // Top position 00222 0, // Right - unused 00223 0, // Bottom - unused 00224 iSizeOfCell.iWidth, // Width 00225 iSizeOfCell.iHeight/2,// Height 00226 TPoint(0,0), // Start position 00227 TPoint(iSizeOfCell.iWidth, iSizeOfCell.iHeight/2)); // End position 00228 00229 const CFont* fontText = AknLayoutUtils::FontFromId( 00230 EAknLogicalFontPrimaryFont, NULL ); 00231 00232 // Deretminate the baseline for the text 00233 TInt baseline = iSizeOfCell.iHeight - fontText->DescentInPixels() - 1; 00234 00235 // Layout of text 00236 AknListBoxLayouts::SetupFormTextCell( 00237 *iGrid, // Reference to grid 00238 iGrid->ItemDrawer(), // Pointer to the item drawer 00239 1, // Column index 00240 fontText, // Font 00241 215, // Color (215 = black) 00242 0, // Left margin 00243 0, // Right margin - unused 00244 baseline, // Baseline 00245 iSizeOfCell.iWidth, // Text width 00246 CGraphicsContext::ECenter, // Text alignment 00247 TPoint(0, iSizeOfCell.iHeight/2), // Start position 00248 TPoint(iSizeOfCell.iWidth, 00249 iSizeOfCell.iHeight)); // End position 00250 00251 //Update icon size 00252 SetIconSizes( iGrid->ItemDrawer()->FormattedCellData()->IconArray() ); 00253 }
|
|
|
SetIconSizes. Sets size of the icon in iconarray.
Definition at line 261 of file FilelistContainer.cpp. References iSizeOfCell. 00262 { 00263 TSize iconSize; 00264 iconSize.iWidth = iSizeOfCell.iWidth / 2; 00265 iconSize.iHeight = iSizeOfCell.iHeight / 2; 00266 00267 // note AknIconUtils::SetSize sets both mask and bitmap size. 00268 // regardless which is given. 00269 AknIconUtils::SetSize( (*aIconArray)[0]->Bitmap(), iconSize ); 00270 }
|
|
|
CreateFilelist Read files in folder and save them to iFilelist Definition at line 277 of file FilelistContainer.cpp. References FolderID(), iFilelist, and iSession. 00278 { 00279 // List must be empty 00280 if ( iFilelist ) 00281 { 00282 delete iFilelist; 00283 iFilelist=NULL; 00284 } 00285 00286 TBuf< KPathNameLength > dPath; 00287 TBuf< KPathNameLength > dPathF; 00288 00289 // Get application's private path 00290 iSession.PrivatePath( dPath ); 00291 00292 // Set actual folder path 00293 if ( FolderID() == EPrivateFolder2 ) 00294 { 00295 dPathF.Format( KPrivateFolderPath2, &dPath ); 00296 } 00297 else 00298 { 00299 dPathF.Format( KPrivateFolderPath1, &dPath ); 00300 } 00301 00302 // Get the file list, sorted by name 00303 User::LeaveIfError( iSession.GetDir( 00304 dPathF, 00305 KEntryAttMaskSupported, 00306 ESortByName, 00307 iFilelist ) ); 00308 }
|
|
|
ChangePrivateFolderL. Retrieves data from another private folder.
Definition at line 315 of file FilelistContainer.cpp. References AddDataL(), CreateFilelist(), iGrid, SetFolderID(), and SetNaviPaneTextL(). 00316 { 00317 // Change folder ID 00318 SetFolderID( aDestFolder ); 00319 00320 // Read filenames from folder 00321 CreateFilelist(); 00322 00323 // Add text to grid 00324 AddDataL(); 00325 00326 // Set text to navi pane 00327 SetNaviPaneTextL(); 00328 00329 iGrid->DrawNow(); 00330 }
|
|
|
ChangeProtectedFolderL. Changes to protected folder. Definition at line 337 of file FilelistContainer.cpp. References iSession, and ShowErrorNoteL(). 00338 { 00339 CDir* protFolder; 00340 00341 //Expected value is KErrPermissionDenied=(-46) 00342 TInt err = iSession.GetDir( 00343 KProtectedFolderPath, 00344 KEntryAttMaskSupported, 00345 ESortByName, 00346 protFolder ) ; 00347 00348 if ( err != KErrNone ) 00349 { 00350 ShowErrorNoteL( err ); 00351 } 00352 delete protFolder; 00353 }
|
|
|
ShowErrorNoteL. Shows error dialog
Definition at line 360 of file FilelistContainer.cpp. 00361 { 00362 TBuf< KErrorNoteLength > errorBuf; 00363 // Create CAknErrorNote instance 00364 CAknErrorNote* dialog = new ( ELeave ) CAknErrorNote(); 00365 00366 //Allocate TBuf with constant length. 00367 TBuf< KErrorNoteLength > errNote; 00368 00369 // Reads a resource into a descriptor. 00370 iCoeEnv->ReadResourceL( errNote, R_FILELIST_ERRORNOTE_TEXT ); 00371 errorBuf.Format( errNote, aErr ); 00372 00373 // Show the Dialog 00374 dialog->ExecuteLD( errorBuf ); 00375 }
|
|
||||||||||||
|
From MEikListBoxObserver,HandleListBoxEventL. Definition at line 383 of file FilelistContainer.cpp.
|
|
|
From CCoeControl,ConstructL. Symbian default constructor.
Definition at line 413 of file FilelistContainer.cpp. References CreateFilelist(), CreateGridResourceL(), iGrid, iGridM, iSession, SetEmptyTextL(), SetFolderID(), SetGridInitialParametersL(), and SetNaviPaneTextL(). 00414 { 00415 CreateWindowL(); 00416 00417 iSession.Connect(); 00418 00419 SetFolderID( EPrivateFolder1 ); 00420 00421 // Create CAknGrid instance: 00422 iGrid = new(ELeave) CAknGrid; 00423 00424 //Set the container window for grid control 00425 iGrid->SetContainerWindowL( *this ); 00426 00427 //Create a model and attach it to grid control: 00428 iGridM = new(ELeave) CAknGridM; 00429 iGrid->SetModel( iGridM ); 00430 00431 //Call ConstructL for the grid object: 00432 TInt gridFlags = EAknListBoxSelectionGrid; 00433 iGrid->ConstructL( this, gridFlags); 00434 00435 // Gets filename from folder 00436 CreateFilelist(); 00437 00438 // Set initial parameters for the grid 00439 SetGridInitialParametersL(); 00440 00441 //Sets text to empty grid 00442 SetEmptyTextL(); 00443 00444 // Create resouce for grid 00445 CreateGridResourceL(); 00446 00447 // Set observer 00448 iGrid->SetListBoxObserver( this ); 00449 00450 //Set navi pane text from resource 00451 SetNaviPaneTextL(); 00452 00453 // Set the windows size 00454 SetRect( aRect ); 00455 00456 // Activate the window, which makes it ready to be drawn 00457 ActivateL(); 00458 }
|
|
|
From CoeControl,SizeChanged. Definition at line 465 of file FilelistContainer.cpp. References ApplySelGridGraphicStyle(), iGrid, and SetGridInitialParametersL(). 00466 { 00467 if ( iGrid ) 00468 { 00469 // Set initial parameters for the grid 00470 TRAP_IGNORE( SetGridInitialParametersL() ); 00471 00472 //Apply the layout to cells in the grid 00473 ApplySelGridGraphicStyle(); 00474 00475 iGrid->SetRect( Rect() ); 00476 } 00477 }
|
|
|
From CCoeControl,Draw. Definition at line 484 of file FilelistContainer.cpp.
|
|
|
From CCoeControl,CountComponentControls. Definition at line 495 of file FilelistContainer.cpp.
|
|
|
From CCoeControl,ComponentControl. Definition at line 507 of file FilelistContainer.cpp. References iGrid. 00508 { 00509 switch ( aIndex ) 00510 { 00511 case 0: 00512 return iGrid; 00513 default: 00514 return NULL; 00515 } 00516 }
|
|
||||||||||||
|
From CCoeControl,OfferKeyEventL. Definition at line 525 of file FilelistContainer.cpp. References iGrid. 00527 { 00528 if ( iGrid ) 00529 { 00530 return iGrid->OfferKeyEventL ( aKeyEvent, aType ); 00531 } 00532 else 00533 { 00534 return EKeyWasNotConsumed; 00535 } 00536 }
|
|
|
SetFolderID. Sets folderID.
Definition at line 543 of file FilelistContainer.cpp. References iFolderID. 00544 { 00545 iFolderID = aFolderID; 00546 }
|
|
|
GetFolderID. Returns folder ID
Definition at line 553 of file FilelistContainer.cpp. References iFolderID. 00554 { 00555 return iFolderID; 00556 }
|
|
|
SetEmptyTextL. Sets text to empty grid Definition at line 563 of file FilelistContainer.cpp. References iGrid. 00564 { 00565 TBuf< KEmptyGridText > emptyTxt; 00566 iCoeEnv->ReadResourceL( emptyTxt, R_FILELIST_EMPTYTEXT ); 00567 iGrid->SetEmptyGridTextL( emptyTxt ); 00568 }
|
|
|
SetNaviPaneTextL. Sets text to Navigation Pane Definition at line 574 of file FilelistContainer.cpp. References FolderID(), iNaviDecorator, and iNaviPane. 00575 { 00576 TResourceReader spText; 00577 00578 // Create navipane pointer 00579 if ( !iNaviPane ) 00580 { 00581 CEikStatusPane *sp = 00582 ( ( CAknAppUi* )iEikonEnv->EikAppUi() )->StatusPane(); 00583 // Fetch pointer to the default navi pane control 00584 iNaviPane = ( CAknNavigationControlContainer * ) 00585 sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ); 00586 } 00587 00588 if ( iNaviDecorator ) 00589 { 00590 delete iNaviDecorator; 00591 iNaviDecorator = NULL; 00592 } 00593 00594 // Read text from resource 00595 if ( FolderID() == EPrivateFolder1 ) 00596 { 00597 iCoeEnv->CreateResourceReaderLC( spText, R_FILELIST_NAVI_PANE_TEXT1 ); 00598 } 00599 else 00600 { 00601 iCoeEnv->CreateResourceReaderLC( spText, R_FILELIST_NAVI_PANE_TEXT2 ); 00602 } 00603 00604 // Set text to navi pane 00605 iNaviDecorator = iNaviPane->CreateNavigationLabelL( spText ); 00606 CleanupStack::PopAndDestroy(); // Pushed by CreateResourceReaderLC 00607 iNaviPane->PushL( *iNaviDecorator ); 00608 }
|
|
|
iGrid, the grid shown in this view. Definition at line 255 of file FilelistContainer.h. |
|
|
iGridM, model for iGrid Definition at line 260 of file FilelistContainer.h. |
|
|
iVerticalOrientation, vertical orietation status Definition at line 265 of file FilelistContainer.h. |
|
|
iLeftToRight, fill order status Definition at line 270 of file FilelistContainer.h. |
|
|
iTopToBottom, fill order status Definition at line 275 of file FilelistContainer.h. |
|
|
iNumOfColumns, number of grid columns Definition at line 280 of file FilelistContainer.h. |
|
|
iNumOfRows, number of grid rows Definition at line 285 of file FilelistContainer.h. |
|
|
iContentType, type of content Definition at line 290 of file FilelistContainer.h. |
|
|
iSizeOfCell, size of grid cell Definition at line 295 of file FilelistContainer.h. |
|
|
iNumOfItems, number of grid items Definition at line 300 of file FilelistContainer.h. |
|
|
iVerticalScrollingType, scrolling type Definition at line 305 of file FilelistContainer.h. |
|
|
iHorizontalScrollingType, scrolling type Definition at line 310 of file FilelistContainer.h. |
|
|
iFilelist, file list Definition at line 315 of file FilelistContainer.h. |
|
|
iBitmap, grid icon Definition at line 320 of file FilelistContainer.h. |
|
|
iMask, mask of grid icon Definition at line 325 of file FilelistContainer.h. |
|
|
iFolderID, ID to current private folder Definition at line 330 of file FilelistContainer.h. |
|
|
iNaviDecorator Definition at line 335 of file FilelistContainer.h. |
|
|
iNaviPane Definition at line 340 of file FilelistContainer.h. |
|
|
iSession file server session Definition at line 345 of file FilelistContainer.h. |
|
© Nokia 2006 |