browserui/browser/BrowserAppSrc/BrowserWindowSelectionContainer.cpp
branchRCL_3
changeset 48 8e6fa1719340
equal deleted inserted replaced
47:6385c4c93049 48:8e6fa1719340
       
     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 CBrowserWindowSelectionContainer.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "BrowserWindowSelectionContainer.h"
       
    24 #include "BrowserWindowSelectionView.h"
       
    25 #include "BrowserAppUi.h"
       
    26 #include "Display.h"
       
    27 #include "WindowInfoProvider.h"
       
    28 #include "BrowserWindowManager.h"
       
    29 #include "BrowserWindow.h"
       
    30 #include <BrowserNG.rsg>
       
    31 #include <aknnavi.h>
       
    32 #include <akntabgrp.h>
       
    33 #include <aknnavide.h> 
       
    34 #include <akntabgrp.h>
       
    35 #include <eikimage.h>
       
    36 #include <barsread.h>
       
    37 #include <brctldefs.h>
       
    38 #include <brctlinterface.h>
       
    39 #include <brctldefs.h>
       
    40 #include <browser.mbg>
       
    41 #include <gulicon.h>
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------
       
    45 // CBrowserWindowSelectionContainer::ConstructL
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 void CBrowserWindowSelectionContainer::ConstructL(const TRect& aRect)
       
    49     {
       
    50     CreateWindowL();	
       
    51     // Tabgroup has been read from resource and it were pushed to the navi pane.
       
    52     // Get pointer to the navigation decorator with the ResourceDecorator() function.
       
    53     // Application owns the decorator and it has responsibility to delete the object.
       
    54     iNaviDecorator = iView->ApiProvider().Display().NaviPaneL()->CreateTabGroupL();
       
    55     iTabGroup = (CAknTabGroup*)iNaviDecorator->DecoratedControl();   
       
    56     iTabGroup->SetObserver(this);
       
    57 
       
    58     /*
       
    59     // Create tab icon  	
       
    60     iTabIcon = new (ELeave) CEikImage;
       
    61     TResourceReader rr;
       
    62     iCoeEnv->CreateResourceReaderLC( rr, R_BROWSER_ICON_PROP_FOLDER );
       
    63     iTabIcon->ConstructFromResourceL( rr );
       
    64     CleanupStack::PopAndDestroy(); // rr
       
    65     */
       
    66          
       
    67     SetRect(aRect);
       
    68     ActivateL();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CBrowserWindowSelectionContainer::CBrowserWindowSelectionContainer
       
    73 // ---------------------------------------------------------
       
    74 //    
       
    75 CBrowserWindowSelectionContainer::CBrowserWindowSelectionContainer( CBrowserWindowSelectionView *aView ) : iView( aView )
       
    76     {
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CBrowserWindowSelectionContainer::~CBrowserWindowSelectionContainer
       
    81 // ---------------------------------------------------------
       
    82 //    
       
    83 CBrowserWindowSelectionContainer::~CBrowserWindowSelectionContainer()
       
    84     {
       
    85     delete iNaviDecorator;
       
    86     delete iThumbnail;
       
    87     }            
       
    88 
       
    89 // ---------------------------------------------------------
       
    90 // CBrowserWindowSelectionContainer::ChangeTabL
       
    91 // ---------------------------------------------------------
       
    92 //        
       
    93 void CBrowserWindowSelectionContainer::ChangeTabL( CArrayFixFlat<HBufC*>* aTabTexts, TInt aActivateTab )
       
    94     {
       
    95     // If there are any tabs
       
    96     if ( iTabGroup->TabCount() )
       
    97         {
       
    98         TInt tabCount = iTabGroup->TabCount();
       
    99         // Delete all tabs
       
   100         for ( TInt tabIndex = 0; tabIndex < tabCount; tabIndex++ )
       
   101             {
       
   102             // Delete the first tab until there is no more tab...
       
   103             iTabGroup->DeleteTabL( iTabGroup->TabIdFromIndex( 0 )  );
       
   104             }        
       
   105         }        
       
   106     // If only two tabs are needed, dont show more tabs.
       
   107     if ( aTabTexts->Count() == 2 )
       
   108         {
       
   109         GetTabGroup()->SetTabFixedWidthL( EAknTabWidthWithTwoLongTabs );        
       
   110         }
       
   111     // If more than two tabs are needed, maximum 3 tabs are visible
       
   112     else
       
   113         {
       
   114         GetTabGroup()->SetTabFixedWidthL( EAknTabWidthWithThreeLongTabs );                    
       
   115         }    
       
   116     // Add create the tabs
       
   117     for ( TInt tabIndex = 0; tabIndex < aTabTexts->Count(); tabIndex++ )
       
   118         {
       
   119         iTabGroup->AddTabL( tabIndex, (*aTabTexts)[tabIndex]->Des() /*, iTabIcon->Bitmap(), iTabIcon->Mask()*/ );
       
   120         }        
       
   121     // Set focus of the specified tab
       
   122     iTabGroup->SetActiveTabByIndex( aActivateTab );
       
   123     // Handle tab changes.
       
   124     iView->ApiProvider().Display().NaviPaneL()->PushL( *iNaviDecorator );
       
   125     
       
   126     // Draw the thumbnail by the window id.
       
   127     GetWindowThumbnailL( iView->GetWindowIdFromTabIndex( GetTabGroup()->ActiveTabIndex() ) );
       
   128     DrawNow();
       
   129     }
       
   130         
       
   131 // ---------------------------------------------------------
       
   132 // CBrowserWindowSelectionContainer::SizeChanged
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 void CBrowserWindowSelectionContainer::SizeChanged()
       
   136     {
       
   137     // TODO: Add here control resize code etc.
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // CBrowserWindowSelectionContainer::CountComponentControls
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 TInt CBrowserWindowSelectionContainer::CountComponentControls() const
       
   145     {
       
   146     return 0; // return nbr of controls inside this container
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CBrowserWindowSelectionContainer::ComponentControl
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 CCoeControl* CBrowserWindowSelectionContainer::ComponentControl(TInt aIndex) const
       
   154     {
       
   155     switch ( aIndex )
       
   156         {
       
   157         default:
       
   158             return NULL;
       
   159         }
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------
       
   163 // CBrowserWindowSelectionContainer::Draw
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 void CBrowserWindowSelectionContainer::Draw(const TRect& aRect) const
       
   167     {
       
   168     CWindowGc& gc = SystemGc();
       
   169     
       
   170     // Create a gray background...
       
   171     gc.SetPenColor(TRgb(45,44,50));
       
   172     gc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   173     gc.SetBrushColor( KRgbDarkGray );
       
   174     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   175     gc.DrawRect( aRect );
       
   176     
       
   177     if ( iThumbnail )
       
   178         {
       
   179 #ifdef BRDO_MULTITOUCH_ENABLED_FF        
       
   180         TSize viewSize(aRect.Width(), aRect.Height());
       
   181         int centerImageWidth(viewSize.iWidth*60/100);
       
   182         int centerImageHeight(viewSize.iHeight*75/100);
       
   183         int centerImageX(viewSize.iWidth*20/100);
       
   184         int centerImageY(viewSize.iHeight*(100-75)/(2*100));
       
   185         TPoint centerImageOrigin(centerImageX, centerImageY);
       
   186 #endif        
       
   187         // Put in center        
       
   188         // release
       
   189         TSize bitmapSize = iThumbnail->Bitmap()->SizeInPixels();        
       
   190         // test
       
   191         //TSize bitmapSize = iThumbnail->SizeInPixels();
       
   192         TInt x = ( aRect.Width()-bitmapSize.iWidth ) / 2;
       
   193         TInt y = ( aRect.Height()-bitmapSize.iHeight ) / 2;    
       
   194         // Draw thumbnail
       
   195         // release
       
   196 #ifdef BRDO_MULTITOUCH_ENABLED_FF        
       
   197         gc.BitBlt( centerImageOrigin, iThumbnail->Bitmap(), TRect(0, 0, centerImageWidth, centerImageHeight) );
       
   198 #else
       
   199         gc.BitBlt( TPoint(x,y), iThumbnail->Bitmap() );
       
   200 #endif
       
   201         // test
       
   202         // gc.BitBlt( TPoint(x,y), iThumbnail );                
       
   203         }
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CBrowserWindowSelectionContainer::OfferKeyEventL
       
   208 // ---------------------------------------------------------
       
   209 //    
       
   210 TKeyResponse CBrowserWindowSelectionContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   211     {
       
   212     // Handle if Ok key was pressed.
       
   213 	if ( aType == EEventKey && aKeyEvent.iCode == EKeyOK )
       
   214 	    {
       
   215         TInt windowId = iView->GetWindowIdFromTabIndex( GetTabGroup()->ActiveTabIndex() );
       
   216         iView->ApiProvider().WindowMgr().SwitchWindowL( windowId );
       
   217         //If the user switches window we reset the CalledFromAnotherApp status
       
   218         if(iView->ApiProvider().CalledFromAnotherApp())
       
   219             {
       
   220             iView->ApiProvider().SetCalledFromAnotherApp(EFalse);
       
   221             }
       
   222         iView->ApiProvider().SetViewToBeActivatedIfNeededL( iView->GetPreviousViewID() );	    
       
   223 	    return EKeyWasConsumed;
       
   224 	    }
       
   225     
       
   226     // Check if navipane has valid parameters.
       
   227     if ( !iTabGroup )
       
   228         {
       
   229         return EKeyWasNotConsumed;        
       
   230         }    
       
   231     if ( !iTabGroup->TabCount() )
       
   232         {
       
   233         return EKeyWasNotConsumed;        
       
   234         }        
       
   235     if ( !iNaviDecorator )
       
   236         {
       
   237         return EKeyWasNotConsumed;
       
   238         }
       
   239     // Get tab group
       
   240 	CAknTabGroup* tabGroup = STATIC_CAST( CAknTabGroup*, iNaviDecorator->DecoratedControl() );
       
   241     // If tab group was not created succesfully.
       
   242     if ( !tabGroup )	
       
   243         {
       
   244         return EKeyWasNotConsumed;
       
   245         }        
       
   246     // If tab group has no tabs.
       
   247     if ( !tabGroup->TabCount() )
       
   248         {
       
   249         return EKeyWasNotConsumed;
       
   250         }
       
   251     // Forward events to tabgroup.
       
   252     const TKeyResponse result = tabGroup->OfferKeyEventL( aKeyEvent, aType );
       
   253     
       
   254     return result;
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------
       
   258 // CBrowserWindowSelectionContainer::HandleControlEventL
       
   259 // ---------------------------------------------------------
       
   260 //
       
   261 void CBrowserWindowSelectionContainer::HandleControlEventL(
       
   262     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   263     {
       
   264     // TODO: Add your control event handler code here
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------
       
   268 // CBrowserWindowSelectionContainer::GetWindowThumbnail
       
   269 // ---------------------------------------------------------
       
   270 //
       
   271 void CBrowserWindowSelectionContainer::GetWindowThumbnailL( TInt aWindowId )
       
   272     {   
       
   273     // Get window url
       
   274     CBrowserWindow* window;
       
   275     iView->ApiProvider().WindowMgr().Window( aWindowId, window );
       
   276     HBufC* windowUrl = window->BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoUrl );
       
   277     
       
   278     // Get thumbnail
       
   279     // release
       
   280     delete iThumbnail;
       
   281     if (windowUrl)
       
   282     {
       
   283     	iThumbnail = window->BrCtlInterface().GetBitmapData( windowUrl->Des(), TBrCtlDefs::EBitmapThumbnail );
       
   284     }
       
   285     else
       
   286     {
       
   287        	iThumbnail = NULL;
       
   288     }
       
   289     // eof release
       
   290    	
       
   291        
       
   292     CleanupStack::PopAndDestroy(); // windowUrl               
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------
       
   296 // CBrowserWindowSelectionContainer::HandlePointerEventL
       
   297 // ---------------------------------------------------------
       
   298 //
       
   299 void CBrowserWindowSelectionContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   300     {
       
   301     if (aPointerEvent.iType == TPointerEvent::EButton1Down)
       
   302         {
       
   303         iView->HandleCommandL(EAknCmdOpen);
       
   304         }
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------
       
   308 // CBrowserWindowSelectionContainer::TabChangedL
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 void CBrowserWindowSelectionContainer::TabChangedL(TInt /*aIndex*/)
       
   312     {
       
   313     iView->UpdateTitleL();
       
   314     iView->UpdateTumbnailL();
       
   315     }
       
   316 
       
   317 // End of File