imageeditor/ImageEditorUI/src/PluginGrid.cpp
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:
       
    16 * Effect plugin selection dialog that shows icons of available
       
    17 * plugins in a grid.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 // INCLUDES
       
    23 #include <fbs.h> 
       
    24 #include <avkon.hrh>
       
    25 #include <eikspane.h>
       
    26 #include <aknutils.h>
       
    27 #include <avkon.hrh>
       
    28 #include <AknBidiTextUtils.h>
       
    29 #include <BidiText.h> 
       
    30 #include <AknIconUtils.h>
       
    31 #include <AknInfoPopupNoteController.h>
       
    32 #include <AknLayoutScalable_Avkon.cdl.h>
       
    33 #include <AknLayoutScalable_Apps.cdl.h>
       
    34 #include <eiklabel.h>
       
    35 #include <ImageEditorUi.mbg>
       
    36 #include <layoutmetadata.cdl.h>
       
    37 
       
    38 #ifdef RD_TACTILE_FEEDBACK 
       
    39 #include <touchfeedback.h>
       
    40 #endif /* RD_TACTILE_FEEDBACK  */
       
    41 
       
    42 #include "PluginGrid.h"
       
    43 #include "PluginInfo.h"
       
    44 #include "ResolutionUtil.h"
       
    45 #include <ImageEditorUI.rsg>
       
    46 #include "ImageEditorUI.hrh"
       
    47 #include "ImageEditorUIDefs.h" 
       
    48 #include "DrawUtils.h"
       
    49 
       
    50 // CONSTANTS
       
    51 const TInt KDefaultCurrentItem = 7;
       
    52 const TInt KPortraitNumberOfRows = 5;
       
    53 const TInt KPortraitNumberOfColumns = 3;
       
    54 const TInt KLandscapeNumberOfRows = 3;
       
    55 const TInt KLandscapeNumberOfColumns = 5;
       
    56 const TInt KBorderPartsNum = 9;
       
    57 const TInt KTooltipDelayBeforeShow = 200;
       
    58 
       
    59 //=============================================================================
       
    60 CPluginGrid::CPluginGrid (CFbsBitmap** aBitmap, 
       
    61                           const RPluginArray* aItems)
       
    62 : iBitmap( aBitmap ), 
       
    63   iPluginItems( aItems ), 
       
    64   iCurrentItem( KDefaultCurrentItem ),
       
    65   iNumberOfRows( KPortraitNumberOfRows ),
       
    66   iNumberOfColumns( KPortraitNumberOfColumns ),
       
    67   iCellSize(0,0),
       
    68   iTouchGridRect(0,0,0,0),
       
    69   iHighlightPos(0,0),
       
    70   iParentRect(0,0,0,0)
       
    71     {
       
    72     }
       
    73 
       
    74 //=============================================================================
       
    75 CPluginGrid::~CPluginGrid ()
       
    76     {
       
    77     iBorders.ResetAndDestroy();
       
    78     iHighlight.ResetAndDestroy();
       
    79     iIcons.ResetAndDestroy();
       
    80     delete iText;
       
    81 
       
    82     iBitmap = NULL;
       
    83     iPluginItems = NULL;
       
    84     }
       
    85 
       
    86 //=============================================================================
       
    87 void CPluginGrid::ConstructL ()
       
    88     {
       
    89     TFileName iconFile (KImageEditorUiMifFile);
       
    90 
       
    91 	// create popup graphics
       
    92     for ( TInt i = 0; i < KBorderPartsNum; ++i )
       
    93         {
       
    94         CEikImage* image = new (ELeave) CEikImage;
       
    95 
       
    96 		image->CreatePictureFromFileL(iconFile,
       
    97 										EMbmImageeditoruiQgn_graf_popup_trans_center + 2*i,
       
    98 										EMbmImageeditoruiQgn_graf_popup_trans_center_mask + 2*i);
       
    99 
       
   100         CleanupStack::PushL( image );
       
   101         image->SetContainerWindowL( *this );
       
   102         iBorders.AppendL( image );
       
   103         CleanupStack::Pop( image );
       
   104         }
       
   105 
       
   106 	// create highlight graphics
       
   107     for ( TInt i = 0; i < KBorderPartsNum; ++i )
       
   108         {
       
   109         CEikImage* image = new (ELeave) CEikImage;
       
   110 
       
   111 		image->CreatePictureFromFileL(iconFile,
       
   112 										EMbmImageeditoruiQgn_graf_popup_trans_center + 2*i,
       
   113 										EMbmImageeditoruiQgn_graf_popup_trans_center_mask + 2*i);
       
   114 //										EMbmImageeditoruiQsn_fr_imed_grid_center + 2*i,
       
   115 //										EMbmImageeditoruiQsn_fr_imed_grid_center_mask + 2*i);
       
   116 
       
   117         CleanupStack::PushL( image );
       
   118         image->SetContainerWindowL( *this );
       
   119         iHighlight.AppendL( image );
       
   120         CleanupStack::Pop( image );
       
   121         }
       
   122 
       
   123 	// title text
       
   124 	iText = new (ELeave) CEikLabel;
       
   125 	iText->SetContainerWindowL( *this );
       
   126     HBufC* heading = CEikonEnv::Static()->AllocReadResourceLC( R_HEADING_APPLY_EFFECT );
       
   127 	iText->SetTextL( heading->Des() );
       
   128 	CleanupStack::PopAndDestroy( heading );
       
   129 
       
   130 	// plugin graphics
       
   131     for (TInt i = 0; i < iPluginItems->Count(); ++i)
       
   132         {
       
   133         CPluginInfo * pgn_info = (*iPluginItems)[i];
       
   134 
       
   135         CEikImage* image = new (ELeave) CEikImage;
       
   136 
       
   137 		image->SetPicture(pgn_info->Icon(), pgn_info->Mask());
       
   138 		image->SetPictureOwnedExternally(ETrue);
       
   139 
       
   140         CleanupStack::PushL( image );
       
   141         image->SetContainerWindowL( *this );
       
   142         iIcons.AppendL( image );
       
   143         CleanupStack::Pop( image );
       
   144         }
       
   145 
       
   146     ActivateL();
       
   147     }
       
   148 
       
   149 //=============================================================================
       
   150 TInt CPluginGrid::GetSelectedItemIndex() const
       
   151     {
       
   152     return iCurrentItem;
       
   153     }
       
   154 
       
   155 
       
   156 //=============================================================================
       
   157 void CPluginGrid::SizeChanged()
       
   158     {
       
   159     
       
   160     TBool variant = Layout_Meta_Data::IsLandscapeOrientation();    
       
   161     if( variant )
       
   162         {
       
   163         iNumberOfRows = KLandscapeNumberOfRows;
       
   164         iNumberOfColumns =  KLandscapeNumberOfColumns;
       
   165         }
       
   166     else
       
   167         {
       
   168         iNumberOfRows = KPortraitNumberOfRows; 
       
   169         iNumberOfColumns = KPortraitNumberOfColumns;
       
   170         }  
       
   171         
       
   172     TAknLayoutRect layoutRect;
       
   173     
       
   174     if(variant) 
       
   175         {
       
   176         layoutRect.LayoutRect( Rect(), AknLayoutScalable_Apps::popup_imed_trans_window(4) );        
       
   177         }
       
   178     else
       
   179         {
       
   180         layoutRect.LayoutRect( Rect(), AknLayoutScalable_Apps::bg_tb_trans_pane_cp02(1) );
       
   181         }        
       
   182     iParentRect = layoutRect.Rect();
       
   183 
       
   184 	// determine grid cell size
       
   185     layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::cell_imed_effect_pane(1,1,variant) );
       
   186 	iCellSize = layoutRect.Rect().Size();
       
   187 
       
   188 	TInt delta = 0;
       
   189 
       
   190 	// determine caption layout
       
   191     layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::heading_imed_pane(variant) );
       
   192     TAknLayoutText layoutText;
       
   193     layoutText.LayoutText( layoutRect.Rect(), AknLayoutScalable_Apps::heading_imed_pane_t1(variant) );
       
   194     TRgb color = layoutText.Color();
       
   195 	iText->SetFont(layoutText.Font());
       
   196 	iText->OverrideColorL( EColorLabelText, color );
       
   197 	iText->SetExtent(layoutText.TextRect().iTl, layoutText.TextRect().Size());
       
   198 	if(AknLayoutUtils::LayoutMirrored())
       
   199 		{
       
   200 		iText->SetAlignment( EHRightVCenter );    
       
   201 		}
       
   202 	else
       
   203 		{
       
   204 		iText->SetAlignment( EHLeftVCenter );
       
   205 		}
       
   206 
       
   207 	// determine popup border layouts
       
   208     if( !AknLayoutUtils::LayoutMirrored() )
       
   209         {                  
       
   210         AknLayoutUtils::LayoutControl( iBorders[1], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2().LayoutLine() );
       
   211         AknLayoutUtils::LayoutControl( iBorders[2], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g3().LayoutLine() );
       
   212         AknLayoutUtils::LayoutControl( iBorders[3], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g4().LayoutLine() );
       
   213         AknLayoutUtils::LayoutControl( iBorders[4], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g5().LayoutLine() );
       
   214         AknLayoutUtils::LayoutControl( iBorders[5], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g6().LayoutLine() );
       
   215         AknLayoutUtils::LayoutControl( iBorders[6], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g7().LayoutLine() );
       
   216         }
       
   217     else
       
   218         {
       
   219         AknLayoutUtils::LayoutControl( iBorders[1], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g3().LayoutLine() );
       
   220         AknLayoutUtils::LayoutControl( iBorders[2], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2().LayoutLine() );
       
   221         AknLayoutUtils::LayoutControl( iBorders[3], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g5().LayoutLine() );
       
   222         AknLayoutUtils::LayoutControl( iBorders[4], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g4().LayoutLine() );
       
   223         AknLayoutUtils::LayoutControl( iBorders[5], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g7().LayoutLine() );
       
   224         AknLayoutUtils::LayoutControl( iBorders[6], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g6().LayoutLine() );
       
   225         }
       
   226     AknLayoutUtils::LayoutControl( iBorders[0], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g1().LayoutLine() );
       
   227     AknLayoutUtils::LayoutControl( iBorders[7], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g8().LayoutLine() );
       
   228     AknLayoutUtils::LayoutControl( iBorders[8], iParentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g9().LayoutLine() );
       
   229     // Images need to be resized separately, because the standard LayoutImage
       
   230     // tries to preserve the aspect ratio and we don't want that.
       
   231     //
       
   232     for ( TInt i = 0; i < iBorders.Count(); ++i )
       
   233         {
       
   234         AknIconUtils::SetSize(
       
   235             const_cast<CFbsBitmap*>( iBorders[i]->Bitmap() ),
       
   236             iBorders[i]->Size(), EAspectRatioNotPreserved );
       
   237         }
       
   238 
       
   239 	// plugin graphics sizes
       
   240     layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::cell_imed_effect_pane_g1(variant) );
       
   241     TRect iconRect = layoutRect.Rect();
       
   242     TSize iconSize = iconRect.Size();
       
   243     for (TInt i = 0; i < iPluginItems->Count(); ++i)
       
   244         {
       
   245         CPluginInfo * pgn_info = (*iPluginItems)[i];
       
   246 
       
   247         // Set size for scalable icons - MUST BE CALLED BEFORE ICON IS USABLE
       
   248         if (pgn_info->Icon())
       
   249             {
       
   250             AknIconUtils::SetSize(pgn_info->Icon(), iconSize);
       
   251             }
       
   252         if (pgn_info->Mask())
       
   253             {
       
   254             AknIconUtils::SetSize(pgn_info->Mask(), iconSize);
       
   255             }
       
   256         }
       
   257 
       
   258 	// touch area
       
   259     layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::listscroll_imed_pane (variant) );
       
   260 	iTouchGridRect = layoutRect.Rect();
       
   261 	delta = layoutRect.Rect().Width();
       
   262     layoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane(0,0,variant) );            
       
   263 	iTouchGridRect.SetWidth(layoutRect.Rect().Width() * iNumberOfColumns);
       
   264 	iTouchGridRect.SetHeight(layoutRect.Rect().Height() * iNumberOfRows);
       
   265 	delta = (delta - iTouchGridRect.Width()) / 2;
       
   266     if( AknLayoutUtils::LayoutMirrored() )
       
   267         {                  
       
   268 		delta = -delta;
       
   269         }
       
   270 	iTouchGridRect.iTl.iX += delta;
       
   271 
       
   272 	// plugin graphics positions
       
   273     layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::listscroll_imed_pane (variant) );
       
   274     TAknLayoutRect iconLayoutRect;
       
   275                   
       
   276     for ( TInt i = 0; i <iNumberOfRows; ++i )
       
   277         {
       
   278 	    for ( TInt j = 0; j <iNumberOfColumns; ++j )
       
   279 	        {
       
   280 		    iconLayoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane(j, i,variant) );
       
   281 		    iconLayoutRect.LayoutRect( iconLayoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane_g1(variant) );
       
   282 			TPoint iconPos = iconLayoutRect.Rect().iTl;
       
   283 			iconPos.iX += delta;
       
   284 
       
   285 			iIcons[j + iNumberOfColumns * i]->SetSize(iconSize);
       
   286 			iIcons[j + iNumberOfColumns * i]->SetPosition(iconPos);
       
   287 	        }
       
   288         }
       
   289 
       
   290 	// determine highlight layouts
       
   291     layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::listscroll_imed_pane (variant) );
       
   292     layoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane(0,0,variant) );
       
   293 	iHighlightPos = layoutRect.Rect().iTl;
       
   294     layoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::grid_highlight_pane_cp017(variant) );
       
   295 	TRect highlightRect = layoutRect.Rect();
       
   296 	highlightRect.iTl.iX += delta;
       
   297 	highlightRect.iBr.iX += delta;
       
   298     if( !AknLayoutUtils::LayoutMirrored() )
       
   299         {                  
       
   300 	    AknLayoutUtils::LayoutControl( iHighlight[1], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2().LayoutLine() );
       
   301 	    AknLayoutUtils::LayoutControl( iHighlight[2], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g3().LayoutLine() );
       
   302 	    AknLayoutUtils::LayoutControl( iHighlight[3], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g4().LayoutLine() );
       
   303 	    AknLayoutUtils::LayoutControl( iHighlight[4], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g5().LayoutLine() );
       
   304 	    AknLayoutUtils::LayoutControl( iHighlight[5], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g6().LayoutLine() );
       
   305 	    AknLayoutUtils::LayoutControl( iHighlight[6], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g7().LayoutLine() );
       
   306         }
       
   307     else
       
   308         {
       
   309 	    AknLayoutUtils::LayoutControl( iHighlight[1], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g3().LayoutLine() );
       
   310 	    AknLayoutUtils::LayoutControl( iHighlight[2], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2().LayoutLine() );
       
   311 	    AknLayoutUtils::LayoutControl( iHighlight[3], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g5().LayoutLine() );
       
   312 	    AknLayoutUtils::LayoutControl( iHighlight[4], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g4().LayoutLine() );
       
   313 	    AknLayoutUtils::LayoutControl( iHighlight[5], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g7().LayoutLine() );
       
   314 	    AknLayoutUtils::LayoutControl( iHighlight[6], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g6().LayoutLine() );
       
   315         }
       
   316     AknLayoutUtils::LayoutControl( iHighlight[0], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g1().LayoutLine() );
       
   317     AknLayoutUtils::LayoutControl( iHighlight[7], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g8().LayoutLine() );
       
   318     AknLayoutUtils::LayoutControl( iHighlight[8], highlightRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g9().LayoutLine() );
       
   319     // Images need to be resized separately, because the standard LayoutImage
       
   320     // tries to preserve the aspect ratio and we don't want that.
       
   321     //
       
   322     for ( TInt i = 0; i < iHighlight.Count(); ++i )
       
   323         {
       
   324         AknIconUtils::SetSize(
       
   325             const_cast<CFbsBitmap*>( iHighlight[i]->Bitmap() ),
       
   326             iHighlight[i]->Size(), EAspectRatioNotPreserved );
       
   327         }
       
   328 
       
   329 	iHighlightPos = highlightRect.iTl - iHighlightPos;
       
   330     }
       
   331 
       
   332 //=============================================================================    
       
   333 void CPluginGrid::Draw(const TRect& /*aRect*/) const
       
   334     {
       
   335     //  Get graphics context
       
   336     CWindowGc & gc = SystemGc();
       
   337 
       
   338 	//	Draw preview image if found
       
   339 	if ( (*iBitmap)->Handle() )
       
   340 	    {
       
   341 		gc.BitBlt (Rect().iTl, *iBitmap);
       
   342         }
       
   343     
       
   344     TBool variant = Layout_Meta_Data::IsLandscapeOrientation();  
       
   345     TAknLayoutRect layoutRect;
       
   346     for ( TInt i = 0; i < iNumberOfRows; ++i )
       
   347         {
       
   348 	    for ( TInt j = 0; j < iNumberOfColumns; ++j )
       
   349 	        {
       
   350 	        if(j + iNumberOfColumns * i == iCurrentItem)
       
   351 	        	{
       
   352 			    layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::listscroll_imed_pane (variant) );
       
   353 			    layoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane(j, i,variant) );
       
   354 				TPoint deltaPos = iHighlight[1]->Position() - (layoutRect.Rect().iTl + iHighlightPos);
       
   355 
       
   356 			    for ( TInt ii = 0; ii < iHighlight.Count(); ++ii )
       
   357 					{
       
   358 			            iHighlight[ii]->SetPosition(iHighlight[ii]->Position() - deltaPos);
       
   359 			        }
       
   360 	        	}
       
   361 	        }
       
   362         }
       
   363     }
       
   364 
       
   365 //=============================================================================    
       
   366 TKeyResponse CPluginGrid::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   367     {
       
   368     TKeyResponse res = EKeyWasNotConsumed;
       
   369 
       
   370     if (aType == EEventKey) 
       
   371         {
       
   372         // If in landscape mode, do different mapping for the number keys.
       
   373         TUint keyCode = aKeyEvent.iCode;
       
   374         TBool landscape = CResolutionUtil::Self()->GetLandscape();
       
   375         if (landscape)
       
   376         	{
       
   377             switch (keyCode)
       
   378                 {
       
   379                 case 49: // numeric keypad '1'
       
   380                     keyCode = 55;
       
   381                     break;
       
   382                 case 50: // numeric keypad '2'
       
   383                     keyCode = 52;
       
   384                     break;
       
   385                 case 51: // numeric keypad '3'
       
   386                     keyCode = 49;
       
   387                     break;
       
   388                 case 52: // numeric keypad '4'
       
   389                     keyCode = 56;
       
   390                     break;
       
   391                 case 54: // numeric keypad '6'
       
   392                     keyCode = 50;
       
   393                     break;
       
   394                 case 55: // numeric keypad '7'
       
   395                     keyCode = 57;
       
   396                     break;
       
   397                 case 56: // numeric keypad '8'
       
   398                     keyCode = 54;
       
   399                     break;
       
   400                 case 57: // numeric keypad '9'
       
   401                     keyCode = 51;
       
   402                     break;
       
   403                 default:
       
   404                     break;
       
   405                 }
       
   406         	}
       
   407 
       
   408         switch (keyCode)
       
   409             {
       
   410             case EKeyLeftArrow:
       
   411             case 52: // numeric keypad '4'
       
   412                 {
       
   413 			    if( AknLayoutUtils::LayoutMirrored() )
       
   414 			        {                  
       
   415 	                iCurrentItem++;
       
   416 	                if (iCurrentItem >= iPluginItems->Count())
       
   417 	                    {
       
   418 	                    iCurrentItem = 0; 
       
   419 	                    }
       
   420 			        }
       
   421 				else
       
   422 			        {                  
       
   423 	                if (iCurrentItem == 0)
       
   424 	                    {
       
   425 	                    iCurrentItem = iPluginItems->Count() - 1; 
       
   426 	                    }
       
   427 	                else
       
   428 	                    {
       
   429 	                    iCurrentItem--;
       
   430 	                    }
       
   431 			        }
       
   432 
       
   433                 res = EKeyWasConsumed;
       
   434                 break;
       
   435                 }
       
   436 
       
   437             case EKeyRightArrow:
       
   438             case 54: // numeric keypad '6'
       
   439                 {
       
   440 			    if( AknLayoutUtils::LayoutMirrored() )
       
   441 			        {                  
       
   442 	                if (iCurrentItem == 0)
       
   443 	                    {
       
   444 	                    iCurrentItem = iPluginItems->Count() - 1; 
       
   445 	                    }
       
   446 	                else
       
   447 	                    {
       
   448 	                    iCurrentItem--;
       
   449 	                    }
       
   450 			        }
       
   451 				else
       
   452 			        {                  
       
   453 	                iCurrentItem++;
       
   454 	                if (iCurrentItem >= iPluginItems->Count())
       
   455 	                    {
       
   456 	                    iCurrentItem = 0; 
       
   457 	                    }
       
   458 			        }
       
   459 
       
   460                 res = EKeyWasConsumed;
       
   461                 break;
       
   462                 }
       
   463 
       
   464             case EKeyDownArrow:
       
   465             case 56: // numeric keypad '8'
       
   466                 {
       
   467                 iCurrentItem += iNumberOfColumns;
       
   468                 if (iCurrentItem >= iPluginItems->Count())
       
   469                     {
       
   470                     iCurrentItem = iCurrentItem - iPluginItems->Count();
       
   471                     }
       
   472 
       
   473                 res = EKeyWasConsumed;
       
   474                 break;
       
   475                 }
       
   476 
       
   477             case EKeyUpArrow:
       
   478             case 50: // numeric keypad '2'
       
   479                 {
       
   480                 iCurrentItem -= iNumberOfColumns;
       
   481                 if (iCurrentItem < 0)
       
   482                     {
       
   483                     iCurrentItem = iPluginItems->Count() + iCurrentItem;
       
   484                     }
       
   485 
       
   486                 res = EKeyWasConsumed;
       
   487                 break;
       
   488                 }
       
   489 
       
   490             case 49: // numeric keypad '1'
       
   491                 {
       
   492                 // Move up and left
       
   493                 iCurrentItem -= iNumberOfColumns;
       
   494 			    if( AknLayoutUtils::LayoutMirrored() )
       
   495 			    if( AknLayoutUtils::LayoutMirrored() )
       
   496 			        {                  
       
   497 	                iCurrentItem ++;
       
   498 			        }
       
   499 				else
       
   500 			        {                  
       
   501 	                iCurrentItem --;
       
   502 			        }
       
   503                 if (iCurrentItem < 0)
       
   504                     {
       
   505                     iCurrentItem = iPluginItems->Count() + iCurrentItem;
       
   506                     }
       
   507                 res = EKeyWasConsumed;
       
   508                 break;
       
   509                 }
       
   510 
       
   511             case 51: // numeric keypad '3'
       
   512                 {
       
   513                 // Move up and right
       
   514                 iCurrentItem -= iNumberOfColumns;
       
   515 			    if( AknLayoutUtils::LayoutMirrored() )
       
   516 			        {                  
       
   517 	                iCurrentItem --;
       
   518 			        }
       
   519 				else
       
   520 			        {                  
       
   521 	                iCurrentItem ++;
       
   522 			        }
       
   523                 if (iCurrentItem < 0)
       
   524                     {
       
   525                     iCurrentItem = iPluginItems->Count() + iCurrentItem;
       
   526                     }
       
   527                 res = EKeyWasConsumed;
       
   528                 break;
       
   529                 }
       
   530 
       
   531             case 55: // numeric keypad '7'
       
   532                 {
       
   533                 // Move down and left
       
   534                 iCurrentItem += iNumberOfColumns;
       
   535 			    if( AknLayoutUtils::LayoutMirrored() )
       
   536 			        {                  
       
   537 	                iCurrentItem++;
       
   538 			        }
       
   539 				else
       
   540 			        {                  
       
   541 	                iCurrentItem--;
       
   542 			        }
       
   543                 if (iCurrentItem >= iPluginItems->Count())
       
   544                     {
       
   545                     iCurrentItem = iCurrentItem - iPluginItems->Count();
       
   546                     }
       
   547                 res = EKeyWasConsumed;
       
   548                 break;
       
   549                 }
       
   550 
       
   551             case 57: // numeric keypad '9'
       
   552                 {
       
   553                 // Move down and left
       
   554                 iCurrentItem += iNumberOfColumns;
       
   555 			    if( AknLayoutUtils::LayoutMirrored() )
       
   556 			        {                  
       
   557 	                iCurrentItem--;
       
   558 			        }
       
   559 				else
       
   560 			        {                  
       
   561 	                iCurrentItem++;
       
   562 			        }
       
   563                 if (iCurrentItem >= iPluginItems->Count())
       
   564                     {
       
   565                     iCurrentItem = iCurrentItem - iPluginItems->Count();
       
   566                     }
       
   567                 res = EKeyWasConsumed;
       
   568                 break;
       
   569                 }
       
   570 
       
   571              default:
       
   572                 {
       
   573                 break;
       
   574                 }
       
   575 
       
   576             }
       
   577 
       
   578         }
       
   579 
       
   580     return res;
       
   581     }
       
   582     
       
   583 //=============================================================================
       
   584 void CPluginGrid::HandlePointerEventL( const TPointerEvent &aPointerEvent )
       
   585     {	
       
   586     if( AknLayoutUtils::PenEnabled() )
       
   587 		{
       
   588 		switch( aPointerEvent.iType )
       
   589 			{
       
   590 			case TPointerEvent::EButton1Down:
       
   591 			case TPointerEvent::EDrag:
       
   592 				{
       
   593 				TBool variant = Layout_Meta_Data::IsLandscapeOrientation(); 	
       
   594 			    TAknLayoutRect layoutRect;
       
   595 			    for ( TInt i = 0; i < iNumberOfRows; ++i )
       
   596 			        {
       
   597 				    for ( TInt j = 0; j < iNumberOfColumns; ++j )
       
   598 				        {
       
   599 					    layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::listscroll_imed_pane (variant) );
       
   600 					    layoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane(j, i, variant) );
       
   601 
       
   602 						if( layoutRect.Rect().Contains( aPointerEvent.iPosition ) )
       
   603 							{
       
   604 							// set new highlighted item
       
   605 							iCurrentItem = j + iNumberOfColumns * i;
       
   606 							return;
       
   607 							}
       
   608 				        }
       
   609 			        }
       
   610 
       
   611 				break;
       
   612 				}
       
   613 			case TPointerEvent::EButton1Up:
       
   614 				{
       
   615 				break;
       
   616 				}
       
   617 			default:
       
   618 				{
       
   619 				break;	
       
   620 				}	
       
   621 			}
       
   622 		}
       
   623     }
       
   624 
       
   625 //=============================================================================    
       
   626 TRect CPluginGrid::GridRect() const
       
   627     {
       
   628     TRect boundingRect( iTouchGridRect );
       
   629 //    boundingRect.BoundingRect( iTitleboxBorderRect );
       
   630     return boundingRect;
       
   631     }
       
   632 
       
   633 //=============================================================================    
       
   634 TBool CPluginGrid::HighlightedItemPressed( TPoint aPosition ) const
       
   635     {	
       
   636     TAknLayoutRect layoutRect;
       
   637     TBool variant = Layout_Meta_Data::IsLandscapeOrientation(); 
       
   638     for ( TInt i = 0; i < iNumberOfRows; ++i )
       
   639         {
       
   640 	    for ( TInt j = 0; j < iNumberOfColumns; ++j )
       
   641 	        {
       
   642 	        if(j + iNumberOfColumns * i == iCurrentItem)
       
   643 	        	{
       
   644 			    layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::listscroll_imed_pane (variant) );
       
   645 			    layoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane(j, i, variant) );
       
   646 	        	}
       
   647 	        }
       
   648         }
       
   649                     
       
   650     if (layoutRect.Rect().Contains( aPosition ))  
       
   651         {
       
   652         return ETrue;
       
   653         }
       
   654     else 
       
   655         {
       
   656         return EFalse;
       
   657         }       
       
   658     }
       
   659 
       
   660 //=============================================================================
       
   661 void CPluginGrid::ShowTooltip ( CAknInfoPopupNoteController* aPopupController,
       
   662                                 CCoeControl* aCallingControl )
       
   663     {
       
   664     TAknLayoutRect layoutRect;
       
   665     TBool variant = Layout_Meta_Data::IsLandscapeOrientation();
       
   666     
       
   667     TBool layoutFound = EFalse; 
       
   668     for ( TInt i = 0; i < iNumberOfRows; ++i )
       
   669         {
       
   670 	    for ( TInt j = 0; j < iNumberOfColumns; ++j )
       
   671 	        {
       
   672 	        if(j + iNumberOfColumns * i == iCurrentItem)
       
   673 	        	{
       
   674 			    layoutRect.LayoutRect( iParentRect, AknLayoutScalable_Apps::listscroll_imed_pane (variant) );
       
   675 			    layoutRect.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::cell_imed_effect_pane(j, i, variant) );
       
   676 			    layoutFound = ETrue;
       
   677 	        	}
       
   678 	        }
       
   679         }
       
   680     
       
   681     if( layoutFound )    
       
   682         {
       
   683         CPluginInfo * pgn_info = ( *iPluginItems )[ iCurrentItem ];
       
   684     
       
   685         // change default time to shorter one
       
   686         aPopupController->SetTimeDelayBeforeShow( KTooltipDelayBeforeShow );
       
   687             
       
   688         SDrawUtils::ShowToolTip( aPopupController,
       
   689                                  aCallingControl,
       
   690                                  layoutRect.Rect(),
       
   691                                  pgn_info->PluginName()->Des() );    
       
   692         }
       
   693     
       
   694     }
       
   695 
       
   696 //=============================================================================    
       
   697 TInt CPluginGrid::CountComponentControls() const
       
   698     {
       
   699     TInt count = iBorders.Count();
       
   700     count += iHighlight.Count();
       
   701     count += iIcons.Count();
       
   702 	count++;
       
   703 
       
   704     return count;
       
   705     }
       
   706 
       
   707 //=============================================================================    
       
   708 CCoeControl* CPluginGrid::ComponentControl(TInt aIndex) const
       
   709     {
       
   710     if ( aIndex < iBorders.Count() )
       
   711         {
       
   712         return iBorders[aIndex];
       
   713         }
       
   714     if ( aIndex < iBorders.Count() + iHighlight.Count())
       
   715         {
       
   716         return iHighlight[aIndex - iBorders.Count()];
       
   717         }
       
   718     if ( aIndex < iBorders.Count() + iHighlight.Count() + iIcons.Count())
       
   719         {
       
   720         return iIcons[aIndex - iBorders.Count() - iHighlight.Count()];
       
   721         }
       
   722 
       
   723     return iText;
       
   724     }
       
   725 
       
   726 //=============================================================================
       
   727 TInt CPluginSelectionDialog::RunDlgLD(CFbsBitmap** aBitmap, 
       
   728                                        TInt& aSelectedItem, 
       
   729                                        const RPluginArray* aItems,
       
   730                                        const TRect& aRect)
       
   731     {
       
   732     CPluginSelectionDialog* dialog = 
       
   733         new (ELeave) CPluginSelectionDialog (aBitmap, aSelectedItem, aItems);
       
   734     dialog->ConstructL(aRect);
       
   735     return dialog->ExecuteLD(R_IMAGE_EDITOR_PLUGIN_DIALOG);
       
   736     }
       
   737 
       
   738 //=============================================================================
       
   739 CPluginSelectionDialog::CPluginSelectionDialog(CFbsBitmap** aBitmap, 
       
   740                                                TInt& aSelectedItem, 
       
   741                                                const RPluginArray* aItems)
       
   742  : iBitmap(aBitmap), iItems(aItems), iSelectedItem(aSelectedItem)
       
   743     {
       
   744 
       
   745     }
       
   746 //=============================================================================
       
   747 CPluginSelectionDialog::~CPluginSelectionDialog()
       
   748     {
       
   749     delete iGrid;
       
   750     iBitmap = NULL;
       
   751     iItems = NULL;
       
   752     delete iPopupController;
       
   753     iPopupController = NULL;
       
   754     }
       
   755 
       
   756 //=============================================================================
       
   757 
       
   758 void CPluginSelectionDialog::ConstructL(const TRect& aRect)
       
   759     {
       
   760     SetRect(aRect);
       
   761 
       
   762     iGrid = new (ELeave) CPluginGrid(iBitmap, iItems);
       
   763     iGrid->ConstructL();
       
   764 
       
   765     iGrid->SetSize(aRect.Size());
       
   766     iGrid->SetPosition(TPoint(0,0));
       
   767 
       
   768     iPopupController = CAknInfoPopupNoteController::NewL(); 
       
   769     
       
   770 #ifdef RD_TACTILE_FEEDBACK 
       
   771     iTouchFeedBack = MTouchFeedback::Instance();
       
   772 #endif /* RD_TACTILE_FEEDBACK  */
       
   773     
       
   774     }
       
   775 
       
   776 //=============================================================================
       
   777 TBool CPluginSelectionDialog::OkToExitL( TInt aButtonId )
       
   778     {
       
   779     if ( aButtonId == EAknSoftkeyOk || aButtonId == EAknSoftkeySelect)
       
   780         {
       
   781         if (iGrid)
       
   782             {
       
   783             iSelectedItem = iGrid->GetSelectedItemIndex();
       
   784             }
       
   785         return ETrue;
       
   786         }
       
   787     else
       
   788         {
       
   789         iSelectedItem = KErrCancel;
       
   790         return EFalse;
       
   791         }
       
   792     }
       
   793 
       
   794 //=============================================================================    
       
   795 void CPluginSelectionDialog::Draw(const TRect& /*aRect*/) const
       
   796     {
       
   797     }
       
   798 
       
   799 //=============================================================================    
       
   800 void CPluginSelectionDialog::SizeChanged()
       
   801     {
       
   802     if (iGrid)
       
   803 	    {
       
   804 	    iGrid->SetRect( Rect() );
       
   805 	    iGrid->SizeChanged();
       
   806 	    
       
   807 		if ( iPopupController )
       
   808 		    {
       
   809 		    // Shows the first tooltip when effect grid is entered
       
   810 		    iGrid->ShowTooltip( iPopupController, this );
       
   811 		    }		
       
   812 	    }  
       
   813     }
       
   814 
       
   815 //=============================================================================    
       
   816 TInt CPluginSelectionDialog::CountComponentControls() const
       
   817     {
       
   818     return 1;
       
   819     }
       
   820 
       
   821 //=============================================================================    
       
   822 CCoeControl* CPluginSelectionDialog::ComponentControl(TInt /*aIndex*/) const
       
   823     {
       
   824     return iGrid;
       
   825     }
       
   826 
       
   827 //=============================================================================    
       
   828 TKeyResponse CPluginSelectionDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   829     {
       
   830     // Selection key or numeric keypad '5' close the dialog
       
   831     TKeyResponse res = EKeyWasNotConsumed;
       
   832     if (aType == EEventKey && 
       
   833         (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == 53 || aKeyEvent.iScanCode == EStdKeyEnter) )
       
   834         {
       
   835         TryExitL (EAknSoftkeyOk);
       
   836         res = EKeyWasConsumed;
       
   837         }
       
   838     else if (aType == EEventKey && aKeyEvent.iCode == EKeyNo || aKeyEvent.iCode == EKeyEscape) // Do not exit if dialog active
       
   839 		{
       
   840 		TryExitL (EAknSoftkeyCancel);
       
   841 		res = EKeyWasNotConsumed;
       
   842         }
       
   843 #ifdef FULLSCREEN_AVAILABLE        
       
   844     else if (aType == EEventKey && aKeyEvent.iCode == 48 ) // 0             
       
   845       {
       
   846       // Switch normal screen / full screen
       
   847       if (CResolutionUtil::Self()->GetFullScreen())
       
   848           {
       
   849           iEikonEnv->EikAppUi()->HandleCommandL(EImageEditorMenuCmdNormalScreen);
       
   850 	      SetRect(iEikonEnv->EikAppUi()->ClientRect());
       
   851 	      SizeChanged();
       
   852 	      DrawNow();
       
   853           }
       
   854       else
       
   855 	      {      
       
   856 	      iEikonEnv->EikAppUi()->HandleCommandL(EImageEditorMenuCmdFullScreen);			  
       
   857 	      SetExtentToWholeScreen();
       
   858 	      SizeChanged();
       
   859 	      DrawNow();
       
   860 	      }              
       
   861       res = EKeyWasConsumed;              
       
   862       }
       
   863 #endif // FULLSCREEN_AVAILABLE      						 
       
   864     else 
       
   865         {
       
   866         res = iGrid->OfferKeyEventL(aKeyEvent, aType);
       
   867         if (res == EKeyWasConsumed)
       
   868             {
       
   869             DrawDeferred();
       
   870             iGrid->ShowTooltip( iPopupController, this );
       
   871             }
       
   872 
       
   873         }
       
   874         
       
   875     return res;
       
   876     }
       
   877 
       
   878 //=============================================================================
       
   879 void CPluginSelectionDialog::HandlePointerEventL( 
       
   880                                            const TPointerEvent &aPointerEvent )
       
   881     {
       
   882     if( AknLayoutUtils::PenEnabled() )
       
   883 	    {
       
   884         TBool draw( EFalse );
       
   885         switch( aPointerEvent.iType )
       
   886 			{
       
   887 			case TPointerEvent::EButton1Down:
       
   888 				{
       
   889 			    // forward event only if grid area was pressed    
       
   890 			    if ( iGrid->GridRect().Contains( aPointerEvent.iPosition ) )
       
   891 			        {
       
   892 			        iPopupController->HideInfoPopupNote();
       
   893 #ifdef RD_TACTILE_FEEDBACK 
       
   894 					if ( iTouchFeedBack )
       
   895 	                	{
       
   896 			            iTouchFeedBack->InstantFeedback( ETouchFeedbackBasic );
       
   897 			            RDebug::Printf( "ImageEditor::CPluginSelectionDialog: ETouchFeedback" );
       
   898 	                	}
       
   899 #endif /* RD_TACTILE_FEEDBACK  */
       
   900 			        iGrid->HandlePointerEventL( aPointerEvent );			        
       
   901 			        draw = ETrue;
       
   902 			        }    
       
   903 		        else
       
   904 		            {
       
   905 		            // Cancel if tapped outside of the grid
       
   906 		            TryExitL( EAknSoftkeyCancel );
       
   907 		            }
       
   908 				break;
       
   909 				}
       
   910 			case TPointerEvent::EDrag:
       
   911 				{
       
   912 			    if ( iGrid->GridRect().Contains( aPointerEvent.iPosition ) )
       
   913 			        {
       
   914 			        TBool highlightedBefore = 
       
   915 			            iGrid->HighlightedItemPressed( aPointerEvent.iPosition );
       
   916 			        
       
   917 			        iGrid->HandlePointerEventL( aPointerEvent );
       
   918 			        
       
   919 			        TBool highlightedAfter = 
       
   920 			            iGrid->HighlightedItemPressed( aPointerEvent.iPosition );
       
   921 			        
       
   922 			        // if these two values differ from each other, it indicates
       
   923 			        // that focus has changed in the grid to a new item    
       
   924 			        if ( highlightedBefore != highlightedAfter )
       
   925 			            {
       
   926 #ifdef RD_TACTILE_FEEDBACK 
       
   927                         if ( iTouchFeedBack )
       
   928                             {
       
   929                             iTouchFeedBack->InstantFeedback( ETouchFeedbackSensitive );
       
   930                             RDebug::Printf( "ImageEditor::CPluginSelectionDialog: ETouchFeedbackSensitive" );
       
   931                             }
       
   932 #endif /* RD_TACTILE_FEEDBACK  */
       
   933 			        
       
   934 			            draw = ETrue;			                
       
   935 			            }			        			        
       
   936 			        }
       
   937 				break;		
       
   938 				}
       
   939 			case TPointerEvent::EButton1Up:
       
   940 				{
       
   941 				// already highlighted item is pressed
       
   942 			    if ( iGrid->HighlightedItemPressed( aPointerEvent.iPosition ) )
       
   943 			        {
       
   944 			        TryExitL (EAknSoftkeyOk);
       
   945 			        }
       
   946 				break;
       
   947 				}
       
   948 			default:
       
   949 				{
       
   950 				break;	
       
   951 				}	
       
   952 			}
       
   953 			
       
   954 	    if ( draw )
       
   955 	        {
       
   956 		    DrawDeferred();
       
   957 		    iGrid->ShowTooltip( iPopupController, this );
       
   958 	        }	
       
   959         }
       
   960     }
       
   961     
       
   962 // End of File