browserui/browser/BrowserAppSrc/BrowserAppViewBase.cpp
changeset 0 84ad3b177aa3
child 1 57d5b8e231c4
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     1 /*
       
     2 * Copyright (c) 2002 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 *      Declaration of class CBrowserAppViewBase.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "BrowserAppViewBase.h"
       
    22 #include "BrowserAppUi.h"
       
    23 #include "ApiProvider.h"
       
    24 #include <BrowserNG.rsg>
       
    25 #include "CommonConstants.h"
       
    26 #include <aknviewappui.h>
       
    27 #include <eikbtgpc.h>
       
    28 #include <avkon.rsg>
       
    29 #include <LayoutMetaData.cdl.h> // check landscape/portrait modes
       
    30 #include <aknenv.h>
       
    31 #include <AknSgcc.h>
       
    32 #include <StringLoader.h>
       
    33 
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // TSKPair::TSKPair
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 TSKPair::TSKPair():
       
    42 	iCmdId(EWmlNoCmd),iQtnRsc(R_BROWSER_DYN_SK_NULL)
       
    43 {
       
    44 }	
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // TSKPair::TSKPair
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 TSKPair::TSKPair(TInt aId,TInt aRsc):
       
    51 	iCmdId(aId),iQtnRsc(aRsc)
       
    52 {
       
    53 }	
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // TSKPair::IsNotDefault
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 TBool TSKPair::IsAssigned()
       
    60 {
       
    61 	return ( (iCmdId != EWmlNoCmd) && (iQtnRsc != R_BROWSER_DYN_SK_NULL) );
       
    62 }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // TSKPair::operator==
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 TBool TSKPair::operator==(TSKPair aSkPair)
       
    69 {
       
    70 	return( (iCmdId == aSkPair.id()) && (iQtnRsc == aSkPair.qtn()) );
       
    71 }
       
    72 
       
    73 // ---------------------------------------------------------
       
    74 // TSKPair::operator=
       
    75 // ---------------------------------------------------------
       
    76 //
       
    77 void TSKPair::operator=(TSKPair aSKPair)
       
    78 {
       
    79 	iCmdId = aSKPair.id();
       
    80 	iQtnRsc = aSKPair.qtn();
       
    81 }
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // TSKPair::set
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void TSKPair::setPair(TInt aId, TInt aRsc)
       
    88 {
       
    89 	iCmdId = aId;
       
    90 	iQtnRsc = aRsc;
       
    91 }
       
    92 
       
    93 
       
    94 // ================= MEMBER FUNCTIONS =======================
       
    95 
       
    96 // ---------------------------------------------------------
       
    97 // CBrowserViewBase::CBrowserViewBase
       
    98 // ---------------------------------------------------------
       
    99 //
       
   100 CBrowserViewBase::CBrowserViewBase( MApiProvider& aApiProvider ):
       
   101     iApiProvider( aApiProvider ),
       
   102     iLastCommandSet( R_BROWSER_BUTTONS_CBA_NULL )
       
   103     {
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // CBrowserViewBase::ApiProvider
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 MApiProvider& CBrowserViewBase::ApiProvider()
       
   111     {
       
   112     return iApiProvider;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------
       
   116 // CBrowserViewBase::UpdateCbaL
       
   117 // ---------------------------------------------------------
       
   118 //
       
   119 void CBrowserViewBase::UpdateCbaL()
       
   120 {
       
   121     if ( !iApiProvider.ExitInProgress() )
       
   122         {
       
   123         TInt commandSet = CommandSetResourceIdL();
       
   124         TUid currViewId = Id();
       
   125 
       
   126 		// Ask BrowserAppUi which view we were in when we last updated the CBA
       
   127 		// this will help decide if we should do it again
       
   128         TUid previousCBAUpdateViewId = iApiProvider.GetLastCBAUpdateView();
       
   129 
       
   130         if ( commandSet )
       
   131         	{
       
   132         	// Don't perform updates to the CBA when
       
   133         	//
       
   134         	// - We're still in the same view we were just in AND
       
   135         	// - We're not dynamically setting CBA (do more checking below) AND
       
   136         	// - The command set is the same as the one we just set last time
       
   137         	//   this was called
       
   138         	// - We're currently in the content view (the update-cba is more complex here
       
   139         	//   and we should just do it when asked by ContentView class)
       
   140         	//
       
   141         	// NOTE that we rely on CommandSetResource to set the commandSet to
       
   142         	//  R_BROWSER_BUTTONS_CBA_DYNAMIC to signal a desire to update the keys
       
   143         	//  dynamically. 
       
   144 			if(	currViewId == iPreviousViewID &&
       
   145 				commandSet != R_BROWSER_BUTTONS_CBA_DYNAMIC &&
       
   146 				currViewId == previousCBAUpdateViewId &&
       
   147 				currViewId != KUidBrowserContentViewId)
       
   148 				{
       
   149 				return;
       
   150 				}
       
   151         	
       
   152         	// If command set is our special dynamic cba set,
       
   153         	// now ask derived class for the resources dynamically.        	
       
   154         	if(commandSet == R_BROWSER_BUTTONS_CBA_DYNAMIC)
       
   155             	{
       
   156 				TSKPair lsk,rsk,msk;					
       
   157 				CommandSetResourceDynL(lsk,rsk,msk);
       
   158 
       
   159 				// Similar exclusion as above:
       
   160 				// Don't update the LSK, RSK, MSK dynamic assignments if:
       
   161 				//
       
   162 				// - We're still in the same view we were just in
       
   163 				// - The lsk, rsk, msk are all the same settings we set last time
       
   164 				if(currViewId == previousCBAUpdateViewId &&
       
   165 					lsk == iLastLSK && 
       
   166 					rsk == iLastRSK &&
       
   167 					msk == iLastMSK)
       
   168 				{
       
   169 					return;
       
   170 				}				
       
   171 				
       
   172 				// Save the settings
       
   173 				iLastLSK = lsk;
       
   174 				iLastRSK = rsk;
       
   175 				iLastMSK = msk;
       
   176 				
       
   177 				//
       
   178 				// Update each softkey in turn
       
   179 				// 
       
   180 				// If the CommandSetResourceDynL command assigned something to the key
       
   181 				// (in other words, it changed the key assignment from its default - it does have the option not to do so), 
       
   182 				// 
       
   183 				// Update each key now.
       
   184 				//
       
   185 				// Each derived-class view should update them as a general rule, even if it is to some default value
       
   186 				//	
       
   187 				if( lsk.IsAssigned() )
       
   188 					{
       
   189 					HBufC* txt = StringLoader::LoadLC( lsk.qtn() );
       
   190             		Cba()->SetCommandL(CEikButtonGroupContainer::ELeftSoftkeyPosition, lsk.id(), *txt);
       
   191 					CleanupStack::PopAndDestroy();  // txt
       
   192 					}
       
   193 				if( rsk.IsAssigned() )
       
   194 					{
       
   195 					HBufC* txt = StringLoader::LoadLC( rsk.qtn() );
       
   196             		Cba()->SetCommandL(CEikButtonGroupContainer::ERightSoftkeyPosition, rsk.id(), *txt);
       
   197 					CleanupStack::PopAndDestroy();  // txt
       
   198 					}
       
   199 				if( msk.IsAssigned() )
       
   200 					{
       
   201 					HBufC* txt = StringLoader::LoadLC( msk.qtn() );
       
   202             		Cba()->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition, msk.id(), *txt);
       
   203 					CleanupStack::PopAndDestroy();  // txt
       
   204 					}
       
   205 				}
       
   206 			else // Else - the exisiting case: set the softkeys as a block by assigning a pre-defined resource id
       
   207 				{
       
   208 	        	// The usual case is to set the command set to 
       
   209     	    	// whatever CommandSetResourceIdL has said
       
   210 	    	  	Cba()->SetCommandSetL( commandSet );				
       
   211 				}				
       
   212  			
       
   213  			// Save the last command set and set view id
       
   214  			iLastCommandSet = commandSet;
       
   215  			iApiProvider.SetLastCBAUpdateView(currViewId);
       
   216  			
       
   217 	   		// DrawNow() doesn't refresh MSK properly
       
   218            	Cba()->DrawDeferred();
       
   219 			}
       
   220         }    
       
   221 }
       
   222 
       
   223 
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 
       
   229 
       
   230 // ---------------------------------------------------------
       
   231 // CBrowserViewBase::MakeCbaVisible
       
   232 // ---------------------------------------------------------
       
   233 //
       
   234 void CBrowserViewBase::MakeCbaVisible(TBool aVisible)
       
   235     {
       
   236     // don't turn off the cba in landscape mode since it will still be visible and
       
   237     // calling MakeVisible(EFalse) will just make it not update correctly
       
   238 
       
   239     TBool vis = aVisible;
       
   240     if (!vis)
       
   241         {
       
   242         CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
       
   243         TInt currentStatusPaneLayoutResId = 0;
       
   244         if (statusPane)
       
   245             {
       
   246             currentStatusPaneLayoutResId = statusPane->CurrentLayoutResId();
       
   247             }
       
   248         else
       
   249             {
       
   250             // If this CBA:s owner does not have statuspane, then we ask the layout from AknCapServer.
       
   251             currentStatusPaneLayoutResId = AVKONENV->StatusPaneResIdForCurrentLayout(CAknSgcClient::CurrentStatuspaneResource());
       
   252             }
       
   253 
       
   254         TBool staconPane = ((currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT) ||
       
   255                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT)  ||
       
   256                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT) ||
       
   257                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT)  ||
       
   258                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_RIGHT) ||
       
   259                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_LEFT));
       
   260         vis = staconPane;
       
   261         }
       
   262     Cba()->MakeVisible( vis );
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------
       
   266 // CBrowserViewBase::UpdateGotoPaneL
       
   267 // ---------------------------------------------------------
       
   268 //
       
   269 void CBrowserViewBase::UpdateGotoPaneL()
       
   270     {
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------
       
   274 // CBrowserViewBase::ClearCbaL
       
   275 // ---------------------------------------------------------
       
   276 //
       
   277 void CBrowserViewBase::ClearCbaL()
       
   278     {
       
   279     TInt commandSet = R_AVKON_SOFTKEYS_EMPTY;
       
   280     Cba()->SetCommandSetL( commandSet );
       
   281     Cba()->DrawNow();
       
   282     }
       
   283 // End of File