uifw/AvKon/src/AknPreviewPopUpController.cpp
branchRCL_3
changeset 55 aecbbf00d063
parent 4 8ca85d2f0db7
child 56 d48ab3b357f1
equal deleted inserted replaced
51:fcdfafb36fe7 55:aecbbf00d063
     1 /*
     1 /*
     2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2009 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".
   229         if ( popupSize != iPopUp->Size() )
   229         if ( popupSize != iPopUp->Size() )
   230             {
   230             {
   231             resize = ETrue;
   231             resize = ETrue;
   232             }
   232             }
   233 
   233 
   234         // Adjust the position if the popup would go outside of the screen
   234         // allowed rect
   235         // rect with the given position.
   235         TRect clientRect;
   236         TRect screenRect;
   236         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect );
   237         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
   237         
   238         TInt screenWidth( screenRect.Width() );
   238         // Control is allowed to be on top of the status pane but it cannot
   239         TInt screenHeight( screenRect.Height() );
   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             }
   240 
   271 
   241         TPoint finalPosition;
   272         TPoint finalPosition;
   242 
   273 
   243         // Resize if the popup is too wide.
   274         // resize if the popup is too wide
   244         if ( popupSize.iWidth > screenWidth )
   275         if ( popupSize.iWidth > clientRect.Width() )
   245             {
   276             {
   246             resize = ETrue;
   277             resize = ETrue;
   247             popupSize.iWidth = screenWidth;
   278             popupSize.iWidth = clientRect.Width();
   248             }
   279             }
   249 
   280 
   250         // Resize if the popup is too tall.
   281         // resize if the popup is too tall
   251         if ( popupSize.iHeight > screenHeight )
   282         if ( popupSize.iHeight > clientRect.Height() )
   252             {
   283         	{
   253             resize = ETrue;
   284             resize = ETrue;
   254             popupSize.iHeight = screenHeight;
   285             popupSize.iHeight = clientRect.Height();
   255             }
   286         	}
   256 
   287 
   257         // Default horizontal position is left from the given point.
   288         // :winterTTr:
   258         if ( askedPoint.iX - popupSize.iWidth >= screenRect.iTl.iX )
   289         // Auto mirror left <==> right if there is space on the other side.
   259             {
   290         // Let the popup not drop out under the finger, if possible
   260             finalPosition.iX = askedPoint.iX - popupSize.iWidth;
   291         if ( ( askedPoint.iX <= clientRect.iBr.iX ) 
   261             }
   292         	 && ( askedPoint.iX - popupSize.iWidth >=  clientRect.iTl.iX ) )
   262         else
   293         	{
   263             {
   294         	finalPosition.iX = askedPoint.iX - popupSize.iWidth ;
   264             // outside left border, move to left border
   295         	}
   265             finalPosition.iX = screenRect.iTl.iX;
   296         else if ( askedPoint.iX > clientRect.iBr.iX )
   266             }
   297         	{
   267 
   298         	if ( askedPoint.iX - popupSize.iWidth * 2 >= clientRect.iTl.iX )
   268         // Check the right border.
   299         		{
   269         if ( finalPosition.iX + popupSize.iWidth > screenRect.iBr.iX )
   300         		finalPosition.iX = askedPoint.iX - popupSize.iWidth * 2 ;
   270             {
   301         		}
   271             finalPosition.iX = screenRect.iBr.iX - popupSize.iWidth;
   302         	else
   272             }
   303         		{
   273 
   304         		finalPosition.iX = clientRect.iBr.iX - popupSize.iWidth ;
   274         // Default vertical position is up from the given point.
   305         		}
   275         // Coordinates grow from top to bottom.
   306         	}
   276         if ( askedPoint.iY > screenRect.iTl.iY )
   307         else // askedPoint.iX - popupSize.iWidth <  clientRect.iTl.iX
   277             {
   308         	{
   278             finalPosition.iY = askedPoint.iY;
   309         	if ( askedPoint.iX + popupSize.iWidth <= clientRect.iBr.iX )
   279             }
   310         		{
   280         else
   311         		finalPosition.iX = askedPoint.iX;
   281             {
   312         		}
   282             // Outside top border, move to top border.
   313         	else
   283             finalPosition.iY = screenRect.iTl.iY;
   314         		{
   284             }
   315         		finalPosition.iX = clientRect.iTl.iX;
   285 
   316         		}
   286         // Outside bottom border, move to bottom border.
   317         	
   287         if ( ( askedPoint.iY + popupSize.iHeight ) > screenRect.iBr.iY )
   318         	}
   288             {
   319         
   289             finalPosition.iY = screenRect.iBr.iY - popupSize.iHeight;
   320         // :winterTTr:
   290             }
   321         // Auto mirror top <==> buttom if there is space on the other side.
   291 
   322         // Let the popup not drop out under the finger, if possible
       
   323         if ( askedPoint.iY >= clientRect.iTl.iY 
       
   324         		&& askedPoint.iY + popupSize.iHeight <= clientRect.iBr.iY )
       
   325         	{
       
   326         	finalPosition.iY = askedPoint.iY;
       
   327         	}
       
   328         else if ( askedPoint.iY < clientRect.iTl.iY )
       
   329         	{
       
   330         	if ( askedPoint.iY + popupSize.iHeight *2 <= clientRect.iBr.iY )
       
   331         		{
       
   332         		finalPosition.iY = askedPoint.iY + popupSize.iHeight;
       
   333         		}
       
   334         	else
       
   335         		{
       
   336         		finalPosition.iY = clientRect.iTl.iY;
       
   337         		}
       
   338         	}
       
   339         else // askedPoint.iY + popupSize.iHeight > clientRect.iBr.iY
       
   340         	{
       
   341         	if ( askedPoint.iY - popupSize.iHeight >= clientRect.iTl.iY )
       
   342         		{
       
   343         		finalPosition.iY = askedPoint.iY - popupSize.iHeight;
       
   344         		}
       
   345         	else
       
   346         		{
       
   347         		finalPosition.iY = clientRect.iBr.iY - popupSize.iHeight;
       
   348         		}
       
   349         	
       
   350         	}
       
   351         
   292         if ( resize )
   352         if ( resize )
   293             {
   353             {
   294             iPopUp->SetSize( popupSize );
   354             iPopUp->SetSize( popupSize );
   295             }
   355             }
   296 
   356