| 65 |      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 the License "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: 
 | 
|  |     15 | *      Implementation of CBrowserWindowSelectionView.
 | 
|  |     16 | *
 | 
|  |     17 | *
 | 
|  |     18 | */
 | 
|  |     19 | 
 | 
|  |     20 | 
 | 
|  |     21 | // INCLUDE FILES
 | 
|  |     22 | #include <aknviewappui.h>
 | 
|  |     23 | #include <avkon.hrh>
 | 
|  |     24 | #include <BrowserNG.rsg>
 | 
|  |     25 | #include <FeatMgr.h>
 | 
|  |     26 | #include <avkon.RSG>
 | 
|  |     27 | #include <eikbtgpc.h>
 | 
|  |     28 | #include <akntabgrp.h>
 | 
|  |     29 | #include <aknnavi.h>
 | 
|  |     30 | #include <brctlinterface.h>
 | 
|  |     31 | #include <brctldefs.h>
 | 
|  |     32 | #include "BrowserAppUi.h"
 | 
|  |     33 | #include "CommonConstants.h"
 | 
|  |     34 | #include "BrowserWindowSelectionView.h"
 | 
|  |     35 | #include "BrowserWindowSelectionContainer.h" 
 | 
|  |     36 | #include "Preferences.h"
 | 
|  |     37 | #include "Display.h"
 | 
|  |     38 | #include "BrowserWindowManager.h"
 | 
|  |     39 | #include "BrowserWindow.h"
 | 
|  |     40 | 
 | 
|  |     41 | // ================= MEMBER FUNCTIONS =======================
 | 
|  |     42 | 
 | 
|  |     43 | // ----------------------------------------------------------------------------
 | 
|  |     44 | // CBrowserWindowSelectionView::NewLC
 | 
|  |     45 | // ----------------------------------------------------------------------------
 | 
|  |     46 | //
 | 
|  |     47 | CBrowserWindowSelectionView* CBrowserWindowSelectionView::NewLC( MApiProvider& aApiProvider )
 | 
|  |     48 |     {
 | 
|  |     49 |     CBrowserWindowSelectionView* view = new (ELeave) CBrowserWindowSelectionView( aApiProvider );
 | 
|  |     50 |     CleanupStack::PushL( view );
 | 
|  |     51 |     view->ConstructL( );    
 | 
|  |     52 |     return view;
 | 
|  |     53 |     }
 | 
|  |     54 |     
 | 
|  |     55 | // ---------------------------------------------------------
 | 
|  |     56 | // CBrowserWindowSelectionView::CBrowserWindowSelectionView
 | 
|  |     57 | // ---------------------------------------------------------
 | 
|  |     58 | //
 | 
|  |     59 | CBrowserWindowSelectionView::CBrowserWindowSelectionView( MApiProvider& aApiProvider ):
 | 
|  |     60 | CBrowserViewBase( aApiProvider )
 | 
|  |     61 |     {
 | 
|  |     62 |     }
 | 
|  |     63 |         
 | 
|  |     64 | // ---------------------------------------------------------
 | 
|  |     65 | // CBrowserWindowSelectionView::ConstructL(const TRect& aRect)
 | 
|  |     66 | // EPOC two-phased constructor
 | 
|  |     67 | // ---------------------------------------------------------
 | 
|  |     68 | //
 | 
|  |     69 | void CBrowserWindowSelectionView::ConstructL()
 | 
|  |     70 |     {
 | 
|  |     71 |     BaseConstructL( R_BROWSERWINDOWSELECTION_VIEW );    
 | 
|  |     72 |     iTitles = new (ELeave) CArrayFixFlat<HBufC*>( 2 );
 | 
|  |     73 |     iWindowIds = new (ELeave) CArrayFixFlat<TInt>( 2 );
 | 
|  |     74 |     }
 | 
|  |     75 | 
 | 
|  |     76 | // ---------------------------------------------------------
 | 
|  |     77 | // CBrowserWindowSelectionView::~CBrowserWindowSelectionView()
 | 
|  |     78 | // destructor
 | 
|  |     79 | // ---------------------------------------------------------
 | 
|  |     80 | //
 | 
|  |     81 | CBrowserWindowSelectionView::~CBrowserWindowSelectionView()
 | 
