uifw/EikStd/coctlsrc/aknstyluspopupmenu.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
child 64 85902f042028
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
     1 /*
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22 #include <barsread.h>
    22 #include <barsread.h>
    23 #include <aknlayoutscalable_avkon.cdl.h>
    23 #include <aknlayoutscalable_avkon.cdl.h>
    24 #include <eikapp.h>
    24 #include <eikapp.h>
    25 #include <aknappui.h>
    25 #include <aknappui.h>
    26 #include <AknDef.h>
    26 #include <AknDef.h>
    27 
    27 #include <touchfeedback.h>
       
    28 #include <akntranseffect.h>
       
    29 #include <akntransitionutils.h>
    28 #include "aknstyluspopupmenu.h"
    30 #include "aknstyluspopupmenu.h"
    29 #include "aknstyluspopupmenucontent.h"
    31 #include "aknstyluspopupmenucontent.h"
    30 
    32 
    31 const TInt KDefaultPopUpShowDelay = 0;
    33 const TInt KDefaultPopUpShowDelay = 0;
    32 const TInt KDefaultPopUpHideDelay = 6000000; // 6 seconds
    34 const TInt KDefaultPopUpHideDelay = 6000000; // 6 seconds
    42 // Default constructor
    44 // Default constructor
    43 // ---------------------------------------------------------------------------
    45 // ---------------------------------------------------------------------------
    44 //
    46 //
    45 CAknStylusPopUpMenu::CAknStylusPopUpMenu( MEikMenuObserver* aObserver, 
    47 CAknStylusPopUpMenu::CAknStylusPopUpMenu( MEikMenuObserver* aObserver, 
    46     const TPoint& aPoint,
    48     const TPoint& aPoint,
    47     CAknPreviewPopUpController* aPopup ) 
    49     CAknPreviewPopUpController* aPopup,
       
    50     const TInt aFlags )
    48     : iPosition ( aPoint ),
    51     : iPosition ( aPoint ),
    49      iMenuObserver( aObserver ),
    52      iMenuObserver( aObserver ),
    50      iPreviewPopup( aPopup ),
    53      iPreviewPopup( aPopup ),
    51      iPositionType( EPositionTypeLeftTop )
    54      iPositionType( EPositionTypeLeftTop ),
       
    55      iModeFlags ( aFlags )
    52     {
    56     {
    53     }
    57     }
    54 
    58 
    55 
    59 
    56 // ---------------------------------------------------------------------------
    60 // ---------------------------------------------------------------------------
    79                                                             aPopup );
    83                                                             aPopup );
    80     CleanupStack::Pop( self );
    84     CleanupStack::Pop( self );
    81     return self;
    85     return self;
    82     }
    86     }
    83 
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CAknStylusPopUpMenu::NewL
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 CAknStylusPopUpMenu* CAknStylusPopUpMenu::NewL( MEikMenuObserver* aObserver,
       
    93         const TPoint& aPoint,
       
    94         CAknPreviewPopUpController* aPopup,
       
    95         const TInt aFlags )
       
    96     {
       
    97     CAknStylusPopUpMenu* self = new ( ELeave ) CAknStylusPopUpMenu( aObserver,
       
    98                                                                     aPoint,
       
    99                                                                     aPopup,
       
   100                                                                     aFlags );
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL();
       
   103     CleanupStack::Pop( self );
       
   104     return self;
       
   105     }
    84 
   106 
    85 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
    86 // CAknStylusPopUpMenu::NewL
   108 // CAknStylusPopUpMenu::NewL
    87 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
    88 //
   110 //
   117 // Destructor
   139 // Destructor
   118 // ---------------------------------------------------------------------------
   140 // ---------------------------------------------------------------------------
   119 //
   141 //
   120 CAknStylusPopUpMenu::~CAknStylusPopUpMenu()
   142 CAknStylusPopUpMenu::~CAknStylusPopUpMenu()
   121     {
   143     {
       
   144     if ( iContent )
       
   145         {
       
   146         iContent->SetObserver(NULL);
       
   147         }
   122     if ( iIsDeleted )
   148     if ( iIsDeleted )
   123         {
   149         {
   124         *iIsDeleted = ETrue;
   150         *iIsDeleted = ETrue;
   125         iIsDeleted = NULL;
   151         iIsDeleted = NULL;
   126         }
   152         }
   170 // CAknStylusPopUpMenu::ShowMenu
   196 // CAknStylusPopUpMenu::ShowMenu
   171 // ---------------------------------------------------------------------------
   197 // ---------------------------------------------------------------------------
   172 //
   198 //
   173 EXPORT_C void CAknStylusPopUpMenu::ShowMenu()
   199 EXPORT_C void CAknStylusPopUpMenu::ShowMenu()
   174     {
   200     {
   175     TRAPD( err, 
   201     // if contoller exists, re-use it .
   176            iController = CAknPreviewPopUpController::NewL( *iContent,
   202     if ( !iController )
   177                    CAknPreviewPopUpController::ELayoutSubMenu | 
   203         {
   178                    CAknPreviewPopUpController::EAutoMirror |
   204         TInt err ( KErrNone );
   179                    CAknPreviewPopUpController::EDontClose ) );
   205 
   180     if ( err )
   206         if ( iModeFlags & EConsumeKeyEvents )
   181         {
   207             {
   182         return;
   208             TRAP( err, iController = CAknPreviewPopUpController::NewL(
   183         }
   209                     *iContent,
       
   210                     CAknPreviewPopUpController::ELayoutSubMenu |
       
   211                     CAknPreviewPopUpController::EAutoMirror |
       
   212                     CAknPreviewPopUpController::EDontClose |
       
   213                     CAknPreviewPopUpController::EConsumeKeys ) );
       
   214             }
       
   215         else
       
   216             {
       
   217             TRAP( err, iController = CAknPreviewPopUpController::NewL(
       
   218                     *iContent,
       
   219                     CAknPreviewPopUpController::ELayoutSubMenu |
       
   220                     CAknPreviewPopUpController::EAutoMirror |
       
   221                     CAknPreviewPopUpController::EDontClose ) );
       
   222             }
       
   223         if ( err )
       
   224             {
       
   225             return;
       
   226             }
   184             
   227             
   185     iController->SetPopUpShowDelay( KDefaultPopUpShowDelay );
   228         iController->SetPopUpShowDelay( KDefaultPopUpShowDelay );
   186     iController->SetPopUpHideDelay( KDefaultPopUpHideDelay );
   229         iController->SetPopUpHideDelay( KDefaultPopUpHideDelay );
   187     iContent->Parent()->DrawableWindow()->SetNonFading(ETrue);
   230         }
   188     
   231     
   189     TSize size(iController->Size());
   232     TSize size(iController->Size());
   190     iController->ShowPopUp();
   233     iController->ShowPopUp();
   191 
   234     if ( AknLayoutUtils::PenEnabled() )
       
   235         {
       
   236         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   237         if ( feedback )
       
   238             {
       
   239             TTouchLogicalFeedback feedbackType = ETouchFeedbackPopUp;
       
   240             if ( CAknTransitionUtils::TransitionsEnabled( AknTransEffect::EComponentTransitionsOff ) )
       
   241                 {
       
   242                 feedbackType = ETouchFeedbackOptionsMenuOpened;
       
   243                 }
       
   244             feedback->InstantFeedback(
       
   245                     iContent,
       
   246                     feedbackType,
       
   247                     ETouchFeedbackVibra,
       
   248                     TPointerEvent() );
       
   249             }
       
   250         }
   192     if ( size.iWidth == 0 && size.iHeight == 0 )
   251     if ( size.iWidth == 0 && size.iHeight == 0 )
   193         {
   252         {
   194         if ( iPositionType != KErrNotFound )
   253         if ( iPositionType != KErrNotFound )
   195             {
   254             {
   196             SetPosition( iPosition, TPositionType( iPositionType ) );
   255             SetPosition( iPosition, TPositionType( iPositionType ) );
   221 
   280 
   222 // ---------------------------------------------------------------------------
   281 // ---------------------------------------------------------------------------
   223 // CAknStylusPopUpMenu::SetPosition 
   282 // CAknStylusPopUpMenu::SetPosition 
   224 // ---------------------------------------------------------------------------
   283 // ---------------------------------------------------------------------------
   225 //
   284 //
   226 EXPORT_C void CAknStylusPopUpMenu::SetPosition( const TPoint& aPoint, TPositionType aPosType )
   285 EXPORT_C void CAknStylusPopUpMenu::SetPosition( const TPoint& aPoint,
       
   286                                                 TPositionType aPosType )
   227     {
   287     {
   228     TPoint adjustedPoint( aPoint );
   288     TPoint adjustedPoint( aPoint );
   229     if ( !iController )
   289     if ( !iController )
   230         {
   290         {
   231         iPosition = aPoint;
   291         iPosition = aPoint;
   232         iPositionType = aPosType;
   292         iPositionType = aPosType;
   233         return;
   293         return;
   234         }
   294         }
       
   295 
   235     iController->UpdateContentSize(); 
   296     iController->UpdateContentSize(); 
   236     TSize menuSize = iController->Size();
   297     TSize menuSize = iController->Size();
   237 	// calculate to right-top corner by aPosType and popup menu size
   298 
       
   299 	// Calculate the position to right-top corner by aPosType and
       
   300     // popup menu size. Add also a margin between the screen borders and the
       
   301     // popup if the popup is too close to screen border.
       
   302     TBool layoutMirrored( AknLayoutUtils::LayoutMirrored() );
       
   303     TRect screenRect;
       
   304     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen,
       
   305                                        screenRect );
       
   306     
       
   307     // Margin is read from the popup window's layout data
       
   308     // (left parameter used).
       
   309     TAknWindowLineLayout popupWindowLayout(
       
   310         AknLayoutScalable_Avkon::popup_touch_menu_window( 0 ).LayoutLine() );
       
   311     TInt windowMargin = layoutMirrored ? popupWindowLayout.ir :
       
   312                                          popupWindowLayout.il;
       
   313 
   238     switch ( aPosType )	
   314     switch ( aPosType )	
   239         {
   315         {
   240         case EPositionTypeRightTop: 
   316         case EPositionTypeRightTop:
       
   317             {
   241             break;
   318             break;
       
   319             }
       
   320 
   242         case EPositionTypeLeftTop:
   321         case EPositionTypeLeftTop:
   243             if( AknLayoutUtils::LayoutMirrored() ) 
   322             {
   244                 {
   323             if ( !layoutMirrored ) 
   245                 adjustedPoint.iX -= menuSize.iWidth;
       
   246                 }
       
   247             else
       
   248                 {
   324                 {
   249                 adjustedPoint.iX += menuSize.iWidth;
   325                 adjustedPoint.iX += menuSize.iWidth;
   250                 }
   326                 }
   251             break;   
   327 
       
   328             break;
       
   329             }
       
   330 
   252         case EPositionTypeRightBottom:
   331         case EPositionTypeRightBottom:
       
   332             {
   253             adjustedPoint.iY -= menuSize.iHeight;
   333             adjustedPoint.iY -= menuSize.iHeight;
       
   334 
   254             break;
   335             break;
   255         case EPositionTypeLeftBottom: 
   336             }
   256             if( AknLayoutUtils::LayoutMirrored() ) 
   337 
   257                 {
   338         case EPositionTypeLeftBottom:
   258                 adjustedPoint.iX -= menuSize.iWidth;
   339             {
   259                 }
   340             if ( !layoutMirrored ) 
   260             else
       
   261                 {
   341                 {
   262                 adjustedPoint.iX += menuSize.iWidth;
   342                 adjustedPoint.iX += menuSize.iWidth;
   263                 }
   343                 }
       
   344 
   264             adjustedPoint.iY -= menuSize.iHeight;
   345             adjustedPoint.iY -= menuSize.iHeight;
   265             break;    
   346 
       
   347             break;
       
   348             }
       
   349 
   266         default:
   350         default:
   267             break;  
   351             {
   268     
   352             break;
   269         }
   353             }
       
   354         }
       
   355 
       
   356     // Check if margins need to be added.
       
   357     TInt xLeftPos( layoutMirrored ? adjustedPoint.iX :
       
   358                                     adjustedPoint.iX - menuSize.iWidth );
       
   359     TInt xRightPos( layoutMirrored ? adjustedPoint.iX + menuSize.iWidth :
       
   360                                      adjustedPoint.iX );
       
   361     TInt xPosRightMargin( screenRect.iBr.iX - windowMargin );
       
   362     TInt xPosBottomMargin( screenRect.iBr.iY - windowMargin );
       
   363 
       
   364     if ( xLeftPos < windowMargin )
       
   365         {
       
   366         // Too close to the left side of the screen.
       
   367         adjustedPoint.iX = windowMargin + menuSize.iWidth;
       
   368         }
       
   369     else if ( xRightPos > xPosRightMargin )
       
   370         {
       
   371         // Too close to the right side of the screen.
       
   372         if ( layoutMirrored )
       
   373             {
       
   374             // In mirrored layout a left-top position must be provided
       
   375             // for the preview popup controller.
       
   376             adjustedPoint.iX = xPosRightMargin - menuSize.iWidth;
       
   377             }
       
   378         else
       
   379             {
       
   380             adjustedPoint.iX = xPosRightMargin;
       
   381             }
       
   382         }
       
   383 
       
   384     if ( adjustedPoint.iY < windowMargin )
       
   385         {
       
   386         // Too close to the top border of the screen.
       
   387         adjustedPoint.iY = windowMargin;
       
   388         }
       
   389     else if ( adjustedPoint.iY + menuSize.iHeight > xPosBottomMargin )
       
   390         {
       
   391         // Too close to the bottom border of the screen.
       
   392         adjustedPoint.iY = xPosBottomMargin - menuSize.iHeight;
       
   393         }
       
   394     
   270     iPosition = adjustedPoint;           
   395     iPosition = adjustedPoint;           
   271     iController->SetPosition( adjustedPoint ); 
   396     iController->SetPosition( adjustedPoint ); 
   272     }
   397     }
   273 
   398 
   274 
   399 
   310             iController->HidePopUp();
   435             iController->HidePopUp();
   311             }
   436             }
   312 
   437 
   313         if ( iMenuObserver )
   438         if ( iMenuObserver )
   314             {
   439             {
       
   440             TBool isAlreadySet = iFlags.IsSet( EIdleDisabled );
       
   441 
   315             iFlags.Set( EIdleDisabled );
   442             iFlags.Set( EIdleDisabled );
   316             TBool isDeleted = EFalse;
   443             TBool isDeleted = EFalse;
   317             iIsDeleted = &isDeleted;
   444             iIsDeleted = &isDeleted;
   318 
   445 
       
   446             CleanupStack::PushL( TCleanupItem( CleanLocalRef, this ) );
   319             iMenuObserver->ProcessCommandL( iContent->CurrentCommandId() );
   447             iMenuObserver->ProcessCommandL( iContent->CurrentCommandId() );
   320 
   448             CleanupStack::Pop();
       
   449             
   321             if ( isDeleted )
   450             if ( isDeleted )
   322                 {
   451                 {
   323                 return;
   452                 return;
   324                 }
   453                 }
   325 
   454 
   326             iIsDeleted = NULL;
   455             iIsDeleted = NULL;
   327             iFlags.Clear( EIdleDisabled );
   456             if( !isAlreadySet )
       
   457                 {
       
   458                 iFlags.Clear( EIdleDisabled );
       
   459                 }
   328             }
   460             }
   329 
   461 
   330         StartControllerIdleL();
   462         StartControllerIdleL();
   331         }
   463         }
   332     else if ( aControl && aEventType == EEventRequestExit )
   464     else if ( aControl && aEventType == EEventRequestExit )
   333         {
   465         {
   334         if ( iPreviewPopup )
   466         if ( iPreviewPopup )
   335             {
   467             {
   336             iPreviewPopup->HidePopUp();
   468             iPreviewPopup->HidePopUp();
   337             }
   469             }
       
   470 
   338         if ( iController )
   471         if ( iController )
   339             {
   472             {
   340             iController->HidePopUp();
   473             iController->HidePopUp();
   341             }      
   474             }      
   342 
   475 
   344         }
   477         }
   345     else if ( aControl && aEventType == EEventRequestCancel )
   478     else if ( aControl && aEventType == EEventRequestCancel )
   346         {
   479         {
   347         if ( iMenuObserver )
   480         if ( iMenuObserver )
   348             {
   481             {
       
   482             TBool isAlreadySet = iFlags.IsSet( EIdleDisabled );
       
   483 
   349             iFlags.Set( EIdleDisabled );
   484             iFlags.Set( EIdleDisabled );
   350             iMenuObserver->ProcessCommandL( KErrCancel );
   485             iMenuObserver->ProcessCommandL( KErrCancel );
   351             iFlags.Clear( EIdleDisabled );
   486 
       
   487             if( !isAlreadySet )
       
   488                 {
       
   489                 iFlags.Clear( EIdleDisabled );
       
   490                 }
       
   491 
   352             }
   492             }
   353 
   493 
   354         StartControllerIdleL();
   494         StartControllerIdleL();
   355         }
   495         }
   356     }
   496     }
   376     if ( iController )
   516     if ( iController )
   377         {
   517         {
   378         iController->UpdateContentSize();
   518         iController->UpdateContentSize();
   379         }
   519         }
   380     }
   520     }
       
   521 
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 // CAknStylusPopUpMenu::HideMenu
       
   525 // ---------------------------------------------------------------------------
       
   526 //
       
   527 void CAknStylusPopUpMenu::HideMenu()
       
   528     {
       
   529     if ( iController )
       
   530         {
       
   531         iController->HidePopUp();
       
   532         }
       
   533     }
       
   534 
   381 
   535 
   382 // -----------------------------------------------------------------------------
   536 // -----------------------------------------------------------------------------
   383 // CAknStylusPopUpMenu::StartControllerIdleL
   537 // CAknStylusPopUpMenu::StartControllerIdleL
   384 // -----------------------------------------------------------------------------
   538 // -----------------------------------------------------------------------------
   385 //
   539 //
   422         {
   576         {
   423         delete iController;
   577         delete iController;
   424         iController = NULL;
   578         iController = NULL;
   425         }
   579         }
   426     }
   580     }
       
   581 
       
   582 // -----------------------------------------------------------------------------
       
   583 // CAknStylusPopUpMenu::CleanLocalRef
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 void CAknStylusPopUpMenu::CleanLocalRef( TAny* aParam )
       
   587     {
       
   588     static_cast<CAknStylusPopUpMenu*>( aParam )->iIsDeleted = NULL;
       
   589     }