Nokia N97 SDK
Example Applications Guide

aknexpoplistview.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : aknexpoplistview.cpp
00004 *  Part of     : Popup-list example
00005 *  Interface   :
00006 *  Description :
00007 *  Version     :
00008 *
00009 *  Copyright (c) 2004 - 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 <aknviewappui.h>
00018 #include <avkon.hrh>
00019 #include <AknPopup.h>
00020 #include <AknLists.h>
00021 #include <AknNoteDialog.h>
00022 #include <BarsRead.h>
00023 #include <eikdef.h>
00024 #include <GulIcon.h>
00025 #include <EikClbd.h>
00026 #include <eikenv.h>
00027 #include <eikapp.h>
00028 #include <eikappui.h>
00029 #include <AknIconArray.h>
00030 #include <AknExPopList.mbg>
00031 #include <AknExPopList.rsg>
00032 
00033 #include "IconFileProvider.h"
00034 #include "AknExPopList.hrh"
00035 #include "AknExPopListView.h"
00036 #include "AknExPopListContainer.h" 
00037 
00038 // ========================= MEMBER FUNCTIONS ==================================
00039 
00040 // ------------------------------------------------------------------------------
00041 // CAknExPopListView::ConstructL()
00042 // Symbian 2nd phase constructor can leave.
00043 // ------------------------------------------------------------------------------
00044 //
00045 void CAknExPopListView::ConstructL()
00046     {
00047     BaseConstructL( R_AKNEXPOPLIST_VIEW1 );
00048     
00049         // create and open file server session
00050     User::LeaveIfError(iFsSession.Connect());
00051     iFsSession.ShareProtected();
00052 
00053     TFileName filePath;
00054 
00055     // set path of the bitmap file
00056     User::LeaveIfError(iFsSession.PrivatePath(filePath));
00057 
00058     // append the MBM file name to the private path
00059     filePath.Append(KPathAppMbm);
00060 
00061     // insert the drive to the private path
00062     TParsePtrC parse((CEikonEnv::Static()->EikAppUi()->Application())->AppFullName());
00063     filePath.Insert(0, parse.Drive());
00064 
00065     // with the help of icon-provider AknIconUtils can get get the file
00066     // from this application's private folder
00067     iIconProvider = CIconFileProvider::NewL(iFsSession, filePath);
00068     }
00069 
00070 // ------------------------------------------------------------------------------
00071 // CAknExPopListView::~CAknExPopListView()
00072 // Destructor.
00073 // ------------------------------------------------------------------------------
00074 //
00075 CAknExPopListView::~CAknExPopListView()
00076     {
00077     if ( iContainer )
00078         {
00079         AppUi()->RemoveFromStack( iContainer );
00080         }
00081     delete iContainer;
00082 
00083     iFsSession.Close();
00084     delete iIconProvider;
00085     }
00086 
00087 // ------------------------------------------------------------------------------
00088 // CAknExPopListView::Id()
00089 // Returns view id
00090 // ------------------------------------------------------------------------------
00091 //
00092 TUid CAknExPopListView::Id() const
00093     {
00094     return KViewId;
00095     }
00096 
00097 // -----------------------------------------------------------------------------
00098 // CAknExPopListView::HandleCommandL()
00099 // Handles the commands.
00100 // -----------------------------------------------------------------------------
00101 //
00102 void CAknExPopListView::HandleCommandL( TInt aCommand )
00103     {   
00104     switch ( aCommand )
00105         {
00106         case EAknSoftkeyBack:
00107             AppUi()->HandleCommandL( EAknCmdExit );
00108             break;
00109 
00110         case EAknExPopListCmdAuto:
00111         case EAKnTaPopListSoftkeyNext:
00112             AutoTestL();
00113             break;
00114 
00115         case EAknExPopListCmdView1Menu2:
00116             ShowSingleItemPopupListL();
00117             break;
00118 
00119         case EAknExPopListCmdView1Menu5:
00120             ShowSingleItemPopupListWithGraphicsL();
00121             break;
00122 
00123         case EAknExPopListCmdView1Menu9:
00124             ShowDoubleItemPopupListWithGraphicsL();
00125             break;
00126 
00127         default:
00128             AppUi()->HandleCommandL( aCommand );
00129             break;
00130 
00131         }
00132     }
00133 
00134 // -----------------------------------------------------------------------------
00135 // CAknExPopListView::HandleViewRectChange()
00136 // Handles Clients Rect
00137 // -----------------------------------------------------------------------------
00138 //
00139 void CAknExPopListView::HandleViewRectChange()
00140     {
00141     if ( iContainer )
00142         {
00143         iContainer->SetRect( ClientRect() );
00144         }
00145     }
00146 
00147 // -----------------------------------------------------------------------------
00148 // CAknExPopListView::DoActivateL()
00149 // Creates container class object.
00150 // -----------------------------------------------------------------------------
00151 //
00152 void CAknExPopListView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
00153                                      TUid /*aCustomMessageId*/,
00154                                      const TDesC8& /*aCustomMessage*/ )
00155     {
00156 
00157     iContainer = new( ELeave ) CAknExPopListContainer;
00158     iContainer->SetMopParent( this );
00159     iContainer->ConstructL( ClientRect() );
00160     AppUi()->AddToStackL( *this, iContainer );
00161    }
00162 
00163 
00164 // -----------------------------------------------------------------------------
00165 // CAknExPopListView::DoDeactivate()
00166 // Deletes container class object.
00167 // -----------------------------------------------------------------------------
00168 //
00169 void CAknExPopListView::DoDeactivate()
00170     {
00171     if ( iContainer )
00172         {
00173         AppUi()->RemoveFromStack( iContainer );
00174         }
00175     
00176     delete iContainer;
00177     iContainer = NULL;
00178     }
00179 
00180 
00181 // -----------------------------------------------------------------------------
00182 // CAknExPopListView::AutoTestL()
00183 // Shows all kind of popup-windows except list_single_number_pane,
00184 // list_single_heading_pane, and list_single_number_heading_pane
00185 // automatically.
00186 // -----------------------------------------------------------------------------
00187 //
00188 void CAknExPopListView::AutoTestL()
00189     {
00190     ShowSingleItemPopupListL();
00191     ShowSingleItemPopupListWithGraphicsL();
00192     ShowDoubleItemPopupListWithGraphicsL();
00193     }
00194 
00195 
00196 // -----------------------------------------------------------------------------
00197 // CAknExPopListView::ShowSingleItemPopupListL()
00198 // shows "List pane for single item"
00199 // -----------------------------------------------------------------------------
00200 //
00201 void CAknExPopListView::ShowSingleItemPopupListL()
00202     {
00203 
00204     // Create CEikTextListBox instance, list
00205     CEikTextListBox* list = new( ELeave ) CAknSinglePopupMenuStyleListBox;
00206 
00207     // Push list'pointer to CleanupStack.
00208     CleanupStack::PushL( list );
00209 
00210     // Create CAknPopupList instance, popupList
00211     CAknPopupList* popupList = CAknPopupList::NewL( list, 
00212                                                     R_AVKON_SOFTKEYS_SELECT_CANCEL,
00213                                                     AknPopupLayouts::EMenuWindow );
00214     // Push popupList'pointer to CleanupStack.
00215     CleanupStack::PushL( popupList );
00216 
00217     
00218     // Initialize listbox.
00219     list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
00220     list->CreateScrollBarFrameL( ETrue );
00221     list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
00222                                                      CEikScrollBarFrame::EAuto );
00223 
00224     // Create CDesCArrayFlat instance, items
00225     CDesCArrayFlat* items = iCoeEnv->ReadDesCArrayResourceL(
00226                                        R_AKNEXPOPLIST_MENU_ITEMS_TEST1 );
00227         // Push items'pointer to CleanupStack.  
00228     CleanupStack::PushL( items );
00229 
00230     // Set listitems.
00231     CTextListBoxModel* model = list->Model();
00232     model->SetItemTextArray( items );
00233     model->SetOwnershipType( ELbmOwnsItemArray );
00234     
00235     CleanupStack::Pop();
00236 
00237     // Show popup list and then show return value.
00238     TInt popupOk = popupList->ExecuteLD();
00239 
00240     // Pop the popupList's pointer from CleanupStack
00241     CleanupStack::Pop();
00242 
00243     if ( popupOk )
00244         {
00245         TInt index = list->CurrentItemIndex();
00246         TBuf<KMessageLength> msg;
00247         TBuf<KMessageLength> format;
00248         iCoeEnv->ReadResource( format, R_AKNEXPOPLIST_SELECT_MESSAGE );
00249         msg.Format( format, index + 1 );
00250         CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog( 
00251                                                 CAknNoteDialog::ENoTone, 
00252                                                 CAknNoteDialog::ENoTimeout );
00253 
00254         dlg->PrepareLC(  R_AKNEXPOPLIST_SELECT_MESSAGE_NOTE  );
00255         dlg->SetTextPluralityL(  EFalse  );
00256         dlg->SetTextL(  msg  );
00257         dlg->RunLD();
00258         }
00259     // Pop and Destroy the list's pointer from CleanupStack
00260     CleanupStack::PopAndDestroy();
00261     }
00262 
00263 // -----------------------------------------------------------------------------
00264 // CAknExPopListView::ShowSingleItemPopupListWithGraphicsL( )
00265 // shows "List pane for single item with graphic"
00266 // -----------------------------------------------------------------------------
00267 void CAknExPopListView::ShowSingleItemPopupListWithGraphicsL()
00268     {
00269 
00270     // Create CAknSingleGraphicPopupMenuStyleListBox instance, list
00271     CAknSingleGraphicPopupMenuStyleListBox* list = 
00272                             new( ELeave ) CAknSingleGraphicPopupMenuStyleListBox;
00273     
00274     // Push list'pointer to CleanupStack.
00275     CleanupStack::PushL( list );
00276 
00277     // Create CAknPopupList instance, popupList
00278     CAknPopupList* popupList = CAknPopupList::NewL( 
00279                                             list, R_AVKON_SOFTKEYS_SELECT_CANCEL,
00280                                             AknPopupLayouts::EMenuGraphicWindow );    
00281     // Push popupList'pointer to CleanupStack.
00282     CleanupStack::PushL( popupList );
00283 
00284     // Initialize list.
00285     list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
00286     list->CreateScrollBarFrameL( ETrue );
00287     list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
00288                                                      CEikScrollBarFrame::EAuto );
00289     // Reads a resource into a descriptor.
00290     CDesCArrayFlat* items =  iCoeEnv->ReadDesCArrayResourceL(
00291                                                R_AKNEXPOPLIST_MENU_ITEMS_TEST2 );
00292     // Push items'pointer to CleanupStack.
00293     CleanupStack::PushL( items );
00294 
00295     // Set listitems.
00296     CTextListBoxModel* model = list->Model();
00297     model->SetItemTextArray( items );
00298     model->SetOwnershipType( ELbmOwnsItemArray );
00299     CleanupStack::Pop();
00300 
00301     // Create Icon object
00302     CArrayPtr<CGulIcon>* icons =  new( ELeave ) CAknIconArray( KMaxIcons );
00303 
00304     // Push icons'pointer to CleanupStack.
00305     CleanupStack::PushL( icons );
00306 
00307     CFbsBitmap* bitmap = AknIconUtils::CreateIconL( *iIconProvider,
00308             EMbmAknexpoplistCard );
00309     CleanupStack::PushL( bitmap );
00310 
00311     CFbsBitmap* mask = AknIconUtils::CreateIconL( *iIconProvider,
00312             EMbmAknexpoplistCard_mask );
00313     CleanupStack::PushL( mask );
00314     icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
00315 
00316     CleanupStack::Pop(); // mask
00317     CleanupStack::Pop(); // bitmap
00318 
00319     CFbsBitmap* bitmap2 = AknIconUtils::CreateIconL( *iIconProvider,
00320             EMbmAknexpoplistTel );
00321     CleanupStack::PushL( bitmap2 );
00322 
00323     CFbsBitmap* mask2 = AknIconUtils::CreateIconL( *iIconProvider,
00324             EMbmAknexpoplistTel_mask );
00325     CleanupStack::PushL( mask2 );
00326     icons->AppendL( CGulIcon::NewL( bitmap2, mask2 ) );
00327 
00328     CleanupStack::Pop(); // mask2
00329     CleanupStack::Pop(); // bitmap2
00330 
00331     list->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
00332     
00333     // Pop the Icon's pointer from CleanupStack
00334     CleanupStack::Pop();
00335 
00336     list->ClearSelection();
00337     CArrayFixFlat<TInt>* array1 = new( ELeave ) 
00338                                        CArrayFixFlat<TInt>( KIndexArraySize );
00339 
00340     CleanupStack::PushL( array1 );
00341     array1->AppendL( 1 );
00342     array1->AppendL( 2 );
00343     
00344     list->SetSelectionIndexesL( array1 );
00345 
00346     // Pop and Destroy the array1's pointer from CleanupStack
00347     CleanupStack::PopAndDestroy();
00348 
00349     list->ItemDrawer()->SetItemMarkPosition( KInitPos );
00350     TPtrC blank( KInitPosString );
00351     list->ItemDrawer()->SetItemMarkReplacement( blank );
00352 
00353     // Set title
00354     // Allocate TBuf with constant length.
00355     TBuf<KMaxTitleLength> title;
00356 
00357     // Reads a resource into a descriptor.
00358     iCoeEnv->ReadResource( title, R_AKNEXPOPLIST_MENU_TITLE_TEST2 );
00359 
00360     popupList->SetTitleL( title );
00361 
00362     // Show popup list and then show return value.
00363     TInt popupOk = popupList->ExecuteLD();
00364     
00365      // Pop the popupList's pointer from CleanupStack
00366     CleanupStack::Pop();
00367     if ( popupOk )
00368         {
00369         TInt index = list->CurrentItemIndex();
00370         //Allocate TBuf with constant length.
00371         TBuf<KMessageLength> msg;
00372         
00373         //Allocate TBuf with constant length.
00374         TBuf<KMessageLength> format;
00375 
00376         // Reads a resource into a descriptor.
00377         iCoeEnv->ReadResource( format, R_AKNEXPOPLIST_SELECT_MESSAGE );
00378 
00379         msg.Format( format, index + 1 );
00380         CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog( 
00381                                             CAknNoteDialog::ENoTone, 
00382                                             CAknNoteDialog::ENoTimeout );
00383 
00384         dlg->PrepareLC(  R_AKNEXPOPLIST_SELECT_MESSAGE_NOTE  );
00385         dlg->SetTextPluralityL(  EFalse  );
00386         dlg->SetTextL(  msg  );
00387         dlg->RunLD();
00388         }
00389 
00390     // Pop and Destroy the list's pointer from CleanupStack
00391     CleanupStack::PopAndDestroy();
00392     }
00393 
00394 // -----------------------------------------------------------------------------
00395 // CAknExPopListView::ShowDoubleItemPopupListWithGraphicsL()
00396 // shows "List pane for double item"
00397 // -----------------------------------------------------------------------------
00398 //
00399 void CAknExPopListView::ShowDoubleItemPopupListWithGraphicsL()
00400     {
00401 
00402     CAknDoubleLargeGraphicPopupMenuStyleListBox* list = 
00403                      new( ELeave ) CAknDoubleLargeGraphicPopupMenuStyleListBox;
00404     
00405     CleanupStack::PushL( list );
00406     CAknPopupList* popupList = CAknPopupList::NewL( 
00407                                         list, R_AVKON_SOFTKEYS_SELECT_CANCEL,
00408                                         AknPopupLayouts::EMenuDoubleLargeGraphicWindow );    
00409     CleanupStack::PushL( popupList );
00410 
00411     TInt flags = 0; // Initialize flag
00412     list->ConstructL( popupList, flags );
00413     list->CreateScrollBarFrameL( ETrue );
00414     list->ScrollBarFrame()->SetScrollBarVisibilityL( 
00415                                 CEikScrollBarFrame::EOff,
00416                                 CEikScrollBarFrame::EAuto );
00417 
00418     // Set Item text
00419     CDesCArrayFlat* items = 
00420             iCoeEnv->ReadDesCArrayResourceL( R_AKNEXPOPLIST_MENU_ITEMS_TEST5 );
00421     CleanupStack::PushL( items );
00422 
00423     // Set listitems.
00424     CTextListBoxModel* model = list->Model();
00425     model->SetItemTextArray( items );
00426     model->SetOwnershipType( ELbmOwnsItemArray );
00427     CleanupStack::Pop();
00428 
00429     // Create Icon object
00430     CArrayPtr<CGulIcon>* icons =  new( ELeave ) CAknIconArray( KMaxIcons );
00431    
00432     CleanupStack::PushL( icons );
00433 
00434     // Load bitmap and append them to "icons" array.
00435     CFbsBitmap* bitmap = AknIconUtils::CreateIconL( *iIconProvider,
00436             EMbmAknexpoplistFinflag );
00437     CleanupStack::PushL( bitmap );
00438 
00439     CFbsBitmap* mask = AknIconUtils::CreateIconL( *iIconProvider,
00440             EMbmAknexpoplistFinflag_mask );
00441     CleanupStack::PushL( mask );
00442     icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
00443 
00444     CleanupStack::Pop(); // mask
00445     CleanupStack::Pop(); // bitmap
00446 
00447     CFbsBitmap* bitmap2 = AknIconUtils::CreateIconL( *iIconProvider,
00448             EMbmAknexpoplistJpnflag );
00449     CleanupStack::PushL( bitmap2 );
00450 
00451     CFbsBitmap* mask2 = AknIconUtils::CreateIconL( *iIconProvider,
00452             EMbmAknexpoplistJpnflag_mask );
00453     CleanupStack::PushL( mask2 );
00454     icons->AppendL( CGulIcon::NewL( bitmap2, mask2 ) );
00455 
00456     CleanupStack::Pop(); // mask2
00457     CleanupStack::Pop(); // bitmap2
00458 
00459     list->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
00460     
00461     // Pop the icons's pointer from CleanupStack 
00462     CleanupStack::Pop();
00463 
00464     list->ClearSelection();
00465     CArrayFixFlat<TInt>* array1 =
00466                             new( ELeave ) CArrayFixFlat<TInt>( KIndexArraySize );
00467 
00468     CleanupStack::PushL( array1 );
00469     array1->AppendL( 1 );
00470     array1->AppendL( 2 );
00471     
00472     list->SetSelectionIndexesL( array1 );
00473 
00474     // Pop and Destroy the array1's pointer from CleanupStack
00475     CleanupStack::PopAndDestroy();
00476 
00477     list->ItemDrawer()->SetItemMarkPosition( KInitPos );
00478     TPtrC blank( KInitPosString );
00479     list->ItemDrawer()->SetItemMarkReplacement( blank );
00480 
00481     // Show popup list and then show return value.
00482     TInt popupOk = popupList->ExecuteLD();
00483 
00484     // Pop the popupList's pointer from CleanupStack 
00485     CleanupStack::Pop();
00486 
00487     if ( popupOk )
00488         {
00489         TInt index = list->CurrentItemIndex();
00490         TBuf<KMessageLength> msg;
00491         TBuf<KMessageLength> format;
00492         iCoeEnv->ReadResource( format, R_AKNEXPOPLIST_SELECT_MESSAGE );
00493         msg.Format( format, index + 1 );
00494 
00495         CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog(
00496             CAknNoteDialog::ENoTone, CAknNoteDialog::ENoTimeout );
00497 
00498         dlg->PrepareLC( R_AKNEXPOPLIST_SELECT_MESSAGE_NOTE );
00499         dlg->SetTextPluralityL( EFalse );
00500         dlg->SetTextL( msg );
00501         dlg->RunLD();
00502         }
00503 
00504     // Pop and Destroy the list's pointer from CleanupStack
00505     CleanupStack::PopAndDestroy(); 
00506 
00507     }
00508 
00509 // End of File

© Nokia 2009

Back to top