uifw/EikStd/coctlsrc/AknDoubleSpanScrollIndicator.cpp
changeset 0 2f259fa3e83a
child 3 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Indicator for double span scroll bar.
       
    15 *    
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "AknDoubleSpanScrollIndicator.h"
       
    21 #include "AknDoubleSpanScrollIndicatorItem.h"
       
    22 #include <aknconsts.h>
       
    23 #include <avkon.mbg>
       
    24 #include <AknUtils.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 #include <aknlayoutscalable_avkon.cdl.h>
       
    27 #include <aknappui.h>
       
    28 #include <AknDef.h>
       
    29 #include <AknPriv.hrh>
       
    30 #include <AknTasHook.h>
       
    31 #include <AknsDrawUtils.h>
       
    32 // Do not use these constants directly, use implemented private methods instead.
       
    33 // const TInt KScrollBackgroundMinVisibleSizeInPixels = 4; // minimum distance handle and scb bottom. 
       
    34 //const TInt KHandleBackgroundMinSizeInPixels = 24; // double spanned non focused handle minimum size
       
    35 //const TInt KHandleMinSizeInPixels = 12; // focused handle minimum size
       
    36 const TInt KPrecision = 8; // Used in pixel effect calculations
       
    37 
       
    38 CAknDoubleSpanScrollIndicator* CAknDoubleSpanScrollIndicator::NewL(CEikScrollBar::TOrientation aOrientation)
       
    39     {
       
    40     CAknDoubleSpanScrollIndicator* self = new (ELeave) CAknDoubleSpanScrollIndicator();
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL(aOrientation);
       
    43     CleanupStack::Pop();
       
    44     return self;
       
    45     }
       
    46 
       
    47 CAknDoubleSpanScrollIndicator::CAknDoubleSpanScrollIndicator() 
       
    48 : iOwnsWindow(EFalse), iTransparentBackground(EFalse), iDrawBackground(ETrue), 
       
    49     iBackgroundHighlight(EFalse),iDrawBackgroundBitmap(EFalse)
       
    50     {
       
    51     AKNTASHOOK_ADD( this, "CAknDoubleSpanScrollIndicator" );
       
    52     }
       
    53 
       
    54 CAknDoubleSpanScrollIndicator::~CAknDoubleSpanScrollIndicator()
       
    55     {
       
    56     AKNTASHOOK_REMOVE();
       
    57     AknsUtils::DeregisterControlPosition( this );
       
    58     
       
    59     delete iBackgroundBar;
       
    60     delete iHighlightBackgroundBar;
       
    61     delete iHandleBar;
       
    62     delete iHighlightHandleBar;
       
    63     
       
    64  
       
    65     }
       
    66 
       
    67 void CAknDoubleSpanScrollIndicator::ConstructL(CEikScrollBar::TOrientation aOrientation)
       
    68     {
       
    69     iOrientation = aOrientation;
       
    70     CreateScrollBarItemsL();
       
    71     UpdateScrollBarLayout();
       
    72     }
       
    73 
       
    74 void CAknDoubleSpanScrollIndicator::Draw(const TRect& /*aRect*/) const
       
    75     {
       
    76     CWindowGc& gc = SystemGc();
       
    77 
       
    78     if(iDrawBackground)
       
    79         {
       
    80         DrawBackground();
       
    81         }
       
    82     
       
    83     CAknDoubleSpanScrollIndicatorItem* handleBackgroundBar = 
       
    84         iBackgroundHighlight && iHighlightBackgroundBar ?
       
    85             iHighlightBackgroundBar : iBackgroundBar;
       
    86     
       
    87     DrawTiled(gc, iBackgroundRect, handleBackgroundBar);
       
    88 
       
    89     TBool showHandleBarBackground = iFieldPosition >= 0 && iFieldSize > 0; 
       
    90     if(showHandleBarBackground)
       
    91         {
       
    92         DrawTiled(gc, iHandleBackgroundRect, iHighlightBackgroundBar);
       
    93         }
       
    94 
       
    95     CAknDoubleSpanScrollIndicatorItem* handleBar = 
       
    96         iHandleHighlight && iHighlightHandleBar ?
       
    97         iHighlightHandleBar : iHandleBar;
       
    98 
       
    99     DrawTiled(gc, iHandleRect, handleBar);
       
   100     }
       
   101 void CAknDoubleSpanScrollIndicator::UpdateScrollBarLayout()
       
   102     {
       
   103     iHeadItemSize = 12;
       
   104     iMidItemSize = 12 * 5;
       
   105     iTailItemSize = 12;
       
   106     
       
   107     TRect rect = Rect();
       
   108     if(rect.IsEmpty())
       
   109         {        
       
   110         return;
       
   111         }
       
   112     
       
   113     TInt varietyIndex ( 0 );
       
   114     if ( iOrientation == CEikScrollBar::EHorizontal )
       
   115         {
       
   116         varietyIndex = 1;
       
   117         }
       
   118 
       
   119     TAknLayoutRect layRect;
       
   120     TAknWindowComponentLayout layout = AknLayoutScalable_Avkon::scroll_bg_pane_g1( varietyIndex ); //top
       
   121     layRect.LayoutRect( rect, layout.LayoutLine() );    
       
   122     TSize newSize = layRect.Rect().Size();  
       
   123     iHeadItemSize = (iOrientation == CEikScrollBar::EVertical?newSize.iHeight:newSize.iWidth);
       
   124     
       
   125     layout = AknLayoutScalable_Avkon::scroll_bg_pane_g3(varietyIndex); // bottom
       
   126     layRect.LayoutRect(rect, layout.LayoutLine());
       
   127     newSize = layRect.Rect().Size();
       
   128     iTailItemSize =  (iOrientation == CEikScrollBar::EVertical?newSize.iHeight:newSize.iWidth);
       
   129         
       
   130     layout = AknLayoutScalable_Avkon::scroll_bg_pane_g2(varietyIndex); //middle
       
   131     layRect.LayoutRect(rect, layout.LayoutLine());
       
   132     newSize = layRect.Rect().Size();    
       
   133  //   iMidItemSize = (iOrientation == CEikScrollBar::EVertical?newSize.iHeight:newSize.iWidth) * 5;
       
   134     }
       
   135 
       
   136 void CAknDoubleSpanScrollIndicator::DrawTiled(
       
   137         CWindowGc& aGc, const TRect& aRect, 
       
   138         CAknDoubleSpanScrollIndicatorItem *aIndicatorItem) const
       
   139     {
       
   140     if (aRect.IsEmpty())
       
   141         return;
       
   142 
       
   143     TRect headRect = aRect;
       
   144     TRect tailRect = aRect;
       
   145     TRect midRect = aRect;
       
   146     TInt midDrawLength;
       
   147     TSize midSize;
       
   148     if (iOrientation == CEikScrollBar::EVertical)
       
   149         {
       
   150         if ((iHeadItemSize + iTailItemSize) <= aRect.Height())
       
   151             {
       
   152             headRect.SetHeight(iHeadItemSize);
       
   153             tailRect.iTl.iY = tailRect.iBr.iY - iTailItemSize;
       
   154             }
       
   155         else
       
   156             {
       
   157             headRect.SetHeight((aRect.Height() >> 1));
       
   158             tailRect.iTl.iY = tailRect.iBr.iY - headRect.Height();
       
   159             }
       
   160         midRect.iTl.iY += headRect.Height();
       
   161         midRect.iBr.iY -= tailRect.Height();
       
   162         midDrawLength = midRect.Height();
       
   163         midSize.SetSize(midRect.Width(), iMidItemSize);
       
   164         }
       
   165     else
       
   166         {
       
   167         headRect.SetWidth( iHeadItemSize );
       
   168         tailRect.iTl.iX = tailRect.iBr.iX - iTailItemSize;
       
   169 
       
   170         midRect.iTl.iX += iHeadItemSize;
       
   171         midRect.iBr.iX -= iTailItemSize;
       
   172         midDrawLength = midRect.Width();
       
   173         midSize.SetSize(iMidItemSize, midRect.Height());
       
   174         }
       
   175    
       
   176     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   177 
       
   178     CFbsBitmap *bmp = NULL; 
       
   179     CFbsBitmap *mask = NULL;
       
   180     AknsUtils::GetCachedMaskedBitmap(skin, aIndicatorItem->iTopId, bmp, mask);
       
   181     AknIconUtils::SetSize(bmp, headRect.Size(), EAspectRatioNotPreserved);
       
   182     AknIconUtils::SetSize(mask, headRect.Size(), EAspectRatioNotPreserved);
       
   183     aGc.BitBltMasked(headRect.iTl, bmp, TRect(TPoint(0, 0), headRect.Size()), mask, ETrue);
       
   184     
       
   185     AknsUtils::GetCachedMaskedBitmap(skin, aIndicatorItem->iMidId, bmp, mask);
       
   186     AknIconUtils::SetSize(bmp, midSize, EAspectRatioNotPreserved);
       
   187     AknIconUtils::SetSize(mask, midSize, EAspectRatioNotPreserved);
       
   188 
       
   189     TInt count = midDrawLength / iMidItemSize;
       
   190     TPoint destPos(midRect.iTl.iX, midRect.iTl.iY);
       
   191     TRect sourRect(TPoint(0, 0), bmp->SizeInPixels());
       
   192     for(TInt i = 0; i < count; i++)
       
   193         {
       
   194         aGc.BitBltMasked(destPos, bmp, sourRect, mask, ETrue);
       
   195         iOrientation == CEikScrollBar::EVertical?destPos.iY += iMidItemSize : destPos.iX += iMidItemSize;
       
   196         }
       
   197     iOrientation == CEikScrollBar::EVertical?sourRect.iBr.iY = midRect.Height() % iMidItemSize
       
   198                     :sourRect.iBr.iX = midRect.Width() % iMidItemSize;
       
   199     aGc.BitBltMasked(destPos, bmp, sourRect, mask, ETrue);
       
   200 
       
   201     AknsUtils::GetCachedMaskedBitmap(skin, aIndicatorItem->iBottomId, bmp, mask);
       
   202     AknIconUtils::SetSize(bmp, tailRect.Size(), EAspectRatioNotPreserved);
       
   203     AknIconUtils::SetSize(mask, tailRect.Size(), EAspectRatioNotPreserved);
       
   204     aGc.BitBltMasked(tailRect.iTl, bmp, TRect(TPoint(0, 0), tailRect.Size()), mask, ETrue);
       
   205     }
       
   206 
       
   207 void CAknDoubleSpanScrollIndicator::CalculateRects()
       
   208     {
       
   209     iBackgroundRect = Rect();
       
   210     
       
   211     // 
       
   212     // sanity checks for values used in drawing   
       
   213     //
       
   214     TInt checkedScrollSpan    = iScrollSpan; // all items
       
   215     TInt checkedFocusPosition = iFocusPosition; // current item
       
   216     TInt checkedWindowSize    = iWindowSize; // number of visible items
       
   217     TInt checkedFieldPosition = iFieldPosition; // position in sub list
       
   218     TInt checkedFieldSize     = iFieldSize; // number of visible items in sub list
       
   219        
       
   220     CheckValues(checkedScrollSpan, 
       
   221         checkedFocusPosition, 
       
   222         checkedWindowSize, 
       
   223         checkedFieldPosition, 
       
   224         checkedFieldSize);
       
   225     
       
   226     // If span (max number of items) is zero, then draw only the background
       
   227     if (checkedScrollSpan == 0)
       
   228         {
       
   229         iHandleBackgroundRect = TRect(0,0,0,0);
       
   230         iHandleRect = TRect(0,0,0,0);
       
   231         return;
       
   232         }
       
   233 
       
   234     // 
       
   235     // Transform values into pixels and rects.
       
   236     //
       
   237     TInt scrollBarHeightInPixels( 0 );
       
   238     
       
   239     if ( iOrientation == CEikScrollBar::EHorizontal )
       
   240         {
       
   241         scrollBarHeightInPixels = iBackgroundRect.Width();
       
   242         }
       
   243     else
       
   244         {
       
   245         scrollBarHeightInPixels = iBackgroundRect.Height();
       
   246         }
       
   247     
       
   248     // The code block below was probably used to prevent
       
   249     // a truncation-vs-rounding error from happening
       
   250     /*
       
   251     if ((checkedWindowSize > 0) && (checkedScrollSpan > 0))
       
   252         {
       
   253         if((checkedFocusPosition + checkedWindowSize) == checkedScrollSpan)
       
   254             windowSizeInPixels = scrollBarHeightInPixels - focusPositionInPixels;
       
   255         else
       
   256             windowSizeInPixels = scrollBarHeightInPixels*checkedWindowSize/checkedScrollSpan;
       
   257         }
       
   258     */
       
   259     
       
   260     TInt windowSizeInPixels = 
       
   261         Max( checkedWindowSize * scrollBarHeightInPixels / checkedScrollSpan,
       
   262              HandleBackgroundMinSizeInPixels() );
       
   263     
       
   264     TInt roomForMovementInSpan   = checkedScrollSpan - checkedWindowSize;
       
   265     TInt roomForMovementInPixels = 
       
   266         scrollBarHeightInPixels - windowSizeInPixels;    
       
   267     
       
   268     TInt focusPositionInPixels( 0 );
       
   269         
       
   270     if ( roomForMovementInSpan > 0 && roomForMovementInPixels > 0 )
       
   271         {
       
   272         focusPositionInPixels =
       
   273             checkedFocusPosition * roomForMovementInPixels /
       
   274             roomForMovementInSpan;
       
   275         }
       
   276 
       
   277     // If window would cover whole scrollbar, then modify 
       
   278     // it to leave the thumb little short from bottom
       
   279     TInt scrollBarHandleMaxSizeInPixels =  ScrollHandleMaxVisibleSizeInPixels();
       
   280     if (windowSizeInPixels >= scrollBarHeightInPixels)
       
   281         {
       
   282         windowSizeInPixels = scrollBarHandleMaxSizeInPixels;    
       
   283         }
       
   284 
       
   285     TBool doubleSpanInUse = (checkedFieldPosition >= 0) && (checkedFieldSize > 0);
       
   286     TInt minHandleBackgroundSize = 0;
       
   287     TInt fieldSizeInPixels = 0; // sub field size
       
   288     TInt fieldPositionInPixels = 0;
       
   289     if (doubleSpanInUse)
       
   290         {
       
   291         fieldSizeInPixels = windowSizeInPixels/checkedFieldSize;
       
   292         fieldPositionInPixels = windowSizeInPixels*checkedFieldPosition/checkedFieldSize;
       
   293         minHandleBackgroundSize = HandleBackgroundMinSizeInPixels();
       
   294         }
       
   295     else
       
   296         {
       
   297         minHandleBackgroundSize = HandleMinSizeInPixels();
       
   298         }
       
   299     
       
   300     TInt handleMinSize = HandleMinSizeInPixels();
       
   301     // Similar compensation for handle if double span is in use
       
   302     if (doubleSpanInUse && (fieldSizeInPixels < handleMinSize))
       
   303         {
       
   304         TInt extraPixels = 0;
       
   305         TInt extraPixelCompensationInterval = 0;
       
   306         TInt extraPixelCompensation = 0;
       
   307         extraPixels = handleMinSize - fieldSizeInPixels;
       
   308         extraPixelCompensationInterval = windowSizeInPixels/extraPixels;
       
   309         if (extraPixelCompensationInterval != 0)
       
   310             {
       
   311             extraPixelCompensation = fieldPositionInPixels/extraPixelCompensationInterval;
       
   312             if (extraPixelCompensation > handleMinSize)
       
   313                 {
       
   314                 extraPixelCompensation = handleMinSize;
       
   315                 }
       
   316             }
       
   317 
       
   318         if ((fieldPositionInPixels - extraPixelCompensation) > 0)
       
   319             {
       
   320             fieldPositionInPixels -= extraPixelCompensation;
       
   321             }
       
   322         
       
   323         // Additional compensation at the end is sometimes needed as above compensation is not
       
   324         // always accurate because the fieldPositionInPixels is not anymore in "right" place. 
       
   325         if (checkedFieldPosition < (checkedFieldSize - 1))
       
   326             {           
       
   327             if ((fieldPositionInPixels + handleMinSize) >= windowSizeInPixels - 1)
       
   328                 {
       
   329                 fieldPositionInPixels = windowSizeInPixels - (handleMinSize + 2);
       
   330                 }
       
   331             }            
       
   332         fieldSizeInPixels = handleMinSize;
       
   333         }
       
   334     
       
   335     
       
   336     // If orientation is horizontal, then rotate rects here first
       
   337     // 90 degrees. At the end of this function rotate them back again.
       
   338     if (iOrientation == CEikScrollBar::EHorizontal)
       
   339         {
       
   340         TRect original = iBackgroundRect;
       
   341         iBackgroundRect.iBr.iX = original.iTl.iX + original.Height();
       
   342         iBackgroundRect.iBr.iY = original.iTl.iY + original.Width();
       
   343         iHandleBackgroundRect = TRect(0,0,0,0);
       
   344         iHandleRect = TRect(0,0,0,0);
       
   345         }
       
   346     
       
   347     // handle background
       
   348     iHandleBackgroundRect = iBackgroundRect;
       
   349     iHandleBackgroundRect.iTl.iY += focusPositionInPixels;
       
   350     iHandleBackgroundRect.iBr.iY = iHandleBackgroundRect.iTl.iY + windowSizeInPixels; 
       
   351   
       
   352     if (iHandleBackgroundRect.iBr.iY > iBackgroundRect.iBr.iY)
       
   353         {
       
   354         iHandleBackgroundRect.iBr.iY = iBackgroundRect.iBr.iY;
       
   355         iHandleBackgroundRect.iTl.iY = iBackgroundRect.iBr.iY - windowSizeInPixels;
       
   356         }
       
   357 
       
   358     // fields
       
   359     iHandleRect= iHandleBackgroundRect;
       
   360     iHandleRect.iTl.iY += fieldPositionInPixels;
       
   361     iHandleRect.iBr.iY = iHandleRect.iTl.iY + fieldSizeInPixels;
       
   362     if (iHandleRect.iTl.iY < iHandleBackgroundRect.iTl.iY)
       
   363         {
       
   364         iHandleRect.iTl.iY = iHandleBackgroundRect.iTl.iY;
       
   365         }
       
   366 
       
   367     if (iHandleRect.iBr.iY > iHandleBackgroundRect.iBr.iY)
       
   368         {
       
   369         iHandleRect.iBr.iY = iHandleBackgroundRect.iBr.iY;
       
   370         }    
       
   371 
       
   372     // if double span is not used, set the handle to cover whole handle background area.
       
   373     if (!doubleSpanInUse)
       
   374         {
       
   375         iHandleRect.SetHeight(iHandleBackgroundRect.Height());
       
   376         }
       
   377         
       
   378     // check overflow 
       
   379     if (iHandleBackgroundRect.iBr.iY > iBackgroundRect.iBr.iY)
       
   380         {
       
   381         
       
   382         iHandleBackgroundRect.iBr.iY = iBackgroundRect.iBr.iY;
       
   383         iHandleBackgroundRect.iTl.iY = iBackgroundRect.iBr.iY - minHandleBackgroundSize;
       
   384         }
       
   385     if (iHandleBackgroundRect.iTl.iY < iBackgroundRect.iTl.iY)
       
   386         {
       
   387         iHandleBackgroundRect.iTl.iY = iBackgroundRect.iTl.iY;
       
   388         }
       
   389 
       
   390     // check overflow
       
   391     if (iHandleRect.iBr.iY > iHandleBackgroundRect.iBr.iY)
       
   392         {
       
   393         iHandleRect.iBr.iY = iHandleBackgroundRect.iBr.iY;
       
   394         iHandleRect.iTl.iY = iHandleBackgroundRect.iBr.iY - handleMinSize;
       
   395         }
       
   396     if (iHandleRect.iTl.iY < iHandleBackgroundRect.iTl.iY)
       
   397         {
       
   398         iHandleRect.iTl.iY = iHandleBackgroundRect.iTl.iY;
       
   399         }
       
   400     
       
   401     // If calculations were done to 90 degrees rotated rects, rotate those back here. 
       
   402     if (iOrientation == CEikScrollBar::EHorizontal)
       
   403         {
       
   404         TRect originalBackgroundRect = iBackgroundRect;
       
   405         iBackgroundRect.SetWidth(originalBackgroundRect.Height());
       
   406         iBackgroundRect.SetHeight(originalBackgroundRect.Width());
       
   407         
       
   408         TRect originalHandleBackgroundRect = iHandleBackgroundRect;
       
   409         iHandleBackgroundRect = iBackgroundRect;
       
   410 
       
   411         iHandleBackgroundRect.iTl.iX += originalHandleBackgroundRect.iTl.iY - originalBackgroundRect.iTl.iY;
       
   412         iHandleBackgroundRect.iBr.iX = iHandleBackgroundRect.iTl.iX + originalHandleBackgroundRect.Height();
       
   413 
       
   414         TRect originalHandleRect = iHandleRect;
       
   415         iHandleRect = iBackgroundRect;
       
   416  
       
   417         iHandleRect.iTl.iX += originalHandleRect.iTl.iY - originalBackgroundRect.iTl.iY;
       
   418         iHandleRect.iBr.iX = iHandleRect.iTl.iX + originalHandleRect.Height();
       
   419         }
       
   420     }
       
   421 
       
   422 
       
   423 void CAknDoubleSpanScrollIndicator::CheckValues(TInt& aScrollSpan, TInt& aFocusPosition, TInt& aWindowSize, TInt& aFieldPosition, TInt& aFieldSize) const
       
   424     {
       
   425     // Scrollspan
       
   426     if (aScrollSpan <= 0)
       
   427         {
       
   428         // Default values, only background will be drawn
       
   429         aScrollSpan = 0; 
       
   430         aWindowSize = 0;
       
   431         aFocusPosition = 0;
       
   432         aFieldSize = 0;
       
   433         aFieldPosition = 0;
       
   434         return;
       
   435         }
       
   436 
       
   437     // Window size
       
   438     if (aWindowSize < 1)
       
   439         {
       
   440         aWindowSize = 1;
       
   441         }
       
   442     if (aWindowSize > aScrollSpan)
       
   443         {
       
   444         aWindowSize = aScrollSpan;
       
   445         }
       
   446 
       
   447     // FocusPosition
       
   448     if (aFocusPosition < 0)
       
   449         {
       
   450         aFocusPosition = 0;
       
   451         }
       
   452     if (aFocusPosition + aWindowSize > aScrollSpan)
       
   453         {
       
   454         aFocusPosition = aScrollSpan - aWindowSize;
       
   455         }
       
   456 
       
   457     // Field size & position
       
   458     if (aFieldSize <= 0)
       
   459         {
       
   460         aFieldSize = 0;
       
   461         aFieldPosition = 0;
       
   462         }
       
   463     else
       
   464         {
       
   465         // Field position
       
   466         if (aFieldPosition < 0)
       
   467             {
       
   468             aFieldPosition = 0;
       
   469             }
       
   470         if (aFieldPosition > aFieldSize - 1)
       
   471             {
       
   472             aFieldPosition = aFieldSize - 1;
       
   473             }
       
   474 
       
   475         }
       
   476     }
       
   477 
       
   478 
       
   479 void CAknDoubleSpanScrollIndicator::SizeChanged()
       
   480     {
       
   481     TRect rect( Rect() );
       
   482     if(iOldRect != rect)
       
   483         {
       
   484         iOldRect = rect;        
       
   485         AknsUtils::RegisterControlPosition( this );
       
   486         CalculateRects();
       
   487 
       
   488         if (iOwnsWindow)
       
   489             {
       
   490             TRAP_IGNORE(CreateBackgroundBitmapL());
       
   491             }
       
   492         
       
   493         UpdateScrollBarLayout();
       
   494         
       
   495         if (IsVisible() & iOwnsWindow)
       
   496             DrawDeferred();
       
   497         }
       
   498     }
       
   499 
       
   500 void CAknDoubleSpanScrollIndicator::SetIndicatorValues(TInt aScrollSpan, TInt aFocusPosition, TInt aWindowSize, TInt aFieldPosition, TInt aFieldSize)
       
   501     {
       
   502     // if nothing changed
       
   503     if((iScrollSpan == aScrollSpan) &&
       
   504     (iFocusPosition == aFocusPosition) &&
       
   505     (iWindowSize == aWindowSize) &&
       
   506     (iFieldPosition == aFieldPosition) &&
       
   507     (iFieldSize == aFieldSize))
       
   508         return;
       
   509     
       
   510     iScrollSpan = aScrollSpan;
       
   511     iFocusPosition = aFocusPosition;
       
   512     iWindowSize = aWindowSize;
       
   513     iFieldPosition = aFieldPosition;
       
   514     iFieldSize = aFieldSize;
       
   515     
       
   516     // Calculate the sizes for graphics
       
   517     CalculateRects();            
       
   518     if( iWindowSize > 0 )
       
   519         {   
       
   520         // layout handle graphics
       
   521         LayoutHandleGraphics();
       
   522         }
       
   523     }
       
   524 
       
   525 TInt CAknDoubleSpanScrollIndicator::ScrollSpan()
       
   526     {
       
   527     return iScrollSpan;
       
   528     }
       
   529 
       
   530 TInt CAknDoubleSpanScrollIndicator::FocusPosition()
       
   531     {
       
   532     return iFocusPosition;
       
   533     }
       
   534 
       
   535 TInt CAknDoubleSpanScrollIndicator::WindowSize()
       
   536     {
       
   537     return iWindowSize;
       
   538     }
       
   539 
       
   540 TInt CAknDoubleSpanScrollIndicator::FieldPosition()
       
   541     {
       
   542     return iFieldPosition;
       
   543     }
       
   544 
       
   545 TInt CAknDoubleSpanScrollIndicator::FieldSize()
       
   546     {
       
   547     return iFieldSize;
       
   548     }
       
   549 
       
   550 void CAknDoubleSpanScrollIndicator::SetTransparentBackground(TBool aTransparentBackground)
       
   551     {
       
   552     iTransparentBackground = aTransparentBackground;
       
   553     }
       
   554 
       
   555 TBool CAknDoubleSpanScrollIndicator::TransparentBackground()
       
   556     {
       
   557     return iTransparentBackground;
       
   558     }
       
   559 
       
   560 void CAknDoubleSpanScrollIndicator::HandleResourceChange(TInt aType)
       
   561     {
       
   562     if ( aType == KAknsMessageSkinChange )
       
   563         {
       
   564         iDrawBackgroundBitmap = ETrue;
       
   565         }
       
   566     else if( aType == KAknMessageFocusLost || KEikMessageUnfadeWindows == aType)
       
   567         {
       
   568         if( HandleHighlight() )
       
   569             {
       
   570             SetHandleHighlight(EFalse);
       
   571             DrawDeferred();
       
   572             }
       
   573         if( BackgroudHighlight() )
       
   574             {
       
   575         	SetBackgroudHighlight( EFalse );
       
   576             }
       
   577         
       
   578         }
       
   579     
       
   580     // SizeChanged handles this. The Scb is always layouted by its parent
       
   581     // if(aType == KEikDynamicLayoutVariantSwitch)
       
   582 
       
   583         
       
   584     CCoeControl::HandleResourceChange(aType);
       
   585     }
       
   586 
       
   587 CAknDoubleSpanScrollIndicatorItem* CAknDoubleSpanScrollIndicator::LoadScrollIndicatorItemL(
       
   588         const TAknsItemID &aTopId,
       
   589         const TAknsItemID &aMidId,
       
   590         const TAknsItemID &aBottomId)
       
   591     {
       
   592     return CAknDoubleSpanScrollIndicatorItem::NewL(ETrue,
       
   593         aTopId, 0, 0,
       
   594         aMidId, 0, 0,
       
   595         aBottomId, 0, 0); 
       
   596     }
       
   597 
       
   598 
       
   599 void CAknDoubleSpanScrollIndicator::CreateScrollBarItemsL()
       
   600     {
       
   601     // create items
       
   602     if(iOrientation == CEikScrollBar::EVertical)
       
   603         {
       
   604         iBackgroundBar = LoadScrollIndicatorItemL(
       
   605                 KAknsIIDQsnCpScrollBgTop,
       
   606                 KAknsIIDQsnCpScrollBgMiddle,
       
   607                 KAknsIIDQsnCpScrollBgBottom);
       
   608         
       
   609         iHandleBar = LoadScrollIndicatorItemL(
       
   610                 KAknsIIDQsnCpScrollHandleTop,
       
   611                 KAknsIIDQsnCpScrollHandleMiddle,
       
   612                 KAknsIIDQsnCpScrollHandleBottom);
       
   613         
       
   614         
       
   615        
       
   616         if(AknLayoutUtils::PenEnabled())
       
   617             {
       
   618             iHighlightBackgroundBar = LoadScrollIndicatorItemL(
       
   619                 KAknsIIDQsnCpScrollHandleBgTop,
       
   620                 KAknsIIDQsnCpScrollHandleBgMiddle,
       
   621                 KAknsIIDQsnCpScrollHandleBgBottom);
       
   622             
       
   623             iHighlightHandleBar = LoadScrollIndicatorItemL(
       
   624                 KAknsIIDQsnCpScrollHandleTopPressed,
       
   625                 KAknsIIDQsnCpScrollHandleMiddlePressed,
       
   626                 KAknsIIDQsnCpScrollHandleBottomPressed);
       
   627             }
       
   628         }
       
   629     else
       
   630         {
       
   631         iBackgroundBar = LoadScrollIndicatorItemL(
       
   632                 KAknsIIDQsnCpScrollHorizontalBgTop,
       
   633                 KAknsIIDQsnCpScrollHorizontalBgMiddle,
       
   634                 KAknsIIDQsnCpScrollHorizontalBgBottom);
       
   635         
       
   636         iHandleBar = LoadScrollIndicatorItemL(
       
   637                 KAknsIIDQsnCpScrollHorizontalHandleTop,
       
   638                 KAknsIIDQsnCpScrollHorizontalHandleMiddle,
       
   639                 KAknsIIDQsnCpScrollHorizontalHandleBottom);
       
   640 
       
   641         
       
   642         
       
   643         if(AknLayoutUtils::PenEnabled())
       
   644             {
       
   645             //Handle background bar image missing....
       
   646             /*
       
   647             iHandleBackgroundBar = LoadScrollIndicatorItem(
       
   648                 KAknsIIDQsnCpScrollHorizontalHandleBgTop,
       
   649                 KAknsIIDQsnCpScrollHorizontalHandleBgMiddle,
       
   650                 KAknsIIDQsnCpScrollHorizontalHandleBgBottom);
       
   651             */
       
   652             
       
   653             iHighlightHandleBar = LoadScrollIndicatorItemL(
       
   654                 KAknsIIDQsnCpScrollHorizontalHandleTopPressed,
       
   655                 KAknsIIDQsnCpScrollHorizontalHandleMiddlePressed,
       
   656                 KAknsIIDQsnCpScrollHorizontalHandleBottomPressed);
       
   657             }
       
   658         }    
       
   659     }
       
   660 
       
   661 TInt CAknDoubleSpanScrollIndicator::IndicatorWidth()
       
   662     {
       
   663     TAknWindowComponentLayout layout;
       
   664     
       
   665     if(iOrientation == CEikScrollBar::EHorizontal)
       
   666         layout = AknLayoutScalable_Avkon::scroll_pane(1);
       
   667     else
       
   668         layout = AknLayoutScalable_Avkon::scroll_pane(0);
       
   669     
       
   670     TAknLayoutRect layRect;
       
   671     TRect mainpaneRect;
       
   672     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainpaneRect );
       
   673     layRect.LayoutRect(mainpaneRect, layout.LayoutLine());
       
   674     
       
   675     if(iOrientation == CEikScrollBar::EHorizontal)
       
   676         return layRect.Rect().Height();
       
   677     else
       
   678         return layRect.Rect().Width();
       
   679     }
       
   680 
       
   681 TInt CAknDoubleSpanScrollIndicator::ScrollHandleMaxVisibleSizeInPixels()
       
   682     {
       
   683     TRect scbRect = Rect();
       
   684     if ( iOrientation == CEikScrollBar::EHorizontal )
       
   685         scbRect.SetRect(scbRect.iTl, TSize(scbRect.Height(), scbRect.Width()));
       
   686     
       
   687     TAknLayoutRect layRect;
       
   688     TAknWindowComponentLayout layout = AknLayoutScalable_Avkon::aid_size_max_handle();
       
   689     layRect.LayoutRect(scbRect, layout.LayoutLine());
       
   690     return layRect.Rect().Height();
       
   691     }
       
   692 
       
   693 TInt CAknDoubleSpanScrollIndicator::HandleBackgroundMinSizeInPixels()
       
   694     {
       
   695     return HandleMinSizeInPixels();
       
   696     }
       
   697 
       
   698 TInt CAknDoubleSpanScrollIndicator::HandleMinSizeInPixels()
       
   699     {
       
   700     // We have the minimum size as aid value, do not layout to the handle layout as it is not correct
       
   701     // on behalf of height argument (not set as maximum)
       
   702     TRect scbRect = Rect();
       
   703     if ( iOrientation == CEikScrollBar::EHorizontal )
       
   704         scbRect.SetRect(scbRect.iTl, TSize(scbRect.Height(), scbRect.Width()));
       
   705     
       
   706     TAknLayoutRect layRect;
       
   707     TAknWindowComponentLayout layout = AknLayoutScalable_Avkon::aid_size_min_handle();
       
   708     layRect.LayoutRect(scbRect, layout.LayoutLine());
       
   709     
       
   710     return layRect.Rect().Height();
       
   711     }
       
   712 
       
   713 
       
   714 void CAknDoubleSpanScrollIndicator::SetAsWindowOwning(TBool aOwnsWindow)
       
   715     {
       
   716     iOwnsWindow = aOwnsWindow;
       
   717     }
       
   718     
       
   719 void CAknDoubleSpanScrollIndicator::SetDrawBackgroundState(TBool aDraw)
       
   720     {
       
   721     iDrawBackground = aDraw;
       
   722     }
       
   723     
       
   724 TBool CAknDoubleSpanScrollIndicator::DrawBackgroundState()
       
   725     {
       
   726     return iDrawBackground;
       
   727     }
       
   728 
       
   729 // Prepares background for window-owning scrollbar 
       
   730 void CAknDoubleSpanScrollIndicator::CreateBackgroundBitmapL()
       
   731     {
       
   732    
       
   733     }
       
   734 
       
   735 void CAknDoubleSpanScrollIndicator::DrawBackground() const
       
   736     {
       
   737     CWindowGc& gc=SystemGc();
       
   738     TPoint pos = Position();
       
   739     TRect rect = Rect();
       
   740     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   741     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   742     
       
   743     if(!iTransparentBackground)
       
   744         {
       
   745         if (iOwnsWindow ) // owns window
       
   746             {
       
   747             // Redraw the background to bitmap if the skin or the size is changed.
       
   748             // Note that the indicator itself is not window owning but the actual window owning 
       
   749             // component is the scrollbar class, therefore the window may be in different position
       
   750             // and size than the indicator itself
       
   751             RWindow& win = Window();
       
   752             iDrawBackgroundBitmap = EFalse;
       
   753             TRect bmpRect(win.Position() + pos, rect.Size()); // There may be an arrow on top of scb
       
   754             if ( CAknEnv::Static()->TransparencyEnabled() )
       
   755                 {
       
   756                 AknsDrawUtils::DrawBackground( skin, cc, NULL, gc,
       
   757                     rect.iTl, bmpRect, KAknsDrawParamNoClearUnderImage );
       
   758                 }
       
   759             else
       
   760                 {
       
   761                 AknsDrawUtils::DrawBackground( skin, cc, NULL, gc, 
       
   762                     TPoint(0,0), bmpRect , KAknsDrawParamNoClearUnderImage );
       
   763                     
       
   764                          
       
   765                 }
       
   766             }
       
   767         else             //SB is non-window-owning
       
   768             {
       
   769             if ( CAknEnv::Static()->TransparencyEnabled() )
       
   770                 {
       
   771                 AknsDrawUtils::Background( skin, cc, this, gc, rect, KAknsDrawParamNoClearUnderImage );
       
   772                 }
       
   773             else
       
   774                 {
       
   775                 AknsDrawUtils::Background( skin, cc, this, gc, rect );
       
   776                 }
       
   777             }
       
   778         }
       
   779     }
       
   780 
       
   781 void CAknDoubleSpanScrollIndicator::LayoutHandleGraphics()
       
   782     {
       
   783     
       
   784     // We layout the handle middle graphics here according to the given inidcator values
       
   785     TRect rect = Rect();
       
   786     
       
   787     if (!iHandleBar || rect.IsEmpty())
       
   788         return;
       
   789     
       
   790     TInt varietyIndex = 0;
       
   791     TInt varietyIndexForHandle = 0;
       
   792     if (iOrientation == CEikScrollBar::EHorizontal)
       
   793         {        
       
   794         varietyIndex = 1;
       
   795         varietyIndexForHandle = 2;
       
   796         }
       
   797     
       
   798     TAknLayoutRect layRect;
       
   799     TAknWindowComponentLayout // layout handle bottom & top as they do not scale according to handle size
       
   800     layout = AknLayoutScalable_Avkon::scroll_handle_pane(varietyIndexForHandle); // handle (the shadow if two handles)
       
   801     layRect.LayoutRect(rect, layout.LayoutLine());
       
   802     layout = AknLayoutScalable_Avkon::scroll_handle_focus_pane(varietyIndex); // focus handle
       
   803     // The horizontal data for focus handle is missing so switch the values from the vertical data
       
   804     TAknWindowLineLayout layoutLine = layout.LayoutLine();
       
   805     if (iOrientation == CEikScrollBar::EHorizontal)
       
   806         {
       
   807         TInt height = layoutLine.iH;
       
   808         TInt width = layoutLine.iW;
       
   809         layoutLine.iW = height;
       
   810         layoutLine.iH = width;
       
   811         }
       
   812     layRect.LayoutRect(layRect.Rect(), layoutLine);
       
   813     rect = layRect.Rect(); // parent rect is now the focus handle
       
   814     
       
   815     // the retangle includes the variated length of the middle, 
       
   816     // the top and bottom graphics must subtracted from the value
       
   817     
       
   818     // do not change the handle retangle, the full size is needed in drawing
       
   819     // set the width or height to be correct
       
   820     if (iOrientation == CEikScrollBar::EVertical)
       
   821         {
       
   822         iHandleRect.iTl.iX = rect.iTl.iX;
       
   823         iHandleRect.iBr.iX = rect.iBr.iX;
       
   824         }
       
   825     else
       
   826         {
       
   827         iHandleRect.iTl.iY = rect.iTl.iY;
       
   828         iHandleRect.iBr.iY = rect.iBr.iY;
       
   829         }
       
   830     
       
   831    
       
   832     }
       
   833 
       
   834 TInt CAknDoubleSpanScrollIndicator::GetCurrentThumbSpanInPixels()
       
   835     {
       
   836     return ( iOrientation == CEikScrollBar::EVertical ?
       
   837              iHandleBackgroundRect.Height() :
       
   838              iHandleBackgroundRect.Width() );
       
   839     }
       
   840     
       
   841 TInt CAknDoubleSpanScrollIndicator::GetCurrentThumbPositionInPixels()
       
   842     {
       
   843     TInt ret;
       
   844     
       
   845     if ( iOrientation == CEikScrollBar::EHorizontal )
       
   846         {
       
   847         ret = iHandleBackgroundRect.iTl.iX -
       
   848             iBackgroundRect.iTl.iX;
       
   849         }
       
   850     else
       
   851         {
       
   852         ret = iHandleBackgroundRect.iTl.iY -
       
   853             iBackgroundRect.iTl.iY;
       
   854         }
       
   855         
       
   856     return ret;
       
   857     }
       
   858 
       
   859 void CAknDoubleSpanScrollIndicator::SetHandleHighlight( TBool aHandleHighlight )
       
   860     {
       
   861     // This does nothing in non-touch
       
   862     iHandleHighlight = aHandleHighlight;
       
   863     SetBackgroudHighlight(aHandleHighlight);
       
   864     }
       
   865     
       
   866 TBool CAknDoubleSpanScrollIndicator::HandleHighlight() const
       
   867     {
       
   868     return iHandleHighlight;
       
   869     }
       
   870     
       
   871 void CAknDoubleSpanScrollIndicator::SetTouchAreaControl( CCoeControl* aTouchAreaControl )
       
   872     {
       
   873     iTouchAreaControl = aTouchAreaControl;
       
   874     }
       
   875   
       
   876  void CAknDoubleSpanScrollIndicator::SetBackgroudHighlight( TBool aBackgroudHighlight )
       
   877     {
       
   878     // This does nothing in non-touch
       
   879     iBackgroundHighlight = aBackgroudHighlight;
       
   880 
       
   881     }
       
   882     
       
   883 TBool CAknDoubleSpanScrollIndicator::BackgroudHighlight() const
       
   884     {
       
   885     return iBackgroundHighlight;
       
   886     }
       
   887 CFbsBitmap* CAknDoubleSpanScrollIndicator::CopyAndApplyEffectL(
       
   888     const CFbsBitmap* aSource, TBool aCopyOnly )
       
   889     {
       
   890     CFbsBitmap* newBitmap = NULL;
       
   891     
       
   892     
       
   893         newBitmap = new ( ELeave ) CFbsBitmap; 
       
   894     
       
   895     
       
   896     
       
   897     TInt err = newBitmap->Create( aSource->SizeInPixels(), aSource->DisplayMode() );
       
   898     
       
   899     // We still have to return a dummy bitmap object, even if
       
   900     // the creation fails.
       
   901     if ( err == KErrNone )
       
   902         {
       
   903         SEpocBitmapHeader header = aSource->Header();
       
   904         
       
   905         // We support only 16-bit (5-6-5), since this is the default
       
   906         // display mode icons are created in. Otherwise just copy.
       
   907         if ( !aCopyOnly && aSource->DisplayMode() == EColor64K )
       
   908             {
       
   909             // Don't modify header data.
       
   910             TInt size = ( header.iBitmapSize - header.iStructSize ) /
       
   911                         sizeof( TUint16 );
       
   912                         
       
   913             aSource->BeginDataAccess();
       
   914         
       
   915             TUint16* source = (TUint16*)aSource->DataAddress();
       
   916             TUint16* dest = (TUint16*)newBitmap->DataAddress();
       
   917             
       
   918             for ( TInt i = 0; i < size; ++i )
       
   919                 {
       
   920                 *dest = *source++;
       
   921                 TBitmapFx::PixelEffect( dest++ );
       
   922                 }
       
   923             
       
   924             aSource->EndDataAccess( ETrue );
       
   925             }
       
   926         else
       
   927             {
       
   928             // This is probably faster than blitting it. Copy
       
   929             // the header data in the same run to minimize size
       
   930             // calculations, although it's already correct in the
       
   931             // new bitmap.
       
   932             TInt size = aSource->Header().iBitmapSize;
       
   933 
       
   934             aSource->BeginDataAccess();
       
   935             
       
   936             Mem::Copy( newBitmap->DataAddress(),
       
   937                        aSource->DataAddress(),
       
   938                        size );
       
   939                        
       
   940             aSource->EndDataAccess( ETrue );
       
   941             }
       
   942         }
       
   943     
       
   944     
       
   945     return newBitmap;
       
   946     }
       
   947 
       
   948 
       
   949 void TBitmapFx::PixelEffect( TUint16* aPixelData )
       
   950     {
       
   951     // Note: the calculations in this function are based on
       
   952     // graphic designers' conception of what Photoshop does
       
   953     // to images with certain values. There might also be some
       
   954     // room for optimizations.
       
   955     
       
   956     TRGB rgb;
       
   957     
       
   958     rgb.iR = ( *aPixelData & 0xF800 ) >> 11;
       
   959     rgb.iG = ( *aPixelData & 0x7E0 ) >> 5;
       
   960     rgb.iB = ( *aPixelData & 0x1F );
       
   961     
       
   962     // Scale to 65280 (0xFF00). Under no circumstances should these
       
   963     // values end up being > 0xFF00 or < 0x00
       
   964     rgb.iR *= 2105.82f;
       
   965     rgb.iG *= 1036.20f;
       
   966     rgb.iB *= 2105.82f;
       
   967     
       
   968     // Convert RGB to HSL
       
   969     TInt min = Min( rgb.iR, Min( rgb.iG, rgb.iB ) );
       
   970     TInt max = Max( rgb.iR, Max( rgb.iG, rgb.iB ) );
       
   971     TInt delta = max - min;
       
   972 
       
   973     THSL hsl = { 0, 0, 0 } ;
       
   974     
       
   975     // Lightness
       
   976     hsl.iL = ( max + min ) >> 1;
       
   977     
       
   978     if ( delta == 0 )
       
   979         {
       
   980         hsl.iH = 0;
       
   981         hsl.iS = 0;
       
   982         }
       
   983     else
       
   984         {
       
   985         // Hue
       
   986         if ( max == rgb.iR )
       
   987             {
       
   988             hsl.iH = 10880 * ( rgb.iG - rgb.iB ) / delta;
       
   989             }
       
   990         else if ( max == rgb.iG )
       
   991             {
       
   992             hsl.iH = 10880 * ( rgb.iB - rgb.iR ) / delta + 21760;
       
   993             }
       
   994         else if ( max == rgb.iB )
       
   995             {
       
   996             hsl.iH = 10880 * ( rgb.iR - rgb.iG ) / delta + 43520;
       
   997             }
       
   998         
       
   999         // Saturation
       
  1000         if ( hsl.iL <= 32640 )
       
  1001             {
       
  1002             hsl.iS = ( delta << KPrecision ) / ( ( max + min ) >> KPrecision );
       
  1003             }
       
  1004         else
       
  1005             {
       
  1006             hsl.iS = ( delta << KPrecision ) / ( ( 0x1FE00 - ( max + min ) ) >> KPrecision );
       
  1007             }
       
  1008         }
       
  1009 
       
  1010     // Apply hue shift, moved to proper range in HueToRGB()
       
  1011     hsl.iH += 0x715;
       
  1012         
       
  1013     // Apply saturation
       
  1014     // +10 in -100..100 in Photoshop terms. According to related material
       
  1015     // corresponds to 0xCC0 when applied to 0x00..0xFF00
       
  1016     hsl.iS += 0xCC0;
       
  1017     
       
  1018     if ( hsl.iS > 0xFF00 )
       
  1019         {
       
  1020         hsl.iS = 0xFF00;
       
  1021         }
       
  1022 
       
  1023     // Convert back to RGB
       
  1024     TInt v1;
       
  1025     TInt v2;
       
  1026     
       
  1027     if ( hsl.iS == 0 )
       
  1028         {
       
  1029         rgb.iR = ( hsl.iL * 255 ) >> KPrecision;
       
  1030         rgb.iG = ( hsl.iL * 255 ) >> KPrecision;
       
  1031         rgb.iB = ( hsl.iL * 255 ) >> KPrecision;
       
  1032         }
       
  1033     else
       
  1034         {
       
  1035         if ( hsl.iL < 32640 )
       
  1036             {
       
  1037             v2 = ( hsl.iL  * ( ( 0xFF00 + hsl.iS ) >> KPrecision ) ) >> KPrecision;
       
  1038             }
       
  1039         else
       
  1040             {
       
  1041             v2 = ( hsl.iL + hsl.iS ) - ( ( hsl.iS >> KPrecision ) * ( hsl.iL >> KPrecision ) );
       
  1042             }
       
  1043         
       
  1044         v1 = 2 * hsl.iL - v2;
       
  1045       
       
  1046         rgb.iR = ( HueToRGB( v1, v2, hsl.iH + 0x54FF ) );
       
  1047         rgb.iG = ( HueToRGB( v1, v2, hsl.iH ) );
       
  1048         rgb.iB = ( HueToRGB( v1, v2, hsl.iH - 0x54FF ) );
       
  1049         }
       
  1050 
       
  1051     rgb.iR /= 2105.82f;
       
  1052     rgb.iG /= 1036.20f;
       
  1053     rgb.iB /= 2105.82f;
       
  1054 
       
  1055     // Apply contrast.. However, the original req stated that the
       
  1056     // contrast value should be +6 in a range of -100..100.
       
  1057     // With 5 and 6 bit values and fixed point math such a small value has
       
  1058     // no effect, so it has been left out. The code is here in case
       
  1059     // the contrast value is updated at some point.
       
  1060     /*
       
  1061     const TInt contrast   = ( 6 * 65536 / 200 ) + 65536;
       
  1062     
       
  1063     rgb.iR -= 15;
       
  1064     rgb.iG -= 31;
       
  1065     rgb.iB -= 15;
       
  1066     
       
  1067     rgb.iR *= contrast;
       
  1068     rgb.iG *= contrast;
       
  1069     rgb.iB *= contrast;
       
  1070     
       
  1071     rgb.iR /= 65536;
       
  1072     rgb.iG /= 65536;
       
  1073     rgb.iB /= 65536;
       
  1074 
       
  1075     rgb.iR += 15;
       
  1076     rgb.iG += 31;
       
  1077     rgb.iB += 15;
       
  1078     */
       
  1079 
       
  1080     // Apply brightness, -40 in a range of -100..100 for
       
  1081     // 0..255 rgb values, which corresponds to -5 for 5 bit
       
  1082     // and -10 for 6 bit rgb values.
       
  1083     rgb.iR -= 5;
       
  1084     rgb.iG -= 10;
       
  1085     rgb.iB -= 5;
       
  1086 
       
  1087     if ( rgb.iR < 0 ) rgb.iR = 0;
       
  1088     if ( rgb.iG < 0 ) rgb.iG = 0;
       
  1089     if ( rgb.iB < 0 ) rgb.iB = 0;
       
  1090     
       
  1091     if ( rgb.iR > 31 ) rgb.iR = 31;
       
  1092     if ( rgb.iG > 63 ) rgb.iG = 63;
       
  1093     if ( rgb.iB > 31 ) rgb.iB = 31;
       
  1094 
       
  1095     *aPixelData =
       
  1096         ( rgb.iB | ( rgb.iG << 5 ) | ( rgb.iR << 11 ) );
       
  1097     }
       
  1098     
       
  1099 TInt TBitmapFx::HueToRGB( TInt v1, TInt v2, TInt aH )
       
  1100     {
       
  1101     while ( aH < 0 )
       
  1102         {
       
  1103         aH += 0xFF00;
       
  1104         }
       
  1105         
       
  1106     while ( aH >= 0xFF00 )
       
  1107         {
       
  1108         aH -= 0xFF00;
       
  1109         }
       
  1110         
       
  1111     if ( ( ( 6 * aH ) ) < 0xFF00 )
       
  1112         {
       
  1113         return v1 + ( ( v2 - v1 ) * ( ( 6 * aH ) >> KPrecision ) >> KPrecision );
       
  1114         }
       
  1115 
       
  1116     if ( ( ( 2 * aH ) ) < 0xFF00 )
       
  1117         {
       
  1118         return v2;
       
  1119         }
       
  1120 
       
  1121     if ( ( ( 3 * aH ) ) < 0x1FE00 )
       
  1122         {
       
  1123         return v1 + ( ( v2 - v1 ) * ( ( ( 0xA9FF - aH ) * 6 ) >> KPrecision ) >> KPrecision );
       
  1124         }
       
  1125     
       
  1126     return v1;
       
  1127     }
       
  1128