imstutils/imconversationview/imcvuiapp/src/cimcvappsmileicondialog.cpp
changeset 0 5e5d6b214f4f
child 7 bef90b82da71
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Dialog for selecting smile icon.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "cimcvappsmileicondialog.h"
       
    24 #include "cimcvappsmileicongrid.h"
       
    25 #include "imcvappsmileutility.hrh"
       
    26 #include <AknDef.h>
       
    27 #include <aknappui.h>
       
    28 #include <aknutils.h>
       
    29 #include <aknconsts.h>
       
    30 #include <aknborders.h>
       
    31 #include <AknsDrawUtils.h>
       
    32 #include <AknLayoutScalable_Avkon.cdl.h>
       
    33 #include <aknlists.h> 
       
    34 #include <AknUtils.h> 
       
    35 #include "imcvlogger.h"
       
    36 #include "imcvuiapputils.h"
       
    37 
       
    38 #include "e32property.h"
       
    39 // CONSTANTS
       
    40 
       
    41 const TInt KAknSctCBaButtonDirections = 3; // bottom, right and left
       
    42 
       
    43 
       
    44 
       
    45 
       
    46 
       
    47 // ================= MEMBER FUNCTIONS =======================
       
    48 
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CIMCVAppSmileIconDialog::NewL
       
    52 // (other items were commented in a header).
       
    53 // ---------------------------------------------------------
       
    54 CIMCVAppSmileIconDialog* CIMCVAppSmileIconDialog::NewL( 
       
    55             const RPointerArray<CGulIcon>& aIconArray,
       
    56 			TInt& aSelectedIconId )
       
    57     {
       
    58     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::NewL() start") );
       
    59     CIMCVAppSmileIconDialog* self =
       
    60         new (ELeave) CIMCVAppSmileIconDialog( aIconArray, aSelectedIconId );
       
    61 	IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::NewL() end") );
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CIMCVAppSmileIconDialog::~CIMCVAppSmileIconDialog
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 CIMCVAppSmileIconDialog::~CIMCVAppSmileIconDialog()
       
    72     {
       
    73 	
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CIMCVAppSmileIconDialog::CIMCVAppSmileIconDialog
       
    79 // (other items were commented in a header).
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 CIMCVAppSmileIconDialog::CIMCVAppSmileIconDialog( 
       
    83                             const RPointerArray<CGulIcon>& aIconArray,
       
    84 							TInt& aSelectedIconId )
       
    85 :iIconArray( aIconArray ), iIconId( aSelectedIconId )
       
    86     {
       
    87     
       
    88     }
       
    89 
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // CIMCVAppSmileIconDialog::OfferKeyEventL
       
    94 // Handle key event.
       
    95 // If key code is other than OK and arrow key, no action.
       
    96 // (other items were commented in a header).
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 TKeyResponse CIMCVAppSmileIconDialog::OfferKeyEventL(
       
   100     const TKeyEvent& aKeyEvent, TEventCode aType)
       
   101     {
       
   102     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::OfferKeyEventL() start") );
       
   103     TKeyResponse response( EKeyWasConsumed );
       
   104     switch( aKeyEvent.iCode )
       
   105         {
       
   106 		// fall through
       
   107         case EKeyLeftArrow:
       
   108         case EKeyRightArrow:
       
   109         case EKeyUpArrow:
       
   110         case EKeyDownArrow:
       
   111             {
       
   112             CIMCVAppSmileIconGrid* grid =
       
   113 				static_cast< CIMCVAppSmileIconGrid*>(
       
   114 				Control( EIMIdSelectSmileGrid ) );
       
   115             grid->MoveCursor( aKeyEvent.iCode );
       
   116             break;
       
   117             }
       
   118         case EKeyEscape: // handle dialog shutdown.
       
   119             {
       
   120 			TryExitL( EAknSoftkeyExit );
       
   121             return EKeyWasNotConsumed;
       
   122             }
       
   123         default:
       
   124             {
       
   125             response = CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   126             break;
       
   127             }
       
   128         }
       
   129     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::OfferKeyEventL() end") );
       
   130     return response;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CIMCVAppSmileIconDialog::OkToExitL
       
   135 // Called when CBA-key or OK-key is pressed.
       
   136 // (other items were commented in a header).
       
   137 // ---------------------------------------------------------
       
   138 //
       
   139 void CIMCVAppSmileIconDialog::HandleResourceChange( TInt aType )
       
   140     {
       
   141     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::HandleResourceChange() start") );
       
   142     if( aType == KEikDynamicLayoutVariantSwitch )
       
   143         {
       
   144         SetLayout();
       
   145         }
       
   146 	CAknDialog::HandleResourceChange( aType );
       
   147 	IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::HandleResourceChange() end") );
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------
       
   151 // CIMCVAppSmileIconDialog::OkToExitL
       
   152 // Called when CBA-key or OK-key is pressed.
       
   153 // (other items were commented in a header).
       
   154 // ---------------------------------------------------------
       
   155 //
       
   156 TBool CIMCVAppSmileIconDialog::OkToExitL( TInt aButtonId )
       
   157     {
       
   158     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::OkToExitL() start") );
       
   159     if( aButtonId == EAknSoftkeySelect ||
       
   160         aButtonId == EEikBidOk )
       
   161         {
       
   162 		CIMCVAppSmileIconGrid* grid =
       
   163 			static_cast< CIMCVAppSmileIconGrid*>(
       
   164 			Control( EIMIdSelectSmileGrid ) );
       
   165 		iIconId = grid->SelectedBitmapId();
       
   166         }
       
   167     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::OkToExitL() end") );
       
   168     return ETrue;
       
   169     }
       
   170 
       
   171 
       
   172 
       
   173 // ---------------------------------------------------------
       
   174 // CIMCVAppSmileIconDialog::PreLayoutDynInitL
       
   175 // Prepare for drawing dialog.
       
   176 // (other items were commented in a header).
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CIMCVAppSmileIconDialog::PreLayoutDynInitL()
       
   180     {
       
   181     SetLineNonFocusing( EIMIdSelectSmileLabel );
       
   182     EnableDragEvents();
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // CIMCVAppSmileIconDialog::SetSizeAndPosition
       
   187 // Control size is set. This is called just after PreLayoutDynInitL().
       
   188 // (other items were commented in a header).
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 void CIMCVAppSmileIconDialog::SetSizeAndPosition(const TSize& /*aSize*/)
       
   192     {
       
   193     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetSizeAndPosition() start") );
       
   194 	SetLayout();
       
   195 	IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetSizeAndPosition() end") );
       
   196     }
       
   197 
       
   198 
       
   199 
       
   200 // ---------------------------------------------------------
       
   201 // CIMCVAppSmileIconDialog::CalculatePopupVariety
       
   202 // (other items were commented in a header).
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 
       
   206 TInt CIMCVAppSmileIconDialog::CalculatePopupVariety()
       
   207     {
       
   208     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::CalculatePopupVariety() start") );
       
   209 	CIMCVAppSmileIconGrid* grid =
       
   210 			static_cast< CIMCVAppSmileIconGrid*>(
       
   211 			Control( EIMIdSelectSmileGrid ) );   
       
   212 
       
   213     TAknLayoutScalableParameterLimits smileyDialogVariety = 
       
   214     	AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
   215     TInt maxVariety = smileyDialogVariety.LastVariety();
       
   216 
       
   217     // CBA location affects popup layout
       
   218     AknLayoutUtils::TAknCbaLocation cbaLocation = AknLayoutUtils::CbaLocation();
       
   219 
       
   220     // bottom variety
       
   221     TInt maxVarietyOffset = 0;
       
   222     TInt varietyOffset = maxVariety + 1;
       
   223     // right variety
       
   224     if (cbaLocation == AknLayoutUtils::EAknCbaLocationRight)
       
   225         {
       
   226     	varietyOffset = (maxVariety + 1)/KAknSctCBaButtonDirections;
       
   227     	maxVarietyOffset = varietyOffset;
       
   228         }
       
   229 
       
   230     // left variety
       
   231     else if (cbaLocation == AknLayoutUtils::EAknCbaLocationLeft)
       
   232         {
       
   233     	varietyOffset = (maxVariety + 1)/KAknSctCBaButtonDirections;
       
   234     	maxVarietyOffset = varietyOffset + varietyOffset;
       
   235         }
       
   236     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::CalculatePopupVariety() end") );
       
   237 	
       
   238 	if ((maxVarietyOffset + varietyOffset)>maxVariety)
       
   239 		return maxVariety;
       
   240 	else
       
   241     	return maxVarietyOffset + varietyOffset;
       
   242 	
       
   243     }
       
   244 
       
   245 
       
   246 
       
   247 // ---------------------------------------------------------
       
   248 // CIMCVAppSmileIconDialog::SetLayout
       
   249 // Set dialog layout.
       
   250 // (other items were commented in a header).
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 void CIMCVAppSmileIconDialog::SetLayout()
       
   254 	{   
       
   255 	IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetLayout() start") );
       
   256 	iIsMirrored = AknLayoutUtils::LayoutMirrored() ;
       
   257 	TRect clientRect = iAvkonAppUi->ApplicationRect();
       
   258     //check LAF docs for constants
       
   259     TAknLayoutRect mainPane;
       
   260     mainPane.LayoutRect( clientRect, AknLayoutScalable_Avkon::main_pane( 6 ) );
       
   261 	
       
   262 	CIMCVAppSmileIconGrid* grid =
       
   263 
       
   264 			static_cast< CIMCVAppSmileIconGrid*>(
       
   265 
       
   266 			Control( EIMIdSelectSmileGrid ) ); 	
       
   267 			
       
   268     // Select correct popup layout
       
   269 
       
   270     TInt varietyNumber = CalculatePopupVariety();
       
   271     TRect rect = grid->GetFirstCellRect();
       
   272     TInt iconCount = iIconArray.Count();
       
   273     // calculating the number of rows required by the icon grid.
       
   274     TInt rowCount = 1 + ( iconCount/4 );
       
   275     
       
   276     // 4 * rowCount denotes the maximum number of icons accomodated
       
   277     // in the row.
       
   278     TInt areaOfIcon = 4 * rowCount * rect.Width() * rect.Height();
       
   279 	TInt viewableWidth=0;
       
   280 	    
       
   281     for (TInt i=varietyNumber; i>0; i--)
       
   282 	    {    
       
   283 
       
   284     TAknWindowLineLayout popupGridDialogLayout( 
       
   285 	        AknLayoutScalable_Avkon::popup_grid_graphic_window( i ) );
       
   286 
       
   287 
       
   288 	    TAknLayoutRect dialogRect;
       
   289 
       
   290 	    dialogRect.LayoutRect(
       
   291 	        mainPane.Rect(), popupGridDialogLayout );
       
   292 		    
       
   293 		viewableWidth = CheckDialog(dialogRect,rect);    
       
   294 	    if(viewableWidth)
       
   295 		    {
       
   296 		    varietyNumber = i;
       
   297 		    break;
       
   298 		    }
       
   299 	    }
       
   300     
       
   301 	if(viewableWidth)
       
   302 		{
       
   303 	    TAknWindowLineLayout popupGridDialogLayout( 
       
   304         AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
       
   305     TAknLayoutRect dialogRect;
       
   306     dialogRect.LayoutRect(
       
   307         mainPane.Rect(), popupGridDialogLayout );
       
   308 		grid->SetViewableWindowWidth(viewableWidth);
       
   309     SetRect( dialogRect.Rect() );
       
   310 	    }
       
   311 	// If there is no suitable solution for the smiley dialog layout
       
   312 	else 
       
   313 	    {
       
   314 	    // Use the max variety number
       
   315 	    varietyNumber = CalculatePopupVariety();
       
   316 
       
   317 	    TAknWindowLineLayout popupGridDialogLayout( 
       
   318 	            AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
       
   319 
       
   320 	    TAknLayoutRect dialogRect;
       
   321 
       
   322 	    dialogRect.LayoutRect(
       
   323 	            mainPane.Rect(), popupGridDialogLayout );
       
   324 
       
   325 	  
       
   326 
       
   327 	    if ( !iIsMirrored )
       
   328 	        {
       
   329 	        // Right Margin of the top left (top right) icon's X
       
   330 	        TInt leftMargin = rect.iTl.iX;
       
   331 
       
   332 	        // Use the max viewable width
       
   333 	        viewableWidth = dialogRect.Rect().iBr.iX - dialogRect.Rect().iTl.iX - leftMargin;
       
   334 	        }
       
   335 	    else 
       
   336 	        {
       
   337 	        // Left Margin of the top left (top right) icon's X
       
   338 	        TInt rightMargin = rect.iBr.iX;
       
   339 
       
   340 	        // Use the max viewable width
       
   341 	        viewableWidth = dialogRect.Rect().iBr.iX - dialogRect.Rect().iTl.iX + rightMargin;
       
   342 	        }
       
   343 
       
   344 	    grid->SetViewableWindowWidth( viewableWidth );
       
   345 
       
   346 	    if ( !iIsMirrored )
       
   347 	        SetRect( dialogRect.Rect() );
       
   348 	    // When the Hebrew is the language as well as the Arb languages
       
   349 	    // The align is not right
       
   350 	    else 
       
   351 	        {
       
   352 	        TRect mirroredDialogRect;
       
   353 
       
   354 	        // Align to right.
       
   355 	        mirroredDialogRect = dialogRect.Rect();
       
   356 
       
   357 	        // Get the rect of the cba pane.
       
   358 	        TRect controlPaneRect;
       
   359 	        AknLayoutUtils::LayoutMetricsRect(
       
   360 	                AknLayoutUtils::EControlPane, controlPaneRect);
       
   361 
       
   362 	        TInt cbaWidth = controlPaneRect.iBr.iX - controlPaneRect.iTl.iX;
       
   363 
       
   364 	        mirroredDialogRect.iTl.iX -= cbaWidth;
       
   365 	        mirroredDialogRect.iBr.iX -= cbaWidth;
       
   366 
       
   367 	        SetRect( mirroredDialogRect );
       
   368 	        }
       
   369 	    }
       
   370 	}
       
   371 
       
   372 
       
   373 
       
   374 // ---------------------------------------------------------
       
   375 
       
   376 // CIMCVAppSmileIconDialog::CheckDialog
       
   377 
       
   378 // Check if Dialog is suitable to fit all smile icon
       
   379 
       
   380 // (other items were commented in a header).
       
   381 
       
   382 // ---------------------------------------------------------
       
   383 
       
   384 TInt CIMCVAppSmileIconDialog::CheckDialog(TAknLayoutRect aDialogRect,TRect aRect)
       
   385 		{
       
   386         TInt topMargin = aRect.iTl.iY;
       
   387         
       
   388         TInt viewableWidth = 0;
       
   389         
       
   390         if ( !iIsMirrored )
       
   391             {
       
   392             TInt leftMargin = aRect.iTl.iX;
       
   393                     
       
   394             viewableWidth = aDialogRect.Rect().iBr.iX - aDialogRect.Rect().iTl.iX - 2*leftMargin;
       
   395             }
       
   396         else 
       
   397             {
       
   398             TInt rightMargin = aRect.iBr.iX;
       
   399                                 
       
   400             viewableWidth = aDialogRect.Rect().iBr.iX - aDialogRect.Rect().iTl.iX + 2*rightMargin;
       
   401             }
       
   402         TInt viewableHight = aDialogRect.Rect().iBr.iY -aDialogRect.Rect().iTl.iY - topMargin;
       
   403 		
       
   404 		TInt viewableArea = viewableWidth*viewableHight;
       
   405 		
       
   406 	    TInt iconCount = iIconArray.Count();
       
   407 
       
   408 	    // calculating the number of rows required by the icon grid.
       
   409 	    TInt rowCount = 1 + ( iconCount/4 );
       
   410 	    
       
   411 	    // 4 * rowCount denotes the maximum number of icons accomodated
       
   412 	    // in the row.
       
   413 	    TInt areaOfIcon = 4 * rowCount * aRect.Width() * aRect.Height();
       
   414 	    
       
   415 	    if(areaOfIcon > viewableArea)
       
   416 		    {
       
   417 			return 0;
       
   418 		    }
       
   419 		else
       
   420 			{
       
   421 			return viewableWidth;
       
   422 			}
       
   423 		}
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------
       
   427 // CIMCVAppSmileIconDialog::CreateCustomControlL
       
   428 // Create CIMCVAppSmileIconGrid class in order to display
       
   429 // icons in grid.
       
   430 // This is called when dialog is created.
       
   431 // (other items were commented in a header).
       
   432 // ---------------------------------------------------------
       
   433 //
       
   434 SEikControlInfo CIMCVAppSmileIconDialog::CreateCustomControlL(
       
   435 										TInt aControlType )
       
   436     {
       
   437     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetLayout() start") );
       
   438     SEikControlInfo controlInfo;
       
   439     controlInfo.iControl = NULL;
       
   440     controlInfo.iTrailerTextId = 0;
       
   441     controlInfo.iFlags = 0;
       
   442     if( aControlType == EIMCtrlSelectSmileGrid )
       
   443         {
       
   444         controlInfo.iControl = CIMCVAppSmileIconGrid::NewL( this, iIconArray );
       
   445 
       
   446         static_cast<CIMCVAppSmileIconGrid*>
       
   447 
       
   448             (controlInfo.iControl)->SetTapObserver( this, 0 );
       
   449 
       
   450         }
       
   451     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetLayout() end") );
       
   452     return controlInfo;
       
   453     }
       
   454 
       
   455 
       
   456 
       
   457 // ---------------------------------------------------------
       
   458 
       
   459 // CIMCVAppSmileIconDialog::HandleDialogPageEventL
       
   460 
       
   461 // (other items were commented in a header).
       
   462 
       
   463 // ---------------------------------------------------------
       
   464 
       
   465 //
       
   466 
       
   467 void CIMCVAppSmileIconDialog::HandleDialogPageEventL( TInt aEventID )
       
   468 
       
   469     {
       
   470     if( IMCVUiAppUtils::PenEnabled() )
       
   471         {
       
   472         if ( iSmileyPointed &&
       
   473              aEventID == MEikDialogPageObserver::EDialogPageTapped )
       
   474             {        
       
   475             // Exit requested, exit with ok. 
       
   476             TryExitL( EAknSoftkeyOk );
       
   477             }
       
   478          
       
   479          //else keep dialog as it is do not exit.  
       
   480         }
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------
       
   484 
       
   485 // CIMCVAppSmileIconDialog::HandleTapEventL
       
   486 
       
   487 // (other items were commented in a header).
       
   488 
       
   489 // ---------------------------------------------------------
       
   490 
       
   491 //
       
   492 
       
   493 void CIMCVAppSmileIconDialog::HandleTapEventL( TTapEvent aEvent, 
       
   494 
       
   495                                           TUint /*aControlId*/ )
       
   496 
       
   497     {
       
   498 
       
   499     // User tapped on smiley.
       
   500 
       
   501     if( aEvent == MIMCVTapEventObserver::ESingleTap )
       
   502 
       
   503         {
       
   504 
       
   505         // Smiley was selected but we can't exit directly from here. 
       
   506 
       
   507         // Instead we put the flag on and wait for 
       
   508 
       
   509         // HandleDialogPageEventL.
       
   510 
       
   511         iSmileyPointed = ETrue;
       
   512 
       
   513         }
       
   514 
       
   515     }
       
   516 
       
   517 
       
   518 
       
   519 // End of File