uifw/AvKon/src/AknAppUi.cpp
changeset 0 2f259fa3e83a
child 9 aabf2c525e0f
child 45 667edd0b8678
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002 - 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:  App UI
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikbtgpc.h>
       
    19 #include "aknappui.h"
       
    20 #include <avkon.rsg>
       
    21 #include <avkon.hrh>
       
    22 #include <eikenv.h>
       
    23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include <uikon/eikenvinterface.h>
       
    25 #endif
       
    26 #include <AknDef.h>
       
    27 #include "aknconsts.h"
       
    28 #include <aknsoundsystem.h>
       
    29 #include <AknSgcc.h>
       
    30 #include <AknSettingCache.h>
       
    31 #include <AknWsEventObserver.h>
       
    32 #include <apgwgnam.h>
       
    33 #include <babitflags.h>
       
    34 #include <hlplch.h>
       
    35 
       
    36 #include <centralrepository.h>
       
    37 #include <AvkonInternalCRKeys.h>   // KAknQwertyInputModeActive (and others)
       
    38 #include <AknFepInternalCRKeys.h>  // KAknFepHashKeySelection
       
    39 #include <settingsinternalcrkeys.h> // KSettingsAutolockStatus
       
    40 #include <cenrepnotifyhandler.h>
       
    41 #include <e32property.h>
       
    42 #include <ctsydomainpskeys.h>
       
    43 
       
    44 #include <eikmenub.h>
       
    45 #include <eikcolib.h>
       
    46 #include <eikapp.h>
       
    47 #include <eikon.hrh>
       
    48 #include <AknsUtils.h>
       
    49 #include <AknsConstants.h>
       
    50 
       
    51 #include "aknshut.h"
       
    52 #include "aknenv.h"
       
    53 #include <aknsoundsystem.h>
       
    54 #include "aknanimdllstd.h"
       
    55  
       
    56 #include <textresolver.h>
       
    57 #include <AknGlobalNote.h>
       
    58 #include <apgcli.h>
       
    59 #include <AknUtils.h>
       
    60 #include <AknBidiTextUtils.h>
       
    61 #include <aknconsts.h>
       
    62 
       
    63 #include <AknCapServerClient.h>
       
    64 #include "AknDebug.h"
       
    65 #include <AknPanic.h>
       
    66 
       
    67 #include <akntranseffect.h> // for Transition effect enumerations
       
    68 #include <aknlayoutscalable_avkon.cdl.h>
       
    69 #include <gfxtranseffect/gfxtranseffect.h>
       
    70 
       
    71 #include <aknSDData.h>
       
    72 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h>
       
    73 #include <startupdomainpskeys.h>
       
    74 
       
    75 #include "transitionmanager.h"
       
    76 #include <PtiEngine.h>   
       
    77 #include <PtiKeyMappings.h> 
       
    78 
       
    79 #include <akntoolbar.h>
       
    80 #include <eikdialg.h>
       
    81 
       
    82 #ifdef RD_SCALABLE_UI_V2
       
    83 #include <AknPriv.hrh>
       
    84 #include <akntouchpane.h>
       
    85 #endif
       
    86 
       
    87 #include <touchfeedbackadaptation.h>
       
    88 #include <touchfeedback.h>
       
    89 
       
    90 #include <aknpointereventmodifier.h>
       
    91 
       
    92 // UIDS for dialler view
       
    93 const TUid KPhoneAppUid = { 0x100058B3 };
       
    94 const TUid KAknDiallerViewUid = {0x10282D81};
       
    95 const TUid KDiallerVievCommand = {0x1};
       
    96 const TUid KVoiceUiUID = { 0x101F8543 };
       
    97 _LIT( KVoiceDialApplication, "z:\\sys\\bin\\vuivoicerecognition.exe" ); //SIVC
       
    98 
       
    99 #include "akncompaif.h" // touch compatibility mode
       
   100 
       
   101 const TUid KActiveIdle2Uid = {0x102750F0};
       
   102 const TUid KActiveIdleView = {0x1};
       
   103 
       
   104 #ifndef APPLICATIONORIENTATION_H
       
   105 const TUid KCRUidDefaultAppOrientation = {0x200159ED};
       
   106 #endif
       
   107 
       
   108 //const TInt KAknAppUiViewsGranularity = 1;
       
   109 
       
   110 NONSHARABLE_CLASS(CAknAppUiExtension)
       
   111   : public CBase, 
       
   112     public MCenRepNotifyHandlerCallback,
       
   113     public MCoeViewActivationObserver
       
   114     {
       
   115 public:
       
   116     static CAknAppUiExtension* NewL();
       
   117     ~CAknAppUiExtension();
       
   118 
       
   119     // From MCenRepNotifyHandlerCallback
       
   120     void HandleNotifyInt(TUint32 aId, TInt aNewValue); 
       
   121     
       
   122     // from MCoeViewActivationObserver
       
   123     void HandleViewActivation(const TVwsViewId& aNewlyActivatedViewId,const TVwsViewId& aViewIdToBeDeactivated);
       
   124     
       
   125 private: 
       
   126     CAknAppUiExtension();
       
   127     void ConstructL();  
       
   128 
       
   129 public:    
       
   130     MAknAliasKeyCodeResolver* iAknAliasKeyCodeResolver;
       
   131 
       
   132     // Handle to Central Repository.
       
   133     CRepository* iCenRep;    
       
   134     
       
   135     // For CenRep value change notifications. 
       
   136     CCenRepNotifyHandler* iCenRepNotifyHandler;        
       
   137     
       
   138     // PubSub property for qwerty mode status.
       
   139     RProperty iQwertyModeStatusProperty;
       
   140 
       
   141     // more app UI flags    
       
   142     enum TAknExtFlags
       
   143         {
       
   144         EHashKeyDown,       // Indicates whether hash key is down.    
       
   145         EHashKeyMarking,    // Caches the value of CenRep key KAknFepHashKeySelection.
       
   146         ESimulatingEvent,
       
   147         EAppIsHiddenInBackground,
       
   148         EFocusLost
       
   149         };
       
   150     TBitFlags iFlags;
       
   151     
       
   152     TInt iDisabledScanCode;
       
   153     
       
   154     TUid iLastActivatedViewId;
       
   155     };
       
   156     
       
   157     
       
   158 CAknAppUiExtension* CAknAppUiExtension::NewL()
       
   159     {
       
   160     CAknAppUiExtension* self = new (ELeave) CAknAppUiExtension();
       
   161     CleanupStack::PushL(self);
       
   162     self->ConstructL();
       
   163     CleanupStack::Pop();
       
   164     return self;
       
   165     }    
       
   166     
       
   167 CAknAppUiExtension::CAknAppUiExtension():
       
   168     iDisabledScanCode( -1 )
       
   169     {
       
   170     }
       
   171     
       
   172 void CAknAppUiExtension::ConstructL()
       
   173     {
       
   174     // Start listening a CenRep key indicating whether hash key selection is active.
       
   175     TRAPD(err, iCenRep = CRepository::NewL(KCRUidAknFep));
       
   176     if (err == KErrNone)
       
   177         {
       
   178         iCenRepNotifyHandler = CCenRepNotifyHandler::NewL(*this,
       
   179             *iCenRep,
       
   180             CCenRepNotifyHandler::EIntKey,
       
   181             KAknFepHashKeySelection);
       
   182 
       
   183         iCenRepNotifyHandler->StartListeningL();
       
   184         TBool hashKeyMarking;
       
   185         if (iCenRep->Get(KAknFepHashKeySelection, hashKeyMarking) == KErrNone)
       
   186             iFlags.Assign(EHashKeyMarking, hashKeyMarking);
       
   187         } 
       
   188         
       
   189     // Attach to qwerty mode status property. Hash key marking is disabled when qwerty 
       
   190     // mode is active. Attach success also even if the value doesn't exist.
       
   191     User::LeaveIfError(iQwertyModeStatusProperty.Attach(KCRUidAvkon, KAknQwertyInputModeActive));
       
   192     }     
       
   193     
       
   194 CAknAppUiExtension::~CAknAppUiExtension()
       
   195     {
       
   196     // Stop listening CenRep.
       
   197     if (iCenRepNotifyHandler)
       
   198         {
       
   199         iCenRepNotifyHandler->StopListening();
       
   200         }
       
   201     delete iCenRepNotifyHandler;
       
   202     delete iCenRep; 
       
   203     
       
   204     // Close PubSub handle.
       
   205     iQwertyModeStatusProperty.Close();
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CAknAppUiExtension::HandleNotifyInt
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CAknAppUiExtension::HandleNotifyInt(TUint32 aId, TInt aNewValue)
       
   213     {
       
   214     if (aId == KAknFepHashKeySelection)
       
   215         {
       
   216         iFlags.Assign(EHashKeyMarking, aNewValue);
       
   217         }
       
   218     }
       
   219     
       
   220 void CAknAppUiExtension::HandleViewActivation(const TVwsViewId& aNewlyActivatedViewId,const TVwsViewId& aViewIdToBeDeactivated)
       
   221     {
       
   222     CEikonEnv& eikEnv = *CEikonEnv::Static();
       
   223     TUid thisAppUid = eikEnv.EikAppUi()->Application()->AppDllUid();
       
   224     // if changing from another app to a new view in this app, clear the redraw stores
       
   225     if (aViewIdToBeDeactivated.iAppUid != thisAppUid &&
       
   226          ( (iLastActivatedViewId != TUid::Null() && 
       
   227          aNewlyActivatedViewId.iViewUid != iLastActivatedViewId) ||
       
   228          eikEnv.ScreenDevice()->CurrentScreenMode() != CAknSgcClient::ScreenMode().ModeNumber()))
       
   229         eikEnv.WsSession().ClearAllRedrawStores();
       
   230     if (aNewlyActivatedViewId.iAppUid == thisAppUid)
       
   231         iLastActivatedViewId = aNewlyActivatedViewId.iViewUid;
       
   232     }
       
   233     
       
   234 
       
   235 enum TAknAppUiBaseFlags
       
   236     {
       
   237     EEmbedded,
       
   238     EFaded,
       
   239     EContainerWasForeground,
       
   240     EContainerWasPartialForeground,
       
   241     EFullScreen,
       
   242     EPartialForeground,
       
   243     ELayoutAwareApp, // Deprecated
       
   244     EOrientationSpecified,
       
   245     EOrientationLandscape,
       
   246     EOrientationAutomatic,
       
   247     EMSKEnabled,
       
   248     EForegroundOrPartialForeground,
       
   249     EAppClosing,
       
   250     ETouchCompatible,
       
   251     ESingleClickCompatible
       
   252     };
       
   253 
       
   254 
       
   255 // CLASS DECLARATION
       
   256 
       
   257 /** 
       
   258  * A class to launch the dialler or SIVC from non used send key press
       
   259  */ 
       
   260  
       
   261 NONSHARABLE_CLASS ( CAknDiallerLauncher ) : public CCoeControl
       
   262     {
       
   263 public:
       
   264     static CAknDiallerLauncher* NewL(CAknCompaIf*& aCompaIf);
       
   265     ~CAknDiallerLauncher();
       
   266     void SetFlags( const TInt aFlags );
       
   267 private: // From CCoeControl
       
   268     TKeyResponse OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType);
       
   269     
       
   270 private:
       
   271     CAknDiallerLauncher(CAknCompaIf*& aCompaIf);
       
   272     void ConstructL();
       
   273     void StartKeyTimerL();
       
   274     void StopKeyTimer();
       
   275     void LaunchDiallerL();
       
   276     void LaunchVoiceCommandL();
       
   277     static TInt ReportLongPressL( TAny* aThis );
       
   278     
       
   279 private:
       
   280     CPeriodic* iKeyTimer;
       
   281     CAknCompaIf*& iCompaIf; // touch compatibility mode
       
   282     TInt iKeyFlags;
       
   283     };
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CAknDiallerLauncher::NewL
       
   287 // Two-phased constructor.
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 CAknDiallerLauncher* CAknDiallerLauncher::NewL(CAknCompaIf*& aCompaIf)
       
   291     {
       
   292     CAknDiallerLauncher* self = new ( ELeave ) CAknDiallerLauncher(aCompaIf);
       
   293     CleanupStack::PushL( self );
       
   294     self->ConstructL();
       
   295     CleanupStack::Pop( self );
       
   296     return self;
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CAknDiallerLauncher::CAknDiallerLauncher
       
   301 // C++ default constructor.
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 CAknDiallerLauncher::CAknDiallerLauncher(CAknCompaIf*& aCompaIf):
       
   305     iCompaIf(aCompaIf)
       
   306     {
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CAknDiallerLauncher::ConstructL
       
   311 // Symbian 2nd phase constructor.
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CAknDiallerLauncher::ConstructL()
       
   315     {
       
   316     iKeyFlags = 0;
       
   317     }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // Destructor
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 CAknDiallerLauncher::~CAknDiallerLauncher()
       
   324     {
       
   325     delete iKeyTimer;
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CAknDiallerLauncher::SetFlags
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CAknDiallerLauncher::SetFlags( const TInt aFlags )
       
   333     {
       
   334     iKeyFlags = aFlags;
       
   335     }
       
   336     
       
   337 // -----------------------------------------------------------------------------
       
   338 // CAknDiallerLauncher::OfferKeyEventL
       
   339 // Returns always EKeyWasNotConsumed
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 TKeyResponse CAknDiallerLauncher::OfferKeyEventL( 
       
   343     const TKeyEvent &aKeyEvent, TEventCode aType )
       
   344     {    
       
   345 
       
   346     if ( aKeyEvent.iScanCode != EStdKeyYes ) 
       
   347         { 
       
   348         return EKeyWasNotConsumed;
       
   349         }
       
   350 
       
   351     if ( iKeyFlags & CAknAppUiBase::EDisableSendKeyLong && 
       
   352          iKeyFlags & CAknAppUiBase::EDisableSendKeyShort )
       
   353         {
       
   354         return EKeyWasNotConsumed;
       
   355         }
       
   356     
       
   357     // Check if autolock is on (if there is a an active call ongoing
       
   358     // and sendkey is pressed, keyevent ends up here and must be dismissed
       
   359     // to avoid opening dialler)
       
   360     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings); 
       
   361     
       
   362     TInt lockStatus(0);
       
   363     TInt lockStatusErr = repository->Get(KSettingsAutolockStatus, lockStatus);
       
   364     
       
   365     delete repository;
       
   366     repository = NULL;
       
   367     
       
   368     // If lock is on, nothing should be done so we can just return.
       
   369     // Also return if status could't be fetched (just in case).
       
   370     if ( lockStatus == 1 || lockStatusErr != KErrNone )
       
   371         {
       
   372         return EKeyWasNotConsumed;
       
   373         }
       
   374 
       
   375     TInt curVal( 0 );
       
   376     TInt err = RProperty::Get( KPSUidStartup, KPSStartupUiPhase, curVal );
       
   377     if ( curVal != EStartupUiPhaseAllDone )
       
   378         {
       
   379         return EKeyWasNotConsumed;
       
   380         }
       
   381 
       
   382     // if it's alerting & Ringing status, ignore the send key event
       
   383     TInt callVal( 0 );
       
   384     TInt errCall = RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callVal );
       
   385     if ( err == KErrNone  && ( callVal == EPSCTsyCallStateDialling || EPSCTsyCallStateRinging == callVal ) )
       
   386         {
       
   387         return EKeyWasNotConsumed;
       
   388         }
       
   389     
       
   390     // if it's emerency calls status, ignore the send key event
       
   391     TInt emergVal( 0 );
       
   392     TInt errEmerg = RProperty::Get( KPSUidCtsyEmergencyCallInfo, KCTSYEmergencyCallInfo, emergVal );
       
   393     if ( errEmerg == KErrNone  && emergVal == 1 )
       
   394         {
       
   395         return EKeyWasNotConsumed;
       
   396         }
       
   397     
       
   398     if ( aType == EEventKeyDown )
       
   399         {
       
   400         StartKeyTimerL();                
       
   401         }
       
   402 
       
   403     if ( aType == EEventKeyUp && 
       
   404          iKeyTimer && iKeyTimer->IsActive() )
       
   405         {
       
   406         StopKeyTimer();
       
   407         if ( iKeyFlags & CAknAppUiBase::EDisableSendKeyShort )
       
   408             {
       
   409             return EKeyWasNotConsumed;
       
   410             }
       
   411                                               
       
   412         TBool launch = AknLayoutUtils::PenEnabled();
       
   413         // In touch compatibility mode current layout (QVGA) doesn't have
       
   414         // pen enabled. But dialler can be launched as it executes in
       
   415         // "native" layout where pen is enabled.
       
   416         launch = launch || ( iCompaIf && iCompaIf->IsForeground() );
       
   417         if ( launch )
       
   418             {
       
   419             LaunchDiallerL();
       
   420             }
       
   421         }
       
   422     return EKeyWasNotConsumed;
       
   423     }    
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CAknDiallerLauncher::StartKeyTimerL
       
   427 // Starts the timer for the long press. Timer is constructed when used for the
       
   428 // first time
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 void CAknDiallerLauncher::StartKeyTimerL()
       
   432     {
       
   433     if ( !iKeyTimer )
       
   434         {
       
   435         iKeyTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   436         }
       
   437     else if ( iKeyTimer->IsActive() )
       
   438         {
       
   439         iKeyTimer->Cancel();
       
   440         }
       
   441     iKeyTimer->Start( KAknKeyboardRepeatInitialDelay,
       
   442                       KAknKeyboardRepeatInitialDelay, 
       
   443                       TCallBack ( ReportLongPressL, this ) );
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CAknDiallerLauncher::StopKeyTimer
       
   448 // -----------------------------------------------------------------------------
       
   449 //
       
   450 void CAknDiallerLauncher::StopKeyTimer()
       
   451     {
       
   452     if ( iKeyTimer && iKeyTimer->IsActive() )
       
   453         {
       
   454         iKeyTimer->Cancel();
       
   455         }
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CAknDiallerLauncher::ReportLongPressL
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 TInt CAknDiallerLauncher::ReportLongPressL( TAny* aThis )
       
   463     {
       
   464     CAknDiallerLauncher* self = 
       
   465         reinterpret_cast <CAknDiallerLauncher* > ( aThis );
       
   466     self->StopKeyTimer();
       
   467     if ( iAvkonAppUi->IsForeground() )
       
   468         {
       
   469         self->LaunchVoiceCommandL();
       
   470         }
       
   471     return 1; // CPeriodic ignores return value
       
   472     }
       
   473     
       
   474 // -----------------------------------------------------------------------------
       
   475 // CAknDiallerLauncher::LaunchDiallerL
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 void CAknDiallerLauncher::LaunchDiallerL()
       
   479     {
       
   480     TVwsViewId diallerView( KPhoneAppUid, KAknDiallerViewUid );
       
   481     iAvkonAppUi->CreateActivateViewEventL( diallerView,
       
   482                 KDiallerVievCommand, KNullDesC8() );
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CAknDiallerLauncher::LaunchVoiceCommandL
       
   487 // -----------------------------------------------------------------------------
       
   488 //    
       
   489 void CAknDiallerLauncher::LaunchVoiceCommandL()
       
   490     {
       
   491     if ( iKeyFlags & CAknAppUiBase::EDisableSendKeyLong )
       
   492         {
       
   493         return;
       
   494         }
       
   495             
       
   496     // Touch compatibility mode
       
   497     if (iCompaIf)
       
   498         {
       
   499         // Voice command launches itself in QHD layout on top of compa-mode
       
   500         // application. The screen gets messed up. Compa-mode application is
       
   501         // using wserv offset support to switch screen right (center the QVGA
       
   502         // application window). When it shows behind another non-offsetting
       
   503         // application, the shith is lost and screen is messed up.
       
   504         // A workaroundfor for this is to switch idle screen to foreground
       
   505         // before voice commander is launched.
       
   506         TVwsViewId idleView(KActiveIdle2Uid, KActiveIdleView);
       
   507         if (iCompaIf->IsForeground())
       
   508             {
       
   509             iAvkonAppUi->CreateActivateViewEventL(idleView, KNullUid,
       
   510                 KNullDesC8());
       
   511             }
       
   512         }
       
   513     
       
   514     TApaTaskList apaTaskList( iCoeEnv->WsSession() );
       
   515     TApaTask apaTask = apaTaskList.FindApp( KVoiceUiUID );
       
   516     
       
   517     if ( apaTask.Exists() )
       
   518         {
       
   519         apaTask.BringToForeground();
       
   520         }
       
   521     else
       
   522         {
       
   523     RApaLsSession apa;
       
   524     User::LeaveIfError( apa.Connect() );
       
   525     CleanupClosePushL( apa );
       
   526     CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   527     cmdLine->SetExecutableNameL( KVoiceDialApplication );
       
   528     cmdLine->SetCommandL( EApaCommandRunWithoutViews );
       
   529     User::LeaveIfError( apa.StartApp( *cmdLine ) );
       
   530     CleanupStack::PopAndDestroy( 2 ); // cmdLine, apa
       
   531         }
       
   532 
       
   533     }
       
   534     
       
   535 class CAknAppUiBaseExtension : public CBase
       
   536     {
       
   537 public:
       
   538     CAknAppUiBaseExtension();
       
   539     TRect iApplicationRect; // Application rect stored inside appui so that we dont need to call wserv methods when someone asks for application rect.
       
   540     TInt iDefaultRotation;
       
   541     TAknUiZoom iLocalUiZoom;
       
   542     TInt iScreenMode;
       
   543     TInt iMSKEnabled; //CenRep value cached here
       
   544     CTouchFeedbackAdaptation* iFeedbackAdaptation;
       
   545 
       
   546     CAknDiallerLauncher* iDiallerLauncher;
       
   547     CAknCompaIf* iCompaIf; // touch compatibility mode
       
   548     CAknPointerEventModifier* iPointerEventModifier;
       
   549     };
       
   550 
       
   551 CAknAppUiBaseExtension::CAknAppUiBaseExtension()
       
   552     : iLocalUiZoom(EAknUiZoomAutomatic), iScreenMode(KAknScreenModeUnset)
       
   553     {
       
   554     }
       
   555 
       
   556 EXPORT_C CAknAppUiBase::~CAknAppUiBase()
       
   557     {
       
   558     if (iAppUiBaseExtension)
       
   559         {
       
   560         MTouchFeedback::DestroyInstance();
       
   561         iAppUiBaseExtension->iFeedbackAdaptation = NULL;
       
   562         RemoveFromStack( iAppUiBaseExtension->iDiallerLauncher );
       
   563         delete iAppUiBaseExtension->iDiallerLauncher;        
       
   564         iAppUiBaseExtension->iDiallerLauncher = NULL;
       
   565         delete iAppUiBaseExtension->iCompaIf;
       
   566         delete iAppUiBaseExtension->iPointerEventModifier;
       
   567         }
       
   568     delete iAppUiBaseExtension;
       
   569     iAppUiBaseExtension = NULL;
       
   570     delete iEventMonitor;
       
   571     delete iKeySounds;
       
   572     }
       
   573 
       
   574 EXPORT_C CAknAppUiBase::CAknAppUiBase() : CEikAppUi()
       
   575     {
       
   576     SetFullScreenApp(ETrue);
       
   577     }
       
   578 
       
   579 EXPORT_C void CAknAppUiBase::HandleForegroundEventL(TBool aForeground)
       
   580     {
       
   581     CAknSgcClient::SetKeyboardRepeatRate(EAknApplicationDefaulRepeatRate);
       
   582     iAknFlags.Clear(EContainerWasForeground);      // no longer need this flag
       
   583     iAknFlags.Clear(EContainerWasPartialForeground);       // no longer need this flag
       
   584     iAknFlags.Clear(EPartialForeground);           // now either foreground or background
       
   585 
       
   586     CEikAppUi::HandleForegroundEventL( aForeground );
       
   587 
       
   588     CAknSgcClient::HandleChangeL();
       
   589     }
       
   590 
       
   591 EXPORT_C void CAknAppUiBase::ConstructL()
       
   592     {
       
   593     // Should Implement
       
   594     BaseConstructL(0);
       
   595     }
       
   596 
       
   597 void CAknAppUiBase::SetAppUiAndLeaveIfErrorL( TInt aError )
       
   598     {
       
   599     if ( aError < KErrNone )
       
   600         {
       
   601         iContainerAppUi = static_cast<CEikAppUi*>(iEikonEnv->SetAppUi( this ));
       
   602         User::Leave( aError );       
       
   603         }   
       
   604     }
       
   605 
       
   606 EXPORT_C void CAknAppUiBase::BaseConstructL( TInt aAppUiFlags )
       
   607     {
       
   608 #ifdef AVKON_RDEBUG_INFO
       
   609     RDebug::Print(_L("CAknAppUiBase::BaseConstructL()"));
       
   610 #endif
       
   611 
       
   612     // note that the extension may have already been created by some other API call
       
   613     // for example SetLocalUiZoomL
       
   614         
       
   615     if(!iAppUiBaseExtension)
       
   616         {
       
   617         // To avoid having to test on this extension everywhere, we need to Leave if the alloc fails.
       
   618         TRAPD( err,iAppUiBaseExtension = new(ELeave) CAknAppUiBaseExtension);   
       
   619         // ensure that CCoeEnv takes ownership before leaving
       
   620         SetAppUiAndLeaveIfErrorL( err );
       
   621         }
       
   622 
       
   623     // enable receipt of changes to screen state
       
   624     iEikonEnv->RootWin().EnableScreenChangeEvents();
       
   625 
       
   626     iAppUiBaseExtension->iApplicationRect = iCoeEnv->ScreenDevice()->SizeInPixels();
       
   627     
       
   628     if (!iAppUiBaseExtension->iFeedbackAdaptation )
       
   629         {
       
   630         iAppUiBaseExtension->iFeedbackAdaptation = CTouchFeedbackAdaptation::NewL();
       
   631         }
       
   632     
       
   633 #ifdef AVKON_RDEBUG_INFO
       
   634     RDebug::Print(_L("CAknAppUiBase::BaseConstructL() application rect set"));
       
   635 #endif
       
   636     CRepository* repository = NULL;
       
   637     TRAPD(ret, repository = CRepository::NewL(KCRUidAvkon));
       
   638     if (ret == KErrNone)
       
   639         {
       
   640         ret = repository->Get(KAknDefaultAppOrientation, iAppUiBaseExtension->iDefaultRotation);
       
   641         ret = repository->Get(KAknMiddleSoftkeyEnabled, iAppUiBaseExtension->iMSKEnabled);
       
   642         }
       
   643 #ifdef AVKON_RDEBUG_INFO
       
   644     RDebug::Print(_L("CAknAppUiBase::BaseConstructL() orientation ok"));
       
   645 #endif
       
   646 
       
   647     TInt orientationFlags = aAppUiFlags;
       
   648     CRepository* defaultOrientationCr = NULL;
       
   649     TRAPD( err, defaultOrientationCr = CRepository::NewL( KCRUidDefaultAppOrientation ) );
       
   650     if (err == KErrNone)
       
   651         {
       
   652         // Repository found, check if the orientation has been set
       
   653         TInt value = 0;
       
   654         err = defaultOrientationCr->Get( RProcess().SecureId().iId, value );
       
   655         if( err == KErrNone && value )
       
   656             {
       
   657             // Application key found and orientation has been set
       
   658             orientationFlags = value;
       
   659             }
       
   660         delete defaultOrientationCr;
       
   661         defaultOrientationCr = NULL;
       
   662         }
       
   663     iAknFlags.Assign(EOrientationSpecified, orientationFlags&EAppOrientationSpecifiedFlag);
       
   664     iAknFlags.Assign(EOrientationLandscape, orientationFlags&EAppOrientationLandscapeFlag);
       
   665     iAknFlags.Assign(EOrientationAutomatic, orientationFlags&EAppOrientationAutomaticFlag);
       
   666     iAknFlags.Assign(EMSKEnabled, aAppUiFlags&EAknEnableMSKflag);
       
   667     iAknFlags.Assign( ESingleClickCompatible,
       
   668             aAppUiFlags & EAknSingleClickCompatibleFlag );
       
   669 
       
   670     if ( aAppUiFlags & EAknTouchCompatibleFlag )
       
   671         {
       
   672         iAknFlags.Set( ETouchCompatible );
       
   673         }
       
   674     else
       
   675         {
       
   676         RProcess process;
       
   677         TFileName fileName = process.FileName();
       
   678         _LIT(KRomDrive,"z:");
       
   679         
       
   680         if ( fileName.FindF( KRomDrive ) == 0 )
       
   681             {
       
   682             iAknFlags.Set( ETouchCompatible );
       
   683             }
       
   684         }
       
   685 
       
   686 #ifdef AVKON_RDEBUG_INFO
       
   687     RDebug::Print(_L("Entering CEikAppUi::BaseConstructL()"));    
       
   688 #endif
       
   689 
       
   690     // Touch compatibility mode. Change application screen mode before
       
   691     // a call to CEikAppUi::BaseConstructL(). This way application
       
   692     // starts in a correct screen mode and there are no
       
   693     // HandleResourceChangeL() calls due to screen mode change.
       
   694     TInt compaScreenMode = KErrNotFound;
       
   695     TBool screenModeChanged = EFalse;
       
   696     // Check if the application doesn't need compa-mode or compa-mode is
       
   697     // disabled
       
   698     if (CAknCompaIf::IsNeeded(aAppUiFlags, repository))
       
   699         {
       
   700         // Compa-mode may be needed. Instantiate ecom plugin to check
       
   701         // further. Change application screen mode if compa-mode is needed.
       
   702         TBool isConsoleApp;
       
   703         TRAPD(compaModeErr,
       
   704             iAppUiBaseExtension->iCompaIf = CAknCompaIf::NewL();
       
   705             // SetCompaAppScreenModeL() returns KErrNotFound if compa-mode
       
   706             // is not needed
       
   707             compaScreenMode =
       
   708                 iAppUiBaseExtension->iCompaIf->SetCompaAppScreenModeL(
       
   709                     screenModeChanged, isConsoleApp, aAppUiFlags, *this,
       
   710                     *iCoeEnv, *repository));
       
   711         delete repository; repository = NULL;
       
   712         // Ensure that CCoeEnv takes ownership before leaving
       
   713         SetAppUiAndLeaveIfErrorL(compaModeErr);
       
   714         if (compaScreenMode == KErrNotFound)
       
   715             {
       
   716             delete iAppUiBaseExtension->iCompaIf;
       
   717             iAppUiBaseExtension->iCompaIf = NULL;
       
   718             }
       
   719         else
       
   720             {
       
   721             if (isConsoleApp)
       
   722                 {
       
   723                 // If console application is run in compa-mode, allow status
       
   724                 // bar to be created. Status bar is required to be able to set
       
   725                 // application screen mode.
       
   726                 aAppUiFlags &= ~CEikAppUi::ENoScreenFurniture;
       
   727                 }
       
   728             }
       
   729         }
       
   730     delete repository; repository = NULL;
       
   731 
       
   732     CEikAppUi::BaseConstructL( aAppUiFlags );
       
   733     
       
   734     if ( !iAppUiBaseExtension->iDiallerLauncher )
       
   735         {
       
   736         iAppUiBaseExtension->iDiallerLauncher =
       
   737             CAknDiallerLauncher::NewL(iAppUiBaseExtension->iCompaIf);
       
   738         AddToStackL( iAppUiBaseExtension->iDiallerLauncher, -100, 
       
   739                      ECoeStackFlagRefusesFocus );
       
   740         }
       
   741 
       
   742     iAvkonEnv->TransitionEvent(KAknTransitionEventFlags); //look at fullsceen flags
       
   743 
       
   744     
       
   745 #ifdef AVKON_RDEBUG_INFO
       
   746     RDebug::Print(_L("CEikAppUi::BaseConstructL() out "));
       
   747 #endif
       
   748 
       
   749     if (iEikonEnv->StartedAsServerApp())
       
   750         EnableExternalViewSwitches(EFalse);
       
   751 
       
   752     // Note: iKeySounds is left uninitialized  //
       
   753 
       
   754     iEventMonitor = CAknWsEventMonitor::NewL();
       
   755     
       
   756     if(!(aAppUiFlags & EAknExplicitStartupEffectCompletion)) //does start idle time
       
   757         iAvkonEnv->TransitionEvent(AknTransEffect::EAppStartComplete);//normal case
       
   758 
       
   759     // Touch compatibility mode
       
   760     if (iAppUiBaseExtension->iCompaIf)
       
   761         {
       
   762         // Create compatibility mode keyboard and make it visible in the case
       
   763         // of a normal application. Compa-keyboard is also created for servers
       
   764         // that display global/notes notifications but left invisible.
       
   765         iAppUiBaseExtension->iCompaIf->CreateKbL(compaScreenMode,
       
   766             screenModeChanged);
       
   767         // Tactile feedback needs to be informed about layout change, because
       
   768         // otherwise it won't get correct information about pen support
       
   769         // (Tactile Feedback was instantiated earlier in this function, when
       
   770         // pen was still enabled).
       
   771         iAppUiBaseExtension->iFeedbackAdaptation->LayoutChanged();
       
   772         }
       
   773     else
       
   774         {
       
   775         // Pointer event modifier is not needed while in compatibility mode so
       
   776         // its creation is delayed until here.
       
   777         //
       
   778         // Leaves during construction are ignored since pointer event modifier
       
   779         // isn't mandatory i.e. the device should be usable also without it.
       
   780         TRAP_IGNORE( iAppUiBaseExtension->iPointerEventModifier = CAknPointerEventModifier::NewL() )
       
   781         }
       
   782     }
       
   783 
       
   784 EXPORT_C TBool CAknAppUiBase::IsFaded() const
       
   785     {
       
   786     return CAknSgcClient::IsSystemFaded();
       
   787     }
       
   788 
       
   789 /**
       
   790  * Returns the object which allows events to be spyed upon in addition to
       
   791  * normal event handling
       
   792  */
       
   793 EXPORT_C CAknWsEventMonitor* CAknAppUiBase::EventMonitor() const
       
   794     {
       
   795     return iEventMonitor;
       
   796     }
       
   797 
       
   798 EXPORT_C CAknKeySoundSystem* CAknAppUiBase::KeySounds() const
       
   799     {
       
   800     return iKeySounds;
       
   801     }
       
   802 
       
   803 EXPORT_C void CAknAppUiBase::ReplaceKeySoundsL( TInt aUid )
       
   804     {
       
   805     delete iKeySounds;
       
   806     iKeySounds = NULL;
       
   807     iKeySounds = CAknKeySoundSystem::NewL(aUid);
       
   808     }
       
   809 
       
   810 EXPORT_C TTypeUid::Ptr CAknAppUiBase::MopSupplyObject(TTypeUid aId)
       
   811     {
       
   812     // We give tactile feedback client as object provider for
       
   813     // MCoeControlStateObserver interface, so that feedback
       
   814     // areas of dimmed and invisible controls can be
       
   815     // disabled automatically.
       
   816     if ( aId.iUid == MCoeControlStateObserver::ETypeId &&  
       
   817          iAppUiBaseExtension && 
       
   818          iAppUiBaseExtension->iFeedbackAdaptation )
       
   819         {
       
   820         return aId.MakePtr( 
       
   821             static_cast<MCoeControlStateObserver*>(
       
   822                 iAppUiBaseExtension->iFeedbackAdaptation ) );
       
   823         }
       
   824     else
       
   825         {
       
   826         // Touch compatibility mode. AknCapServer needs access to interface.
       
   827        if (aId.iUid == CAknCompaIf::ETypeId)
       
   828             {
       
   829             CAknCompaIf* compaIf = iAppUiBaseExtension ?
       
   830                 iAppUiBaseExtension->iCompaIf : NULL;
       
   831             return aId.MakePtr(compaIf);
       
   832             }
       
   833         return CEikAppUi::MopSupplyObject(aId);
       
   834         }
       
   835     }
       
   836 
       
   837 EXPORT_C void CAknAppUiBase::SetFullScreenApp(TBool aIsFullScreen)
       
   838     {
       
   839     iAknFlags.Assign(EFullScreen, aIsFullScreen);
       
   840     }
       
   841 
       
   842 EXPORT_C TBool CAknAppUiBase::IsFullScreenApp() const
       
   843     {
       
   844     return iAknFlags[EFullScreen];
       
   845     }
       
   846 
       
   847 TBool CAknAppUiBase::IsMSKEnabledApp() const
       
   848     {
       
   849     return iAknFlags[EMSKEnabled];
       
   850     }
       
   851 
       
   852 EXPORT_C TBool CAknAppUiBase::IsLayoutAwareApp() const
       
   853     {
       
   854     return ETrue;
       
   855     }
       
   856 
       
   857 EXPORT_C void CAknAppUiBase::SetLayoutAwareApp(TBool /*aLayoutAwareApp*/)
       
   858     {
       
   859     }
       
   860 
       
   861 EXPORT_C TBool CAknAppUiBase::IsForeground() const
       
   862     {
       
   863     return static_cast<CAknAppUiBase*>(iEikonEnv->EikAppUi()) == this && ThreadIsForeground();
       
   864     }
       
   865 
       
   866 EXPORT_C TBool CAknAppUiBase::IsPartialForeground() const
       
   867     {
       
   868     return iAknFlags[EPartialForeground];
       
   869     }
       
   870 
       
   871 EXPORT_C void CAknAppUiBase::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
       
   872 /** Handles an application-specific event. 
       
   873 
       
   874 
       
   875 @param aType The type of the event that occurred. This should be a unique 
       
   876 identifier constant. 
       
   877 @param aEvent The window server event that occurred. 
       
   878 @see CCoeAppUi */
       
   879     {
       
   880     if (aType == KEikPartialForeground)
       
   881         {
       
   882         iAknFlags.Set(EPartialForeground);
       
   883         iAknFlags.Clear(EContainerWasPartialForeground);       // no longer need this flag
       
   884         HandleResourceChangeL(KEikPartialForeground);
       
   885         CAknSgcClient::HandleChangeL();
       
   886         }
       
   887     else if (aType == KEikClearPartialForegroundState)
       
   888         {
       
   889         iAknFlags.Clear(EPartialForeground);
       
   890         CAknSgcClient::HandleChangeL();
       
   891         }
       
   892     else if (aType == KEikDynamicLayoutVariantSwitch ||
       
   893         aType == KEikInputLanguageChange ||
       
   894         aType == KAknHardwareLayoutSwitch ||
       
   895         aType == KAknLocalZoomLayoutSwitch ||
       
   896         aType == KAknILDInstallationLayoutSwitch)
       
   897         {
       
   898         UpdateSettingCacheAndForwardEventL( aType );
       
   899         // Update application rect
       
   900         iAppUiBaseExtension->iApplicationRect = iCoeEnv->ScreenDevice()->SizeInPixels();       
       
   901         }
       
   902     else if ( aType == KEikHasBecomeCurrentAppUiWhileEmbeddedAppUiDeletes )
       
   903         {
       
   904         TBool thisWasForeground = IsForeground();
       
   905         TRAPD(ignore, CAknEnv::Static()->LoadAknLayoutL());
       
   906         TRAP(ignore,HandleResourceChangeL(KEikMessageEmbedLevelChange));
       
   907         HandleStackedControlsResourceChange(KEikMessageEmbedLevelChange);
       
   908         TRAP(ignore, SimulateWsEventL(
       
   909             EventForForegroundState(
       
   910             IsPartialForeground() || iAknFlags[EContainerWasPartialForeground], 
       
   911             thisWasForeground || (iAknFlags[EContainerWasForeground] ) 
       
   912             ) ) );
       
   913         }
       
   914     else if ( aType == KEikNotifyPreCreateEmbeddedL  )
       
   915         {
       
   916         iAknFlags.Assign(EContainerWasForeground, ThreadIsForeground());
       
   917         iAknFlags.Assign(EContainerWasPartialForeground, 
       
   918         static_cast<CAknAppUiBase*>(iContainerAppUi)->IsPartialForeground() );
       
   919         static_cast<CAknAppUiBase*>(iContainerAppUi)->SimulateWsEventL(EEventFocusLost); // TSOI-56GJ6M
       
   920         }
       
   921     else if ( aType == KEikNotifyPostCreateEmbeddedL  )
       
   922         {
       
   923         TWsEvent focusEvent;
       
   924         focusEvent.SetType(EventForForegroundState(iAknFlags[EContainerWasPartialForeground], iAknFlags[EContainerWasForeground]));
       
   925         iEikonEnv->WsSession().SendEventToWindowGroup(iEikonEnv->RootWin().Identifier(), focusEvent);
       
   926         }
       
   927     else if ( aType == KEikPostCoeAppUiConstructL  )
       
   928         {
       
   929         ApplyLayoutChangeL(EFalse);
       
   930         iAppUiBaseExtension->iApplicationRect = iCoeEnv->ScreenDevice()->SizeInPixels();
       
   931         }
       
   932     else if ( aType == KAknShutOrHideApp )
       
   933         {
       
   934         CAknEnv::ShutOrHideAppL();
       
   935         }
       
   936     else
       
   937         {
       
   938         CEikAppUi::HandleApplicationSpecificEventL( aType, aEvent);
       
   939         }
       
   940     }
       
   941 
       
   942 EXPORT_C void CAknAppUiBase::HandleScreenDeviceChangedL()
       
   943     {
       
   944     // By-pass CEikAppUi's call (It would do too-early status pane reload)
       
   945     CCoeAppUi::HandleScreenDeviceChangedL();
       
   946     UpdateSettingCacheAndForwardEventL(KAknHardwareLayoutSwitch);
       
   947     iAppUiBaseExtension->iApplicationRect = iCoeEnv->ScreenDevice()->SizeInPixels();
       
   948     }
       
   949 
       
   950 EXPORT_C void CAknAppUiBase::HandleResourceChangeL(TInt aType)
       
   951     {
       
   952     if (aType == KEikDynamicLayoutVariantSwitch)
       
   953         {
       
   954         // update application rect.
       
   955         iAppUiBaseExtension->iApplicationRect = iCoeEnv->ScreenDevice()->SizeInPixels();
       
   956 
       
   957         // Tactile feedback needs to be informed about new layout, 
       
   958         // because pen support may have been changed.   
       
   959         if ( iAppUiBaseExtension->iFeedbackAdaptation )
       
   960             {
       
   961             iAppUiBaseExtension->iFeedbackAdaptation->LayoutChanged();            
       
   962             }
       
   963         }
       
   964     CEikAppUi::HandleResourceChangeL( aType );
       
   965     }
       
   966     
       
   967 EXPORT_C TRect CAknAppUiBase::ApplicationRect() const
       
   968     {
       
   969     TRect rect(iAppUiBaseExtension->iApplicationRect);
       
   970     return rect;        
       
   971     }
       
   972     
       
   973 EXPORT_C void CAknAppUiBase::PrepareToExit()
       
   974 /** Performs pre-exit processing to ensure the application will exit cleanly. */
       
   975     {
       
   976     iAknFlags.Assign(EAppClosing, ETrue);   
       
   977     CEikAppUi::PrepareToExit();
       
   978 
       
   979     // If this app is dying while in partial foreground, get app beneath to activate its view
       
   980 /*  if (IsPartialForeground())
       
   981     {
       
   982         TInt nextWgId = KErrNotFound;
       
   983         TRAP_IGNORE(nextWgId = FindAppWgIdBelowMeL());
       
   984         if (nextWgId != KErrNotFound)
       
   985             {
       
   986             TWsEvent event;
       
   987             event.SetType(EEventUser);
       
   988             *(TApaSystemEvent*)(event.EventData())=EApaSystemEventBroughtToForeground;
       
   989             event.SetTimeNow();
       
   990             iEikonEnv->WsSession().SendEventToWindowGroup(nextWgId, event);
       
   991             }
       
   992         }
       
   993 */  }
       
   994 
       
   995 TBool CAknAppUiBase::IsAppClosing() const
       
   996     {
       
   997     return iAknFlags[EAppClosing];
       
   998     }
       
   999 
       
  1000 
       
  1001 void CAknAppUiBase::UpdateSettingCacheAndForwardEventL( TInt aEventId )
       
  1002     {
       
  1003     CAknEnv* env = iAvkonEnv;
       
  1004     CAknSettingCache& cache = env->SettingCache();
       
  1005     TBool changed = cache.Update( aEventId );
       
  1006 
       
  1007     if ( changed || AlwaysForwardEvent(aEventId) )
       
  1008         {
       
  1009         TBool reportEvent = ETrue;
       
  1010         TInt originalEventId = aEventId;
       
  1011         if (originalEventId == KAknHardwareLayoutSwitch || 
       
  1012             originalEventId == KAknLocalZoomLayoutSwitch ||
       
  1013             originalEventId == KAknILDInstallationLayoutSwitch)
       
  1014             {
       
  1015             aEventId = KEikDynamicLayoutVariantSwitch; // all layout changes are sent to apps as KEikDynamicLayoutVariantSwitch
       
  1016             }
       
  1017             
       
  1018         if (aEventId == KEikDynamicLayoutVariantSwitch)
       
  1019             {
       
  1020             RelinquishPriorityToForegroundAppLC();
       
  1021             if(originalEventId == KAknILDInstallationLayoutSwitch)
       
  1022                 {
       
  1023                 // always reload the current layout configuration, as we are expecting
       
  1024                 // a change in the actual layout pack instances that will be loaded, 
       
  1025                 // and always report the event to all app uis
       
  1026                 env->ReloadAknLayoutL();
       
  1027                 }
       
  1028             else
       
  1029                 {
       
  1030                 reportEvent = env->LoadAknLayoutL();
       
  1031                 }
       
  1032             }
       
  1033         
       
  1034         if (reportEvent)
       
  1035             {
       
  1036             // report resource changed to all app uis
       
  1037             for ( CEikAppUi* appUi = iEikonEnv->EikAppUi();
       
  1038                   appUi;
       
  1039                   appUi = appUi->ContainerAppUi() )
       
  1040                 {
       
  1041                 appUi->ReportResourceChangedToAppL( aEventId );
       
  1042                 }
       
  1043             }
       
  1044 
       
  1045 
       
  1046         // Unblank screen if screen blanking is done at KEikDynamicLayoutVariantSwitch at aknglobaui side.
       
  1047         if (IsForeground() && aEventId == KEikDynamicLayoutVariantSwitch)
       
  1048              {
       
  1049              RAknUiServer* client = CAknSgcClient::AknSrv();
       
  1050              if (client && client->Handle())
       
  1051                 client->UnblankScreen();
       
  1052              }
       
  1053 
       
  1054         if (aEventId == KEikDynamicLayoutVariantSwitch)
       
  1055             {
       
  1056             CleanupStack::PopAndDestroy(); // RelinquishPriorityToForegroundAppLC
       
  1057             }
       
  1058         }
       
  1059     }
       
  1060 
       
  1061 void CAknAppUiBase::RelinquishPriorityToForegroundAppLC()
       
  1062     {
       
  1063     CAknSgcClient::RelinquishPriorityToForegroundAppLC(iAknFlags[EForegroundOrPartialForeground] || IsForeground());
       
  1064     }
       
  1065 
       
  1066 TBool CAknAppUiBase::AlwaysForwardEvent( TInt aEventId )
       
  1067     {
       
  1068     switch(aEventId)
       
  1069         {
       
  1070         case KAknILDInstallationLayoutSwitch:
       
  1071             // - If an ILD layout has been installed, then all application layouts 
       
  1072             //  must be updated
       
  1073             return ETrue;
       
  1074         case KAknHardwareLayoutSwitch:
       
  1075         case KEikDynamicLayoutVariantSwitch:
       
  1076             // - For non-full screen apps, they need to follow the foreground
       
  1077             //  application's orientation. 
       
  1078             return !IsFullScreenApp(); 
       
  1079         default:
       
  1080             return EFalse;
       
  1081         };
       
  1082     }
       
  1083 
       
  1084 EXPORT_C CAknAppUiBase::TAppUiOrientation CAknAppUiBase::Orientation() const
       
  1085     {
       
  1086     CAknAppUiBase::TAppUiOrientation orientation = EAppUiOrientationUnspecified;
       
  1087     if (!iAknFlags[EOrientationSpecified])
       
  1088         {
       
  1089         if (iAppUiBaseExtension->iDefaultRotation >= 0 && iAppUiBaseExtension->iDefaultRotation <= 2)
       
  1090             {
       
  1091             // Product specific orientation configuration for applications that do not
       
  1092             // set any orientation flag is done here.
       
  1093             //
       
  1094             // Return value:                 orientation
       
  1095             // EAppUiOrientationUnspecified: Follows device orientation.
       
  1096             // EAppUiOrientationPortrait:    Applications runs in portrait mode
       
  1097             // EAppUiOrientationLandscape:   Applications runs in landscape mode
       
  1098             orientation = (CAknAppUiBase::TAppUiOrientation)iAppUiBaseExtension->iDefaultRotation;
       
  1099             }        
       
  1100         }
       
  1101     else if (iAknFlags[EOrientationAutomatic])
       
  1102         orientation = EAppUiOrientationUnspecified;
       
  1103     else if (iAknFlags[EOrientationLandscape])
       
  1104         orientation = EAppUiOrientationLandscape;
       
  1105     else
       
  1106         orientation = EAppUiOrientationPortrait;
       
  1107 
       
  1108     return orientation;
       
  1109     }
       
  1110 
       
  1111 EXPORT_C TBool CAknAppUiBase::OrientationCanBeChanged() const
       
  1112     {
       
  1113     // parameters affecting ability to set mode
       
  1114     TBool isFullScreen = IsFullScreenApp();
       
  1115     TInt fixedMode = iAppUiBaseExtension ? iAppUiBaseExtension->iScreenMode : KAknScreenModeUnset;
       
  1116 
       
  1117     // Get portrait and landscape screen modes
       
  1118     CAknLayoutConfig::TScreenMode portraitMode = 
       
  1119         CAknSgcClient::CalculateScreenMode(isFullScreen, ETrue, EFalse, fixedMode);
       
  1120             
       
  1121     CAknLayoutConfig::TScreenMode landscapeMode = 
       
  1122         CAknSgcClient::CalculateScreenMode(isFullScreen, ETrue, ETrue, fixedMode);
       
  1123     
       
  1124     // are the portrait and landscape modes different?
       
  1125     return portraitMode.ModeNumber() != landscapeMode.ModeNumber();
       
  1126     }
       
  1127 
       
  1128 EXPORT_C void CAknAppUiBase::SetOrientationL(TAppUiOrientation aOrientation)
       
  1129     {
       
  1130     if (aOrientation != Orientation())
       
  1131         {
       
  1132         iAknFlags.Assign(EOrientationSpecified, aOrientation != EAppUiOrientationUnspecified);
       
  1133         iAknFlags.Assign(EOrientationLandscape, aOrientation == EAppUiOrientationLandscape);
       
  1134         iAknFlags.Assign(EOrientationAutomatic, aOrientation == EAppUiOrientationAutomatic);
       
  1135         ApplyLayoutChangeL(ETrue);
       
  1136         if(IsForeground())
       
  1137             {
       
  1138             RAknUiServer* client = CAknSgcClient::AknSrv();
       
  1139             if (client && client->Handle())
       
  1140                 {
       
  1141                 client->UnblankScreen();
       
  1142                 }
       
  1143             }
       
  1144         }
       
  1145     }
       
  1146 
       
  1147 TBool CAknAppUiBase::ThreadIsForeground() const
       
  1148     {
       
  1149     RWsSession& ws = iEikonEnv->WsSession();
       
  1150     TThreadId focusThreadId;
       
  1151     ws.GetWindowGroupClientThreadId(ws.GetFocusWindowGroup(), focusThreadId);
       
  1152     RThread myThread;
       
  1153     return myThread.Id() == focusThreadId;
       
  1154     }
       
  1155 
       
  1156 
       
  1157 // deprecated
       
  1158 TInt CAknAppUiBase::FindAppWgIdBelowMeL()
       
  1159     {
       
  1160 /*    RWsSession& wsSession=iEikonEnv->WsSession();
       
  1161     TInt count=wsSession.NumWindowGroups(0);
       
  1162     CArrayFixFlat<TInt>* wgIds = new (ELeave) CArrayFixFlat<TInt>(count);
       
  1163     CleanupStack::PushL(wgIds);
       
  1164     User::LeaveIfError(wsSession.WindowGroupList(0,wgIds));
       
  1165     count = wgIds->Count();
       
  1166     TInt nextWgId = KErrNotFound;
       
  1167     TThreadId nextThreadId;
       
  1168     TInt myWgId = iEikonEnv->RootWin().Identifier();
       
  1169     TThreadId myThreadId;
       
  1170     wsSession.GetWindowGroupClientThreadId(myWgId, myThreadId);
       
  1171     for (TInt ii=count-1; ii>=0; ii--)
       
  1172         {
       
  1173         TInt wgId = wgIds->At(ii);
       
  1174         if (wgId == myWgId)
       
  1175             break;
       
  1176         // only record window groups if they belong to a different thread - prevents sending an event back to this thread
       
  1177         wsSession.GetWindowGroupClientThreadId(wgId, nextThreadId);
       
  1178         if (nextThreadId != myThreadId)
       
  1179             {
       
  1180             CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(wsSession, wgId);
       
  1181             if (wgName->IsAppReady())
       
  1182                 nextWgId = wgId;
       
  1183             CleanupStack::PopAndDestroy();
       
  1184             }
       
  1185         }
       
  1186     CleanupStack::PopAndDestroy(wgIds);
       
  1187 */
       
  1188     return KErrNotSupported; //nextWgId;
       
  1189     }
       
  1190 
       
  1191 /**
       
  1192  * Simulate a foreground event by passing it straight into HandleWsEventL. 
       
  1193  * Used for telling embedding app to lose the foreground, part of fix for TSOI-56GJ6M 
       
  1194  *
       
  1195  * @param aForeground if EFalse, send to background, otherwise send to foreground
       
  1196  *
       
  1197  */
       
  1198 void CAknAppUiBase::SimulateWsEventL(TInt aEventId)
       
  1199     {
       
  1200     TWsEvent event;
       
  1201     event.SetType(aEventId);
       
  1202     event.SetHandle(0);
       
  1203     HandleWsEventL(event, NULL);
       
  1204     }
       
  1205 
       
  1206 TInt CAknAppUiBase::EventForForegroundState(TBool aPartialFg, TBool aForeground)
       
  1207     {
       
  1208     if (aPartialFg)
       
  1209         return KEikPartialForeground;
       
  1210     else if (aForeground)
       
  1211         return EEventFocusGained;
       
  1212     else
       
  1213         return EEventFocusLost;
       
  1214     }
       
  1215 
       
  1216 EXPORT_C void CAknAppUiBase::Exit()
       
  1217 /** Closes the app UI. */
       
  1218     {
       
  1219     // Exit() leaves. The app UI is deleted during exit, and processing must stop immediately.
       
  1220     if (iContainerAppUi)
       
  1221         {
       
  1222         delete this;
       
  1223         User::Leave(KLeaveWithoutAlert);    // stop this event here!
       
  1224         }
       
  1225     else
       
  1226         {
       
  1227         // default reason for exiting is EEikCmdExit. If server exists,
       
  1228         // clients must be told. Other exit reasons should be notified
       
  1229         // before they call Exit().
       
  1230         CEikAppServer* server = iEikonEnv->AppServer();
       
  1231         if (server)
       
  1232             server->NotifyServerExit(EEikCmdExit);
       
  1233         
       
  1234         CBaActiveScheduler::Exit();
       
  1235         }
       
  1236     }
       
  1237 
       
  1238 EXPORT_C void CAknAppUiBase::SetFadedL(TBool aFaded)
       
  1239     {
       
  1240     const TInt message=(aFaded? KEikMessageFadeAllWindows : KEikMessageUnfadeWindows);
       
  1241     TRAPD(ignore, ReportResourceChangedToAppL(message));
       
  1242     if (IsForeground())
       
  1243        CAknSgcClient::SetSystemFaded(aFaded);
       
  1244     TRAP(ignore, ReportResourceChangedToAppL(KEikMessageWindowsFadeChange));
       
  1245     }
       
  1246 
       
  1247 EXPORT_C TAknUiZoom CAknAppUiBase::LocalUiZoom() const
       
  1248     {
       
  1249     CAknEnv* env = iAvkonEnv;
       
  1250     TInt value = EAknUiZoomAutomatic;
       
  1251     CAknSettingCache& cache = env->SettingCache();
       
  1252     // get the value from the top plugin
       
  1253     TInt err = cache.PluginValue(KAknLocalZoomLayoutSwitch, value);
       
  1254     // if there are no plugins, just use the real local value
       
  1255     if(err != KErrNone && iAppUiBaseExtension)
       
  1256         {
       
  1257         value = iAppUiBaseExtension->iLocalUiZoom;
       
  1258         }
       
  1259     return static_cast<TAknUiZoom>(value);
       
  1260     }
       
  1261 
       
  1262 EXPORT_C void CAknAppUiBase::SetLocalUiZoom(TAknUiZoom aZoom)
       
  1263     {
       
  1264     TInt err = KErrNone;
       
  1265     if(!iAppUiBaseExtension)
       
  1266         {
       
  1267         // we must have been called by application before their call to BaseConstructL
       
  1268         // therefore we need to create the extension.
       
  1269         // if it leaves, BaseConstructL will try to construct the extension again, 
       
  1270         // and the side effect will be that normal zoom level is incorrectly used.
       
  1271         TRAP(err, iAppUiBaseExtension = new(ELeave) CAknAppUiBaseExtension());
       
  1272         }
       
  1273     if(!err)
       
  1274         {
       
  1275         iAppUiBaseExtension->iLocalUiZoom = aZoom;
       
  1276         }
       
  1277     }
       
  1278 
       
  1279 EXPORT_C void CAknAppUiBase::ApplyLayoutChangeL(TBool aReportChange)
       
  1280     {
       
  1281     CAknSgcClient::HandleChangeL();
       
  1282     if (iAvkonEnv->LoadAknLayoutL())
       
  1283         {
       
  1284         if(aReportChange)
       
  1285             {
       
  1286             ReportResourceChangedToAppL(KEikDynamicLayoutVariantSwitch);
       
  1287             }
       
  1288         }
       
  1289     }
       
  1290 
       
  1291 TBool CAknAppUiBase::HasFullOrPartialForeground() const
       
  1292     {
       
  1293     return iAknFlags[EForegroundOrPartialForeground];
       
  1294     }
       
  1295 
       
  1296 void CAknAppUiBase::SetScreenModeL(TInt aModeNumber)
       
  1297     {
       
  1298     TInt err = KErrNone;
       
  1299     if(!iAppUiBaseExtension)
       
  1300         {
       
  1301         // we must have been called by application before their call to BaseConstructL
       
  1302         // therefore we need to create the extension.
       
  1303         // if it leaves, BaseConstructL will try to construct the extension again, 
       
  1304         // and the side effect will be that the natural screen mode is used.
       
  1305         TRAP(err, iAppUiBaseExtension = new(ELeave) CAknAppUiBaseExtension());
       
  1306         }
       
  1307     if(!err)
       
  1308         {
       
  1309         iAppUiBaseExtension->iScreenMode = aModeNumber;
       
  1310         // use iEventMonitor's existence to check if this is
       
  1311         // fully constructed yet. If so, change the layout.
       
  1312         if (iEventMonitor)
       
  1313             ApplyLayoutChangeL(ETrue);
       
  1314         }
       
  1315     }
       
  1316 
       
  1317 TInt CAknAppUiBase::ScreenMode() const
       
  1318     {
       
  1319     return iAppUiBaseExtension ?
       
  1320         iAppUiBaseExtension->iScreenMode :
       
  1321         KAknScreenModeUnset;
       
  1322     }
       
  1323 
       
  1324 EXPORT_C void CAknAppUiBase::SetKeyEventFlags( const TInt aFlags )
       
  1325     {
       
  1326     iAppUiBaseExtension->iDiallerLauncher->SetFlags( aFlags );
       
  1327     }
       
  1328 
       
  1329 EXPORT_C CAknPointerEventModifier* CAknAppUiBase::PointerEventModifier()
       
  1330     {
       
  1331     if ( iAppUiBaseExtension )
       
  1332         {
       
  1333         return iAppUiBaseExtension->iPointerEventModifier;
       
  1334         }
       
  1335         
       
  1336     return NULL;
       
  1337     }
       
  1338 
       
  1339 EXPORT_C TBool CAknAppUiBase::IsTouchCompatible() const
       
  1340     {
       
  1341     return iAknFlags.IsSet( ETouchCompatible );
       
  1342     }
       
  1343 
       
  1344 
       
  1345 EXPORT_C TBool CAknAppUiBase::IsSingleClickCompatible() const
       
  1346     {
       
  1347     return iAknFlags.IsSet( ESingleClickCompatible )
       
  1348         && AknLayoutUtils::PenEnabled();
       
  1349     }
       
  1350 
       
  1351 
       
  1352 //===============
       
  1353 // class CAknAppUi 
       
  1354 //===============
       
  1355 
       
  1356 void CAknAppUi::DecideWsClientBufferSizesL()
       
  1357     {
       
  1358     RWsSession &ws = iEikonEnv->WsSession();
       
  1359     ws.SetMaxBufferSizeL(KAknDefaultWsBufferSize);
       
  1360     }
       
  1361 
       
  1362 EXPORT_C void CAknAppUi::ConstructL()
       
  1363     {
       
  1364     // Should implement to catch those who do not implement MyApp::ConstructL()
       
  1365     // Or ASSERT?
       
  1366     CAknAppUi::BaseConstructL();
       
  1367     }
       
  1368 
       
  1369 EXPORT_C void CAknAppUi::BaseConstructL(TInt aAppUiFlags)
       
  1370     {
       
  1371     // Initialize AppUi-specific skin parameters and skin support
       
  1372     // Trap errors and leave after BaseConstructL() if any.
       
  1373     TInt skinParamErr = KErrNone;
       
  1374     if( (aAppUiFlags&EAknEnableSkinFlag) != 0 )
       
  1375         {
       
  1376         TRAP( skinParamErr, AknsUtils::SetAvkonSkinEnabledL( ETrue ) );
       
  1377         }
       
  1378     TRAPD( skinErr, AknsUtils::InitSkinSupportL() );
       
  1379     TRAPD( allocErr, DecideWsClientBufferSizesL() );
       
  1380     // No leaving function calls before BaseConstructL().
       
  1381     CAknAppUiBase::BaseConstructL(aAppUiFlags);
       
  1382 
       
  1383     User::LeaveIfError( allocErr );
       
  1384     User::LeaveIfError( skinParamErr );
       
  1385     User::LeaveIfError( skinErr );
       
  1386 
       
  1387     // Ensures that embedded applications get the right parameter
       
  1388     if( (aAppUiFlags&EAknEnableSkinFlag) != 0 )
       
  1389         {
       
  1390         AknsUtils::SetAvkonSkinEnabledL( ETrue );
       
  1391         }
       
  1392 
       
  1393     if( (aAppUiFlags & EAknDisableHighlightAnimationFlag) != 0 )
       
  1394         {
       
  1395         AknsUtils::SetAvkonHighlightAnimationEnabledL( EFalse );
       
  1396         }
       
  1397 
       
  1398 #ifdef RD_SCALABLE_UI_V2
       
  1399     if ( CAknTouchPane* tp = TouchPane() )
       
  1400         {
       
  1401         tp->SetObserver( this );
       
  1402         if ( EventMonitor() )
       
  1403             {
       
  1404             EventMonitor()->AddObserverL( tp );
       
  1405             EventMonitor()->Enable();
       
  1406             }
       
  1407         }
       
  1408 #endif
       
  1409 
       
  1410     if (StatusPane())
       
  1411         StatusPane()->SetObserver(this);
       
  1412 
       
  1413     TInt uid = KErrNotFound;
       
  1414     if (Application())
       
  1415         {
       
  1416         // Only assign uid if an application is present
       
  1417         // This is true for all Avkon apps, but not for Java MIDP
       
  1418         uid = Application()->AppDllUid().iUid;
       
  1419         }
       
  1420 
       
  1421     ReplaceKeySoundsL(uid);
       
  1422 
       
  1423     AddViewDeactivationObserverL(this);
       
  1424 
       
  1425     iAppShutter = CAknAppShutter::NewL(*iEikonEnv, this, &iAppShutter);
       
  1426     if(!iExtension)
       
  1427         {
       
  1428         iExtension = CAknAppUiExtension::NewL();
       
  1429         }
       
  1430         
       
  1431     AddViewActivationObserverL(iExtension);
       
  1432         
       
  1433     if (ExitHidesInBackground())
       
  1434         {
       
  1435         TBool isBackground = !IsForeground();
       
  1436         HideApplicationFromFSW(isBackground);
       
  1437         iExtension->iFlags.Assign(CAknAppUiExtension::EAppIsHiddenInBackground, isBackground);
       
  1438         }
       
  1439     }
       
  1440 
       
  1441 EXPORT_C void CAknAppUi::HandleTouchPaneSizeChange()
       
  1442     {    
       
  1443     }
       
  1444 
       
  1445 EXPORT_C void CAknAppUi::HandleStatusPaneSizeChange()
       
  1446     {
       
  1447     }
       
  1448 
       
  1449 EXPORT_C CAknAppUi::~CAknAppUi()
       
  1450     {
       
  1451     if (iExtension)
       
  1452         {
       
  1453         RemoveViewActivationObserver(iExtension);
       
  1454         }
       
  1455 
       
  1456     delete iExtension;
       
  1457     // embedded apps need to let the shutter live till long enough to handle the app exit leave
       
  1458     if (iAppShutter)
       
  1459         iAppShutter->DeleteSelfWhenReady();
       
  1460 
       
  1461     RemoveViewDeactivationObserver(this);
       
  1462 
       
  1463     // Delete skin parameter singleton (if one exists)
       
  1464     delete CCoeEnv::Static( KAknsAppUiParametersTls );
       
  1465     }
       
  1466 
       
  1467 EXPORT_C CEikStatusPane* CAknAppUi::StatusPane()
       
  1468     {
       
  1469     return iEikonEnv->AppUiFactory()->StatusPane();
       
  1470     }
       
  1471 
       
  1472 EXPORT_C void CAknAppUi::ProcessCommandL(TInt aCommand)
       
  1473     {
       
  1474     MEikAppUiFactory* appUiFactory = (iEikonEnv)->AppUiFactory();
       
  1475     ASSERT(appUiFactory);
       
  1476     if (appUiFactory->Popup())
       
  1477         ClosePopup();
       
  1478     else if (appUiFactory->MenuBar())
       
  1479         StopDisplayingMenuBar();
       
  1480     // Test for 'options' command
       
  1481     if (aCommand == EAknSoftkeyOptions)
       
  1482         {
       
  1483         appUiFactory->MenuBar()->TryDisplayMenuBarL();
       
  1484         return;
       
  1485         }
       
  1486     if (aCommand == EAknSoftkeyContextOptions)
       
  1487         {
       
  1488         appUiFactory->MenuBar()->TryDisplayContextMenuBarL();
       
  1489         return;
       
  1490         }
       
  1491     if (aCommand == EAknCmdExit)
       
  1492         {
       
  1493         StopDisplayingPopupToolbar();
       
  1494         CAknEnv::RunAppShutter();
       
  1495         return;
       
  1496         }
       
  1497     if ( aCommand != EEikCmdCanceled )
       
  1498         HandleCommandL(aCommand);
       
  1499     }
       
  1500 
       
  1501 EXPORT_C CEikButtonGroupContainer* CAknAppUi::Cba()
       
  1502     {
       
  1503     return iEikonEnv->AppUiFactory()->ToolBar();
       
  1504     }
       
  1505 
       
  1506 EXPORT_C void CAknAppUi::HandleErrorL(TInt aError, HBufC** aErrorDesc, TBool aShowNote )
       
  1507     {
       
  1508     // Lets Create TextResolver instance for error resolving
       
  1509     CTextResolver* textresolver = CTextResolver::NewLC(); 
       
  1510 
       
  1511     TUint flags( 0 ); 
       
  1512     TInt id( 0 );
       
  1513 
       
  1514     // Resolve the Error
       
  1515 //    TBuf<KErrorResolverMaxTextLength> errorstring = 
       
  1516     if (!aErrorDesc)
       
  1517         User::Leave(KErrNotSupported);
       
  1518     
       
  1519     // This is nasty, we alloc memory for error handling -> KErrNoMemory might fail
       
  1520     // Anyway, it will be handled in eikon env, so we can allow this fail
       
  1521     *aErrorDesc  = 
       
  1522         textresolver->ResolveErrorString( aError, id, flags, CTextResolver::ECtxNoCtx ).AllocL();
       
  1523 
       
  1524     if ( flags & EErrorResOOMFlag || (*aErrorDesc)->Length() == 0 )
       
  1525         {
       
  1526         User::Leave(KErrNoMemory); // let EikEnv preallocated error handling take care of showing note.
       
  1527         }
       
  1528 
       
  1529     if ( !(flags & ETextResolverBlankErrorFlag) )
       
  1530         {
       
  1531         // There is no need create Note before we know that error will displayed i.e. is not blank
       
  1532         CAknGlobalNote* note = 0;        
       
  1533 
       
  1534         if (aShowNote)
       
  1535             {
       
  1536             note = CAknGlobalNote::NewL();
       
  1537             CleanupStack::PushL( note );                                                         
       
  1538             }
       
  1539 
       
  1540         TText contextChar = ((*aErrorDesc)->Des())[0]; // this is a colon
       
  1541 
       
  1542         // remove context character and line end character
       
  1543         (*aErrorDesc)->Des().Delete( 0, 2 );
       
  1544 
       
  1545         // Solving the application name asing AppArc.lib
       
  1546         RApaLsSession apparcSession;
       
  1547         User::LeaveIfError( apparcSession.Connect() );
       
  1548         CleanupClosePushL( apparcSession );
       
  1549         TApaAppInfo appInfo;
       
  1550         TInt err = apparcSession.GetAppInfo( appInfo, this->Application()->AppDllUid() );
       
  1551         
       
  1552         // +2 for colon and line end
       
  1553         HBufC* captionBuffer = 
       
  1554             HBufC::NewLC( KApaMaxAppCaption + KAknBidiExtraSpacePerLine + 2 ); 
       
  1555 
       
  1556 //        CleanupStack::PushL( captionBuffer );
       
  1557         TPtr caption = captionBuffer->Des();
       
  1558 
       
  1559         if ( err == KErrNone )
       
  1560             {
       
  1561             caption = appInfo.iCaption;
       
  1562             }
       
  1563 
       
  1564         // Lets remove trailing spaces
       
  1565         caption.TrimRight();
       
  1566         
       
  1567         // Insert the application name into the beginning of the error string
       
  1568         if ( caption.Length() != 0 ) 
       
  1569             {
       
  1570             HBufC* result = HBufC::NewLC((*aErrorDesc)->Des().MaxLength() + 5 * (KAknBidiExtraSpacePerLine + 1)); // wasting more memory ...
       
  1571 
       
  1572             CArrayFix<TInt>* lineWidthArray =
       
  1573                 new( ELeave ) CArrayFixFlat<TInt>( 4 );
       
  1574 
       
  1575             CleanupStack::PushL( lineWidthArray );
       
  1576             
       
  1577             TRect mainPane;
       
  1578             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EPopupParent, mainPane );
       
  1579             
       
  1580             const TInt lineVariety( 2 ); // Equals 5 lines, which adapt. layer uses here.
       
  1581             
       
  1582             AknLayoutUtils::TAknCbaLocation cbaLocation( AknLayoutUtils::CbaLocation() );
       
  1583             TInt softkeyVariety( lineVariety ); // Defaults to bottom cbalocation value
       
  1584     
       
  1585             // Modify the softkeyVariety in case cba is at either side
       
  1586             if ( cbaLocation == AknLayoutUtils::EAknCbaLocationRight )
       
  1587                 {
       
  1588                 softkeyVariety += 3;
       
  1589                 }
       
  1590             else if ( cbaLocation == AknLayoutUtils::EAknCbaLocationLeft )
       
  1591                 {
       
  1592                 softkeyVariety += 6;
       
  1593                 }           
       
  1594             
       
  1595             TAknLayoutRect popupLayoutRect;
       
  1596             popupLayoutRect.LayoutRect( mainPane,
       
  1597                 AknLayoutScalable_Avkon::popup_note_window( softkeyVariety ) );
       
  1598             
       
  1599             TRect popupRect = popupLayoutRect.Rect();
       
  1600             
       
  1601             TAknLayoutText firstLineLayoutText;
       
  1602             firstLineLayoutText.LayoutText( popupRect,
       
  1603                 AknLayoutScalable_Avkon::popup_note_window_t1( lineVariety ) );
       
  1604 
       
  1605             const CFont* font = firstLineLayoutText.Font();
       
  1606             
       
  1607             TAknLayoutText textRect;
       
  1608             TAknTextComponentLayout textLayout;
       
  1609             
       
  1610             for ( TInt i = 1; i <= 4; ++i )
       
  1611                 {
       
  1612                 textLayout = AknLayoutScalable_Avkon::popup_note_window_t( i, lineVariety );
       
  1613                 textRect.LayoutText( popupRect, textLayout.LayoutLine() );
       
  1614                 lineWidthArray->AppendL( textRect.TextRect().Width() );
       
  1615                 }
       
  1616 
       
  1617             TPtr ptr = result->Des();
       
  1618 
       
  1619             // convert error string to visual order
       
  1620             AknBidiTextUtils::ConvertToVisualAndWrapToStringL(
       
  1621                 (*aErrorDesc)->Des(),
       
  1622                 *lineWidthArray,
       
  1623                 *font,
       
  1624                 ptr,
       
  1625                 ETrue ); // insert truncation char if doesn't fit
       
  1626 
       
  1627             CleanupStack::PopAndDestroy(); // lineWidthArray
       
  1628 
       
  1629             // in visual order now
       
  1630             CleanupStack::Pop(); // result
       
  1631             delete *aErrorDesc;
       
  1632             *aErrorDesc = result; // ownership to caller
       
  1633 
       
  1634             // add the caption
       
  1635 
       
  1636             TInt captionLength = firstLineLayoutText.TextRect().Width() - 
       
  1637                 font->CharWidthInPixels( contextChar );
       
  1638 
       
  1639             // Here we truncate the application name to fit in the first row of the note
       
  1640             AknBidiTextUtils::ConvertToVisualAndClipL(
       
  1641                 caption,
       
  1642                 *font,
       
  1643                 captionLength,
       
  1644                 captionLength );
       
  1645 
       
  1646             TBuf<1> buf;
       
  1647             buf.Append( contextChar );
       
  1648 
       
  1649             // in mirrored layout, ':' is the leftmost character
       
  1650             if ( AknLayoutUtils::LayoutMirrored() )
       
  1651                 {
       
  1652                 caption.Insert( 0, buf );
       
  1653                 }
       
  1654             // in non-mirrored layout, ':' is the rightmost character
       
  1655             else
       
  1656                 {
       
  1657                 caption.Append( buf );
       
  1658                 }
       
  1659 
       
  1660             caption.Append( '\n' );
       
  1661 
       
  1662             // Insert caption row, in visual order.
       
  1663             // The line end after it exists in string already.
       
  1664             (*aErrorDesc)->Des().Insert( 0, caption );
       
  1665             }
       
  1666         if ( note )
       
  1667             {
       
  1668             if ( aError == KErrDiskFull ) 
       
  1669                 {
       
  1670                 note->SetSoftkeys(R_AVKON_SOFTKEYS_OK_EMPTY__OK);
       
  1671                 }
       
  1672 
       
  1673             // If there was a caption, we processed the text ourselves
       
  1674             if ( caption.Length() )
       
  1675                 {
       
  1676                 note->SetTextProcessing( EFalse );
       
  1677                 }
       
  1678 
       
  1679 
       
  1680             // secondary display needs to be informed about the error note
       
  1681             SAknIntegerUpdate s = 
       
  1682                 {
       
  1683                 EAknTrappedError,
       
  1684                 aError 
       
  1685                 };
       
  1686             TPckg<SAknIntegerUpdate> pck(s);
       
  1687             CAknSDData* sdData = CAknSDData::NewL( KAknSecondaryDisplayCategory, EAknErrorNote, pck );
       
  1688             note->SetSecondaryDisplayData( sdData );
       
  1689                 
       
  1690             // Finally, let's show the global note
       
  1691             note->ShowNoteL( EAknGlobalErrorNote, (*aErrorDesc)->Des() ); 
       
  1692 
       
  1693             CleanupStack::PopAndDestroy( 3 ); // note, apparcSession, captionBuffer
       
  1694             }
       
  1695         else
       
  1696             {
       
  1697             CleanupStack::PopAndDestroy( 2 ); // apparcSession, captionBuffer
       
  1698             }
       
  1699         }
       
  1700     else 
       
  1701         { 
       
  1702         (*aErrorDesc)->Des().Zero(); // make text lenght 0 if error is blank
       
  1703         }
       
  1704 
       
  1705     CleanupStack::PopAndDestroy(); // error resolver
       
  1706     }
       
  1707 
       
  1708 EXPORT_C TErrorHandlerResponse CAknAppUi::HandleError(TInt aError, 
       
  1709                                                       const SExtendedError& /*aExtErr*/,  
       
  1710                                                       TDes& /*aErrorText*/, 
       
  1711                                                       TDes& /*aContextText*/ )
       
  1712     {
       
  1713     HBufC* buf = 0;
       
  1714     TRAPD(err, HandleErrorL(aError, &buf));
       
  1715     delete buf;
       
  1716     
       
  1717     if ( !err )
       
  1718         {
       
  1719         return(ENoDisplay); // Error handled proper way.
       
  1720         }
       
  1721     
       
  1722     return(EErrorNotHandled); // Error not handled, let EIKENV handle the error.
       
  1723     }
       
  1724 
       
  1725 EXPORT_C void CAknAppUi::HandleSystemEventL(const TWsEvent& aEvent)
       
  1726     {
       
  1727     switch (*(TApaSystemEvent*)(aEvent.EventData()))
       
  1728         {
       
  1729     case EApaSystemEventShutdown:
       
  1730         if((static_cast<CEikonEnv*>(iCoeEnv)->IsSystem()))
       
  1731             {
       
  1732             break;
       
  1733             }
       
  1734         // else fall-through
       
  1735     case EApaSystemEventSecureShutdown:
       
  1736         StopDisplayingPopupToolbar();
       
  1737         CAknEnv::RunAppShutter();
       
  1738         break;
       
  1739     default:
       
  1740         CEikAppUi::HandleSystemEventL(aEvent);
       
  1741         break;
       
  1742         }
       
  1743     }
       
  1744 
       
  1745 EXPORT_C void CAknAppUi::Reserved_MtsmPosition()
       
  1746     {
       
  1747     }
       
  1748 
       
  1749 EXPORT_C void CAknAppUi::Reserved_MtsmObject()
       
  1750     {
       
  1751     }
       
  1752 
       
  1753 EXPORT_C void CAknAppUi::HandleForegroundEventL(TBool aForeground)
       
  1754     {
       
  1755 #ifdef RD_SCALABLE_UI_V2
       
  1756     TVwsViewId viewId;
       
  1757     TInt err = GetActiveViewId( viewId );
       
  1758     if ( ( err == KErrNotFound || viewId.iAppUid == viewId.iViewUid ) && CurrentFixedToolbar() )
       
  1759         {
       
  1760         CurrentFixedToolbar()->HandleResourceChange( KAknToolbarSetVisible ); 
       
  1761         }
       
  1762 #endif 
       
  1763     if ( KeySounds() && IsForeground() ) // IsForeground() used because aForeground may already be out of date
       
  1764         {
       
  1765         KeySounds()->BringToForeground();
       
  1766         }
       
  1767 
       
  1768 #ifdef RD_SCALABLE_UI_V2
       
  1769     if ( TouchPane() && aForeground )
       
  1770         {
       
  1771         TouchPane()->RefreshL();
       
  1772         }
       
  1773 
       
  1774     if ( !aForeground )
       
  1775         {  
       
  1776         HandleStackedControlsResourceChange(KAknMessageFocusLost);            
       
  1777         }
       
  1778 #endif
       
  1779 
       
  1780     if (aForeground && iExtension->iFlags[CAknAppUiExtension::EAppIsHiddenInBackground])
       
  1781         {
       
  1782         HideApplicationFromFSW(EFalse);
       
  1783         iExtension->iFlags.Clear(CAknAppUiExtension::EAppIsHiddenInBackground);
       
  1784         }
       
  1785         
       
  1786     CEikAppUi::HandleForegroundEventL(aForeground);
       
  1787     }
       
  1788 
       
  1789 EXPORT_C void CAknAppUi::HandleViewDeactivation(const TVwsViewId& /*aViewIdToBeDeactivated*/, const TVwsViewId &/*aNewlyActivatedViewId*/)
       
  1790     {
       
  1791     iAvkonEnv->CloseAllIntermediateStates();
       
  1792     }
       
  1793 
       
  1794 EXPORT_C void CAknAppUi::PrepareToExit()
       
  1795     {
       
  1796     if( IsForeground() && Document() )
       
  1797         {
       
  1798         //only if focused, otherwise next app HandleForeground may never come.
       
  1799         iAvkonEnv->TransitionEvent(AknTransEffect::EApplicationExit, Application()->AppDllUid());
       
  1800         }
       
  1801     else
       
  1802         {
       
  1803         iAvkonEnv->TransitionEvent(AknTransEffect::EApplicationExit);
       
  1804         }
       
  1805         
       
  1806     if ( StatusPane() )
       
  1807         {
       
  1808         StatusPane()->PrepareForAppExit();
       
  1809         }
       
  1810     CAknAppUiBase::PrepareToExit();
       
  1811     }
       
  1812 
       
  1813 EXPORT_C void CAknAppUi::RunAppShutter()
       
  1814     {
       
  1815     if (!iAppShutter)
       
  1816         {
       
  1817         // the app shutter may not exist if a previous shut attempt failed,
       
  1818         // eg because KLeaveExit was trapped, or the app did not call Exit() in response to EEikCmdExit.
       
  1819         TRAP_IGNORE(iAppShutter = CAknAppShutter::NewL(*iEikonEnv, this, &iAppShutter));
       
  1820         }
       
  1821         
       
  1822     if (iAppShutter)
       
  1823         iAppShutter->Start();
       
  1824     }
       
  1825 
       
  1826 EXPORT_C TBool CAknAppUi::IsAppShutterRunning() const
       
  1827     {
       
  1828     return iAppShutter ? iAppShutter->IsActive() : EFalse;
       
  1829     }
       
  1830 
       
  1831 TBool CAknAppUi::IsAppHiddenInBackground() const
       
  1832     {
       
  1833     return iExtension && iExtension->iFlags[CAknAppUiExtension::EAppIsHiddenInBackground];
       
  1834     }
       
  1835 
       
  1836 EXPORT_C void CAknAppUi::HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination)
       
  1837     {
       
  1838     iAvkonEnv->TransitionEvent(KAknTransitionEventAvkon); 
       
  1839     if (EventMonitor() && EventMonitor()->IsEnabled())
       
  1840         {
       
  1841         EventMonitor()->HandleWsEventL(aEvent,aDestination);
       
  1842         }
       
  1843     
       
  1844     TInt eventType = aEvent.Type();
       
  1845     // block these two here to avoid any extra execution beneath avkon level
       
  1846     if (eventType == KAknFullOrPartialForegroundLost ||
       
  1847         eventType == KAknFullOrPartialForegroundGained )
       
  1848         {
       
  1849         iAknFlags.Assign(EForegroundOrPartialForeground, eventType == KAknFullOrPartialForegroundGained);
       
  1850         return;
       
  1851         }
       
  1852 
       
  1853     // This method call practically adds a shift modifier to hash key + joystick events.
       
  1854     // This is because of marking in lists and editors when edit there is no edit key in device.
       
  1855     if (SimulateHashKeyMarkingEvent(aEvent))
       
  1856         {
       
  1857         return;
       
  1858         }
       
  1859 
       
  1860     // ---- To turn on key code conversion by default -----            
       
  1861     // must be done before passing to base classes
       
  1862     if (eventType == EEventKey && iExtension && !iExtension->iFlags[CAknAppUiExtension::ESimulatingEvent])
       
  1863         {
       
  1864         TKeyEvent key = *(aEvent.Key());
       
  1865         TUint code = key.iCode;
       
  1866         
       
  1867         GetAliasKeyCodeL(key.iCode, key, EEventKey);
       
  1868             
       
  1869         // if key conversion returned something different from original                  
       
  1870         if (code != key.iCode)
       
  1871            {
       
  1872            iExtension->iFlags.Set(CAknAppUiExtension::ESimulatingEvent);
       
  1873            TRAPD(err, iCoeEnv->SimulateKeyEventL(key, EEventKey));
       
  1874            iExtension->iFlags.Clear(CAknAppUiExtension::ESimulatingEvent);
       
  1875            User::LeaveIfError(err);
       
  1876                 
       
  1877            return; // block handling of this event.         
       
  1878            }
       
  1879         }
       
  1880         
       
  1881 #ifdef RD_SCALABLE_UI_V2
       
  1882     if ( eventType == EEventPointer )        
       
  1883         {
       
  1884         if ( PointerEventModifier() )
       
  1885             {
       
  1886             PointerEventModifier()->HandlePointerEvent( *aEvent.Pointer(), aDestination );
       
  1887             }
       
  1888 
       
  1889         if ( aEvent.Pointer()->iType == TPointerEvent::EButton1Down )
       
  1890             {                       
       
  1891             if ( iExtension )
       
  1892                 {
       
  1893                 iExtension->iFlags.Clear(CAknAppUiExtension::EFocusLost);
       
  1894                 }
       
  1895             
       
  1896             CAknToolbar* toolbar = CurrentPopupToolbar();
       
  1897             
       
  1898             // Non-focusing toolbar takes focus away from its embedded editor
       
  1899             // or other component control if a control other than toolbar is 
       
  1900             // tapped. Focus is not removed if the tapped control is CBA, 
       
  1901             // touchpane or a non-fullscreen dialog.
       
  1902             if ( toolbar && toolbar->IsShown() && toolbar != aDestination )
       
  1903                 {
       
  1904                 if ( TouchPane() != aDestination )
       
  1905                     {
       
  1906                     CEikDialog* dlg = aDestination->MopGetObject( dlg );
       
  1907                     
       
  1908                     TBool focusLost = ETrue;
       
  1909                     
       
  1910                     if ( dlg )
       
  1911                         {
       
  1912                         TInt flags = dlg->DialogFlags();
       
  1913                         
       
  1914                         if ( flags != EEikDialogFlagFillScreen &&
       
  1915                              flags != EEikDialogFlagFillAppClientRect )
       
  1916                             {
       
  1917                             focusLost = EFalse;
       
  1918                             }
       
  1919                         }
       
  1920                     else
       
  1921                         {
       
  1922                         CEikCba* cba = aDestination->MopGetObject( cba );
       
  1923                         
       
  1924                         if ( cba == aDestination )
       
  1925                             {
       
  1926                             focusLost = EFalse;
       
  1927                             }
       
  1928                         }
       
  1929                     
       
  1930                     if ( focusLost )
       
  1931                         {
       
  1932                         toolbar->PrepareForFocusLossL(); 
       
  1933                         }
       
  1934                     }
       
  1935                 }
       
  1936             }     
       
  1937         else if ( iExtension && iExtension->iFlags[CAknAppUiExtension::EFocusLost] )
       
  1938             {
       
  1939             aDestination->IgnoreEventsUntilNextPointerUp();
       
  1940             iExtension->iFlags.Clear(CAknAppUiExtension::EFocusLost);
       
  1941             }                
       
  1942         }
       
  1943 #endif // RD_SCALABLE_UI_V2        
       
  1944 
       
  1945 
       
  1946 
       
  1947 
       
  1948     if ( eventType == EEventPointer && iExtension &&
       
  1949         aEvent.Pointer()->iType == TPointerEvent::EButton1Up )
       
  1950         {
       
  1951         iExtension->iDisabledScanCode = -1; 
       
  1952         }
       
  1953         
       
  1954 
       
  1955 
       
  1956 
       
  1957     if (!iDumpNextControl)
       
  1958         {
       
  1959         CAknAppUiBase::HandleWsEventL(aEvent, aDestination);    
       
  1960         }
       
  1961     switch (eventType)
       
  1962         {
       
  1963         case EEventFocusGained:
       
  1964             UpdateKeyBlockMode();
       
  1965             GfxTransEffect::Enable();
       
  1966             iAvkonEnv->TransitionEvent(AknTransEffect::EApplicationActivate);
       
  1967             if (iExtension)
       
  1968                 {
       
  1969 #ifdef RD_SCALABLE_UI_V2
       
  1970                 iExtension->iFlags.Clear(CAknAppUiExtension::EFocusLost);
       
  1971 #endif                         
       
  1972                 }
       
  1973             break;
       
  1974         case EEventFocusLost:
       
  1975             if (iExtension)
       
  1976                 {
       
  1977                 iExtension->iFlags.Clear(CAknAppUiExtension::EHashKeyDown);
       
  1978                     
       
  1979 #ifdef RD_SCALABLE_UI_V2
       
  1980                 iExtension->iFlags.Set(CAknAppUiExtension::EFocusLost);
       
  1981 #endif                         
       
  1982                 }
       
  1983                 
       
  1984             break;          
       
  1985         case EEventKey:
       
  1986             {
       
  1987             TKeyEvent* key = aEvent.Key();
       
  1988             
       
  1989             TInt disabledScanCode = iExtension ? iExtension->iDisabledScanCode : -1;
       
  1990             
       
  1991             if ( key->iRepeats && KeySounds() && key->iScanCode != disabledScanCode )
       
  1992                 {
       
  1993                 KeySounds()->PlaySound(*key);
       
  1994                 }
       
  1995             
       
  1996                 
       
  1997 #ifdef _DEBUG
       
  1998             if (key->iCode == CTRL('i') && (key->iModifiers&EAllStdModifiers)==EAllStdModifiers)
       
  1999                 {
       
  2000                 iDumpNextControl = ETrue;
       
  2001                 }
       
  2002 #endif
       
  2003             // Launch help application.
       
  2004             if (key->iCode == EKeyHelp && !key->iRepeats)
       
  2005                 {
       
  2006                 // Some applications do not handle EAknCmdHelp, but define their own command.
       
  2007                 // So first check if help context is available.
       
  2008                 CArrayFix<TCoeHelpContext> *helpContext = iEikonEnv->EikAppUi()->AppHelpContextL();
       
  2009                 if ( helpContext && helpContext->Count())
       
  2010                     {
       
  2011                     // Help context is available, launch help directly from here.
       
  2012                     // Still need to check if stuff from ProcessCommandL's beginning is needed
       
  2013                     // (eg. close menu & pop-up's) or are they handled by focus lost/gain.
       
  2014                     HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), helpContext);   
       
  2015                     return;
       
  2016                     }
       
  2017                 else
       
  2018                     {
       
  2019                     // Help context was not available. App either does not support help
       
  2020                     // or creates the context manually. Send EAknCmdHelp to the application.
       
  2021                     // This will work if the application handles EAknCmdHelp instead of defining
       
  2022                     // its own command for help. If the app didn't return help context and does
       
  2023                     // not handle EAknCmdHelp, we can not launch help.
       
  2024                     ProcessCommandL(EAknCmdHelp);
       
  2025                     return;
       
  2026                     }
       
  2027                 }
       
  2028             break;
       
  2029             }
       
  2030 #ifdef _DEBUG
       
  2031         case EEventPointer:
       
  2032             {
       
  2033             if (iDumpNextControl)
       
  2034                 {
       
  2035                 iDumpNextControl = EFalse;
       
  2036                 RDebug debug;
       
  2037                 DumpControl(aDestination, 0, debug);
       
  2038                 }
       
  2039             break;
       
  2040             }
       
  2041 #endif
       
  2042         case KUidValueAknsSkinChangeEvent:
       
  2043             {
       
  2044             RelinquishPriorityToForegroundAppLC();
       
  2045             
       
  2046             HandleResourceChangeL(KAknsMessageSkinChange);
       
  2047             HandleStackedControlsResourceChange(KAknsMessageSkinChange);
       
  2048 
       
  2049             // Pass the event to container AppUi in case we are embedded
       
  2050             CEikAppUi* container = ContainerAppUi();
       
  2051             if (container)
       
  2052                 {
       
  2053                 container->HandleResourceChangeL(KAknsMessageSkinChange);
       
  2054                 container->HandleStackedControlsResourceChange(KAknsMessageSkinChange);
       
  2055                 }
       
  2056             
       
  2057             CleanupStack::PopAndDestroy();  // RelinquishPriorityToForegroundAppLC
       
  2058             break;
       
  2059             }
       
  2060 
       
  2061         case KAknUidValueEndKeyCloseEvent:
       
  2062             {
       
  2063             CEikonEnv* env = iEikonEnv;
       
  2064             if ( env && !env->IsSystem() ) // System apps are not closed
       
  2065                 {
       
  2066                 // Close or hide the application.
       
  2067                 TWsEvent event;
       
  2068                 event.SetType( KAknShutOrHideApp );
       
  2069                 event.SetTimeNow();
       
  2070                 CAknAppUiBase::HandleWsEventL( event, aDestination );
       
  2071                 }
       
  2072             break;
       
  2073             }
       
  2074 
       
  2075 
       
  2076         default:
       
  2077             break;
       
  2078         }
       
  2079         
       
  2080     }
       
  2081     
       
  2082 // This method watches for hash key presses, and adds a shift modifier to all arrow key 
       
  2083 // and ok key events, if hash key is simultaneously down. This is done because of making the 
       
  2084 // edit key optional in the device. Therefore, hash key with joystick (or single hash press, 
       
  2085 // see eiklbx.cpp) can be used for marking in lists and editors.    
       
  2086 TBool CAknAppUi::SimulateHashKeyMarkingEvent(const TWsEvent& aEvent)
       
  2087     {
       
  2088     TInt eventType = aEvent.Type();        
       
  2089         
       
  2090     if (iExtension && 
       
  2091         iExtension->iFlags[CAknAppUiExtension::EHashKeyMarking] &&
       
  2092         (eventType == EEventKeyDown || eventType == EEventKeyUp || eventType == EEventKey) &&
       
  2093         !iExtension->iFlags[CAknAppUiExtension::ESimulatingEvent])
       
  2094         {
       
  2095         TKeyEvent key = *(aEvent.Key());
       
  2096         
       
  2097         if (eventType == EEventKeyDown && key.iScanCode == EStdKeyHash)
       
  2098             {
       
  2099             iExtension->iFlags.Set(CAknAppUiExtension::EHashKeyDown);
       
  2100             }
       
  2101         else if (eventType == EEventKeyUp && key.iScanCode == EStdKeyHash)
       
  2102             {
       
  2103             iExtension->iFlags.Clear(CAknAppUiExtension::EHashKeyDown);
       
  2104             }
       
  2105         else if (iExtension->iFlags[CAknAppUiExtension::EHashKeyDown] && eventType == EEventKey && 
       
  2106             (key.iCode == EKeyUpArrow    || 
       
  2107              key.iCode == EKeyDownArrow  || 
       
  2108              key.iCode == EKeyLeftArrow  || 
       
  2109              key.iCode == EKeyRightArrow ||
       
  2110              key.iCode == EKeyOK))
       
  2111             {
       
  2112             // Fetch the qwerty mode status from pubsub. No error handling needed.
       
  2113             TBool qwertyMode = EFalse;    
       
  2114             iExtension->iQwertyModeStatusProperty.Get(qwertyMode);                        
       
  2115                 
       
  2116             if (!qwertyMode)
       
  2117                 {
       
  2118                 TKeyEvent keyEvent;
       
  2119                 keyEvent.iCode = key.iCode;
       
  2120                 keyEvent.iScanCode = key.iScanCode;
       
  2121                 keyEvent.iRepeats = key.iRepeats;
       
  2122                 keyEvent.iModifiers = key.iModifiers|EModifierShift;  // Adds shift.
       
  2123                  
       
  2124                 iExtension->iFlags.Set(CAknAppUiExtension::ESimulatingEvent);
       
  2125                 TRAPD(err, iCoeEnv->SimulateKeyEventL(keyEvent, EEventKey));          
       
  2126                 iExtension->iFlags.Clear(CAknAppUiExtension::ESimulatingEvent);
       
  2127                 User::LeaveIfError(err);
       
  2128                 
       
  2129                 return ETrue; // block handling of this event.   
       
  2130                 }
       
  2131             }            
       
  2132         }
       
  2133         
       
  2134     return EFalse;          
       
  2135     }
       
  2136 
       
  2137 EXPORT_C void CAknAppUi::SetKeyBlockMode(TAknKeyBlockMode aMode)
       
  2138     {
       
  2139     iBlockMode = aMode;
       
  2140     UpdateKeyBlockMode();
       
  2141     }
       
  2142 
       
  2143 
       
  2144 void CAknAppUi::UpdateKeyBlockMode()
       
  2145     {
       
  2146     CAknSgcClient::SetKeyBlockMode((TAknKeySoundOpcode)iBlockMode);
       
  2147     }
       
  2148 
       
  2149 #ifdef _DEBUG
       
  2150 const TInt KDumpIndentWidth = 2;
       
  2151 
       
  2152 class CPublicCCoeControl : public CCoeControl
       
  2153     {
       
  2154 public:
       
  2155     TInt CountComponentControls() const { return 0; }
       
  2156     CCoeControl* ComponentControl(TInt /*aIndex*/) const { return 0; }
       
  2157     };
       
  2158 
       
  2159 void CAknAppUi::DumpControl(CCoeControl* aControl, TInt aLevel, RDebug& aDebug)
       
  2160     {
       
  2161     TInt indent = KDumpIndentWidth * aLevel;
       
  2162     aDebug.Print(_L("%*cAddress = (CCoeControl*)0x%08x"), indent, ' ', aControl);
       
  2163 
       
  2164     _LIT(KDumpIs, "is");
       
  2165     _LIT(KDumpHas, "has");
       
  2166     _LIT(KDumpNo, "no");
       
  2167     _LIT(KDumpNot, "not");
       
  2168     aDebug.Print(_L("%*c%S visible, %S dimmed, %S focused, %S border, %S focusable, %S window owning"), indent, ' ', 
       
  2169         aControl->IsVisible() ? &KDumpIs : &KDumpNot,
       
  2170         aControl->IsDimmed() ? &KDumpIs : &KDumpNot,
       
  2171         aControl->IsFocused() ? &KDumpIs : &KDumpNot,
       
  2172         aControl->HasBorder() ? &KDumpHas : &KDumpNo,
       
  2173         aControl->IsNonFocusing() ? &KDumpNot : &KDumpIs,
       
  2174         aControl->OwnsWindow() ? &KDumpIs : &KDumpNot
       
  2175         );
       
  2176 
       
  2177     TPoint pos = aControl->PositionRelativeToScreen();
       
  2178     TRect rect = aControl->Rect();
       
  2179     aDebug.Print(_L("%*cscreen pos = (%d,%d)   top left = (%d,%d)   bottom right = (%d,%d)   size = (%d,%d)"),
       
  2180         indent, ' ', pos.iX, pos.iY, rect.iTl.iX, rect.iTl.iY,
       
  2181         rect.iBr.iX, rect.iBr.iY, rect.Width(), rect.Height());
       
  2182 
       
  2183     CPublicCCoeControl* pub = reinterpret_cast<CPublicCCoeControl*>(aControl);
       
  2184     TInt count = pub->CountComponentControls();
       
  2185     aDebug.Print(_L("%*c%d sub control(s)"), indent, ' ', count);
       
  2186     for (TInt ii=0; ii<count; ii++)
       
  2187         {
       
  2188         aDebug.Print(_L("%*csub control %d:"), indent, ' ', ii);
       
  2189         DumpControl(pub->ComponentControl(ii), aLevel+1, aDebug);
       
  2190         }
       
  2191     }
       
  2192 
       
  2193 #endif
       
  2194 
       
  2195 EXPORT_C void CAknAppUi::HideApplicationFromFSW(TBool aHide)
       
  2196     {
       
  2197     RAknUiServer* client = CAknSgcClient::AknSrv();
       
  2198     if ( client && client->Handle())
       
  2199         {
       
  2200         client->HideApplicationFromFsw(aHide, Application()->AppDllUid().iUid);
       
  2201         }
       
  2202     else 
       
  2203         {
       
  2204         // if CAknSgcClient connection to capserver client
       
  2205         // is not available, make a new connection
       
  2206         RAknUiServer cap;
       
  2207         cap.HideApplicationFromFsw(aHide, Application()->AppDllUid().iUid);
       
  2208         cap.Close();
       
  2209         }
       
  2210     }
       
  2211 
       
  2212 EXPORT_C CAknTouchPane* CAknAppUi::TouchPane()
       
  2213     {
       
  2214 #ifdef RD_SCALABLE_UI_V2  
       
  2215     return static_cast<CEikAppUiFactory*>(iEikonEnv->AppUiFactory())->TouchPane();
       
  2216 #else
       
  2217     return NULL;
       
  2218 #endif
       
  2219     }
       
  2220 
       
  2221 EXPORT_C CAknToolbar* CAknAppUi::PopupToolbar() const
       
  2222     {
       
  2223     return static_cast<CEikAppUiFactory*>(iEikonEnv->AppUiFactory())->PopupToolbar();
       
  2224     }
       
  2225     
       
  2226 EXPORT_C CAknToolbar* CAknAppUi::CurrentPopupToolbar() const
       
  2227     {
       
  2228     return static_cast<CEikAppUiFactory*>(iEikonEnv->AppUiFactory())->CurrentPopupToolbar();
       
  2229     }
       
  2230 
       
  2231 EXPORT_C CAknToolbar* CAknAppUi::CurrentFixedToolbar() const
       
  2232     {
       
  2233     return static_cast<CEikAppUiFactory*>(iEikonEnv->AppUiFactory())->CurrentFixedToolbar();
       
  2234     }
       
  2235 
       
  2236     
       
  2237 EXPORT_C void CAknAppUi::StopDisplayingPopupToolbar()
       
  2238     {
       
  2239     if (CurrentPopupToolbar())
       
  2240         {
       
  2241         CurrentPopupToolbar()->SetToolbarVisibility( EFalse );
       
  2242         }
       
  2243     if (PopupToolbar())
       
  2244         {
       
  2245         PopupToolbar()->SetToolbarVisibility( EFalse );
       
  2246         }
       
  2247     }
       
  2248 
       
  2249 EXPORT_C void CAknAppUi::GetAliasKeyCodeL(TUint& aCode, const TKeyEvent& aKeyEvent,TEventCode aType)
       
  2250     {
       
  2251     if (iExtension && iExtension->iAknAliasKeyCodeResolver)
       
  2252         {
       
  2253         User::LeaveIfError(iExtension->iAknAliasKeyCodeResolver->GetAliasKeyCode(aCode,aKeyEvent,aType));
       
  2254         return;
       
  2255         }
       
  2256         
       
  2257     aCode = aKeyEvent.iCode;
       
  2258     RAknUiServer* cap = CAknSgcClient::AknSrv();
       
  2259     if (cap && cap->Handle())
       
  2260         {
       
  2261         User::LeaveIfError(cap->GetAliasKeyCode(aCode, aKeyEvent, aType));        
       
  2262         }
       
  2263     }
       
  2264 
       
  2265 EXPORT_C void CAknAppUi::SetAliasKeyCodeResolverL(MAknAliasKeyCodeResolver* aResolver)
       
  2266     {
       
  2267     if(!iExtension)
       
  2268         {
       
  2269         iExtension = CAknAppUiExtension::NewL();
       
  2270         }
       
  2271     iExtension->iAknAliasKeyCodeResolver = aResolver;
       
  2272     }
       
  2273     
       
  2274     
       
  2275 
       
  2276 EXPORT_C TInt32 CAknAppUi::CaptureKey(TUint aKeycode, TUint aModifierMask, TUint aModifier)
       
  2277     {
       
  2278     TInt err = KErrNone;
       
  2279     TInt32 handle = 0;
       
  2280     TRAP(err, CaptureKeyL(aKeycode, aModifierMask, aModifier, handle));
       
  2281     
       
  2282     if (err != KErrNone)
       
  2283         {
       
  2284         return err;
       
  2285         }
       
  2286         
       
  2287     return handle;  
       
  2288     }
       
  2289     
       
  2290     
       
  2291 EXPORT_C void CAknAppUi::CaptureKeyL(TUint aKeycode, TUint aModifierMask, TUint aModifier, TInt32& aHandle)
       
  2292     {   
       
  2293     TBool qwertyOn = EFalse;    
       
  2294     User::LeaveIfError(RProperty::Get(KCRUidAvkon, KAknQwertyInputModeActive, qwertyOn));
       
  2295     
       
  2296     RWindowGroup& group = iCoeEnv->RootWin();       
       
  2297     
       
  2298     if (qwertyOn)   
       
  2299         {           
       
  2300         RArray<TPtiNumericKeyBinding> numMaps;
       
  2301         CPtiEngine* pti = NULL;     
       
  2302                 
       
  2303         CAknSettingCache& settingsCache = CAknEnv::Static()->SettingCache();
       
  2304     
       
  2305         pti = CPtiEngine::NewL();
       
  2306         CleanupStack::PushL(pti);
       
  2307                 
       
  2308         pti->GetNumericModeKeysForQwertyL(settingsCache.InputLanguage(), numMaps);
       
  2309         
       
  2310         TPtiKey starScanCode = (TPtiKey)0;  
       
  2311         TInt i = 0;     
       
  2312         for (; i < numMaps.Count(); i++)
       
  2313             {
       
  2314             if (numMaps[i].iChar == '*')     
       
  2315                 {
       
  2316                 starScanCode = numMaps[i].iKey;
       
  2317                 break;
       
  2318                 }                               
       
  2319             }
       
  2320                 
       
  2321         if (starScanCode)
       
  2322             {
       
  2323             CPtiCoreLanguage* lang = static_cast<CPtiCoreLanguage*>(pti->GetLanguage(ELangEnglish));
       
  2324             if (lang)
       
  2325                 {
       
  2326                 CPtiQwertyKeyMappings* qmap = static_cast<CPtiQwertyKeyMappings*>(lang->GetQwertyKeymappings());
       
  2327                 if (qmap)
       
  2328                     {   
       
  2329                     TBuf<50> keyData;
       
  2330                     qmap->GetDataForKey(starScanCode, keyData, numMaps[i].iCase);
       
  2331                     if (keyData.Length())                       
       
  2332                         {
       
  2333                         aKeycode = keyData[0];
       
  2334                         }
       
  2335                     else
       
  2336                         {
       
  2337                         User::Leave(KErrNotFound);
       
  2338                         }                           
       
  2339                     }                                                       
       
  2340                 }                                                               
       
  2341             }
       
  2342                     
       
  2343         CleanupStack::PopAndDestroy(); // pti
       
  2344         numMaps.Close();            
       
  2345         }
       
  2346                     
       
  2347     aHandle = group.CaptureKey( aKeycode, aModifierMask, aModifier );           
       
  2348     User::LeaveIfError(aHandle);
       
  2349     }
       
  2350      
       
  2351 EXPORT_C TBool CAknAppUi::ExitHidesInBackground() const
       
  2352     {
       
  2353     TBool hide = EFalse;
       
  2354     if (!iEikonEnv->StartedAsServerApp())
       
  2355         TRAP_IGNORE(hide = ExitHidesInBackgroundL());
       
  2356     return hide;
       
  2357     }
       
  2358     
       
  2359 TBool CAknAppUi::ExitHidesInBackgroundL() const
       
  2360     {
       
  2361     // Detect whether or not the application should attempt a fake exit. 
       
  2362     // Configuration is through a cenrep keyspace listing the application UIDs which should fake exit.
       
  2363     CEikApplication* app = Application();
       
  2364     if (!app)
       
  2365         return EFalse;
       
  2366     TInt uid = app->AppDllUid().iUid;
       
  2367     CRepository* repository = CRepository::NewLC(KCRUidLeaveAppsInMemory);
       
  2368     RArray<TUint32> keys;
       
  2369     repository->FindEqL(KLeaveAppsInMemoryAppListKeyRange,
       
  2370                         KLeaveAppsInMemoryAppListKeyMask,
       
  2371                         uid,
       
  2372                         keys);
       
  2373     TBool hide = keys.Count() != 0;
       
  2374     keys.Close();
       
  2375     CleanupStack::PopAndDestroy(repository);
       
  2376     return hide;
       
  2377     }
       
  2378     
       
  2379 EXPORT_C void CAknAppUi::HideInBackground()
       
  2380     {
       
  2381   /*
       
  2382   Call EApplicationExit effect start here since for the user hiding app in background
       
  2383   is still exiting an app. So this call changes the application switch effect to an application 
       
  2384   exit effect.
       
  2385   */
       
  2386   CEikApplication* app = Application();
       
  2387 
       
  2388     const TInt focusWGroupId = iEikonEnv->WsSession().GetFocusWindowGroup();
       
  2389     const TInt thisApplicationWgId = iEikonEnv->RootWin().Identifier();
       
  2390 
       
  2391     if ( focusWGroupId == thisApplicationWgId )
       
  2392         {
       
  2393         GfxTransEffect::BeginFullScreen( AknTransEffect::EApplicationExit, TRect(),
       
  2394         AknTransEffect::EParameterType, AknTransEffect::GfxTransParam( app->AppDllUid() ) );
       
  2395         }
       
  2396 
       
  2397     // Hide the application in the background. 
       
  2398     // This performs the push-to-background and hide-from-FSW operations necessary to make the application look as if it has exited.
       
  2399     HideApplicationFromFSW(ETrue);
       
  2400     iExtension->iFlags.Set(CAknAppUiExtension::EAppIsHiddenInBackground);
       
  2401     CAknSgcClient::MoveApp(iEikonEnv->RootWin().Identifier(), ESgcMoveAppToBackground);
       
  2402     }
       
  2403     
       
  2404     
       
  2405 EXPORT_C void CAknAppUi::DisableNextKeySound( TInt aScanCode )
       
  2406     {
       
  2407     if ( iExtension )
       
  2408         {
       
  2409         iExtension->iDisabledScanCode = aScanCode;
       
  2410         }
       
  2411     if ( KeySounds() )
       
  2412         {
       
  2413         KeySounds()->DisableNextKeySound( aScanCode );
       
  2414         }
       
  2415     }
       
  2416 
       
  2417 // End of File
       
  2418