windowing/windowserver/nga/SERVER/renderorientationtracker.cpp
changeset 116 171fae344dd4
equal deleted inserted replaced
103:2717213c588a 116:171fae344dd4
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This material, including documentation and any related
       
     4 // computer programs, is protected by copyright controlled by
       
     5 // Nokia. All rights are reserved. Copying, including
       
     6 // reproducing, storing, adapting or translating, any
       
     7 // or all of this material requires the prior written consent of
       
     8 // Nokia. This material also contains confidential
       
     9 // information which may not be disclosed to others without the
       
    10 // prior written consent of Nokia.
       
    11 //
       
    12 // Description:
       
    13 // Render Orientation Tracking and Publication
       
    14 // 
       
    15 
       
    16 #include <hal.h>
       
    17 #include <e32std.h>
       
    18 #include "renderorientationtracker.h"
       
    19 #include "rootwin.h"
       
    20 #include "windowgroup.h"
       
    21 #include "wstop.h"
       
    22 #include "..\debuglog\DEBUGLOG.H"
       
    23 
       
    24 extern CDebugLogBase* wsDebugLog;
       
    25 
       
    26 /** Convert a TRenderOrientation value into a TDigitiserOrientation.
       
    27 Note: The algorithm used makes use of the ordering of the values of the respective enums, 
       
    28 thus this is checked for (at compile time) at the start of the function.
       
    29 @param aWservOrientation A value from the TRenderOrientation enums.
       
    30 @return The equivalent value from the TDigitiserOrientation enums.
       
    31 */
       
    32 inline HALData::TDigitiserOrientation WservToDigitiser(TRenderOrientation aWservOrientation)
       
    33 	{
       
    34 	__ASSERT_COMPILE(EDisplayOrientationNormal+1 == EDisplayOrientation90CW);
       
    35 	__ASSERT_COMPILE(EDisplayOrientationNormal+2 == EDisplayOrientation180);
       
    36 	__ASSERT_COMPILE(EDisplayOrientationNormal+3 == EDisplayOrientation270CW);
       
    37 	__ASSERT_COMPILE(HALData::EDigitiserOrientation_000+1 == HALData::EDigitiserOrientation_090);
       
    38 	__ASSERT_COMPILE(HALData::EDigitiserOrientation_000+2 == HALData::EDigitiserOrientation_180);
       
    39 	__ASSERT_COMPILE(HALData::EDigitiserOrientation_000+3 == HALData::EDigitiserOrientation_270);
       
    40 	HALData::TDigitiserOrientation ret=static_cast<HALData::TDigitiserOrientation>
       
    41 			(HALData::EDigitiserOrientation_000 + (aWservOrientation - EDisplayOrientationNormal));
       
    42 	return ret;
       
    43 	}
       
    44 
       
    45 // Todo remove/undefine this for release
       
    46 #define TECHVIEW_TESTMODE
       
    47 
       
    48 CWsRenderOrienationTracker* CWsRenderOrienationTracker::NewL()
       
    49     {
       
    50     CWsRenderOrienationTracker* self = new(ELeave)CWsRenderOrienationTracker();
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop();
       
    54     return self;
       
    55     }
       
    56 
       
    57 CWsRenderOrienationTracker::CWsRenderOrienationTracker()
       
    58     : CActive(CActive::EPriorityStandard),
       
    59       iRenderOrientationTrackingType(EDisplayOrientationNormal),
       
    60       iPublishedRenderOrientation(EDisplayOrientationNormal)
       
    61     {
       
    62     CActiveScheduler::Add(this);    
       
    63     }
       
    64 
       
    65 void CWsRenderOrienationTracker::ConstructL()
       
    66     {    
       
    67     const TSecurityPolicy   KRenderOrientationReadSecurityPolicy(ECapability_None);
       
    68     const TSecurityPolicy   KRenderOrientationWriteSecurityPolicy(ECapabilityWriteDeviceData);
       
    69     
       
    70     // Define P&S Property to publish to
       
    71     TInt error = RProperty::Define( KRenderOrientationCategory,
       
    72                                     KRenderOrientationKey,
       
    73                                     RProperty::EInt,
       
    74                                     KRenderOrientationReadSecurityPolicy,
       
    75                                     KRenderOrientationWriteSecurityPolicy);
       
    76 
       
    77     // Attach the publisher for real-time publishing
       
    78     if(KErrNone == error)
       
    79         error = iRenderOrientationPublisher.Attach( KRenderOrientationCategory,
       
    80                                                     KRenderOrientationKey);
       
    81 
       
    82     // Publish the initial value
       
    83     if(KErrNone == error)    
       
    84         error = DoPublishOrientation(EDisplayOrientationNormal);
       
    85     
       
    86     //Set the initial value to HAL
       
    87     if(KErrNone == error)
       
    88         SetHALOrientation(EDisplayOrientationNormal);
       
    89     
       
    90     if (wsDebugLog && KErrNone!=error)
       
    91         {
       
    92         _LIT(logText,"Orientation Tracker: failed to initialise with error %d");
       
    93         wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,logText,error);
       
    94         }    
       
    95     User::LeaveIfError(error);
       
    96     }
       
    97 
       
    98 CWsRenderOrienationTracker::~CWsRenderOrienationTracker()
       
    99     {
       
   100     Cancel();
       
   101     iRenderOrientationPublisher.Delete(KRenderOrientationCategory, KRenderOrientationKey);
       
   102     iRenderOrientationPublisher.Close();
       
   103     }
       
   104 
       
   105 /**
       
   106 If the orientation of the given window group is useable updates aOrientationTrackingType with the orientation
       
   107 
       
   108 @param Input: the window group to check
       
   109 @param Output: the window group's orientation if usable ( otherwise unchanged )
       
   110 @return KErrNone if the orienation is usable, KErrNotFound if the orientation is not useable, KErrNotSupported if the orientation is unknown
       
   111 */
       
   112 TInt CWsRenderOrienationTracker::CheckWindowGroupOrientation(const CWsWindowGroup& aWinGroup, TRenderOrientationTrackingType& aOrientationTrackingType)
       
   113     {
       
   114     TInt error = KErrNone;
       
   115     TRenderOrientationTrackingType tempOrientationTrackingType = static_cast<TRenderOrientationTrackingType>(aWinGroup.WsOwner()->GetIndicatedAppOrientation());
       
   116     switch(tempOrientationTrackingType)
       
   117         {
       
   118         case EDisplayOrientationNormal:
       
   119         case EDisplayOrientation90CW:                
       
   120         case EDisplayOrientation180:
       
   121         case EDisplayOrientation270CW:            
       
   122         case EDisplayOrientationAuto:
       
   123             aOrientationTrackingType = tempOrientationTrackingType;
       
   124             break;
       
   125 
       
   126         case EDisplayOrientationIgnore:
       
   127             error = KErrNotFound;
       
   128             if (wsDebugLog)
       
   129                 {
       
   130                 _LIT(logText,"Orientation Tracker: winGroup %08x orientation is set to be ignored");
       
   131                 wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,logText,reinterpret_cast<TInt>(&aWinGroup));
       
   132                 }            
       
   133             break;
       
   134 
       
   135         default:
       
   136             error = KErrNotSupported;
       
   137             if (wsDebugLog)
       
   138                 {
       
   139                 _LIT(logText,"Orientation Tracker: winGroup %08x has undefined orientation, Error %d");                
       
   140                 TBuf<LogTBufSize> buf;
       
   141                 buf.Format(logText, &aWinGroup, error);                
       
   142                 wsDebugLog->MiscMessage(CDebugLogBase::ELogIntermediate,buf);
       
   143                 }                          
       
   144             break;             
       
   145         }
       
   146     
       
   147     return error;
       
   148     }
       
   149 
       
   150 /**
       
   151 Checks that the given group window is appropriate for dictating the render orientation
       
   152 
       
   153 @param Input:  The group window to check
       
   154 @return ETrue is the group window is usable, else EFalse  
       
   155 */
       
   156 TBool CWsRenderOrienationTracker::UseableGroupWindow(const CWsWindowGroup& aWinGroup) const
       
   157     {
       
   158 #ifdef TECHVIEW_TESTMODE
       
   159     // for some reason IsFocusable seems to return 0 and 2, not 0 and 1
       
   160     return NULL!=aWinGroup.Child() &&
       
   161             (aWinGroup.IsFocusable() ? ETrue : EFalse);
       
   162 #else    
       
   163     return (NULL!=aWinGroup.Child());     
       
   164 #endif
       
   165     }
       
   166 
       
   167 /**
       
   168 Finds the topmost usable windowgroup which has a usable orientation, and outputs that orientation
       
   169 
       
   170 @param Output: The current render orientation
       
   171 @return KErrNone if successful, KErrNotFound if the focus window group is not usable, KErrNotSupported if an invalid orientation is found
       
   172 */
       
   173 TInt CWsRenderOrienationTracker::GetFocusWindowOrientation(TRenderOrientationTrackingType& aOrientationTrackingType)
       
   174     {
       
   175     TInt error = KErrNone;
       
   176     CWsWindowGroup* focusWinGroup = CWsTop::FocusWindowGroup();    
       
   177     if(!focusWinGroup)
       
   178         {
       
   179         if(wsDebugLog)
       
   180             {
       
   181             _LIT(logText,"Orientation Tracker: focusWinGroup not found");
       
   182             wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,logText);
       
   183             }
       
   184         error = KErrNotFound;
       
   185         }
       
   186     else
       
   187         {
       
   188         error = CheckWindowGroupOrientation(*focusWinGroup, aOrientationTrackingType);
       
   189         }
       
   190     return error;
       
   191     }
       
   192 
       
   193 /**
       
   194 Finds the topmost usable windowgroup which has a usable orientation, and outputs that orientation
       
   195 
       
   196 @param Output: The current render orientation
       
   197 @return KErrNone if successful, KErrNotSupported if an invalid orientation is found
       
   198 */
       
   199 TInt CWsRenderOrienationTracker::FindOrientationFromWindowTree(TRenderOrientationTrackingType& aOrientationTrackingType)
       
   200     {
       
   201     TInt error = KErrNone;
       
   202     TRenderOrientationTrackingType tempOrientationTrackingType = iRenderOrientationTrackingType;
       
   203     CWsRootWindow* rootWin = CWsTop::CurrentFocusScreen()->RootWindow();
       
   204     TBool finished = EFalse;
       
   205     for(CWsWindowGroup* winGroup = rootWin->Child(); !finished && NULL != winGroup; winGroup = winGroup->NextSibling())
       
   206         {
       
   207         if (wsDebugLog)
       
   208             {
       
   209             _LIT(logText,"Orientation Tracker: winGroup %08x has priority %d, Orientation %d, Focusable %d, Child %08x");
       
   210             TBuf<LogTBufSize> buf;
       
   211             buf.Format(logText, winGroup, winGroup->OrdinalPriority(), winGroup->WsOwner()->GetIndicatedAppOrientation(),
       
   212                     winGroup->IsFocusable()?ETrue:EFalse, winGroup->Child());                                
       
   213             wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,buf);
       
   214             }               
       
   215         // winGroup is a higher priority ordinal, so see if it has an orientation that can be used
       
   216         // although we're only interested in window groups with child windows otherwise nothing is visible anyway        
       
   217         if(UseableGroupWindow(*winGroup))
       
   218             {
       
   219             error = CheckWindowGroupOrientation(*winGroup, tempOrientationTrackingType);
       
   220             switch(error)
       
   221                 {
       
   222                 case KErrNone:
       
   223                     {
       
   224                     // List is in order, so just find the first one
       
   225                     if (wsDebugLog)
       
   226                         {
       
   227                         _LIT(logText,"Orientation Tracker: Found winGroup %08x with Orientation %d");
       
   228                         TBuf<LogTBufSize> buf;
       
   229                         buf.Format(logText, winGroup, winGroup->WsOwner()->GetIndicatedAppOrientation());                    
       
   230                         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,buf);
       
   231                         }
       
   232                     finished = ETrue;
       
   233                     break;
       
   234                     }
       
   235 
       
   236                 case KErrNotFound:
       
   237                     // so keep searching
       
   238                     break;                    
       
   239                     
       
   240                 case KErrNotSupported:
       
   241                 default:
       
   242                     finished = ETrue;
       
   243                     break;
       
   244                     
       
   245                 }
       
   246             
       
   247             }
       
   248         }
       
   249     // Safe even in error code as won't have been changed by CheckWindowGroupOrientation
       
   250     aOrientationTrackingType = tempOrientationTrackingType;
       
   251     
       
   252     return error;
       
   253     }
       
   254 
       
   255 /**
       
   256 First checks to see if the focus window group has a usable orientation, if so that is output.
       
   257 Otherwise, finds the topmost usable windowgroup which has a usable orientation, and outputs that
       
   258 
       
   259 @param Output: The current render orientation
       
   260 @return KErrNone if successful, KErrNotSupported if an invalid orientation is found 
       
   261  */
       
   262 TInt CWsRenderOrienationTracker::GetIndicatedOrientation(TRenderOrientationTrackingType& aOrientationTrackingType)
       
   263     {
       
   264     // First check the focus window group
       
   265     TInt error = GetFocusWindowOrientation(aOrientationTrackingType);
       
   266 
       
   267     // Don't look for another window if the focus window is usable
       
   268     // or if an error has occured, then don't change current orientation
       
   269     switch(error)
       
   270         {
       
   271         case KErrNone:
       
   272             {
       
   273             if(wsDebugLog)
       
   274                 {
       
   275                 _LIT(logText,"Orientation Tracker: Using focus window %08x for orientation");
       
   276                 wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,logText,reinterpret_cast<TInt>(CWsTop::FocusWindowGroup()));
       
   277                 }
       
   278             break;
       
   279             }
       
   280         
       
   281         case KErrNotFound:
       
   282             {
       
   283             // Can't use focus window group, so find the topmost windowgroup with a valid orientation
       
   284             error = FindOrientationFromWindowTree(aOrientationTrackingType);
       
   285             break;
       
   286             }
       
   287             
       
   288         default:
       
   289             // Unrecoverable error, abort and leave published orientation unchanged
       
   290             break;
       
   291         }
       
   292     
       
   293     return error;
       
   294     }
       
   295 
       
   296 /**
       
   297 Checks to see if the render orientation has changed, and publishes any new orientaion
       
   298 via publish and subscribe
       
   299 
       
   300 @see KRenderOrientationCategory
       
   301 @see KRenderOrientationKey 
       
   302 */
       
   303 void CWsRenderOrienationTracker::CheckRenderOrientation()
       
   304     {
       
   305     TRenderOrientationTrackingType newOrientationTrackingType = iRenderOrientationTrackingType;    
       
   306     TInt error = GetIndicatedOrientation(newOrientationTrackingType);
       
   307 
       
   308     // if the tracking type has changed...
       
   309     if(KErrNone == error && iRenderOrientationTrackingType != newOrientationTrackingType)
       
   310         {
       
   311         if(EDisplayOrientationAuto == iRenderOrientationTrackingType)
       
   312             {
       
   313             // change from auto type, so we need to cancel request for updates from the theme server        
       
   314             Cancel();
       
   315             }    
       
   316         iRenderOrientationTrackingType = newOrientationTrackingType;
       
   317         if(EDisplayOrientationAuto == iRenderOrientationTrackingType)
       
   318             {
       
   319             // Change to auto type, so we need to request updates from the theme server            
       
   320             // Attach to the Theme server to get orientation change updates
       
   321             error = iThemeOrientationProperty.Attach( KThemeOrientationCategory, KThemeOrientationKey );
       
   322             if (wsDebugLog)
       
   323                 {
       
   324                 if(KErrNone == error)
       
   325                     {
       
   326                     // Information Log
       
   327                     _LIT(logText,"Orientation Tracker: Attached to theme orientation property");
       
   328                     wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,logText);
       
   329                     }
       
   330                 else
       
   331                     {
       
   332                     // Error Log
       
   333                     _LIT(logText,"Orientation Tracker: Error %d attaching to theme orientation property");
       
   334                     wsDebugLog->MiscMessage(CDebugLogBase::ELogIntermediate,logText, error);                
       
   335                     }
       
   336                 }              
       
   337             
       
   338             RequestDeviceOrientationNotification();
       
   339             }
       
   340         // See if the  has changed, and publish if it has        
       
   341         error = DoOrientationTracking();
       
   342         }
       
   343 
       
   344     if (wsDebugLog && KErrNone != error)
       
   345         {
       
   346         _LIT(logText,"Orientation Tracker: Error %d Checking Render Orientation");
       
   347         wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,logText, error);
       
   348         }  
       
   349     }
       
   350 
       
   351 /**
       
   352 Requests notification of change of the theme server orientation
       
   353 
       
   354 @Pre iThemeOrientationProperty has had Attach called on it
       
   355 */
       
   356 void CWsRenderOrienationTracker::RequestDeviceOrientationNotification()
       
   357     {
       
   358     if(!IsActive())
       
   359         {
       
   360         if (wsDebugLog)
       
   361             {
       
   362             _LIT(logText,"Orientation Tracker: Subscribing to theme orientation property");
       
   363             wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,logText);
       
   364             }          
       
   365         // Request for Theme Server Orientation P&S  
       
   366         iThemeOrientationProperty.Subscribe(iStatus);        
       
   367         SetActive();
       
   368         }
       
   369     }
       
   370 
       
   371 /**
       
   372 Cancels and closes (detaches) from the theme orientation publish and subscribe
       
   373 */
       
   374 void CWsRenderOrienationTracker::CancelDeviceOrientationNotification()
       
   375     {
       
   376     // Cancel Request for Theme Server Orientation P&S  
       
   377     iThemeOrientationProperty.Cancel();
       
   378     iThemeOrientationProperty.Close();
       
   379     
       
   380     if (wsDebugLog)
       
   381         {
       
   382         _LIT(logText,"Orientation Tracker: Cancelled/closed theme orientation property");
       
   383         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,logText);
       
   384         }      
       
   385     }
       
   386 
       
   387 /**
       
   388 Called when the theme servers orientation has changed.
       
   389 Re-requests unless cancelled
       
   390 */
       
   391 void CWsRenderOrienationTracker::RunL()
       
   392     {
       
   393     TInt error = iStatus.Int();
       
   394     if(KErrNone == error)
       
   395         {
       
   396         // Re-request
       
   397         RequestDeviceOrientationNotification();
       
   398     
       
   399         TInt error = DoOrientationTracking();
       
   400         if (wsDebugLog && KErrNone != error)
       
   401             {
       
   402             _LIT(logText,"Orientation Tracker: Error %d processing theme orientation property");
       
   403             wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,logText, error);
       
   404             }         
       
   405         }
       
   406     else if (wsDebugLog && KErrCancel != error)
       
   407         {
       
   408         _LIT(logText,"Orientation Tracker: Error %d from theme orientation property, not resubscribed");
       
   409         wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,logText, error);     
       
   410         }
       
   411     }
       
   412 
       
   413 /**
       
   414 Cancels the request for notification for changes to theme orientation
       
   415 */
       
   416 void CWsRenderOrienationTracker::DoCancel()
       
   417     {
       
   418     CancelDeviceOrientationNotification();
       
   419     }
       
   420 
       
   421 /**
       
   422 Gets the orientation published from theme server
       
   423 
       
   424 @param Output: the theme server orientation
       
   425 @return KErrNone if successful, KErrNotSupported if the theme server returns an unknown orientation, else any of the system wide error codes 
       
   426 */
       
   427 TInt CWsRenderOrienationTracker::GetThemeOrientation(TRenderOrientation& aThemeOrientation)
       
   428     { 
       
   429     TInt themeOrientation=EDisplayOrientationNormal;
       
   430     TInt error = iThemeOrientationProperty.Get(themeOrientation);
       
   431     if(wsDebugLog && KErrNone != error)
       
   432         {
       
   433         _LIT(logText,"Orientation Tracker: Error %d getting theme orientation property");
       
   434         wsDebugLog->MiscMessage(CDebugLogBase::ELogIntermediate,logText, error);     
       
   435         }
       
   436     
       
   437     if(KErrNone == error)
       
   438         {
       
   439         // Translate the received orientation    
       
   440         switch(themeOrientation)
       
   441             {           
       
   442             case EDisplayOrientationNormal:
       
   443             case EDisplayOrientation90CW:
       
   444             case EDisplayOrientation180:
       
   445             case EDisplayOrientation270CW:
       
   446                 // only update if orientation is supported
       
   447                 aThemeOrientation = static_cast<TRenderOrientation>(themeOrientation);
       
   448                 break;
       
   449             
       
   450             default:
       
   451                 error = KErrNotSupported;
       
   452                 if (wsDebugLog)
       
   453                     {
       
   454                     _LIT(logText,"Orientation Tracker: Unsupported orientation %d from theme orientation property, Error %d");
       
   455                     TBuf<LogTBufSize> buf;
       
   456                     buf.Format(logText, themeOrientation, error);
       
   457                     wsDebugLog->MiscMessage(CDebugLogBase::ELogIntermediate,buf);     
       
   458                     }                
       
   459                 break;
       
   460             }
       
   461         }
       
   462     return error;  
       
   463     }
       
   464 
       
   465 /**
       
   466 Processes the indicated orientation into an actual orientation
       
   467 
       
   468 @return KErrNone for success, KErrNotSupported if the orientation is unknown, else any of the system wide error codes
       
   469 */
       
   470 TInt CWsRenderOrienationTracker::DoOrientationTracking()
       
   471     {
       
   472     TInt error = KErrNone;
       
   473     TRenderOrientation newDeviceOrientation;
       
   474     switch(iRenderOrientationTrackingType)
       
   475         {
       
   476         case EDisplayOrientationNormal:
       
   477         case EDisplayOrientation90CW:                
       
   478         case EDisplayOrientation180:
       
   479         case EDisplayOrientation270CW:            
       
   480             newDeviceOrientation = iRenderOrientationTrackingType;
       
   481             break;
       
   482             
       
   483         case EDisplayOrientationAuto:
       
   484             error = GetThemeOrientation(newDeviceOrientation);
       
   485             break;
       
   486                       
       
   487         default:
       
   488             error = KErrNotSupported;
       
   489             if (wsDebugLog)
       
   490                 {
       
   491                 _LIT(logText,"Orientation Tracker: Unsupported orientation tracking type %d, error %d");
       
   492                 TBuf<LogTBufSize> buf;
       
   493                 buf.Format(logText, iRenderOrientationTrackingType, error);
       
   494                 wsDebugLog->MiscMessage(CDebugLogBase::ELogIntermediate,buf);     
       
   495                 }              
       
   496             break;            
       
   497         }    
       
   498 
       
   499     if(KErrNone == error)
       
   500         {
       
   501         error = PublishOrientation(newDeviceOrientation);
       
   502         }
       
   503     
       
   504     return error;
       
   505     }
       
   506 
       
   507 /**
       
   508 Publishes the given value
       
   509 
       
   510 @param The render orientation to publish
       
   511 @return KErrNone for success, else any of the system wide erro codes
       
   512 */
       
   513 TInt CWsRenderOrienationTracker::DoPublishOrientation(const TRenderOrientation aRenderOrientation)
       
   514     {
       
   515     TInt error = iRenderOrientationPublisher.Set(aRenderOrientation);
       
   516          
       
   517     // if it's published OK, then remember the newly published value
       
   518     if(KErrNone == error)
       
   519         {
       
   520         iPublishedRenderOrientation = aRenderOrientation;
       
   521         if(wsDebugLog)
       
   522             {
       
   523             _LIT(logText,"Orientation Tracker: Published render orientation %d");
       
   524             wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, logText, aRenderOrientation);
       
   525             }
       
   526         }
       
   527     else if(wsDebugLog)
       
   528         {
       
   529         _LIT(logText,"Orientation Tracker: Error %d setting render orientation property");
       
   530         wsDebugLog->MiscMessage(CDebugLogBase::ELogIntermediate, logText, error);                   
       
   531         }
       
   532     return error;
       
   533     }
       
   534 
       
   535 void CWsRenderOrienationTracker::SetHALOrientation(const TRenderOrientation aRenderOrientation)
       
   536     {
       
   537     // If the render orientation is EDisplayOrientationAuto then don't update HAL
       
   538     // The application and HAL should always have the same state for the orientation.
       
   539     if(EDisplayOrientationAuto != aRenderOrientation)
       
   540         {
       
   541         TInt error = HAL::Set(CWsTop::CurrentFocusScreen()->ScreenNumber(), HALData::EDigitiserOrientation, WservToDigitiser(iPublishedRenderOrientation));
       
   542         //Just log the error if there is one.
       
   543         if(wsDebugLog && error != KErrNone)
       
   544             {
       
   545             _LIT(logText,"Orientation Tracker: Error %d setting digitiser orientation");
       
   546             wsDebugLog->MiscMessage(CDebugLogBase::ELogIntermediate, logText, error);           
       
   547             } 
       
   548         }
       
   549     }
       
   550 
       
   551 /**
       
   552 If the current orientation differs from the previously published value then publishes the current value
       
   553 
       
   554 @param The render orientation to check and publish
       
   555 @return KErrNone for success, else any of the system wide erro codes
       
   556 */
       
   557 TInt CWsRenderOrienationTracker::PublishOrientation(const TRenderOrientation aRenderOrientation)
       
   558     {
       
   559     TInt error = KErrNone;
       
   560   
       
   561     if(aRenderOrientation != iPublishedRenderOrientation)
       
   562         {
       
   563         // If the device Orientation has changed, publish it
       
   564         error = DoPublishOrientation(aRenderOrientation);
       
   565         if(KErrNone == error)
       
   566             SetHALOrientation(aRenderOrientation);
       
   567         }
       
   568     return error;
       
   569     }
       
   570