gssettingsuis/Gs/GSFramework/src/GSParentContainer.cpp
changeset 0 8c5d936e5675
child 8 f62c3a3d66b8
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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 GSParentPlugin.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    <gsparentcontainer.h>
       
    20 #include    <gsparentplugin.h>
       
    21 #include    <gsplugininterface.h>
       
    22 #include    "GsLogger.h"
       
    23 #include    <GSParentPluginRsc.rsg>
       
    24 #include    <gsfwviewuids.h>
       
    25 #include    "GSBaseDocument.h"
       
    26 #include    <mgswatchdog.h>
       
    27 
       
    28 #include    <AknIconArray.h>  //for loading icons
       
    29 #include    <aknlists.h>
       
    30 #include    <AknsUtils.h>     //for loading icons
       
    31 #include    <akntitle.h>
       
    32 #include    <akntitle.h>
       
    33 #include    <aknViewAppUi.h>
       
    34 #include    <barsread.h> // For TResourceReader
       
    35 #include    <bldvariant.hrh>
       
    36 #include    <calslbs.h>
       
    37 #include    <eikclbd.h>
       
    38 
       
    39 //CONSTANTS
       
    40 const TInt KGSPluginArrayInitSize = 10;
       
    41 const TInt KGSCaptionBufSize = 256;
       
    42 
       
    43 // ========================= MEMBER FUNCTIONS ================================
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CGSParentContainer::ConstructL(const TRect& aRect)
       
    47 // Symbian OS two phased constructor
       
    48 //
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CGSParentContainer::ConstructL(
       
    52     const TRect& aRect,
       
    53     CAknViewAppUi* aAppUi,
       
    54     CArrayPtrFlat<CGSPluginInterface>* aPluginArray,
       
    55     TInt aTitleRscId,
       
    56     CGSParentPlugin* aParentPlugin,
       
    57     TGSListboxTypes aListBoxType )
       
    58     {
       
    59     iAppUi = aAppUi;
       
    60     iPluginArray = aPluginArray;
       
    61     iListBoxType = aListBoxType;
       
    62     iParentPlugin = aParentPlugin;
       
    63 
       
    64     CGSBaseDocument* doc = static_cast< CGSBaseDocument* >( iAppUi->Document() );
       
    65     iGSWatchDog = doc->WatchDog();
       
    66 
       
    67     // Initialize the array containing pointers to plugins that are actually
       
    68     // displayed in lbx.
       
    69     iVisiblePlugins = new (ELeave) CArrayPtrFlat<CGSPluginInterface>( KGSPluginArrayInitSize );
       
    70 
       
    71     __GSLOGSTRING( "[CGSParentContainer] ConstructL" );
       
    72 
       
    73     // Set view title from resource:
       
    74     CEikStatusPane* sp = iAppUi->StatusPane();
       
    75     CAknTitlePane* title = static_cast<CAknTitlePane*>
       
    76         ( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    77     TResourceReader rReader;
       
    78     iCoeEnv->CreateResourceReaderLC( rReader, aTitleRscId );
       
    79     title->SetFromResourceL( rReader );
       
    80     CleanupStack::PopAndDestroy(); // rReader
       
    81 
       
    82     CreateWindowL(); //makes this control a window-owning control
       
    83 
       
    84     CreateListBoxL( iListBoxType );
       
    85 
       
    86     SetRect( aRect );
       
    87     ActivateL();
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CGSParentContainer::~CGSParentContainer()
       
    93 // Destructor
       
    94 //
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CGSParentContainer::~CGSParentContainer()
       
    98     {
       
    99     __GSLOGSTRING( "[CGSParentContainer] ~CGSParentContainer()|->" );
       
   100     if  ( iVisiblePlugins )
       
   101         {
       
   102         iVisiblePlugins->Reset();
       
   103         }
       
   104     delete iVisiblePlugins;
       
   105     if ( iListBox )
       
   106         {
       
   107         delete iListBox;
       
   108         }
       
   109     __GSLOGSTRING( "[CGSParentContainer] ~CGSParentContainer()-|" );
       
   110   }
       
   111 
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CGSParentContainer::UpdateListboxL
       
   115 //
       
   116 // Updates listbox from iPluginArray. Uses switch statement to handle different
       
   117 // listbox types from TGSListboxTypes because the list item format
       
   118 // and icon numbers depend on the listbox type.
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CGSParentContainer::UpdateListBoxL()
       
   122     {
       
   123     __GSLOGSTRING( "[CGSParentContainer::UpdateListBoxL]" );
       
   124     iItemTextArray->Reset();
       
   125 
       
   126     // Empty the array because it will be updated.
       
   127     iVisiblePlugins->Reset();
       
   128 
       
   129     // Array for icons in the listbox. Array owns the icons.
       
   130     CAknIconArray* icons = NULL;
       
   131 
       
   132     // Create icon array if required by the listbox type:
       
   133     switch( iListBoxType )
       
   134         {
       
   135         case EGSListBoxTypeSingleLarge:
       
   136         case EGSListBoxTypeDouble2Large:
       
   137         case EGSListBoxTypeDoubleLarge:
       
   138             icons = new (ELeave) CAknIconArray( KGSPluginArrayInitSize );
       
   139             CleanupStack::PushL( icons );
       
   140             break;
       
   141 
       
   142         default:
       
   143             break;
       
   144         }
       
   145 
       
   146     // Counter for created icons. This is used to maintain corrext indexing for
       
   147     // each plugin's icons in case a plugin has multiple icons and icon indexes
       
   148     // can not be mapped directly to plugin index.
       
   149     TInt iconCounter = 0;
       
   150 
       
   151     // 1) Add each plugin's data to listbox if the plugin is visible.
       
   152     for( TInt i = 0; i < iPluginArray->Count(); i++ )
       
   153         {
       
   154         CGSPluginInterface* plugin = iPluginArray->operator[]( i );
       
   155 
       
   156         // Adding plugin data to lbx has a lot of CGSPluginInterface API calls.
       
   157         // -> A good place to use quarantine to catch panicking plugins in
       
   158         // any of these calls.
       
   159         iGSWatchDog->QuarantineL( plugin->Id() );
       
   160         if( plugin->Visible() )
       
   161             {
       
   162             AddPluginDataToLbxL( plugin,
       
   163                                  iItemTextArray,
       
   164                                  icons,
       
   165                                  iconCounter );
       
   166             }
       
   167         iGSWatchDog->RemoveFromQuarantineL( plugin->Id() );
       
   168         }
       
   169 
       
   170     // 2) Replace old icon array if needed.
       
   171     switch( iListBoxType )
       
   172         {
       
   173         case EGSListBoxTypeSingleLarge:
       
   174             {
       
   175             // Temporary variable needed to use casted lbx.
       
   176             CAknSingleLargeStyleListBox* lbx =
       
   177                 STATIC_CAST( CAknSingleLargeStyleListBox*, iListBox );
       
   178             // Destroy the old icons because SetIconArray() does not destroy them.
       
   179             CArrayPtr<CGulIcon>* oldIcons
       
   180                 = lbx->ItemDrawer()->ColumnData()->IconArray();
       
   181             if( oldIcons )
       
   182                 {
       
   183                 __GSLOGSTRING( "[CGSParentContainer] Destroying old icons." );
       
   184                 oldIcons->ResetAndDestroy();
       
   185                 delete oldIcons;
       
   186                 }
       
   187             // Transfer ownership of icon array to the lbx.
       
   188             // SetIconArray() does not delete the old icon array
       
   189             lbx->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   190             CleanupStack::Pop( icons );
       
   191             }
       
   192             break;
       
   193         case EGSListBoxTypeDouble2Large:
       
   194         case EGSListBoxTypeDoubleLarge:
       
   195             {
       
   196             // Temporary variable needed to use casted lbx.
       
   197             CEikFormattedCellListBox* lbx =
       
   198                 STATIC_CAST( CEikFormattedCellListBox*, iListBox );
       
   199             // Destroy the old icons because SetIconArray() does not destroy them.
       
   200             CArrayPtr<CGulIcon>* oldIcons
       
   201                 = lbx->ItemDrawer()->ColumnData()->IconArray();
       
   202             if( oldIcons )
       
   203                 {
       
   204                 __GSLOGSTRING( "[CGSParentContainer] Destroying old icons." );
       
   205                 oldIcons->ResetAndDestroy();
       
   206                 delete oldIcons;
       
   207                 }
       
   208             // Transfer ownership of icon array to the lbx.
       
   209             // SetIconArray() does not delete the old icon array
       
   210             lbx->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   211             CleanupStack::Pop( icons );
       
   212             }
       
   213             break;
       
   214 
       
   215         case EGSListBoxTypeSettings:
       
   216             break;
       
   217 
       
   218         default:
       
   219             break;
       
   220         }
       
   221 
       
   222 #ifdef _GS_PARENTPLUGIN_LBX_FORMAT_TRACES
       
   223 #pragma message("_GS_PARENTPLUGIN_LBX_FORMAT_TRACES activated")
       
   224         __GSLOGSTRING( "[CGSParentContainer::UpdateListBoxL] iItemTextArray:" );
       
   225         for( TInt i = 0; i < iItemTextArray->Count(); i++ )
       
   226             {
       
   227             __GSLOGSTRING1( "%S", &iItemTextArray->operator[]( i ) );
       
   228             }
       
   229 #endif // _GS_PARENTPLUGIN_LBX_FORMAT_TRACES
       
   230 
       
   231     // 3) Draw listbox again
       
   232     iListBox->HandleItemAdditionL();
       
   233     __GSLOGSTRING( "[CGSParentContainer] UpdateListBoxL()-|" );
       
   234     }
       
   235 
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CGSParentContainer::AddPluginDataToLbxL()
       
   239 //
       
   240 //
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CGSParentContainer::AddPluginDataToLbxL( CGSPluginInterface* aPlugin,
       
   244                                               CDesCArray* aItemTextArray,
       
   245                                               CAknIconArray* aIconArray,
       
   246                                               TInt& aIconCounter )
       
   247     {
       
   248     // Used to disable icon
       
   249     const TInt KIconNotSupported = -1;
       
   250 
       
   251     // Index of icon used in AB-column
       
   252     TInt iconIndexAB = KIconNotSupported;
       
   253 
       
   254     // Index of icon used in D-column
       
   255     TInt iconIndexD = KIconNotSupported;
       
   256 
       
   257 #pragma message("TODO: The HBufC buffer sizes could be optimized if possible:")
       
   258 
       
   259     // First line of lbx item text (plugin caption)
       
   260     HBufC* firstLabelBuf = HBufC::NewLC( KGSCaptionBufSize );
       
   261     TPtr firstLabel = firstLabelBuf->Des();
       
   262 
       
   263     // Second line of lbx item text (optional)
       
   264     HBufC* secondLabelBuf = HBufC::NewLC( KGSCaptionBufSize );
       
   265     TPtr secondLabel = secondLabelBuf->Des();
       
   266 
       
   267     // The complete formatted lbx item string which is added to lbx
       
   268     HBufC* lbxItemStringBuf = HBufC::NewLC( KGSCaptionBufSize * 2 );
       
   269     TPtr lbxItemString = lbxItemStringBuf->Des();
       
   270 
       
   271     // Separates lbx item elements
       
   272     _LIT( KTab, "\t" );
       
   273 
       
   274     // Normal icon in AB-Column
       
   275     CGulIcon* iconAB = NULL;
       
   276 
       
   277     // Small icon used in D-column (optional)
       
   278     CGulIcon* iconD = NULL;
       
   279 
       
   280     // Add the plugin to visible plugins array:
       
   281     iVisiblePlugins->AppendL( aPlugin );
       
   282 
       
   283     // 1) Read item descriptor from plugin:
       
   284     TRAPD( captionErr,
       
   285            aPlugin->GetCaptionL( firstLabel );
       
   286          )
       
   287 
       
   288     // If plugin caption fails, set caption to error string.
       
   289     if( captionErr != KErrNone )
       
   290         {
       
   291         _LIT( KGSParentPluginCaptionErrorTxt, "Error" );
       
   292         firstLabel.Append( KGSParentPluginCaptionErrorTxt );
       
   293         }
       
   294        else
       
   295         {
       
   296         __GSLOGSTRING2( "[CGSParentContainer] 0x%X::GetCaptionL Error: %d",
       
   297         aPlugin->Id().iUid, captionErr );
       
   298         }
       
   299 
       
   300     // 2) Add icons if listbox uses them:
       
   301     //    - AB-column icon
       
   302     //    - D-column icon
       
   303     switch( iListBoxType )
       
   304         {
       
   305         case EGSListBoxTypeSingleLarge:
       
   306         case EGSListBoxTypeDouble2Large:
       
   307         case EGSListBoxTypeDoubleLarge:
       
   308             {
       
   309             // This might fail because plugin implementors might do funny stuff.
       
   310             // GS Must still behave well...
       
   311             TRAPD( iconErr,
       
   312                    iconAB = aPlugin->CreateIconL( KGSIconTypeLbxItem );
       
   313                  )
       
   314             if( iconErr != KErrNone )
       
   315                 {
       
   316                 // Use default icon because plugin implementor's CreateIconL
       
   317                 // failed. If this fails, everything is lost anyway so might as
       
   318                 // well leave (abort GS).
       
   319                 iconAB = aPlugin->CGSPluginInterface::CreateIconL( KGSIconTypeLbxItem );
       
   320                 __GSLOGSTRING2( "[CGSParentContainer] CreateIconL for 0x%X failed:%d",
       
   321                                 aPlugin->Id().iUid,
       
   322                                 iconErr );
       
   323                 }
       
   324             if( iconAB ) // Append only if not NULL (not supported)
       
   325                 {
       
   326                 CleanupStack::PushL( iconAB );
       
   327                 aIconArray->AppendL( iconAB );
       
   328                 CleanupStack::Pop( iconAB );
       
   329                 iconIndexAB = aIconCounter;
       
   330                 aIconCounter++;
       
   331                 }
       
   332 
       
   333             TRAPD( iconDColErr,
       
   334                    iconD = aPlugin->CreateIconL( KGSIconTypeDColumn );
       
   335                  )
       
   336             if( iconDColErr != KErrNone )
       
   337                 {
       
   338                 iconD = aPlugin->CGSPluginInterface::CreateIconL( KGSIconTypeDColumn );
       
   339                 __GSLOGSTRING2( "[CGSParentContainer] CreateIconL for 0x%X failed:%d",
       
   340                                 aPlugin->Id().iUid,
       
   341                                 iconErr );
       
   342                 }
       
   343             if( iconD ) // Append only if not NULL (not supported)
       
   344                 {
       
   345                 CleanupStack::PushL( iconD );
       
   346                 aIconArray->AppendL( iconD );
       
   347                 CleanupStack::Pop( iconD );
       
   348                 iconIndexD = aIconCounter;
       
   349                 aIconCounter++;
       
   350                 }
       
   351             break;
       
   352             }
       
   353         case EGSListBoxTypeSettings:
       
   354             break;
       
   355 
       
   356         default:
       
   357             break;
       
   358         }
       
   359 
       
   360     /**
       
   361     * 3) Create formatted item string. Lbx item's format string depends
       
   362     *    on lbx type.
       
   363     */
       
   364     switch( iListBoxType )
       
   365         {
       
   366         /**
       
   367         * list_single_large_pane:
       
   368         * list item string format: "1\tTextLabel\t0\t0"
       
   369         * where 0 is an index to icon array
       
   370         */
       
   371         case EGSListBoxTypeSingleLarge:
       
   372             {
       
   373             if( iconIndexAB != KIconNotSupported ) lbxItemString.AppendNum( iconIndexAB ); // AB-Column icon
       
   374             lbxItemString.Append( KTab );
       
   375             lbxItemString.Append( firstLabel );
       
   376             break;
       
   377             }
       
   378         /**
       
   379         * list_setting_pane and list_big_single_setting_pane:
       
   380         * list item string format: "\tFirstLabel\t\tValueText"
       
   381         * list item string format: "\tFirstLabel\t0\t"
       
   382         * list item string format: "\tFirstLabel\t\tValueText\t*"
       
   383         * list item string format: "\tFirstLabel\t\t\t\tSecondLabel"
       
   384         * where 0 is an index to icon array
       
   385         */
       
   386         case EGSListBoxTypeSettings:
       
   387             {
       
   388             aPlugin->GetValue( EGSPluginKeySettingsItemValueString, secondLabel );
       
   389 
       
   390             lbxItemString.Append( KTab );
       
   391             lbxItemString.Append( firstLabel );
       
   392             lbxItemString.Append( KTab );
       
   393             lbxItemString.Append( KTab );
       
   394             lbxItemString.Append( secondLabel );
       
   395             break;
       
   396             }
       
   397         /**
       
   398         * list_double2_large_graphic_pane:
       
   399         * list item string format: "1\tFirstLabel\tSecondLabel\t0"
       
   400         * where 0 is an index of small (13x13) icon in icon array
       
   401         *   and 1 is an index of a thumbnail image
       
   402         */
       
   403         case EGSListBoxTypeDouble2Large:
       
   404         case EGSListBoxTypeDoubleLarge:
       
   405             {
       
   406             aPlugin->GetValue( EGSPluginKeySettingsItemValueString, secondLabel );
       
   407 
       
   408             if( iconIndexAB != KIconNotSupported ) lbxItemString.AppendNum( iconIndexAB ); // AB-Column icon
       
   409             lbxItemString.Append( KTab );
       
   410             lbxItemString.Append( firstLabel ); // FirstLabel
       
   411             lbxItemString.Append( KTab );
       
   412             lbxItemString.Append( secondLabel ); // SecondLabel
       
   413             lbxItemString.Append( KTab );
       
   414             if( iconIndexD != KIconNotSupported ) lbxItemString.AppendNum( iconIndexD ); // D-Column Icon
       
   415             break;
       
   416             }
       
   417         }
       
   418     aItemTextArray->AppendL( lbxItemString );
       
   419 
       
   420     CleanupStack::PopAndDestroy( lbxItemStringBuf );
       
   421     CleanupStack::PopAndDestroy( secondLabelBuf );
       
   422     CleanupStack::PopAndDestroy( firstLabelBuf );
       
   423     }
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CGSParentContainer::ListBox()
       
   428 //
       
   429 //
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 CEikListBox* CGSParentContainer::ListBox()
       
   433     {
       
   434     return iListBox;
       
   435     }
       
   436 
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // CGSParentContainer::SizeChanged
       
   440 // called by framework when the view size is changed
       
   441 //
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 void CGSParentContainer::SizeChanged()
       
   445     {
       
   446     if ( iListBox )
       
   447         {
       
   448         iListBox->SetRect( Rect() );
       
   449         }
       
   450     }
       
   451 
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CGSParentContainer::CountComponentControls
       
   455 //
       
   456 //
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 TInt CGSParentContainer::CountComponentControls() const
       
   460     {
       
   461     return 1;
       
   462     }
       
   463 
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CGSParentContainer::ComponentControl
       
   467 //
       
   468 //
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 CCoeControl* CGSParentContainer::ComponentControl(TInt /*aIndex*/) const
       
   472     {
       
   473     return iListBox;
       
   474     }
       
   475 
       
   476 
       
   477 // ---------------------------------------------------------------------------
       
   478 // CGSParentContainer::TKeyResponse OfferKeyEventL
       
   479 // Called when a key is pressed.
       
   480 //
       
   481 // ---------------------------------------------------------------------------
       
   482 //
       
   483 TKeyResponse  CGSParentContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   484                                                   TEventCode aType )
       
   485     {
       
   486     switch ( aKeyEvent.iCode )
       
   487         {
       
   488         case EKeyUpArrow:
       
   489         case EKeyDownArrow:
       
   490             {
       
   491             TKeyResponse listboxResp =
       
   492                 iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   493             if ( iParentPlugin )
       
   494                 {
       
   495                 iParentPlugin->CheckMiddleSoftkeyLabelL();
       
   496                 }
       
   497             return listboxResp;
       
   498             }
       
   499         case EKeyLeftArrow:
       
   500         case EKeyRightArrow:
       
   501             // Listbox takes all events even if it doesn't use them
       
   502             return EKeyWasNotConsumed;
       
   503         default:
       
   504             break;
       
   505         }
       
   506     // now it's iListBox's job to process the key event
       
   507     return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   508     }
       
   509 
       
   510 
       
   511 // ---------------------------------------------------------------------------
       
   512 // CGSParentContainer::HandleListBoxEventL
       
   513 //
       
   514 //
       
   515 // ---------------------------------------------------------------------------
       
   516 void CGSParentContainer::HandleListBoxEventL( CEikListBox* aListBox,
       
   517                                               TListBoxEvent aEventType )
       
   518     {
       
   519     __GSLOGSTRING1(
       
   520         "[CGSParentContainer] HandleListBoxEventL aEventType:%d",
       
   521         aEventType);
       
   522     switch (aEventType)
       
   523         {
       
   524         case EEventEnterKeyPressed:
       
   525         case EEventItemSingleClicked:
       
   526             {
       
   527             __GSLOGSTRING1(
       
   528                 "[CGSParentContainer] Activating view plugin in index[%d]",
       
   529                 aListBox->CurrentItemIndex() );
       
   530             
       
   531             if( aListBox->CurrentItemIndex() < 0 )
       
   532                 {
       
   533                 // Negative listbox value -> no item selected? 
       
   534                 break;
       
   535                 }
       
   536             
       
   537             CGSPluginInterface* selectedPlugin = iVisiblePlugins->operator[](
       
   538                 aListBox->CurrentItemIndex() );
       
   539 
       
   540             // Different command is used depending on the plugin type.
       
   541             switch( selectedPlugin->ItemType() )
       
   542                 {
       
   543                 // In these cases the plugin is a view:
       
   544                 case EGSItemTypeSingleLarge:
       
   545                 case EGSItemTypeSetting:
       
   546                 case EGSItemTypeSettingIcon:
       
   547                     iAppUi->ActivateLocalViewL( selectedPlugin->Id() );
       
   548                     break;
       
   549                 // In these cases the plugin is a dialog:
       
   550                 case EGSItemTypeSettingDialog:
       
   551                 case EGSItemTypeSingleLargeDialog:
       
   552                     selectedPlugin->HandleSelection(
       
   553                         EGSSelectionBySelectionKey );
       
   554                     UpdateListBoxL(); // Refrest the listbox if value changed.
       
   555                     break;
       
   556                 }
       
   557             }
       
   558             break;
       
   559 
       
   560         default:
       
   561            break;
       
   562         }
       
   563     }
       
   564 
       
   565 
       
   566 // ---------------------------------------------------------------------------
       
   567 // CGSParentContainer::HandleResourceChange()
       
   568 //
       
   569 //
       
   570 // ---------------------------------------------------------------------------
       
   571 //
       
   572 void CGSParentContainer::HandleResourceChange( TInt aType )
       
   573     {
       
   574     CCoeControl::HandleResourceChange( aType );
       
   575     //Handle layout orientation or skin change
       
   576     if ( aType == KAknsMessageSkinChange ||
       
   577          aType == KEikDynamicLayoutVariantSwitch )
       
   578         {
       
   579         TRect mainPaneRect;
       
   580         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
   581                                            mainPaneRect);
       
   582         SetRect( mainPaneRect );
       
   583         if ( aType == KAknsMessageSkinChange )
       
   584             {
       
   585             TRAP_IGNORE( UpdateListBoxL() );
       
   586             }
       
   587         }
       
   588     }
       
   589 
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 // CGSParentContainer::CreateListBoxL()
       
   593 //
       
   594 //
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 void CGSParentContainer::CreateListBoxL(
       
   598     TGSListboxTypes aListBoxType )
       
   599     {
       
   600     switch( aListBoxType )
       
   601         {
       
   602         case EGSListBoxTypeSingleLarge:
       
   603             {
       
   604             CAknSingleLargeStyleListBox* lbx =
       
   605                 new( ELeave ) CAknSingleLargeStyleListBox;
       
   606             iListBox = lbx;
       
   607             lbx->ConstructL( this );
       
   608             lbx->SetContainerWindowL( *this );
       
   609             lbx->SetListBoxObserver( this );
       
   610             lbx->CreateScrollBarFrameL( ETrue );
       
   611             lbx->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   612                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   613             // Obtain reference to listbox model's item text array:
       
   614             iItemTextArray = STATIC_CAST( CDesCArray*,
       
   615                 lbx->Model()->ItemTextArray() );
       
   616             }
       
   617             break;
       
   618 
       
   619         case EGSListBoxTypeSettings:
       
   620             {
       
   621             CAknSettingStyleListBox* lbx = 
       
   622                 new( ELeave ) CAknSettingStyleListBox;
       
   623             iListBox = lbx;
       
   624             lbx->ConstructL( this, EAknListBoxSelectionList );
       
   625             lbx->SetContainerWindowL( *this );
       
   626             lbx->SetListBoxObserver( this );
       
   627             lbx->CreateScrollBarFrameL( ETrue );
       
   628             lbx->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   629                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   630             // Obtain reference to listbox model's item text array:
       
   631             iItemTextArray = STATIC_CAST( CDesCArray*,
       
   632                 lbx->Model()->ItemTextArray() );
       
   633             }
       
   634             break;
       
   635             
       
   636         case EGSListBoxTypeDouble2Large:
       
   637             {
       
   638             TInt flags = 0;
       
   639             CAknDouble2LargeStyleListBox* lbx = 
       
   640                 new( ELeave ) CAknDouble2LargeStyleListBox;
       
   641             iListBox = lbx;
       
   642             lbx->ConstructL( this, flags );
       
   643             lbx->SetContainerWindowL( *this );
       
   644             lbx->SetListBoxObserver( this );
       
   645             lbx->CreateScrollBarFrameL( ETrue );
       
   646             lbx->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   647                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   648             // Obtain reference to listbox model's item text array:
       
   649             iItemTextArray = STATIC_CAST( CDesCArray*,
       
   650                 lbx->Model()->ItemTextArray() );
       
   651             }
       
   652             break;
       
   653 
       
   654         case EGSListBoxTypeDoubleLarge:
       
   655             {
       
   656             TInt flags = 0;
       
   657             CAknDoubleLargeStyleListBox* lbx = 
       
   658                 new( ELeave ) CAknDoubleLargeStyleListBox;
       
   659             iListBox = lbx;
       
   660             lbx->ConstructL( this, flags );
       
   661             lbx->SetContainerWindowL( *this );
       
   662             lbx->SetListBoxObserver( this );
       
   663             lbx->CreateScrollBarFrameL( ETrue );
       
   664             lbx->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   665                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   666             // Obtain reference to listbox model's item text array:
       
   667             iItemTextArray = STATIC_CAST( CDesCArray*,
       
   668                 lbx->Model()->ItemTextArray() );
       
   669             }
       
   670             break;
       
   671 
       
   672         default:
       
   673             break;
       
   674         }
       
   675     }
       
   676 
       
   677 
       
   678 // -----------------------------------------------------------------------------
       
   679 // CGSParentContainer::SelectedPlugin()
       
   680 //
       
   681 //
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 CGSPluginInterface* CGSParentContainer::SelectedPlugin()
       
   685     {
       
   686     CGSPluginInterface* plugin = NULL;
       
   687     const TInt index = iListBox->CurrentItemIndex();
       
   688     if ( index >= 0 && index < iVisiblePlugins->Count() )
       
   689         {
       
   690         plugin = iVisiblePlugins->operator[]( index );
       
   691         __GSLOGSTRING2( "[CGSParentContainer] SelectedPlugin 0x%X in index %d",
       
   692             plugin->Id().iUid, index );
       
   693         }
       
   694     return plugin;
       
   695     }
       
   696 
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // CGSParentContainer::SetSelectedItem()
       
   700 //
       
   701 //
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 void CGSParentContainer::SetSelectedItem( TUid aSelectedItemUid )
       
   705     {
       
   706     __GSLOGSTRING1( "[CGSParentContainer] SetSelectedItem(0x%X)",
       
   707         aSelectedItemUid.iUid );
       
   708 
       
   709     if( aSelectedItemUid != KGSNoneSelected )
       
   710         {
       
   711         TInt selectedItemIndex  = 0;
       
   712         for( TInt i = 0; i < iVisiblePlugins->Count(); i++ )
       
   713             {
       
   714             CGSPluginInterface* plugin = iVisiblePlugins->operator[]( i );
       
   715             __GSLOGSTRING2( "[CGSParentContainer] Checking [%d] 0x%X)",
       
   716                 i, plugin->Id().iUid );
       
   717             // If plugin is found, select it:
       
   718             if( plugin->Id() == aSelectedItemUid )
       
   719                 {
       
   720                 __GSLOGSTRING2( "[CGSParentContainer] Match 0x%X in index %d",
       
   721                     plugin->Id().iUid, i );
       
   722                 selectedItemIndex = i;
       
   723                 break;
       
   724                 }
       
   725             }
       
   726         iListBox->SetCurrentItemIndexAndDraw( selectedItemIndex );
       
   727         }
       
   728     }
       
   729 
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // CGSParentContainer::GetHelpContext()
       
   733 //
       
   734 //
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 void CGSParentContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   738     {
       
   739     // This is forwarded to the CGSParentPlugin type class that actually knows
       
   740     // the help context but does not have its own CCoeControl class.
       
   741     iParentPlugin->GetHelpContext( aContext );
       
   742     }
       
   743 
       
   744 
       
   745 // ---------------------------------------------------------------------------
       
   746 // CGSParentContainer::FocusChanged
       
   747 //
       
   748 // Set focus on the selected listbox. For animated skins feature.
       
   749 // ---------------------------------------------------------------------------
       
   750 EXPORT_C void CGSParentContainer::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   751     {
       
   752     if( iListBox )
       
   753         {
       
   754         iListBox->SetFocus( IsFocused() );
       
   755         }
       
   756     }
       
   757 
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // CGSParentContainer::HandleSelectionKeyL
       
   761 //
       
   762 // Behaves like a selection key.
       
   763 // ---------------------------------------------------------------------------
       
   764 void CGSParentContainer::HandleSelectionKeyL()
       
   765     {
       
   766     HandleListBoxEventL( iListBox,EEventEnterKeyPressed );
       
   767     }
       
   768 
       
   769 
       
   770 // -----------------------------------------------------------------------------
       
   771 // CGSParentContainer::TopPlugin()
       
   772 //
       
   773 //
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 CGSPluginInterface* CGSParentContainer::TopPlugin()
       
   777     {
       
   778     CGSPluginInterface* plugin = NULL;
       
   779     const TInt index = iListBox->TopItemIndex();
       
   780     if ( index >= 0 && index < iVisiblePlugins->Count() )
       
   781         {
       
   782         plugin = iVisiblePlugins->operator[]( index );
       
   783         __GSLOGSTRING2( "[CGSParentContainer] TopPlugin 0x%X in index %d",
       
   784             plugin->Id().iUid, index );
       
   785         }
       
   786     return plugin;
       
   787     }
       
   788 
       
   789 
       
   790 // -----------------------------------------------------------------------------
       
   791 // CGSParentContainer::SetSelectedItem()
       
   792 //
       
   793 //
       
   794 // -----------------------------------------------------------------------------
       
   795 //
       
   796 void CGSParentContainer::SetTopItem( TUid aTopItemUid )
       
   797     {
       
   798     __GSLOGSTRING1( "[CGSParentContainer] SetTopItem(0x%X)",
       
   799         aTopItemUid.iUid );
       
   800 
       
   801     if( aTopItemUid != KGSNoneSelected )
       
   802         {
       
   803         TInt topItemIndex  = 0;
       
   804         for( TInt i = 0; i < iVisiblePlugins->Count(); i++ )
       
   805             {
       
   806             CGSPluginInterface* plugin = iVisiblePlugins->operator[]( i );
       
   807             __GSLOGSTRING2( "[CGSParentContainer] Checking [%d] 0x%X)",
       
   808                 i, plugin->Id().iUid );
       
   809             // If plugin is found, select it:
       
   810             if( plugin->Id() == aTopItemUid )
       
   811                 {
       
   812                 __GSLOGSTRING2( "[CGSParentContainer] Match 0x%X in index %d",
       
   813                     plugin->Id().iUid, i );
       
   814                 topItemIndex = i;
       
   815                 break;
       
   816                 }
       
   817             }
       
   818         iListBox->SetTopItemIndex( topItemIndex );
       
   819         }
       
   820     }
       
   821 
       
   822 // -----------------------------------------------------------------------------
       
   823 // CGSParentContainer::SetListBoxEmptyTextL()
       
   824 //
       
   825 //Set the empty text of list box.
       
   826 // -----------------------------------------------------------------------------
       
   827 //
       
   828 void CGSParentContainer::SetListBoxEmptyTextL(const TDes& aEmpty )
       
   829     {
       
   830     if ( iListBox )
       
   831         {
       
   832         iListBox->View()->SetListEmptyTextL( aEmpty );
       
   833         }
       
   834     }
       
   835 
       
   836 // -----------------------------------------------------------------------------
       
   837 // CGSParentContainer::GetPositionL()
       
   838 //
       
   839 //Get the exact position of listbox.
       
   840 // -----------------------------------------------------------------------------
       
   841 //
       
   842 void CGSParentContainer::GetPositionL(RArray<TInt>& posArray)
       
   843 	{
       
   844 	posArray.AppendL(iListBox->CurrentItemIndex());
       
   845 	posArray.AppendL(iListBox->View()->ItemOffsetInPixels());
       
   846 	posArray.AppendL(iListBox->View()->TopItemIndex());
       
   847 	return;
       
   848 	}
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CGSParentContainer::GetPositionL()
       
   852 //
       
   853 //Get the exact position of listbox.
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 void CGSParentContainer::SetPosition(const RArray<TInt>& pos, TBool aChangeMode)
       
   857 	{
       
   858 	iListBox->SetCurrentItemIndex(pos.operator[](0));
       
   859 	iListBox->View()->SetItemOffsetInPixels(pos.operator[](1));
       
   860 	if (aChangeMode)
       
   861 		{
       
   862 		iListBox->View()->VerticalMoveToItemL(pos.operator[](0), CListBoxView::ESingleSelection);
       
   863 		}
       
   864 	else
       
   865 		{
       
   866 		iListBox->View()->SetTopItemIndex(pos.operator[](2));
       
   867 		}
       
   868 	}
       
   869 //End of File