idlehomescreen/nativeuicontroller/src/aistatuspanel.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Handles of drawing text on navi and title panes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknappui.h>
       
    20 #include <aknnavide.h>
       
    21 #include <aknnavi.h>
       
    22 #include <aknnavilabel.h>
       
    23 #include <akntitle.h>
       
    24 #include <AknUtils.h>
       
    25 #include <AknIconUtils.h>
       
    26 #include <avkon.rsg>
       
    27 #include <AknStatuspaneUtils.h>
       
    28 #include <aknlayoutscalable_avkon.cdl.h>
       
    29 #include <AknLayout2ScalableDef.h>
       
    30 #include <e32property.h>
       
    31 #include <avkondomainpskeys.h>
       
    32 #include <telinformationpskeys.h>
       
    33 #include <AknNaviDecoratorObserver.h>
       
    34 #include <AknTitlePaneObserver.h>
       
    35 #include "aistatuspanel.h"
       
    36 #include "debug.h"
       
    37 
       
    38 using namespace AiNativeUiController;
       
    39 
       
    40 // Read capability: ReadDeviceData.
       
    41 _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData );
       
    42 // Write capability: WriteDeviceData.
       
    43 _LIT_SECURITY_POLICY_C1( KWritePolicy, ECapabilityWriteDeviceData );
       
    44 
       
    45 
       
    46 void CAiStatusPanel::ConstructL()
       
    47     {
       
    48     // Display info
       
    49     RProperty::Define(
       
    50         KPSUidTelInformation,
       
    51         KTelDisplayInfo,
       
    52         RProperty::EByteArray,
       
    53         KReadPolicy,
       
    54         KWritePolicy );
       
    55 
       
    56     // RenderTitlePaneL() can be called without the bitmap set to valid handle
       
    57     iBitmapHandle = KErrNotFound;
       
    58     // Get pointer to status pane
       
    59     iStatusPane = static_cast<CAknAppUi*>( CEikonEnv::Static()->
       
    60         EikAppUi() )->StatusPane();
       
    61 
       
    62     // If status pane can't be initialized, let framework handle the problem
       
    63     if( !iStatusPane )
       
    64         {
       
    65         User::Leave( KErrNotFound );
       
    66         }
       
    67 
       
    68     //Get pointer to title pane
       
    69     iTitlePane = ( CAknTitlePane* )iStatusPane->ControlL(
       
    70         TUid::Uid( EEikStatusPaneUidTitle ) );
       
    71 
       
    72     // If title pane can't be initialized, let framework handle the problem
       
    73     if( !iTitlePane )
       
    74         {
       
    75         User::Leave( KErrNotFound );
       
    76         }
       
    77 
       
    78     //Get pointer to navi pane
       
    79     iNaviPane = (CAknNavigationControlContainer *)iStatusPane->
       
    80         ControlL(TUid::Uid(EEikStatusPaneUidNavi));
       
    81 
       
    82     // If navi pane can't be initialized, let framework handle the problem
       
    83     if( !iNaviPane )
       
    84         {
       
    85         User::Leave( KErrNotFound );
       
    86         }
       
    87 
       
    88     // Construct navi pane
       
    89     //iNaviDecorator = iNaviPane->CreateNavigationLabelL( KNullDesC() );
       
    90     //iNaviPane->PushL( *iNaviDecorator );
       
    91 
       
    92 #ifdef _DEBUG
       
    93     _LIT(titlepanetext, "Operator");
       
    94     SetTitlePaneTextL(titlepanetext);
       
    95 #endif
       
    96     }
       
    97 
       
    98 
       
    99 CAiStatusPanel* CAiStatusPanel::NewL()
       
   100     {
       
   101     CAiStatusPanel* self = new( ELeave ) CAiStatusPanel;
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL();
       
   104     CleanupStack::Pop( self );
       
   105     return self;
       
   106     }
       
   107 
       
   108 
       
   109 
       
   110 CAiStatusPanel::~CAiStatusPanel()
       
   111     {
       
   112     delete iTitlePaneText;
       
   113     delete iNaviPaneText;
       
   114     delete iNaviDecorator;
       
   115     }
       
   116 
       
   117 
       
   118 CAiStatusPanel::CAiStatusPanel()
       
   119     {
       
   120     }
       
   121 
       
   122 
       
   123 void CAiStatusPanel::RenderTextOnNaviPaneL()
       
   124     {
       
   125     if( iNaviPaneText )
       
   126         {
       
   127         if (!iNaviDecorator)
       
   128             {
       
   129             iNaviDecorator = iNaviPane->CreateNavigationLabelL( KNullDesC() );
       
   130 
       
   131             iNaviDecorator->SetNaviDecoratorObserver( iNaviDecoratorObserver );
       
   132 
       
   133             iNaviPane->PushL( *iNaviDecorator );
       
   134             }
       
   135         CAknNaviLabel* naviLabel =
       
   136             static_cast< CAknNaviLabel* >( iNaviDecorator->DecoratedControl() );
       
   137         if( naviLabel )
       
   138             {
       
   139             naviLabel->SetTextL( *iNaviPaneText );
       
   140             iNaviDecorator->DrawDeferred();
       
   141             }
       
   142         else
       
   143             {
       
   144             User::Leave( KErrNotFound );
       
   145             }
       
   146         }
       
   147     else
       
   148         {
       
   149         iNaviPane->Pop( iNaviDecorator );
       
   150         delete iNaviDecorator;
       
   151         iNaviDecorator = NULL;
       
   152         }
       
   153     }
       
   154 
       
   155 void CAiStatusPanel::RenderTextOnTitlePaneL()
       
   156     {
       
   157     __PRINTS("XAI: Rendering text to title pane");
       
   158     if( !iTitlePaneText )
       
   159         {
       
   160         __PRINTS("XAI: Rendering text to title pane - invalid text, aborting");
       
   161         
       
   162         iTextInTitlePane = EFalse;
       
   163         
       
   164         return;
       
   165         }
       
   166 
       
   167     TTelTitleDisplay displayText;
       
   168     displayText.iLogoHandle = 0;
       
   169     displayText.iLogoMaskHandle = 0;
       
   170     TBool scroll = !IsKeyLockEnabled();
       
   171     iTitlePane->SetText( iTitlePaneText, scroll );
       
   172     displayText.iDisplayTag.Copy(
       
   173     iTitlePaneText->Left(displayText.iDisplayTag.MaxLength()) );
       
   174 
       
   175     // SetText took ownership
       
   176     iTitlePaneText = NULL;
       
   177 
       
   178     UpdatePhoneDisplayInfo( displayText );
       
   179     
       
   180     iTextInTitlePane = ETrue;
       
   181     
       
   182     __PRINTS("XAI: Rendering text to title pane - done");
       
   183     }
       
   184 
       
   185 
       
   186 void CAiStatusPanel::RenderBitmapOnTitlePaneL()
       
   187     {
       
   188     __PRINTS("XAI: Rendering bitmap to title pane");
       
   189     if( iBitmapHandle == KErrNotFound )
       
   190         {
       
   191         __PRINTS("XAI: Rendering bitmap to title pane - invalid bitmap handle, aborting");
       
   192                 
       
   193         return;
       
   194         }
       
   195 
       
   196     TSize size;
       
   197     TRect rect;
       
   198     TBool hasTitlePane = AknLayoutUtils::LayoutMetricsRect(
       
   199                                             AknLayoutUtils::ETitlePane, rect );
       
   200     if ( !hasTitlePane )
       
   201         {
       
   202         // no title pane, size is unknown.
       
   203         User::Leave( KErrNotReady );
       
   204         }
       
   205     User::LeaveIfError( GetTitlePaneSize( size ) );
       
   206 
       
   207     // CAknIcon takes ownership of bitmaps.
       
   208     CFbsBitmap* dupMain = new ( ELeave ) CFbsBitmap;
       
   209     CleanupStack::PushL( dupMain );
       
   210     User::LeaveIfError(
       
   211         dupMain->Duplicate( iBitmapHandle ) );
       
   212 
       
   213     CFbsBitmap* dupMask = NULL;
       
   214     if ( iMaskHandle != KErrNotFound )
       
   215         {
       
   216         dupMask = new ( ELeave ) CFbsBitmap;
       
   217         CleanupStack::PushL( dupMask );
       
   218         User::LeaveIfError(
       
   219             dupMask->Duplicate( iMaskHandle ) );
       
   220         }
       
   221 
       
   222     //bitmapIcon is not pushed to cleanupstack, ownership
       
   223     //is transferred later
       
   224     CAknIcon* bitmapIcon = CAknIcon::NewL();
       
   225     bitmapIcon->SetMask( dupMask ); // ownership transferred
       
   226     if ( iMaskHandle != KErrNotFound )
       
   227         {
       
   228         CleanupStack::Pop( dupMask );
       
   229         }
       
   230 
       
   231     bitmapIcon->SetBitmap( dupMain ); // ownership transferred
       
   232     CleanupStack::Pop( dupMain );
       
   233 
       
   234     //ownership of bitmapIcon is transferred
       
   235     CAknIcon* scalableIcon = AknIconUtils::CreateIconL( bitmapIcon );
       
   236     CleanupStack::PushL( scalableIcon );
       
   237 
       
   238     AknIconUtils::SetSize( scalableIcon->Bitmap(), size,
       
   239                            EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   240     AknIconUtils::SetSize( scalableIcon->Mask(), size,
       
   241                            EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   242 
       
   243     // Title pane takes ownership of icons.
       
   244     CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
       
   245     CleanupStack::PushL( bitmap );
       
   246     User::LeaveIfError( bitmap->Duplicate( scalableIcon->Bitmap()->Handle() ) );
       
   247 
       
   248     // Check if icon has mask
       
   249     CFbsBitmap* bitmapMask = NULL;
       
   250     if ( scalableIcon->Mask() )
       
   251         {
       
   252         bitmapMask = new ( ELeave ) CFbsBitmap;
       
   253         CleanupStack::PushL( bitmapMask );
       
   254         User::LeaveIfError(
       
   255             bitmapMask->Duplicate( scalableIcon->Mask()->Handle() ) );
       
   256         }
       
   257 
       
   258     // Set the icon in title pane...
       
   259     iTitlePane->SetPicture( bitmap, bitmapMask );
       
   260 
       
   261     const TInt bitmapHandle = bitmap ? bitmap->Handle() : 0;
       
   262     const TInt bitmapMaskHandle = bitmapMask ? bitmapMask->Handle() : 0;
       
   263 
       
   264     // ... and inform TSY to use it
       
   265     TTelTitleDisplay displayText;
       
   266     displayText.iDisplayTag.Zero();
       
   267     displayText.iLogoHandle = bitmapHandle;
       
   268     displayText.iLogoMaskHandle = bitmapMaskHandle;
       
   269 
       
   270     UpdatePhoneDisplayInfo( displayText );
       
   271 
       
   272     if ( bitmapMask )
       
   273         {
       
   274         CleanupStack::Pop( bitmapMask );
       
   275         }
       
   276     CleanupStack::Pop( bitmap );
       
   277     CleanupStack::PopAndDestroy( scalableIcon );
       
   278 
       
   279 
       
   280     // Assume invalid bitmaps. Client needs to set the handles again
       
   281     // Otherwise invalid handles could be hold here and when drawing
       
   282     // undetermined stuff could occurr
       
   283     iBitmapHandle = KErrNotFound;
       
   284     iMaskHandle = KErrNotFound;
       
   285     
       
   286     iTextInTitlePane = EFalse;
       
   287     
       
   288     __PRINTS("XAI: Rendering bitmap to title pane - done");
       
   289     }
       
   290 
       
   291 TInt CAiStatusPanel::GetTitlePaneSize( TSize& aSize )
       
   292     {
       
   293     TRect titlePaneRect;
       
   294     TBool hasTitlePane = AknLayoutUtils::LayoutMetricsRect(
       
   295         AknLayoutUtils::ETitlePane, titlePaneRect );
       
   296 
       
   297     if ( !hasTitlePane )
       
   298         {
       
   299         return KErrNotFound;
       
   300         }
       
   301 
       
   302     TAknLayoutRect oplogoLayout;
       
   303 
       
   304     if ( AknStatuspaneUtils::StaconPaneActive() )
       
   305         {
       
   306         // stacon
       
   307         oplogoLayout.LayoutRect( titlePaneRect,
       
   308             AknLayoutScalable_Avkon::title_pane_stacon_g2(0).LayoutLine() );
       
   309         }
       
   310     else if ( AknStatuspaneUtils::FlatLayoutActive() )
       
   311         {
       
   312         // flat
       
   313         oplogoLayout.LayoutRect( titlePaneRect,
       
   314             AknLayoutScalable_Avkon::title_pane_stacon_g2(0).LayoutLine() );
       
   315         }
       
   316     else
       
   317         {
       
   318         // usual idle
       
   319         oplogoLayout.LayoutRect( titlePaneRect,
       
   320             AknLayout::Title_pane_elements_Line_1() );
       
   321         }
       
   322 
       
   323     aSize = oplogoLayout.Rect().Size();
       
   324 
       
   325     return KErrNone;
       
   326     }
       
   327 
       
   328 
       
   329 void CAiStatusPanel::UpdatePhoneDisplayInfo( const TTelTitleDisplay& aDisplayInfo )
       
   330     {
       
   331     TBool changed = EFalse;
       
   332     TBool indicatorChanged =
       
   333         aDisplayInfo.iDisplayTag != iDisplayInfo.iDisplayTag ||
       
   334         aDisplayInfo.iLogoHandle != iDisplayInfo.iLogoHandle ||
       
   335         aDisplayInfo.iLogoMaskHandle != iDisplayInfo.iLogoMaskHandle;
       
   336 
       
   337     if ( indicatorChanged )
       
   338         {
       
   339         changed = ETrue;
       
   340         iDisplayInfo.iDisplayTag = aDisplayInfo.iDisplayTag;
       
   341         iDisplayInfo.iLogoHandle = aDisplayInfo.iLogoHandle;
       
   342         iDisplayInfo.iLogoMaskHandle = aDisplayInfo.iLogoMaskHandle;
       
   343         }
       
   344 
       
   345     if ( changed )
       
   346         {
       
   347         TTelTitleDisplay::TDisplayInfoPckg pckg( iDisplayInfo );
       
   348         RProperty::Set(
       
   349             KPSUidTelInformation,
       
   350             KTelDisplayInfo,
       
   351             pckg );
       
   352         }
       
   353     }
       
   354 
       
   355 
       
   356 void CAiStatusPanel::SetNaviPaneTextL( const TDesC& aText )
       
   357     {
       
   358     delete iNaviPaneText;
       
   359     iNaviPaneText = NULL;
       
   360     if ( !AknStatuspaneUtils::FlatLayoutActive() )
       
   361         {
       
   362         HBufC* temp = aText.AllocL();
       
   363         iNaviPaneText = temp;
       
   364         }
       
   365     }
       
   366 
       
   367 
       
   368 
       
   369 void CAiStatusPanel::SetTitlePaneTextL( const TDesC& aText )
       
   370     {
       
   371     HBufC* temp = aText.AllocL();
       
   372     delete iTitlePaneText;
       
   373     iTitlePaneText = temp;
       
   374     }
       
   375 
       
   376 
       
   377 void CAiStatusPanel::SetTitlePaneBitmapL( TInt aBitmapHandle, TInt aMaskHandle )
       
   378     {
       
   379     iBitmapHandle = aBitmapHandle;
       
   380     iMaskHandle = aMaskHandle;
       
   381     }
       
   382 
       
   383 
       
   384 void CAiStatusPanel::RenderTitlePaneL()
       
   385     {
       
   386     RenderTextOnTitlePaneL();
       
   387     RenderBitmapOnTitlePaneL();
       
   388     }
       
   389 
       
   390 
       
   391 void CAiStatusPanel::RenderNaviPaneL()
       
   392     {
       
   393     RenderTextOnNaviPaneL();
       
   394     }
       
   395 
       
   396 void CAiStatusPanel::StopTitlePaneScrollingL()
       
   397     {
       
   398     // stop scrolling
       
   399     if(  iTextInTitlePane && iTitlePane->Text() )
       
   400         {
       
   401         iTitlePane->SetTextL( *iTitlePane->Text(), EFalse );
       
   402         }
       
   403     }
       
   404 
       
   405 void CAiStatusPanel::ScrollTitlePaneTextL()
       
   406     {
       
   407     // start scrolling
       
   408     if ( iTextInTitlePane && iTitlePane->Text() )           
       
   409         {
       
   410         iTitlePane->SetTextL( *iTitlePane->Text(), ETrue );
       
   411         }
       
   412     }
       
   413 
       
   414 void CAiStatusPanel::SetNaviDecoratorObserver( MAknNaviDecoratorObserver* aObserver )
       
   415     {
       
   416     iNaviDecoratorObserver = aObserver;
       
   417     }
       
   418 
       
   419 void CAiStatusPanel::SetTitlePaneObserver( MAknTitlePaneObserver* aObserver )
       
   420     {
       
   421     iTitlePane->SetTitlePaneObserver( aObserver );
       
   422     }
       
   423 
       
   424 TBool CAiStatusPanel::IsKeyLockEnabled()
       
   425     {
       
   426     TInt value;
       
   427     TInt err = RProperty::Get(KPSUidAvkonDomain, KAknKeyguardStatus, value);
       
   428     if ( err != KErrNone )
       
   429         return EFalse;
       
   430     switch( value )
       
   431         {
       
   432         case EKeyguardLocked:
       
   433         case EKeyguardAutolockEmulation:
       
   434             return ETrue;
       
   435         case EKeyguardNotActive:
       
   436         default:
       
   437             return EFalse;
       
   438         }
       
   439     }
       
   440