|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: factory for alf built-in hitchcock compenents |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32cmn.h> |
|
20 #include <uiacceltk/HuiControl.h> |
|
21 #include <uiacceltk/HuiVisual.h> |
|
22 #include <uiacceltk/HuiLayout.h> |
|
23 #include <uiacceltk/HuiTexture.h> |
|
24 #include <uiacceltk/HuiEvent.h> |
|
25 #include <uiacceltk/HuiDisplay.h> |
|
26 #include <uiacceltk/HuiUtil.h> |
|
27 #include "alf/alfvisualhandlers.h" |
|
28 #include "alf/alflayouthandlers.h" |
|
29 #include "alf/alfbrushhandlers.h" |
|
30 #include "alftextstylehandlers.h" |
|
31 #include "alf/alfappsrvsessionbase.h" |
|
32 #include "alfstaticfactory.h" |
|
33 #include "alf/alfconstants.h" |
|
34 #include "alfmappingfunctionhandlers.h" |
|
35 #include "alf/alfmetric.h" |
|
36 |
|
37 |
|
38 CHuiVisual* FindLastHittingChild( const CHuiVisual& aParentVisual, |
|
39 const TPoint& aDisplayPoint ) |
|
40 { |
|
41 // If we want that the pointer event are passed only to the visuals which |
|
42 // (effective) opacity is greater than 50%, this would be the place to |
|
43 // implement it. |
|
44 for ( TInt i = aParentVisual.Count() - 1 ; i >= 0 ; i-- ) |
|
45 { |
|
46 // DisplayRect() returns the current value of the rectange. If the pointer |
|
47 // hit needs to be compared to the target rect, change this function call |
|
48 // from DisplayRect() into DisplayRectTarget() |
|
49 const TRect rect = aParentVisual.Visual( i ).DisplayRect(); |
|
50 if ( rect.Contains( aDisplayPoint ) ) |
|
51 { |
|
52 CHuiVisual* leaf = |
|
53 FindLastHittingChild( aParentVisual.Visual( i ), aDisplayPoint ); |
|
54 return leaf ? leaf : &aParentVisual.Visual( i ); |
|
55 } |
|
56 } |
|
57 return NULL; |
|
58 } |
|
59 |
|
60 //---------------------------- |
|
61 // Control, private so declaration directly here |
|
62 //---------------------------- |
|
63 |
|
64 NONSHARABLE_CLASS(CAlfControl2): public CHuiControl |
|
65 { |
|
66 public: |
|
67 CAlfControl2(CHuiEnv& aSharedEnv, CAlfControl2** ptr, CAlfAppSrvSessionBase* aSession): |
|
68 CHuiControl(aSharedEnv), |
|
69 iPtr(ptr), |
|
70 iSession(aSession) |
|
71 {} |
|
72 |
|
73 TBool OfferEventL(const THuiEvent& aEvent) |
|
74 { |
|
75 if ( aEvent.IsPointerEvent() ) |
|
76 { |
|
77 // Update event coordinates to match the "client rect" of the application |
|
78 THuiEvent eventWithLocalCoordinates(aEvent); |
|
79 |
|
80 // Set the iParentPosition coordinates to be ralative to the |
|
81 // visual aread of the display i.e the root visuals. |
|
82 const TPoint clientDrawingAreaTl = iSession->ClientDrawingArea().iTl; |
|
83 eventWithLocalCoordinates.iPointerEvent.iParentPosition -= clientDrawingAreaTl; |
|
84 |
|
85 if ( aEvent.Visual() ) |
|
86 { |
|
87 // If visual is found, move the iPosition coordinates to be relative to the |
|
88 // visual area. |
|
89 const THuiRealRect realVisualArea = aEvent.Visual()->DisplayRect(); |
|
90 const TPoint intVisualTl( |
|
91 HUI_ROUND_FLOAT_TO_INT( realVisualArea.iTl.iX ), |
|
92 HUI_ROUND_FLOAT_TO_INT( realVisualArea.iTl.iY ) ); |
|
93 |
|
94 eventWithLocalCoordinates.iPointerEvent.iPosition -= intVisualTl; |
|
95 } |
|
96 else |
|
97 { |
|
98 // If there is no accociated visual, set iPosotion coordinates to be relative to |
|
99 // the display visual area. |
|
100 eventWithLocalCoordinates.iPointerEvent.iPosition -= clientDrawingAreaTl; |
|
101 } |
|
102 |
|
103 TBool isLongTap = aEvent.iPointerEvent.iType == TPointerEvent::EButtonRepeat; |
|
104 if ( isLongTap ) |
|
105 { |
|
106 iSession->StartPointerHandling(); |
|
107 } |
|
108 iSession->HandleEventL(this, aEvent.Visual() , eventWithLocalCoordinates); |
|
109 if ( isLongTap ) |
|
110 { |
|
111 iSession->FlushPointerHandling(); |
|
112 } |
|
113 } |
|
114 return EFalse; // let env offer event to all ctrls it hits |
|
115 } |
|
116 |
|
117 ~CAlfControl2() |
|
118 { |
|
119 *iPtr = 0; |
|
120 |
|
121 // Remove possbile pointer observers |
|
122 if ( Env().DisplayCount() ) |
|
123 { |
|
124 CHuiDisplay& disp = Env().PrimaryDisplay(); // assume one display |
|
125 disp.Roster().Observers(EHuiInputPointerDrag).RemoveIfFound(*this); |
|
126 disp.Roster().Observers(EHuiInputPointerLongTap).RemoveIfFound(*this); |
|
127 disp.Roster().Observers(EHuiInputPointerUnhandled).RemoveIfFound(*this); |
|
128 } |
|
129 } |
|
130 |
|
131 private: |
|
132 CAlfControl2** iPtr; |
|
133 CAlfAppSrvSessionBase* iSession; |
|
134 }; |
|
135 |
|
136 |
|
137 NONSHARABLE_CLASS(CAlfControlHandler): public CBase, public MAlfExtension |
|
138 { |
|
139 public: |
|
140 static MAlfExtension* NewL(const TDesC8& aInputBuffer, CHuiEnv& aSharedEnv, CAlfAppSrvSessionBase* aSession ); |
|
141 private: |
|
142 void Release(); |
|
143 TAny* GetInterface(const THuiInterfaceSupport& aInterface); |
|
144 void HandleCmdL(TInt aCommandId, const TDesC8& aInputBuffer, TDes8& aResponse); |
|
145 CAlfControl2* iControl; |
|
146 ~CAlfControlHandler() |
|
147 { |
|
148 if (iControl && !iControl->ControlGroup()) |
|
149 { |
|
150 delete iControl; |
|
151 } |
|
152 } |
|
153 }; |
|
154 |
|
155 MAlfExtension* CAlfControlHandler::NewL(const TDesC8& /*aInputBuffer*/, CHuiEnv& aSharedEnv, CAlfAppSrvSessionBase* aSession) |
|
156 { |
|
157 CAlfControlHandler* me = new (ELeave) CAlfControlHandler(); |
|
158 CleanupStack::PushL(me); |
|
159 me->iControl = new (ELeave) CAlfControl2(aSharedEnv, &me->iControl, aSession); |
|
160 CleanupStack::Pop(); |
|
161 return me; |
|
162 } |
|
163 |
|
164 void CAlfControlHandler::Release() |
|
165 { |
|
166 delete this; |
|
167 } |
|
168 |
|
169 TAny* CAlfControlHandler::GetInterface(const THuiInterfaceSupport& aInterface) |
|
170 { |
|
171 switch (aInterface) |
|
172 { |
|
173 case EHuiObjectTypeControl: |
|
174 return static_cast<CHuiControl*>(iControl); |
|
175 case EHuiInterfaceVisualOwner: |
|
176 return static_cast<MHuiVisualOwner*>(iControl); |
|
177 default: |
|
178 return 0; |
|
179 |
|
180 } |
|
181 |
|
182 } |
|
183 |
|
184 void CAlfControlHandler::HandleCmdL(TInt /*aCommandId*/, const TDesC8& /*aInputBuffer*/, TDes8& /*aResponse*/) |
|
185 { |
|
186 } |
|
187 |
|
188 |
|
189 MAlfExtension* TAlfFixedFactory::CreateExtensionL(const TInt aObjectId, const TDesC8& aInitialParams, MAlfInterfaceProvider& aResolver ) |
|
190 { |
|
191 |
|
192 MAlfExtension* result = 0; |
|
193 switch(aObjectId) |
|
194 { |
|
195 case EAlfCntrlCreate: |
|
196 { |
|
197 result = CAlfControlHandler::NewL(aInitialParams, *aResolver.SharedHuiEnv(), static_cast<CAlfAppSrvSessionBase*>(&aResolver)); |
|
198 break; |
|
199 } |
|
200 |
|
201 case EAlfVisualCreate: |
|
202 case EAlfTextVisualCreate: |
|
203 case EAlfLCTTextVisualCreate: |
|
204 case EAlfLayoutCreate: |
|
205 case EAlfAnchorLayoutCreate: |
|
206 case EAlfLCTAnchorLayoutCreate: |
|
207 case EAlfDeckLayoutCreate: |
|
208 case EAlfFlowLayoutCreate: |
|
209 case EAlfCurvePathLayoutCreate: |
|
210 case EAlfGridLayoutCreate: |
|
211 case EAlfLCTGridLayoutCreate: |
|
212 case EAlfViewportLayoutCreate: |
|
213 case EAlfImageVisualCreate: |
|
214 case EAlfLineVisualCreate: |
|
215 case EAlfCanvasVisualCreate: |
|
216 { |
|
217 TInt2* params = (TInt2*)aInitialParams.Ptr(); |
|
218 |
|
219 CHuiControl* owner = 0; |
|
220 CHuiLayout* parentLayout = 0; |
|
221 |
|
222 if (!params->iInt1) |
|
223 { |
|
224 User::Leave(KErrArgument); |
|
225 } |
|
226 else |
|
227 { // currently we must use concrete owner as interface does not provide means to |
|
228 // transfer ownership |
|
229 owner = (CHuiControl*) aResolver.GetInterfaceL(EHuiObjectTypeControl, params->iInt1 ); |
|
230 } |
|
231 |
|
232 if (params->iInt2) // not compulsory |
|
233 { |
|
234 parentLayout = (CHuiLayout*) aResolver.GetInterfaceL(EHuiObjectTypeLayout, params->iInt2 ); |
|
235 } |
|
236 |
|
237 if (aObjectId == EAlfVisualCreate) |
|
238 result = CAlfVisualHandler::NewL(aResolver, owner, parentLayout); |
|
239 else if (aObjectId == EAlfTextVisualCreate) |
|
240 result = CAlfTextVisualHandler::NewL(aResolver, owner, parentLayout); |
|
241 else if (aObjectId == EAlfLCTTextVisualCreate) |
|
242 result = CAlfLCTTextVisualHandler::NewL(aResolver, owner, parentLayout); |
|
243 else if (aObjectId == EAlfImageVisualCreate) |
|
244 result = CAlfImageVisualHandler::NewL(aResolver, owner, parentLayout); |
|
245 else if (aObjectId ==EAlfLayoutCreate) |
|
246 result = CAlfLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
247 else if (aObjectId ==EAlfAnchorLayoutCreate) |
|
248 result = CAlfAnchorLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
249 else if (aObjectId ==EAlfLCTAnchorLayoutCreate) |
|
250 result = CAlfLCTAnchorLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
251 else if (aObjectId ==EAlfGridLayoutCreate) |
|
252 result = CAlfGridLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
253 else if (aObjectId ==EAlfLCTGridLayoutCreate) |
|
254 result = CAlfLCTGridLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
255 else if (aObjectId ==EAlfDeckLayoutCreate) |
|
256 result = CAlfDeckLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
257 else if (aObjectId ==EAlfFlowLayoutCreate) |
|
258 result = CAlfFlowLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
259 else if (aObjectId ==EAlfViewportLayoutCreate) |
|
260 result = CAlfViewportLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
261 else if (aObjectId ==EAlfCurvePathLayoutCreate) |
|
262 result = CAlfCurvePathLayoutHandler::NewL(aResolver, owner, parentLayout); |
|
263 else if (aObjectId ==EAlfLineVisualCreate) |
|
264 result = CAlfLineVisualHandler::NewL(aResolver, owner, parentLayout); |
|
265 else if (aObjectId ==EAlfCanvasVisualCreate) |
|
266 result = CAlfCanvasVisualHandler::NewL(aResolver, owner, parentLayout); |
|
267 |
|
268 ASSERT(result); // missing obejct would be clear implementation error |
|
269 break; |
|
270 } |
|
271 |
|
272 case EAlfMeshVisualCreate: |
|
273 { |
|
274 TInt3* params = (TInt3*)aInitialParams.Ptr(); |
|
275 |
|
276 CHuiControl* owner = 0; |
|
277 THuiMeshType type = EHuiMeshTypeProcedural; |
|
278 CHuiLayout* parentLayout = 0; |
|
279 |
|
280 if (!params->iInt1) |
|
281 { |
|
282 User::Leave(KErrArgument); |
|
283 } |
|
284 else |
|
285 { // currently we must use concrete owner as interface does not provide means to |
|
286 // transfer ownership |
|
287 owner = (CHuiControl*) aResolver.GetInterfaceL(EHuiObjectTypeControl, params->iInt1 ); |
|
288 } |
|
289 |
|
290 |
|
291 if (params->iInt2) // not compulsory |
|
292 { |
|
293 parentLayout = (CHuiLayout*) aResolver.GetInterfaceL(EHuiObjectTypeLayout, params->iInt2 ); |
|
294 } |
|
295 |
|
296 result = CAlfMeshVisualHandler::NewL(aResolver, owner, type, parentLayout); |
|
297 |
|
298 ASSERT(result); // missing obejct would be clear implementation error |
|
299 break; |
|
300 } |
|
301 |
|
302 case EAlfBorderBrushCreate: |
|
303 { |
|
304 TAlfCreateBorderBrushParams* params = (TAlfCreateBorderBrushParams*)aInitialParams.Ptr(); |
|
305 |
|
306 result = CAlfBorderBrushHandler::NewL( |
|
307 aResolver, |
|
308 params->iThicknessWidth, |
|
309 params->iThicknessHeight, |
|
310 params->iEdgeOffsetX, |
|
311 params->iEdgeOffsetY ); |
|
312 } |
|
313 break; |
|
314 case EAlfBorderBrushCreateMetric: |
|
315 { |
|
316 TAlfCreateBorderBrushMetricParams* params = (TAlfCreateBorderBrushMetricParams*)aInitialParams.Ptr(); |
|
317 |
|
318 result = CAlfBorderBrushHandler::NewL( |
|
319 aResolver, |
|
320 params->iThickness, |
|
321 params->iEdgeOffset ); |
|
322 } |
|
323 break; |
|
324 |
|
325 case EAlfImageBrushCreate: |
|
326 { |
|
327 TAlfImageBrushParams* params = (TAlfImageBrushParams*)aInitialParams.Ptr(); |
|
328 MHuiTexture* texture = reinterpret_cast<MHuiTexture*> (params->iTextureHandle); |
|
329 result = CAlfImageBrushHandler::NewL(aResolver, THuiImage(*texture)); |
|
330 } |
|
331 break; |
|
332 |
|
333 case EAlfShadowBorderBrushCreate: |
|
334 { |
|
335 TInt* params = (TInt*)aInitialParams.Ptr(); |
|
336 result = CAlfShadowBorderBrushHandler::NewL(aResolver, *params); |
|
337 break; |
|
338 } |
|
339 case EAlfShadowBorderBrushCreateMetric: |
|
340 { |
|
341 TAlfMetric* params = (TAlfMetric*)aInitialParams.Ptr(); |
|
342 result = CAlfShadowBorderBrushHandler::NewL(aResolver, *params); |
|
343 break; |
|
344 } |
|
345 |
|
346 case EAlfDropShadowBrushCreate: |
|
347 { |
|
348 TInt* params = (TInt*)aInitialParams.Ptr(); |
|
349 result = CAlfDropShadowBrushHandler::NewL(aResolver, *params); |
|
350 break; |
|
351 } |
|
352 case EAlfDropShadowBrushCreateMetric: |
|
353 { |
|
354 TAlfMetric* params = (TAlfMetric*)aInitialParams.Ptr(); |
|
355 result = CAlfDropShadowBrushHandler::NewL(aResolver, *params); |
|
356 break; |
|
357 } |
|
358 |
|
359 case EAlfGradientBrushCreate: |
|
360 { |
|
361 result = CAlfGradientBrushHandler::NewL( aResolver ); |
|
362 break; |
|
363 } |
|
364 case EAlfFrameBrushCreate: |
|
365 { |
|
366 TAlfFrameBrushParams* params = (TAlfFrameBrushParams*)aInitialParams.Ptr(); |
|
367 result = CAlfFrameBrushHandler::NewL(aResolver, params->iFrameIID, params->iEdgeOffsetX, params->iEdgeOffsetY); |
|
368 } |
|
369 break; |
|
370 case EAlfFrameBrushCreateMetric: |
|
371 { |
|
372 TAlfFrameBrushMetricParams* params = (TAlfFrameBrushMetricParams*)aInitialParams.Ptr(); |
|
373 result = CAlfFrameBrushHandler::NewL(aResolver, params->iFrameIID, params->iEdgeOffset); |
|
374 } |
|
375 break; |
|
376 case EAlfFrameBrushCreateImage: |
|
377 { |
|
378 TAlfFrameBrushImageParams* params = (TAlfFrameBrushImageParams*)aInitialParams.Ptr(); |
|
379 |
|
380 // Todo: is is safe enough to handle textures as direct casts.. |
|
381 TInt handle = params->iImage.iTextureHandle; |
|
382 MHuiTexture* texture = reinterpret_cast<MHuiTexture*>(handle); |
|
383 THuiImage huiImage; |
|
384 if (texture) |
|
385 { |
|
386 huiImage = THuiImage(*texture, |
|
387 params->iImage.iTl.iX.ValueNow(), |
|
388 params->iImage.iTl.iY.ValueNow(), |
|
389 params->iImage.iBr.iX.ValueNow(), |
|
390 params->iImage.iBr.iY.ValueNow()); |
|
391 |
|
392 // We take transition time from one, assuming it is same for everyone. |
|
393 TInt transitionTime = params->iImage.iBr.iY.TimeToTargetinMilliSeconds(); |
|
394 |
|
395 huiImage.SetTexCoords(params->iImage.iTl.iX.Target(), |
|
396 params->iImage.iTl.iY.Target(), |
|
397 params->iImage.iBr.iX.Target(), |
|
398 params->iImage.iBr.iY.Target(), |
|
399 transitionTime ); |
|
400 } |
|
401 |
|
402 result = CAlfFrameBrushHandler::NewL(aResolver, huiImage, params->iEdgeOffset); |
|
403 } |
|
404 break; |
|
405 |
|
406 case EAlfMappingFunctionConstantCreate: |
|
407 { |
|
408 TReal32* params = (TReal32*)aInitialParams.Ptr(); |
|
409 result = new (ELeave) TAlfConstantMappingFunctionHandler( |
|
410 aResolver, |
|
411 *params ); |
|
412 break; |
|
413 } |
|
414 |
|
415 case EAlfMappingFunctionLinearCreate: |
|
416 { |
|
417 TReal2* params = (TReal2*)aInitialParams.Ptr(); |
|
418 result = new (ELeave) TAlfLinearMappingFunctionHandler( |
|
419 aResolver, |
|
420 params->iReal1, |
|
421 params->iReal2 ); |
|
422 break; |
|
423 } |
|
424 |
|
425 case EAlfMappingFunctionSineCreate: |
|
426 { |
|
427 TReal2* params = (TReal2*)aInitialParams.Ptr(); |
|
428 result = new (ELeave) TAlfSineMappingFunctionHandler( |
|
429 aResolver, |
|
430 params->iReal1, |
|
431 params->iReal2 ); |
|
432 break; |
|
433 } |
|
434 |
|
435 case EAlfMappingFunctionCosineCreate: |
|
436 { |
|
437 TReal2* params = (TReal2*)aInitialParams.Ptr(); |
|
438 result = new (ELeave) TAlfCosineMappingFunctionHandler( |
|
439 aResolver, |
|
440 params->iReal1, |
|
441 params->iReal2 ); |
|
442 break; |
|
443 } |
|
444 |
|
445 case EAlfMappingFunctionAverageCreate: |
|
446 { |
|
447 TInt2* params = (TInt2*)aInitialParams.Ptr(); |
|
448 |
|
449 MHuiMappingFunction* func1 = NULL; |
|
450 MHuiMappingFunction* func2 = NULL; |
|
451 |
|
452 if ( params->iInt1 ) |
|
453 { |
|
454 func1 = (MHuiMappingFunction*) aResolver.GetInterfaceL(EHuiInterfaceMappingFunction, params->iInt1 ); |
|
455 } |
|
456 |
|
457 if ( params->iInt2 ) |
|
458 { |
|
459 func2 = (MHuiMappingFunction*) aResolver.GetInterfaceL(EHuiInterfaceMappingFunction, params->iInt2 ); |
|
460 } |
|
461 |
|
462 |
|
463 result = new (ELeave) TAlfAverageMappingFunctionHandler( |
|
464 aResolver, |
|
465 func1, |
|
466 func2 |
|
467 ); |
|
468 } |
|
469 break; |
|
470 |
|
471 case EAlfCurvePathCreate: |
|
472 { |
|
473 CHuiCurvePath* curvePath = NULL; |
|
474 TInt* params = (TInt*)aInitialParams.Ptr(); |
|
475 if ( *params ) |
|
476 { |
|
477 curvePath = (CHuiCurvePath*) aResolver.GetInterfaceL(EHuiObjectTypeCurvePathProvider, *params ); |
|
478 } |
|
479 result = CAlfCurvePathHandler::NewL( aResolver,curvePath ); |
|
480 break; |
|
481 } |
|
482 case EAlfMappingFunctionTableCreate: |
|
483 { |
|
484 result = new (ELeave) TAlfTableMappingFunctionHandler(aResolver); |
|
485 break; |
|
486 } |
|
487 |
|
488 case EAlfPlatformTextStyleCreate: |
|
489 { |
|
490 TInt2* params = (TInt2*)aInitialParams.Ptr(); |
|
491 result = new (ELeave) TAlfTextStyleHandler(aResolver, params->iInt1, params->iInt2, EAlfPlatformTextStyleCreate); |
|
492 break; |
|
493 } |
|
494 |
|
495 case EAlfPreconfiguredTextStyleCreate: |
|
496 { |
|
497 TInt* params = (TInt*)aInitialParams.Ptr(); |
|
498 result = new (ELeave) TAlfTextStyleHandler(aResolver, *params, 0, EAlfPreconfiguredTextStyleCreate); |
|
499 break; |
|
500 } |
|
501 |
|
502 case EAlfPlatformTextStyleCopy: |
|
503 { |
|
504 TInt* params = (TInt*)aInitialParams.Ptr(); |
|
505 result = new (ELeave) TAlfTextStyleHandler(aResolver, *params, 0, EAlfPlatformTextStyleCopy); |
|
506 break; |
|
507 } |
|
508 |
|
509 default: |
|
510 User::Leave(KErrNotSupported); |
|
511 break; |
|
512 } |
|
513 |
|
514 return result; |
|
515 } |
|
516 |
|
517 void TAlfFixedFactory::Release() |
|
518 { |
|
519 delete this; |
|
520 } |
|
521 |
|
522 // end of file |
|
523 |