|  |     82 |     {
 | 
|  |     83 |     if ( iContainer )
 | 
|  |     84 |         {
 | 
|  |     85 |         AppUi()->RemoveFromViewStack( *this, iContainer );
 | 
|  |     86 |         }
 | 
|  |     87 | 
 | 
|  |     88 |     delete iContainer;
 | 
|  |     89 |     delete iWindowInfo;
 | 
|  |     90 |     delete iTitles;
 | 
|  |     91 |     delete iWindowIds;
 | 
|  |     92 |     }
 | 
|  |     93 | 
 | 
|  |     94 | // ---------------------------------------------------------
 | 
|  |     95 | // TUid CBrowserWindowSelectionView::Id()
 | 
|  |     96 | //
 | 
|  |     97 | // ---------------------------------------------------------
 | 
|  |     98 | //
 | 
|  |     99 | TUid CBrowserWindowSelectionView::Id() const
 | 
|  |    100 |     {
 | 
|  |    101 |     return KUidBrowserWindowSelectionViewId;
 | 
|  |    102 |     }
 | 
|  |    103 |     
 | 
|  |    104 | // ---------------------------------------------------------------------------
 | 
|  |    105 | // CBrowserWindowSelectionView::CommandSetResourceIdL
 | 
|  |    106 | // ---------------------------------------------------------------------------
 | 
|  |    107 | TInt CBrowserWindowSelectionView::CommandSetResourceIdL()
 | 
|  |    108 |     {
 | 
|  |    109 |     TInt commandSet = 0; // R_AVKON_SOFTKEYS_EMPTY;
 | 
|  |    110 |     return commandSet;
 | 
|  |    111 |     }  
 | 
|  |    112 |     
 | 
|  |    113 | // ---------------------------------------------------------
 | 
|  |    114 | // CBrowserWindowSelectionView::HandleCommandL()
 | 
|  |    115 | // ---------------------------------------------------------
 | 
|  |    116 | //
 | 
|  |    117 | void CBrowserWindowSelectionView::HandleCommandL(TInt aCommand)
 | 
|  |    118 |     {   
 | 
|  |    119 |     switch ( aCommand )
 | 
|  |    120 |         {
 | 
|  |    121 |         case EAknCmdOpen:
 | 
|  |    122 |             {
 | 
|  |    123 |             TInt windowId = GetWindowIdFromTabIndex( iContainer->GetTabGroup()->ActiveTabIndex() );
 | 
|  |    124 |             ApiProvider().WindowMgr().SwitchWindowL( windowId );
 | 
|  |    125 |             //If the user switches window we reset the CalledFromAnotherApp status
 | 
|  |    126 |         	if(ApiProvider().CalledFromAnotherApp())
 | 
|  |    127 |             	{
 | 
|  |    128 |             	ApiProvider().SetCalledFromAnotherApp(EFalse);
 | 
|  |    129 |             	}
 | 
|  |    130 |             ApiProvider().SetViewToBeActivatedIfNeededL( GetPreviousViewID() );
 | 
|  |    131 |             break;                
 | 
|  |    132 |             }
 | 
|  |    133 |         case EWmlCmdCloseWindow:
 | 
|  |    134 |             {            
 | 
|  |    135 |             TInt windowId = GetWindowIdFromTabIndex( iContainer->GetTabGroup()->ActiveTabIndex() );
 | 
|  |    136 |             TInt newWindowId = ApiProvider().WindowMgr().DeleteWindowL( windowId, EFalse );
 | 
|  |    137 |             
 | 
|  |    138 |             // Check if there is only one remaining window,
 | 
|  |    139 |             // after closing the window.
 | 
|  |    140 |             delete iWindowInfo;
 | 
|  |    141 |             iWindowInfo = NULL;
 | 
|  |    142 |             iWindowInfo = ApiProvider().WindowMgr().GetWindowInfoL( this );
 | 
|  |    143 |             if ( iWindowInfo->Count() < 2 )
 | 
|  |    144 |                 {
 | 
|  |    145 |                 ApiProvider().SetViewToBeActivatedIfNeededL( KUidBrowserContentViewId );
 | 
|  |    146 |                 ApiProvider().WindowMgr().SwitchWindowL( newWindowId );                
 | 
|  |    147 |                 }
 | 
|  |    148 |             break;                
 | 
|  |    149 |             }            
 | 
|  |    150 |         case EWmlCmdCloseAllWindowButThis:
 | 
|  |    151 |             {
 | 
|  |    152 |             iWindowEventsDisabled = ETrue;
 | 
|  |    153 |             // Get current window id.
 | 
|  |    154 |             TInt windowId = GetWindowIdFromTabIndex( iContainer->GetTabGroup()->ActiveTabIndex() );
 | 
|  |    155 |             // Get all windows id.
 | 
|  |    156 |             delete iWindowInfo;
 | 
|  |    157 |             iWindowInfo = NULL;
 | 
|  |    158 |             iWindowInfo = ApiProvider().WindowMgr().GetWindowInfoL( this );
 | 
|  |    159 |             
 | 
|  |    160 |             // Delete all windows except this.            
 | 
|  |    161 |             for ( TInt i = 0; i < iWindowInfo->Count(); i++ )
 | 
|  |    162 |                 {                
 | 
|  |    163 |                 if ( (*iWindowInfo)[i]->iWindowId != windowId )
 | 
|  |    164 |                     {
 | 
|  |    165 |                     ApiProvider().WindowMgr().DeleteWindowL( (*iWindowInfo)[i]->iWindowId, ETrue );                    
 | 
|  |    166 |                     }                    
 | 
|  |    167 |                 }
 | 
|  |    168 |             // Activate curent window.
 | 
|  |    169 |             ApiProvider().SetViewToBeActivatedIfNeededL( KUidBrowserContentViewId );
 | 
|  |    170 |             ApiProvider().WindowMgr().SwitchWindowL( windowId );
 | 
|  |    171 |             iWindowEventsDisabled = EFalse;            
 | 
|  |    172 |             break;                
 | 
|  |    173 |             }            
 | 
|  |    174 |         case EWmlCmdWindowSelectionCancel:
 | 
|  |    175 |             {
 | 
|  |    176 |             ApiProvider().SetViewToBeActivatedIfNeededL( KUidBrowserContentViewId );
 | 
|  |    177 |             break;
 | 
|  |    178 |             }
 | 
|  |    179 |         default:
 | 
|  |    180 |             {
 | 
|  |    181 |             break;
 | 
|  |    182 |             }
 | 
|  |    183 |         }
 | 
|  |    184 |     }
 | 
