uifw/AvKon/src/AknPreviewPopUpController.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".
   229         if ( popupSize != iPopUp->Size() )
   229         if ( popupSize != iPopUp->Size() )
   230             {
   230             {
   231             resize = ETrue;
   231             resize = ETrue;
   232             }
   232             }
   233 
   233 
   234         // allowed rect
   234         // Adjust the position if the popup would go outside of the screen
   235         TRect clientRect;
   235         // rect with the given position.
   236         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect );
   236         TRect screenRect;
   237         
   237         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
   238         // Control is allowed to be on top of the status pane but it cannot
   238         TInt screenWidth( screenRect.Width() );
   239         // overlay either stacon pane or control pane.
   239         TInt screenHeight( screenRect.Height() );
   240         
   240 
   241         //switch ( iAvkonAppUi->StatusPane()->CurrentLayoutResId() )
   241         TPoint finalPosition;
   242         CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
   242 
   243         TInt currentStatusPaneLayoutResId = 0;
   243         // Resize if the popup is too wide.
   244         if (statusPane)
   244         if ( popupSize.iWidth > screenWidth )
   245             {
   245             {
   246             currentStatusPaneLayoutResId = statusPane->CurrentLayoutResId();
   246             resize = ETrue;
       
   247             popupSize.iWidth = screenWidth;
       
   248             }
       
   249 
       
   250         // Resize if the popup is too tall.
       
   251         if ( popupSize.iHeight > screenHeight )
       
   252             {
       
   253             resize = ETrue;
       
   254             popupSize.iHeight = screenHeight;
       
   255             }
       
   256 
       
   257         // Default horizontal position is left from the given point.
       
   258         if ( askedPoint.iX - popupSize.iWidth >= screenRect.iTl.iX )
       
   259             {
       
   260             finalPosition.iX = askedPoint.iX - popupSize.iWidth;
   247             }
   261             }
   248         else
   262         else
   249             {
   263             {
   250             // If this app does not have statuspane, then we ask the layout from AknCapServer.
   264             // outside left border, move to left border
   251             currentStatusPaneLayoutResId = CAknSgcClient::CurrentStatuspaneResource();        
   265             finalPosition.iX = screenRect.iTl.iX;
   252             }
   266             }
   253             
   267 
   254         switch ( currentStatusPaneLayoutResId )
   268         // Check the right border.
   255             {
   269         if ( finalPosition.iX + popupSize.iWidth > screenRect.iBr.iX )
   256             case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT:
   270             {
   257             case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT:
   271             finalPosition.iX = screenRect.iBr.iX - popupSize.iWidth;
   258             case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_RIGHT:
   272             }
   259             case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_LEFT:
   273 
   260             case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT:
   274         // Default vertical position is up from the given point.
   261             case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT:
   275         // Coordinates grow from top to bottom.
   262                 break;
   276         if ( askedPoint.iY > screenRect.iTl.iY )
   263                 
   277             {
   264             default:
   278             finalPosition.iY = askedPoint.iY;
   265                 TRect statusPaneRect;
   279             }
   266                 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, 
   280         else
   267                                                    statusPaneRect );
   281             {
   268 
   282             // Outside top border, move to top border.
   269                 clientRect.BoundingRect( statusPaneRect );
   283             finalPosition.iY = screenRect.iTl.iY;
   270             }
   284             }
   271 
   285 
   272         TPoint finalPosition;
   286         // Outside bottom border, move to bottom border.
   273 
   287         if ( ( askedPoint.iY + popupSize.iHeight ) > screenRect.iBr.iY )
   274         // resize if the popup is too wide
   288             {
   275         if ( popupSize.iWidth > clientRect.Width() )
   289             finalPosition.iY = screenRect.iBr.iY - popupSize.iHeight;
   276             {
   290             }
   277             resize = ETrue;
   291 
   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         // :winterTTr:
       
   289         // Auto mirror left <==> right if there is space on the other side.
       
   290         // Let the popup not drop out under the finger, if possible
       
   291         if ( ( askedPoint.iX <= clientRect.iBr.iX ) 
       
   292         	 && ( askedPoint.iX - popupSize.iWidth >=  clientRect.iTl.iX ) )
       
   293         	{
       
   294         	finalPosition.iX = askedPoint.iX - popupSize.iWidth ;
       
   295         	}
       
   296         else if ( askedPoint.iX > clientRect.iBr.iX )
       
   297         	{
       
   298         	if ( askedPoint.iX - popupSize.iWidth * 2 >= clientRect.iTl.iX )
       
   299         		{
       
   300         		finalPosition.iX = askedPoint.iX - popupSize.iWidth * 2 ;
       
   301         		}
       
   302         	else
       
   303         		{
       
   304         		finalPosition.iX = clientRect.iBr.iX - popupSize.iWidth ;
       
   305         		}
       
   306         	}
       
   307         else // askedPoint.iX - popupSize.iWidth <  clientRect.iTl.iX
       
   308         	{
       
   309         	if ( askedPoint.iX + popupSize.iWidth <= clientRect.iBr.iX )
       
   310         		{
       
   311         		finalPosition.iX = askedPoint.iX;
       
   312         		}
       
   313         	else
       
   314         		{
       
   315         		finalPosition.iX = clientRect.iTl.iX;
       
   316         		}
       
   317         	
       
   318         	}
       
   319         
       
   320         // :winterTTr:
       
   321         // Auto mirror top <==> buttom if there is space on the other side.
       
   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         
       
   352         if ( resize )
   292         if ( resize )
   353             {
   293             {
   354             iPopUp->SetSize( popupSize );
   294             iPopUp->SetSize( popupSize );
   355             }
   295             }
   356 
   296