imageeditor/ImageEditorUI/src/ImageEditorUIContainer.cpp
changeset 1 edfc90759b9f
child 8 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 * Container class that handles/forwards keyevents and pointer
       
    17 * events to other controls.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <fbs.h>
       
    24 #include <eikenv.h>
       
    25 #include <eikspane.h>
       
    26 #include <aknsbasicbackgroundcontrolcontext.h> 
       
    27 #include <aknsdrawutils.h> 
       
    28 
       
    29 #include "ImageEditorUIContainer.h"
       
    30 #include "ImageEditorControlBase.h"
       
    31 #include "ImageEditorUI.hrh"
       
    32 
       
    33 #include "WaitIndicator.h"
       
    34 
       
    35 #ifdef RD_TACTILE_FEEDBACK 
       
    36 #include <touchfeedback.h>
       
    37 #endif /* RD_TACTILE_FEEDBACK  */
       
    38 
       
    39 const TInt KTouchPanTotalMoveThreshold = 5;
       
    40 
       
    41 //=============================================================================
       
    42 void CImageEditorUIContainer::ConstructL(const TRect & aRect)
       
    43 	{
       
    44 	//	Create window
       
    45 	CreateWindowL();
       
    46 
       
    47 	iWaitIndicator = CWaitIndicator::NewL();
       
    48 	iWaitIndicator->SetParent( this);
       
    49 
       
    50 #ifdef RD_TACTILE_FEEDBACK 
       
    51 	iTouchFeedBack = MTouchFeedback::Instance();
       
    52 #endif /* RD_TACTILE_FEEDBACK  */
       
    53 
       
    54 	//	Set window rectangle
       
    55 	SetRect(aRect);
       
    56 
       
    57 	//	Set busy
       
    58 	SetBusy();
       
    59 
       
    60 	SetCanDrawOutsideRect();
       
    61 	iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
    62 			KAknsIIDQsnBgAreaMain, Rect(), EFalse);
       
    63 
       
    64 	EnableDragEvents();
       
    65 
       
    66 	//	Activate container control
       
    67 	ActivateL();
       
    68 	}
       
    69 
       
    70 //=============================================================================
       
    71 CImageEditorUIContainer::~CImageEditorUIContainer()
       
    72 	{
       
    73 	delete iWaitIndicator;
       
    74 	delete iBgContext;
       
    75 	iEditorView = NULL;
       
    76 	iPreview = NULL;
       
    77 	iControl = NULL;
       
    78 	}
       
    79 
       
    80 //=============================================================================
       
    81 void CImageEditorUIContainer::SetImageL(CFbsBitmap * aBitmap)
       
    82 	{
       
    83 	iPreview = aBitmap;
       
    84 	if (iControl)
       
    85 		{
       
    86 		((CImageEditorControlBase*)iControl)->SetImageL(iPreview);
       
    87 		}
       
    88 	DrawDeferred();
       
    89 	}
       
    90 
       
    91 //=============================================================================
       
    92 void CImageEditorUIContainer::SetControl(CCoeControl * aControl)
       
    93 	{
       
    94 	iControl = aControl;
       
    95 	if (iControl)
       
    96 		{
       
    97 		((CImageEditorControlBase *)iControl)->SetView(iEditorView);
       
    98 		iControl->SetRect(Rect() );
       
    99 		}
       
   100 	DrawDeferred();
       
   101 	}
       
   102 
       
   103 //=============================================================================
       
   104 void CImageEditorUIContainer::SetView(CImageEditorUIView * aView)
       
   105 	{
       
   106 	if (iControl)
       
   107 		{
       
   108 		((CImageEditorControlBase *)iControl)->SetView(aView);
       
   109 		}
       
   110 	iEditorView = aView;
       
   111 	}
       
   112 
       
   113 //=============================================================================
       
   114 TKeyResponse CImageEditorUIContainer::OfferKeyEventL(
       
   115 		const TKeyEvent & aKeyEvent, TEventCode aType)
       
   116 	{
       
   117 	if (Busy() )
       
   118 		{
       
   119 		return EKeyWasConsumed;
       
   120 		}
       
   121 	else
       
   122 		{
       
   123 		TKeyResponse res = EKeyWasNotConsumed;
       
   124 		if (iControl)
       
   125 			{
       
   126 			res = ((CCoeControl*)iControl)->OfferKeyEventL(aKeyEvent,
       
   127 					aType);
       
   128 			}
       
   129 		return res;
       
   130 		}
       
   131 	}
       
   132 
       
   133 //=============================================================================
       
   134 void CImageEditorUIContainer::SizeChanged()
       
   135 	{
       
   136 	if (iBgContext)
       
   137 		{
       
   138 		iBgContext->SetRect(Rect() );
       
   139 		}
       
   140 
       
   141 	if (iControl)
       
   142 		{
       
   143 		iControl->SetRect(Rect() );
       
   144 		}
       
   145 
       
   146 	iWaitIndicator->SetItemRect(Rect() );
       
   147 	}
       
   148 
       
   149 //=============================================================================
       
   150 void CImageEditorUIContainer::HandlePointerEventL(
       
   151 		const TPointerEvent &aPointerEvent)
       
   152 	{
       
   153 	if (Busy() )
       
   154 		{
       
   155 		return;
       
   156 		}
       
   157 	else
       
   158 		{
       
   159 		if (iControl)
       
   160 			{
       
   161 			((CCoeControl*)iControl)->HandlePointerEventL(aPointerEvent);
       
   162 			}
       
   163 		else
       
   164 			{
       
   165 
       
   166 			switch (aPointerEvent.iType)
       
   167 				{
       
   168 				case TPointerEvent::EButton1Down:
       
   169 					{
       
   170 					
       
   171 #ifdef RD_TACTILE_FEEDBACK
       
   172 						if ( iTouchFeedBack )
       
   173 							{
       
   174 							iTouchFeedBack->InstantFeedback( ETouchFeedbackBasic );
       
   175 							RDebug::Printf( "ImageEditor::ImageEditorUIContainer: ETouchFeedback" );
       
   176 							}
       
   177 #endif /* RD_TACTILE_FEEDBACK  */
       
   178 						
       
   179 					if ( !iEditorView->InZoomingState() )
       
   180 						{
       
   181 						iEditorView->HandleCommandL(EImageEditorMenuCmdApplyEffect);
       
   182 						}
       
   183 					else
       
   184 						{
       
   185 						iTappedPosition = aPointerEvent.iPosition;
       
   186 						}
       
   187 					break;
       
   188 					}
       
   189 				case TPointerEvent::EDrag:
       
   190 					{
       
   191 					iXDirChange = iTappedPosition.iX
       
   192 							- aPointerEvent.iPosition.iX;
       
   193 					iYDirChange = iTappedPosition.iY
       
   194 							- aPointerEvent.iPosition.iY;
       
   195 
       
   196 					// Compare total change in pixels (absolute value) to 
       
   197 					// threshold value. This is to prevent calling engine's 
       
   198 					// Pan-function in every minimal movement                                                         
       
   199 					if ( (Abs(iXDirChange) + Abs(iYDirChange) )
       
   200 							> KTouchPanTotalMoveThreshold)
       
   201 						{
       
   202 						iTappedPosition = aPointerEvent.iPosition;
       
   203 						iEditorView->HandleCommandL(EImageEditorCmdTouchPan);
       
   204 						}
       
   205 
       
   206 					break;
       
   207 					}
       
   208 				case TPointerEvent::EButton1Up:
       
   209 					{
       
   210 					iTappedPosition = aPointerEvent.iPosition;
       
   211 					break;
       
   212 					}
       
   213 
       
   214 				default:
       
   215 					{
       
   216 					break;
       
   217 					}
       
   218 				}
       
   219 
       
   220 			}
       
   221 
       
   222 		}
       
   223 
       
   224 	}
       
   225 
       
   226 //=============================================================================
       
   227 TInt CImageEditorUIContainer::CountComponentControls() const
       
   228 	{
       
   229 	TInt count = 0;
       
   230 	if (iControl)
       
   231 		{
       
   232 		++count;
       
   233 		}
       
   234 	return count;
       
   235 	}
       
   236 
       
   237 //=============================================================================
       
   238 CCoeControl * CImageEditorUIContainer::ComponentControl(TInt aIndex) const
       
   239 	{
       
   240 	switch (aIndex)
       
   241 		{
       
   242 		case 0:
       
   243 			{
       
   244 			return iControl;
       
   245 			}
       
   246 		default:
       
   247 			{
       
   248 			return 0;
       
   249 			}
       
   250 		}
       
   251 	}
       
   252 
       
   253 //=============================================================================
       
   254 void CImageEditorUIContainer::SetBusy()
       
   255 	{
       
   256 	if (iControl)
       
   257 		{
       
   258 		((CImageEditorControlBase *)iControl)->SetBusy();
       
   259 		}
       
   260 	iBusy = ETrue;
       
   261 	}
       
   262 
       
   263 //=============================================================================
       
   264 void CImageEditorUIContainer::ResetBusy()
       
   265 	{
       
   266 	if (iControl)
       
   267 		{
       
   268 		((CImageEditorControlBase *)iControl)->ResetBusy();
       
   269 		}
       
   270 	iBusy = EFalse;
       
   271 	}
       
   272 
       
   273 //=============================================================================
       
   274 TBool CImageEditorUIContainer::Busy() const
       
   275 	{
       
   276 	return iBusy;
       
   277 	}
       
   278 
       
   279 //=============================================================================
       
   280 void CImageEditorUIContainer::SetFullScreen()
       
   281 	{
       
   282 	iFullScreen = ETrue;
       
   283 	}
       
   284 
       
   285 //=============================================================================
       
   286 void CImageEditorUIContainer::ResetFullScreen()
       
   287 	{
       
   288 	iFullScreen = EFalse;
       
   289 	}
       
   290 
       
   291 //=============================================================================
       
   292 void CImageEditorUIContainer::Draw(const TRect & /*aRect*/) const
       
   293 	{
       
   294 	// Get graphics context
       
   295 	CWindowGc & gc = SystemGc();
       
   296 
       
   297 	// If there is a plug-in control, it is responsible
       
   298 	// for drawing the preview image (to avoid flicker)
       
   299 	if (!iControl)
       
   300 		{
       
   301 		gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   302 		gc.SetBrushColor(KRgbWhite);
       
   303 		gc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   304 		gc.SetPenColor(KRgbWhite);
       
   305 
       
   306 		if (iPreview && iPreview->Handle() )
       
   307 			{
       
   308 			gc.DrawBitmap(Rect(), iPreview);
       
   309 			}
       
   310 		else
       
   311 			{
       
   312 			// Draw skin background
       
   313 			MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   314 			MAknsControlContext* cc = AknsDrawUtils::ControlContext( this);
       
   315 			AknsDrawUtils::DrawBackground(skin, cc, this, gc, TPoint(0, 0),
       
   316 					Rect(), KAknsDrawParamDefault);
       
   317 
       
   318 			}
       
   319 		}
       
   320 
       
   321 	iWaitIndicator->DrawItem(gc);
       
   322 	}
       
   323 
       
   324 //=============================================================================
       
   325 void CImageEditorUIContainer::HandleControlEventL(CCoeControl * /*aControl*/,
       
   326 		TCoeEvent /*aEventType*/
       
   327 )
       
   328 	{
       
   329 
       
   330 	}
       
   331 
       
   332 //=============================================================================
       
   333 void CImageEditorUIContainer::GetHelpContext(TCoeHelpContext& aContext) const
       
   334 	{
       
   335 	if (iControl)
       
   336 		{
       
   337 		iControl->GetHelpContext(aContext);
       
   338 		}
       
   339 	}
       
   340 
       
   341 //=============================================================================
       
   342 void CImageEditorUIContainer::GetDragDirections(TInt& xMovement, TInt& yMovement)
       
   343 	{
       
   344 	xMovement = iXDirChange;
       
   345 	yMovement = iYDirChange;
       
   346 	}
       
   347 
       
   348 //=============================================================================
       
   349 void CImageEditorUIContainer::HandleNaviDecoratorEventL(TInt aEventID)
       
   350 	{
       
   351 	if (aEventID == EAknNaviDecoratorEventRightTabArrow)
       
   352 		{
       
   353 		// A right arrow key event is simulated
       
   354 		TKeyEvent key;
       
   355 		key.iRepeats = 0;
       
   356 		key.iCode = EKeyRightArrow;
       
   357 		key.iModifiers = 0;
       
   358 		CEikonEnv::Static()->SimulateKeyEventL(key, EEventKey);
       
   359 		}
       
   360 	else
       
   361 		if (aEventID == EAknNaviDecoratorEventLeftTabArrow)
       
   362 			{
       
   363 			// A left arrow key event is simulated
       
   364 			TKeyEvent key;
       
   365 			key.iRepeats = 0;
       
   366 			key.iCode = EKeyLeftArrow;
       
   367 			key.iModifiers = 0;
       
   368 			CEikonEnv::Static()->SimulateKeyEventL(key, EEventKey);
       
   369 			}
       
   370 	}
       
   371 
       
   372 //=============================================================================
       
   373 TTypeUid::Ptr CImageEditorUIContainer::MopSupplyObject(TTypeUid aId)
       
   374 	{
       
   375 	if (aId.iUid == MAknsControlContext::ETypeId && iBgContext)
       
   376 		{
       
   377 		return MAknsControlContext::SupplyMopObject(aId, iBgContext);
       
   378 		}
       
   379 	return CCoeControl::MopSupplyObject(aId);
       
   380 	}
       
   381 
       
   382 //=============================================================================
       
   383 void CImageEditorUIContainer::HideWaitNote()
       
   384 	{
       
   385 	iWaitIndicator->Hide();
       
   386 	}
       
   387 
       
   388 //=============================================================================
       
   389 void CImageEditorUIContainer::ShowWaitNote()
       
   390 	{
       
   391 	iWaitIndicator->Show();
       
   392 	}
       
   393 
       
   394 // End of File