camerauis/activepalette/Src/ActivePalette2BasicUI.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 0 1ddebce53859
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007 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:  AP implementation using standard Symbian controls*
       
    15 */
       
    16 
       
    17 
       
    18 /**
       
    19  * @file ActivePalette2BasicUI.cpp
       
    20  * AP implementation using standard Symbian controls
       
    21  */
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include <eikenv.h>
       
    26 #include <aknenv.h>
       
    27 #include <barsread.h>
       
    28 #include <AknsDrawUtils.h>
       
    29 #include <AknsControlContext.h>
       
    30 #include <AknsBasicBackgroundControlContext.h>
       
    31 #include <AknUtils.h>
       
    32 #include <gdi.h>
       
    33 #include <activepalette2factory.h>
       
    34 #include <activepalette2observer.h>
       
    35 #include <activepalette2ui.h>
       
    36 #include <activepalette2eventdata.h>
       
    37 
       
    38 #include "ActivePalette2BasicUI.h"
       
    39 #include "ActivePalette2Styler.h"
       
    40 #include "ActivePalette2StylerFactory.h"
       
    41 #include "ActivePalette2Item.h"
       
    42 #include "ActivePalette2Cfg.h"
       
    43 #include "activepalette2configuration.h"
       
    44 #include "ActivePalette2Logger.h"
       
    45 #include "ActivePalette2Utils.h"
       
    46 #include "ActivePalette2Model.h"
       
    47 #include "ActivePalette2Const.h"
       
    48 #include "ActivePalette2Tooltip.h"
       
    49 #include "activepalette2tooltipfactory.h"
       
    50 
       
    51 
       
    52 // ================= MEMBER FUNCTIONS =======================
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CActivePalette2BasicUI::NewL()
       
    57 // Symbian 2 phase constructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CActivePalette2BasicUI* CActivePalette2BasicUI::NewL(TActivePalette2DrawMode aDrawMode)
       
    61 	{
       
    62 	CActivePalette2BasicUI* self = new (ELeave) CActivePalette2BasicUI();
       
    63 	CleanupStack::PushL(self);
       
    64 	self->ConstructL(aDrawMode);
       
    65 	CleanupStack::Pop(self);
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CActivePalette2BasicUI::CActivePalette2BasicUI()
       
    71 // C++ constructor
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 
       
    75 CActivePalette2BasicUI::CActivePalette2BasicUI():
       
    76     iNavigationKeys()                  // default navigation keys
       
    77   {
       
    78 	LOGTEXT( _L( "CActivePalette2BasicUI::CActivePalette2BasicUI"));
       
    79   }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CActivePalette2BasicUI::ConstructL
       
    83 // Leaving constructor
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CActivePalette2BasicUI::ConstructL(TActivePalette2DrawMode aDrawMode )
       
    87 	{
       
    88 	LOGTEXT( _L( "CActivePalette2BasicUI::ConstructL entered"));
       
    89 
       
    90 	// UI sizes and dimensions
       
    91 	AknLayoutUtils::LayoutMetricsSize( AknLayoutUtils::EScreen, iScreenSize );
       
    92 
       
    93 	iTopLeftCorner.iX = iScreenSize.iWidth + ActivePalette2Utils::APDimensionPoint(ActivePalette2Utils::EDefault2dPaletteOffset).iX;
       
    94 	iTopLeftCorner.iY = ActivePalette2Utils::APDimensionPoint(ActivePalette2Utils::EDefault2dPaletteOffset).iY;
       
    95 	
       
    96 	iDrawMode = aDrawMode;
       
    97 
       
    98   iStyler = ActivePalette2StylerFactory::CreateStylerL(aDrawMode);
       
    99 
       
   100   TRendererCallBacks callBacks;
       
   101   callBacks.iTooltipTimer = this;
       
   102   callBacks.iFocusTimer = this;
       
   103   callBacks.iItemScrollTimer = this;
       
   104   callBacks.iAppearanceTimer = this;
       
   105   
       
   106   // Configuration provider
       
   107   iConfiguration = CActivePalette2Configuration::NewL( aDrawMode );  
       
   108   
       
   109 	// model
       
   110 	iModel = CActivePalette2Model::NewL( *this, 
       
   111 	                                     ActivePalette2Utils::APDimensionSize( ActivePalette2Utils::EItemSize ), 
       
   112 	                                     callBacks, 
       
   113 	                                     iConfiguration );
       
   114   // valid model required from this point
       
   115 
       
   116   iTooltipNote = ActivePalette2TooltipFactory::CreateTooltipL( aDrawMode, this, iModel, iStyler );
       
   117   iTooltipNote->SetAnchor(iTopLeftCorner);
       
   118 
       
   119 	ReCalcAutoSizeL();
       
   120 
       
   121 	// enter idle
       
   122 	RedrawIdle(EFalse);
       
   123 
       
   124 	ActivateL();
       
   125 
       
   126 	LOGTEXT( _L( "CActivePalette2BasicUI::ConstructL left"));
       
   127 	}
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CActivePalette2BasicUI::~CActivePalette2BasicUI()
       
   131 // Destructor
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 CActivePalette2BasicUI::~CActivePalette2BasicUI()
       
   135     {
       
   136 	LOGTEXT( _L( "CActivePalette2BasicUI::~CActivePalette2BasicUI entered"));
       
   137 
       
   138 	delete iTooltipNote;
       
   139 	iTooltipNote = NULL;
       
   140 
       
   141   delete iStyler;
       
   142   iStyler = NULL;
       
   143   
       
   144   delete iConfiguration;
       
   145   iConfiguration = NULL;
       
   146 
       
   147 	delete iModel;
       
   148 	iModel = NULL;
       
   149 
       
   150 	LOGTEXT( _L( "CActivePalette2BasicUI::~CActivePalette2BasicUI left"));
       
   151     }
       
   152 
       
   153 
       
   154 
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CActivePalette2BasicUI::Draw()
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CActivePalette2BasicUI::Draw(const TRect& aRect) const
       
   161 	{
       
   162 	LOGTEXT( _L( "CActivePalette2BasicUI::Draw entered" ));
       
   163 
       
   164     if ( !iRenderGc )
       
   165         {    
       
   166     	// Flush buf to the screen
       
   167     	ProducePaletteToScreen(aRect);
       
   168     	
       
   169     	if ( iTooltipNote )
       
   170         	{
       
   171         	iTooltipNote->Draw(aRect);
       
   172         	}
       
   173     	}
       
   174 
       
   175 	LOGTEXT( _L( "CActivePalette2BasicUI::Draw left" ));
       
   176 	}
       
   177 
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CActivePalette2BasicUI::RedrawIdle()
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CActivePalette2BasicUI::RedrawIdle(TBool aForceDisplayUpdate) const
       
   184     {
       
   185     const TRect rect(TPoint(0,0),TPoint(Rect().Width(), Rect().Height()));
       
   186 
       
   187     // Invalidating and redrawing the toolbar background at this point causes
       
   188     // blinking and is unnecessary. Background will be redrawn with the toolbar.
       
   189     /*
       
   190     if ( iAPObserver )
       
   191         {
       
   192         TRect rectToFlush(DrawBufRectToScreenRect(rect));
       
   193         
       
   194         if ( rectToFlush.Size().iWidth > 0 && rectToFlush.Size().iHeight > 0 )
       
   195             {
       
   196             if ( !iRenderGc )
       
   197                 {
       
   198             	Window().Invalidate(rectToFlush);
       
   199             	ActivateGc();
       
   200             	Window().BeginRedraw(rectToFlush);
       
   201                 }            
       
   202                 
       
   203             iAPObserver->Redraw(rectToFlush);
       
   204 
       
   205             if ( !iRenderGc )
       
   206                 {
       
   207             	Window().EndRedraw();
       
   208             	DeactivateGc();
       
   209             	}
       
   210         	}
       
   211         }
       
   212     */
       
   213     
       
   214     iStyler->DrawTopScrollArrowSection(iModel->ShowTopScrollIndicator());
       
   215 
       
   216     TInt num_items = iModel->CountItemsOnScreen();
       
   217     if ( iModel->ItemScrollOffset() != 0 )
       
   218         {
       
   219         num_items++;
       
   220         }
       
   221 
       
   222 	TInt index;
       
   223 	for (index = 0; index < num_items; index++)
       
   224 	    {
       
   225 		CActivePalette2Item* item = iModel->ItemFromScreenPos(index);
       
   226 		
       
   227 		if ( item )
       
   228 		    {
       
   229             iStyler->DrawItem(index, &item->Icon(), item->Mask(), iModel->ItemScrollOffset(), iModel->ItemScrollTotalFrames());
       
   230             if (index+1 < num_items)
       
   231                 {
       
   232                 iStyler->DrawGap(index, iModel->ItemScrollOffset(), iModel->ItemScrollTotalFrames());
       
   233                 }
       
   234 			}
       
   235 	    }
       
   236 
       
   237     iStyler->DrawBottomScrollArrowSection(iModel->ShowBottomScrollIndicator());
       
   238     
       
   239     if ( iModel->PaletteActive() 
       
   240          && iModel->CountItemsOnScreen() > 0 )
       
   241         {
       
   242         TInt focusedItem = iModel->FocusedItem();
       
   243         iStyler->DrawFocusRing(focusedItem, iModel->FocusCurrentOffset(), iModel->FocusCurrentTotalOffsetFrames());
       
   244         iFocusedItem1 = focusedItem;
       
   245         iFocusedItem2 = focusedItem + 1;
       
   246 	    }
       
   247 
       
   248 	if (aForceDisplayUpdate)
       
   249 	    {
       
   250 		DrawDeferred();
       
   251 		
       
   252         if ( iRenderGc && iAPObserver )
       
   253             {
       
   254             iAPObserver->ActivePaletteUpdated();
       
   255             }
       
   256     	}
       
   257     }
       
   258 
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CActivePalette2BasicUI::ProducePaletteToScreen()
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CActivePalette2BasicUI::ProducePaletteToScreen(const TRect& aRect) const
       
   265 	{
       
   266 	if ( iAPObserver )
       
   267     	{
       
   268     	TRect redrawRect(aRect);
       
   269     	redrawRect.Intersection(iRenderedRect);
       
   270         if ( redrawRect.Size().iHeight > 0 && redrawRect.Size().iWidth > 0 )
       
   271             {
       
   272             iAPObserver->Redraw(redrawRect);
       
   273             }
       
   274         } 
       
   275    
       
   276     iRenderedRect = TRect(PalettePosition(), iStyler->Size());
       
   277 
       
   278 	if ( iRenderGc )
       
   279     	{
       
   280         iStyler->BlitPalette(iRenderGc, PalettePosition(), ScreenRectToDrawBufRect(aRect));
       
   281     	}
       
   282 	else
       
   283     	{
       
   284         iStyler->BlitPalette(&SystemGc(), PalettePosition(), ScreenRectToDrawBufRect(aRect));
       
   285         }            
       
   286 
       
   287 	}
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CActivePalette2BasicUI::FlushBufNow()
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CActivePalette2BasicUI::FlushBufNow(const TRect& aRectToFlush)
       
   294     {
       
   295     if ( !iRenderGc )
       
   296         {
       
   297     	Window().Invalidate(aRectToFlush);
       
   298     	ActivateGc();
       
   299     	Window().BeginRedraw(aRectToFlush);
       
   300         }            
       
   301             
       
   302 	ProducePaletteToScreen(aRectToFlush);
       
   303 
       
   304     if ( !iRenderGc )
       
   305         {
       
   306     	Window().EndRedraw();
       
   307     	DeactivateGc();
       
   308     	}
       
   309     }
       
   310 
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CActivePalette2BasicUI::SetCurrentItem()
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 TInt CActivePalette2BasicUI::SetCurrentItem(const TInt aItemId)
       
   317     {
       
   318     return iModel->SetCurrentItem(aItemId);
       
   319     }
       
   320 
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CActivePalette2BasicUI::GetCurrentItem()
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 TInt CActivePalette2BasicUI::GetCurrentItem(TInt & aItemId) const
       
   327     {
       
   328     return iModel->GetCurrentItem(aItemId);
       
   329     }
       
   330 
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CActivePalette2BasicUI::SizeChanged()
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CActivePalette2BasicUI::SizeChanged(void)
       
   337     {
       
   338 	LOGTEXT( _L( "CActivePalette2BasicUI::SizeChanged") );
       
   339 	CCoeControl::SizeChanged();
       
   340     }
       
   341 
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CActivePalette2BasicUI::SetNavigationKeys()
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CActivePalette2BasicUI::SetNavigationKeys(const TActivePalette2NavigationKeys & aNavigationKeys)
       
   348     {
       
   349 	iNavigationKeys = aNavigationKeys;
       
   350     }
       
   351 
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CActivePalette2BasicUI::SetObserver()
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 void CActivePalette2BasicUI::SetObserver(MActivePalette2Observer * aObserver)
       
   358     {
       
   359 	iAPObserver = aObserver;
       
   360     }
       
   361 
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // CActivePalette2BasicUI::SendMessage()
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 TInt CActivePalette2BasicUI::SendMessage(TInt aItemId, TInt aMessageId, const TDesC8& aDataDes)
       
   368     {
       
   369     return iModel->SendMessage(aItemId, aMessageId, aDataDes);
       
   370     }
       
   371 
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CActivePalette2BasicUI::SendMessage()
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 TInt CActivePalette2BasicUI::SendMessage(const TInt aItemId, const TInt aMessageId, const TInt aDataInt)
       
   378     {
       
   379     return iModel->SendMessage(aItemId, aMessageId, aDataInt);
       
   380     }
       
   381 
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CActivePalette2BasicUI::ReCalcAutoSizeL()
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CActivePalette2BasicUI::ReCalcAutoSizeL(void)
       
   388     {
       
   389     iStyler->SetNumberOfItemsL(iModel->CountItemsOnScreen());
       
   390 
       
   391     TRect newRect(TPoint(0,0),iStyler->Size());
       
   392     newRect.Move(PalettePosition());
       
   393     SetRect(newRect);
       
   394     }
       
   395 
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // TInt CActivePalette2BasicUI::InstallItemL()
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 TInt CActivePalette2BasicUI::InstallItemL(const TActivePalette2ItemVisible& aItemVisible,
       
   402                                              const TUid& aPluginUid,
       
   403                                              const TDesC8& aCustomDataDes)
       
   404     {
       
   405 	return iModel->InstallItemL(aItemVisible, aPluginUid, aCustomDataDes);
       
   406     }
       
   407 
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CActivePalette2BasicUI::InstallItemL()
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 TInt CActivePalette2BasicUI::InstallItemL(const TActivePalette2ItemVisible& aItemVisible,
       
   414                                              const TUid& aPluginUid,
       
   415                                              TInt aCustomDataInt)
       
   416     {
       
   417 	return iModel->InstallItemL(aItemVisible, aPluginUid, aCustomDataInt);
       
   418     }
       
   419 
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CActivePalette2BasicUI::InstallItemL()
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 TInt CActivePalette2BasicUI::InstallItemL(const TActivePalette2ItemVisible& aItemVisible,
       
   426                                              const TUid& aPluginUid,
       
   427                                              TInt aCustomDataInt,
       
   428                                              const TDesC8& aCustomDataDes)
       
   429     {
       
   430 	return iModel->InstallItemL(aItemVisible, aPluginUid, aCustomDataInt, aCustomDataDes);
       
   431     }
       
   432 
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CActivePalette2BasicUI::RemoveItem()
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 TInt CActivePalette2BasicUI::RemoveItem(const TInt aItemId)
       
   439     {
       
   440     return iModel->RemoveItem(aItemId);
       
   441     }
       
   442 
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // CActivePalette2BasicUI::LocateTo()
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 void CActivePalette2BasicUI::LocateTo(const TPoint& aTopLeft)
       
   449 	{
       
   450 	iTopLeftCorner = aTopLeft;
       
   451     iTooltipNote->SetAnchor(aTopLeft);
       
   452     
       
   453 	TRect newRect(PalettePosition(),Rect().Size());
       
   454 	SetRect(newRect);
       
   455 	}
       
   456 
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CActivePalette2BasicUI::Location()
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 TPoint CActivePalette2BasicUI::Location(void) const
       
   463 	{
       
   464 	return iTopLeftCorner;
       
   465 	}
       
   466 
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // CActivePalette2BasicUI::OfferKeyEventL(
       
   470 // -----------------------------------------------------------------------------
       
   471 //
       
   472 TKeyResponse CActivePalette2BasicUI::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   473                                               TEventCode aType)
       
   474     {
       
   475 	LOGTEXT2( _L( "CActivePalette2BasicUI::OfferKeyEventL entered, type : %d, scancode : %d"),
       
   476 			aType, aKeyEvent.iScanCode);
       
   477 
       
   478 	TKeyResponse res = EKeyWasNotConsumed;
       
   479 	if (EEventKey == aType && iModel)
       
   480     	{
       
   481 		if (aKeyEvent.iScanCode == iNavigationKeys.iNaviPrev)
       
   482 	    	{ 
       
   483 	    	// go to previous
       
   484             if ( iModel->ProcessInputEvent(EAP2InputUp) )
       
   485                 {
       
   486     			res = EKeyWasConsumed;
       
   487                 }
       
   488 		    }
       
   489 		else if (aKeyEvent.iScanCode == iNavigationKeys.iNaviNext)
       
   490 		    { 
       
   491 		    // go to next
       
   492             if ( iModel->ProcessInputEvent(EAP2InputDown) )
       
   493                 {
       
   494     			res = EKeyWasConsumed;
       
   495                 }
       
   496 		    }
       
   497 		else if ( aKeyEvent.iScanCode == iNavigationKeys.iNaviSelect &&
       
   498 		          aKeyEvent.iRepeats == 0 )
       
   499 		    { 
       
   500 		    // select item
       
   501             if ( iModel->ProcessInputEvent(EAP2InputSelect) )
       
   502                 {
       
   503     			res = EKeyWasConsumed;
       
   504                 }
       
   505 		    }
       
   506 		else
       
   507 		    {
       
   508 		    // Lint!
       
   509     		}
       
   510 	    }
       
   511 
       
   512 	LOGTEXT1( _L( "CActivePalette2BasicUI::OfferKeyEventL left, res : %d"),res);
       
   513 
       
   514 	return res;
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CActivePalette2BasicUI::DrawBufRectToScreenRect()
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 TRect CActivePalette2BasicUI::DrawBufRectToScreenRect(TRect aDrawBufRect) const
       
   522     {
       
   523     TRect screenRect(aDrawBufRect);
       
   524     screenRect.Move(PalettePosition());
       
   525     return screenRect;
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CActivePalette2BasicUI::ScreenRectToDrawBufRect()
       
   530 // -----------------------------------------------------------------------------
       
   531 //
       
   532 TRect CActivePalette2BasicUI::ScreenRectToDrawBufRect(TRect aScreenRect) const
       
   533     {
       
   534     TRect bufRect(aScreenRect);
       
   535     bufRect.Move(-PalettePosition());
       
   536     return bufRect;
       
   537     }
       
   538 
       
   539 // -----------------------------------------------------------------------------
       
   540 // CActivePalette2BasicUI::SetContainerWindowL()
       
   541 // -----------------------------------------------------------------------------
       
   542 //
       
   543 void CActivePalette2BasicUI::SetContainerWindowL(const CCoeControl& aContainer)
       
   544     {
       
   545     CCoeControl::SetContainerWindowL(aContainer);
       
   546     
       
   547     if(iTooltipNote)
       
   548         {
       
   549         iTooltipNote->SetContainerWindowL(aContainer);
       
   550         }
       
   551 
       
   552     }
       
   553 
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // CActivePalette2BasicUI::CountComponentControls()
       
   557 // -----------------------------------------------------------------------------
       
   558 //
       
   559 TInt CActivePalette2BasicUI::CountComponentControls() const
       
   560     {
       
   561     return 1;
       
   562     }
       
   563 
       
   564 
       
   565 // -----------------------------------------------------------------------------
       
   566 // CActivePalette2BasicUI::ComponentControl()
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 CCoeControl* CActivePalette2BasicUI::ComponentControl(TInt aIndex) const
       
   570     {
       
   571     switch ( aIndex )
       
   572         {
       
   573         case 0:
       
   574             return iTooltipNote;
       
   575         default:
       
   576             return NULL;
       
   577         }
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // CActivePalette2BasicUI::TooltipUpdated()
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 TInt CActivePalette2BasicUI::TooltipUpdated()
       
   585     {
       
   586     return iTooltipNote->TooltipUpdated();
       
   587     }
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // CActivePalette2BasicUI::TooltipAnimated()
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 void CActivePalette2BasicUI::TooltipAnimated()
       
   594     {
       
   595     iTooltipNote->TooltipAnimated();
       
   596 
       
   597     if ( iRenderGc && iAPObserver )
       
   598         {
       
   599         iAPObserver->ActivePaletteUpdated();
       
   600         }
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CActivePalette2BasicUI::ShowTooltipUpdated()
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 void CActivePalette2BasicUI::ShowTooltipUpdated()
       
   608     {
       
   609     TooltipAnimated();
       
   610     }
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CActivePalette2BasicUI::ItemsUpdated()
       
   614 // -----------------------------------------------------------------------------
       
   615 //
       
   616 void CActivePalette2BasicUI::ItemsUpdated()
       
   617     {
       
   618 	TRAP_IGNORE(ReCalcAutoSizeL());
       
   619 	
       
   620     RedrawIdle(ETrue);
       
   621     }
       
   622 
       
   623 // -----------------------------------------------------------------------------
       
   624 // CActivePalette2BasicUI::ItemAnimated()
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 void CActivePalette2BasicUI::ItemAnimated(TInt aScreenPos, CActivePalette2Item* aItem, TInt aAnimFrame)
       
   628     {
       
   629 	// animation frame
       
   630 	TBool ownershipTransferForFrame;
       
   631 	TBool ownershipTransferForMask;
       
   632 	CFbsBitmap* frame = NULL;
       
   633 	CFbsBitmap* frameMask = NULL;
       
   634 
       
   635 	aItem->Plugin().ProduceAniFrame(
       
   636 		CActivePalettePluginBase::EAniFocused,
       
   637 		aAnimFrame,
       
   638 		iModel->ItemAnimInfo(),
       
   639 		aItem->Icon(),
       
   640 		aItem->Mask(),
       
   641 		&frame,
       
   642 		&frameMask,
       
   643 		ownershipTransferForFrame,
       
   644 		ownershipTransferForMask);
       
   645 
       
   646     iStyler->AnimItem(aScreenPos, frame, frameMask);
       
   647 
       
   648 	// release resources
       
   649 	if (ownershipTransferForFrame)
       
   650 	    {
       
   651 		delete frame;
       
   652 	    }
       
   653 	if (ownershipTransferForMask)
       
   654 	    {
       
   655 		delete frameMask;
       
   656 	    }
       
   657 
       
   658 	// flush
       
   659 	FlushDirtyRect();
       
   660     }
       
   661 
       
   662 // -----------------------------------------------------------------------------
       
   663 // CActivePalette2BasicUI::ItemAnimationComplete()
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 void CActivePalette2BasicUI::ItemAnimationComplete(TInt aScreenPos, CActivePalette2Item* aItem)
       
   667     {
       
   668 	aItem->Plugin().ReleaseAniFrames(CActivePalettePluginBase::EAniFocused);
       
   669 	DrawItem(aScreenPos, ETrue);
       
   670 	FlushDirtyRect();
       
   671     }
       
   672 
       
   673 // -----------------------------------------------------------------------------
       
   674 // CActivePalette2BasicUI::FocusUpdated()
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 void CActivePalette2BasicUI::FocusUpdated()
       
   678     {
       
   679     TInt focusedItem = iModel->FocusedItem();
       
   680 
       
   681     DrawItemRange(iFocusedItem1, iFocusedItem2);
       
   682     iFocusedItem1 = focusedItem;
       
   683     iFocusedItem2 = focusedItem;
       
   684 
       
   685     DrawItemRange(focusedItem, focusedItem);
       
   686     iStyler->DrawFocusRing(focusedItem, iModel->FocusCurrentOffset(), iModel->FocusCurrentTotalOffsetFrames());
       
   687     FlushDirtyRect();
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CActivePalette2BasicUI::FocusAnimated()
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 void CActivePalette2BasicUI::FocusAnimated()
       
   695     {
       
   696     TInt focusedItem = iModel->FocusedItem();
       
   697 
       
   698     if ( focusedItem != iFocusedItem1 || (focusedItem + 1) != iFocusedItem2)
       
   699         {
       
   700         DrawItemRange(iFocusedItem1, iFocusedItem2);
       
   701         iFocusedItem1 = focusedItem;
       
   702         iFocusedItem2 = focusedItem + 1;
       
   703         }
       
   704 
       
   705     DrawItemRange(iFocusedItem1, iFocusedItem2);
       
   706         
       
   707     iStyler->DrawFocusRing(iFocusedItem1, iModel->FocusCurrentOffset(), iModel->FocusCurrentTotalOffsetFrames());
       
   708     FlushDirtyRect();
       
   709     }
       
   710 
       
   711 // -----------------------------------------------------------------------------
       
   712 // CActivePalette2BasicUI::PaletteAppearingAnimated()
       
   713 // -----------------------------------------------------------------------------
       
   714 //
       
   715 void CActivePalette2BasicUI::PaletteAppearingAnimated()
       
   716     {
       
   717     PaletteAppearingUpdated();
       
   718     }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CActivePalette2BasicUI::PaletteAppearingUpdated()
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 void CActivePalette2BasicUI::PaletteAppearingUpdated()
       
   725     {
       
   726     TRect newRect(PalettePosition(), Rect().Size());
       
   727     
       
   728     if ( !iRenderGc )
       
   729         {
       
   730         Window().Invalidate(Rect());
       
   731         Window().Invalidate(newRect);  
       
   732         }
       
   733     SetRect(newRect);            
       
   734     RedrawIdle(ETrue);
       
   735     
       
   736     if ( iRenderGc )
       
   737         {
       
   738         TRect totalRect(Rect());
       
   739         totalRect.BoundingRect(newRect);
       
   740         ProducePaletteToScreen(totalRect);
       
   741         }
       
   742     }
       
   743 
       
   744 // -----------------------------------------------------------------------------
       
   745 // CActivePalette2BasicUI::SetPaletteVisibility()
       
   746 // -----------------------------------------------------------------------------
       
   747 //
       
   748 TInt CActivePalette2BasicUI::SetPaletteVisibility(TBool aVisible, TBool aAnimated, TInt aDelayedStartMilliseconds)
       
   749     {
       
   750     return iModel->SetPaletteVisibility(aVisible, aAnimated, aDelayedStartMilliseconds);
       
   751     }
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 // CActivePalette2BasicUI::PalettePosition()
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 TPoint CActivePalette2BasicUI::PalettePosition() const
       
   758     {
       
   759     TInt totalFrames = iModel->PaletteAppearingTotalFrames();
       
   760     TInt xOffset = ((iScreenSize.iWidth - iTopLeftCorner.iX) * (totalFrames - iModel->PaletteAppearingCurrentFrame())) / totalFrames;
       
   761     
       
   762     return TPoint(iTopLeftCorner.iX + xOffset, iTopLeftCorner.iY);
       
   763     }
       
   764     
       
   765 // -----------------------------------------------------------------------------
       
   766 // CActivePalette2BasicUI::APObserver()
       
   767 // -----------------------------------------------------------------------------
       
   768 //
       
   769 MActivePalette2Observer* CActivePalette2BasicUI::APObserver() const
       
   770     {
       
   771     return iAPObserver;
       
   772     }
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 // CActivePalette2BasicUI::SetItemVisibility()
       
   776 // -----------------------------------------------------------------------------
       
   777 //
       
   778 TInt CActivePalette2BasicUI::SetItemVisibility(const TInt aItemId, const TBool aIsVisible)
       
   779     {
       
   780     return iModel->SetItemVisibility(aItemId, aIsVisible);
       
   781     }
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 // CActivePalette2BasicUI::GetItemVisibility()
       
   785 // -----------------------------------------------------------------------------
       
   786 //
       
   787 TInt CActivePalette2BasicUI::GetItemVisibility(const TInt aItemId, TBool &aIsVisible) const
       
   788     {
       
   789     return iModel->GetItemVisibility(aItemId, aIsVisible);
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CActivePalette2BasicUI::SetGc()
       
   794 // -----------------------------------------------------------------------------
       
   795 //
       
   796 void CActivePalette2BasicUI::SetGc(CBitmapContext* aGc)
       
   797     {
       
   798     iRenderGc = aGc;
       
   799     iTooltipNote->SetGc(aGc);
       
   800     iRenderedRect = TRect(0,0,0,0);
       
   801     MakeVisible(!aGc);
       
   802     }
       
   803 
       
   804 // -----------------------------------------------------------------------------
       
   805 // CActivePalette2BasicUI::GetAvailablePlugins()
       
   806 // -----------------------------------------------------------------------------
       
   807 //
       
   808 TInt CActivePalette2BasicUI::GetAvailablePlugins(RArray<TUid>& aPluginList) const
       
   809     {
       
   810     return iModel->GetAvailablePlugins(aPluginList);
       
   811     }
       
   812 
       
   813 // -----------------------------------------------------------------------------
       
   814 // CActivePalette2BasicUI::RenderActivePalette()
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 void CActivePalette2BasicUI::RenderActivePalette(const TRect& aRect) const
       
   818     {
       
   819         ProducePaletteToScreen(aRect);
       
   820 
       
   821     	if ( iModel->ShowTooltip() )
       
   822         	{
       
   823         	iTooltipNote->ProduceTooltipToScreen(EFalse);
       
   824         	}
       
   825     }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // CActivePalette2BasicUI::SetPaletteVisibilityAnimationDuration()
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 TInt CActivePalette2BasicUI::SetPaletteVisibilityAnimationDuration(TInt aTimeInMilliSeconds)
       
   832     {
       
   833     return iModel->SetPaletteVisibilityAnimationDuration(aTimeInMilliSeconds);
       
   834     }
       
   835 
       
   836 // -----------------------------------------------------------------------------
       
   837 // CActivePalette2BasicUI::GetItemList()
       
   838 // -----------------------------------------------------------------------------
       
   839 //
       
   840 TInt CActivePalette2BasicUI::GetItemList(RArray<TActivePalette2ItemVisible>& aItemVisibleList) const
       
   841     {
       
   842     return iModel->GetItemList(aItemVisibleList);
       
   843     }
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CActivePalette2BasicUI::SetItemList()
       
   847 // -----------------------------------------------------------------------------
       
   848 //
       
   849 TInt CActivePalette2BasicUI::SetItemList(const RArray<TActivePalette2ItemVisible>& aItemVisibleList)
       
   850     {
       
   851     return iModel->SetItemList(aItemVisibleList);
       
   852     }
       
   853 
       
   854 // -----------------------------------------------------------------------------
       
   855 // CActivePalette2BasicUI::CoeControl()
       
   856 // -----------------------------------------------------------------------------
       
   857 //
       
   858 CCoeControl* CActivePalette2BasicUI::CoeControl() 
       
   859     { 
       
   860     return this; 
       
   861     }
       
   862 
       
   863 // -----------------------------------------------------------------------------
       
   864 // CActivePalette2BasicUI::HuiControl()
       
   865 // -----------------------------------------------------------------------------
       
   866 //
       
   867 CHuiControl* CActivePalette2BasicUI::HuiControl() 
       
   868     { 
       
   869     return NULL; 
       
   870     }
       
   871 
       
   872 // -----------------------------------------------------------------------------
       
   873 // CActivePalette2BasicUI::GetPaletteVisibilityAnimationDuration()
       
   874 // -----------------------------------------------------------------------------
       
   875 //
       
   876 TInt CActivePalette2BasicUI::GetPaletteVisibilityAnimationDuration(TInt& aTimeInMilliseconds) const
       
   877     {
       
   878     return iModel->GetPaletteVisibilityAnimationDuration(aTimeInMilliseconds);
       
   879     }
       
   880 
       
   881 // -----------------------------------------------------------------------------
       
   882 // CActivePalette2BasicUI::ItemsScrolled()
       
   883 // -----------------------------------------------------------------------------
       
   884 //
       
   885 void CActivePalette2BasicUI::ItemsScrolled()
       
   886     {
       
   887     RedrawIdle(ETrue);
       
   888     }
       
   889 
       
   890 // -----------------------------------------------------------------------------
       
   891 // CActivePalette2BasicUI::DrawItemRange()
       
   892 // -----------------------------------------------------------------------------
       
   893 //
       
   894 void CActivePalette2BasicUI::DrawItemRange(TInt aStartIndex, TInt aFinishIndex) const
       
   895     {
       
   896     aStartIndex = Max(aStartIndex, 0);
       
   897     aFinishIndex = Min(aFinishIndex, iModel->CountItemsOnScreen());
       
   898 
       
   899     if ( aFinishIndex >= aStartIndex )
       
   900         {
       
   901         TInt index;
       
   902         for ( index = aStartIndex - 1; index <= aFinishIndex; index++)
       
   903             {
       
   904             DrawSeparator(index);
       
   905             }
       
   906 
       
   907         for ( index = aStartIndex; index <= aFinishIndex; index++)
       
   908             {
       
   909             DrawItem(index);
       
   910             }
       
   911         }
       
   912     }
       
   913 
       
   914 // -----------------------------------------------------------------------------
       
   915 // CActivePalette2BasicUI::DrawItem()
       
   916 // -----------------------------------------------------------------------------
       
   917 //
       
   918 void CActivePalette2BasicUI::DrawItem(TInt aIndex, TBool aAnimOnly) const
       
   919     {
       
   920 	CActivePalette2Item* item = iModel->ItemFromScreenPos(aIndex);
       
   921 	
       
   922 	if ( item )
       
   923 	    {
       
   924 	    if ( aAnimOnly )
       
   925 	        {
       
   926             iStyler->AnimItem(aIndex, &item->Icon(), item->Mask());
       
   927 	        }
       
   928 	    else
       
   929 	        {
       
   930             iStyler->DrawItem(aIndex, &item->Icon(), item->Mask(), iModel->ItemScrollOffset(), iModel->ItemScrollTotalFrames());
       
   931             }
       
   932         }
       
   933     }
       
   934     
       
   935 // -----------------------------------------------------------------------------
       
   936 // CActivePalette2BasicUI::DrawSeparator()
       
   937 // -----------------------------------------------------------------------------
       
   938 //
       
   939 void CActivePalette2BasicUI::DrawSeparator(TInt aIndex) const
       
   940     {
       
   941     if ( aIndex < 0 )
       
   942         {
       
   943         iStyler->DrawTopScrollArrowSection(iModel->ShowTopScrollIndicator());
       
   944         }
       
   945     else if (aIndex >= (iModel->CountItemsOnScreen()-1))
       
   946         {
       
   947         iStyler->DrawBottomScrollArrowSection(iModel->ShowBottomScrollIndicator());
       
   948         }
       
   949     else
       
   950         {
       
   951         iStyler->DrawGap(aIndex, iModel->ItemScrollOffset(), iModel->ItemScrollTotalFrames());
       
   952         }
       
   953     }
       
   954     
       
   955 // -----------------------------------------------------------------------------
       
   956 // CActivePalette2BasicUI::FlushDirtyRect()
       
   957 // -----------------------------------------------------------------------------
       
   958 //
       
   959 void CActivePalette2BasicUI::FlushDirtyRect()
       
   960     {
       
   961 	FlushBufNow(DrawBufRectToScreenRect(iStyler->DirtyRect()));
       
   962 	iStyler->ClearDirtyRect();
       
   963 
       
   964     if ( iRenderGc && iAPObserver)
       
   965         {
       
   966         iAPObserver->ActivePaletteUpdated();
       
   967         }
       
   968     }
       
   969     
       
   970 // -----------------------------------------------------------------------------
       
   971 // CActivePalette2BasicUI::HandleResourceChange()
       
   972 // -----------------------------------------------------------------------------
       
   973 //   
       
   974 void CActivePalette2BasicUI::HandleResourceChange( TInt aType )
       
   975 	{
       
   976 	if ( KEikDynamicLayoutVariantSwitch == aType )
       
   977         {
       
   978         // UI sizes and dimensions
       
   979 		AknLayoutUtils::LayoutMetricsSize( AknLayoutUtils::EScreen, iScreenSize );
       
   980 		
       
   981 		TRAP_IGNORE( ReCalcAutoSizeL() );
       
   982 		
       
   983 		// enter idle
       
   984 		RedrawIdle(EFalse);
       
   985         }
       
   986         
       
   987     CCoeControl::HandleResourceChange( aType );
       
   988 
       
   989 	}
       
   990 // End of File