webengine/webkitutils/ToolBar/ToolBarButton.cpp
changeset 0 dd21522fd290
child 13 10e98eab6f85
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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:  The Toolbar button class
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32std.h>
       
    20 #include <AknUtils.h>
       
    21 #include <stringloader.h>
       
    22 #include "ToolBarButton.h"
       
    23 #include "ToolBar.h"
       
    24 #include "W32STD.H"
       
    25 #include "RecentUrlStore.h"
       
    26 #include <Uri16.h>
       
    27 #include <GULICON.H>
       
    28 #include <AknBidiTextUtils.h>
       
    29 #include "BrCtlInterface.h"
       
    30 #include <favouritesitem.h>
       
    31 #include <favouritesitemlist.h>
       
    32 #include <favouritessession.h>
       
    33 #include <favouritesdb.h>
       
    34 
       
    35 #include "eikon.hrh"
       
    36 
       
    37 
       
    38 // EXTERNAL DATA STRUCTURES
       
    39 
       
    40 // EXTERNAL FUNCTION PROTOTYPES
       
    41 
       
    42 // CONSTANTS
       
    43 const TInt KListItemMargin = 9;
       
    44 const TInt KListMargin = 10;
       
    45 const TInt KBorderSize = 5;
       
    46 const TInt KCursorOffset = 8;
       
    47 const TInt KDropdownSlidePixel = 20;
       
    48 _LIT(KTitle,"title");
       
    49 _LIT(KUrl,"url");
       
    50 const TInt KMaxBorderAlpha = 128; // how dark is the shadow around the sprite
       
    51 const TInt KDefaultTransparency = 10; // % transparent
       
    52 const TInt KToolTipBorder = 4;
       
    53 const TInt KTextMargin = 3;
       
    54 
       
    55 
       
    56 // MACROS
       
    57 
       
    58 // LOCAL CONSTANTS AND MACROS
       
    59 
       
    60 // MODULE DATA STRUCTURES
       
    61 
       
    62 // LOCAL FUNCTION PROTOTYPES
       
    63 
       
    64 // FORWARD DECLARATIONS
       
    65 
       
    66 // ============================= LOCAL FUNCTIONS ===============================
       
    67 
       
    68 // ============================ MEMBER FUNCTIONS ===============================
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CDropDownList::CDropDownList
       
    72 // C++ default constructor can NOT contain any code, that
       
    73 // might leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CDropDownList::CDropDownList(
       
    77     CDropDownButton& aParent,
       
    78     CArrayPtrFlat<HBufC>* aItemText,
       
    79     CArrayPtrFlat<CGulIcon>* aItemIcon )
       
    80     : iParent( &aParent ), iItemText( aItemText ), iItemIcon( aItemIcon ), iSize( -1, -1 )
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CDropDownList::ConstructL
       
    86 // Symbian 2nd phase constructor can leave.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CDropDownList::ConstructL()
       
    90     {
       
    91     iAnimTimer = CPeriodic::NewL( CActive::EPriorityHigh );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CDropDownList::NewL
       
    96 // Two-phased constructor.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CDropDownList* CDropDownList::NewL(
       
   100     CDropDownButton& aParent,
       
   101     CArrayPtrFlat<HBufC>* aItemText,
       
   102     CArrayPtrFlat<CGulIcon>* aItemIcon )
       
   103     {
       
   104     CDropDownList *self = new CDropDownList( aParent, aItemText, aItemIcon );
       
   105     CleanupStack::PushL(self);
       
   106     self->ConstructL();
       
   107     CleanupStack::Pop();
       
   108     return self;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // Destructor
       
   113 // -----------------------------------------------------------------------------
       
   114 CDropDownList::~CDropDownList()
       
   115     {
       
   116     if ( iItemText )
       
   117         {
       
   118         iItemText->ResetAndDestroy();
       
   119         delete iItemText;
       
   120         }
       
   121     if ( iItemIcon )
       
   122         {
       
   123         iItemIcon->ResetAndDestroy();
       
   124         delete iItemIcon;
       
   125         }
       
   126     if ( iAnimTimer )
       
   127         {
       
   128         iAnimTimer->Cancel();
       
   129         delete iAnimTimer;
       
   130         }
       
   131     delete iDropDownBitmapDevice;
       
   132     delete iDropDownBitmapContext;
       
   133     delete iDropDownBitmap;
       
   134 
       
   135     delete iSpriteBitmapDevice;
       
   136     delete iSpriteBitmapContext;
       
   137     delete iSpriteBitmap;
       
   138 
       
   139     delete iSpriteMaskBitmapDevice;
       
   140     delete iSpriteMaskBitmapContext;
       
   141     delete iSpriteMaskBitmap;
       
   142 
       
   143     delete iMaskBitmapDevice;
       
   144     delete iMaskBitmapContext;
       
   145     delete iMaskBitmap;
       
   146 
       
   147     iDropSprite.Close();
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CDropDownList::MakeVisible
       
   152 //
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CDropDownList::MakeVisible(
       
   156     TBool aVisible )
       
   157     {
       
   158     if ( iVisible == aVisible || iItemText->Count() == 0 )
       
   159         {
       
   160         return;
       
   161         }
       
   162 
       
   163     // We have toggled visibility for this dropdown list
       
   164     iVisible = aVisible;
       
   165 
       
   166     if ( !iVisible )
       
   167         {
       
   168         // If requesting to close dropdown list, close it without animation
       
   169         iAnimTimer->Cancel();
       
   170         //iDropSlide = 0;
       
   171         iDropSprite.Close();
       
   172            iSpriteInitialised = EFalse;
       
   173         return;
       
   174         }
       
   175 
       
   176     if ( !iAnimTimer->IsActive() )
       
   177         {
       
   178         // If not currently animating, animate dropdown list open
       
   179         iAnimTimer->Start( 0, 1000, TCallBack( &DropDownCb, this ) );
       
   180         }
       
   181 
       
   182     if ( iVisible )
       
   183         {
       
   184         TBool build( EFalse );
       
   185         // get position
       
   186         iPosition.iX = iParent->ToolBar().Position().iX + iParent->Position().iX;
       
   187         iPosition.iY = iParent->ToolBar().Position().iY + iParent->ToolBar().Size().iHeight - KBorderSize;
       
   188         if ( iSize == TSize( -1, -1 ) )
       
   189             {
       
   190             iSize = CalculateListSize();
       
   191             TRAP_IGNORE(CreateBitmapL());
       
   192             }
       
   193         // adjust position
       
   194         CCoeControl& view = iParent->ToolBar().ToolBarCallback().View();
       
   195         // out of the view case
       
   196         if ( iPosition.iX + iSize.iWidth > view.Size().iWidth )
       
   197             {
       
   198             iPosition.iX -= ( ( iPosition.iX + iSize.iWidth ) - view.Size().iWidth );
       
   199             }
       
   200         // y
       
   201         if ( iPosition.iY + iSize.iHeight > view.Size().iHeight )
       
   202             {
       
   203             build = !iDropUp;
       
   204             iDropUp = ETrue;
       
   205             iPosition.iY = iParent->ToolBar().Position().iY - iSize.iHeight + KBorderSize;
       
   206             }
       
   207         else
       
   208             {
       
   209             build = iDropUp;
       
   210             iDropUp = EFalse;
       
   211             }
       
   212 
       
   213         if ( build || iSelectedItem != -1 )
       
   214             {
       
   215             iSelectedItem = -1;
       
   216             TRAP_IGNORE(DrawDropDownListL());
       
   217             }
       
   218 
       
   219         ConstructSprite();
       
   220         }
       
   221     }
       
   222 
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CDropDownList::HandleOfferKeyEventL
       
   226 //
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 TKeyResponse CDropDownList::HandleOfferKeyEventL(
       
   230     const TKeyEvent& aKeyEvent,
       
   231     TEventCode aEventCode )
       
   232     {
       
   233     if ( !iVisible )
       
   234         {
       
   235         return EKeyWasNotConsumed;
       
   236         }
       
   237     // The arrow key events
       
   238     if ( aEventCode == EEventKey )
       
   239         {
       
   240         if (    aKeyEvent.iCode == EKeyLeftUpArrow          // Northwest
       
   241              || aKeyEvent.iCode == EStdKeyDevice10          //   : Extra KeyEvent supports diagonal event simulator wedge
       
   242              || aKeyEvent.iCode == EKeyUpArrow              // North
       
   243              || aKeyEvent.iCode == EKeyRightUpArrow         // Northeast
       
   244              || aKeyEvent.iCode == EStdKeyDevice11          //   : Extra KeyEvent supports diagonal event simulator wedge
       
   245 
       
   246              || aKeyEvent.iCode == EKeyLeftDownArrow        // Southwest
       
   247              || aKeyEvent.iCode == EStdKeyDevice13          //   : Extra KeyEvent supports diagonal event simulator wedge
       
   248              || aKeyEvent.iCode == EKeyDownArrow            // South
       
   249              || aKeyEvent.iCode == EKeyRightDownArrow       // Southeast
       
   250              || aKeyEvent.iCode == EStdKeyDevice12 )        //   : Extra KeyEvent supports diagonal event simulator wedge
       
   251             {
       
   252             iParent->ToolBar().MakeToolTipVisible(EFalse);
       
   253             if (    ( !iDropUp && (    aKeyEvent.iCode == EKeyLeftUpArrow       // Northwest
       
   254                                     || aKeyEvent.iCode == EStdKeyDevice10       //   : Extra KeyEvent supports diagonal event sim
       
   255                                     || aKeyEvent.iCode == EKeyUpArrow           // North
       
   256                                     || aKeyEvent.iCode == EKeyRightUpArrow      // Northeast
       
   257                                     || aKeyEvent.iCode == EStdKeyDevice11 ) )   //   : Extra KeyEvent supports diagonal event sim
       
   258 
       
   259                  || (  iDropUp && (    aKeyEvent.iCode == EKeyLeftDownArrow     // Southwest
       
   260                                     || aKeyEvent.iCode == EStdKeyDevice13       //   : Extra KeyEvent supports diagonal event sim
       
   261                                     || aKeyEvent.iCode == EKeyDownArrow         // South
       
   262                                     || aKeyEvent.iCode == EKeyRightDownArrow    // Southeast
       
   263                                     || aKeyEvent.iCode == EStdKeyDevice12 ) ) ) //   : Extra KeyEvent supports diagonal event sim
       
   264                 {
       
   265                 // can go down to -1
       
   266                 iSelectedItem = --iSelectedItem >= -1 ? iSelectedItem : -1;
       
   267                 }
       
   268             else
       
   269                 {
       
   270                 iSelectedItem = ++iSelectedItem > iItemText->Count() - 1 ? 0 : iSelectedItem;
       
   271                 }
       
   272             DrawDropDownListL();
       
   273             // update cursor unless we move out of the dropdown
       
   274             if ( iSelectedItem != -1 )
       
   275                 {
       
   276                 TSize bmSize( iDropDownBitmap->SizeInPixels() );
       
   277                 const CFont* font = LatinBold16();
       
   278                 TInt height( font->AscentInPixels() + KListItemMargin );
       
   279                 TPoint curPos( bmSize.iWidth/2, KListMargin + iSelectedItem * height + KCursorOffset );
       
   280                 if ( iDropUp )
       
   281                     {
       
   282                     curPos.iY = bmSize.iHeight - curPos.iY - height + KCursorOffset;
       
   283                     }
       
   284                 curPos+= iPosition;
       
   285                 iParent->ToolBar().ToolBarCallback().SetAndUpdateCursorPosition( curPos );
       
   286 
       
   287                 //iParent->ToolBar().Draw(*(CWindowGc*)NULL);
       
   288                 iParent->ToolBar().Draw();
       
   289                 iParent->ToolBar().SelectableItemHighlighted();
       
   290                 }
       
   291              else
       
   292                 {
       
   293                 iParent->ToolBar().UpdateCursorPosition();
       
   294                 iParent->ToolBar().ToolBarCallback().View().DrawDeferred();
       
   295                 }
       
   296             }
       
   297         else if ( aKeyEvent.iCode == EKeyDevice3 && SelectedItem() != -1 )
       
   298             {
       
   299             // The activate
       
   300             iParent->ActivatedL( SelectedItem() );
       
   301             return EKeyWasConsumed;
       
   302             }
       
   303         }
       
   304     return EKeyWasNotConsumed;
       
   305     }
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CDropDownList::HandlePointerEventL
       
   309 //
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 TBool CDropDownList::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   313     {
       
   314     TPointerEvent::TType pEventType = aPointerEvent.iType;
       
   315     if ( pEventType == TPointerEvent::EButton1Up )
       
   316         {
       
   317         TRect listRect(iPosition, iSize);
       
   318         if (listRect.Contains(aPointerEvent.iPosition))
       
   319             {
       
   320             TInt itemCount = iItemText->Count();
       
   321             TInt itemHight = (listRect.Height()-KBorderSize)/itemCount;
       
   322             TSize itemSize(listRect.Width(), itemHight);
       
   323             TPoint cPosition = iPosition;
       
   324             iOldSelectedItem = SelectedItem();
       
   325 
       
   326             TInt n;
       
   327             for ( n = iDropUp ? (itemCount - 1):0; iDropUp ? n >= 0:n <= itemCount ; iDropUp ? n--:n++)
       
   328                 {
       
   329                 TRect itemRect(cPosition, itemSize);
       
   330                 if (itemRect.Contains(aPointerEvent.iPosition))
       
   331                     {
       
   332                     iSelectedItem = n;
       
   333                     DrawDropDownListL();
       
   334                     iParent->ToolBar().ToolBarCallback().View().DrawNow();
       
   335                     if (SelectedItem() == iOldSelectedItem && iSelectedItem != -1)
       
   336                         {
       
   337                         iParent->ActivatedL( SelectedItem() );
       
   338                         }
       
   339                     return EFalse;
       
   340                     }
       
   341                 cPosition.iY += itemHight;
       
   342                 }
       
   343             }
       
   344         }
       
   345     return ETrue;
       
   346     }
       
   347 
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CDropDownList::Draw
       
   351 //
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 //void CDropDownList::Draw(
       
   355   //  CWindowGc& /*aGc*/ )
       
   356 void CDropDownList::Draw()
       
   357     {
       
   358     if ( iVisible || iAnimTimer->IsActive() )
       
   359         {
       
   360         TSpriteMember spriteMem;
       
   361         TSize bmSize( iSpriteBitmap->SizeInPixels() );
       
   362         //
       
   363         iSpriteBitmapContext->Clear();
       
   364         iSpriteMaskBitmapContext->Clear();
       
   365         if ( iDropUp )
       
   366             {
       
   367             iSpriteBitmapContext->BitBlt( TPoint( 0, bmSize.iHeight - iDropSlide/* - yOffset*/ ), *iDropDownBitmapContext,
       
   368                 TRect( TPoint( 0, 0 ), TSize( bmSize.iWidth, iDropSlide )  ) );
       
   369             iSpriteMaskBitmapContext->BitBlt( TPoint( 0, bmSize.iHeight - iDropSlide /*- yOffset*/ ), iMaskBitmap,
       
   370                 TRect( TPoint( 0, 0 ), TSize( bmSize.iWidth, iDropSlide )  ) );
       
   371             }
       
   372         else
       
   373             {
       
   374             iSpriteBitmapContext->BitBlt( TPoint( 0, 0 ), *iDropDownBitmapContext,
       
   375                 TRect( TPoint( 0, bmSize.iHeight - iDropSlide  ), TSize( bmSize.iWidth, iDropSlide )  ) );
       
   376             iSpriteMaskBitmapContext->BitBlt( TPoint( 0, 0 ), iMaskBitmap,
       
   377                 TRect( TPoint( 0, bmSize.iHeight - iDropSlide ), TSize( bmSize.iWidth, iDropSlide )  ) );
       
   378             }
       
   379 
       
   380         spriteMem.iBitmap = iSpriteBitmap;
       
   381         spriteMem.iMaskBitmap = iSpriteMaskBitmap;
       
   382         if (iSpriteInitialised)
       
   383             {
       
   384             iDropSprite.UpdateMember(0, spriteMem);
       
   385             }
       
   386         else
       
   387             {
       
   388             iSpriteInitialised = ETrue;
       
   389             iDropSprite.AppendMember(spriteMem);
       
   390             iDropSprite.SetPosition(iPosition);
       
   391             iDropSprite.Activate();
       
   392             }
       
   393         }
       
   394     iParent->RefreshToolTip();
       
   395 
       
   396     }
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CDropDownList::UpdateIconsL
       
   400 //
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CDropDownList::UpdateIconsL(
       
   404     CArrayPtrFlat<CGulIcon>* aItemIcon )
       
   405     {
       
   406     delete iItemIcon;
       
   407     iItemIcon = aItemIcon;
       
   408     //
       
   409     CCoeControl& view = iParent->ToolBar().ToolBarCallback().View();
       
   410     TSize size( CalculateListSize() );
       
   411     if ( iSize != size )
       
   412         {
       
   413         TInt diff( size.iWidth - iSize.iWidth );
       
   414         iSize = size;
       
   415         CreateBitmapL();
       
   416         // adjust dropdown x pos
       
   417         if ( iPosition.iX - diff > 0 )
       
   418             {
       
   419             iPosition.iX -= diff;
       
   420             }
       
   421         }
       
   422     DrawDropDownListL();
       
   423 
       
   424    iParent->ToolBar().Draw();
       
   425     }
       
   426 // -----------------------------------------------------------------------------
       
   427 // CDropDownList::DropDownCb
       
   428 //
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 void CDropDownList::AnimateDropDown()
       
   432     {
       
   433     TSize bmSize( iDropDownBitmap->SizeInPixels() );
       
   434 
       
   435     if ( iVisible )
       
   436         {
       
   437         iDropSlide+=KDropdownSlidePixel;
       
   438         if ( iDropSlide >= bmSize.iHeight )
       
   439             {
       
   440             iDropSlide = Min( iDropSlide, bmSize.iHeight );
       
   441             iAnimTimer->Cancel();
       
   442             }
       
   443         }
       
   444     else
       
   445         {
       
   446         iDropSlide-=KDropdownSlidePixel;
       
   447         if ( iDropSlide <= 0 )
       
   448             {
       
   449             iDropSlide = Max( iDropSlide, 0 );
       
   450             iAnimTimer->Cancel();
       
   451             }
       
   452         }
       
   453 
       
   454         iParent->ToolBar().Draw();
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CDropDownList::DropDownCb
       
   459 //
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 TInt CDropDownList::DropDownCb(
       
   463     TAny* aPtr )
       
   464     {
       
   465     static_cast<CDropDownList*>(aPtr)->AnimateDropDown();
       
   466     return ETrue;
       
   467     }
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // CDropDownList::CreateBitmapL
       
   471 //
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void CDropDownList::CreateBitmapL()
       
   475     {
       
   476 
       
   477     delete iDropDownBitmapDevice;
       
   478     iDropDownBitmapDevice = NULL;
       
   479     delete iDropDownBitmapContext;
       
   480     iDropDownBitmapContext = NULL;
       
   481     delete iDropDownBitmap;
       
   482     iDropDownBitmap = NULL;
       
   483     iDropDownBitmap = new (ELeave) CFbsBitmap;
       
   484     User::LeaveIfError( iDropDownBitmap->Create( iSize, EColor16MA ) );
       
   485     iDropDownBitmapDevice = CFbsBitmapDevice::NewL( iDropDownBitmap );
       
   486     User::LeaveIfError( iDropDownBitmapDevice->CreateContext( iDropDownBitmapContext ) );
       
   487 
       
   488     // draw shadows only once
       
   489     TRect r( TPoint( 0, 0 ), iDropDownBitmap->SizeInPixels() );
       
   490     iDropDownBitmapContext->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   491     iDropDownBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   492     iDropDownBitmapContext->SetPenStyle( CGraphicsContext::ENullPen );
       
   493     iDropDownBitmapContext->SetBrushColor( TRgb( 242, 244, 242, 20 ) );
       
   494     iDropDownBitmapContext->DrawRect( r );
       
   495 
       
   496     iDropDownBitmapContext->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   497     iDropDownBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   498     iDropDownBitmapContext->SetBrushStyle( CGraphicsContext::ENullBrush );
       
   499     // wider shadow to bottom, no shadow to top
       
   500     TInt bw = KBorderSize;
       
   501     for (TInt n=1;n<=2*bw-1;n++)
       
   502         {
       
   503         iDropDownBitmapContext->SetPenColor(TRgb(0,0,0,n*n*KMaxBorderAlpha/(2*2*bw*bw)));
       
   504         iDropDownBitmapContext->DrawRect( r );
       
   505         r.iTl.iX += n%2;
       
   506         r.iBr.iX -= n%2;
       
   507         r.iBr.iY -= 1;
       
   508         }
       
   509 
       
   510     delete iSpriteBitmapDevice;
       
   511     iSpriteBitmapDevice = NULL;
       
   512     delete iSpriteBitmapContext;
       
   513     iSpriteBitmapContext = NULL;
       
   514     delete iSpriteBitmap;
       
   515     iSpriteBitmap = NULL;
       
   516     iSpriteBitmap = new (ELeave) CFbsBitmap;
       
   517     User::LeaveIfError( iSpriteBitmap->Create( iSize, EColor16MA ) );
       
   518     iSpriteBitmapDevice = CFbsBitmapDevice::NewL( iSpriteBitmap );
       
   519     User::LeaveIfError( iSpriteBitmapDevice->CreateContext( iSpriteBitmapContext ) );
       
   520     iSpriteBitmapContext->CopySettings(*iDropDownBitmapContext);
       
   521 
       
   522     //mask
       
   523     delete iSpriteMaskBitmapDevice;
       
   524     iSpriteMaskBitmapDevice = NULL;
       
   525     delete iSpriteMaskBitmapContext;
       
   526     iSpriteMaskBitmapContext = NULL;
       
   527     delete iSpriteMaskBitmap;
       
   528     iSpriteMaskBitmap = NULL;
       
   529     iSpriteMaskBitmap = new (ELeave) CFbsBitmap;
       
   530     User::LeaveIfError( iSpriteMaskBitmap->Create( iSize, EColor256 ) );
       
   531     iSpriteMaskBitmapDevice = CFbsBitmapDevice::NewL( iSpriteMaskBitmap );
       
   532     User::LeaveIfError( iSpriteMaskBitmapDevice->CreateContext( iSpriteMaskBitmapContext ) );
       
   533 
       
   534     delete iMaskBitmapDevice;
       
   535     iMaskBitmapDevice = NULL;
       
   536     delete iMaskBitmapContext;
       
   537     iMaskBitmapContext = NULL;
       
   538     delete iMaskBitmap;
       
   539     iMaskBitmap = NULL;
       
   540     iMaskBitmap = new (ELeave) CFbsBitmap;
       
   541     User::LeaveIfError( iMaskBitmap->Create( iSize, EColor256 ) );
       
   542     iMaskBitmapDevice = CFbsBitmapDevice::NewL( iMaskBitmap );
       
   543     User::LeaveIfError( iMaskBitmapDevice->CreateContext( iMaskBitmapContext ) );
       
   544 
       
   545     // draw shadows only once
       
   546     r.SetRect( TPoint( 0, 0 ), iDropDownBitmap->SizeInPixels() );
       
   547     iMaskBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   548     iMaskBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   549     iMaskBitmapContext->SetPenColor( TRgb( 30, 30, 30 ) );
       
   550     iMaskBitmapContext->SetBrushColor( TRgb( 30, 30, 30 ) );
       
   551     iMaskBitmapContext->DrawRect( r );
       
   552 
       
   553     iMaskBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   554     iMaskBitmapContext->SetBrushStyle( CGraphicsContext::ENullBrush );
       
   555 
       
   556     // wider shadow to bottom, no shadow to top
       
   557     for (TInt n=1;n<=2*bw-1;n++)
       
   558         {
       
   559         TInt grade = 85*n/(2*bw);
       
   560         iMaskBitmapContext->SetPenColor(TRgb(255-grade,255-grade,255-grade));
       
   561         iMaskBitmapContext->DrawRect( r );
       
   562         r.iTl.iX += n%2;
       
   563         r.iBr.iX -= n%2;
       
   564         r.iBr.iY -= 1;
       
   565         }
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CDropDownList::ConstructSprite
       
   570 //
       
   571 // -----------------------------------------------------------------------------
       
   572 //
       
   573 void CDropDownList::ConstructSprite()
       
   574     {
       
   575     CToolBar& toolbar = iParent->ToolBar();
       
   576     CCoeControl& view = toolbar.ToolBarCallback().View();
       
   577 
       
   578     iDropSprite = RWsSprite(view.ControlEnv()->WsSession());
       
   579     RWindowTreeNode *window =  (RDrawableWindow* )toolbar.ToolBarCallback().CCoeControlParent().DrawableWindow();
       
   580     iDropSprite.Construct(*window,iPosition,ESpriteNoChildClip);
       
   581 
       
   582     }
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // CDropDownList::DrawDropDownListL
       
   586 //
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 void CDropDownList::DrawDropDownListL()
       
   590     {
       
   591     if ( iItemText->Count() )
       
   592         {
       
   593         TSize bmSize( iDropDownBitmap->SizeInPixels() );
       
   594 
       
   595         TRect r( TPoint( KBorderSize, 2 ), iDropDownBitmap->SizeInPixels() - TSize( 2*KBorderSize, 2*KBorderSize ) );
       
   596         iDropDownBitmapContext->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   597         iDropDownBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   598         iDropDownBitmapContext->SetPenStyle( CGraphicsContext::ENullPen );
       
   599         iDropDownBitmapContext->SetBrushColor( TRgb( 242, 244, 242, 255*(100-KDefaultTransparency)/100 ) );
       
   600         iDropDownBitmapContext->DrawRect( r );
       
   601 
       
   602         const CFont* font = LatinBold16();
       
   603 
       
   604         iDropDownBitmapContext->UseFont( font );
       
   605         iDropDownBitmapContext->SetDrawMode( CGraphicsContext::EDrawModePEN );
       
   606         iDropDownBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   607         TInt height( font->AscentInPixels() + KListItemMargin );
       
   608         TInt x( KBorderSize + KListMargin );
       
   609         x += iItemIcon ? ( height ) : 0;
       
   610         TInt y( KListMargin - KListItemMargin );
       
   611         for ( TInt i = 0; i < iItemText->Count(); i++ )
       
   612             {
       
   613             y += height;
       
   614             iDropDownBitmapContext->SetPenColor( TRgb( 0,0,0 ) );
       
   615             TPoint upperXY( KBorderSize, y - height +  KListItemMargin / 2 );
       
   616             if ( iDropUp )
       
   617                 {
       
   618                 upperXY.iY = bmSize.iHeight - y - height + KListItemMargin / 2;
       
   619                 }
       
   620             if ( i == iSelectedItem )
       
   621                 {
       
   622                 iDropDownBitmapContext->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   623                 iDropDownBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   624 
       
   625                 TSize selSize( bmSize.iWidth - 2*KBorderSize, height );
       
   626 
       
   627                 for ( TInt j = selSize.iHeight/2; j >= 0 ; j-- )
       
   628                     {
       
   629                     iDropDownBitmapContext->SetPenColor( TRgb( 50 + j*12, 50 + j*12, 255, 255*(100-KDefaultTransparency)/100) );
       
   630                     iDropDownBitmapContext->DrawRect( TRect( upperXY + TPoint( 0, j ), TSize( selSize.iWidth, 1 ) ) );
       
   631                     iDropDownBitmapContext->DrawRect( TRect( upperXY + TPoint( 0, selSize.iHeight - j ), TSize( selSize.iWidth, 1 ) ) );
       
   632                     }
       
   633                 iDropDownBitmapContext->SetDrawMode( CGraphicsContext::EDrawModePEN );
       
   634                 iDropDownBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   635                 iDropDownBitmapContext->SetPenColor( TRgb( 0xff, 0xff, 0xff ) );
       
   636                 }
       
   637             // item icon
       
   638             if ( iItemIcon && iItemIcon->At( i ) )
       
   639                 {
       
   640                 TInt iconSize( Min( height, iItemIcon->At( i )->Bitmap()->SizeInPixels().iHeight ) );
       
   641 
       
   642                 iDropDownBitmapContext->BitBltMasked( upperXY + TPoint( KBorderSize, height/2 - iconSize/2 ),
       
   643                     iItemIcon->At( i )->Bitmap(),
       
   644                     TRect( TPoint( 0, 0 ), TSize( iconSize, iconSize ) ),
       
   645                     iItemIcon->At( i )->Mask(), EFalse );
       
   646                 }
       
   647             CGraphicsContext::TDrawTextExtendedParam aParam;
       
   648             TChar a( (iItemText->At( i ))->Des()[0]);
       
   649             TChar::TBdCategory cat = a.GetBdCategory();
       
   650             if (cat == TChar::ERightToLeft || cat == TChar::ERightToLeftArabic || cat == TChar::ERightToLeftEmbedding || cat == TChar::ERightToLeftOverride)
       
   651                {
       
   652                aParam.iParRightToLeft = ETrue;
       
   653                iDropDownBitmapContext->DrawTextExtended(*(iItemText->At( i )),TPoint( x, iDropUp ? bmSize.iHeight - y : y ),aParam);
       
   654                }
       
   655             else
       
   656                {
       
   657                iDropDownBitmapContext->DrawText( *(iItemText->At( i )), TPoint( x, iDropUp ? bmSize.iHeight - y : y ) );
       
   658                }
       
   659             }
       
   660         iDropDownBitmapContext->DiscardFont();
       
   661         }
       
   662     }
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CDropDownList::CalculateListSize
       
   666 //
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 TSize CDropDownList::CalculateListSize()
       
   670     {
       
   671     CToolBar& toolbar = iParent->ToolBar();
       
   672     CCoeControl& view = toolbar.ToolBarCallback().View();
       
   673     TInt maxWidth( view.Size().iWidth / 3 * 2 );
       
   674     TInt maxHeight = Max( toolbar.Position().iY, ( view.Size().iHeight - toolbar.Position().iY - toolbar.Size().iHeight ) );
       
   675     const CFont* font = LatinBold16();
       
   676     TInt itemHeight( font->AscentInPixels() + KListItemMargin );
       
   677     //
       
   678     TSize strSize( 0, 2*KBorderSize + 2*KListMargin );
       
   679     TInt count( iItemText->Count() );
       
   680     for ( TInt i = 0; i < count; i++ )
       
   681         {
       
   682         TPtr text = iItemText->At( i )->Des();
       
   683         // pick the longest text
       
   684         TInt width( font->TextWidthInPixels( text ) + 2*KBorderSize + 2*KListMargin );
       
   685         if ( strSize.iWidth < width )
       
   686             {
       
   687             if ( width > maxWidth )
       
   688                 {
       
   689                 TextUtils::ClipToFit( text, *font, maxWidth - 2*KBorderSize - 2*KListMargin );
       
   690                 width = maxWidth;
       
   691                 }
       
   692             strSize.iWidth = width;
       
   693             }
       
   694         if ( strSize.iHeight + itemHeight > maxHeight )
       
   695             {
       
   696             // remove extra items
       
   697             for ( TInt j = count - 1; j >= i ; j-- )
       
   698                 {
       
   699                 HBufC* text = iItemText->At( j );
       
   700                 iItemText->Delete( j );
       
   701                 delete text;
       
   702                 }
       
   703             break;
       
   704             }
       
   705         strSize.iHeight += itemHeight;
       
   706         }
       
   707     // remove item margin from the last item
       
   708     strSize.iHeight -= KListItemMargin;
       
   709     if ( iItemIcon )
       
   710         {
       
   711         // icon is square. use item height for width
       
   712         strSize.iWidth += itemHeight;
       
   713         }
       
   714     return strSize;
       
   715     }
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // CToolBarButton::CToolBarButton
       
   719 // C++ default constructor can NOT contain any code, that
       
   720 // might leave.
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 CToolBarButton::CToolBarButton(
       
   724     CToolBar& aParent ) : iParent( &aParent )
       
   725     {
       
   726     }
       
   727 
       
   728 // -----------------------------------------------------------------------------
       
   729 // CToolBarButton::ConstructL
       
   730 // Symbian 2nd phase constructor can leave.
       
   731 // -----------------------------------------------------------------------------
       
   732 //
       
   733 void CToolBarButton::BaseConstructL(
       
   734     TInt aButtonCmd,
       
   735     const TDesC& aToolTip )
       
   736     {
       
   737     iParent->GetButtonImage(aButtonCmd,iToolBarButton,iToolBarButtonMask);
       
   738     iToolTip = aToolTip.AllocL();
       
   739 
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CToolBarButton::NewL
       
   744 // Two-phased constructor.
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 CToolBarButton* CToolBarButton::NewL(
       
   748     CToolBar& aParent,
       
   749     TInt aButtonCmd,
       
   750     const TDesC& aToolTip )
       
   751     {
       
   752     CToolBarButton *self = new CToolBarButton( aParent );
       
   753     CleanupStack::PushL(self);
       
   754     self->BaseConstructL( aButtonCmd, aToolTip );
       
   755     CleanupStack::Pop();
       
   756     return self;
       
   757     }
       
   758 
       
   759 // Destructor
       
   760 CToolBarButton::~CToolBarButton()
       
   761     {
       
   762     delete iToolTip;
       
   763     delete iToolBarButton;
       
   764     delete iToolBarButtonMask;
       
   765 
       
   766     delete iToolTipBitmapDevice;
       
   767     delete iToolTipBitmapContext;
       
   768     delete iToolTipBitmap;
       
   769 
       
   770     delete iToolTipMaskDevice;
       
   771     delete iToolTipMaskContext;
       
   772     delete iToolTipMask;
       
   773     }
       
   774 
       
   775 // -----------------------------------------------------------------------------
       
   776 // CToolBarButton::SetFocus
       
   777 //
       
   778 // -----------------------------------------------------------------------------
       
   779 //
       
   780 void CToolBarButton::SetFocus(
       
   781     TBool aFocusOn )
       
   782     {
       
   783     if ( !aFocusOn)
       
   784         {
       
   785         ShowToolTip(EFalse);
       
   786         }
       
   787     }
       
   788 
       
   789 //-------------------------------------------------------------------------------
       
   790 // CToolBarButton::ShowToolTip()
       
   791 // Method that draws the tooltip
       
   792 //-------------------------------------------------------------------------------
       
   793 void CToolBarButton::ShowToolTip(TBool aVisible)
       
   794     {
       
   795     if (aVisible)
       
   796         {
       
   797         delete iToolTipMask;
       
   798         iToolTipMask = 0;
       
   799         delete iToolTipBitmap;
       
   800         iToolTipBitmap = 0;
       
   801         delete iToolTipMaskDevice;
       
   802         iToolTipMaskDevice = 0;
       
   803         delete iToolTipBitmapDevice;
       
   804         iToolTipBitmapDevice = 0;
       
   805         delete iToolTipMaskContext;
       
   806         iToolTipMaskContext = 0;
       
   807         delete iToolTipBitmapContext;
       
   808         iToolTipBitmapContext = 0;
       
   809 
       
   810         const CFont* myFont = LatinBold13();
       
   811 
       
   812         TPoint cp = iParent->ToolBarCallback().CursorPosition();
       
   813 
       
   814         TRect rect = iParent->ToolBarCallback().View().Rect();
       
   815 
       
   816         TInt sW = iParent->ToolBarCallback().View().Rect().Width();
       
   817         TInt sH = iParent->ToolBarCallback().View().Rect().Height();
       
   818 
       
   819 
       
   820         TInt w = myFont->TextWidthInPixels(*iToolTip) + 2*KToolTipBorder + 2*KTextMargin;
       
   821         TInt h = myFont->HeightInPixels() + 2*KTextMargin  + 2*KToolTipBorder;
       
   822         HBufC* visualText= 0;
       
   823         TRAPD(err, visualText = HBufC::NewL( iToolTip->Length() + KAknBidiExtraSpacePerLine);
       
   824         //
       
   825         TPtr visualTextPtr = visualText->Des();
       
   826         // convert the text to lines
       
   827         AknBidiTextUtils::ConvertToVisualAndClip( *iToolTip,visualTextPtr,*myFont, w,w););
       
   828 
       
   829         if ( err != KErrNone)
       
   830             {
       
   831             return;
       
   832             }
       
   833 
       
   834         TPoint p;
       
   835         p.iX = Min(sW - w, Max(0,cp.iX - w/2));
       
   836         p.iY = Max(iParent->Position().iY - h,0);
       
   837         if (p.iY == 0)
       
   838             {
       
   839             // show tool tip below toolbar
       
   840             p.iY = iParent->Position().iY + iParent->Size().iHeight;
       
   841             }
       
   842 
       
   843         TRect boundingRect(TPoint(0,0),TSize(w,h));
       
   844 
       
   845         //mask
       
   846         iToolTipMask = new (ELeave) CFbsBitmap;
       
   847         User::LeaveIfError( iToolTipMask->Create( TSize(w,h), EColor16MA ) );
       
   848         iToolTipMaskDevice = CFbsBitmapDevice::NewL( iToolTipMask );
       
   849         User::LeaveIfError( iToolTipMaskDevice->CreateContext( iToolTipMaskContext ) );
       
   850         iToolTipMaskContext->SetPenColor(KRgbBlack);
       
   851         iToolTipMaskContext->SetBrushColor(KRgbBlack);
       
   852         iToolTipMaskContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   853         iToolTipMaskContext->SetPenStyle(CGraphicsContext::ESolidPen);
       
   854         iToolTipMaskContext->DrawRoundRect(boundingRect,TSize(4,4));
       
   855 
       
   856         //bitmap
       
   857         iToolTipBitmap = new (ELeave) CFbsBitmap;
       
   858         User::LeaveIfError( iToolTipBitmap->Create( TSize(w,h), EColor16MA ) );
       
   859         iToolTipBitmapDevice = CFbsBitmapDevice::NewL( iToolTipBitmap );
       
   860         User::LeaveIfError( iToolTipBitmapDevice->CreateContext( iToolTipBitmapContext ) );
       
   861         iToolTipBitmapContext->SetPenColor(KRgbBlack);
       
   862         iToolTipBitmapContext->SetBrushColor(TRgb(0xfa,0xfa,0xd2));
       
   863         iToolTipBitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   864         iToolTipBitmapContext->SetPenStyle(CGraphicsContext::ESolidPen);
       
   865         iToolTipBitmapContext->DrawRoundRect(boundingRect,TSize(4,4));
       
   866 
       
   867         //add text
       
   868         iToolTipBitmapContext->SetPenColor(KRgbBlack);
       
   869         iToolTipBitmapContext->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   870 
       
   871         iToolTipBitmapContext->UseFont(myFont);
       
   872         TPoint pt = boundingRect.iTl;
       
   873         pt += TPoint(KToolTipBorder + KTextMargin,KToolTipBorder + KTextMargin);
       
   874         iToolTipBitmapContext->DrawText(*visualText,
       
   875                     TPoint(pt.iX,pt.iY + myFont->AscentInPixels()));
       
   876         iToolTipBitmapContext->DiscardFont();
       
   877 
       
   878         CCoeControl& view = iParent->ToolBarCallback().View();
       
   879 
       
   880         iToolTipSprite = RWsSprite(view.ControlEnv()->WsSession());
       
   881         RWindowTreeNode *window =  (RDrawableWindow* )iParent->ToolBarCallback().CCoeControlParent().DrawableWindow();
       
   882         iToolTipSprite.Construct(*window,p, ESpriteNoChildClip);
       
   883 
       
   884         TSpriteMember spriteMem;
       
   885         spriteMem.iBitmap = iToolTipBitmap;
       
   886         spriteMem.iMaskBitmap = iToolTipMask;
       
   887         spriteMem.iInvertMask = ETrue;
       
   888 
       
   889         iToolTipSprite.AppendMember(spriteMem);
       
   890         iToolTipSprite.Activate();
       
   891         delete visualText;//visual text
       
   892 
       
   893         }
       
   894     else  // aVisible = false
       
   895         {
       
   896         iToolTipSprite.Close();
       
   897         }
       
   898 
       
   899     iToolTipSpriteVisible = aVisible;
       
   900     }
       
   901 
       
   902 // -----------------------------------------------------------------------------
       
   903 // CDropDownButton::RefreshToolTip
       
   904 //
       
   905 // -----------------------------------------------------------------------------
       
   906 //
       
   907 void CToolBarButton::RefreshToolTip()
       
   908     {
       
   909     if (iToolTipSpriteVisible)
       
   910         {
       
   911         ShowToolTip(EFalse);// hide
       
   912         }
       
   913     }
       
   914 
       
   915 // -----------------------------------------------------------------------------
       
   916 // CDropDownButton::CDropDownButton
       
   917 // C++ default constructor can NOT contain any code, that
       
   918 // might leave.
       
   919 // -----------------------------------------------------------------------------
       
   920 //
       
   921 CDropDownButton::CDropDownButton(
       
   922     CToolBar& aParent ) : CToolBarButton( aParent )
       
   923     {
       
   924     }
       
   925 
       
   926 // -----------------------------------------------------------------------------
       
   927 // Destructor
       
   928 // -----------------------------------------------------------------------------
       
   929 CDropDownButton::~CDropDownButton()
       
   930     {
       
   931     delete iDropDown;
       
   932     }
       
   933 
       
   934 // -----------------------------------------------------------------------------
       
   935 // CDropDownButton::Focus
       
   936 //
       
   937 // -----------------------------------------------------------------------------
       
   938 //
       
   939 void CDropDownButton::SetFocus(
       
   940     TBool aFocus )
       
   941     {
       
   942     CToolBarButton::SetFocus( aFocus );
       
   943     iDropDown->MakeVisible( aFocus );
       
   944     }
       
   945 
       
   946 // -----------------------------------------------------------------------------
       
   947 // CDropDownButton::HandleOfferKeyEventL
       
   948 //
       
   949 // -----------------------------------------------------------------------------
       
   950 //
       
   951 TKeyResponse CDropDownButton::HandleOfferKeyEventL(
       
   952     const TKeyEvent& aKeyEvent,
       
   953     TEventCode aEventCode )
       
   954     {
       
   955     return iDropDown->HandleOfferKeyEventL( aKeyEvent, aEventCode );
       
   956     }
       
   957 
       
   958 TBool CDropDownButton::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   959     {
       
   960     return iDropDown->HandlePointerEventL(aPointerEvent);
       
   961     }
       
   962 
       
   963 
       
   964 // -----------------------------------------------------------------------------
       
   965 // CDropDownButton::Draw
       
   966 //
       
   967 // -----------------------------------------------------------------------------
       
   968 //
       
   969 //void CDropDownButton::Draw(
       
   970   //  CWindowGc& aGc ) const
       
   971 void CDropDownButton::Draw() const
       
   972     {
       
   973     iDropDown->Draw();
       
   974     }
       
   975 
       
   976 // -----------------------------------------------------------------------------
       
   977 // CDropDownButton::ShowToolTip
       
   978 //
       
   979 // -----------------------------------------------------------------------------
       
   980 //
       
   981 void CDropDownButton::ShowToolTip( )
       
   982     {
       
   983     if ( iDropDown->SelectedItem() < 0)
       
   984        {
       
   985        CToolBarButton::ShowToolTip();
       
   986        }
       
   987     }
       
   988 
       
   989 // -----------------------------------------------------------------------------
       
   990 // CBackButton::CBackButton
       
   991 // C++ default constructor can NOT contain any code, that
       
   992 // might leave.
       
   993 // -----------------------------------------------------------------------------
       
   994 //
       
   995 CVisitedButton::CVisitedButton(
       
   996     CToolBar& aParent ) : CDropDownButton( aParent ), iCurrentFavicon( -1 )
       
   997     {
       
   998     }
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CVisitedButton::ConstructL
       
  1002 // Symbian 2nd phase constructor can leave.
       
  1003 // -----------------------------------------------------------------------------
       
  1004 //
       
  1005 void CVisitedButton::ConstructL(
       
  1006     TInt aButtonCmd,
       
  1007     const TDesC& aToolTip )
       
  1008     {
       
  1009     BaseConstructL( aButtonCmd, aToolTip );
       
  1010 
       
  1011     iRecentUrlStore = CRecentUrlStore::NewL();
       
  1012 
       
  1013     iListIcons = new( ELeave) CArrayPtrFlat<CGulIcon>(5);
       
  1014     CArrayPtrFlat<HBufC>* listItems = new( ELeave) CArrayPtrFlat<HBufC>(5);
       
  1015     CleanupStack::PushL( listItems );
       
  1016     CArrayPtrFlat<HBufC>* hosts = new( ELeave) CArrayPtrFlat<HBufC>(5);
       
  1017     CleanupStack::PushL( hosts );
       
  1018 
       
  1019     iVisitedUrls = new( ELeave) CArrayPtrFlat<HBufC>(5);
       
  1020 
       
  1021     CDesCArrayFlat* visitedNames = new( ELeave ) CDesCArrayFlat( 20 );
       
  1022     CleanupStack::PushL( visitedNames );
       
  1023     CDesCArrayFlat* visitedUrls = new( ELeave ) CDesCArrayFlat( 20 );
       
  1024     CleanupStack::PushL( visitedUrls );
       
  1025 
       
  1026     iRecentUrlStore->GetData(*visitedUrls, *visitedNames);
       
  1027 
       
  1028     TInt visitedPageCount( visitedUrls->Count() );
       
  1029     // latest on top
       
  1030     for ( TInt i = 0; i < visitedPageCount ; i++ )
       
  1031         {
       
  1032         HBufC* url = (*visitedUrls)[ i ].AllocLC();
       
  1033         HBufC* name = (*visitedNames)[ i ].AllocLC();
       
  1034         TPtr namePtr( name->Des() );
       
  1035         TPtr urlPtr( url->Des() );
       
  1036         TUriParser parser;
       
  1037         TInt status( parser.Parse( urlPtr ) );
       
  1038 
       
  1039         if ( status == KErrNone )
       
  1040             {
       
  1041             TPtrC host = parser.Extract( EUriHost );
       
  1042             TBool found( EFalse );
       
  1043             for ( TInt j = 0; j < hosts->Count(); j++ )
       
  1044                 {
       
  1045                 if ( host == *(hosts->At( j )) )
       
  1046                     {
       
  1047                     found = ETrue;
       
  1048                     break;
       
  1049                     }
       
  1050                 }
       
  1051             if ( !found )
       
  1052                 {
       
  1053                 // save this host
       
  1054                 hosts->AppendL( host.AllocL() );
       
  1055 
       
  1056                 // remove the trailing '/' character
       
  1057                 TInt len( urlPtr.Length() - 1 );
       
  1058                 if ( urlPtr[ len ] == '/' )
       
  1059                     {
       
  1060                     urlPtr = urlPtr.Left( len );
       
  1061                     }
       
  1062                 // use url if name is empty
       
  1063                 if ( namePtr.Length() == 0 )
       
  1064                     {
       
  1065                     CleanupStack::PopAndDestroy(); // name
       
  1066                     name = NULL;
       
  1067                     name = urlPtr.AllocLC();
       
  1068                     }
       
  1069 
       
  1070                 listItems->AppendL( name );
       
  1071                 CleanupStack::Pop(); // name
       
  1072                 iVisitedUrls->AppendL( url );
       
  1073                 CleanupStack::Pop(); // url
       
  1074                 }
       
  1075             else
       
  1076                 {
       
  1077                 CleanupStack::PopAndDestroy(); // name
       
  1078                 CleanupStack::PopAndDestroy(); // url
       
  1079                 }
       
  1080 
       
  1081             }
       
  1082         else
       
  1083             {
       
  1084             CleanupStack::PopAndDestroy(); // name
       
  1085             CleanupStack::PopAndDestroy(); // url
       
  1086             }
       
  1087         }
       
  1088     CleanupStack::PopAndDestroy( 3 ); // visitedNames, visitedUrls, hosts
       
  1089 
       
  1090     iDropDown = CDropDownList::NewL( *this, listItems );
       
  1091     CleanupStack::Pop(); // listItem
       
  1092     iFaviTimer = CIdle::NewL( CActive::EPriorityLow );
       
  1093     iFaviTimer->Start( TCallBack( &ReadFaviconCb, this ) );
       
  1094     }
       
  1095 
       
  1096 // -----------------------------------------------------------------------------
       
  1097 // CVisitedButton::NewL
       
  1098 // Two-phased constructor.
       
  1099 // -----------------------------------------------------------------------------
       
  1100 //
       
  1101 CVisitedButton* CVisitedButton::NewL(
       
  1102     CToolBar& aParent,
       
  1103     TInt aButtonCmd,
       
  1104     const TDesC& aToolTip )
       
  1105     {
       
  1106     CVisitedButton *self = new CVisitedButton( aParent );
       
  1107     CleanupStack::PushL(self);
       
  1108     self->ConstructL(aButtonCmd,aToolTip);
       
  1109     CleanupStack::Pop();
       
  1110     return self;
       
  1111     }
       
  1112 
       
  1113 // Destructor
       
  1114 CVisitedButton::~CVisitedButton()
       
  1115     {
       
  1116     delete iRecentUrlStore;
       
  1117     if ( iVisitedUrls )
       
  1118         {
       
  1119         iVisitedUrls->ResetAndDestroy();
       
  1120         delete iVisitedUrls;
       
  1121         }
       
  1122     if ( iListIcons )
       
  1123         {
       
  1124         iListIcons->ResetAndDestroy();
       
  1125         delete iListIcons;
       
  1126         }
       
  1127     delete iFaviTimer;
       
  1128     }
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // CVisitedButton::ActivatedL
       
  1132 //
       
  1133 // -----------------------------------------------------------------------------
       
  1134 //
       
  1135 void CVisitedButton::ActivatedL(
       
  1136     TInt aSelectedItem )
       
  1137     {
       
  1138     ToolBar().ToolBarCallback().LoadUrlL( *(iVisitedUrls->At( aSelectedItem )), TBrCtlDefs::ECacheModeNormal );
       
  1139     ToolBar().ToolBarCallback().CloseToolBarL();
       
  1140     }
       
  1141 //-------------------------------------------------------------------------------
       
  1142 // CVisitedButton::ReadNextFavicon
       
  1143 //
       
  1144 //-------------------------------------------------------------------------------
       
  1145 TBool CVisitedButton::ReadNextFaviconL()
       
  1146     {
       
  1147     TBool next( ++iCurrentFavicon < iVisitedUrls->Count() );
       
  1148     if ( next )
       
  1149         {
       
  1150         CGulIcon* icon = NULL;
       
  1151         icon = iParent->ToolBarCallback().GetFaviconL( *(iVisitedUrls->At( iCurrentFavicon ) ) );
       
  1152         CleanupStack::PushL( icon );
       
  1153         iListIcons->AppendL( icon );
       
  1154         CleanupStack::Pop(); //icon
       
  1155         }
       
  1156     else if ( iListIcons->Count() > 0 )
       
  1157         {
       
  1158         iDropDown->UpdateIconsL( iListIcons );
       
  1159         iListIcons = NULL;
       
  1160         }
       
  1161     return next;
       
  1162     }
       
  1163 //-------------------------------------------------------------------------------
       
  1164 // CVisitedButton::ReadFaviconCb
       
  1165 //
       
  1166 //-------------------------------------------------------------------------------
       
  1167 TBool CVisitedButton::ReadFaviconCb(
       
  1168     TAny* aAny )
       
  1169     {
       
  1170     TBool result( EFalse );
       
  1171     TRAP_IGNORE( result = static_cast<CVisitedButton*>(aAny)->ReadNextFaviconL() );
       
  1172     return result;
       
  1173     }
       
  1174 
       
  1175 // -----------------------------------------------------------------------------
       
  1176 // CRssButton::CRssButton
       
  1177 // C++ default constructor can NOT contain any code, that
       
  1178 // might leave.
       
  1179 // -----------------------------------------------------------------------------
       
  1180 //
       
  1181 CRssButton::CRssButton(
       
  1182     CToolBar& aParent ) : CDropDownButton( aParent )
       
  1183     {
       
  1184     }
       
  1185 
       
  1186 // -----------------------------------------------------------------------------
       
  1187 // CRssButton::ConstructL
       
  1188 // Symbian 2nd phase constructor can leave.
       
  1189 // -----------------------------------------------------------------------------
       
  1190 //
       
  1191 void CRssButton::ConstructL(
       
  1192     TInt aButtonCmd,
       
  1193     const TDesC& aToolTip,
       
  1194     const RPointerArray<TBrCtlSubscribeTo>& aRssArray )
       
  1195     {
       
  1196     BaseConstructL( aButtonCmd, aToolTip );
       
  1197 
       
  1198     CArrayPtrFlat<HBufC>* listItems = new( ELeave) CArrayPtrFlat<HBufC>(5);
       
  1199     CleanupStack::PushL( listItems );
       
  1200 
       
  1201     iSubscribeToItemsUrls = new( ELeave) CArrayPtrFlat<HBufC>(5);
       
  1202 
       
  1203     // Add the items.
       
  1204     for ( TInt i = 0; i < aRssArray.Count(); i++ )
       
  1205         {
       
  1206         // Resolve the url and append it to iSubscribeToItemsUrls.  The resolved
       
  1207         // url is added to this list to store the value after this method returns
       
  1208         // and so the memory can be cleaned up later.
       
  1209         HBufC* resolvedUrl = ToolBar().ToolBarCallback().ResolveUrlL( aRssArray[i]->Url() );
       
  1210         CleanupStack::PushL( resolvedUrl );
       
  1211         iSubscribeToItemsUrls->AppendL(resolvedUrl);
       
  1212         CleanupStack::Pop();
       
  1213 
       
  1214         if (aRssArray[i]->Title().Length())
       
  1215             {
       
  1216             listItems->AppendL( aRssArray[i]->Title().AllocL() );
       
  1217             }
       
  1218         else
       
  1219             {
       
  1220             listItems->AppendL( aRssArray[i]->Url().AllocL() );
       
  1221             }
       
  1222         }
       
  1223 
       
  1224     iDropDown = CDropDownList::NewL( *this, listItems );
       
  1225     CleanupStack::Pop(); // listItem
       
  1226     }
       
  1227 
       
  1228 // -----------------------------------------------------------------------------
       
  1229 // CRssButton::NewL
       
  1230 // Two-phased constructor.
       
  1231 // -----------------------------------------------------------------------------
       
  1232 //
       
  1233 CRssButton* CRssButton::NewL(
       
  1234     CToolBar& aParent,
       
  1235     TInt aButtonCmd,
       
  1236     const TDesC& aToolTip,
       
  1237     const RPointerArray<TBrCtlSubscribeTo>& aRssArray )
       
  1238     {
       
  1239     CRssButton *self = new CRssButton( aParent );
       
  1240     CleanupStack::PushL(self);
       
  1241     self->ConstructL(aButtonCmd,aToolTip,aRssArray );
       
  1242     CleanupStack::Pop();
       
  1243     return self;
       
  1244     }
       
  1245 
       
  1246 // Destructor
       
  1247 CRssButton::~CRssButton()
       
  1248     {
       
  1249     if (iSubscribeToItemsUrls)
       
  1250         {
       
  1251         iSubscribeToItemsUrls->ResetAndDestroy();
       
  1252         delete iSubscribeToItemsUrls;
       
  1253         }
       
  1254     }
       
  1255 
       
  1256 // -----------------------------------------------------------------------------
       
  1257 // CRssButton::ActivatedL
       
  1258 //
       
  1259 // -----------------------------------------------------------------------------
       
  1260 //
       
  1261 void CRssButton::ActivatedL(
       
  1262     TInt aSelectedItem )
       
  1263     {
       
  1264     CArrayFixFlat<TPtrC> *attrNames = new (ELeave) CArrayFixFlat<TPtrC>(1);
       
  1265     CleanupStack::PushL(attrNames);
       
  1266     CArrayFixFlat<TPtrC> *attrValues = new (ELeave) CArrayFixFlat<TPtrC>(1);
       
  1267     CleanupStack::PushL(attrValues);
       
  1268 
       
  1269     attrNames->AppendL(KTitle());
       
  1270     attrNames->AppendL(KUrl());
       
  1271 
       
  1272     const HBufC& text = iDropDown->SelectedItemText();
       
  1273     TPtrC title;
       
  1274     title.Set(*(text.AllocL()));
       
  1275     attrValues->AppendL(title);
       
  1276 
       
  1277     TPtrC url( *iSubscribeToItemsUrls->At( aSelectedItem )->AllocL() );
       
  1278     attrValues->AppendL(url);
       
  1279 
       
  1280     ToolBar().ToolBarCallback().SendCommandsToClient(TBrCtlDefs::EClientCommandSubscribeToFeeds,*attrNames,*attrValues);
       
  1281 
       
  1282     CleanupStack::PopAndDestroy(2);
       
  1283     }
       
  1284 
       
  1285 ////// BOOKMARKS IN TOOLBAR
       
  1286 
       
  1287 
       
  1288 
       
  1289 // -----------------------------------------------------------------------------
       
  1290 // CBookmarksButton::CBookmarksButton
       
  1291 // C++ default constructor can NOT contain any code, that
       
  1292 // might leave.
       
  1293 // -----------------------------------------------------------------------------
       
  1294 //
       
  1295 CBookmarksButton::CBookmarksButton(
       
  1296     CToolBar& aParent ) : CDropDownButton( aParent ), iCurrentFavicon( -1 )
       
  1297     {
       
  1298     }
       
  1299 
       
  1300 // -----------------------------------------------------------------------------
       
  1301 // CBookmarksButton::ConstructL
       
  1302 // Symbian 2nd phase constructor can leave.
       
  1303 // -----------------------------------------------------------------------------
       
  1304 //
       
  1305 void CBookmarksButton::ConstructL(
       
  1306     TInt aButtonCmd,
       
  1307     const TDesC& aToolTip )
       
  1308     {
       
  1309     BaseConstructL( aButtonCmd, aToolTip );
       
  1310 
       
  1311     // MJB: before from favouritesengine/clientserver/internal/...
       
  1312 
       
  1313     // ----------------------------------------------------------
       
  1314     // CFavouritesEngineTestAppUi::TestSomethingL()
       
  1315     // ----------------------------------------------------------
       
  1316     //
       
  1317 
       
  1318 
       
  1319     CFavouritesItemList* bookmarks = new (ELeave) CFavouritesItemList();
       
  1320     CleanupStack::PushL( bookmarks );
       
  1321     RFavouritesSession session;       ///< Session.
       
  1322 
       
  1323     User::LeaveIfError( session.Connect() );
       
  1324 
       
  1325     RFavouritesDb bookmarksDb;
       
  1326     TInt err = bookmarksDb.Open( session, KBrowserBookmarks );
       
  1327     if ( err )
       
  1328         {
       
  1329         return;
       
  1330         }
       
  1331 
       
  1332     CleanupClosePushL<RFavouritesDb>( bookmarksDb );
       
  1333 
       
  1334     err = bookmarksDb.GetAll( *bookmarks, KFavouritesRootUid, CFavouritesItem::EItem);
       
  1335 
       
  1336     CleanupStack::PopAndDestroy();  // Close db.
       
  1337     session.Close();
       
  1338 
       
  1339     iListIcons = new( ELeave) CArrayPtrFlat<CGulIcon>(5);
       
  1340     CArrayPtrFlat<HBufC>* listItems = new( ELeave) CArrayPtrFlat<HBufC>(5);
       
  1341     CleanupStack::PushL( listItems );
       
  1342 
       
  1343     iBookmarkUrls = new( ELeave) CArrayPtrFlat<HBufC>(5);
       
  1344 
       
  1345     TInt bookmarksCount( bookmarks->Count() );
       
  1346     // latest on top
       
  1347     for ( TInt i = 0; i < bookmarksCount ; i++ )
       
  1348         {
       
  1349         HBufC* url = (*bookmarks)[ i ]->Url().AllocLC();
       
  1350         HBufC* name = (*bookmarks)[ i ]->Name().AllocLC();
       
  1351 
       
  1352         listItems->AppendL( name );
       
  1353         CleanupStack::Pop(); // name
       
  1354 
       
  1355         iBookmarkUrls->AppendL( url );
       
  1356         CleanupStack::Pop(); // url
       
  1357         }
       
  1358 
       
  1359     iDropDown = CDropDownList::NewL( *this, listItems );
       
  1360     CleanupStack::Pop(); // listItems
       
  1361     CleanupStack::PopAndDestroy();  // bookmarks
       
  1362     iFaviTimer = CIdle::NewL( CActive::EPriorityLow );
       
  1363     iFaviTimer->Start( TCallBack( &ReadFaviconCb, this ) );
       
  1364     }
       
  1365 
       
  1366 // -----------------------------------------------------------------------------
       
  1367 // CBookmarksButton::NewL
       
  1368 // Two-phased constructor.
       
  1369 // -----------------------------------------------------------------------------
       
  1370 //
       
  1371 CBookmarksButton* CBookmarksButton::NewL(
       
  1372     CToolBar& aParent,
       
  1373     TInt aButtonCmd,
       
  1374     const TDesC& aToolTip )
       
  1375     {
       
  1376     CBookmarksButton *self = new CBookmarksButton( aParent );
       
  1377     CleanupStack::PushL(self);
       
  1378     self->ConstructL(aButtonCmd,aToolTip);
       
  1379     CleanupStack::Pop();
       
  1380     return self;
       
  1381     }
       
  1382 
       
  1383 // Destructor
       
  1384 CBookmarksButton::~CBookmarksButton()
       
  1385     {
       
  1386     if ( iBookmarkUrls )
       
  1387         {
       
  1388         iBookmarkUrls->ResetAndDestroy();
       
  1389         delete iBookmarkUrls;
       
  1390         }
       
  1391     if ( iListIcons )
       
  1392         {
       
  1393         iListIcons->ResetAndDestroy();
       
  1394         delete iListIcons;
       
  1395         }
       
  1396     delete iFaviTimer;
       
  1397     }
       
  1398 
       
  1399 // -----------------------------------------------------------------------------
       
  1400 // CBookmarksButton::ActivatedL
       
  1401 //
       
  1402 // -----------------------------------------------------------------------------
       
  1403 //
       
  1404 void CBookmarksButton::ActivatedL(
       
  1405     TInt aSelectedItem )
       
  1406     {
       
  1407     ToolBar().ToolBarCallback().LoadUrlL( *(iBookmarkUrls->At( aSelectedItem )), TBrCtlDefs::ECacheModeNormal );
       
  1408     ToolBar().ToolBarCallback().CloseToolBarL();
       
  1409     }
       
  1410 //-------------------------------------------------------------------------------
       
  1411 // CBookmarksButton::ReadNextFavicon
       
  1412 //
       
  1413 //-------------------------------------------------------------------------------
       
  1414 TBool CBookmarksButton::ReadNextFaviconL()
       
  1415     {
       
  1416     TBool next( ++iCurrentFavicon < iBookmarkUrls->Count() );
       
  1417     if ( next )
       
  1418         {
       
  1419         CGulIcon* icon = NULL;
       
  1420         icon = iParent->ToolBarCallback().GetFaviconL( *(iBookmarkUrls->At( iCurrentFavicon ) ) );
       
  1421         CleanupStack::PushL( icon );
       
  1422         iListIcons->AppendL( icon );
       
  1423         CleanupStack::Pop(); //icon
       
  1424         }
       
  1425     else if ( iListIcons->Count() > 0 )
       
  1426         {
       
  1427         iDropDown->UpdateIconsL( iListIcons );
       
  1428         iListIcons = NULL;
       
  1429         }
       
  1430     return next;
       
  1431     }
       
  1432 //-------------------------------------------------------------------------------
       
  1433 // CBookmarksButton::ReadFaviconCb
       
  1434 //
       
  1435 //-------------------------------------------------------------------------------
       
  1436 TBool CBookmarksButton::ReadFaviconCb(
       
  1437     TAny* aAny )
       
  1438     {
       
  1439     TBool result( EFalse );
       
  1440     TRAP_IGNORE( result = static_cast<CBookmarksButton*>(aAny)->ReadNextFaviconL() );
       
  1441     return result;
       
  1442     }
       
  1443 
       
  1444 //  End of File
       
  1445 
       
  1446 
       
  1447 
       
  1448 
       
  1449 
       
  1450