gssettingsuis/Gs/GSApplication/Src/GSMainContainer.cpp
branchRCL_3
changeset 54 7e0eff37aedb
equal deleted inserted replaced
53:8ee96d21d9bf 54:7e0eff37aedb
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Container for the main view of General Settings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <bldvariant.hrh>
       
    21 
       
    22 #include    "GSUi.h"
       
    23 #include    "gsmainview.h"
       
    24 #include    "GSMainContainer.h"
       
    25 #include    "gsplugininterface.h"
       
    26 #include    "GsLogger.h"
       
    27 #include    <gsapp.rsg>         // Resources for mainview
       
    28 
       
    29 #include    <aknlists.h>
       
    30 #include    <calslbs.h>
       
    31 #include    <eikclbd.h>
       
    32 #include    <AknIconArray.h>    // For loading icons
       
    33 #include    <AknsUtils.h>       // For loading icons
       
    34 #include    <aknViewAppUi.h>
       
    35 #include    <akntitle.h>
       
    36 #include    <barsread.h>
       
    37 #include    <gulicon.h>         // For CGulIcon
       
    38 #include    <csxhelp/cp.hlp.hrh>
       
    39 #include    <gsfwviewuids.h>    // for KUidGS
       
    40 #include    "GsContainerExt.h" //For CGsContainerExt
       
    41 
       
    42 //CONSTANTS
       
    43 
       
    44 // ========================= MEMBER FUNCTIONS ================================
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CGSMainContainer::ConstructL(const TRect& aRect)
       
    49 // Symbian OS two phased constructor
       
    50 //
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void CGSMainContainer::ConstructL(
       
    54     const TRect& aRect,
       
    55     CAknViewAppUi* aAppUi,
       
    56     CArrayPtrFlat<CGSPluginInterface>* aPluginArray )
       
    57     {
       
    58     iAppUi = aAppUi;
       
    59     iPluginArray = aPluginArray;
       
    60 
       
    61     // Initialize the array containing pointers to plugins that are actually
       
    62     // displayed in lbx.
       
    63     iVisiblePlugins = new CArrayPtrFlat<CGSPluginInterface>( 10 );
       
    64 
       
    65     CEikStatusPane* sp = iAppUi->StatusPane();
       
    66     CAknTitlePane* title = static_cast<CAknTitlePane*>
       
    67         ( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    68 
       
    69     // Set view title from resource:
       
    70     TResourceReader rReader;
       
    71     iCoeEnv->CreateResourceReaderLC( rReader, R_GS_MAIN_VIEW_TITLE );
       
    72     title->SetFromResourceL( rReader );
       
    73     CleanupStack::PopAndDestroy(); //rReader
       
    74 
       
    75     CreateWindowL(); // Makes this control a window-owning control
       
    76 
       
    77     // Create listbox:
       
    78     iListBox = new( ELeave ) CAknSingleLargeStyleListBox;
       
    79     iListBox->ConstructL( this );
       
    80     iListBox->SetContainerWindowL( *this );
       
    81     iListBox->SetListBoxObserver( this );
       
    82     iListBox->CreateScrollBarFrameL(ETrue);
       
    83     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
    84         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
    85 
       
    86     // Obtain reference to listbox's item text array:
       
    87     iItemTextArray
       
    88         = STATIC_CAST( CDesCArray*, iListBox->Model()->ItemTextArray() );
       
    89     iExt = CGsContainerExt::NewL();
       
    90 
       
    91     SetRect( aRect );
       
    92     ActivateL();
       
    93     __GSLOGSTRING( "[CGSMainContainer] ConstructL()" );
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CGSMainContainer::~CGSMainContainer()
       
    99 // Destructor
       
   100 //
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 CGSMainContainer::~CGSMainContainer()
       
   104     {
       
   105     if  ( iVisiblePlugins )
       
   106         {
       
   107         iVisiblePlugins->Reset();
       
   108         }
       
   109     delete iVisiblePlugins;
       
   110 
       
   111     if  ( iItemTextArray )
       
   112         {
       
   113         iItemTextArray->Reset();
       
   114         }
       
   115 
       
   116     if ( iListBox )
       
   117         {
       
   118         delete iListBox;
       
   119         }
       
   120     delete iExt;
       
   121     __GSLOGSTRING( "[CGSMainContainer] ~CGSMainContainer" );
       
   122   }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CGSMainContainer::UpdateListbox
       
   126 //
       
   127 // Updates listbox from iPluginArray.
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CGSMainContainer::UpdateListBoxL()
       
   131     {
       
   132     
       
   133     if( iPluginArray->Count() == 0 )
       
   134 		{
       
   135         return;
       
   136 		}
       
   137     
       
   138     __GSLOGSTRING( "[CGSMainContainer::UpdateListBoxL]" );
       
   139     
       
   140     // Empty item array because it will be reoccupied.
       
   141     iItemTextArray->Reset();
       
   142 
       
   143     // Empty the array because it will be updated.
       
   144     iVisiblePlugins->Reset();
       
   145 
       
   146     // Array for icons in the listbox. Owns the icons.
       
   147     CAknIconArray* icons = new (ELeave) CAknIconArray( 10 );
       
   148     CleanupStack::PushL( icons );
       
   149 
       
   150     // Index of the plugin inserted into lbx item array.
       
   151     TInt pluginIndex = 0;
       
   152 
       
   153     // 1) Add each plugin's data to listbox if the plugin is visible.
       
   154     for( TInt i = 0; i < iPluginArray->Count(); i++ )
       
   155         {
       
   156         CGSPluginInterface* plugin = iPluginArray->operator[]( i );
       
   157         if( plugin->Visible() )
       
   158             {
       
   159             AddPluginDataToLbxL( plugin, pluginIndex, iItemTextArray, icons );
       
   160             pluginIndex++;
       
   161             }
       
   162         }
       
   163 
       
   164     // Destroy the old icons because SetIconArray() does not destroy them.
       
   165     CArrayPtr<CGulIcon>* oldIcons
       
   166         = iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   167     if( oldIcons )
       
   168         {
       
   169         oldIcons->ResetAndDestroy();
       
   170         delete oldIcons;
       
   171         }
       
   172 
       
   173     // Transfer ownership of icon array to the lbx.
       
   174     // SetIconArray() does not delete the old icon array
       
   175     iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   176     CleanupStack::Pop( icons );
       
   177 
       
   178     // Draws listbox again
       
   179     iListBox->HandleItemAdditionL();
       
   180     }
       
   181 
       
   182 
       
   183 //Disabling warning caused by err variable used inside macros
       
   184 #pragma diag_suppress 550
       
   185 // -----------------------------------------------------------------------------
       
   186 // CGSMainContainer::AddPluginDataToLbxL()
       
   187 //
       
   188 //
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CGSMainContainer::AddPluginDataToLbxL( CGSPluginInterface* aPlugin,
       
   192                                               TInt aIndex,
       
   193                                               CDesCArray* aItemTextArray,
       
   194                                               CAknIconArray* aIconArray )
       
   195     {
       
   196     // Add the plugin to visible plugins array:
       
   197     iVisiblePlugins->AppendL( aPlugin );
       
   198 
       
   199     // 1.1) Read item descriptor from plugin:
       
   200     TBuf<256> buf;
       
   201     _LIT( KTab, "\t" );
       
   202 
       
   203     TRAPD
       
   204         (
       
   205         captionErr,
       
   206         aPlugin->GetCaptionL( buf );
       
   207         )
       
   208 
       
   209     // If plugin caption fails, set caption to error string.
       
   210     if( captionErr != KErrNone )
       
   211         {
       
   212         _LIT( KGSParentPluginCaptionErrorTxt, "Error" );
       
   213         buf.Append( KGSParentPluginCaptionErrorTxt );
       
   214         }
       
   215        else
       
   216         {
       
   217         __GSLOGSTRING2( "[CGSMainContainer] 0x%X::GetCaptionL Error: %d",
       
   218         aPlugin->Id().iUid, captionErr );
       
   219         }
       
   220 
       
   221     /**
       
   222     * 1.2) Create formatted item string.
       
   223     * list_single_large_pane:
       
   224     * list item string format: "1\tTextLabel\t0\t0"
       
   225     * where 0 is an index to icon array
       
   226     */
       
   227     TBuf<256> item;
       
   228     item.AppendNum( aIndex );
       
   229     item.Append( KTab );
       
   230     item.Append( buf );
       
   231 
       
   232     aItemTextArray->AppendL( item );
       
   233 
       
   234     // 1.3) Add icons if listbox uses them:
       
   235     CGulIcon* icon;
       
   236     TRAPD
       
   237         (
       
   238         iconErr,
       
   239         icon = aPlugin->CreateIconL( KGSIconTypeLbxItem );
       
   240         )
       
   241 
       
   242     __GSLOGSTRING2(
       
   243         "[CGSMainContainer] CreateIconL result for 0x%X: %d",
       
   244         aPlugin->Id().iUid, iconErr );
       
   245     TSize size = icon->Bitmap()->SizeInPixels();
       
   246     CleanupStack::PushL( icon );
       
   247     aIconArray->AppendL( icon );
       
   248     CleanupStack::Pop( icon );
       
   249 
       
   250     }
       
   251 //Enabling warnings
       
   252 #pragma diag_default 550
       
   253     
       
   254     
       
   255 // ---------------------------------------------------------------------------
       
   256 // CGSMainContainer::GetHelpContext(TCoeHelpContext& aContext) const
       
   257 // Gets Help
       
   258 //
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void CGSMainContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   262     {
       
   263     aContext.iMajor = KUidGS;
       
   264     aContext.iContext = KCP_HLP_MAIN_VIEW;
       
   265     }
       
   266 
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CGSMainContainer::SizeChanged
       
   270 // called by framwork when the view size is changed
       
   271 //
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 void CGSMainContainer::SizeChanged()
       
   275     {
       
   276     if ( iListBox )
       
   277         {
       
   278         iListBox->SetRect( Rect() );
       
   279         }
       
   280     }
       
   281 
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CGSMainContainer::CountComponentControls
       
   285 //
       
   286 //
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 TInt CGSMainContainer::CountComponentControls() const
       
   290     {
       
   291     return 1;
       
   292     }
       
   293 
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CGSMainContainer::ComponentControl
       
   297 //
       
   298 //
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 CCoeControl* CGSMainContainer::ComponentControl(TInt /*aIndex*/) const
       
   302     {
       
   303     return iListBox;
       
   304     }
       
   305 
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // CGSMainContainer::TKeyResponse OfferKeyEventL
       
   309 // Called when a key is pressed.
       
   310 //
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 TKeyResponse  CGSMainContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   314                                                TEventCode aType)
       
   315     {
       
   316     switch ( aKeyEvent.iCode )
       
   317         {
       
   318         case EKeyLeftArrow:
       
   319         case EKeyRightArrow:
       
   320             // Listbox takes all event even if it doesn't use them
       
   321             return EKeyWasNotConsumed;
       
   322         default:
       
   323             break;
       
   324         }
       
   325     // now it's iListBox's job to process the key event
       
   326     return iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   327     }
       
   328 
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // CGSMainContainer::HandleListBoxEventL
       
   332 //
       
   333 //
       
   334 // ---------------------------------------------------------------------------
       
   335 void CGSMainContainer::HandleListBoxEventL(
       
   336     CEikListBox* aListBox,
       
   337     TListBoxEvent aEventType )
       
   338     {
       
   339     __GSLOGSTRING1(
       
   340         "[CGSMainContainer] HandleListBoxEventL aEventType:%d",
       
   341         aEventType);
       
   342     switch ( aEventType )
       
   343         {
       
   344         case EEventEnterKeyPressed:
       
   345         case EEventItemSingleClicked:
       
   346             {
       
   347             if (aListBox->CurrentItemIndex() < 0)
       
   348                 {
       
   349                 // Negative listbox value -> no item selected? 
       
   350                 break;
       
   351                 }
       
   352             if ( iExt->iDblClickPreventer->IsActive() )
       
   353                 {
       
   354                 break;
       
   355                 }
       
   356             iExt->iDblClickPreventer->Start();
       
   357             CGSPluginInterface* selectedPlugin = iVisiblePlugins->operator[](
       
   358                     aListBox->CurrentItemIndex());
       
   359 
       
   360             // Different command is used depending on the plugin type.
       
   361             switch (selectedPlugin->ItemType())
       
   362                 {
       
   363                 // In these cases the plugin is a view:
       
   364                 case EGSItemTypeSingleLarge:
       
   365                 case EGSItemTypeSetting:
       
   366                 case EGSItemTypeSettingIcon:
       
   367                     iAppUi->ActivateLocalViewL(selectedPlugin->Id());
       
   368                     break;
       
   369                     // In these cases the plugin is a dialog:
       
   370                 case EGSItemTypeSettingDialog:
       
   371                 case EGSItemTypeSingleLargeDialog:
       
   372                     selectedPlugin->HandleSelection(
       
   373                             EGSSelectionBySelectionKey);
       
   374                     UpdateListBoxL(); // Refrest the listbox if value changed.
       
   375                     break;
       
   376                 }
       
   377             }
       
   378             break;
       
   379         default:
       
   380            break;
       
   381         }
       
   382     }
       
   383 
       
   384 
       
   385 // ---------------------------------------------------------------------------
       
   386 // CGSMainContainer::ListBox()
       
   387 //
       
   388 //
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 CAknSingleLargeStyleListBox* CGSMainContainer::ListBox()
       
   392     {
       
   393     return iListBox;
       
   394     }
       
   395 
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // CGSMainContainer::HandleResourceChange()
       
   399 //
       
   400 //
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 void CGSMainContainer::HandleResourceChange( TInt aType )
       
   404     {
       
   405     //Handle layout orientation or skin change
       
   406     CCoeControl::HandleResourceChange( aType );
       
   407     if ( aType == KAknsMessageSkinChange )
       
   408         {
       
   409         TRAP_IGNORE( UpdateListBoxL() );
       
   410         }
       
   411     else if ( aType == KEikDynamicLayoutVariantSwitch  )
       
   412 	    {
       
   413         TRect mainPaneRect;
       
   414         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
   415                                            mainPaneRect);
       
   416         SetRect( mainPaneRect );
       
   417 	    }
       
   418     }
       
   419     
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CGSMainContainer::SelectedPlugin()
       
   423 //
       
   424 //
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 CGSPluginInterface* CGSMainContainer::SelectedPlugin()
       
   428     {
       
   429     CGSPluginInterface* plugin = NULL;
       
   430     const TInt index = iListBox->CurrentItemIndex();
       
   431     if ( index >= 0 && index <= iVisiblePlugins->Count() )
       
   432         {
       
   433         plugin = iVisiblePlugins->operator[]( index );
       
   434     __GSLOGSTRING2( "[CGSMainContainer] SelectedPlugin 0x%X in index %d",
       
   435         plugin->Id().iUid, index );
       
   436         }
       
   437     return plugin;
       
   438     }
       
   439 
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // CGSMainContainer::SetSelectedItem()
       
   443 //
       
   444 //
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 void CGSMainContainer::SetSelectedItem( TUid aSelectedItemUid )
       
   448     {
       
   449     __GSLOGSTRING1( "[CGSMainContainer] SetSelectedItem(0x%X)",
       
   450         aSelectedItemUid.iUid );
       
   451 
       
   452     TInt selectedItemIndex  = 0;
       
   453     for( TInt i = 0; i < iVisiblePlugins->Count(); i++ )
       
   454         {
       
   455         CGSPluginInterface* plugin = iVisiblePlugins->operator[]( i );
       
   456 
       
   457         __GSLOGSTRING2( "[CGSMainContainer] Checking [%d] 0x%X)",
       
   458             i, plugin->Id().iUid );
       
   459 
       
   460         // If plugin is found, select it:
       
   461         if( plugin->Id() == aSelectedItemUid )
       
   462             {
       
   463             __GSLOGSTRING2( "[CGSMainContainer] Match 0x%X in index %d",
       
   464                 plugin->Id().iUid, i );
       
   465             selectedItemIndex = i;
       
   466             break;
       
   467             }
       
   468         }
       
   469     iListBox->SetCurrentItemIndexAndDraw( selectedItemIndex );
       
   470     }
       
   471 
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // CGSMainContainer::FocusChanged
       
   475 //
       
   476 // Set focus on the selected listbox. For animated skins feature.
       
   477 // ---------------------------------------------------------------------------
       
   478 void CGSMainContainer::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   479     {
       
   480     if( iListBox )
       
   481         {
       
   482         iListBox->SetFocus( IsFocused() );
       
   483         }
       
   484     }
       
   485 
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CGSMainContainer::SetListBoxEmptyTextL()
       
   489 //
       
   490 //Set the empty text of list box.
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 void CGSMainContainer::SetListBoxEmptyTextL(const TDes& aEmpty )
       
   494     {
       
   495     if( iListBox )
       
   496         {
       
   497         iListBox->View()->SetListEmptyTextL( aEmpty );
       
   498         }
       
   499     }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CGSMainContainer::StoreListBoxPositionL
       
   503 //
       
   504 //Store the exact position of listbox.
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 void CGSMainContainer::StoreListBoxPositionL( CGSMainView::TListBoxPosition& aPosition )
       
   508 	{
       
   509     aPosition.iCurrentItemIndex = iListBox->CurrentItemIndex();
       
   510     aPosition.iItemOffsetInPixels = iListBox->View()->ItemOffsetInPixels();
       
   511     aPosition.iTopItemIndex = iListBox->View()->TopItemIndex();
       
   512 	}
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CGSMainContainer::RestoreListBoxPositionL
       
   516 //
       
   517 //Restore the exact position of listbox.
       
   518 // -----------------------------------------------------------------------------
       
   519 //
       
   520 void CGSMainContainer::RestoreListBoxPositionL( const CGSMainView::TListBoxPosition& aPosition, TBool aScreenModeChanged )
       
   521 	{
       
   522     if ( aPosition.iCurrentItemIndex >= 0 )
       
   523         {
       
   524         iListBox->SetCurrentItemIndex( aPosition.iCurrentItemIndex );
       
   525         }
       
   526     
       
   527     if ( aScreenModeChanged )
       
   528         {
       
   529         iListBox->View()->VerticalMoveToItemL( aPosition.iCurrentItemIndex,
       
   530                 CListBoxView::ESingleSelection );
       
   531         }
       
   532     else
       
   533         {
       
   534         iListBox->View()->SetItemOffsetInPixels( aPosition.iItemOffsetInPixels );
       
   535         iListBox->View()->SetTopItemIndex( aPosition.iTopItemIndex );
       
   536         }
       
   537     }
       
   538 // End of File