|  |    185 | 
 | 
|  |    186 | // ---------------------------------------------------------
 | 
|  |    187 | // CBrowserWindowSelectionView::HandleClientRectChange()
 | 
|  |    188 | // ---------------------------------------------------------
 | 
|  |    189 | //
 | 
|  |    190 | void CBrowserWindowSelectionView::HandleClientRectChange()
 | 
|  |    191 |     {
 | 
|  |    192 |     if ( iContainer )
 | 
|  |    193 |         {
 | 
|  |    194 |         iContainer->SetRect( ClientRect() );
 | 
|  |    195 |         }
 | 
|  |    196 |     }
 | 
|  |    197 | 
 | 
|  |    198 | // ---------------------------------------------------------
 | 
|  |    199 | // CBrowserWindowSelectionView::DoActivateL(...)
 | 
|  |    200 | // 
 | 
|  |    201 | // ---------------------------------------------------------
 | 
|  |    202 | //
 | 
|  |    203 | void CBrowserWindowSelectionView::DoActivateL( const TVwsViewId& aPrevViewId,TUid /*aCustomMessageId*/,
 | 
|  |    204 |                                                const TDesC8& /*aCustomMessage*/)
 | 
|  |    205 |     {    
 | 
|  |    206 |     StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
 | 
|  |    207 |     StatusPane()->MakeVisible( ETrue );
 | 
|  |    208 | 
 | 
|  |    209 |     iPreviousViewID = ApiProvider().LastActiveViewId( );
 | 
|  |    210 |     ApiProvider().SetLastActiveViewId( Id() );
 | 
|  |    211 |     iLastViewId = aPrevViewId;
 | 
|  |    212 |     if (!iContainer)
 | 
|  |    213 |         {
 | 
|  |    214 |         iContainer = new (ELeave) CBrowserWindowSelectionContainer( this );
 | 
|  |    215 |         iContainer->SetMopParent(this);
 | 
|  |    216 |         iContainer->ConstructL( ClientRect() );
 | 
|  |    217 |         AppUi()->AddToStackL( *this, iContainer );
 | 
|  |    218 |         UpdateTabsL();
 | 
|  |    219 |         }
 | 
|  |    220 |     ApiProvider().WindowMgr().AddObserverL( this );        
 | 
|  |    221 |     }
 | 
|  |    222 | 
 | 
|  |    223 | // ---------------------------------------------------------
 | 
|  |    224 | // CBrowserWindowSelectionView::DoDeactivate()
 | 
|  |    225 | // ---------------------------------------------------------
 | 
|  |    226 | //
 | 
