imstutils/imconversationview/imcvuiapp/src/cimcvappsmileicondialog.cpp
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     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 ), iLayoutChanged(EFalse)
       
    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 		iLayoutChanged = ETrue;
       
   145 		SetLayout();
       
   146         } 
       
   147 	CAknDialog::HandleResourceChange( aType );
       
   148 	IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::HandleResourceChange() end") );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CIMCVAppSmileIconDialog::OkToExitL
       
   153 // Called when CBA-key or OK-key is pressed.
       
   154 // (other items were commented in a header).
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 TBool CIMCVAppSmileIconDialog::OkToExitL( TInt aButtonId )
       
   158     {
       
   159     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::OkToExitL() start") );
       
   160     if( aButtonId == EAknSoftkeySelect ||
       
   161         aButtonId == EEikBidOk )
       
   162         {
       
   163 		CIMCVAppSmileIconGrid* grid =
       
   164 			static_cast< CIMCVAppSmileIconGrid*>(
       
   165 			Control( EIMIdSelectSmileGrid ) );
       
   166 		iIconId = grid->SelectedBitmapId();
       
   167         }
       
   168     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::OkToExitL() end") );
       
   169     return ETrue;
       
   170     }
       
   171 
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CIMCVAppSmileIconDialog::PreLayoutDynInitL
       
   176 // Prepare for drawing dialog.
       
   177 // (other items were commented in a header).
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 void CIMCVAppSmileIconDialog::PreLayoutDynInitL()
       
   181     {
       
   182     SetLineNonFocusing( EIMIdSelectSmileLabel );
       
   183     EnableDragEvents();
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // CIMCVAppSmileIconDialog::SetSizeAndPosition
       
   188 // Control size is set. This is called just after PreLayoutDynInitL().
       
   189 // (other items were commented in a header).
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 void CIMCVAppSmileIconDialog::SetSizeAndPosition(const TSize& /*aSize*/)
       
   193     {
       
   194     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetSizeAndPosition() start") );
       
   195 	SetLayout();
       
   196 	IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetSizeAndPosition() end") );
       
   197     }
       
   198 
       
   199 
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CIMCVAppSmileIconDialog::CalculatePopupVariety
       
   203 // (other items were commented in a header).
       
   204 // ---------------------------------------------------------
       
   205 //
       
   206 
       
   207 TInt CIMCVAppSmileIconDialog::CalculatePopupVariety()
       
   208     {
       
   209     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::CalculatePopupVariety() start") );
       
   210 
       
   211     TAknLayoutScalableParameterLimits smileyDialogVariety = 
       
   212     	AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
   213     TInt maxVariety = smileyDialogVariety.LastVariety();
       
   214 
       
   215     // CBA location affects popup layout
       
   216     AknLayoutUtils::TAknCbaLocation cbaLocation = AknLayoutUtils::CbaLocation();
       
   217 
       
   218     // bottom variety
       
   219     TInt maxVarietyOffset = 0;
       
   220     TInt varietyOffset = maxVariety + 1;
       
   221     // right variety
       
   222     if (cbaLocation == AknLayoutUtils::EAknCbaLocationRight)
       
   223         {
       
   224     	varietyOffset = (maxVariety + 1)/KAknSctCBaButtonDirections;
       
   225     	maxVarietyOffset = varietyOffset;
       
   226         }
       
   227 
       
   228     // left variety
       
   229     else if (cbaLocation == AknLayoutUtils::EAknCbaLocationLeft)
       
   230         {
       
   231     	varietyOffset = (maxVariety + 1)/KAknSctCBaButtonDirections;
       
   232     	maxVarietyOffset = varietyOffset + varietyOffset;
       
   233         }
       
   234     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::CalculatePopupVariety() end") );
       
   235 	
       
   236 	if ((maxVarietyOffset + varietyOffset)>maxVariety)
       
   237 		return maxVariety;
       
   238 	else
       
   239     	return maxVarietyOffset + varietyOffset;
       
   240 	
       
   241     }
       
   242 
       
   243 
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // CIMCVAppSmileIconDialog::SetLayout
       
   247 // Set dialog layout.
       
   248 // (other items were commented in a header).
       
   249 // ---------------------------------------------------------
       
   250 //
       
   251 void CIMCVAppSmileIconDialog::SetLayout()
       
   252     {
       
   253     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetLayout() start"));
       
   254     iIsMirrored = AknLayoutUtils::LayoutMirrored();
       
   255     TRect clientRect; 
       
   256     //check LAF docs for constants
       
   257     //AknLayoutUtils::LayoutMetricsRect
       
   258     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EApplicationWindow,
       
   259             clientRect);
       
   260     CIMCVAppSmileIconGrid* grid =
       
   261 
       
   262     static_cast<CIMCVAppSmileIconGrid*> (
       
   263 
       
   264     Control(EIMIdSelectSmileGrid));
       
   265 
       
   266     // Select correct popup layout
       
   267 
       
   268     TInt varietyNumber = CalculatePopupVariety();
       
   269     TRect rect = grid->GetFirstCellRect();
       
   270 
       
   271     TInt iconCount = iIconArray.Count();
       
   272     // calculating the number of rows required by the icon grid.
       
   273 
       
   274     TInt viewableWidth = 0;
       
   275     
       
   276     for (TInt i = varietyNumber; i >= 0; i--)
       
   277         {
       
   278 
       
   279         TAknWindowLineLayout popupGridDialogLayout(
       
   280                 AknLayoutScalable_Avkon::popup_grid_graphic_window(i)); 
       
   281 
       
   282         TAknLayoutRect dialogRect;
       
   283 
       
   284         dialogRect.LayoutRect(clientRect, popupGridDialogLayout);
       
   285         
       
   286         viewableWidth = CheckDialog(dialogRect, rect);
       
   287         if (viewableWidth)
       
   288             {
       
   289             varietyNumber = i;
       
   290             break;
       
   291             }
       
   292         }
       
   293     if (viewableWidth)
       
   294         {
       
   295         TAknWindowLineLayout popupGridDialogLayout(
       
   296                 AknLayoutScalable_Avkon::popup_grid_graphic_window(
       
   297                         varietyNumber));
       
   298         TAknLayoutRect dialogRect;
       
   299         dialogRect.LayoutRect(clientRect, popupGridDialogLayout);
       
   300         grid->SetViewableWindowWidth(viewableWidth);
       
   301         SetRect(dialogRect.Rect());
       
   302         }
       
   303     // If there is no suitable solution for the smiley dialog layout
       
   304     else
       
   305         {
       
   306         // No variety of the popup_grid_graphic_window has provided sufficient area
       
   307         // for the grid display. Hence selecting 0 variety for displaying the grid
       
   308         // because it has the greatest area.
       
   309         varietyNumber = 0;
       
   310         TAknWindowLineLayout popupGridDialogLayout(
       
   311                 AknLayoutScalable_Avkon::popup_grid_graphic_window(
       
   312                         varietyNumber));
       
   313 
       
   314         TAknLayoutRect dialogRect;
       
   315 
       
   316         dialogRect.LayoutRect(clientRect, popupGridDialogLayout);
       
   317 
       
   318         if (!iIsMirrored)
       
   319             {
       
   320             // Right Margin of the top left (top right) icon's X
       
   321             TInt leftMargin = rect.iTl.iX;
       
   322 
       
   323             // Use the max viewable width
       
   324             viewableWidth = dialogRect.Rect().iBr.iX
       
   325                     - dialogRect.Rect().iTl.iX - leftMargin;
       
   326             }
       
   327         else
       
   328             {
       
   329             // Left Margin of the top left (top right) icon's X
       
   330             TInt rightMargin = rect.iBr.iX;
       
   331 
       
   332             // Use the max viewable width
       
   333             viewableWidth = dialogRect.Rect().iBr.iX
       
   334                     - dialogRect.Rect().iTl.iX + rightMargin;
       
   335             }
       
   336 
       
   337         grid->SetViewableWindowWidth(viewableWidth);
       
   338 
       
   339         if (!iIsMirrored)
       
   340             SetRect(dialogRect.Rect());
       
   341         // When the Hebrew is the language as well as the Arb languages
       
   342         // The align is not right
       
   343         else
       
   344             {
       
   345             TRect mirroredDialogRect;
       
   346 
       
   347             // Align to right.
       
   348             mirroredDialogRect = dialogRect.Rect();
       
   349 
       
   350             // Get the rect of the cba pane.
       
   351             TRect controlPaneRect;
       
   352             AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EControlPane,
       
   353                     controlPaneRect);
       
   354 
       
   355             TInt cbaWidth = controlPaneRect.iBr.iX - controlPaneRect.iTl.iX;
       
   356 
       
   357             mirroredDialogRect.iTl.iX -= cbaWidth;
       
   358             mirroredDialogRect.iBr.iX -= cbaWidth;
       
   359 
       
   360             SetRect(mirroredDialogRect);
       
   361             }
       
   362         }
       
   363     }
       
   364 
       
   365 
       
   366 
       
   367 // ---------------------------------------------------------
       
   368 
       
   369 // CIMCVAppSmileIconDialog::CheckDialog
       
   370 
       
   371 // Check if Dialog is suitable to fit all smile icon
       
   372 
       
   373 // (other items were commented in a header).
       
   374 
       
   375 // ---------------------------------------------------------
       
   376 
       
   377 TInt CIMCVAppSmileIconDialog::CheckDialog(TAknLayoutRect aDialogRect,TRect aRect)
       
   378 		{
       
   379         // topMargin is the height of the margin which the smiley grid has 
       
   380         // above its top horizontal line and bottom horizontal line.
       
   381         TInt topMargin = aRect.Height();
       
   382         
       
   383         TRect dialogRect = aDialogRect.Rect();
       
   384         
       
   385         TInt vWidth = 0;
       
   386         TInt vheight = 0;
       
   387         TInt vArea = 0;
       
   388         vheight = dialogRect.iBr.iY - dialogRect.iTl.iY - 2*topMargin;
       
   389         if ( !iIsMirrored )
       
   390             {
       
   391             vWidth = dialogRect.iBr.iX - dialogRect.iTl.iX - 2*aRect.iTl.iX;;
       
   392             }
       
   393         else 
       
   394             {
       
   395 			// Patch fix for mirrored layout when mode changes from portrait to
       
   396 			// landscape or vice versa the width calculation differs to adjust the correct width
       
   397 			if (iLayoutChanged) // mode change like portrait to landscape or vice versa
       
   398 				{
       
   399 				vWidth = (2*aRect.iBr.iX) - (dialogRect.iBr.iX - dialogRect.iTl.iX);
       
   400 				}
       
   401 			else
       
   402 				{
       
   403 				vWidth = dialogRect.iBr.iX - dialogRect.iTl.iX + 2*aRect.iBr.iX;
       
   404 				}
       
   405             } 
       
   406 		vArea = vWidth*vheight;
       
   407 		
       
   408 	    TInt iconCount = iIconArray.Count();
       
   409 
       
   410 	    TInt areaOfIcon = iconCount * aRect.Width() * aRect.Height();
       
   411 	    
       
   412 	    if(areaOfIcon > vArea)
       
   413 		    {
       
   414 			return 0;
       
   415 		    }
       
   416 		else
       
   417 			{
       
   418 			return vWidth;
       
   419 			}
       
   420 		}
       
   421 
       
   422 
       
   423 // ---------------------------------------------------------
       
   424 // CIMCVAppSmileIconDialog::CreateCustomControlL
       
   425 // Create CIMCVAppSmileIconGrid class in order to display
       
   426 // icons in grid.
       
   427 // This is called when dialog is created.
       
   428 // (other items were commented in a header).
       
   429 // ---------------------------------------------------------
       
   430 //
       
   431 SEikControlInfo CIMCVAppSmileIconDialog::CreateCustomControlL(
       
   432 										TInt aControlType )
       
   433     {
       
   434     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetLayout() start") );
       
   435     SEikControlInfo controlInfo;
       
   436     controlInfo.iControl = NULL;
       
   437     controlInfo.iTrailerTextId = 0;
       
   438     controlInfo.iFlags = 0;
       
   439     if( aControlType == EIMCtrlSelectSmileGrid )
       
   440         {
       
   441         controlInfo.iControl = CIMCVAppSmileIconGrid::NewL( this, iIconArray );
       
   442 
       
   443         static_cast<CIMCVAppSmileIconGrid*>
       
   444 
       
   445             (controlInfo.iControl)->SetTapObserver( this, 0 );
       
   446 
       
   447         }
       
   448     IM_CV_LOGS(TXT("CIMCVAppSmileIconDialog::SetLayout() end") );
       
   449     return controlInfo;
       
   450     }
       
   451 
       
   452 
       
   453 
       
   454 // ---------------------------------------------------------
       
   455 
       
   456 // CIMCVAppSmileIconDialog::HandleDialogPageEventL
       
   457 
       
   458 // (other items were commented in a header).
       
   459 
       
   460 // ---------------------------------------------------------
       
   461 
       
   462 //
       
   463 
       
   464 void CIMCVAppSmileIconDialog::HandleDialogPageEventL( TInt aEventID )
       
   465 
       
   466     {
       
   467     if( IMCVUiAppUtils::PenEnabled() )
       
   468         {
       
   469         if ( iSmileyPointed &&
       
   470              aEventID == MEikDialogPageObserver::EDialogPageTapped )
       
   471             {        
       
   472             // Exit requested, exit with ok. 
       
   473             TryExitL( EAknSoftkeyOk );
       
   474             }
       
   475          
       
   476          //else keep dialog as it is do not exit.  
       
   477         }
       
   478     }
       
   479 
       
   480 // ---------------------------------------------------------
       
   481 
       
   482 // CIMCVAppSmileIconDialog::HandleTapEventL
       
   483 
       
   484 // (other items were commented in a header).
       
   485 
       
   486 // ---------------------------------------------------------
       
   487 
       
   488 //
       
   489 
       
   490 void CIMCVAppSmileIconDialog::HandleTapEventL( TTapEvent aEvent, 
       
   491 
       
   492                                           TUint /*aControlId*/ )
       
   493 
       
   494     {
       
   495 
       
   496     // User tapped on smiley.
       
   497 
       
   498     if( aEvent == MIMCVTapEventObserver::ESingleTap )
       
   499 
       
   500         {
       
   501 
       
   502         // Smiley was selected but we can't exit directly from here. 
       
   503 
       
   504         // Instead we put the flag on and wait for 
       
   505 
       
   506         // HandleDialogPageEventL.
       
   507 
       
   508         iSmileyPointed = ETrue;
       
   509 
       
   510         }
       
   511 
       
   512     }
       
   513 
       
   514 
       
   515 
       
   516 // End of File