gssettingsuis/Gs/GSFramework/src/GSTabHelper.cpp
changeset 37 940f6b67827d
parent 36 48848d132687
child 38 5a264aaf7677
equal deleted inserted replaced
36:48848d132687 37:940f6b67827d
     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:  Utility class for creating tab groups.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "gstabhelper.h"
       
    21 #include "gstabbedview.h"
       
    22 #include "GsLogger.h"
       
    23 
       
    24 #include <aknappui.h>
       
    25 #include <aknnavi.h>
       
    26 #include <aknnavide.h>
       
    27 #include <akntabgrp.h>
       
    28 #include <AknTabObserver.h>
       
    29 #include <eikspane.h>
       
    30 #include <gulicon.h>
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CGSTabHelper::CGSTabHelper
       
    36 // C++ constructor.
       
    37 //
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CGSTabHelper::CGSTabHelper()
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CGSTabHelper::NewL()
       
    47 // Symbian OS two-phased constructor.
       
    48 //
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CGSTabHelper* CGSTabHelper::NewL()
       
    52     {
       
    53     CGSTabHelper* self = NewLC();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CGSTabHelper::NewLC()
       
    61 // Symbian OS two-phased constructor.
       
    62 //
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C CGSTabHelper* CGSTabHelper::NewLC()
       
    66     {
       
    67     CGSTabHelper* self = new(ELeave) CGSTabHelper();
       
    68     CleanupStack::PushL(self);
       
    69     self->ConstructL();
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CGSTabHelper::ConstructL(const TRect& aRect)
       
    76 // Symbian OS default constuctor.
       
    77 //
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CGSTabHelper::ConstructL()
       
    81     {
       
    82     iNaviDecorator = NULL;
       
    83 
       
    84     iAppUi =  static_cast<CAknViewAppUi*>( CCoeEnv::Static()->AppUi() );
       
    85 
       
    86     CEikStatusPane* statusPane = iAppUi->StatusPane();
       
    87 
       
    88     // Fetch pointer to the default navi pane container:
       
    89     iNaviContainer = static_cast<CAknNavigationControlContainer*>
       
    90         ( statusPane->ControlL( TUid::Uid(EEikStatusPaneUidNavi ) ) );
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CGSTabHelper::~CGSTabHelper()
       
    96 // Destructor
       
    97 //
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 EXPORT_C CGSTabHelper::~CGSTabHelper()
       
   101     {
       
   102     RemoveTabGroup();
       
   103     }
       
   104 
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CGSTabHelper::CreateTabGroupL()
       
   108 //
       
   109 //
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void CGSTabHelper::CreateTabGroupL( TUid aActiveViewUid,
       
   113                                              MGSTabbedViewOwner* aTabOwner )
       
   114     {
       
   115     iTabOwner = aTabOwner;
       
   116     CreateTabGroupL( aActiveViewUid, iTabOwner->TabbedViews() );
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CGSTabHelper::CreateTabGroupL()
       
   121 //
       
   122 //
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 EXPORT_C void CGSTabHelper::CreateTabGroupL(
       
   126     TUid aActiveViewUid,
       
   127     CArrayPtrFlat<CGSPluginInterface>* aTabbedViews )
       
   128     {
       
   129     RemoveTabGroup();//Remove possible old tab group.
       
   130     iNaviDecorator = iNaviContainer->CreateTabGroupL( this );
       
   131     iTabGroup =
       
   132         static_cast<CAknTabGroup*> ( iNaviDecorator->DecoratedControl() );
       
   133 
       
   134     switch ( aTabbedViews->Count() )
       
   135         {
       
   136         case 1:
       
   137             iTabGroup->SetTabFixedWidthL( KTabWidthWithOneTab );
       
   138             break;
       
   139         case 2:
       
   140             iTabGroup->SetTabFixedWidthL( KTabWidthWithTwoTabs );
       
   141             break;
       
   142         case 3:
       
   143             iTabGroup->SetTabFixedWidthL( KTabWidthWithThreeTabs );
       
   144             break;
       
   145         default:
       
   146             iTabGroup->SetTabFixedWidthL( KTabWidthWithFourTabs );
       
   147             break;
       
   148         }
       
   149 
       
   150     for( TInt i = 0; i < aTabbedViews->Count(); i++ )
       
   151         {
       
   152         CGSPluginInterface* tabbedView = aTabbedViews->operator[]( i );
       
   153         CGulIcon* icon = NULL;
       
   154         TRAPD
       
   155             (
       
   156             err,
       
   157             icon = tabbedView->CreateIconL( KGSIconTypeTab );
       
   158             )
       
   159 
       
   160         // CreateIconL should not leave outside. If creating icon leaves, use
       
   161         // default icon.
       
   162         if( err != KErrNone )
       
   163             {
       
   164             __GSLOGSTRING2(
       
   165                 "[CGSTabHelper] ERROR: 0x%X::CreateIconL failed (%d), using default icon.",
       
   166                 tabbedView->Id().iUid, err );
       
   167 
       
   168             icon =
       
   169                 tabbedView->CGSPluginInterface::CreateIconL( KGSIconTypeTab );
       
   170             }
       
   171         CleanupStack::PushL( icon );
       
   172         iTabGroup->AddTabL( tabbedView->Id().iUid,
       
   173                            icon->Bitmap(),
       
   174                            icon->Mask() );
       
   175 
       
   176         // Bitmaps are now owned by the tab:
       
   177         icon->SetBitmapsOwnedExternally( ETrue );
       
   178 
       
   179         // Delete icon object. Bitmaps are not owned by icon anymore and thus
       
   180         // not deleted:
       
   181         CleanupStack::PopAndDestroy( icon );
       
   182         }
       
   183 
       
   184     iNaviContainer->PushL( *iNaviDecorator );
       
   185 
       
   186     // The active tab should be same as active plugin
       
   187     iTabGroup->SetActiveTabById( aActiveViewUid.iUid );
       
   188     }
       
   189 
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CGSTabHelper::CreateTabGroupL()
       
   193 //
       
   194 //
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 EXPORT_C void CGSTabHelper::CreateTabGroupL(
       
   198     TUid aActiveViewUid,
       
   199     CArrayPtrFlat<MGSTabbedView>* aTabbedViews )
       
   200     {
       
   201     RemoveTabGroup();//Remove possible old tab group.
       
   202     iNaviDecorator = iNaviContainer->CreateTabGroupL( this );
       
   203     iTabGroup =
       
   204         static_cast<CAknTabGroup*> ( iNaviDecorator->DecoratedControl() );
       
   205 
       
   206     switch ( aTabbedViews->Count() )
       
   207         {
       
   208         case 1:
       
   209             iTabGroup->SetTabFixedWidthL( KTabWidthWithOneTab );
       
   210             break;
       
   211         case 2:
       
   212             iTabGroup->SetTabFixedWidthL( KTabWidthWithTwoTabs );
       
   213             break;
       
   214         case 3:
       
   215             iTabGroup->SetTabFixedWidthL( KTabWidthWithThreeTabs );
       
   216             break;
       
   217         default:
       
   218             iTabGroup->SetTabFixedWidthL( KTabWidthWithFourTabs );
       
   219             break;
       
   220         }
       
   221 
       
   222     for( TInt i = 0; i < aTabbedViews->Count(); i++ )
       
   223         {
       
   224         MGSTabbedView* tabbedView = aTabbedViews->operator[]( i );
       
   225 
       
   226          // Takes icon ownership
       
   227         CGulIcon* icon = tabbedView->CreateTabIconL();
       
   228         CleanupStack::PushL( icon );
       
   229 
       
   230 
       
   231         iTabGroup->AddTabL( tabbedView->Id().iUid,
       
   232                            icon->Bitmap(),
       
   233                            icon->Mask() );
       
   234 
       
   235         //Bitmaps are now owned by the tab:
       
   236         icon->SetBitmapsOwnedExternally( ETrue );
       
   237 
       
   238         // Delete icon object. Bitmaps are not owned by icon anymore and thus
       
   239         // not deleted:
       
   240         CleanupStack::PopAndDestroy( icon );
       
   241         }
       
   242 
       
   243     iNaviContainer->PushL( *iNaviDecorator );
       
   244 
       
   245     // The active tab should be same as active plugin
       
   246     iTabGroup->SetActiveTabById( aActiveViewUid.iUid );
       
   247     }
       
   248 
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CGSTabHelper::RemoveTabGroup()
       
   252 //
       
   253 // Removes the tab group owned by this class from navi pane.
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 EXPORT_C void CGSTabHelper::RemoveTabGroup()
       
   257     {
       
   258     if( iNaviDecorator )
       
   259         {
       
   260         iNaviContainer->Pop( iNaviDecorator );
       
   261         delete iNaviDecorator;
       
   262         iNaviDecorator = NULL;
       
   263         }
       
   264     }
       
   265 
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CGSTabHelper::TabChangedL()
       
   269 //
       
   270 //
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 EXPORT_C void CGSTabHelper::TabChangedL( TInt aIndex )
       
   274     {
       
   275     TUid uid;
       
   276     uid.iUid = iTabGroup->TabIdFromIndex( aIndex );
       
   277 
       
   278     // If has a tab owner, notify it:
       
   279     if( iTabOwner )
       
   280         {
       
   281         iTabOwner->TabChangedL( uid );
       
   282         }
       
   283 
       
   284     iAppUi->ActivateLocalViewL( uid );
       
   285     }
       
   286 
       
   287 
       
   288 //  End of File