uifw/AvKon/src/AknPreviewPopUpController.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
child 14 3320e4e6e8bb
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  Preview pop-up controller.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AknPreviewPopUpController.h"
       
    21 #include "AknPreviewPopUpContentProvider.h"
       
    22 #include "AknPreviewPopUp.h"
       
    23 #include <AknUtils.h>
       
    24 #include <aknappui.h>
       
    25 #include <AknSgcc.h>
       
    26 #include <w32std.h>
       
    27 #include <aknlayoutscalable_avkon.cdl.h>
       
    28 #include <layoutmetadata.cdl.h>
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt KDefaultPopUpShowDelay = 1000000;
       
    32 const TInt KDefaultPopUpHideDelay = 10000000;
       
    33 const TInt KObserverArrayGranularity = 1;
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CAknPreviewPopUpController::NewL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CAknPreviewPopUpController* CAknPreviewPopUpController::NewL(
       
    42         CCoeControl& aContent, 
       
    43         MAknPreviewPopUpContentProvider& aContentProvider )
       
    44     {
       
    45     return CAknPreviewPopUpController::NewL( aContent, 
       
    46                                              aContentProvider, 
       
    47                                              ELayoutDefault );
       
    48     }
       
    49 
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CAknPreviewPopUpController::NewL
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CAknPreviewPopUpController* CAknPreviewPopUpController::NewL(
       
    56         CCoeControl& aContent )
       
    57     {
       
    58     return CAknPreviewPopUpController::NewL( aContent, ELayoutDefault);
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CAknPreviewPopUpController::NewL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CAknPreviewPopUpController* CAknPreviewPopUpController::NewL(
       
    67         CCoeControl& aContent, 
       
    68         MAknPreviewPopUpContentProvider& aContentProvider,
       
    69         const TInt aStyle )
       
    70     {
       
    71     CAknPreviewPopUpController* self = new ( ELeave ) CAknPreviewPopUpController(
       
    72         &aContentProvider );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL( aContent, aStyle );
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CAknPreviewPopUpController::NewL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C CAknPreviewPopUpController* CAknPreviewPopUpController::NewL( 
       
    85         CCoeControl& aContent,
       
    86         const TInt aStyle )
       
    87     {
       
    88     CAknPreviewPopUpController* self = new ( ELeave ) CAknPreviewPopUpController(
       
    89         NULL );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL( aContent, aStyle );
       
    92     CleanupStack::Pop( self );        
       
    93     return self;        
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CAknPreviewPopUpController::CAknPreviewPopUpController
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CAknPreviewPopUpController::CAknPreviewPopUpController(
       
   102         MAknPreviewPopUpContentProvider* aContentProvider )
       
   103     : CTimer( CActive::EPriorityStandard ),
       
   104       iContentProvider( aContentProvider ),
       
   105       iPopUpShowDelay( KDefaultPopUpShowDelay ),
       
   106       iPopUpHideDelay( KDefaultPopUpHideDelay ),
       
   107       iObservers( KObserverArrayGranularity ),
       
   108       iResetting( EFalse )
       
   109     {
       
   110         
       
   111     }
       
   112 
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CAknPreviewPopUpController::ConstructL
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CAknPreviewPopUpController::ConstructL( CCoeControl& aContent, 
       
   119                                              const TInt aStyle )
       
   120 
       
   121     {
       
   122     iPopUp = CAknPreviewPopUp::NewL( aContent, *this, aStyle );
       
   123     CTimer::ConstructL();
       
   124     CActiveScheduler::Add( this );
       
   125     }
       
   126 
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CAknPreviewPopUpController::~CAknPreviewPopUpController
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 CAknPreviewPopUpController::~CAknPreviewPopUpController()
       
   133     {
       
   134     Cancel();
       
   135     delete iPopUp;
       
   136     iObservers.Reset();
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CAknPreviewPopUpController::ContentSizeInLayout
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 EXPORT_C CAknPreviewPopUpController::TAknPreviewPopUpContentSize 
       
   145     CAknPreviewPopUpController::ContentSizeInLayout()
       
   146     {
       
   147     // feature removed
       
   148     return CAknPreviewPopUpController::ELarge;        
       
   149     }
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CAknPreviewPopUpController::SetPopUpShowDelay
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 EXPORT_C void CAknPreviewPopUpController::SetPopUpShowDelay(
       
   157         const TTimeIntervalMicroSeconds32& aDelay )
       
   158     {
       
   159     iPopUpShowDelay = aDelay;
       
   160     }
       
   161 
       
   162     
       
   163  // -----------------------------------------------------------------------------
       
   164 // CAknPreviewPopUpController::SetPopUpHideDelay
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 EXPORT_C void CAknPreviewPopUpController::SetPopUpHideDelay(
       
   168         const TTimeIntervalMicroSeconds32& aDelay )
       
   169     {
       
   170     iPopUpHideDelay = aDelay;
       
   171     }
       
   172 
       
   173    
       
   174 // -----------------------------------------------------------------------------
       
   175 // CAknPreviewPopUpController::ShowPopUp
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 EXPORT_C void CAknPreviewPopUpController::ShowPopUp()
       
   179     {
       
   180     Cancel();
       
   181     UpdateContentSize();
       
   182     iState = EShowing;
       
   183     After( iPopUpShowDelay );
       
   184     }
       
   185 
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CAknPreviewPopUpController::HidePopUp
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 EXPORT_C void CAknPreviewPopUpController::HidePopUp()
       
   192     {
       
   193     Cancel();
       
   194     iPopUp->Hide();
       
   195     }
       
   196 
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CAknPreviewPopUpController::ContentReady
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 EXPORT_C void CAknPreviewPopUpController::ContentReady()
       
   203     {
       
   204     TRequestStatus* status = &iStatus;
       
   205     User::RequestComplete( status, KErrNone );
       
   206     }
       
   207 
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CAknPreviewPopUpController::SetPosition
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 EXPORT_C void CAknPreviewPopUpController::SetPosition( const TPoint& aPoint )
       
   214     {
       
   215     if ( !( iPopUp->Flags() & EFixedMode ) )
       
   216         {
       
   217         TPoint askedPoint( aPoint );
       
   218         TSize popupSize( iPopUp->MinimumSize() );
       
   219         
       
   220         // if popup's position is to be mirrored then open it right from the asked
       
   221         // location
       
   222         if ( ( iPopUp->Flags() & EAutoMirror ) && AknLayoutUtils::LayoutMirrored() )
       
   223             {
       
   224             askedPoint.iX += popupSize.iWidth;
       
   225             }
       
   226         
       
   227         TBool resize = EFalse;
       
   228 
       
   229         if ( popupSize != iPopUp->Size() )
       
   230             {
       
   231             resize = ETrue;
       
   232             }
       
   233 
       
   234         // allowed rect
       
   235         TRect clientRect;
       
   236         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect );
       
   237         
       
   238         // Control is allowed to be on top of the status pane but it cannot
       
   239         // overlay either stacon pane or control pane.
       
   240         
       
   241         //switch ( iAvkonAppUi->StatusPane()->CurrentLayoutResId() )
       
   242         CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
       
   243         TInt currentStatusPaneLayoutResId = 0;
       
   244         if (statusPane)
       
   245             {
       
   246             currentStatusPaneLayoutResId = statusPane->CurrentLayoutResId();
       
   247             }
       
   248         else
       
   249             {
       
   250             // If this app does not have statuspane, then we ask the layout from AknCapServer.
       
   251             currentStatusPaneLayoutResId = CAknSgcClient::CurrentStatuspaneResource();        
       
   252             }
       
   253             
       
   254         switch ( currentStatusPaneLayoutResId )
       
   255             {
       
   256             case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT:
       
   257             case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT:
       
   258             case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_RIGHT:
       
   259             case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_LEFT:
       
   260             case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT:
       
   261             case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT:
       
   262                 break;
       
   263                 
       
   264             default:
       
   265                 TRect statusPaneRect;
       
   266                 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, 
       
   267                                                    statusPaneRect );
       
   268 
       
   269                 clientRect.BoundingRect( statusPaneRect );
       
   270             }
       
   271 
       
   272         TPoint finalPosition;
       
   273 
       
   274         // resize if the popup is too wide
       
   275         if ( popupSize.iWidth > clientRect.Width() )
       
   276             {
       
   277             resize = ETrue;
       
   278             popupSize.iWidth = clientRect.Width();
       
   279             }
       
   280 
       
   281         // resize if the popup is too tall
       
   282         if ( popupSize.iHeight > clientRect.Height() )
       
   283         	{
       
   284             resize = ETrue;
       
   285             popupSize.iHeight = clientRect.Height();
       
   286         	}
       
   287 
       
   288         // default horizontal position is left from the given point
       
   289         if ( askedPoint.iX - popupSize.iWidth >= clientRect.iTl.iX )
       
   290             {
       
   291             finalPosition.iX = askedPoint.iX - popupSize.iWidth;
       
   292             }
       
   293         else
       
   294             {
       
   295             // outside left border, move to left border
       
   296             finalPosition.iX = clientRect.iTl.iX;
       
   297             }
       
   298 
       
   299         // check the right border
       
   300         if ( finalPosition.iX + popupSize.iWidth > clientRect.iBr.iX )
       
   301             {
       
   302             finalPosition.iX = clientRect.iBr.iX - popupSize.iWidth;
       
   303             }
       
   304 
       
   305         // default vertical position is up from the given point
       
   306         // coordinates grow from top to bottom
       
   307         if ( askedPoint.iY > clientRect.iTl.iY )
       
   308             {
       
   309             finalPosition.iY = askedPoint.iY;
       
   310             }
       
   311         else
       
   312             {
       
   313             // outside top border, move to top border
       
   314             finalPosition.iY = clientRect.iTl.iY;
       
   315             }
       
   316 
       
   317         // outside bottom border, move to bottom border
       
   318         if ( ( askedPoint.iY + popupSize.iHeight ) > clientRect.iBr.iY )
       
   319             {
       
   320             finalPosition.iY = clientRect.iBr.iY - popupSize.iHeight;
       
   321             }
       
   322 
       
   323         if ( resize )
       
   324             {
       
   325             iPopUp->SetSize( popupSize );
       
   326             }
       
   327 
       
   328         iPopUp->SetPosition( finalPosition );
       
   329         }
       
   330     }
       
   331 
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CAknPreviewPopUpController::SetPositionByHighlight
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 EXPORT_C void CAknPreviewPopUpController::SetPositionByHighlight( 
       
   338     const TRect& aHighlightRect )
       
   339     {
       
   340     if ( !( iPopUp->Flags() & EFixedMode ) )
       
   341         {
       
   342         TRect rect( AknLayoutUtils::HighlightBasedRect( aHighlightRect, iPopUp ) );
       
   343 
       
   344         // Call SetRect only when truly necessary in order to avoid unnecessary 
       
   345         // SizeChanged calls in the pop-up side.
       
   346         if ( rect.Size() != iPopUp->Size() )
       
   347             {
       
   348             iPopUp->SetRect( rect );
       
   349             }
       
   350         else
       
   351             {
       
   352             iPopUp->SetPosition( rect.iTl );
       
   353             }
       
   354         }
       
   355     }
       
   356 
       
   357     
       
   358 // -----------------------------------------------------------------------------
       
   359 // CAknPreviewPopUpController::AddObserverL
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 EXPORT_C void CAknPreviewPopUpController::AddObserverL(
       
   363         const MAknPreviewPopUpObserver& aObserver )
       
   364     {
       
   365     iObservers.InsertInAddressOrderL( &aObserver );
       
   366     }
       
   367 
       
   368         
       
   369 // -----------------------------------------------------------------------------
       
   370 // CAknPreviewPopUpController::RemoveObserver
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 EXPORT_C void CAknPreviewPopUpController::RemoveObserver(
       
   374         const MAknPreviewPopUpObserver& aObserver )
       
   375     {
       
   376     TInt index = iObservers.FindInAddressOrder( &aObserver );
       
   377     
       
   378     if ( index != KErrNotFound )
       
   379         {
       
   380         iObservers.Remove( index );
       
   381         }
       
   382     }
       
   383 
       
   384         
       
   385 // -----------------------------------------------------------------------------
       
   386 // CAknPreviewPopUpController::UpdateContentSize
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 EXPORT_C void CAknPreviewPopUpController::UpdateContentSize()
       
   390     {
       
   391     TSize popupSize( iPopUp->MinimumSize() );
       
   392 
       
   393     if ( popupSize != iPopUp->Size() )
       
   394         {
       
   395         iPopUp->SetSize( popupSize );
       
   396         }
       
   397     }
       
   398 
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CAknPreviewPopUpController::Size
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 EXPORT_C TSize CAknPreviewPopUpController::Size() const
       
   405     {
       
   406     return iPopUp->Size();
       
   407     }
       
   408 
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // CAknPreviewPopUpController::SetHeadingTextL
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 EXPORT_C void CAknPreviewPopUpController::SetHeadingTextL( const TDesC& aText )
       
   415     {
       
   416     iPopUp->SetHeadingTextL( aText );
       
   417     }
       
   418 
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CAknPreviewPopUpController::NotifyObservers
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CAknPreviewPopUpController::NotifyObservers(
       
   425         MAknPreviewPopUpObserver::TPreviewPopUpEvent aEvent )
       
   426     {
       
   427     for ( TInt i = 0; i < iObservers.Count(); ++i )
       
   428         {
       
   429         TRAP_IGNORE( iObservers[i]->HandlePreviewPopUpEventL( this, aEvent ) );
       
   430         }
       
   431     }
       
   432 
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CAknPreviewPopUpController::RunL
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CAknPreviewPopUpController::RunL()
       
   439     {
       
   440     switch ( iState )
       
   441         {
       
   442         case EShowing:
       
   443             if ( iContentProvider )
       
   444                 {
       
   445                 iState = EBuildingContent;
       
   446                 iStatus = KRequestPending;
       
   447                 SetActive();
       
   448                 iContentProvider->StartContentBuildingL();
       
   449                 }
       
   450             else
       
   451                 {
       
   452                 iPopUp->Show();
       
   453                 
       
   454                 if ( iPopUpHideDelay.Int() > 0 && 
       
   455                      !( iPopUp->Flags() & EPermanentMode ) )
       
   456                     {
       
   457                     iState = EHiding;
       
   458                     After( iPopUpHideDelay );
       
   459                     }
       
   460                 }
       
   461             break;
       
   462             
       
   463         case EHiding:
       
   464             iPopUp->Hide();
       
   465             break;
       
   466             
       
   467         case EBuildingContent:
       
   468             iPopUp->Show();
       
   469 
       
   470             if ( iPopUpHideDelay.Int() > 0 && 
       
   471                  !( iPopUp->Flags() & EPermanentMode ) )
       
   472                 {
       
   473                 iState = EHiding;
       
   474                 After( iPopUpHideDelay );
       
   475                 }
       
   476             break;
       
   477             
       
   478         default:
       
   479             User::Panic( _L( "Preview pop-up" ), KErrUnknown );
       
   480         }
       
   481     }
       
   482 
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // CAknPreviewPopUpController::DoCancel
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 void CAknPreviewPopUpController::DoCancel()
       
   489     {
       
   490     if ( iState == EBuildingContent )
       
   491         {
       
   492         iContentProvider->CancelContentBuilding();
       
   493         if ( iStatus.Int() == KRequestPending )
       
   494             {
       
   495             TRequestStatus* status = &iStatus;
       
   496             User::RequestComplete( status, KErrCancel );    
       
   497             }
       
   498         }
       
   499     else
       
   500         {
       
   501         CTimer::DoCancel();
       
   502 
       
   503         if(iResetting)
       
   504         	{       	
       
   505         	iResetting = EFalse;
       
   506         	}
       
   507         else
       
   508         	{
       
   509         	iPopUp->Hide();	
       
   510         	}
       
   511         }
       
   512     }
       
   513 
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // CAknPreviewPopUpController::ResetTimer
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 EXPORT_C void CAknPreviewPopUpController::ResetTimer()
       
   520     {
       
   521 	iResetting = ETrue;
       
   522 	Cancel();
       
   523 	After( iPopUpHideDelay );
       
   524     }
       
   525 
       
   526 
       
   527 // -----------------------------------------------------------------------------
       
   528 // CAknPreviewPopUpController::RunError
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 TInt CAknPreviewPopUpController::RunError( TInt /*aError*/ )
       
   532     {
       
   533     return KErrNone;
       
   534     }
       
   535     
       
   536 //  End of File