|  |    227 | void CBrowserWindowSelectionView::DoDeactivate()
 | 
|  |    228 |     {
 | 
|  |    229 |     if ( iContainer )
 | 
|  |    230 |         {
 | 
|  |    231 |         AppUi()->RemoveFromViewStack( *this, iContainer );
 | 
|  |    232 |         }
 | 
|  |    233 |     
 | 
|  |    234 |     delete iContainer;
 | 
|  |    235 |     iContainer = NULL;
 | 
|  |    236 |     ApiProvider().WindowMgr().RemoveObserver( this );    
 | 
|  |    237 |     }
 | 
|  |    238 | 
 | 
|  |    239 | // ---------------------------------------------------------
 | 
|  |    240 | // CBrowserWindowSelectionView::CreateWindowInfoLC()
 | 
|  |    241 | // ---------------------------------------------------------
 | 
|  |    242 | //    
 | 
|  |    243 | HBufC* CBrowserWindowSelectionView::CreateWindowInfoLC( const CBrowserWindow& aWindow )
 | 
|  |    244 |     {
 | 
|  |    245 |     HBufC* buf = aWindow.BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoTitle );
 | 
|  |    246 |     if( !buf || !buf->Length() )
 | 
|  |    247 |         {
 | 
|  |    248 |         CleanupStack::PopAndDestroy( buf );
 | 
|  |    249 |         buf = aWindow.BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoUrl );
 | 
|  |    250 |         }
 | 
|  |    251 |     return buf;
 | 
|  |    252 |     }
 | 
|  |    253 | 
 | 
|  |    254 | // ---------------------------------------------------------
 | 
|  |    255 | // CBrowserWindowSelectionView::UpdateTabs()
 | 
|  |    256 | // ---------------------------------------------------------
 | 
|  |    257 | //        
 | 
|  |    258 | void CBrowserWindowSelectionView::UpdateTabsL()
 | 
|  |    259 |     {
 | 
|  |    260 |     delete iWindowInfo;
 | 
|  |    261 |     iWindowInfo = NULL;
 | 
|  |    262 |     iWindowInfo = ApiProvider().WindowMgr().GetWindowInfoL( this );
 | 
|  |    263 | 
 | 
|  |    264 |     iTitles->Reset();
 | 
|  |    265 |     iWindowIds->Reset();
 | 
|  |    266 |     TInt activeTab = 0;
 | 
|  |    267 |     for ( TInt i = 0; i < iWindowInfo->Count(); i++ )
 | 
|  |    268 |         {
 | 
|  |    269 |         iTitles->AppendL( CONST_CAST( HBufC*, (*iWindowInfo)[i]->iWindowText ) );
 | 
|  |    270 |         iWindowIds->AppendL( (*iWindowInfo)[i]->iWindowId );
 | 
|  |    271 |         if ( (*iWindowInfo)[i]->iCurrent )
 | 
|  |    272 |             {
 | 
|  |    273 |             activeTab = i;
 | 
|  |    274 |             HBufC* title = CONST_CAST( HBufC*, (*iWindowInfo)[i]->iWindowText );
 | 
|  |    275 |             if ( title )
 | 
|  |    276 |                 {
 | 
|  |    277 |                 ApiProvider().Display().SetTitleL( title->Des() );
 | 
|  |    278 |                 }                
 | 
|  |    279 |             }
 | 
|  |    280 |         }
 | 
|  |    281 |     iContainer->ChangeTabL( iTitles, activeTab );
 | 
|  |    282 |     }
 | 
|  |    283 |     
 | 
|  |    284 |     
 | 
|  |    285 | // ---------------------------------------------------------
 | 
|  |    286 | // CBrowserWindowSelectionView::UpdateTabs()
 | 
|  |    287 | // ---------------------------------------------------------
 | 
|  |    288 | //        
 | 
|  |    289 | void CBrowserWindowSelectionView::UpdateTumbnailL()
 | 
|  |    290 |     {
 | 
|  |    291 |     TInt windowId = GetWindowIdFromTabIndex( iContainer->GetTabGroup()->ActiveTabIndex() );
 | 
|  |    292 |     iContainer->GetWindowThumbnailL( windowId );
 | 
|  |    293 |     iContainer->DrawNow();
 | 
|  |    294 |     }
 | 
|  |    295 |     
 | 
|  |    296 | // ---------------------------------------------------------
 | 
|  |    297 | // CBrowserWindowSelectionView::UpdateTitleL()
 | 
|  |    298 | // ---------------------------------------------------------
 | 
