|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * It is the control container for the AI plugins |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <bldvariant.hrh> //feature flags |
|
22 #include <barsread.h> |
|
23 #include <coecntrl.h> |
|
24 #include <e32std.h> |
|
25 #include <bautils.h> |
|
26 #include <e32property.h> |
|
27 #include <connect/sbdefs.h> // pub&sub keys and categories for backup and restore |
|
28 #include <aknappui.h> |
|
29 #include <AknsDrawUtils.h> |
|
30 #include <AknsLayeredBackgroundControlContext.h> |
|
31 #include <layoutmetadata.cdl.h> |
|
32 #include <AknUtils.h> |
|
33 #include <data_caging_path_literals.hrh> |
|
34 #include <centralrepository.h> |
|
35 #include <AIContainerDomainCRKeys.h> |
|
36 #include <activeidle2domainpskeys.h> |
|
37 #include "aicontainer.hrh" |
|
38 #include "caiplugincontainercontrol.h" |
|
39 #include "ExtrStandbyScr.h" |
|
40 |
|
41 |
|
42 const TInt KActOnSendKey = 1; |
|
43 |
|
44 // ================= MEMBER FUNCTIONS ======================= |
|
45 |
|
46 CAIPluginContainerControl* CAIPluginContainerControl::NewL(CCoeControl *aContainer) |
|
47 { |
|
48 CAIPluginContainerControl* self = |
|
49 new (ELeave) CAIPluginContainerControl() ; |
|
50 |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(aContainer); |
|
53 CleanupStack::Pop(self); |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 CAIPluginContainerControl::~CAIPluginContainerControl() |
|
59 { |
|
60 |
|
61 AknsUtils::DeregisterControlPosition(this); |
|
62 |
|
63 delete iBackupObserver; |
|
64 iBackupObserver = NULL; |
|
65 |
|
66 if(iNotifyHandler) |
|
67 { |
|
68 iNotifyHandler->StopListening(); |
|
69 } |
|
70 delete iNotifyHandler; |
|
71 delete iAIRepository; |
|
72 delete iBgContext; |
|
73 |
|
74 DestroyPlugins() ; |
|
75 iPlugins.ResetAndDestroy(); |
|
76 iPlugins.Close(); |
|
77 REComSession::FinalClose() ; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CAIPluginContainerControl::SetDimmed |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 void CAIPluginContainerControl::SetDimmed(TBool aDimmed) |
|
85 { |
|
86 MakeVisible(!aDimmed); |
|
87 if (iContentStatusChangedNotification) |
|
88 { |
|
89 iContentStatusChangedNotification = EFalse; |
|
90 CalculateRectPlugins(); |
|
91 } |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CAIPluginContainerControl::CountComponentControls |
|
96 // Counts the component controls, so it returns one. |
|
97 // --------------------------------------------------------- |
|
98 // |
|
99 TInt CAIPluginContainerControl::CountComponentControls() const |
|
100 { |
|
101 TInt pluginsCount = 0; |
|
102 |
|
103 for ( TInt index = 0; index < iPlugins.Count(); index++ ) |
|
104 { |
|
105 TPluginInfo* plugin = iPlugins[index]; |
|
106 |
|
107 if (plugin->iPlugin) pluginsCount++ ; |
|
108 } |
|
109 |
|
110 return pluginsCount; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // CAIPluginContainerControl::ComponentControl |
|
115 // Returns components by index. |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 CCoeControl* CAIPluginContainerControl::ComponentControl(TInt aIndex) const |
|
119 { |
|
120 if (iPlugins.Count()) |
|
121 { |
|
122 TInt pluginsPos = -1; |
|
123 |
|
124 for ( TInt index = 0; index < iPlugins.Count(); index++ ) |
|
125 { |
|
126 TPluginInfo* plugin = iPlugins[index]; |
|
127 |
|
128 if (plugin->iPlugin) pluginsPos++ ; |
|
129 |
|
130 if (pluginsPos == aIndex) return iPlugins[index]->iPlugin; |
|
131 } |
|
132 } |
|
133 return NULL ; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------- |
|
137 // CAIPluginContainerControl::SizeChanged |
|
138 // Changes the sizes of the components. |
|
139 // --------------------------------------------------------- |
|
140 // |
|
141 void CAIPluginContainerControl::SizeChanged() |
|
142 { |
|
143 AknsUtils::RegisterControlPosition(this); |
|
144 |
|
145 if(iBgContext) |
|
146 { |
|
147 iBgContext->SetRect(Rect()); |
|
148 iBgContext->SetParentPos(PositionRelativeToScreen()); |
|
149 } |
|
150 |
|
151 |
|
152 if (!CountComponentControls()) |
|
153 { |
|
154 return ; |
|
155 } |
|
156 |
|
157 if ((iPrevRect.IsEmpty() || iPrevRect != Rect())) |
|
158 { |
|
159 CalculateRectPlugins() ; |
|
160 iPrevRect = Rect() ; |
|
161 } |
|
162 else |
|
163 { |
|
164 // FocusOnDefaultFocusingPlugin(EDrawNow); |
|
165 } |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CAIPluginContainerControl::FocusChanged |
|
170 // --------------------------------------------------------- |
|
171 // |
|
172 void CAIPluginContainerControl::FocusChanged(TDrawNow /*aDrawNow*/) |
|
173 { |
|
174 if (iCurrentPlugin) |
|
175 { |
|
176 if (IsFocused()) |
|
177 { |
|
178 TRAP_IGNORE(iCurrentPlugin->iPlugin->PrepareForFocusGainL()); |
|
179 } |
|
180 else |
|
181 { |
|
182 TRAP_IGNORE(iCurrentPlugin->iPlugin->PrepareForFocusLossL()); |
|
183 } |
|
184 // The flag must be drawnow because |
|
185 // the plugin focusing have to be happer/disapper |
|
186 iCurrentPlugin->iPlugin->SetFocus(IsFocused(),EDrawNow) ; |
|
187 } |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------- |
|
191 // CAIPluginContainerControl::Draw |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 void CAIPluginContainerControl::Draw( const TRect& /*aRect*/ ) const |
|
195 { |
|
196 if (IsDimmed()) |
|
197 { |
|
198 return ; |
|
199 } |
|
200 TRect rect( Rect() ); |
|
201 |
|
202 CWindowGc& gc = SystemGc(); |
|
203 |
|
204 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this); |
|
205 MAknsSkinInstance* aknsInst = AknsUtils::SkinInstance(); |
|
206 |
|
207 // Draw background starting from correct offset |
|
208 AknsDrawUtils::Background( aknsInst, cc, this, gc, rect ); |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CAIPluginContainerControl::MopSupplyObject |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 TTypeUid::Ptr CAIPluginContainerControl::MopSupplyObject(TTypeUid aId) |
|
217 { |
|
218 if( aId.iUid == MAknsControlContext::ETypeId ) |
|
219 { |
|
220 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
221 } |
|
222 return CCoeControl::MopSupplyObject( aId ); |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CAIPluginContainerControl::OfferKeyEventL |
|
227 // Processes the key event for the incall view. |
|
228 // --------------------------------------------------------- |
|
229 // |
|
230 TKeyResponse CAIPluginContainerControl::OfferKeyEventL( |
|
231 const TKeyEvent& aKeyEvent, |
|
232 TEventCode aType ) |
|
233 { |
|
234 |
|
235 if (iCurrentPlugin) |
|
236 { |
|
237 if (CountComponentControls() > 1) |
|
238 { |
|
239 switch( aKeyEvent.iScanCode ) |
|
240 { |
|
241 case EStdKeyUpArrow: |
|
242 case EStdKeyDownArrow: |
|
243 { |
|
244 if( aKeyEvent.iCode == EKeyUpArrow ) |
|
245 { |
|
246 ChangeFocusPluginL(EAIFocusUp); |
|
247 } |
|
248 else if( aKeyEvent.iCode == EKeyDownArrow ) |
|
249 { |
|
250 ChangeFocusPluginL(EAIFocusDown); |
|
251 } |
|
252 return EKeyWasConsumed; |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 if( aKeyEvent.iCode == EKeyPhoneEnd ) |
|
258 { |
|
259 FocusOnDefaultFocusingPlugin(EDrawNow); |
|
260 } |
|
261 return iCurrentPlugin->iPlugin->OfferKeyEventL(aKeyEvent,aType); |
|
262 } |
|
263 return EKeyWasNotConsumed; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 // CAIPluginContainerControl::HandleResourceChange |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 void CAIPluginContainerControl::HandleResourceChange( TInt aType ) |
|
271 { |
|
272 switch(aType) |
|
273 { |
|
274 case KAknsMessageSkinChange: |
|
275 { |
|
276 iPrevRect.SetSize(TSize(0,0)); |
|
277 } |
|
278 break; |
|
279 |
|
280 case KEikDynamicLayoutVariantSwitch: |
|
281 { |
|
282 TRAP_IGNORE(UpdateBackgroundL()); |
|
283 SetRect(static_cast<CAknAppUi*>(iEikonEnv->AppUi())->ClientRect()); |
|
284 } |
|
285 break; |
|
286 |
|
287 default: |
|
288 break; |
|
289 } |
|
290 |
|
291 CCoeControl::HandleResourceChange( aType ); |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------- |
|
295 // CAIPluginContainerControl::StartL |
|
296 // --------------------------------------------------------- |
|
297 // |
|
298 void CAIPluginContainerControl::StartL() |
|
299 { |
|
300 // Avoid double start calls |
|
301 if(!iStarted) |
|
302 { |
|
303 iStarted = ETrue; |
|
304 ReadPluginsConfigurationsL() ; |
|
305 LoadPluginsL(); |
|
306 SizeChanged(); |
|
307 } |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------- |
|
311 // CAIPluginContainerControl::SetFullScreenMode |
|
312 // --------------------------------------------------------- |
|
313 // |
|
314 void CAIPluginContainerControl::SetFullScreenMode(TBool aFullScreenMode) |
|
315 { |
|
316 iIsFullScreenMode = aFullScreenMode; |
|
317 TRAP_IGNORE(UpdateBackgroundL()); |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------- |
|
321 // CAIPluginContainerControl::HandleControlEventL |
|
322 // --------------------------------------------------------- |
|
323 // |
|
324 void CAIPluginContainerControl::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent aEventType) |
|
325 { |
|
326 if ( aEventType == EEventStateChanged ) |
|
327 { |
|
328 if (IsDimmed()) |
|
329 { |
|
330 iContentStatusChangedNotification = ETrue ; |
|
331 return ; |
|
332 } |
|
333 CalculateRectPlugins() ; |
|
334 //DrawNow(); |
|
335 } |
|
336 } |
|
337 |
|
338 // --------------------------------------------------------- |
|
339 // CAIPluginContainerControl::HandlePropertyChange |
|
340 // From PropertyObserver |
|
341 // --------------------------------------------------------- |
|
342 // |
|
343 void CAIPluginContainerControl::HandlePropertyChange(const TUid& /*aCategory*/, |
|
344 const TUint& /*aKey*/, |
|
345 const TInt& aValue) |
|
346 { |
|
347 // see \epoc32\include\connect\sbdefs.h for enum descriptions |
|
348 |
|
349 const TUint backupMask( conn::KBURPartTypeMask ^ conn::EBURNormal ); |
|
350 |
|
351 if( aValue & backupMask ) // any type of backup or restore operation |
|
352 { |
|
353 // backup or restore started |
|
354 // -> unload plugins |
|
355 if (CountComponentControls()) |
|
356 { |
|
357 DestroyPlugins(); |
|
358 DrawNow() ; |
|
359 } |
|
360 } |
|
361 else // aValue == conn::EBURUnset || aValue & conn::EBURNormal |
|
362 { |
|
363 // backup or restore ended |
|
364 // -> load plugin again |
|
365 if (CountComponentControls() == 0) |
|
366 { |
|
367 TRAP_IGNORE( |
|
368 ReadPluginsConfigurationsL(); |
|
369 LoadPluginsL() |
|
370 ); |
|
371 CalculateRectPlugins(); |
|
372 } |
|
373 } |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // CAIPluginContainerControl::HandleNotifyGeneric |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 void CAIPluginContainerControl::HandleNotifyGeneric(TUint32 aId) |
|
381 { |
|
382 if(aId != NCentralRepositoryConstants::KInvalidNotificationId) |
|
383 { |
|
384 if(aId != KAINumOfOperatorPlugins) |
|
385 { |
|
386 RProperty::Set( KPSUidAiInformation, KActiveIdleExtHS_LSKLocked, KNullDesC ); |
|
387 RProperty::Set( KPSUidAiInformation, KActiveIdleExtHS_RSKLocked, KNullDesC ); |
|
388 DestroyPlugins(); |
|
389 TRAP_IGNORE(ReadPluginsConfigurationsL(); LoadPluginsL();); |
|
390 CalculateRectPlugins(); |
|
391 RProperty::Set( KPSUidAiInformation, KActiveIdleExtHS_PluginConfChange, 1 ); |
|
392 } |
|
393 } |
|
394 } |
|
395 |
|
396 // --------------------------------------------------------- |
|
397 // CAIPluginContainerControl::ReadPluginsConfigurationsL |
|
398 // --------------------------------------------------------- |
|
399 // |
|
400 void CAIPluginContainerControl::ReadPluginsConfigurationsL() |
|
401 { |
|
402 TInt numOfPlugins = 0; |
|
403 TInt error(KErrNone); |
|
404 error = iAIRepository->Get( KAINumOfOperatorPlugins, numOfPlugins ); |
|
405 |
|
406 if( error == KErrNone ) |
|
407 { |
|
408 // Reset old array |
|
409 iPlugins.ResetAndDestroy(); |
|
410 |
|
411 // Load operator plug-in UIDs |
|
412 TInt uid = 0; |
|
413 for(TInt i = 1; i <= numOfPlugins; i++) |
|
414 { |
|
415 error = iAIRepository->Get( KAINumOfOperatorPlugins+i, uid ); |
|
416 |
|
417 if( error == KErrNone ) |
|
418 { |
|
419 TPluginInfo* pluginItem = new ( ELeave ) TPluginInfo; |
|
420 CleanupStack::PushL( pluginItem ); |
|
421 |
|
422 // Define values |
|
423 ResetToDefault( *pluginItem ); |
|
424 pluginItem->iPluginId.iUid = TUid::Uid(uid).iUid; |
|
425 |
|
426 iPlugins.AppendL( pluginItem ); |
|
427 CleanupStack::Pop(); // pluginItem |
|
428 } |
|
429 } |
|
430 } |
|
431 |
|
432 iIndexDefaultFocusingPlugin = 0; |
|
433 } |
|
434 |
|
435 // ----------------------------------------------------------------------------- |
|
436 // CAIPluginContainerControl::LoadPluginsL |
|
437 // ----------------------------------------------------------------------------- |
|
438 // |
|
439 void CAIPluginContainerControl::LoadPluginsL() |
|
440 { |
|
441 // Set send key functionality to default |
|
442 RProperty::Set( |
|
443 KPSUidAiInformation, |
|
444 KActiveIdleActOnSendKey, |
|
445 KActOnSendKey ); |
|
446 for ( TInt index = 0; index < iPlugins.Count() ; index++) |
|
447 { |
|
448 LoadPluginL(index) ; |
|
449 } |
|
450 } |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // CAIPluginContainerControl::LoadPluginL |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 void CAIPluginContainerControl::LoadPluginL(TInt aIndex) |
|
457 { |
|
458 CExtrStandbyScr* currentPlugin = NULL; |
|
459 |
|
460 TPluginInfo *pluginItem = iPlugins[aIndex]; |
|
461 |
|
462 if (pluginItem->iState == EAIPluginOn) |
|
463 { |
|
464 TRAPD(err, currentPlugin = CExtrStandbyScr::NewL(pluginItem->iPluginId,this)) ; |
|
465 |
|
466 if ( err != KErrNone ) |
|
467 { |
|
468 pluginItem->iState = EAIPluginError ; |
|
469 } |
|
470 else |
|
471 { |
|
472 |
|
473 if ( err == KErrNone ) |
|
474 { |
|
475 TSize MinSize = currentPlugin->GetMinSize() ; |
|
476 TSize MaxSize = currentPlugin->GetMaxSize() ; |
|
477 pluginItem->iResizeable = MinSize != MaxSize ; |
|
478 |
|
479 currentPlugin->SetObserver(this) ; |
|
480 |
|
481 TRAP_IGNORE(currentPlugin->LoadEngineL()) ; |
|
482 } |
|
483 |
|
484 if ( err != KErrNone ) |
|
485 { |
|
486 delete currentPlugin ; |
|
487 pluginItem->iState = EAIPluginError ; |
|
488 } |
|
489 else |
|
490 { |
|
491 //currentPlugin->SetDimmed(ETrue) ; |
|
492 pluginItem->iPlugin = currentPlugin ; |
|
493 pluginItem->iPlugin->ActivateL(); |
|
494 } |
|
495 } |
|
496 } |
|
497 |
|
498 } |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // CAIPluginContainerControl::DestroyPluginsL |
|
502 // ----------------------------------------------------------------------------- |
|
503 // |
|
504 void CAIPluginContainerControl::DestroyPlugins() |
|
505 { |
|
506 TInt index; |
|
507 |
|
508 for ( index = 0; index < iPlugins.Count(); index++ ) |
|
509 { |
|
510 TPluginInfo* plugin = iPlugins[index]; |
|
511 |
|
512 if (plugin->iPlugin) |
|
513 { |
|
514 delete plugin->iPlugin; |
|
515 plugin->iPlugin = NULL; |
|
516 } |
|
517 } |
|
518 iPlugins.ResetAndDestroy(); |
|
519 iIndexPlugin = -1; |
|
520 iCurrentPlugin = NULL ; |
|
521 } |
|
522 |
|
523 // ---------------------------------------------------------------------------- |
|
524 // CAIPluginContainerControl::ResetToDefault |
|
525 // ---------------------------------------------------------------------------- |
|
526 // |
|
527 void CAIPluginContainerControl::ResetToDefault( TPluginInfo& aPluginInfo ) |
|
528 { |
|
529 aPluginInfo.iPlugin = NULL; |
|
530 aPluginInfo.iResizeable = EFalse; |
|
531 aPluginInfo.iOnScreen = EFalse; |
|
532 aPluginInfo.iPluginId.iUid = 0; |
|
533 aPluginInfo.iAlignment = EAITop; |
|
534 aPluginInfo.iWeight = 0; |
|
535 aPluginInfo.iCRKeyId = 0; |
|
536 aPluginInfo.iState = EAIPluginOn; |
|
537 } |
|
538 |
|
539 |
|
540 // ---------------------------------------------------------------------------- |
|
541 // CAIPluginContainerControl::IsInFullScreenModeL |
|
542 // ---------------------------------------------------------------------------- |
|
543 // |
|
544 TBool CAIPluginContainerControl::IsInFullScreenModeL() |
|
545 { |
|
546 return iIsFullScreenMode; |
|
547 } |
|
548 |
|
549 // ---------------------------------------------------------------------------- |
|
550 // CAIPluginContainerControl::UpdateBackgroundL |
|
551 // ---------------------------------------------------------------------------- |
|
552 // |
|
553 void CAIPluginContainerControl::UpdateBackgroundL() |
|
554 { |
|
555 delete iBgContext; |
|
556 iBgContext = NULL; |
|
557 |
|
558 CAknAppUi* appui = static_cast<CAknAppUi*>(iEikonEnv->AppUi()); |
|
559 TRect rect = appui->ClientRect(); |
|
560 TAknsItemID backSkinId; |
|
561 |
|
562 if(IsInFullScreenModeL() && !Layout_Meta_Data::IsLandscapeOrientation()) |
|
563 { |
|
564 backSkinId = KAknsIIDQsnBgScreen; |
|
565 } |
|
566 else |
|
567 { |
|
568 backSkinId = KAknsIIDQsnBgAreaMainIdle; |
|
569 } |
|
570 |
|
571 iBgContext = CAknsLayeredBackgroundControlContext::NewL( |
|
572 backSkinId, |
|
573 rect, |
|
574 ETrue, |
|
575 EAIBgLayersN ); |
|
576 |
|
577 iBgContext->SetLayerImage( |
|
578 EAIBgLayerWallpaper, |
|
579 KAknsIIDWallpaper ); |
|
580 |
|
581 TSize wallpapersize; |
|
582 AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EWallpaperPane, wallpapersize ); |
|
583 |
|
584 TRect wallpaperrect(wallpapersize); |
|
585 wallpaperrect.Move(0, rect.Size().iHeight - wallpapersize.iHeight); |
|
586 |
|
587 iBgContext->SetLayerRect( |
|
588 EAIBgLayerWallpaper, |
|
589 wallpaperrect ); |
|
590 |
|
591 iBgContext->SetParentPos(PositionRelativeToScreen()); |
|
592 } |
|
593 |
|
594 // --------------------------------------------------------- |
|
595 // CAIPluginContainerControl::CAIPluginContainerControl |
|
596 // --------------------------------------------------------- |
|
597 // |
|
598 CAIPluginContainerControl::CAIPluginContainerControl() |
|
599 { |
|
600 } |
|
601 |
|
602 // --------------------------------------------------------- |
|
603 // CAIPluginContainerControl::ConstructL |
|
604 // --------------------------------------------------------- |
|
605 // |
|
606 void CAIPluginContainerControl::ConstructL( CCoeControl* aContainer ) |
|
607 { |
|
608 iContainer = aContainer; |
|
609 CreateWindowL(); |
|
610 SetParent(iContainer); |
|
611 |
|
612 UpdateBackgroundL(); |
|
613 |
|
614 iAIRepository = CRepository::NewL( KCRUidActiveIdle ); |
|
615 iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iAIRepository); |
|
616 iNotifyHandler->StartListeningL(); |
|
617 |
|
618 // backup/restore observer |
|
619 iBackupObserver = CPropertyObserver::NewL(*this, KUidSystemCategory, conn::KUidBackupRestoreKey); |
|
620 |
|
621 iIndexPlugin = -1; |
|
622 ActivateL(); |
|
623 } |
|
624 |
|
625 // --------------------------------------------------------- |
|
626 // CAIPluginContainerControl::ChangeFocusPluginL |
|
627 // --------------------------------------------------------- |
|
628 // |
|
629 void CAIPluginContainerControl::ChangeFocusPluginL(TInt aDirection) |
|
630 { |
|
631 if (!iCurrentPlugin) |
|
632 { |
|
633 return ; |
|
634 } |
|
635 iCurrentPlugin->iPlugin->PrepareForFocusLossL(); |
|
636 iCurrentPlugin->iPlugin->SetFocus(EFalse,EDrawNow) ; |
|
637 switch(aDirection) |
|
638 { |
|
639 case EAIFocusDown: |
|
640 iIndexPlugin = NextVisiblePlugin(iIndexPlugin+1) ; |
|
641 break ; |
|
642 case EAIFocusUp: |
|
643 iIndexPlugin = PreviousVisiblePlugin(iIndexPlugin-1) ; |
|
644 break ; |
|
645 default: |
|
646 User::Leave(KErrNotSupported) ; |
|
647 } |
|
648 if (iIndexPlugin == -1) |
|
649 { |
|
650 iCurrentPlugin = NULL ; |
|
651 } |
|
652 else |
|
653 { |
|
654 iCurrentPlugin = iPlugins[iIndexPlugin]; |
|
655 iCurrentPlugin->iPlugin->PrepareForFocusGainL(); |
|
656 iCurrentPlugin->iPlugin->SetFocus(ETrue,EDrawNow) ; |
|
657 } |
|
658 } |
|
659 |
|
660 // --------------------------------------------------------- |
|
661 // CAIPluginContainerControl::FocusOnDefaultFocusingPlugin |
|
662 // --------------------------------------------------------- |
|
663 // |
|
664 void CAIPluginContainerControl::FocusOnDefaultFocusingPlugin(TDrawNow aDrawNow) |
|
665 { |
|
666 if (!CountComponentControls()) |
|
667 { |
|
668 return ; |
|
669 } |
|
670 TInt index = NextVisiblePlugin(iIndexDefaultFocusingPlugin) ; |
|
671 if (index != iIndexPlugin) |
|
672 { |
|
673 if (iCurrentPlugin) |
|
674 { |
|
675 TRAP_IGNORE(iCurrentPlugin->iPlugin->PrepareForFocusLossL()); //TRAPPED |
|
676 iCurrentPlugin->iPlugin->SetFocus(EFalse,aDrawNow) ; |
|
677 } |
|
678 iIndexPlugin = index; |
|
679 } |
|
680 if (iIndexPlugin == -1) |
|
681 { |
|
682 iCurrentPlugin = NULL ; |
|
683 } |
|
684 else |
|
685 { |
|
686 /*if (iCurrentPlugin && iCurrentPlugin->iPlugin->IsFocused()) |
|
687 { |
|
688 return; |
|
689 } |
|
690 */ |
|
691 iCurrentPlugin = iPlugins[iIndexPlugin]; |
|
692 TRAP_IGNORE(iCurrentPlugin->iPlugin->PrepareForFocusGainL()); //TRAPPED |
|
693 iCurrentPlugin->iPlugin->ResetToDefaultState(); |
|
694 iCurrentPlugin->iPlugin->SetFocus(ETrue,aDrawNow) ; |
|
695 } |
|
696 } |
|
697 |
|
698 // --------------------------------------------------------- |
|
699 // CAIPluginContainerControl::CalculateRectPlugins |
|
700 // --------------------------------------------------------- |
|
701 // |
|
702 void CAIPluginContainerControl::CalculateRectPlugins() |
|
703 { |
|
704 if (CountComponentControls() == 0) |
|
705 { |
|
706 DrawNow(); |
|
707 return ; |
|
708 } |
|
709 |
|
710 TInt paneHeight = Rect().Height(); |
|
711 |
|
712 TInt topPluginX=0; |
|
713 TInt bottomPluginX=paneHeight; |
|
714 |
|
715 for ( TInt index = 0; index < iPlugins.Count(); index++) |
|
716 { |
|
717 iPlugins[index]->iOnScreen = EFalse ; |
|
718 } |
|
719 |
|
720 HandleTopPlugins(topPluginX,bottomPluginX) ; |
|
721 HandleBottomPlugins(topPluginX,bottomPluginX) ; |
|
722 |
|
723 if (iIndexPlugin == -1) |
|
724 { |
|
725 FocusOnDefaultFocusingPlugin(); |
|
726 } |
|
727 |
|
728 DrawNow(); |
|
729 } |
|
730 |
|
731 |
|
732 // --------------------------------------------------------- |
|
733 // CAIPluginContainerControl::HandleTopplugins |
|
734 // --------------------------------------------------------- |
|
735 // |
|
736 void CAIPluginContainerControl::HandleTopPlugins(TInt& aTopPluginX, TInt& aBottomPluginX) |
|
737 { |
|
738 |
|
739 for ( TInt index = 0; index < iPlugins.Count(); index++) |
|
740 { |
|
741 HandlePlugin(index,EAITop,aTopPluginX,aBottomPluginX); |
|
742 } // for all plugins |
|
743 |
|
744 } |
|
745 |
|
746 // --------------------------------------------------------- |
|
747 // CAIPluginContainerControl::HandleBottomPlugins |
|
748 // --------------------------------------------------------- |
|
749 // |
|
750 void CAIPluginContainerControl::HandleBottomPlugins(TInt& aTopPluginX, TInt& aBottomPluginX) |
|
751 { |
|
752 for ( TInt index = iPlugins.Count() -1 ; index >= 0 ; index--) |
|
753 { |
|
754 HandlePlugin(index,EAIBottom,aTopPluginX,aBottomPluginX); |
|
755 } |
|
756 } |
|
757 |
|
758 // --------------------------------------------------------- |
|
759 // CAIPluginContainerControl::HandlePlugin |
|
760 // --------------------------------------------------------- |
|
761 // |
|
762 void CAIPluginContainerControl::HandlePlugin(TInt aIndex, |
|
763 TAIPluginAlignment aAlign, |
|
764 TInt& aTopPluginX, |
|
765 TInt& aBottomPluginX) |
|
766 { |
|
767 TRect rectPlugin ; //Rect of the current plugin |
|
768 |
|
769 TPluginInfo* pluginItem = iPlugins[aIndex]; |
|
770 |
|
771 if ((pluginItem->iPlugin) && (pluginItem->iAlignment == aAlign)) |
|
772 { |
|
773 TSize plugSize = pluginItem->iPlugin->GetPreferedSize(); |
|
774 |
|
775 if ((plugSize.iHeight>0) && (plugSize.iWidth >0)) |
|
776 { |
|
777 pluginItem->iOnScreen = ETrue; |
|
778 |
|
779 TInt overRunHeight = 0 ; |
|
780 |
|
781 if (pluginItem->iAlignment == EAITop) |
|
782 { |
|
783 if ((aTopPluginX+plugSize.iHeight) > aBottomPluginX) |
|
784 { |
|
785 overRunHeight = aTopPluginX+plugSize.iHeight-aBottomPluginX ; |
|
786 } |
|
787 } |
|
788 else |
|
789 { |
|
790 |
|
791 if ((aBottomPluginX-plugSize.iHeight) < aTopPluginX) |
|
792 { |
|
793 overRunHeight = aTopPluginX-(aBottomPluginX-plugSize.iHeight) ; |
|
794 } |
|
795 } |
|
796 if (overRunHeight) |
|
797 { |
|
798 |
|
799 while (overRunHeight > 0) |
|
800 { // loop finding reduceable plugins from the first to the current |
|
801 TInt reduceablePluginIndex = FindReduceablePlugin(overRunHeight,aIndex) ; |
|
802 if (reduceablePluginIndex == -1) |
|
803 { |
|
804 // no plugin can be reduced. |
|
805 // get the plugin with the lowerest Weight and hide it |
|
806 TInt hideblePluginIndex = FindLowerWeightPlugin(aIndex) ; |
|
807 if ((hideblePluginIndex == -1) || (hideblePluginIndex == aIndex)) |
|
808 { |
|
809 HidePlugin(aIndex) ; |
|
810 return ; |
|
811 } |
|
812 else |
|
813 { |
|
814 TInt hideblePluginHeight = iPlugins[hideblePluginIndex]->iPlugin->Rect().Size().iHeight ; |
|
815 // Hide the found plugin and move the other before the current |
|
816 ReducePlugin(hideblePluginIndex,aIndex,hideblePluginHeight) ; |
|
817 if (iPlugins[hideblePluginIndex]->iAlignment == EAITop) |
|
818 { |
|
819 // recalculate position the the top current plugin |
|
820 aTopPluginX -= hideblePluginHeight ; |
|
821 } |
|
822 else |
|
823 { |
|
824 // recalculate position the the bottom current plugin |
|
825 aBottomPluginX += hideblePluginHeight; |
|
826 } |
|
827 overRunHeight -= hideblePluginHeight; |
|
828 } |
|
829 } |
|
830 else |
|
831 { |
|
832 // get the height that the found reduaceble plugin can reduce itself |
|
833 TInt reduceablePluginHeight = iPlugins[reduceablePluginIndex]->iPlugin->GetNextSizeDecrement().iHeight ; |
|
834 if (reduceablePluginIndex == aIndex) |
|
835 { |
|
836 // if it has to be reduced the current plugin |
|
837 // just recalculate the size of itself |
|
838 plugSize -= TSize(0,reduceablePluginHeight) ; |
|
839 if (plugSize.iHeight <= 0) |
|
840 { |
|
841 HidePlugin(aIndex) ; |
|
842 return ; |
|
843 } |
|
844 else |
|
845 { |
|
846 if (pluginItem->iAlignment == EAITop) |
|
847 { |
|
848 rectPlugin.SetRect(TPoint(0,aTopPluginX),plugSize) ; |
|
849 } |
|
850 else |
|
851 { |
|
852 rectPlugin.SetRect(TPoint(0,aBottomPluginX-plugSize.iHeight),plugSize) ; |
|
853 } |
|
854 |
|
855 pluginItem->iPlugin->SetRect(rectPlugin); |
|
856 } |
|
857 } |
|
858 else |
|
859 { |
|
860 // reduce the found plugin and move the other before the current |
|
861 ReducePlugin(reduceablePluginIndex,aIndex,reduceablePluginHeight) ; |
|
862 if (iPlugins[reduceablePluginIndex]->iAlignment == EAITop) |
|
863 { |
|
864 // recalculate position the the top current plugin |
|
865 aTopPluginX -= reduceablePluginHeight ; |
|
866 } |
|
867 else |
|
868 { |
|
869 // recalculate position the the bottom current plugin |
|
870 aBottomPluginX += reduceablePluginHeight; |
|
871 } |
|
872 } |
|
873 overRunHeight -= reduceablePluginHeight; |
|
874 } |
|
875 } |
|
876 |
|
877 if (overRunHeight > 0) |
|
878 { |
|
879 //no plugin can be reduced go to the next one |
|
880 return; |
|
881 } |
|
882 } // while finding reduceable plugin(s) |
|
883 |
|
884 if (pluginItem->iAlignment == EAITop) |
|
885 { |
|
886 rectPlugin.SetRect(TPoint(0,aTopPluginX),plugSize) ; |
|
887 aTopPluginX += plugSize.iHeight; |
|
888 } |
|
889 else |
|
890 { |
|
891 rectPlugin.SetRect(TPoint(0,aBottomPluginX-plugSize.iHeight),plugSize) ; |
|
892 aBottomPluginX -= plugSize.iHeight; |
|
893 } |
|
894 pluginItem->iPlugin->SetRect(rectPlugin); |
|
895 //pluginItem->iPlugin->SetDimmed(EFalse); |
|
896 } |
|
897 else |
|
898 { |
|
899 // No on the screen |
|
900 HidePlugin(aIndex) ; |
|
901 } |
|
902 } |
|
903 } |
|
904 |
|
905 // --------------------------------------------------------- |
|
906 // CAIPluginContainerControl::NextVisiblePlugin |
|
907 // --------------------------------------------------------- |
|
908 // |
|
909 TInt CAIPluginContainerControl::NextVisiblePlugin(TInt aStartIndex) |
|
910 { |
|
911 for ( TInt index = aStartIndex; index < iPlugins.Count(); index++) |
|
912 { |
|
913 TPluginInfo* plug = iPlugins[index]; |
|
914 if (plug->iPlugin && (plug->iOnScreen) && (plug->iPlugin->IsNonFocusing() == EFalse)) |
|
915 { |
|
916 return index ; |
|
917 } |
|
918 } |
|
919 return aStartIndex > 0 ? NextVisiblePlugin(0) : -1 ; |
|
920 } |
|
921 |
|
922 // --------------------------------------------------------- |
|
923 // CAIPluginContainerControl::PreviousVisiblePlugin |
|
924 // --------------------------------------------------------- |
|
925 // |
|
926 TInt CAIPluginContainerControl::PreviousVisiblePlugin(TInt aStartIndex) |
|
927 { |
|
928 for ( TInt index = aStartIndex; index >= 0; index--) |
|
929 { |
|
930 TPluginInfo* plug = iPlugins[index]; |
|
931 if (plug->iPlugin && (plug->iOnScreen) && (plug->iPlugin->IsNonFocusing() == EFalse)) |
|
932 { |
|
933 return index ; |
|
934 } |
|
935 } |
|
936 return (aStartIndex < (iPlugins.Count()-1)) ? PreviousVisiblePlugin(iPlugins.Count()-1) : -1 ; |
|
937 } |
|
938 |
|
939 |
|
940 // --------------------------------------------------------- |
|
941 // CAIPluginContainerControl::FindLowerWeightPlugin |
|
942 // --------------------------------------------------------- |
|
943 // |
|
944 TInt CAIPluginContainerControl::FindLowerWeightPlugin(TInt aCurrentIndex) |
|
945 { |
|
946 TInt foundIndex = -1; |
|
947 TInt plugWeight = -1; |
|
948 TInt currentWeight = iPlugins[aCurrentIndex]->iWeight ; |
|
949 |
|
950 for ( TInt index = 0 ; index <= iPlugins.Count()-1; index++) |
|
951 { |
|
952 TPluginInfo* plug = iPlugins[index]; |
|
953 if ((plug->iOnScreen) && (plug->iWeight<=currentWeight) && |
|
954 ((foundIndex==-1) || (plug->iWeight<=plugWeight))) |
|
955 { |
|
956 foundIndex = index ; |
|
957 plugWeight = plug->iWeight; |
|
958 } |
|
959 } |
|
960 return foundIndex ; |
|
961 } |
|
962 |
|
963 // --------------------------------------------------------- |
|
964 // CAIPluginContainerControl::FindReduceablePlugin |
|
965 // --------------------------------------------------------- |
|
966 // |
|
967 TInt CAIPluginContainerControl::FindReduceablePlugin(TInt aOverRunHeight, TInt aCurrentIndex) |
|
968 { |
|
969 TInt foundIndex = -1; |
|
970 TInt plugWeight = -1; |
|
971 |
|
972 for ( TInt index = 0 ; index <= iPlugins.Count()-1; index++) |
|
973 { |
|
974 TPluginInfo* plug = iPlugins[index]; |
|
975 //When resize I don't check the Weight with the current plugin |
|
976 // before we try to reduce a plugin |
|
977 // if any plugin can be reduced then we have to hide a plugin with a weight less of the current |
|
978 if ((plug->iResizeable) && (plug->iOnScreen)) //&& (plug->iWeight <= currentWeight)) |
|
979 { |
|
980 TInt reduceablePluginHeight = iPlugins[index]->iPlugin->GetNextSizeDecrement().iHeight ; |
|
981 if (reduceablePluginHeight > 0) |
|
982 { |
|
983 // the plugin can still be reduced |
|
984 if (index == aCurrentIndex) |
|
985 { |
|
986 if ((plugWeight == -1) || (plug->iWeight <= plugWeight)) |
|
987 { |
|
988 foundIndex = index ; |
|
989 plugWeight = plug->iWeight ; |
|
990 } |
|
991 } |
|
992 else |
|
993 { |
|
994 TSize plugMinSize = plug->iPlugin->GetMinSize() ; |
|
995 TSize plugSize = plug->iPlugin->Rect().Size(); |
|
996 TInt plugOverRunHeight = plugSize.iHeight-plugMinSize.iHeight; |
|
997 if ((plugOverRunHeight >=aOverRunHeight) && |
|
998 ((plugWeight == -1) || (plug->iWeight <= plugWeight))) // before I check the weight |
|
999 { |
|
1000 foundIndex = index ; |
|
1001 plugWeight = plug->iWeight ; |
|
1002 } |
|
1003 } |
|
1004 } |
|
1005 } |
|
1006 } |
|
1007 return foundIndex ; |
|
1008 } |
|
1009 |
|
1010 // --------------------------------------------------------- |
|
1011 // CAIPluginContainerControl::ReducePlugin |
|
1012 // --------------------------------------------------------- |
|
1013 // |
|
1014 void CAIPluginContainerControl::ReducePlugin(TInt aPluginToBeReducedIndex, |
|
1015 TInt aCurrentIndex, |
|
1016 TInt aReduceHeight) |
|
1017 { |
|
1018 TInt startIndex; |
|
1019 TInt lastIndex; |
|
1020 TInt lastTopPluginIndex ; |
|
1021 TInt index; |
|
1022 |
|
1023 TAIPluginAlignment reduceAlign = iPlugins[aPluginToBeReducedIndex]->iAlignment ; |
|
1024 |
|
1025 //find the last top plugin in the list |
|
1026 lastTopPluginIndex = -1; |
|
1027 for ( index = 0 ; index < iPlugins.Count() ; index++) |
|
1028 { |
|
1029 if (iPlugins[index]->iAlignment==EAITop) |
|
1030 { |
|
1031 lastTopPluginIndex = index; |
|
1032 } |
|
1033 } |
|
1034 |
|
1035 if (reduceAlign == EAITop) |
|
1036 { |
|
1037 __ASSERT_ALWAYS(aPluginToBeReducedIndex <= lastTopPluginIndex, User::Invariant()); |
|
1038 startIndex = aPluginToBeReducedIndex; |
|
1039 // we don't have to handle the current if is in the top list |
|
1040 // otherwise if the current index is in the bottom we handle all the top plugin |
|
1041 lastIndex = (aCurrentIndex <= lastTopPluginIndex) ? (aCurrentIndex > aPluginToBeReducedIndex ? aCurrentIndex -1 : aCurrentIndex ): lastTopPluginIndex; |
|
1042 } |
|
1043 else |
|
1044 { |
|
1045 // if lastTopPluginIndex==-1 means all the plugin have a botton alignment |
|
1046 startIndex = lastTopPluginIndex+1; |
|
1047 if (startIndex == aCurrentIndex) |
|
1048 {//we don't have to handle the current plugin |
|
1049 startIndex++; |
|
1050 } |
|
1051 __ASSERT_ALWAYS(aPluginToBeReducedIndex >= startIndex, User::Invariant()); |
|
1052 lastIndex = aPluginToBeReducedIndex; |
|
1053 } |
|
1054 |
|
1055 for ( index = startIndex ; index <= lastIndex; index++) |
|
1056 { |
|
1057 TPluginInfo* plug = iPlugins[index]; |
|
1058 |
|
1059 if (plug->iOnScreen && plug->iPlugin) |
|
1060 { |
|
1061 TRect rectPlugin = plug->iPlugin->Rect() ; |
|
1062 if (index == aPluginToBeReducedIndex) |
|
1063 { |
|
1064 TSize newSize(0, aReduceHeight) ; |
|
1065 rectPlugin.Resize(-newSize) ; |
|
1066 if (rectPlugin.Height() == 0) |
|
1067 { |
|
1068 HidePlugin(index) ; |
|
1069 } |
|
1070 else |
|
1071 { |
|
1072 if (reduceAlign == EAIBottom) |
|
1073 { |
|
1074 rectPlugin.Move(0,+aReduceHeight); |
|
1075 } |
|
1076 plug->iPlugin->SetRect(rectPlugin) ; |
|
1077 } |
|
1078 } |
|
1079 else |
|
1080 { |
|
1081 if (reduceAlign == EAITop) |
|
1082 { |
|
1083 rectPlugin.Move(0,-aReduceHeight); |
|
1084 plug->iPlugin->SetRect(rectPlugin); |
|
1085 } |
|
1086 else |
|
1087 { |
|
1088 rectPlugin.Move(0,+aReduceHeight); |
|
1089 plug->iPlugin->SetRect(rectPlugin); |
|
1090 } |
|
1091 } |
|
1092 } |
|
1093 } |
|
1094 } |
|
1095 |
|
1096 // --------------------------------------------------------- |
|
1097 // CAIPluginContainerControl::HidePlugin |
|
1098 // --------------------------------------------------------- |
|
1099 // |
|
1100 void CAIPluginContainerControl::HidePlugin(TInt aIndex) |
|
1101 { |
|
1102 TPluginInfo* plug = iPlugins[aIndex]; |
|
1103 |
|
1104 //plug->iPlugin->SetDimmed(ETrue) ; |
|
1105 plug->iPlugin->SetRect(TRect(0,0,0,0)) ; |
|
1106 plug->iOnScreen = EFalse ; |
|
1107 |
|
1108 if (iIndexPlugin == aIndex) |
|
1109 { // the plugin that is going to dissappear have the focus |
|
1110 TRAP_IGNORE(ChangeFocusPluginL(EAIFocusDown)); //TRAPPED |
|
1111 } |
|
1112 } |
|
1113 |
|
1114 // End of File |