uifw/EikStd/coctlsrc/EIKSBFRM.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eiksbfrm.h>
       
    20 #include <eikpanic.h>
       
    21 #include <eikbtgpc.h>
       
    22 #include <eikcba.h>
       
    23 #include <eikenv.h>
       
    24 #include <eikappui.h>
       
    25 
       
    26 #include <aknenv.h>
       
    27 #include <aknappui.h>
       
    28 #include <AknLayout.lag>
       
    29 #include <AknUtils.h>
       
    30 
       
    31 #include "EIKSBEXT.H"
       
    32 
       
    33 // const TInt KCbaScrollBarWidth=9;
       
    34 
       
    35 //
       
    36 // TEikScrollBarFrameLayout
       
    37 //
       
    38 
       
    39 EXPORT_C TEikScrollBarFrameLayout::TEikScrollBarFrameLayout()
       
    40 	//
       
    41 	// default constructor
       
    42 	//
       
    43 	{
       
    44     iInclusiveMargin.iTop = 0;
       
    45     iInclusiveMargin.iBottom = 0;
       
    46     iInclusiveMargin.iLeft = 0;
       
    47     iInclusiveMargin.iRight = 0;
       
    48     
       
    49     iClientMargin.iTop = 0;
       
    50     iClientMargin.iBottom = 0;
       
    51     iClientMargin.iLeft = 0;
       
    52     iClientMargin.iRight = 0;
       
    53     
       
    54     iClientAreaGranularity = TSize(0,0);
       
    55     
       
    56     iTilingMode = EClientRectConstant;
       
    57 	}
       
    58 
       
    59 EXPORT_C void TEikScrollBarFrameLayout::SetInclusiveMargin(TInt aMargin)
       
    60 	//
       
    61 	// sets all inclusive margins to aMargin
       
    62 	//
       
    63 	{
       
    64     iInclusiveMargin.iTop = aMargin;
       
    65     iInclusiveMargin.iBottom = aMargin;
       
    66     iInclusiveMargin.iLeft = aMargin;
       
    67     iInclusiveMargin.iRight = aMargin;
       
    68 	}
       
    69 
       
    70 EXPORT_C void TEikScrollBarFrameLayout::SetClientMargin(TInt aMargin)
       
    71 	//
       
    72 	// sets all client margins to aMargin
       
    73 	//
       
    74 	{
       
    75     iClientMargin.iTop = aMargin;
       
    76     iClientMargin.iBottom = aMargin;
       
    77     iClientMargin.iLeft = aMargin;
       
    78     iClientMargin.iRight = aMargin;
       
    79 	}
       
    80 
       
    81 
       
    82 CEikScrollBarFrameExtension::CEikScrollBarFrameExtension()
       
    83     {
       
    84 
       
    85     }
       
    86 
       
    87 CEikScrollBarFrameExtension::~CEikScrollBarFrameExtension()
       
    88     {
       
    89 
       
    90     }
       
    91 
       
    92 //
       
    93 // CEikScrollBarFrame
       
    94 //
       
    95 
       
    96 enum TEikScrollBarFramePanic
       
    97 	{
       
    98 	ENoScrollBarFrame	=0x01,
       
    99 	EFailedToRemoveExternalScrollBar,
       
   100 	EUnexpectedExternalScrollBarDisconnectRequest
       
   101 	};
       
   102 
       
   103 GLDEF_C void SbfPanic(TEikScrollBarFramePanic aPanic)
       
   104     {
       
   105 	_LIT(KPanicCategory, "UIKON - Scrollbar Frame");
       
   106     User::Panic(KPanicCategory, aPanic);
       
   107     }
       
   108 
       
   109 // const TInt KTypeOfScrollBarMask=0x0300;
       
   110 // const TInt KSideOfScrollBarMask=0x0c00;
       
   111 
       
   112 
       
   113 enum // private flags
       
   114 	{
       
   115 	EDisplayHScrollBar			=0x01,
       
   116 	EDisplayVScrollBar			=0x02,
       
   117 	EDoNotAdjustHorizontalModel	=0x04,
       
   118 	EDoNotAdjustVerticalModel	=0x08,
       
   119 	EPreAllocScrollBars			=0x10
       
   120 	};
       
   121 
       
   122 EXPORT_C CEikScrollBarFrame::~CEikScrollBarFrame()
       
   123 	{
       
   124     DeleteScrollBars();
       
   125     delete iExtension;
       
   126 	}
       
   127 
       
   128 EXPORT_C CEikScrollBarFrame::CEikScrollBarFrame(CCoeControl* aParentWindow, MEikScrollBarObserver* aObserver, TBool /*aPreAlloc*/)
       
   129 	{
       
   130     InitExtension(aParentWindow,aObserver);
       
   131 	GetScrollBars(EFalse);	
       
   132 	}
       
   133 
       
   134 CEikScrollBarFrame::CEikScrollBarFrame(CCoeControl* aParentWindow, MEikScrollBarObserver* aObserver, TBool /*aPreAlloc*/, TBool aDoubleSpan)
       
   135 	{
       
   136     InitExtension(aParentWindow,aObserver);
       
   137 	GetScrollBars(aDoubleSpan);
       
   138 	}
       
   139 
       
   140 void CEikScrollBarFrame::InitExtension(CCoeControl* aParentWindow, MEikScrollBarObserver* aObserver)
       
   141     {
       
   142     iExtension = new CEikScrollBarFrameExtension();
       
   143     if (iExtension)
       
   144         {
       
   145         iExtension->iParentWindow = aParentWindow;
       
   146         iExtension->iH.iModel = TAknDoubleSpanScrollBarModel();
       
   147         iExtension->iH.iBar = NULL;
       
   148         iExtension->iH.iExternalScrollBarAttached = EFalse;
       
   149         iExtension->iH.iVisibility = EOff; 
       
   150         if(AknLayoutUtils::PenEnabled())
       
   151             {
       
   152             iExtension->iScrollBarObserver = aObserver;
       
   153             }
       
   154         }
       
   155     }
       
   156 
       
   157 void CEikScrollBarFrame::DisconnectExternalScrollBar(CEikScrollBar* aScrollBar)
       
   158 	{
       
   159 	if (iV.iExternalScrollBarAttached && iV.iBar == aScrollBar)
       
   160         {
       
   161         iV.iExternalScrollBarAttached = EFalse;
       
   162 	    iV.iBar = NULL;
       
   163         }
       
   164 
       
   165     if (iExtension && iExtension->iH.iExternalScrollBarAttached && iExtension->iH.iBar == aScrollBar) 
       
   166         {
       
   167     	iExtension->iH.iExternalScrollBarAttached = EFalse;
       
   168 	    iExtension->iH.iBar = NULL;
       
   169         }
       
   170     }
       
   171 
       
   172 void CEikScrollBarFrame::GetScrollBars(TBool aDoubleSpan)
       
   173 	{
       
   174 	if (!iV.iBar)
       
   175 		{
       
   176 		CEikCba* cba=GetCurrentCba();
       
   177 		if (cba)
       
   178 			{
       
   179 			// If aDoubleSpan is true, we will optimize and do not create arrow heads at all.
       
   180 			// There will come CreateDoubleSpanScrollBarsL call, and arrow heads are not needed.
       
   181 			if ( !(aDoubleSpan && (AknLayoutUtils::DefaultScrollBarType(iAvkonAppUi) == CEikScrollBarFrame::EDoubleSpan)) )
       
   182 			    {
       
   183 			    TRAP_IGNORE(cba->CreateArrowHeadScrollBarL());  
       
   184 			    }
       
   185 			// returns the vertical scroll bar from the top scroll bar host
       
   186 			iV.iBar=cba->VScrollBarAsControl();
       
   187 			iV.iExternalScrollBarAttached=ETrue;
       
   188 			TRAPD(err, iV.iBar->AddExternalFrameL(this));
       
   189 			if (err)
       
   190 				{
       
   191 				iV.iExternalScrollBarAttached = EFalse;
       
   192 				iV.iBar = NULL;
       
   193 				}
       
   194 			}
       
   195 		}
       
   196 	}
       
   197 
       
   198 EXPORT_C void CEikScrollBarFrame::DrawScrollBarsNow() const
       
   199 // Force a redraw of any scrollbars
       
   200 	{	
       
   201 	if (iV.iBar && iExtension && iExtension->iParentWindow->IsVisible())
       
   202 		iV.iBar->DrawNow();
       
   203 
       
   204 	if (iExtension && iExtension->iH.iBar && iExtension->iParentWindow->IsVisible())
       
   205 		iExtension->iH.iBar->DrawNow();
       
   206 
       
   207 	}
       
   208 
       
   209 void CEikScrollBarFrame::DrawScrollBarsDeferred() const
       
   210     {
       
   211     if (iV.iBar && iExtension && iExtension->iParentWindow->IsVisible())
       
   212 	    {	   
       
   213 	    iV.iBar->DrawDeferred();	    
       
   214 	    }		
       
   215 
       
   216 	if (iExtension && iExtension->iH.iBar && iExtension->iParentWindow->IsVisible())
       
   217 	    {
       
   218 	    iExtension->iH.iBar->DrawDeferred();	    
       
   219 	    }    
       
   220     }
       
   221 
       
   222 const TInt KLongEnoughToCauseComponentsToBeCreated=200;
       
   223 
       
   224 
       
   225 EXPORT_C void CEikScrollBarFrame::SetScrollBarVisibilityL(TScrollBarVisibility aHVisibility, TScrollBarVisibility aVVisibility)
       
   226 // Set the visibility state for both scrollbars to be used when tiling
       
   227 	{
       
   228 	__ASSERT_DEBUG(this, SbfPanic(ENoScrollBarFrame));
       
   229 
       
   230     // Vertical scrollbar
       
   231 	iV.iVisibility=aVVisibility;
       
   232     if (iV.iBar && TypeOfVScrollBar() == EDoubleSpan && aVVisibility==EOff)
       
   233         {
       
   234        	iScrollBarFrameFlags&=(~EDisplayVScrollBar);
       
   235         MakeSBarVisible(iV, EFalse);
       
   236         }
       
   237 
       
   238     // Horizontal scrollbar
       
   239     if (iExtension)
       
   240         {
       
   241     	iExtension->iH.iVisibility=aHVisibility;
       
   242         if (iExtension->iH.iBar && TypeOfHScrollBar() == EDoubleSpan && aHVisibility==EOff)
       
   243             {
       
   244        	    iScrollBarFrameFlags&=(~EDisplayHScrollBar);
       
   245             MakeSBarVisible(iExtension->iH, EFalse);
       
   246             }
       
   247         }
       
   248 	}
       
   249 
       
   250 EXPORT_C TBool CEikScrollBarFrame::Tile(TEikScrollBarModel* aVModel)
       
   251 	//
       
   252 	// The main function which provides the necessary scrollbars according to visibilities and size considerations
       
   253 	// returns ETrue if the "output rect" was changed
       
   254 	//
       
   255 	{
       
   256 	GetScrollBars(EFalse);
       
   257 	CalcTheoreticalScrollBarVisibility(aVModel);
       
   258 	if (iV.iVisibility!=EOff)
       
   259 		iV.iModel = *aVModel;
       
   260 	MakeSBarVisible(iV, iScrollBarFrameFlags&EDisplayVScrollBar);
       
   261 	return EFalse;
       
   262 	}
       
   263 
       
   264 EXPORT_C TBool CEikScrollBarFrame::TileL(TEikScrollBarModel* aHModel, TEikScrollBarModel* aVModel,
       
   265 			  TRect& aClientRect, TRect& aInclusiveRect, const TEikScrollBarFrameLayout& aLayout)
       
   266 	{
       
   267 	TRect tempRect(aClientRect);
       
   268 	if(aClientRect.Height() < 0 )
       
   269 	    {
       
   270 	    aClientRect.iTl.iY = aClientRect.iBr.iY;
       
   271 	    aClientRect.iBr.iY = tempRect.iTl.iY;
       
   272 	    }
       
   273 	if(aClientRect.Width() < 0 )
       
   274         {
       
   275         aClientRect.iTl.iX = aClientRect.iBr.iX;
       
   276         aClientRect.iBr.iX = tempRect.iTl.iX;
       
   277         }
       
   278 	tempRect = aInclusiveRect;
       
   279 	if(aInclusiveRect.Height() < 0 )
       
   280         {
       
   281         aInclusiveRect.iTl.iY = aInclusiveRect.iBr.iY;
       
   282         aInclusiveRect.iBr.iY = tempRect.iTl.iY;
       
   283         }
       
   284     if(aInclusiveRect.Width() < 0 )
       
   285         {
       
   286         aInclusiveRect.iTl.iX = aInclusiveRect.iBr.iX;
       
   287         aInclusiveRect.iBr.iX = tempRect.iTl.iX;
       
   288         }
       
   289     if (iExtension && iExtension->iH.iVisibility!=EOff)
       
   290         {
       
   291         if(aClientRect.Height() < ScrollBarBreadth( CEikScrollBar::EHorizontal) )
       
   292             {
       
   293             aClientRect.SetHeight( ScrollBarBreadth(CEikScrollBar::EHorizontal) );
       
   294             }
       
   295         if(aInclusiveRect.Height() < ScrollBarBreadth( CEikScrollBar::EHorizontal) )
       
   296             {
       
   297             aInclusiveRect.SetHeight( ScrollBarBreadth(CEikScrollBar::EHorizontal) );
       
   298             }
       
   299         }
       
   300     TBool sizeChanged = EFalse;
       
   301     
       
   302 	GetScrollBars(EFalse);
       
   303 	CalcTheoreticalScrollBarVisibility(aVModel,aHModel);
       
   304 
       
   305 	if (iV.iVisibility!=EOff)
       
   306 		iV.iModel = *aVModel;
       
   307 	
       
   308 	MakeSBarVisible(iV, iScrollBarFrameFlags&EDisplayVScrollBar);
       
   309 
       
   310     if (iExtension && iExtension->iH.iBar)
       
   311         {
       
   312         if (iExtension->iH.iVisibility!=EOff)
       
   313 	        iExtension->iH.iModel = *aHModel;   
       
   314         
       
   315         MakeSBarVisible(iExtension->iH, iScrollBarFrameFlags&EDisplayHScrollBar);
       
   316         }
       
   317 
       
   318     // Vertical Double span scollbar
       
   319     if (iV.iBar && TypeOfVScrollBar() == EDoubleSpan && iV.iExternalScrollBarAttached==EFalse )
       
   320         {        
       
   321         TInt scrollBarWidth = ScrollBarBreadth(CEikScrollBar::EVertical); // is 0 if SB not visible !
       
   322         TInt horizontalScrollBarWidth = 0;
       
   323         if (iExtension && iExtension->iH.iVisibility!=EOff)
       
   324             {
       
   325             horizontalScrollBarWidth = ScrollBarBreadth(CEikScrollBar::EHorizontal);
       
   326             }
       
   327         CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iV.iBar);
       
   328         if (scrollbar->FixedLayoutRect().Size() == TSize(0,0))
       
   329             {
       
   330             TMargins checkedClientMargin(aLayout.iClientMargin);
       
   331             TMargins checkedInclusiveMargin(aLayout.iInclusiveMargin);
       
   332             checkedClientMargin.iTop = Max(0,checkedClientMargin.iTop);
       
   333             checkedClientMargin.iBottom = Max(0,checkedClientMargin.iBottom);
       
   334             checkedClientMargin.iRight = Max(0,checkedClientMargin.iRight);
       
   335             checkedClientMargin.iLeft = Max(0,checkedClientMargin.iLeft);
       
   336 
       
   337             checkedInclusiveMargin.iTop = Max(0,checkedInclusiveMargin.iTop);
       
   338             checkedInclusiveMargin.iBottom = Max(0,checkedInclusiveMargin.iBottom);
       
   339             checkedInclusiveMargin.iRight = Max(0,checkedInclusiveMargin.iRight);
       
   340             checkedInclusiveMargin.iLeft = Max(0,checkedInclusiveMargin.iLeft);
       
   341 
       
   342             TInt width  = 0;                
       
   343             TInt xPos   = 0;
       
   344             TInt yPos   = 0;
       
   345             TInt height = 0;
       
   346             
       
   347             if (!AknLayoutUtils::LayoutMirrored())
       
   348                 {
       
   349                 if (aLayout.iTilingMode == TEikScrollBarFrameLayout::EInclusiveRectConstant)
       
   350                     {
       
   351                     width = scrollBarWidth + checkedInclusiveMargin.iRight;                
       
   352                     xPos = aInclusiveRect.iBr.iX - width;
       
   353                     yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop;
       
   354                     height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth;
       
   355                 
       
   356                     if ((aClientRect.iBr.iX + width > aInclusiveRect.iBr.iX) || (aInclusiveRect.iBr.iX - width > aClientRect.iBr.iX))
       
   357                         {
       
   358                         aClientRect.iBr.iX = aInclusiveRect.iBr.iX - width;
       
   359                         sizeChanged = ETrue;
       
   360                         }
       
   361                     }
       
   362                 else
       
   363                     {
       
   364                     width = scrollBarWidth + checkedClientMargin.iRight;                
       
   365                     xPos = aClientRect.iBr.iX + checkedClientMargin.iRight;
       
   366                     yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop;
       
   367                     height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth;
       
   368 
       
   369                     if ((aClientRect.iBr.iX + width + checkedInclusiveMargin.iRight > aInclusiveRect.iBr.iX) || 
       
   370                         (aInclusiveRect.iBr.iX - (width + checkedInclusiveMargin.iRight) > aClientRect.iBr.iX))
       
   371                         {
       
   372                         aInclusiveRect.iBr.iX = aClientRect.iBr.iX + width + checkedInclusiveMargin.iRight;
       
   373                         sizeChanged = ETrue;
       
   374                         }
       
   375                     }
       
   376                 }
       
   377             else
       
   378                 {
       
   379                 // Mirrored Left & Right
       
   380                 if (aLayout.iTilingMode == TEikScrollBarFrameLayout::EInclusiveRectConstant)
       
   381                     {
       
   382                     width = scrollBarWidth + checkedInclusiveMargin.iRight;                
       
   383                     xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iRight;
       
   384                     yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop;
       
   385                     height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth;
       
   386                 
       
   387                     if ((aClientRect.iTl.iX - width < aInclusiveRect.iTl.iX) || (aInclusiveRect.iTl.iX + width > aClientRect.iTl.iX))
       
   388                         {
       
   389                         aClientRect.iTl.iX = aInclusiveRect.iTl.iX + width;
       
   390                         xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iRight;
       
   391                         sizeChanged = ETrue;
       
   392                         }
       
   393                     }
       
   394                 else
       
   395                     {
       
   396                     width = scrollBarWidth + checkedClientMargin.iRight;                
       
   397                     xPos = aClientRect.iTl.iX - checkedClientMargin.iRight;
       
   398                     yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop;
       
   399                     height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth;
       
   400 
       
   401                     if ((aClientRect.iTl.iX - width - checkedInclusiveMargin.iRight > aInclusiveRect.iTl.iX) || 
       
   402                         (aInclusiveRect.iTl.iX - (width + checkedInclusiveMargin.iRight) < aClientRect.iTl.iX))
       
   403                         {
       
   404                         aInclusiveRect.iTl.iX = aClientRect.iTl.iX - width - checkedInclusiveMargin.iRight;
       
   405                         xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iRight;
       
   406                         sizeChanged = ETrue;
       
   407                         }
       
   408                     }
       
   409 
       
   410                 }
       
   411     
       
   412             TRect newRect = TRect(TPoint(xPos, yPos), TSize(width, height ));
       
   413             if (iV.iBar->IsVisible() && (newRect != TRect(iV.iBar->Position(), iV.iBar->Size())))
       
   414                 {
       
   415                 iV.iBar->SetRect(newRect);                     
       
   416                 }
       
   417 
       
   418             }
       
   419         }
       
   420 
       
   421     // Horizontal Double span scollbar
       
   422     if (iExtension && 
       
   423         iExtension->iH.iBar && 
       
   424         TypeOfHScrollBar() == EDoubleSpan && 
       
   425         iExtension->iH.iExternalScrollBarAttached==EFalse )
       
   426         {                
       
   427         TInt scrollBarWidth = ScrollBarBreadth(CEikScrollBar::EHorizontal); // is 0 if SB not visible !
       
   428         TInt verticalScrollBarWidth = 0;
       
   429         if (iV.iVisibility!=EOff)
       
   430             {
       
   431             verticalScrollBarWidth = ScrollBarBreadth(CEikScrollBar::EVertical);
       
   432             }
       
   433         CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iExtension->iH.iBar);
       
   434         if (scrollbar->FixedLayoutRect().Size() == TSize(0,0))
       
   435             {
       
   436             TMargins checkedClientMargin(aLayout.iClientMargin);
       
   437             TMargins checkedInclusiveMargin(aLayout.iInclusiveMargin);
       
   438             checkedClientMargin.iTop = Max(0,checkedClientMargin.iTop);
       
   439             checkedClientMargin.iBottom = Max(0,checkedClientMargin.iBottom);
       
   440             checkedClientMargin.iRight = Max(0,checkedClientMargin.iRight);
       
   441             checkedClientMargin.iLeft = Max(0,checkedClientMargin.iLeft);
       
   442 
       
   443             checkedInclusiveMargin.iTop = Max(0,checkedInclusiveMargin.iTop);
       
   444             checkedInclusiveMargin.iBottom = Max(0,checkedInclusiveMargin.iBottom);
       
   445             checkedInclusiveMargin.iRight = Max(0,checkedInclusiveMargin.iRight);
       
   446             checkedInclusiveMargin.iLeft = Max(0,checkedInclusiveMargin.iLeft);
       
   447 
       
   448             TInt width  = 0;                
       
   449             TInt xPos   = 0;
       
   450             TInt yPos   = 0;
       
   451             TInt height = 0;
       
   452             
       
   453             if (aLayout.iTilingMode == TEikScrollBarFrameLayout::EInclusiveRectConstant)
       
   454                 {
       
   455                 width = scrollBarWidth + checkedInclusiveMargin.iBottom; // width as vertical direction (height).               
       
   456                 xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iLeft;
       
   457                 if (AknLayoutUtils::LayoutMirrored())
       
   458                     {
       
   459                     xPos += verticalScrollBarWidth;
       
   460                     }
       
   461                 yPos = aInclusiveRect.iBr.iY - checkedInclusiveMargin.iBottom - width;
       
   462                 height = aInclusiveRect.Size().iWidth - (checkedInclusiveMargin.iLeft + checkedInclusiveMargin.iRight) - verticalScrollBarWidth; // height as horizontal (width).
       
   463                 
       
   464                 if ((aClientRect.iBr.iY + width > aInclusiveRect.iBr.iY) || (aInclusiveRect.iBr.iY - width > aClientRect.iBr.iY))
       
   465                     {
       
   466                     aClientRect.iBr.iY = aInclusiveRect.iBr.iY - width;
       
   467                     sizeChanged = ETrue;
       
   468                     }
       
   469                 }
       
   470             else
       
   471                 {
       
   472                 width = scrollBarWidth + checkedClientMargin.iBottom; // width as vertical direction (height).               
       
   473                 xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iLeft;
       
   474                 if (AknLayoutUtils::LayoutMirrored())
       
   475                     {
       
   476                     xPos += verticalScrollBarWidth;
       
   477                     }
       
   478                 yPos = aClientRect.iBr.iY + checkedClientMargin.iBottom;
       
   479                 height = aInclusiveRect.Size().iWidth - (checkedInclusiveMargin.iLeft + checkedInclusiveMargin.iRight) - verticalScrollBarWidth; // height as horizontal (width).
       
   480                 
       
   481                 if ((aClientRect.iBr.iY + width + checkedClientMargin.iBottom > aInclusiveRect.iBr.iY) || 
       
   482                     (aInclusiveRect.iBr.iY - (width + checkedInclusiveMargin.iBottom) > aClientRect.iBr.iY))
       
   483                     {
       
   484                     aInclusiveRect.iBr.iY = aClientRect.iBr.iY + width + checkedInclusiveMargin.iBottom;
       
   485                     sizeChanged = ETrue;
       
   486                     }
       
   487                 }
       
   488 
       
   489             TRect newRect = TRect(TPoint(xPos, yPos), TSize(height, width ));  // height & width swapped 
       
   490             if (iExtension->iH.iBar->IsVisible() && (newRect != TRect(iV.iBar->Position(), iV.iBar->Size())))
       
   491                 {
       
   492                 iExtension->iH.iBar->SetRect(newRect);                   
       
   493                 }
       
   494             }
       
   495         
       
   496         }
       
   497 
       
   498     return sizeChanged;
       
   499 	}
       
   500 
       
   501 EXPORT_C void CEikScrollBarFrame::MoveThumbsBy(TInt aDeltaX, TInt aDeltaY)
       
   502 	//
       
   503  	// Used to update any scrollbar(s) after an external scroll
       
   504 	// values in terms of the model, presumed not to have changed spans.
       
   505 	//
       
   506 	{
       
   507     // Vertical scrollbar
       
   508     if (aDeltaY && iV.iBar)
       
   509         {
       
   510         if (TypeOfVScrollBar() == TScrollBarType(EArrowHead))
       
   511             {
       
   512 		    iV.iModel.iThumbPosition += aDeltaY;
       
   513             }
       
   514         else
       
   515             {
       
   516             // EDoubleSpan has different model.
       
   517             if (iV.iModel.ScrollBarModelType() == TEikScrollBarModel::EAknDoubleSpanScrollBarModel)
       
   518                 {
       
   519                 TAknDoubleSpanScrollBarModel* model = static_cast <TAknDoubleSpanScrollBarModel*> (&iV.iModel);
       
   520                 // Note that for a large scroll span and small delta this may not actually change focusposition
       
   521                 // because of the 15 bit accuracy of TAknDoubleSpanScrollBarModel values.
       
   522                 model->SetFocusPosition(model->FocusPosition() + aDeltaY);    
       
   523                 }
       
   524             else
       
   525                 {
       
   526                 // Error. User of the API is perhaps assigning values directly to TEikScrollBarModel
       
   527                 // member variables which is not allowed with EAknDoubleSpanScrollBarModel.
       
   528                 // #ifdef _DEBUG
       
   529                 // RDebug::Print(_L("CEikScrollBarFrame: Please, use TAknDoubleSpanScrollBarModel instead of TEikScrollBarModel"));
       
   530                 // #endif
       
   531                 // In most cases we can work with the TEikScrollBarModel model.
       
   532     		    iV.iModel.iThumbPosition += aDeltaY;
       
   533                 }
       
   534             }
       
   535 	    ApplyModel(iV);
       
   536         }
       
   537 
       
   538 
       
   539     // Horizontal scrollbar
       
   540     if (aDeltaX && iExtension && iExtension->iH.iBar && TypeOfHScrollBar() == TScrollBarType(EDoubleSpan))
       
   541         {
       
   542         if (iExtension->iH.iModel.ScrollBarModelType() == TEikScrollBarModel::EAknDoubleSpanScrollBarModel)
       
   543             {
       
   544             TAknDoubleSpanScrollBarModel* model = static_cast <TAknDoubleSpanScrollBarModel*> (&(iExtension->iH.iModel));
       
   545             // Note that for a large scroll span and small delta this may not actually change focusposition
       
   546             // because of the 15 bit accuracy of TAknDoubleSpanScrollBarModel values.
       
   547             model->SetFocusPosition(model->FocusPosition() + aDeltaX);    
       
   548             }
       
   549         else
       
   550             {
       
   551             // Error. User of the API is perhaps assigning values directly to TEikScrollBarModel
       
   552             // member variables which is not allowed with EAknDoubleSpanScrollBarModel.
       
   553             // #ifdef _DEBUG
       
   554             // RDebug::Print(_L("CEikScrollBarFrame: Please, use TAknDoubleSpanScrollBarModel instead of TEikScrollBarModel"));
       
   555             // #endif
       
   556             // In most cases we can work with the TEikScrollBarModel model.
       
   557             iExtension->iH.iModel.iThumbPosition += aDeltaX;
       
   558             }
       
   559         ApplyModel(iExtension->iH);
       
   560         }
       
   561 
       
   562 	}
       
   563 
       
   564 EXPORT_C void CEikScrollBarFrame::MoveVertThumbTo(TInt aVertThumbPos)
       
   565 	{
       
   566 	if (iV.iBar)
       
   567 		{
       
   568         if (TypeOfVScrollBar() == TScrollBarType(EArrowHead))
       
   569             {
       
   570     		iV.iModel.iThumbPosition = aVertThumbPos;
       
   571             }
       
   572         else
       
   573             {
       
   574             // EDoubleSpan has different model.
       
   575             if (iV.iModel.ScrollBarModelType() == TEikScrollBarModel::EAknDoubleSpanScrollBarModel)
       
   576                 {
       
   577                 TAknDoubleSpanScrollBarModel* model = static_cast <TAknDoubleSpanScrollBarModel*> (&iV.iModel);
       
   578                 model->SetFocusPosition(aVertThumbPos);    
       
   579                 }
       
   580             else
       
   581                 {
       
   582                 // Error. User of the API is perhaps assigning values directly to TEikScrollBarModel
       
   583                 // member variables which is not allowed with EAknDoubleSpanScrollBarModel.
       
   584                 // #ifdef _DEBUG
       
   585                 // RDebug::Print(_L("CEikScrollBarFrame: Please, use TAknDoubleSpanScrollBarModel instead of TEikScrollBarModel"));
       
   586                 // #endif
       
   587                 // In most cases we can work with the TEikScrollBarModel model.
       
   588         		iV.iModel.iThumbPosition = aVertThumbPos;
       
   589                 }
       
   590             }
       
   591 		ApplyModel(iV);
       
   592 		}
       
   593 	}
       
   594 
       
   595 EXPORT_C void CEikScrollBarFrame::SetVFocusPosToThumbPos(TInt aFocusPosition)
       
   596 	{
       
   597 	MoveVertThumbTo(aFocusPosition);
       
   598 	}
       
   599 
       
   600 EXPORT_C TInt CEikScrollBarFrame::ScrollBarBreadth(CEikScrollBar::TOrientation aOrientation) const
       
   601 	//
       
   602 	// return the appropriate scrollbar's breadth or zero if none exists
       
   603 	//
       
   604 	{
       
   605 	CAknScrollBar* sBar=(CAknScrollBar*)GetScrollBarHandle(aOrientation);
       
   606 	if (!sBar) 
       
   607 		return 0;
       
   608 	return sBar->ScrollBarBreadth(); 
       
   609 	}
       
   610 
       
   611 EXPORT_C TBool CEikScrollBarFrame::ScrollBarExists(CEikScrollBar::TOrientation aOrientation) const
       
   612 	//
       
   613 	// returns ETrue if the specified scrollbar exists
       
   614 	//
       
   615 	{
       
   616 	if (GetScrollBarHandle(aOrientation))
       
   617 		return ETrue;
       
   618 	return EFalse;
       
   619 	}
       
   620 
       
   621 EXPORT_C TInt CEikScrollBarFrame::CountComponentControls() const
       
   622     {
       
   623     TInt numberOfComponents = 0;
       
   624 	
       
   625     if (iV.iBar)
       
   626 		numberOfComponents++;
       
   627 	
       
   628     if (iExtension && iExtension->iH.iBar)
       
   629 		numberOfComponents++;
       
   630 
       
   631     return numberOfComponents;
       
   632     }
       
   633 
       
   634 EXPORT_C CCoeControl* CEikScrollBarFrame::ComponentControl(TInt aIndex) const
       
   635     {
       
   636     if (aIndex == 0)
       
   637         {
       
   638         if (iV.iBar)
       
   639             return iV.iBar;
       
   640         else
       
   641             {
       
   642             if (iExtension && iExtension->iH.iBar)
       
   643                 return iExtension->iH.iBar;
       
   644             }
       
   645         }
       
   646 
       
   647     if (aIndex == 1)
       
   648         {
       
   649         if (iExtension && iExtension->iH.iBar)
       
   650             return iExtension->iH.iBar;
       
   651         else
       
   652             {
       
   653             if (iV.iBar)
       
   654                 return iV.iBar;
       
   655             }
       
   656         }
       
   657 
       
   658 	return NULL;
       
   659     }
       
   660 
       
   661 EXPORT_C CEikScrollBar* CEikScrollBarFrame::GetScrollBarHandle(CEikScrollBar::TOrientation aOrientation) const
       
   662 	//
       
   663 	// returns the pointer to the appropriate scrollbar
       
   664 	//
       
   665 	{
       
   666 	if (aOrientation==CEikScrollBar::EVertical)
       
   667 		{
       
   668 		if (iScrollBarFrameFlags&EDisplayVScrollBar)
       
   669 			return(iV.iBar);
       
   670 		}
       
   671 
       
   672 	if (aOrientation==CEikScrollBar::EHorizontal)
       
   673 		{
       
   674 		if (iScrollBarFrameFlags&EDisplayHScrollBar && iExtension)
       
   675 			return(iExtension->iH.iBar);
       
   676 		}
       
   677 
       
   678 	return(NULL);
       
   679 	}
       
   680 
       
   681 EXPORT_C CEikScrollBar* CEikScrollBarFrame::VerticalScrollBar() const
       
   682 	//
       
   683 	// returns the vertical scroll bar
       
   684 	//
       
   685 	{
       
   686 	return iV.iBar;
       
   687 	}
       
   688 
       
   689 void CEikScrollBarFrame::CalcTheoreticalScrollBarVisibility(const TEikScrollBarModel* aVModel)
       
   690 	//
       
   691 	// Determines which scrollbars are necessary before size considerations are taken into account
       
   692 	//
       
   693 	{
       
   694 	// assume no scrollbars to start with
       
   695 	iScrollBarFrameFlags&=(~EDisplayVScrollBar);
       
   696     
       
   697     TBool scrollBarUseful = EFalse;
       
   698 
       
   699     switch(TypeOfVScrollBar())
       
   700         {
       
   701         case EDoubleSpan:
       
   702             {
       
   703             if (aVModel->ScrollBarModelType() == TEikScrollBarModel::EAknDoubleSpanScrollBarModel)
       
   704                 {
       
   705                 //const TAknDoubleSpanScrollBarModel* model = static_cast <const TAknDoubleSpanScrollBarModel*> (aVModel);
       
   706                 //scrollBarUseful = (model->FocusPosition() < model->ScrollSpan()) && (model->WindowSize() < model->ScrollSpan());    
       
   707                 scrollBarUseful = ETrue; // S60 style says double span scrollbar is always shown if visibility is EAuto
       
   708                 }
       
   709             else
       
   710                 {
       
   711                 // Error. User of the API is perhaps assigning values directly to TEikScrollBarModel
       
   712                 // member variables which is not allowed with EAknDoubleSpanScrollBarModel.
       
   713                 //#ifdef _DEBUG
       
   714                 //RDebug::Print(_L("CEikScrollBarFrame: Please, use TAknDoubleSpanScrollBarModel instead of TEikScrollBarModel"));
       
   715                 //#endif
       
   716                 // In most cases we can work with the TEikScrollBarModel model.
       
   717                 //scrollBarUseful = (aVModel->iThumbPosition < aVModel->iScrollSpan) && (aVModel->iThumbSpan < aVModel->iScrollSpan);    
       
   718                 scrollBarUseful = ETrue; // S60 style says double span scrollbar is always shown if visibility is EAuto
       
   719                 }
       
   720             break;
       
   721             }
       
   722 
       
   723         case EArrowHead: // fallthrough
       
   724         default:
       
   725             {
       
   726             scrollBarUseful = aVModel->ScrollBarUseful();
       
   727             break;
       
   728             }
       
   729         }
       
   730 
       
   731     if ( (iV.iVisibility==EOn) || ( (iV.iVisibility==EAuto)&&(scrollBarUseful) ) )
       
   732         {
       
   733         iScrollBarFrameFlags|=EDisplayVScrollBar;
       
   734         }
       
   735 
       
   736 	}
       
   737 
       
   738 CEikCba* CEikScrollBarFrame::GetCurrentCba()
       
   739 	{
       
   740 	CEikCba* mopCba = NULL;
       
   741     if (iExtension && iExtension->iParentWindow)
       
   742         mopCba=iExtension->iParentWindow->MopGetObject(mopCba);
       
   743 	return mopCba;
       
   744 	}
       
   745 
       
   746 void CEikScrollBarFrame::ApplyModel(SBarData& aSBar)
       
   747 	{
       
   748 	if (iExtension && iExtension->iParentWindow && iExtension->iParentWindow->IsVisible() 
       
   749 	        && aSBar.iBar && aSBar.iBar->IsVisible())
       
   750 		{
       
   751 		aSBar.iBar->SetModel(&aSBar.iModel);
       
   752 		}		
       
   753 	}
       
   754 
       
   755 void CEikScrollBarFrame::MakeSBarVisible(SBarData& aSBar, TBool aVisible)
       
   756 	{
       
   757 	if (iExtension && iExtension->iParentWindow->IsVisible() && aSBar.iBar)
       
   758 		{
       
   759 		if (aVisible && iExtension->iParentWindow->IsVisible())
       
   760 		    {
       
   761 		    aSBar.iBar->SetModel(&aSBar.iModel);
       
   762 		    aSBar.iBar->MakeVisible(ETrue);
       
   763 		    }
       
   764 		else if(!aVisible)
       
   765 		    {
       
   766 		    aSBar.iBar->MakeVisible(EFalse);
       
   767 		    }
       
   768 		}
       
   769     else if (TypeOfVScrollBar() == TScrollBarType(EDoubleSpan) && aSBar.iBar)
       
   770         aSBar.iBar->SetModel(&aSBar.iModel);
       
   771 	}
       
   772 
       
   773 void CEikScrollBarFrame::SetParentWindow(CCoeControl* aParentWindow)
       
   774 	{
       
   775 	if (iExtension)
       
   776         {
       
   777         iExtension->iParentWindow=aParentWindow;
       
   778         }
       
   779     else
       
   780         {
       
   781         iExtension = new CEikScrollBarFrameExtension();
       
   782         if (iExtension)
       
   783             {
       
   784             iExtension->iParentWindow = aParentWindow;
       
   785             iExtension->iH.iModel = TAknDoubleSpanScrollBarModel();
       
   786             iExtension->iH.iBar = NULL;
       
   787             iExtension->iH.iExternalScrollBarAttached = EFalse;
       
   788             iExtension->iH.iVisibility = EOff; 
       
   789             }
       
   790         }
       
   791 	}
       
   792 
       
   793 CCoeControl* CEikScrollBarFrame::ParentWindow() const
       
   794 	{
       
   795     if (iExtension)
       
   796         {
       
   797         return iExtension->iParentWindow;
       
   798         }
       
   799     else
       
   800         {
       
   801         return NULL;
       
   802         }
       
   803 	}
       
   804 
       
   805 
       
   806 
       
   807 EXPORT_C void CEikScrollBarFrame::SetScrollBarFrameObserver(MEikScrollBarObserver* aObserver)
       
   808 	{
       
   809     if( !AknLayoutUtils::PenEnabled() )
       
   810         {
       
   811         return;
       
   812         }
       
   813     
       
   814     iExtension->iScrollBarObserver = aObserver;
       
   815     
       
   816     if(iV.iBar)
       
   817         {
       
   818         iV.iBar->SetScrollBarObserver(aObserver);
       
   819         }
       
   820     if(iExtension && iExtension->iH.iBar)
       
   821         {
       
   822         iExtension->iH.iBar->SetScrollBarObserver(aObserver);
       
   823         }
       
   824 	}
       
   825 
       
   826 MEikScrollBarObserver* CEikScrollBarFrame::ScrollBarFrameObserver()
       
   827 	{
       
   828 	if(AknLayoutUtils::PenEnabled())
       
   829         return iExtension->iScrollBarObserver;
       
   830 	else
       
   831 	    return NULL;
       
   832 	}
       
   833 
       
   834 // Functions which don't do anything useful in the avkon UI
       
   835 EXPORT_C void CEikScrollBarFrame::SetAdjustsHorizontalModel(TBool /*aAdjusts*/)
       
   836 	{
       
   837 	}
       
   838 
       
   839 EXPORT_C void CEikScrollBarFrame::SetAdjustsVerticalModel(TBool /*aAdjusts*/)
       
   840 	{
       
   841 	}
       
   842 
       
   843 EXPORT_C void CEikScrollBarFrame::MoveHorizThumbTo(TInt aHorizThumbPos)
       
   844 	{
       
   845 	if (iExtension && iExtension->iH.iBar)
       
   846 		{
       
   847         if (TypeOfVScrollBar() == TScrollBarType(EDoubleSpan))
       
   848             {
       
   849             // EDoubleSpan has different model.
       
   850             if (iV.iModel.ScrollBarModelType() == TEikScrollBarModel::EAknDoubleSpanScrollBarModel)
       
   851                 {
       
   852                 TAknDoubleSpanScrollBarModel* model = static_cast <TAknDoubleSpanScrollBarModel*> (&(iExtension->iH.iModel));
       
   853                 model->SetFocusPosition(aHorizThumbPos);    
       
   854                 }
       
   855             else
       
   856                 {
       
   857                 // Error. User of the API is perhaps assigning values directly to TEikScrollBarModel
       
   858                 // member variables which is not allowed with EAknDoubleSpanScrollBarModel.
       
   859                 // #ifdef _DEBUG
       
   860                 // RDebug::Print(_L("CEikScrollBarFrame: Please, use TAknDoubleSpanScrollBarModel instead of TEikScrollBarModel"));
       
   861                 // #endif
       
   862                 // In most cases we can work with the TEikScrollBarModel model.
       
   863         		iExtension->iH.iModel.iThumbPosition = aHorizThumbPos;
       
   864                 }
       
   865             }
       
   866 		ApplyModel(iExtension->iH);
       
   867 		}
       
   868 	}
       
   869 
       
   870 EXPORT_C void CEikScrollBarFrame::SetTypeOfHScrollBar(TScrollBarType aType)
       
   871 	{
       
   872     if (iExtension && iExtension->iH.iBar)
       
   873         {
       
   874         if (TypeOfHScrollBar() == aType)
       
   875             return; // already set to requested type
       
   876 
       
   877         if (aType == CEikScrollBarFrame::TScrollBarType(EDoubleSpan))
       
   878             {
       
   879             TRAP_IGNORE(CreateDoubleSpanScrollBarsL(ETrue,EFalse)); // by default a window owning                
       
   880             return;    
       
   881             }
       
   882 
       
   883         if (aType == CEikScrollBarFrame::TScrollBarType(EArrowHead))
       
   884             {
       
   885             return; // not supported   
       
   886             }
       
   887         }
       
   888 	}
       
   889 
       
   890 EXPORT_C void CEikScrollBarFrame::SetTypeOfVScrollBar(TScrollBarType aType)
       
   891 	{
       
   892     if (iV.iBar)
       
   893         {
       
   894         if (TypeOfVScrollBar() == aType)
       
   895             return; // already set to requested type
       
   896 
       
   897 
       
   898         if (aType == CEikScrollBarFrame::TScrollBarType(EDoubleSpan))
       
   899             {
       
   900             TRAP_IGNORE(CreateDoubleSpanScrollBarsL(ETrue,EFalse)); // by default a window owning                
       
   901             return;    
       
   902             }
       
   903 
       
   904         if (aType == CEikScrollBarFrame::TScrollBarType(EArrowHead))
       
   905             {
       
   906             TRAP_IGNORE(CreateArrowHeadScrollBarsL());
       
   907             return;    
       
   908             }
       
   909         }
       
   910 	}
       
   911 
       
   912 EXPORT_C CEikScrollBarFrame::TScrollBarType CEikScrollBarFrame::TypeOfHScrollBar() const
       
   913 	{
       
   914     if (iExtension && iExtension->iH.iBar && 
       
   915        (iExtension->iH.iBar->ScrollBarType() == CEikScrollBar::TScrollBarType(EDoubleSpan)))
       
   916         {
       
   917         return EDoubleSpan;
       
   918         }
       
   919     else
       
   920         {
       
   921 	    return EArrowHead;
       
   922         }
       
   923 	}
       
   924 
       
   925 EXPORT_C CEikScrollBarFrame::TScrollBarType CEikScrollBarFrame::TypeOfVScrollBar() const
       
   926 	{
       
   927     if (iV.iBar && (iV.iBar->ScrollBarType() == CEikScrollBar::TScrollBarType(EDoubleSpan)))
       
   928         {
       
   929         return EDoubleSpan;
       
   930         }
       
   931     else
       
   932         {
       
   933 	    return EArrowHead;
       
   934         }
       
   935 	}
       
   936 
       
   937 EXPORT_C TBool CEikScrollBarFrame::IsArrowHeadScrollBar(TInt /*aFlag*/) const
       
   938 	{
       
   939     if (TypeOfVScrollBar() == TScrollBarType(EArrowHead))
       
   940         {
       
   941         return ETrue;
       
   942         }
       
   943     else
       
   944         {
       
   945         return EFalse;
       
   946         }
       
   947 	}
       
   948 
       
   949 EXPORT_C void CEikScrollBarFrame::CreateDoubleSpanScrollBarsL(TBool aWindowOwning, TBool aRemote)
       
   950     {
       
   951     CreateDoubleSpanScrollBarsL(aWindowOwning, aRemote, ETrue, ETrue);
       
   952     }
       
   953 
       
   954 EXPORT_C void CEikScrollBarFrame::CreateDoubleSpanScrollBarsL(TBool aWindowOwning, TBool aRemote, TBool aVertical, TBool aHorizontal)
       
   955     {
       
   956     if (!TAknDoubleSpanScrollBarModel::ModelIsSupported())
       
   957         {
       
   958         return;
       
   959         }
       
   960 
       
   961     // This method should not delete the old scrollbars before it is sure that new 
       
   962     // one has been succesfully created. Create a temp variable here.
       
   963     SBarData newVerticalScrollBar;
       
   964     newVerticalScrollBar.iBar = NULL;
       
   965     newVerticalScrollBar.iExternalScrollBarAttached = EFalse;
       
   966     newVerticalScrollBar.iVisibility = iV.iVisibility;
       
   967 
       
   968     SBarData newHorizontalScrollBar;
       
   969     newHorizontalScrollBar.iBar = NULL;
       
   970     newHorizontalScrollBar.iExternalScrollBarAttached = EFalse;
       
   971     if (iExtension)
       
   972         newHorizontalScrollBar.iVisibility = iExtension->iH.iVisibility;
       
   973 
       
   974     if (aRemote && iExtension && iExtension->iParentWindow)
       
   975         {
       
   976         // try getting scrollbarframe from parent using mop supply mechanism
       
   977         CEikScrollBarFrame* sbf = iExtension->iParentWindow->MopGetObject(sbf);
       
   978         if (sbf)
       
   979             {
       
   980             newVerticalScrollBar.iBar = sbf->VerticalScrollBar();
       
   981             newVerticalScrollBar.iExternalScrollBarAttached = ETrue;
       
   982             
       
   983             newHorizontalScrollBar.iBar = sbf->HorizontalScrollBar();
       
   984             newHorizontalScrollBar.iExternalScrollBarAttached = ETrue;
       
   985             
       
   986             TInt err1 = KErrNone;
       
   987             TInt err2 = KErrNone;
       
   988             if (newVerticalScrollBar.iBar)
       
   989                 {
       
   990                 TRAP(err1, newVerticalScrollBar.iBar->AddExternalFrameL(this));
       
   991                 }
       
   992 
       
   993             if (newHorizontalScrollBar.iBar)
       
   994                 {
       
   995                 TRAP(err2, newHorizontalScrollBar.iBar->AddExternalFrameL(this));
       
   996                 }
       
   997             
       
   998             if (err1 || err2)
       
   999 	            {
       
  1000 	            newVerticalScrollBar.iExternalScrollBarAttached = EFalse;
       
  1001 	            newVerticalScrollBar.iBar = NULL;
       
  1002 	            newHorizontalScrollBar.iExternalScrollBarAttached = EFalse;
       
  1003 	            newHorizontalScrollBar.iBar = NULL;
       
  1004 	            }
       
  1005 
       
  1006             User::LeaveIfError(err1);
       
  1007             User::LeaveIfError(err2);
       
  1008 
       
  1009             if (TypeOfVScrollBar() == EDoubleSpan)
       
  1010                 {
       
  1011                 if( AknLayoutUtils::PenEnabled() )
       
  1012                     {
       
  1013 	    			// Correction. Giving null reference as parameter screws up the model values
       
  1014                     newVerticalScrollBar.iModel = TAknDoubleSpanScrollBarModel();
       
  1015                     }
       
  1016                 else
       
  1017                     {
       
  1018                     newVerticalScrollBar.iModel = TAknDoubleSpanScrollBarModel(0);
       
  1019                     }
       
  1020                 }
       
  1021 
       
  1022             if (TypeOfHScrollBar() == EDoubleSpan)
       
  1023                 {
       
  1024                 if( AknLayoutUtils::PenEnabled() )
       
  1025                     {
       
  1026                     // Correction. Giving null reference as parameter screws up the model values
       
  1027                     newHorizontalScrollBar.iModel = TAknDoubleSpanScrollBarModel();
       
  1028                     }
       
  1029                 else
       
  1030                     {
       
  1031                     newHorizontalScrollBar.iModel = TAknDoubleSpanScrollBarModel(0);
       
  1032                     }
       
  1033                 }
       
  1034 
       
  1035             }
       
  1036         else
       
  1037             {
       
  1038             User::Leave(KErrNotFound);
       
  1039             }
       
  1040         }
       
  1041     else
       
  1042         {
       
  1043         // Create new vertical AknDoubleSpanScrollBar
       
  1044         newVerticalScrollBar.iBar = 0;
       
  1045         newVerticalScrollBar.iExternalScrollBarAttached=EFalse;
       
  1046         
       
  1047         CAknDoubleSpanScrollBar* verticalScrollBar = NULL;
       
  1048 
       
  1049         MEikScrollBarObserver* observer = NULL;
       
  1050 
       
  1051         if(AknLayoutUtils::PenEnabled())
       
  1052             {
       
  1053             if(iExtension)
       
  1054                 {
       
  1055                 observer = iExtension->iScrollBarObserver;
       
  1056                 }
       
  1057             }
       
  1058 
       
  1059         TInt scrollBarFlags = 
       
  1060             ( ( iScrollBarFrameFlags & EEnableNudgeButtons ) ? 
       
  1061                 CEikScrollBar::EEnableNudgeButtons : 0 ) |
       
  1062             ( ( iScrollBarFrameFlags & EDisableExpandedTouchArea ) ? 
       
  1063                 CEikScrollBar::EDisableExpandedTouchArea : 0 );
       
  1064                 
       
  1065         if (aVertical)
       
  1066             {
       
  1067             verticalScrollBar = new(ELeave) CAknDoubleSpanScrollBar(ParentWindow());            
       
  1068             CleanupStack::PushL(verticalScrollBar);
       
  1069             verticalScrollBar->ConstructL(
       
  1070                 aWindowOwning, observer ,ParentWindow(),
       
  1071                 CAknScrollBar::EVertical,
       
  1072                 KLongEnoughToCauseComponentsToBeCreated,
       
  1073                 scrollBarFlags );
       
  1074             CleanupStack::Pop(); // verticalScrollBar
       
  1075             }
       
  1076         newVerticalScrollBar.iBar = verticalScrollBar;
       
  1077         if( AknLayoutUtils::PenEnabled() )
       
  1078             {
       
  1079             // Correction. Giving null reference as parameter screws up the model values
       
  1080             newVerticalScrollBar.iModel = TAknDoubleSpanScrollBarModel();
       
  1081             }
       
  1082         else
       
  1083             {
       
  1084             newVerticalScrollBar.iModel = TAknDoubleSpanScrollBarModel(0);
       
  1085             }
       
  1086 
       
  1087         // Create new horizontal AknDoubleSpanScrollBar
       
  1088         newHorizontalScrollBar.iBar = 0;
       
  1089         newHorizontalScrollBar.iExternalScrollBarAttached=EFalse;
       
  1090         CAknDoubleSpanScrollBar* horizontalScrollBar = NULL;
       
  1091        
       
  1092         if (aHorizontal)
       
  1093             {
       
  1094             horizontalScrollBar = new(ELeave) CAknDoubleSpanScrollBar(ParentWindow());
       
  1095             CleanupStack::PushL(horizontalScrollBar);
       
  1096             horizontalScrollBar->ConstructL(
       
  1097                 aWindowOwning, observer ,ParentWindow(),
       
  1098                 CAknScrollBar::EHorizontal,
       
  1099                 KLongEnoughToCauseComponentsToBeCreated,
       
  1100                 scrollBarFlags );
       
  1101             CleanupStack::Pop(); // horizontalScrollBar
       
  1102             }
       
  1103         newHorizontalScrollBar.iBar = horizontalScrollBar;        
       
  1104         if( AknLayoutUtils::PenEnabled() )
       
  1105             {
       
  1106             // Correction. Giving null reference as parameter screws up the model values
       
  1107             newHorizontalScrollBar.iModel = TAknDoubleSpanScrollBarModel();
       
  1108             }
       
  1109         else
       
  1110             {
       
  1111             newHorizontalScrollBar.iModel = TAknDoubleSpanScrollBarModel(0);
       
  1112             }
       
  1113         }
       
  1114 
       
  1115     TBool oldVerticalScrollbarExists = EFalse;
       
  1116     TBool oldHorizontalScrollbarExists = EFalse;
       
  1117 
       
  1118     if (iV.iBar)
       
  1119         oldVerticalScrollbarExists = ETrue;
       
  1120 
       
  1121     if (iExtension && iExtension->iH.iBar)
       
  1122         oldHorizontalScrollbarExists = ETrue;
       
  1123 
       
  1124     
       
  1125     if (oldVerticalScrollbarExists || oldHorizontalScrollbarExists)
       
  1126         {
       
  1127         // Remove old scroll bar
       
  1128         DeleteScrollBars();
       
  1129         }
       
  1130     
       
  1131     iV = newVerticalScrollBar;
       
  1132     
       
  1133     if (iExtension)
       
  1134         iExtension->iH = newHorizontalScrollBar;
       
  1135 
       
  1136     }
       
  1137 
       
  1138 
       
  1139 EXPORT_C void CEikScrollBarFrame::Tile(TEikScrollBarModel* aVModel, TRect& aVScrollBarRect)
       
  1140     {
       
  1141 	Tile(aVModel);
       
  1142 	TRect tempRect(aVScrollBarRect);
       
  1143     if(aVScrollBarRect.Height() < 0 )
       
  1144         {
       
  1145         aVScrollBarRect.iTl.iY = aVScrollBarRect.iBr.iY;
       
  1146         aVScrollBarRect.iBr.iY = tempRect.iTl.iY;
       
  1147         }
       
  1148     if(aVScrollBarRect.Width() < 0 )
       
  1149         {
       
  1150         aVScrollBarRect.iTl.iX = aVScrollBarRect.iBr.iX;
       
  1151         aVScrollBarRect.iBr.iX = tempRect.iTl.iX;
       
  1152         }
       
  1153     if (iV.iBar && TypeOfVScrollBar() == EDoubleSpan && iV.iExternalScrollBarAttached==EFalse )
       
  1154         {
       
  1155         CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iV.iBar);
       
  1156         // check if fixed layout has been set
       
  1157         if (scrollbar->FixedLayoutRect().Size() == TSize(0,0))
       
  1158             {
       
  1159             if (aVScrollBarRect != TRect(iV.iBar->Position(), iV.iBar->Size()))
       
  1160                 {
       
  1161                 iV.iBar->SetRect(aVScrollBarRect);
       
  1162                 }
       
  1163             }
       
  1164         }
       
  1165     }
       
  1166 
       
  1167 
       
  1168 void CEikScrollBarFrame::DeleteScrollBars()
       
  1169     {
       
  1170     //
       
  1171     // Delete vertical scollbar
       
  1172     //
       
  1173     if(!iV.iExternalScrollBarAttached)
       
  1174         delete(iV.iBar);
       
  1175     else if (iV.iBar)
       
  1176 	    {
       
  1177 	    if (iExtension && iExtension->iParentWindow && iExtension->iParentWindow->IsVisible())
       
  1178 		    {
       
  1179 		    // This test will be false if the app is being destroyed, making it unsafe to resize the CBA.
       
  1180 		    if (CCoeEnv::Static()->NormalFont())
       
  1181 			    iV.iBar->MakeVisible(EFalse);
       
  1182 		    }
       
  1183 	    iV.iBar->RemoveExternalFrame(this);		// calls back to DisconnectExternalScrollBar to null iV.iBar
       
  1184 	    __ASSERT_DEBUG(iV.iBar == NULL, SbfPanic(EFailedToRemoveExternalScrollBar));
       
  1185 	    }
       
  1186 
       
  1187     //
       
  1188     // Delete horizontal scrollbar
       
  1189     //
       
  1190     if(iExtension && iExtension->iH.iBar)
       
  1191         {
       
  1192         if(!(iExtension->iH.iExternalScrollBarAttached))
       
  1193             {
       
  1194             delete(iExtension->iH.iBar);
       
  1195             iExtension->iH.iBar = NULL;
       
  1196             }
       
  1197         else if (iExtension->iH.iBar)
       
  1198 	        {
       
  1199 	        if (iExtension && iExtension->iParentWindow && iExtension->iParentWindow->IsVisible())
       
  1200 		        {
       
  1201 		        // This test will be false if the app is being destroyed, making it unsafe to resize the CBA.
       
  1202 		        if (CCoeEnv::Static()->NormalFont())
       
  1203 			        iExtension->iH.iBar->MakeVisible(EFalse);
       
  1204 		        }
       
  1205 	        iExtension->iH.iBar->RemoveExternalFrame(this);		// calls back to DisconnectExternalScrollBar to null iV.iBar
       
  1206 	        __ASSERT_DEBUG(iExtension->iH.iBar == NULL, SbfPanic(EFailedToRemoveExternalScrollBar));
       
  1207 	        }    
       
  1208         }
       
  1209     }
       
  1210 
       
  1211 
       
  1212 void CEikScrollBarFrame::CreateArrowHeadScrollBarsL()
       
  1213     {
       
  1214     CEikCba* cba=GetCurrentCba();
       
  1215     if (cba)
       
  1216         {
       
  1217         // create arrow heads
       
  1218         TRAPD(err, cba->CreateArrowHeadScrollBarL()); 
       
  1219         if (err)
       
  1220             {
       
  1221 		    iV.iExternalScrollBarAttached = EFalse;
       
  1222 		    iV.iBar = NULL;
       
  1223 	        return;
       
  1224             }
       
  1225         // delete old scroll bars
       
  1226         DeleteScrollBars();
       
  1227         // returns the vertical scroll bar from the top scroll bar host
       
  1228 		iV.iBar=cba->VScrollBarAsControl();
       
  1229 		iV.iExternalScrollBarAttached=ETrue;
       
  1230 		TRAPD(err2, iV.iBar->AddExternalFrameL(this));
       
  1231 		if (err2)
       
  1232 		    {
       
  1233 			iV.iExternalScrollBarAttached = EFalse;
       
  1234 			iV.iBar = NULL;
       
  1235 			}
       
  1236 		}
       
  1237     }
       
  1238 
       
  1239 void CEikScrollBarFrame::CalcTheoreticalScrollBarVisibility(const TEikScrollBarModel* aVModel, const TEikScrollBarModel* aHModel)
       
  1240     {
       
  1241 	// assume no scrollbars to start with
       
  1242     iScrollBarFrameFlags&=(~EDisplayVScrollBar);
       
  1243 	iScrollBarFrameFlags&=(~EDisplayHScrollBar);
       
  1244     
       
  1245     TBool verticalScrollBarUseful = EFalse;
       
  1246     TBool horizontalScrollBarUseful = EFalse;
       
  1247 
       
  1248     if (aVModel)
       
  1249         {
       
  1250         switch(TypeOfVScrollBar())
       
  1251             {
       
  1252             case EDoubleSpan:
       
  1253                 {
       
  1254                 if (aVModel->ScrollBarModelType() == TEikScrollBarModel::EAknDoubleSpanScrollBarModel)
       
  1255                     {
       
  1256                     //const TAknDoubleSpanScrollBarModel* model = static_cast <const TAknDoubleSpanScrollBarModel*> (aVModel);
       
  1257                     //verticalScrollBarUseful = (model->FocusPosition() < model->ScrollSpan()) && (model->WindowSize() <= model->ScrollSpan());    
       
  1258                     verticalScrollBarUseful = ETrue; // S60 style says double span scrollbar is always shown if visibility is EAuto
       
  1259                     }
       
  1260                 else
       
  1261                     {
       
  1262                     // Error. User of the API is perhaps assigning values directly to TEikScrollBarModel
       
  1263                     // member variables which is not allowed with EAknDoubleSpanScrollBarModel.
       
  1264                     //#ifdef _DEBUG
       
  1265                     //RDebug::Print(_L("CEikScrollBarFrame: Please, use TAknDoubleSpanScrollBarModel instead of TEikScrollBarModel"));
       
  1266                     //#endif
       
  1267                     // In most cases we can work with the TEikScrollBarModel model.
       
  1268                     //verticalScrollBarUseful = (aVModel->iThumbPosition < aVModel->iScrollSpan) && (aVModel->iThumbSpan <= aVModel->iScrollSpan);    
       
  1269                     verticalScrollBarUseful = ETrue; // S60 style says double span scrollbar is always shown if visibility is EAuto
       
  1270                     }
       
  1271                 break;
       
  1272                 }
       
  1273 
       
  1274             case EArrowHead: // fallthrough
       
  1275             default:
       
  1276                 {
       
  1277                 verticalScrollBarUseful = aVModel->ScrollBarUseful();
       
  1278                 break;
       
  1279                 }
       
  1280             }
       
  1281         }
       
  1282 
       
  1283     if (aHModel)
       
  1284         {
       
  1285         switch(TypeOfHScrollBar())
       
  1286             {
       
  1287             case EDoubleSpan: // by default only double span is supported as horizontal scrollbar
       
  1288             default:
       
  1289                 {
       
  1290                 if (aHModel->ScrollBarModelType() == TEikScrollBarModel::EAknDoubleSpanScrollBarModel)
       
  1291                     {
       
  1292                     //const TAknDoubleSpanScrollBarModel* model = static_cast <const TAknDoubleSpanScrollBarModel*> (aHModel);
       
  1293                     //horizontalScrollBarUseful = (model->FocusPosition() < model->ScrollSpan()) && (model->WindowSize() <= model->ScrollSpan());    
       
  1294                     horizontalScrollBarUseful = ETrue; // S60 style says double span scrollbar is always shown if visibility is EAuto
       
  1295                     }
       
  1296                 else
       
  1297                     {
       
  1298                     // Error. User of the API is perhaps assigning values directly to TEikScrollBarModel
       
  1299                     // member variables which is not allowed with EAknDoubleSpanScrollBarModel.
       
  1300                     //#ifdef _DEBUG
       
  1301                     //RDebug::Print(_L("CEikScrollBarFrame: Please, use TAknDoubleSpanScrollBarModel instead of TEikScrollBarModel"));
       
  1302                     //#endif
       
  1303                     // In most cases we can work with the TEikScrollBarModel model.
       
  1304                     //horizontalScrollBarUseful = (aHModel->iThumbPosition < aHModel->iScrollSpan) && (aHModel->iThumbSpan <= aVModel->iScrollSpan);    
       
  1305                     horizontalScrollBarUseful = ETrue; // S60 style says double span scrollbar is always shown if visibility is EAuto
       
  1306                     }
       
  1307                 break;
       
  1308                 }
       
  1309             }
       
  1310         }
       
  1311 
       
  1312 
       
  1313     // Decide visibility for vertical scrollbar
       
  1314     if ( (iV.iVisibility==EOn) || ( (iV.iVisibility==EAuto)&&(verticalScrollBarUseful) ) )
       
  1315         {
       
  1316         iScrollBarFrameFlags|=EDisplayVScrollBar;
       
  1317         }
       
  1318 
       
  1319     // Decide visibility for horizontal scrollbar
       
  1320     if (iExtension && (iExtension->iH.iVisibility==EOn || (iExtension->iH.iVisibility==EAuto && horizontalScrollBarUseful)))
       
  1321         {
       
  1322         iScrollBarFrameFlags|=EDisplayHScrollBar;
       
  1323         }
       
  1324     }
       
  1325 
       
  1326 EXPORT_C CEikScrollBarFrame::TScrollBarVisibility CEikScrollBarFrame::ScrollBarVisibility(CEikScrollBar::TOrientation aOrientation) const
       
  1327     {
       
  1328     if (aOrientation == CEikScrollBar::EVertical)
       
  1329         {
       
  1330         return iV.iVisibility;
       
  1331         }
       
  1332     else
       
  1333         {
       
  1334         if (iExtension)
       
  1335             {
       
  1336             return iExtension->iH.iVisibility;
       
  1337             }
       
  1338         else
       
  1339             {
       
  1340             return EOff;
       
  1341             }
       
  1342 
       
  1343         }
       
  1344     }
       
  1345 
       
  1346 EXPORT_C void CEikScrollBarFrame::Tile(TEikScrollBarModel* aHModel, TEikScrollBarModel* aVModel)
       
  1347     {
       
  1348 	GetScrollBars(EFalse);
       
  1349 	CalcTheoreticalScrollBarVisibility(aVModel,aHModel);
       
  1350 	
       
  1351 	if (iV.iVisibility!=EOff)
       
  1352 		iV.iModel = *aVModel;
       
  1353     
       
  1354     MakeSBarVisible(iV, iScrollBarFrameFlags&EDisplayVScrollBar);
       
  1355 	
       
  1356     if (iExtension && iExtension->iH.iBar)
       
  1357         {
       
  1358    	    if (iExtension->iH.iVisibility!=EOff)
       
  1359 	        iExtension->iH.iModel = *aHModel;
       
  1360    	    
       
  1361    	    MakeSBarVisible(iExtension->iH, iScrollBarFrameFlags&EDisplayHScrollBar);
       
  1362         }
       
  1363 
       
  1364     }
       
  1365 
       
  1366 EXPORT_C TInt CEikScrollBarFrame::DrawBackground(TBool aDrawHorizontal, TBool aDrawVertical)
       
  1367 	{
       
  1368 	// The double span scrollbar only supports backgroun drawing flag
       
  1369 	if(TypeOfHScrollBar() != EDoubleSpan && TypeOfVScrollBar() != EDoubleSpan)
       
  1370 		{
       
  1371 		return KErrNotSupported;
       
  1372 		}
       
  1373 	
       
  1374 	if(iV.iBar && (TypeOfVScrollBar() == EDoubleSpan))
       
  1375 		{
       
  1376 		CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iV.iBar);
       
  1377 		scrollbar->DrawBackground(aDrawVertical);
       
  1378 		}
       
  1379 	
       
  1380 	if(iExtension && iExtension->iH.iBar && (TypeOfHScrollBar() == EDoubleSpan))
       
  1381 		{
       
  1382 		CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iExtension->iH.iBar);
       
  1383 		scrollbar->DrawBackground(aDrawHorizontal);
       
  1384 		}
       
  1385 	
       
  1386 	return KErrNone;				
       
  1387 	}
       
  1388 	
       
  1389 EXPORT_C TInt CEikScrollBarFrame::DrawBackgroundState(TBool& aDrawHorizontal, TBool& aDrawVertical)
       
  1390 	{
       
  1391 	// The double span scrollbar only supports backgroun drawing flag
       
  1392 		
       
  1393 	if(iV.iBar && (TypeOfVScrollBar() == EDoubleSpan))
       
  1394 		{
       
  1395 		CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iV.iBar);		
       
  1396 		aDrawVertical = scrollbar->DrawBackgroundState();
       
  1397 		}
       
  1398 	
       
  1399 	if(iExtension && iExtension->iH.iBar && (TypeOfHScrollBar() == EDoubleSpan))
       
  1400 		{
       
  1401 		CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iExtension->iH.iBar);
       
  1402 		aDrawHorizontal = scrollbar->DrawBackgroundState();
       
  1403 		}
       
  1404 	
       
  1405 	if(TypeOfHScrollBar() != EDoubleSpan && TypeOfVScrollBar() != EDoubleSpan)
       
  1406 		{
       
  1407 		return KErrNotSupported;
       
  1408 		}
       
  1409 	
       
  1410 	return KErrNone;
       
  1411 	}
       
  1412 
       
  1413 CEikScrollBar* CEikScrollBarFrame::HorizontalScrollBar() const
       
  1414     {
       
  1415     if (iExtension)
       
  1416         return iExtension->iH.iBar;
       
  1417     else
       
  1418         return NULL;
       
  1419     }
       
  1420 
       
  1421 
       
  1422 
       
  1423 // For Cba Scrollbar frame
       
  1424 
       
  1425 CEikCbaScrollBarFrame::CEikCbaScrollBarFrame(CCoeControl* aParentWindow, MEikScrollBarObserver* /*aObserver*/, TBool /*aPreAlloc*/)
       
  1426 	{
       
  1427 	SetParentWindow(aParentWindow);
       
  1428 	}
       
  1429 
       
  1430 void CEikCbaScrollBarFrame::ConstructL()
       
  1431 	{
       
  1432     iV.iBar = 0;
       
  1433     iV.iExternalScrollBarAttached=EFalse;
       
  1434     
       
  1435     // We construct CEikScrollBar instance here, because it doesn't create bitmaps -> faster 
       
  1436     // and save RAM. If CBAs are really needed, then we replace CEikScrollBar with  
       
  1437     // CAknArrowHeadScrollBar instance at SwitchArrowHeadScrollBarL method.
       
  1438     iV.iBar = new(ELeave) CEikScrollBar();
       
  1439     iV.iBar->ConstructL(NULL,ParentWindow(),CAknScrollBar::EVertical,KLongEnoughToCauseComponentsToBeCreated,0);
       
  1440 	}
       
  1441 	
       
  1442 // Delete CEikScrollBar instance and replace it with actual arrow head scroll bar
       
  1443 void CEikCbaScrollBarFrame::SwitchToArrowHeadScrollBarL()
       
  1444 	{
       
  1445 	delete(iV.iBar);
       
  1446 	iV.iBar = 0;
       
  1447 	iV.iExternalScrollBarAttached=EFalse;
       
  1448 	iV.iBar = new(ELeave) CAknArrowHeadScrollBar(ParentWindow());
       
  1449 	iV.iBar->ConstructL(NULL,ParentWindow(),CAknScrollBar::EVertical,KLongEnoughToCauseComponentsToBeCreated,0);
       
  1450 	}
       
  1451