|  |    299 | //        
 | 
|  |    300 | void CBrowserWindowSelectionView::UpdateTitleL( )
 | 
|  |    301 |     {    
 | 
|  |    302 |     HBufC* title = GetWindowTitleFromTabIndex( iContainer->GetTabGroup()->ActiveTabIndex() );
 | 
|  |    303 |     ApiProvider().Display().SetTitleL( (*title).Des( ) );
 | 
|  |    304 |     }
 | 
|  |    305 |     
 | 
|  |    306 | // -----------------------------------------------------------------------------
 | 
|  |    307 | // CBrowserWindowSelectionView::GetWindowIdFromTabIndex
 | 
|  |    308 | // -----------------------------------------------------------------------------
 | 
|  |    309 | //
 | 
|  |    310 | TInt CBrowserWindowSelectionView::GetWindowIdFromTabIndex( TInt aActiveTabIndex )
 | 
|  |    311 |     {
 | 
|  |    312 |     TInt windowId = 0;
 | 
|  |    313 |     for ( TInt i = 0; i < iWindowIds->Count(); i++ )
 | 
|  |    314 |         {
 | 
|  |    315 |         if ( i ==  aActiveTabIndex ) 
 | 
|  |    316 |             {
 | 
|  |    317 |             windowId = (*iWindowInfo)[i]->iWindowId;
 | 
|  |    318 |             }
 | 
|  |    319 |         }
 | 
|  |    320 |     return windowId;
 | 
|  |    321 |     }
 | 
|  |    322 | 
 | 
|  |    323 | // -----------------------------------------------------------------------------
 | 
|  |    324 | // CBrowserWindowSelectionView::GetWindowIdFromTabIndex
 | 
|  |    325 | // -----------------------------------------------------------------------------
 | 
|  |    326 | //
 | 
|  |    327 | HBufC* CBrowserWindowSelectionView::GetWindowTitleFromTabIndex( TInt aActiveTabIndex )
 | 
|  |    328 |     {
 | 
|  |    329 |     HBufC*  windowText = NULL;
 | 
|  |    330 |     for ( TInt i = 0; i < iWindowInfo->Count(); i++ )
 | 
|  |    331 |         {        
 | 
|  |    332 |         if ( i ==  aActiveTabIndex ) 
 | 
|  |    333 |             {
 | 
|  |    334 |             windowText = CONST_CAST( HBufC*, (*iWindowInfo)[i]->iWindowText );
 | 
|  |    335 |             }
 | 
|  |    336 |         }
 | 
|  |    337 |     return windowText;
 | 
|  |    338 |     }
 | 
|  |    339 | 
 | 
|  |    340 | // ---------------------------------------------------------
 | 
|  |    341 | // CBrowserWindowSelectionView::WindowEventHandlerL
 | 
|  |    342 | // ---------------------------------------------------------
 | 
|  |    343 | //
 | 
|  |    344 | void CBrowserWindowSelectionView::WindowEventHandlerL( TWindowEvent aEvent, TInt /*aWindowId*/ )
 | 
|  |    345 |     {
 | 
|  |    346 |     if ( !iWindowEventsDisabled )
 | 
|  |    347 |         {            
 | 
|  |    348 |         if ( aEvent == EWindowClose || aEvent == EWindowOpen )
 | 
|  |    349 |             {
 | 
|  |    350 |             delete iWindowInfo;
 | 
|  |    351 |             iWindowInfo = NULL;
 | 
|  |    352 |             iWindowInfo = ApiProvider().WindowMgr().GetWindowInfoL( this );
 | 
|  |    353 |             // Update tabs when there are more than one windows open.
 | 
|  |    354 |             if ( iWindowInfo->Count() > 1 )
 | 
|  |    355 |                 {        
 | 
|  |    356 |                 UpdateTabsL();
 | 
|  |    357 |                 }            
 | 
|  |    358 |             }            
 | 
|  |    359 |         if ( aEvent == EWindowLoadStart )
 | 
|  |    360 |             {
 | 
|  |    361 |             iEikonEnv->InfoMsg( _L("load start") );
 | 
|  |    362 |             }            
 | 
|  |    363 |         if ( aEvent == EWindowLoadStop )
 | 
|  |    364 |             {
 | 
|  |    365 |             iEikonEnv->InfoMsg( _L("load stop") );
 | 
|  |    366 |             }            
 | 
|  |    367 |         }
 | 
|  |    368 |     }
 | 
|  |    369 |         
 | 
|  |    370 | // End of File
 |