imageeditor/plugins/DrawPlugin/src/imageeditordrawcontrol.cpp
changeset 1 edfc90759b9f
child 12 18b321db4884
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 * Image Editor plugin control class.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 //  INCLUDES
       
    22 #include "imageeditordrawcontrol.h"
       
    23 #include "draw.hrh"
       
    24 
       
    25 #include "ImageEditorUI.hrh"
       
    26 #include "ImageEditorPluginBase.hrh"
       
    27 
       
    28 #include "PluginInfo.h"
       
    29 #include "JpTimer.h"
       
    30 #include "ImageEditorUids.hrh"
       
    31 #include "ImageEditorUiDefs.h"
       
    32 #include "SystemParameters.h"
       
    33 #include "drawpath.h"
       
    34 #include "selectionpopup.h"
       
    35 
       
    36 #include "iepb.h" 
       
    37 // debug log
       
    38 #include "imageeditordebugutils.h"
       
    39 
       
    40 #include <fbs.h>
       
    41 #include <badesca.h>
       
    42 #include <gdi.h>
       
    43 #include <eikenv.h>
       
    44 #include <bitdev.h>
       
    45 
       
    46 #include <aknview.h>
       
    47 #include <aknutils.h>
       
    48 
       
    49 #include <ImageEditorUI.mbg>
       
    50 #include <AknInfoPopupNoteController.h> 
       
    51 #include <draw.rsg> 
       
    52 #include <bautils.h> 
       
    53 #include <ConeResLoader.h> 
       
    54 #include <gulalign.h>
       
    55 #include <csxhelp/sie.hlp.hrh>
       
    56 
       
    57 // Log file
       
    58 _LIT(KDrawPluginLogFile,"drawplugin.log");
       
    59 
       
    60 //  CONSTANTS
       
    61 const TInt KWait			    	= 1;
       
    62 const TInt KMainTextIndex           = 0;
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // NewL
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CImageEditorDrawControl* CImageEditorDrawControl::NewL(
       
    69 	const TRect& aRect,
       
    70 	CCoeControl* aParent )
       
    71     {
       
    72     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::NewL()");
       
    73 
       
    74     CImageEditorDrawControl * self = new (ELeave) CImageEditorDrawControl;
       
    75     CleanupStack::PushL (self);
       
    76     self->ConstructL (aRect, aParent);
       
    77     CleanupStack::Pop ();   // self
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CImageEditorDrawControl
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CImageEditorDrawControl::CImageEditorDrawControl() : 
       
    86 iTickCount(0),
       
    87 iNaviStepMultiplier(KDefaultSmallNavigationStepMultiplier),
       
    88 iDisplayingOkOptionsMenu(EFalse),
       
    89 iReadyToRender(EFalse),
       
    90 iResLoader( *ControlEnv() )
       
    91 {}
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // ~CImageEditorDrawControl()
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CImageEditorDrawControl::~CImageEditorDrawControl()
       
    98     {
       
    99     LOG(KDrawPluginLogFile, 
       
   100             "CImageEditorDrawControl::~CImageEditorDrawControl()");    
       
   101     delete iTimer;
       
   102     delete iIndicator;
       
   103     delete iIndicatorMask;
       
   104 	delete iPopupController;
       
   105 	delete iTooltipResize;
       
   106 	iPaths.ResetAndDestroy();
       
   107     delete iNaviPaneText;	
       
   108 	iResLoader.Close();
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // ConstructL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CImageEditorDrawControl::ConstructL(
       
   116 	const TRect& /*aRect*/, CCoeControl* aParent )
       
   117     {
       
   118     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::ConstructL()");
       
   119 	//	Set parent window
       
   120 	SetContainerWindowL(*aParent);
       
   121     
       
   122     //  Create resource utility
       
   123 	TFileName resFile;
       
   124 	// resource file name
       
   125 	_LIT (KResourceFile, "draw.rsc");	
       
   126 	resFile.Append(KPgnResourcePath);
       
   127 	resFile.Append(KResourceFile);
       
   128 
       
   129     User::LeaveIfError( CompleteWithAppPath( resFile ) );
       
   130     // Implementation of RConeResourceLoader uses BaflUtils::NearestLanguageFile 
       
   131     // to search for a localised resource in proper search order
       
   132     iResLoader.OpenL( resFile );
       
   133     
       
   134 	//	Create timer for fast key repeat
       
   135 	iTimer = CJPTimer::NewL( this );
       
   136 
       
   137 	iPopupController = CAknInfoPopupNoteController::NewL();    
       
   138 	iTooltipResize = ControlEnv()->AllocReadResourceL(R_TOOLTIP_TEXT_RESIZE);           
       
   139 	    
       
   140     EnableDragEvents();
       
   141         
       
   142 	//	Activate control
       
   143     ActivateL();
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // SetView
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CImageEditorDrawControl::SetView(CAknView* aView)
       
   151     {
       
   152     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::SetView()");
       
   153     ASSERT( aView );
       
   154     iEditorView = aView;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // SetSelectedUiItemL
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CImageEditorDrawControl::SetSelectedUiItemL(CPluginInfo* aItem)
       
   162     {
       
   163     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::SetSelectedUiItemL()");
       
   164     ASSERT( aItem );
       
   165     iItem = aItem;
       
   166     delete iNaviPaneText;
       
   167     iNaviPaneText = NULL;
       
   168     iNaviPaneText = (iItem->Parameters()[KMainTextIndex]).AllocL();
       
   169     iEditorView->HandleCommandL(EImageEditorCmdRender);
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // OfferKeyEventL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 TKeyResponse CImageEditorDrawControl::OfferKeyEventL(
       
   177     const TKeyEvent& aKeyEvent,
       
   178     TEventCode aType)
       
   179     {
       
   180     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::OfferKeyEventL()");
       
   181 
       
   182     TKeyResponse response = EKeyWasNotConsumed;
       
   183 
       
   184     //  If busy, do not handle anything
       
   185     if ( Busy() )
       
   186     {
       
   187         response = EKeyWasConsumed;
       
   188     }
       
   189 
       
   190     // In main state handle the OK Options menu
       
   191     else if ( aKeyEvent.iCode == EKeyOK )
       
   192         {
       
   193         iDisplayingOkOptionsMenu = ETrue;
       
   194         iEditorView->HandleCommandL (EImageEditorTryDisplayMenuBar);
       
   195         response = EKeyWasConsumed;
       
   196         }
       
   197 
       
   198     //  We handle only event keys
       
   199     else if (EEventKey == aType)
       
   200     {
       
   201 
       
   202 		switch (aKeyEvent.iCode)
       
   203 		{
       
   204 		
       
   205 			case EKeyDownArrow:
       
   206 			case EKeyUpArrow:
       
   207 			case EKeyRightArrow:
       
   208             case EKeyLeftArrow:
       
   209 			{		
       
   210 			    SetPositionOnImage( ComputeIndicatorPosition() );
       
   211 		    	StoreParameters( EFalse, EFalse );			    
       
   212 				response = EKeyWasConsumed;
       
   213                 break;
       
   214 			}
       
   215 		
       
   216             case EKeyOK:
       
   217                 {           
       
   218                 break;
       
   219                 }
       
   220 
       
   221 		    case 0x30: // 0		    		    
       
   222 		    case 0x32: // 2
       
   223 		    case 0x34: // 4
       
   224 		    case 0x35: // 5
       
   225 		    case 0x36: // 6
       
   226 		    case 0x38: // 8
       
   227 			case EStdKeyIncVolume: // zoom in key
       
   228 			case EStdKeyDecVolume: // zoom out key
       
   229 		    {
       
   230 		    	StorePosAndScaleRelScreen();
       
   231 		    	break;
       
   232 		    }
       
   233 
       
   234 			default:
       
   235 			{
       
   236 				break;
       
   237 			}
       
   238 		}
       
   239 	}
       
   240 
       
   241 	//	Key pressed down, mark pressed key
       
   242 	else if (aType == EEventKeyDown)
       
   243 	{
       
   244 		switch (aKeyEvent.iScanCode)
       
   245 		{
       
   246 			case EStdKeyUpArrow:
       
   247 			{
       
   248 				iKeyCode = 1;
       
   249 			    response = EKeyWasConsumed;
       
   250 				break;
       
   251 			}
       
   252 			case EStdKeyDownArrow:
       
   253 			{
       
   254 				iKeyCode = 2;
       
   255 			    response = EKeyWasConsumed;
       
   256 				break;
       
   257 			}
       
   258 			case EStdKeyLeftArrow:
       
   259 			{
       
   260 				iKeyCode = 3;
       
   261 			    response = EKeyWasConsumed;
       
   262 				break;
       
   263 			}
       
   264 			case EStdKeyRightArrow:
       
   265 			{
       
   266 				iKeyCode = 4;
       
   267 			    response = EKeyWasConsumed;
       
   268 				break;
       
   269 			}
       
   270 		}
       
   271 
       
   272 		if ( iKeyCode != 0 )
       
   273 		{
       
   274 		    iNaviStepMultiplier = KDefaultSmallNavigationStepMultiplier;
       
   275 		    iTickCount = 0;
       
   276 			iTimer->Call( KWait );
       
   277 		}
       
   278 	}
       
   279 	
       
   280 	//	Key released, mark all keys to zero
       
   281 	else if (aType == EEventKeyUp)
       
   282 	{
       
   283 		switch (aKeyEvent.iScanCode)
       
   284 		{
       
   285 			case EStdKeyUpArrow:
       
   286 			case EStdKeyDownArrow:
       
   287 			case EStdKeyLeftArrow:
       
   288 			case EStdKeyRightArrow:
       
   289 			{
       
   290 				iKeyCode = 0;
       
   291 			    response = EKeyWasConsumed;
       
   292 			    ShowTooltip();
       
   293 				break;
       
   294 			}
       
   295 		}
       
   296 	}
       
   297 
       
   298     return response;
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // SizeChanged
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 void CImageEditorDrawControl::SizeChanged()
       
   306     {
       
   307     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::SizeChanged()");
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // GetParam
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 TDesC& CImageEditorDrawControl::GetParam()
       
   315     {
       
   316     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::GetParam()");
       
   317     LOGDES(KDrawPluginLogFile, iParam);
       
   318 	return iParam;
       
   319     }
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // SetSystemParameters
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void CImageEditorDrawControl::SetSystemParameters(const CSystemParameters* aPars) 
       
   326     {
       
   327     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::SetSystemParameters()");
       
   328     ASSERT( aPars );
       
   329     iSysPars = aPars;
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // HandlePluginCommandL
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 void CImageEditorDrawControl::HandlePluginCommandL(const TInt aCommand)
       
   337     {
       
   338     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::HandlePluginCommandL()");
       
   339 
       
   340     switch (aCommand) 
       
   341         {
       
   342         case EImageEditorFocusLost:
       
   343             {
       
   344             if (iTimer)
       
   345                 {
       
   346                 iTimer->Cancel();
       
   347                 }
       
   348             break;
       
   349             }
       
   350         case EPgnSoftkeyIdOk:
       
   351             {
       
   352             iPopupController->HideInfoPopupNote();
       
   353             break;
       
   354             }
       
   355         case EPgnSoftkeyIdCancel:
       
   356             {
       
   357             iPopupController->HideInfoPopupNote();
       
   358             iEditorView->HandleCommandL (EImageEditorCancelPlugin);
       
   359             break;
       
   360             }
       
   361         case EPgnSoftkeyIdDone:
       
   362             // FALLTROUHG
       
   363         case EDrawPgnMenuCmdDone:
       
   364             {   
       
   365             iPopupController->HideInfoPopupNote();
       
   366             StoreParameters(EFalse, ETrue);
       
   367             iEditorView->HandleCommandL( EImageEditorCmdRender );//results Draw call
       
   368             iEditorView->HandleCommandL(EImageEditorApplyPlugin);
       
   369             break;
       
   370             }
       
   371         case EDrawPgnMenuCmdResize:
       
   372             {
       
   373             StoreParameters(ETrue, ETrue);
       
   374             iEditorView->HandleCommandL( EImageEditorCmdRender );//results Draw call
       
   375             SelectSizeL();         
       
   376             break;
       
   377             }
       
   378         case EDrawPgnMenuCmdColor:
       
   379             {
       
   380             StoreParameters(ETrue, ETrue);
       
   381             iEditorView->HandleCommandL( EImageEditorCmdRender );//results Draw call            
       
   382             SDrawUtils::LaunchColorSelectionPopupL(iPreview, Rect(), iRgb);
       
   383             break;
       
   384             }
       
   385         case EDrawPgnMenuCmdCancel:
       
   386             {
       
   387 			iReadyToRender = EFalse;
       
   388             iEditorView->HandleCommandL(EImageEditorCancelPlugin);
       
   389             break;
       
   390             }
       
   391         
       
   392         case EImageEditorGlobalZoomChanged:
       
   393             // FALLTROUGHT
       
   394         case EImageEditorGlobalPanChanged:
       
   395             {
       
   396 			RestorePosAndScaleRelScreen();
       
   397 			//StoreParameters();
       
   398             StoreTempParams();
       
   399 	    	iEditorView->HandleCommandL (EImageEditorCmdRender);
       
   400 
       
   401 			//DrawNow();
       
   402 	        break;
       
   403             }
       
   404         
       
   405         case EImageEditorPreScreenModeChange:
       
   406             {
       
   407 			StorePosAndScaleRelImage();
       
   408         	break;
       
   409             }
       
   410         
       
   411         case EImageEditorPostScreenModeChange:
       
   412             {
       
   413 			RestorePosAndScaleRelImage();
       
   414 			ClipPosition();
       
   415 			//StoreParameters();
       
   416             StoreTempParams();
       
   417 	    	iEditorView->HandleCommandL (EImageEditorCmdRender);
       
   418 			//DrawNow();
       
   419         	break;
       
   420             }
       
   421 
       
   422         default:
       
   423             {
       
   424             break;
       
   425             }
       
   426         }
       
   427     }
       
   428 
       
   429 // ---------------------------------------------------------------------------
       
   430 // GetSoftkeyIndexL
       
   431 // ---------------------------------------------------------------------------
       
   432 //
       
   433 TInt CImageEditorDrawControl::GetSoftkeyIndexL()
       
   434     {
       
   435     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::GetSoftkeyIndexL()");
       
   436     // : Check needed states
       
   437     TInt state(2);
       
   438     return state;
       
   439     }
       
   440 
       
   441 // ---------------------------------------------------------------------------
       
   442 // GetContextMenuResourceId
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 TInt CImageEditorDrawControl::GetContextMenuResourceId()
       
   446     {
       
   447     return R_TEXT_CONTEXT_MENUBAR;    
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------------------------
       
   451 // GetDimmedMenuItems
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 TBitField CImageEditorDrawControl::GetDimmedMenuItems()
       
   455 {
       
   456     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::GetDimmedMenuItems()");
       
   457 
       
   458     TBitField dimmedMenuItems;
       
   459     TInt count = iItem->MenuItems().Count();
       
   460 
       
   461     if ( iDisplayingOkOptionsMenu )
       
   462     {
       
   463         // Dim the command EImageEditorCancelPlugin
       
   464         for ( TInt i = 0; i < count; i++)
       
   465         {
       
   466             // get the menu item id
       
   467             TInt menuItem = iItem->MenuItems().At(i).iCommandId;
       
   468             if ( menuItem == EDrawPgnMenuCmdCancel ) 
       
   469             {
       
   470                 dimmedMenuItems.SetBit( i );
       
   471             }
       
   472         }
       
   473         iDisplayingOkOptionsMenu = EFalse;
       
   474     }
       
   475     
       
   476     for ( TInt i = 0; i < count; i++)
       
   477     {
       
   478         // get the menu item id
       
   479         TInt menuItem = iItem->MenuItems().At(i).iCommandId;
       
   480         if ( menuItem == EDrawPgnMenuCmdMax )
       
   481         	{
       
   482         	dimmedMenuItems.SetBit( i );
       
   483         	}    
       
   484     }
       
   485     return dimmedMenuItems;
       
   486 }
       
   487 
       
   488 // ---------------------------------------------------------------------------
       
   489 // GetNaviPaneTextL
       
   490 // ---------------------------------------------------------------------------
       
   491 //
       
   492 TPtrC CImageEditorDrawControl::GetNaviPaneTextL(
       
   493     TBool& aLeftNaviPaneScrollButtonVisibile, 
       
   494     TBool& aRightNaviPaneScrollButtonVisible )
       
   495     {
       
   496     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::GetNaviPaneTextL()");
       
   497 
       
   498     aLeftNaviPaneScrollButtonVisibile = EFalse;
       
   499     aRightNaviPaneScrollButtonVisible = EFalse;
       
   500     return *iNaviPaneText;
       
   501     }
       
   502 
       
   503 // ---------------------------------------------------------------------------
       
   504 // Draw
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void CImageEditorDrawControl::Draw(const TRect& aRect) const
       
   508     {
       
   509     CWindowGc & gc = SystemGc();
       
   510     if( IsReadyToRender() )
       
   511         {
       
   512         CPreviewControlBase::DrawPreviewImage(aRect);
       
   513         }
       
   514 
       
   515     if( iPaths.Count() )
       
   516         {
       
   517         ASSERT( iSysPars ); 
       
   518         for( TInt i(0); i<iPaths.Count(); ++i)
       
   519             {
       
   520             CDrawPath* path = iPaths[i];
       
   521             CArrayFix<TPoint>* pathPoints = path->ItemArray();
       
   522             gc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   523             gc.SetPenColor( path->Color() );
       
   524             gc.SetPenSize( ScaledLineSize( path->Size() ) );
       
   525             gc.DrawPolyLine( pathPoints );
       
   526             }
       
   527         }
       
   528     
       
   529   /*  
       
   530    * : Too slow cause we need to redraw preview image everytime
       
   531    * if( iIndicator && iIndicator->Handle() && 
       
   532          iIndicatorMask && iIndicatorMask->Handle() )
       
   533         {                
       
   534         gc.BitBltMasked ( 
       
   535             ComputeIndicatorPosition(),
       
   536             iIndicator, 
       
   537             TRect (iIndicator->SizeInPixels()), 
       
   538             iIndicatorMask, 
       
   539             EFalse
       
   540             );
       
   541         }*/       	
       
   542     }
       
   543 
       
   544 // ---------------------------------------------------------------------------
       
   545 // NaviDown
       
   546 // ---------------------------------------------------------------------------
       
   547 //
       
   548 void CImageEditorDrawControl::NaviDown()
       
   549     {
       
   550     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::NaviDown()");
       
   551     }
       
   552 
       
   553 // ---------------------------------------------------------------------------
       
   554 // NaviUp
       
   555 // ---------------------------------------------------------------------------
       
   556 //
       
   557 void CImageEditorDrawControl::NaviUp()
       
   558     {
       
   559     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::NaviUp()");
       
   560     }
       
   561 
       
   562 // ---------------------------------------------------------------------------
       
   563 // NaviRight
       
   564 // ---------------------------------------------------------------------------
       
   565 //
       
   566 void CImageEditorDrawControl::NaviRight()
       
   567     {
       
   568     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::NaviRight()");
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // NaviLeft
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 void CImageEditorDrawControl::NaviLeft()
       
   576     {
       
   577     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::NaviLeft()");
       
   578     }
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // SelectSizeL
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void CImageEditorDrawControl::SelectSizeL()
       
   585     {
       
   586     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::SelectSizeL()");
       
   587     // Symmetric line width / height
       
   588     TInt size(iSize.iWidth);
       
   589     CSelectionDialog::RunDlgLD( iPreview, Rect(), size );
       
   590     iSize = TSize(size,size);
       
   591     }
       
   592 
       
   593 // ---------------------------------------------------------------------------
       
   594 // StoreTempParams
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 void CImageEditorDrawControl::StoreTempParams()
       
   598     {
       
   599     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::StoreTempParams()");
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // RestoreTempParams
       
   604 // ---------------------------------------------------------------------------
       
   605 //
       
   606 void CImageEditorDrawControl::RestoreTempParams()
       
   607     {
       
   608     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::RestoreTempParams()");
       
   609     }
       
   610 
       
   611 // ---------------------------------------------------------------------------
       
   612 // GetHelpContext
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 void CImageEditorDrawControl::GetHelpContext(TCoeHelpContext& aContext) const
       
   616 {
       
   617     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::GetHelpContext()");
       
   618 
       
   619     aContext.iMajor = TUid::Uid(UID_IMAGE_EDITOR);
       
   620     aContext.iContext = KSIE_HLP_EDIT_TEXT;
       
   621 }
       
   622 
       
   623 // ---------------------------------------------------------------------------
       
   624 // PrepareL
       
   625 // ---------------------------------------------------------------------------
       
   626 //
       
   627 void CImageEditorDrawControl::PrepareL()
       
   628     {
       
   629     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::PrepareL()");
       
   630     
       
   631 	//	Get current view port
       
   632 	TRect rect = iSysPars->VisibleImageRectPrev();
       
   633 	
       
   634 	//	Set default position
       
   635 	iX = (rect.iTl.iX + rect.iBr.iX) / 2;
       
   636 	iY = (rect.iTl.iY + rect.iBr.iY) / 2;
       
   637 	
       
   638 	//	Set default color to white
       
   639 	iRgb = KRgbWhite;
       
   640 
       
   641 	// Set default size
       
   642 	TInt defaultSize(8);
       
   643 	iSize = TSize(defaultSize, defaultSize);
       
   644     iReadyToRender = ETrue;
       
   645 
       
   646     iEditorView->HandleCommandL( EImageEditorCmdRender );        
       
   647     }
       
   648 
       
   649 // ---------------------------------------------------------------------------
       
   650 // LoadIndicatorL
       
   651 // ---------------------------------------------------------------------------
       
   652 //
       
   653 void CImageEditorDrawControl::LoadIndicatorL(
       
   654     TInt aBitmapInd, TInt aMaskInd ) 
       
   655     {
       
   656     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::LoadIndicatorL()");
       
   657 
       
   658     //  Delete old indicator
       
   659     delete iIndicator;
       
   660     iIndicator = 0;
       
   661     delete iIndicatorMask;
       
   662     iIndicatorMask = 0;
       
   663 
       
   664     //  Load new indicator
       
   665 	SDrawUtils::GetIndicatorBitmapL (
       
   666 		iIndicator,
       
   667 		iIndicatorMask,
       
   668 		aBitmapInd,
       
   669 		aMaskInd
       
   670 		);
       
   671     }
       
   672 
       
   673 // ---------------------------------------------------------------------------
       
   674 // ComputeIndicatorPosition
       
   675 // ---------------------------------------------------------------------------
       
   676 //
       
   677 TPoint CImageEditorDrawControl::ComputeIndicatorPosition() const
       
   678 	{
       
   679 	TRect vprect = iSysPars->VisibleImageRect();
       
   680 	TRect vpprect = iSysPars->VisibleImageRectPrev();
       
   681     
       
   682     TInt x( 0 );
       
   683 	TInt y( 0 );
       
   684 	// check if there is no indicator
       
   685 	if ( !iIndicator )
       
   686 	    {
       
   687 	    return TPoint ( x, y );
       
   688 	    }
       
   689 	    
       
   690 	y = ((iY - vprect.iTl.iY) * vpprect.Height()) / vprect.Height();
       
   691 	y += vpprect.iTl.iY;
       
   692 	//y -= iIndicator->SizeInPixels().iHeight; /// 4;
       
   693 
       
   694 	x = ((iX  - vprect.iTl.iX) * vpprect.Width()) / vprect.Width();
       
   695 	x += vpprect.iTl.iX;
       
   696 	//x -= iIndicator->SizeInPixels().iWidth / 2;
       
   697 
       
   698     return TPoint (x,y);
       
   699 	}
       
   700 
       
   701 // ---------------------------------------------------------------------------
       
   702 // IsReadyToRender
       
   703 // ---------------------------------------------------------------------------
       
   704 //
       
   705 TBool CImageEditorDrawControl::IsReadyToRender() const
       
   706     {
       
   707     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::IsReadyToRender()");
       
   708 	return iReadyToRender;
       
   709     }
       
   710 
       
   711 // ---------------------------------------------------------------------------
       
   712 // StoreParameters
       
   713 // ---------------------------------------------------------------------------
       
   714 //
       
   715 void CImageEditorDrawControl::StoreParameters(TBool aLastItem, TBool aDone)
       
   716     {
       
   717     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::StoreParameters()");
       
   718     RDebug::Print(_L("CImageEditorDrawControl::StoreParameters color[%d]"), 
       
   719     	iRgb.Internal());    
       
   720 
       
   721 	iParam.Copy(_L("x "));
       
   722 	iParam.AppendNum (iX);
       
   723 	iParam.Append(_L(" y "));
       
   724 	iParam.AppendNum (iY);
       
   725 	
       
   726 	if( aLastItem )
       
   727 		{	
       
   728 	    iParam.Append(_L(" size "));
       
   729 	    iParam.AppendNum (iSize.iHeight);
       
   730 	    iParam.Append(_L(" color "));
       
   731 	    iParam.AppendNum ( iRgb.Value() );  		
       
   732 		iParam.Append(_L(" lastItem "));
       
   733 		}	
       
   734     if( aDone )
       
   735         {   
       
   736         iParam.Append(_L("done"));
       
   737         }
       
   738     }
       
   739 
       
   740 // ---------------------------------------------------------------------------
       
   741 // TimerCallBack
       
   742 // ---------------------------------------------------------------------------
       
   743 //
       
   744 void CImageEditorDrawControl::TimerCallBack()
       
   745 {
       
   746     LOG(KDrawPluginLogFile, "CImageEditorDrawControl::TimerCallBack()");
       
   747 
       
   748     if (iTickCount > KDefaultFastKeyTimerMultiplyThresholdInTicks)
       
   749     {
       
   750         iNaviStepMultiplier = KDefaultBigNavigationStepMultiplier;
       
   751     }
       
   752     else
       
   753     {
       
   754         iTickCount++;
       
   755     }
       
   756 
       
   757 	if (iKeyCode)
       
   758 	{
       
   759 
       
   760 		switch (iKeyCode)
       
   761 		{
       
   762 			case 1:
       
   763 			{
       
   764 	            NaviUp();
       
   765 				break;
       
   766 			}
       
   767 			case 2:
       
   768 			{
       
   769 	            NaviDown();
       
   770 				break;
       
   771 			}
       
   772 			case 3:
       
   773 			{
       
   774 				NaviLeft();
       
   775 				break;
       
   776 			}
       
   777 			case 4:
       
   778 			{
       
   779 	            NaviRight();
       
   780 				break;
       
   781 			}
       
   782 	        default:
       
   783 	            break;
       
   784 		}
       
   785 	    //StoreParameters();
       
   786 	    TRAP_IGNORE( iEditorView->HandleCommandL(EImageEditorCmdRender) );
       
   787 		iTimer->Call (KWait);			
       
   788 	}
       
   789 }
       
   790 
       
   791 // ---------------------------------------------------------------------------
       
   792 // StorePosAndScaleRelScreen
       
   793 // ---------------------------------------------------------------------------
       
   794 //
       
   795 void CImageEditorDrawControl::StorePosAndScaleRelScreen()
       
   796     {
       
   797     LOG(KDrawPluginLogFile, 
       
   798             "CImageEditorClipartControl::StorePosAndScaleRelScreen()");
       
   799 	iParam.Copy(_L("nop"));	
       
   800     }
       
   801 
       
   802 // ---------------------------------------------------------------------------
       
   803 // ?description_if_needed
       
   804 // ---------------------------------------------------------------------------
       
   805 //
       
   806 void CImageEditorDrawControl::RestorePosAndScaleRelScreen()
       
   807     {
       
   808 	LOG(KDrawPluginLogFile, 
       
   809 	        "CImageEditorClipartControl::RestorePosAndScaleRelScreen()");
       
   810     }
       
   811 
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 // StorePosAndScaleRelImage
       
   815 // ---------------------------------------------------------------------------
       
   816 //
       
   817 void CImageEditorDrawControl::StorePosAndScaleRelImage()
       
   818     {
       
   819     TReal relscale = iSysPars->RelScale();    
       
   820     LOGFMT(KDrawPluginLogFile,
       
   821             "CImageEditorClipartControl::StorePosAndScaleRelImage():%g",
       
   822             relscale);
       
   823     }
       
   824 
       
   825 // ---------------------------------------------------------------------------
       
   826 // RestorePosAndScaleRelImage
       
   827 // ---------------------------------------------------------------------------
       
   828 //
       
   829 void CImageEditorDrawControl::RestorePosAndScaleRelImage()
       
   830     {
       
   831     TReal relscale = iSysPars->RelScale();
       
   832     LOGFMT(KDrawPluginLogFile,
       
   833             "CImageEditorClipartControl::RestorePosAndScaleRelImage():%g",
       
   834             relscale);
       
   835     }
       
   836 
       
   837 // ---------------------------------------------------------------------------
       
   838 // ClipPosition
       
   839 // ---------------------------------------------------------------------------
       
   840 //
       
   841 void CImageEditorDrawControl::ClipPosition()
       
   842 {
       
   843     if ( iX < iSysPars->VisibleImageRect().iTl.iX )
       
   844     {
       
   845     	iX = iSysPars->VisibleImageRect().iTl.iX;
       
   846     }
       
   847     else if ( iX > iSysPars->VisibleImageRect().iBr.iX )
       
   848     {
       
   849     	iX = iSysPars->VisibleImageRect().iBr.iX;
       
   850     }
       
   851     
       
   852     if ( iY < iSysPars->VisibleImageRect().iTl.iY )
       
   853     {
       
   854     	iY = iSysPars->VisibleImageRect().iTl.iY;
       
   855     }
       
   856     else if ( iY > iSysPars->VisibleImageRect().iBr.iY )
       
   857     {
       
   858     	iY = iSysPars->VisibleImageRect().iBr.iY;
       
   859     }
       
   860 }
       
   861 
       
   862 // ---------------------------------------------------------------------------
       
   863 // HandlePointerEventL
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 void CImageEditorDrawControl::HandlePointerEventL(
       
   867     const TPointerEvent &aPointerEvent)
       
   868     {
       
   869     RDebug::Print(_L("CImageEditorDrawControl::HandlePointerEventL pen[%d]"), 
       
   870     	AknLayoutUtils::PenEnabled());        
       
   871     if( AknLayoutUtils::PenEnabled() && !Busy())
       
   872 		{
       
   873 		RDebug::Print(_L("CImageEditorDrawControl::iType [%d]"), 
       
   874 			aPointerEvent.iType);
       
   875 		TBool lastItem( EFalse );
       
   876 		switch( aPointerEvent.iType )
       
   877 			{
       
   878 			case TPointerEvent::EButton1Down:
       
   879 				{
       
   880 				iReadyToRender = EFalse;
       
   881 
       
   882 				CDrawPath* lastPath = CDrawPath::NewL();
       
   883 				CleanupStack::PushL( lastPath );
       
   884 				lastPath->SetColor( iRgb );
       
   885 				lastPath->SetSize( iSize );								
       
   886                 SetPositionOnImage( aPointerEvent.iPosition );
       
   887                 lastPath->AddItemL( aPointerEvent.iPosition );
       
   888                 iPaths.AppendL( lastPath );
       
   889                 CleanupStack::Pop( lastPath );
       
   890                 break;
       
   891 				}
       
   892 			case TPointerEvent::EDrag:
       
   893 				{  
       
   894 				if( iPaths.Count() )
       
   895     				{
       
   896     				CDrawPath* path = iPaths[iPaths.Count()-1];
       
   897     				// store current position for next round
       
   898                     iPointerPosition = aPointerEvent.iPosition;    
       
   899     			    SetPositionOnImage( aPointerEvent.iPosition );
       
   900     			    path->AddItemL( aPointerEvent.iPosition );
       
   901     				}
       
   902 				break;		
       
   903 				}
       
   904 			case TPointerEvent::EButton1Up:
       
   905 				{
       
   906 				iReadyToRender = ETrue;
       
   907 				ShowTooltip();
       
   908 				lastItem = ETrue;
       
   909 				break;
       
   910 				}
       
   911 						
       
   912 			default:
       
   913 				{
       
   914 				break;	
       
   915 				}	
       
   916 			}
       
   917 			
       
   918     	StoreParameters( lastItem, EFalse ); 
       
   919 	    iEditorView->HandleCommandL( EImageEditorCmdRender );//results Draw call
       
   920 		CCoeControl::HandlePointerEventL( aPointerEvent );
       
   921 		}
       
   922     }
       
   923 
       
   924 // ---------------------------------------------------------------------------
       
   925 // SetPositionOnImage
       
   926 // ---------------------------------------------------------------------------
       
   927 //    
       
   928 void CImageEditorDrawControl::SetPositionOnImage( TPoint aPointedPosition )
       
   929     {    
       
   930     ASSERT( iSysPars );
       
   931     // Get system parameters
       
   932    	TRect visibleImageRect( iSysPars->VisibleImageRect() );
       
   933    	TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() );
       
   934 
       
   935    	TInt xPosFactorDivider( visibleImageRectPrev.Width() );
       
   936    	TInt yPosFactorDivider( visibleImageRectPrev.Height() );
       
   937     
       
   938    	LOGFMT2(KDrawPluginLogFile, "CImageEditorDrawControl::vir w:%d h:%d", 
       
   939    	        visibleImageRect.Width(), visibleImageRect.Height());
       
   940     LOGFMT2(KDrawPluginLogFile, "CImageEditorDrawControl::virp w:%d h:%d", 
       
   941             visibleImageRectPrev.Width(), visibleImageRectPrev.Height());
       
   942    	   	
       
   943    	// Dividing by zero will cause panic -> check
       
   944    	if ( xPosFactorDivider == 0 || yPosFactorDivider == 0 )
       
   945    	    {
       
   946    	    //	Set default position
       
   947     	iX = (visibleImageRect.iTl.iX + visibleImageRect.iBr.iX) / 2;
       
   948     	iY = (visibleImageRect.iTl.iY + visibleImageRect.iBr.iY) / 2;
       
   949    	    }
       
   950    	else
       
   951    	    {
       
   952    	    // Calculate relative position on the screen
       
   953    	    TReal xPositionFactor 
       
   954    	             ( TReal( aPointedPosition.iX - visibleImageRectPrev.iTl.iX ) /
       
   955 	             xPosFactorDivider );
       
   956 	                        
       
   957     	TReal yPositionFactor 
       
   958     	         ( TReal( aPointedPosition.iY - visibleImageRectPrev.iTl.iY ) /
       
   959 		         yPosFactorDivider );
       
   960         LOGFMT2(KDrawPluginLogFile, "CImageEditorDrawControl::pfx:%g pfy:%g", 
       
   961                 xPositionFactor, yPositionFactor);		
       
   962 		// Calculate position on visible image		
       
   963 
       
   964    	    iX = visibleImageRect.iTl.iX + 
       
   965    	        visibleImageRect.Width() * xPositionFactor + 0.5;	    
       
   966     	
       
   967     	iY = visibleImageRect.iTl.iY + 
       
   968     	    visibleImageRect.Height() * yPositionFactor + 0.5;    	
       
   969    	    }    
       
   970 
       
   971     LOGFMT4(KDrawPluginLogFile, "CImageEditorDrawControl::Draw x:%d iX:%d y:%d iY:%d", 
       
   972             aPointedPosition.iX, iX, aPointedPosition.iY, iY);
       
   973 	// Check that not out of bounds    
       
   974     //ClipPosition();          
       
   975     }
       
   976     
       
   977 // ---------------------------------------------------------------------------
       
   978 // GetPositionOnView
       
   979 // ---------------------------------------------------------------------------
       
   980 // 
       
   981 TPoint CImageEditorDrawControl::GetPositionOnView()
       
   982     {
       
   983     ASSERT( iSysPars );
       
   984     // Get system parameters 
       
   985     TRect visibleImageRect( iSysPars->VisibleImageRect() );
       
   986     TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() );
       
   987 
       
   988     TInt xPosFactorDivider( visibleImageRectPrev.Width() );
       
   989     TInt yPosFactorDivider( visibleImageRectPrev.Height() );
       
   990     
       
   991     // Calculate relative position on the screen
       
   992     TReal xPositionFactor( TReal( iX + visibleImageRectPrev.iTl.iX ) /
       
   993              xPosFactorDivider );
       
   994                         
       
   995     TReal yPositionFactor( TReal( iY + visibleImageRectPrev.iTl.iY ) /
       
   996              yPosFactorDivider );    
       
   997 
       
   998     LOGFMT2(KDrawPluginLogFile, 
       
   999             "CImageEditorDrawControl::GetPositionOnView xf:%g yf:%g", 
       
  1000             xPositionFactor , yPositionFactor );    
       
  1001     
       
  1002     LOGFMT2(KDrawPluginLogFile, 
       
  1003             "CImageEditorDrawControl::GetPositionOnView xf:%d yf:%d", 
       
  1004             xPosFactorDivider , yPosFactorDivider );     
       
  1005     
       
  1006     LOGFMT2(KDrawPluginLogFile, 
       
  1007             "CImageEditorDrawControl::GetPositionOnView w:%d h:%d", 
       
  1008             iX , iY );  
       
  1009     
       
  1010     TInt xPosition(iX + visibleImageRectPrev.iTl.iX);
       
  1011     TInt yPosition(iY + visibleImageRectPrev.iTl.iY);  
       
  1012     
       
  1013     LOGFMT3(KDrawPluginLogFile, 
       
  1014             "CImageEditorDrawControl::GetPositionOnView w:%d h:%d S:%g", 
       
  1015             xPosition, yPosition, iSysPars->RelScale());  
       
  1016     
       
  1017     return TPoint(xPosition, yPosition);
       
  1018     }
       
  1019 
       
  1020 // ---------------------------------------------------------------------------
       
  1021 // ShowTooltip
       
  1022 // ---------------------------------------------------------------------------
       
  1023 //    
       
  1024 void CImageEditorDrawControl::ShowTooltip()
       
  1025     {   
       
  1026     iPopupController->HideInfoPopupNote();
       
  1027 
       
  1028     TPoint iconPosition = ComputeIndicatorPosition();
       
  1029     TRect iconRect( iconPosition.iX, iconPosition.iY, 
       
  1030                     iconPosition.iX, iconPosition.iY );
       
  1031 
       
  1032                               
       
  1033     /*SDrawUtils::ShowToolTip( iPopupController,
       
  1034                              this,
       
  1035                              iconPosition,
       
  1036                              EHRightVTop, 
       
  1037                              *iTooltipResize );                                 
       
  1038     */
       
  1039     
       
  1040     }
       
  1041 
       
  1042 // ---------------------------------------------------------------------------
       
  1043 // ScaledLineSize
       
  1044 // ---------------------------------------------------------------------------
       
  1045 //    
       
  1046 TSize CImageEditorDrawControl::ScaledLineSize( TSize aOriginalSize ) const 
       
  1047     {
       
  1048     TInt sizew(aOriginalSize.iWidth * iSysPars->RelScale() + 0.5);
       
  1049     TInt sizeh(aOriginalSize.iHeight * iSysPars->RelScale() + 0.5);
       
  1050     if( sizew < 1 )
       
  1051         {
       
  1052         sizew++;
       
  1053         }
       
  1054     if( sizeh < 1 )
       
  1055         {
       
  1056         sizeh++;
       
  1057         }
       
  1058 
       
  1059     LOGFMT3(KDrawPluginLogFile, 
       
  1060             "CImageEditorDrawControl::ScaledLineSize w:%d h:%d S:%g", 
       
  1061             sizew, sizeh, iSysPars->RelScale());    
       
  1062     return TSize(sizew , sizeh);
       
  1063     }
       
  1064         
       
  1065 // End of File