taskswitcher/contextengine/tsfswpreviewprovider/wsplugin/src/previewprovidercrp.cpp
branchRCL_3
changeset 11 ff572dfe6d86
parent 4 4d54b72983ae
child 19 79311d856354
--- a/taskswitcher/contextengine/tsfswpreviewprovider/wsplugin/src/previewprovidercrp.cpp	Fri Feb 19 22:42:37 2010 +0200
+++ b/taskswitcher/contextengine/tsfswpreviewprovider/wsplugin/src/previewprovidercrp.cpp	Fri Mar 12 15:41:49 2010 +0200
@@ -33,6 +33,7 @@
 
 // CONSTANTS
 const TInt KImpId( 0x20016BEC );
+const TInt KMinTimeForOrientationSwitch = 1; // 1 second
 
 // --------------------------------------------------------------------------
 // CPreviewProviderCRP::CreateL
@@ -145,7 +146,9 @@
     TSLOG_IN();
     
     BaseConstructL( aEnv, aId, aOwner );
-    aEnv.RegisterEventHandler( this, this, TWservCrEvent::EWindowGroupChanged );
+    aEnv.RegisterEventHandler( this, this, TWservCrEvent::EWindowGroupChanged |
+                                           TWservCrEvent::EDeviceOrientationChanged );
+    iScreenChangedTime = 0;
     
     TSLOG_OUT();
     }
@@ -165,11 +168,30 @@
         if ( iWgIds.FindInOrder( iPrevId ) >= 0 ||
             ( iPrevId == 0 &&  iPrevReg != 0 ) )
             {
-            TRAP_IGNORE( ScreenshotL() );
+            TTime currTime;
+            currTime.HomeTime();
+            TTimeIntervalSeconds secondsFrom;
+            TInt err = currTime.SecondsFrom( iScreenChangedTime, secondsFrom );
+            if ( err != KErrNone || secondsFrom.Int() > KMinTimeForOrientationSwitch )
+                {
+                TRAP_IGNORE( ScreenshotL() );
+                }
+            else
+                {
+                // Reset time to allow screenshot taking on next wg change
+                iScreenChangedTime = 0;
+                // Order screenshot rotation
+                BitmapRotationNeeded( iPrevId?iPrevId:iPrevReg, iClockwiseRot );
+                }
             iPrevReg = 0;
             }
         iPrevId = wgId;
         }
+    else if ( aEvent.Type() == TWservCrEvent::EDeviceOrientationChanged )
+        {
+        iScreenChangedTime.HomeTime();
+        TRAP_IGNORE( ScreenshotL() );
+        }
     
     TSLOG_OUT();
     }
@@ -217,6 +239,28 @@
     TSLOG_OUT();
     }
 
+
+// --------------------------------------------------------------------------
+// CPreviewProviderCRP::BitmapRotationNeeded
+// --------------------------------------------------------------------------
+//
+void CPreviewProviderCRP::BitmapRotationNeeded( TInt aWgId, TBool aClockwise )
+    {
+    TSLOG_CONTEXT( BitmapRotationNeeded, TSLOG_LOCAL );
+    TSLOG_IN();
+    
+    const TInt msg[] = {
+            aClockwise ? NPreviewMsg::EBitmapRotationNeeded90 : NPreviewMsg::EBitmapRotationNeeded270,
+            aWgId,
+            0
+            };
+    TPckgC<TInt[sizeof(msg) / sizeof(TInt)]> buf(msg);
+    SendMessage(buf);
+    
+    TSLOG_OUT();
+    }
+
+
 // --------------------------------------------------------------------------
 // CPreviewProviderCRP::Register
 // --------------------------------------------------------------------------
@@ -300,6 +344,10 @@
         {
         iScreenshotSize = sz;
         }
+    
+    // Mark direction for possible rotation
+    iClockwiseRot = iScreenshotSize.iWidth > iScreenshotSize.iHeight;
+    
     // Use the the same DisplayMode as for the source image
     // so override the display mode, ignoring any requests.
     iScreenshotMode = screenConfig->DisplayMode();