uifw/EikStd/coctlsrc/aknstyluspopupmenu.cpp
branchRCL_3
changeset 4 8ca85d2f0db7
parent 0 2f259fa3e83a
child 15 08e69e956a8c
equal deleted inserted replaced
0:2f259fa3e83a 4:8ca85d2f0db7
     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".
   117 // Destructor
   117 // Destructor
   118 // ---------------------------------------------------------------------------
   118 // ---------------------------------------------------------------------------
   119 //
   119 //
   120 CAknStylusPopUpMenu::~CAknStylusPopUpMenu()
   120 CAknStylusPopUpMenu::~CAknStylusPopUpMenu()
   121     {
   121     {
       
   122     iContent->SetObserver(NULL);
   122     if ( iIsDeleted )
   123     if ( iIsDeleted )
   123         {
   124         {
   124         *iIsDeleted = ETrue;
   125         *iIsDeleted = ETrue;
   125         iIsDeleted = NULL;
   126         iIsDeleted = NULL;
   126         }
   127         }
   221 
   222 
   222 // ---------------------------------------------------------------------------
   223 // ---------------------------------------------------------------------------
   223 // CAknStylusPopUpMenu::SetPosition 
   224 // CAknStylusPopUpMenu::SetPosition 
   224 // ---------------------------------------------------------------------------
   225 // ---------------------------------------------------------------------------
   225 //
   226 //
   226 EXPORT_C void CAknStylusPopUpMenu::SetPosition( const TPoint& aPoint, TPositionType aPosType )
   227 EXPORT_C void CAknStylusPopUpMenu::SetPosition( const TPoint& aPoint,
       
   228                                                 TPositionType aPosType )
   227     {
   229     {
   228     TPoint adjustedPoint( aPoint );
   230     TPoint adjustedPoint( aPoint );
   229     if ( !iController )
   231     if ( !iController )
   230         {
   232         {
   231         iPosition = aPoint;
   233         iPosition = aPoint;
   232         iPositionType = aPosType;
   234         iPositionType = aPosType;
   233         return;
   235         return;
   234         }
   236         }
       
   237 
   235     iController->UpdateContentSize(); 
   238     iController->UpdateContentSize(); 
   236     TSize menuSize = iController->Size();
   239     TSize menuSize = iController->Size();
   237 	// calculate to right-top corner by aPosType and popup menu size
   240 
       
   241 	// Calculate the position to right-top corner by aPosType and
       
   242     // popup menu size. Add also a margin between the screen borders and the
       
   243     // popup if the popup is too close to screen border.
       
   244     TBool layoutMirrored( AknLayoutUtils::LayoutMirrored() );
       
   245     TRect screenRect;
       
   246     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen,
       
   247                                        screenRect );
       
   248     
       
   249     // Margin is read from the popup window's layout data
       
   250     // (left parameter used).
       
   251     TAknWindowLineLayout popupWindowLayout(
       
   252         AknLayoutScalable_Avkon::popup_touch_menu_window( 0 ).LayoutLine() );
       
   253     TInt windowMargin = layoutMirrored ? popupWindowLayout.ir :
       
   254                                          popupWindowLayout.il;
       
   255 
   238     switch ( aPosType )	
   256     switch ( aPosType )	
   239         {
   257         {
   240         case EPositionTypeRightTop: 
   258         case EPositionTypeRightTop:
       
   259             {
   241             break;
   260             break;
       
   261             }
       
   262 
   242         case EPositionTypeLeftTop:
   263         case EPositionTypeLeftTop:
   243             if( AknLayoutUtils::LayoutMirrored() ) 
   264             {
   244                 {
   265             if ( !layoutMirrored ) 
   245                 adjustedPoint.iX -= menuSize.iWidth;
       
   246                 }
       
   247             else
       
   248                 {
   266                 {
   249                 adjustedPoint.iX += menuSize.iWidth;
   267                 adjustedPoint.iX += menuSize.iWidth;
   250                 }
   268                 }
   251             break;   
   269 
       
   270             break;
       
   271             }
       
   272 
   252         case EPositionTypeRightBottom:
   273         case EPositionTypeRightBottom:
       
   274             {
   253             adjustedPoint.iY -= menuSize.iHeight;
   275             adjustedPoint.iY -= menuSize.iHeight;
       
   276 
   254             break;
   277             break;
   255         case EPositionTypeLeftBottom: 
   278             }
   256             if( AknLayoutUtils::LayoutMirrored() ) 
   279 
   257                 {
   280         case EPositionTypeLeftBottom:
   258                 adjustedPoint.iX -= menuSize.iWidth;
   281             {
   259                 }
   282             if ( !layoutMirrored ) 
   260             else
       
   261                 {
   283                 {
   262                 adjustedPoint.iX += menuSize.iWidth;
   284                 adjustedPoint.iX += menuSize.iWidth;
   263                 }
   285                 }
       
   286 
   264             adjustedPoint.iY -= menuSize.iHeight;
   287             adjustedPoint.iY -= menuSize.iHeight;
   265             break;    
   288 
       
   289             break;
       
   290             }
       
   291 
   266         default:
   292         default:
   267             break;  
   293             {
   268     
   294             break;
   269         }
   295             }
       
   296         }
       
   297 
       
   298     // Check if margins need to be added.
       
   299     TInt xLeftPos( layoutMirrored ? adjustedPoint.iX :
       
   300                                     adjustedPoint.iX - menuSize.iWidth );
       
   301     TInt xRightPos( layoutMirrored ? adjustedPoint.iX + menuSize.iWidth :
       
   302                                      adjustedPoint.iX );
       
   303     TInt xPosRightMargin( screenRect.iBr.iX - windowMargin );
       
   304     TInt xPosBottomMargin( screenRect.iBr.iY - windowMargin );
       
   305 
       
   306     if ( xLeftPos < windowMargin )
       
   307         {
       
   308         // Too close to the left side of the screen.
       
   309         adjustedPoint.iX = windowMargin + menuSize.iWidth;
       
   310         }
       
   311     else if ( xRightPos > xPosRightMargin )
       
   312         {
       
   313         // Too close to the right side of the screen.
       
   314         if ( layoutMirrored )
       
   315             {
       
   316             // In mirrored layout a left-top position must be provided
       
   317             // for the preview popup controller.
       
   318             adjustedPoint.iX = xPosRightMargin - menuSize.iWidth;
       
   319             }
       
   320         else
       
   321             {
       
   322             adjustedPoint.iX = xPosRightMargin;
       
   323             }
       
   324         }
       
   325 
       
   326     if ( adjustedPoint.iY < windowMargin )
       
   327         {
       
   328         // Too close to the top border of the screen.
       
   329         adjustedPoint.iY = windowMargin;
       
   330         }
       
   331     else if ( adjustedPoint.iY + menuSize.iHeight > xPosBottomMargin )
       
   332         {
       
   333         // Too close to the bottom border of the screen.
       
   334         adjustedPoint.iY = xPosBottomMargin - menuSize.iHeight;
       
   335         }
       
   336     
   270     iPosition = adjustedPoint;           
   337     iPosition = adjustedPoint;           
   271     iController->SetPosition( adjustedPoint ); 
   338     iController->SetPosition( adjustedPoint ); 
   272     }
   339     }
   273 
   340 
   274 
   341