javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtscrollablebase.cpp
branchRCL_3
changeset 19 04becd199f91
child 60 6c158198356e
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 
       
    13 #include <AknUtils.h>
       
    14 #include <eiksbfrm.h>
       
    15 #include "swtscrollablebase.h"
       
    16 #include "swtscrollbar.h"
       
    17 
       
    18 
       
    19 // ======== MEMBER FUNCTIONS ========
       
    20 
       
    21 
       
    22 TRect ASwtScrollableBase::SbInnerRect(const TRect& aOuterRect) const
       
    23 {
       
    24     TRect innerRect(aOuterRect);
       
    25     CEikScrollBarFrame* sbFrame = SbFrame();
       
    26 
       
    27     if (sbFrame)
       
    28     {
       
    29         const CEikScrollBar* hsb = iHScroll ?
       
    30                                    &iHScroll->EikScrollBar() :
       
    31                                    sbFrame->GetScrollBarHandle(CEikScrollBar::EHorizontal);
       
    32         if (hsb && hsb->IsVisible())
       
    33         {
       
    34             TInt height = iDisplay.UiUtils().ScrollBarBreadth(hsb);
       
    35             innerRect.iBr.iY = Max(innerRect.iBr.iY-height, innerRect.iTl.iY);
       
    36         }
       
    37 
       
    38         const CEikScrollBar* vsb = iVScroll ?
       
    39                                    &iVScroll->EikScrollBar() :
       
    40                                    sbFrame->GetScrollBarHandle(CEikScrollBar::EVertical);
       
    41         if (vsb && vsb->IsVisible())
       
    42         {
       
    43             TInt width = iDisplay.UiUtils().ScrollBarBreadth(vsb);
       
    44             if (AknLayoutUtils::LayoutMirrored())
       
    45             {
       
    46                 innerRect.iTl.iX = Min(innerRect.iTl.iX+width, innerRect.iBr.iX);
       
    47             }
       
    48             else
       
    49             {
       
    50                 innerRect.iBr.iX = Max(innerRect.iBr.iX-width, innerRect.iTl.iX);
       
    51             }
       
    52         }
       
    53     }
       
    54 
       
    55     return innerRect;
       
    56 }
       
    57 
       
    58 TRect ASwtScrollableBase::SbOuterRect(const TRect& aInnerRect) const
       
    59 {
       
    60     TRect outerRect(aInnerRect);
       
    61     CEikScrollBarFrame* sbFrame = SbFrame();
       
    62 
       
    63     if (sbFrame)
       
    64     {
       
    65         const CEikScrollBar* hsb = iHScroll ?
       
    66                                    &iHScroll->EikScrollBar() :
       
    67                                    sbFrame->GetScrollBarHandle(CEikScrollBar::EHorizontal);
       
    68         if (hsb && hsb->IsVisible())
       
    69         {
       
    70             TInt height = iDisplay.UiUtils().ScrollBarBreadth(hsb);
       
    71             outerRect.iBr.iY += height;
       
    72         }
       
    73 
       
    74         const CEikScrollBar* vsb = iVScroll ?
       
    75                                    &iVScroll->EikScrollBar() :
       
    76                                    sbFrame->GetScrollBarHandle(CEikScrollBar::EVertical);
       
    77         if (vsb && vsb->IsVisible())
       
    78         {
       
    79             TInt width = iDisplay.UiUtils().ScrollBarBreadth(vsb);
       
    80             if (AknLayoutUtils::LayoutMirrored())
       
    81             {
       
    82                 outerRect.iTl.iX -= width;
       
    83             }
       
    84             else
       
    85             {
       
    86                 outerRect.iBr.iX += width;
       
    87             }
       
    88         }
       
    89     }
       
    90 
       
    91     return outerRect;
       
    92 }
       
    93 
       
    94 // From MSwtScrollable
       
    95 MSwtControl* ASwtScrollableBase::Control()
       
    96 {
       
    97     return this;
       
    98 }
       
    99 
       
   100 // ASwtScrollableBase::CreateScrollBarL
       
   101 MSwtScrollBar* ASwtScrollableBase::CreateScrollBarL(TSwtPeer aPeer, TInt aStyle)
       
   102 {
       
   103     // Get frame
       
   104     CEikScrollBarFrame* sbFrame = SbFrame();
       
   105     if (!sbFrame)
       
   106     {
       
   107         return NULL;
       
   108     }
       
   109 
       
   110     // Asserts
       
   111     ASSERT(aStyle == KSwtStyleHScroll || aStyle == KSwtStyleVScroll);
       
   112     ASSERT((iStyle & aStyle) != 0);
       
   113 
       
   114     // Get scrollbar reference and orientation
       
   115     CEikScrollBar::TOrientation orientation;
       
   116     CSwtScrollBar** scrollbar;
       
   117     if (aStyle == KSwtStyleHScroll)
       
   118     {
       
   119         orientation = CEikScrollBar::EHorizontal;
       
   120         scrollbar = &iHScroll;
       
   121     }
       
   122     else
       
   123     {
       
   124         orientation = CEikScrollBar::EVertical;
       
   125         scrollbar = &iVScroll;
       
   126     }
       
   127 
       
   128     // Tile and return scrollbar
       
   129     TRect clientRect(Control()->ClientRect());
       
   130     TRect inclusiveRect(SbOuterRect(ClientRect()));
       
   131     TEikScrollBarModel hModel(DefaultSbModel(KSwtStyleHScroll));
       
   132     TEikScrollBarModel vModel(DefaultSbModel(KSwtStyleVScroll));
       
   133     TEikScrollBarFrameLayout layout;
       
   134     layout.iTilingMode = TEikScrollBarFrameLayout::EInclusiveRectConstant;
       
   135     layout.SetClientMargin(0);
       
   136     layout.SetInclusiveMargin(0);
       
   137 
       
   138     // Cannot use non double span models for double span scrollbars! Avoiding panics.
       
   139     TBool doubleSpan = sbFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan;
       
   140     if (doubleSpan)
       
   141     {
       
   142         TAknDoubleSpanScrollBarModel hDsSbarModel(hModel);
       
   143         TAknDoubleSpanScrollBarModel vDsSbarModel(vModel);
       
   144         sbFrame->TileL(&hDsSbarModel, &vDsSbarModel, clientRect, inclusiveRect, layout);
       
   145     }
       
   146     else
       
   147     {
       
   148         sbFrame->TileL(&hModel, &vModel, clientRect, inclusiveRect, layout);
       
   149     }
       
   150 
       
   151     CEikScrollBar* sb = sbFrame->GetScrollBarHandle(orientation);
       
   152     if (sb)
       
   153     {
       
   154         *scrollbar = new(ELeave) CSwtScrollBar(iDisplay, aPeer, aStyle,
       
   155                                                *sb, *this, 0, CSwtLafFacade::KSwtDefaultScrollBarModelScrollSpan,
       
   156                                                CSwtLafFacade::KSwtDefaultScrollBarModelThumbposition,
       
   157                                                CSwtLafFacade::KSwtDefaultScrollBarModelThumbSpan, doubleSpan,
       
   158                                                orientation);
       
   159         sbFrame->SetScrollBarFrameObserver(this);
       
   160         return *scrollbar;
       
   161     }
       
   162 
       
   163     return NULL;
       
   164 }
       
   165 
       
   166 // From MSwtScrollable
       
   167 void ASwtScrollableBase::SetVisibleScrollBar(TInt aStyle, TBool aVisible)
       
   168 {
       
   169     // Get frame
       
   170     CEikScrollBarFrame* sbFrame = SbFrame();
       
   171     if (!sbFrame)
       
   172     {
       
   173         return;
       
   174     }
       
   175 
       
   176     // Get scrollbars visibility
       
   177     CEikScrollBarFrame::TScrollBarVisibility hVis =
       
   178         sbFrame->ScrollBarVisibility(CEikScrollBar::EHorizontal);
       
   179     CEikScrollBarFrame::TScrollBarVisibility vVis =
       
   180         sbFrame->ScrollBarVisibility(CEikScrollBar::EVertical);
       
   181 
       
   182     // Calculate new visibility states
       
   183     if (aStyle & KSwtStyleHScroll)
       
   184     {
       
   185         if (aVisible)
       
   186         {
       
   187             hVis = CEikScrollBarFrame::EOn;
       
   188         }
       
   189         else
       
   190         {
       
   191             hVis = CEikScrollBarFrame::EOff;
       
   192         }
       
   193         iHScroll->SetVisible(aVisible);
       
   194     }
       
   195 
       
   196     if (aStyle & KSwtStyleVScroll)
       
   197     {
       
   198         if (aVisible)
       
   199         {
       
   200             vVis = CEikScrollBarFrame::EOn;
       
   201         }
       
   202         else
       
   203         {
       
   204             vVis = CEikScrollBarFrame::EOff;
       
   205         }
       
   206         iVScroll->SetVisible(aVisible);
       
   207     }
       
   208 
       
   209     // Apply new visibility states
       
   210     TRAP_IGNORE(sbFrame->SetScrollBarVisibilityL(hVis, vVis));
       
   211 
       
   212     // Resize Scrollable, as the client area has changed
       
   213     CCoeControl& coeCtrl = CoeControl();
       
   214     coeCtrl.SetSize(coeCtrl.Size());
       
   215 
       
   216     // Force a redraw here as some Scrollables do not update the screen after
       
   217     // a scrollbar as been switched on or off.
       
   218     Redraw();
       
   219 }
       
   220 
       
   221 // From MSwtScrollable
       
   222 void ASwtScrollableBase::ScrollBarDestroyed(const MSwtScrollBar* aScrollbar)
       
   223 {
       
   224     // Get frame
       
   225     CEikScrollBarFrame* sbFrame = SbFrame();
       
   226     if (sbFrame == NULL)
       
   227     {
       
   228         return;
       
   229     }
       
   230 
       
   231     // Calculate new visibility states, clear scrollbar reference
       
   232     CEikScrollBarFrame::TScrollBarVisibility hVis;
       
   233     CEikScrollBarFrame::TScrollBarVisibility vVis;
       
   234     if (aScrollbar == iHScroll)
       
   235     {
       
   236         hVis = CEikScrollBarFrame::EOff;
       
   237         vVis = sbFrame->ScrollBarVisibility(CEikScrollBar::EVertical);
       
   238         iHScroll = NULL;
       
   239     }
       
   240     else
       
   241     {
       
   242         ASSERT(aScrollbar == iVScroll);
       
   243         hVis = sbFrame->ScrollBarVisibility(CEikScrollBar::EHorizontal);
       
   244         vVis = CEikScrollBarFrame::EOff;
       
   245         iVScroll = NULL;
       
   246     }
       
   247 
       
   248     // Apply new visibility states
       
   249     TRAP_IGNORE(sbFrame->SetScrollBarVisibilityL(hVis, vVis));
       
   250 
       
   251     // Resize Scrollable, as the client area has changed
       
   252     CCoeControl& coeCtrl = CoeControl();
       
   253     coeCtrl.SetSize(coeCtrl.Size());
       
   254 
       
   255     // Force a redraw here as some Scrollables do not update the screen after
       
   256     // a scrollbar as been switched on or off.
       
   257     Redraw();
       
   258 }
       
   259 
       
   260 // From MSwtScrollable
       
   261 void ASwtScrollableBase::ComputeTrim(TRect& aRect) const
       
   262 {
       
   263     aRect = BorderOuterRect(SbOuterRect(aRect));
       
   264 }
       
   265 
       
   266 TBool ASwtScrollableBase::HasScrollBars() const
       
   267 {
       
   268     TBool hasScrollBars = EFalse;
       
   269     CEikScrollBarFrame* sbFrame = SbFrame();
       
   270     if (sbFrame)
       
   271     {
       
   272         if (iHScroll || iVScroll)
       
   273         {
       
   274             hasScrollBars = ETrue;
       
   275         }
       
   276     }
       
   277     return hasScrollBars;
       
   278 }
       
   279 
       
   280 // From ASwtControlBase
       
   281 TRect ASwtScrollableBase::ClientRect() const
       
   282 {
       
   283     return SbInnerRect(BorderInnerRect());
       
   284 }
       
   285 
       
   286 #ifdef RD_SCALABLE_UI_V2
       
   287 // From MEikScrollBarObserver
       
   288 void ASwtScrollableBase::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType)
       
   289 {
       
   290     if (iVScroll && (aScrollBar == &(iVScroll->EikScrollBar())))
       
   291     {
       
   292         iVScroll->HandleScrollEventL(aScrollBar, aEventType);
       
   293     }
       
   294     else if (iHScroll)
       
   295     {
       
   296         iHScroll->HandleScrollEventL(aScrollBar, aEventType);
       
   297     }
       
   298 }
       
   299 #else //RD_SCALABLE_UI_V2
       
   300 void ASwtScrollableBase::HandleScrollEventL(CEikScrollBar*, TEikScrollEvent)
       
   301 {
       
   302 }
       
   303 #endif //RD_SCALABLE_UI_V2