emailuis/uicomponents/src/fsalfscrollbarlayout.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: This file implements class CFsAlfScrollbarLayout.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail> SF
       
    20 #include "emailtrace.h"
       
    21 #include <alf/alfcontrol.h>
       
    22 #include <alf/alfanchorlayout.h>
       
    23 #include <alf/alfenv.h>
       
    24 #include <alf/alfimagebrush.h>
       
    25 #include <alf/alfbrusharray.h>
       
    26 #include <alf/alfconstants.h>
       
    27 #include <alf/alfgencomponent.h>
       
    28 #include <alf/alfconstants.h>
       
    29 //</cmail>
       
    30 
       
    31 #include "fsscrollbarpluginconstants.h"
       
    32 #include "fsalfscrollbarlayout.h"
       
    33 
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 CFsAlfScrollbarLayout::CFsAlfScrollbarLayout()
       
    38     : CAlfLayout()
       
    39     {
       
    40     FUNC_LOG;
       
    41     }
       
    42 
       
    43 
       
    44 void CFsAlfScrollbarLayout::ConstructL( CAlfControl& aOwnerControl )
       
    45     {
       
    46     FUNC_LOG;
       
    47     CAlfLayout::ConstructL( aOwnerControl );
       
    48 
       
    49     iOwnerControl = &aOwnerControl;
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Construct a new scrollbar layout and give its ownership to a control.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C CFsAlfScrollbarLayout* CFsAlfScrollbarLayout::AddNewL(
       
    58     CAlfControl& aOwnerControl,
       
    59     CAlfLayout* aParentLayout )
       
    60     {
       
    61     FUNC_LOG;
       
    62     TInt ownerHandle( aOwnerControl.Identifier() );
       
    63     TInt parentlayouthandle( 0 );
       
    64     if ( aParentLayout )
       
    65         {
       
    66         parentlayouthandle = aParentLayout->Identifier();
       
    67         }
       
    68 
       
    69     TInt2 inputParams( aOwnerControl.Identifier(), parentlayouthandle );
       
    70 
       
    71     TPckg<TInt2> paramBuf( inputParams );
       
    72 
       
    73     CFsAlfScrollbarLayout* layout( new( ELeave )CFsAlfScrollbarLayout() );
       
    74     CleanupStack::PushL( layout );
       
    75 
       
    76     layout->CAlfVisual::ConstructL(
       
    77         aOwnerControl,
       
    78         EFsScrollbarCreateScreenLayout,
       
    79         KFsScrollbarImplementationId, paramBuf );
       
    80 
       
    81     User::LeaveIfError( aOwnerControl.Append( layout, aParentLayout ) );
       
    82     CleanupStack::Pop( layout );
       
    83     return layout;
       
    84     }
       
    85 
       
    86 
       
    87 CFsAlfScrollbarLayout::~CFsAlfScrollbarLayout()
       
    88     {
       
    89     FUNC_LOG;
       
    90     SetVisibilityMode( EFsScrollbarHideAlways, EFsScrollbarVertical );
       
    91     SetVisibilityMode( EFsScrollbarHideAlways, EFsScrollbarHorizontal );
       
    92     ReleaseCustomImage( EFsScrollbarVertical );
       
    93     ReleaseCustomImage( EFsScrollbarHorizontal );
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Set the range of the scrollbar. Will not actually move the scrollbar until
       
    99 // Update() is called.
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C void CFsAlfScrollbarLayout::SetRange(
       
   103     TInt aStart,
       
   104     TInt aEnd,
       
   105     TFsScrollbar aScrollbar )
       
   106     {
       
   107     FUNC_LOG;
       
   108     TFsScrollbarSet scrollbarSet;
       
   109     scrollbarSet.iScrollbar = aScrollbar;
       
   110     scrollbarSet.iRangeStart = aStart;
       
   111     scrollbarSet.iRangeEnd = aEnd;
       
   112 
       
   113     SendCommand( EFsScrollbarLayoutSetScrollbarRangeCommand, scrollbarSet );
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // Get scrollbars minimum range value.
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C TInt CFsAlfScrollbarLayout::RangeStart( TFsScrollbar aScrollbar )
       
   122     {
       
   123     FUNC_LOG;
       
   124     TFsScrollbarSet scrollbarSet;
       
   125     TFsScrollbarSet paramScrollbarSet;
       
   126     paramScrollbarSet.iScrollbar = aScrollbar;
       
   127     SendCommand( EFsScrollbarLayoutGetScrollbarSettingsCommand,
       
   128         paramScrollbarSet, scrollbarSet );
       
   129     return scrollbarSet.iRangeStart;
       
   130     }
       
   131 
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // Get scrollbars maximum range value.
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C TInt CFsAlfScrollbarLayout::RangeEnd( TFsScrollbar aScrollbar )
       
   138     {
       
   139     FUNC_LOG;
       
   140     TFsScrollbarSet scrollbarSet;
       
   141     TFsScrollbarSet paramScrollbarSet;
       
   142     paramScrollbarSet.iScrollbar = aScrollbar;
       
   143     SendCommand( EFsScrollbarLayoutGetScrollbarSettingsCommand,
       
   144         paramScrollbarSet, scrollbarSet );
       
   145     return scrollbarSet.iRangeEnd;
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Set the count of visible units at the time.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void CFsAlfScrollbarLayout::SetThumbSpan(
       
   154     TInt aThumbSpan,
       
   155     TFsScrollbar aScrollbar )
       
   156     {
       
   157     FUNC_LOG;
       
   158     TFsScrollbarSet scrollbarSet;
       
   159     scrollbarSet.iScrollbar = aScrollbar;
       
   160     scrollbarSet.iThumbSpan = aThumbSpan;
       
   161     SendCommand( EFsScrollbarLayoutSetScrollbarThumbSpanCommand,
       
   162         scrollbarSet );
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Get the set value for visible units.
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C TInt CFsAlfScrollbarLayout::ThumbSpan( TFsScrollbar aScrollbar )
       
   171     {
       
   172     FUNC_LOG;
       
   173     TFsScrollbarSet scrollbarSet;
       
   174     TFsScrollbarSet paramScrollbarSet;
       
   175     paramScrollbarSet.iScrollbar = aScrollbar;
       
   176     SendCommand( EFsScrollbarLayoutGetScrollbarSettingsCommand,
       
   177         paramScrollbarSet, scrollbarSet );
       
   178     return scrollbarSet.iThumbSpan;
       
   179     }
       
   180 
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // Adjust the vertical scrollbar's width.
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 EXPORT_C void CFsAlfScrollbarLayout::SetVerticalScrollbarWidth(
       
   187     TInt aWidth,
       
   188     TInt aTransitionTime )
       
   189     {
       
   190     FUNC_LOG;
       
   191     TInt2 params( aWidth, aTransitionTime );
       
   192     TPckgC<TInt2> inBuf( params );
       
   193     TBuf8<1> dummy;
       
   194     TInt err( Comms()->DoSynchronousCmd(
       
   195         EFsScrollbarLayoutSetVerticalScrollbarWidthCommand,
       
   196         inBuf,
       
   197         dummy ) );
       
   198 
       
   199     __ASSERT_ALWAYS( err == KErrNone, User::Invariant() );
       
   200     }
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // Adjust the horizontal scrollbar's height.
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C void CFsAlfScrollbarLayout::SetHorizontalScrollbarHeight(
       
   208     TInt aHeight,
       
   209     TInt aTransitionTime )
       
   210     {
       
   211     FUNC_LOG;
       
   212     TInt2 params( aHeight, aTransitionTime );
       
   213     TPckgC<TInt2> inBuf( params );
       
   214     TBuf8<1> dummy;
       
   215     TInt err( Comms()->DoSynchronousCmd(
       
   216         EFsScrollbarLayoutSetHorizontalScrollbarHeightCommand,
       
   217         inBuf,
       
   218         dummy ) );
       
   219 
       
   220     __ASSERT_ALWAYS( err == KErrNone, User::Invariant() );
       
   221     }
       
   222 
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // Set the position of the scrollbar.
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 EXPORT_C void CFsAlfScrollbarLayout::SetScrollbarPos(
       
   229     const TInt aPos,
       
   230     TFsScrollbar aScrollbar )
       
   231     {
       
   232     FUNC_LOG;
       
   233     TFsScrollbarSet scrollbarSet;
       
   234     scrollbarSet.iScrollbar = aScrollbar;
       
   235     scrollbarSet.iScrollbarPos = aPos;
       
   236 
       
   237     SendCommand( EFsScrollbarLayoutSetScrollbarPosCommand, scrollbarSet );
       
   238     }
       
   239 
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // Resolve the position of the scrollbar.
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 EXPORT_C TInt CFsAlfScrollbarLayout::ScrollbarPos( TFsScrollbar aScrollbar )
       
   246     {
       
   247     FUNC_LOG;
       
   248     TFsScrollbarSet scrollbarSet;
       
   249     TFsScrollbarSet paramScrollbarSet;
       
   250     paramScrollbarSet.iScrollbar = aScrollbar;
       
   251     SendCommand( EFsScrollbarLayoutGetScrollbarSettingsCommand,
       
   252         paramScrollbarSet, scrollbarSet );
       
   253     return scrollbarSet.iScrollbarPos;
       
   254     }
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // Set the scrollbar visibility.
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 EXPORT_C void CFsAlfScrollbarLayout::SetVisibilityMode(
       
   262     TFsScrollbarVisibility aVisibility,
       
   263     TFsScrollbar aScrollbar )
       
   264     {
       
   265     FUNC_LOG;
       
   266     TFsScrollbarSet scrollbarSet;
       
   267     scrollbarSet.iScrollbar = aScrollbar;
       
   268     scrollbarSet.iVisibility = aVisibility;
       
   269 
       
   270     SendCommand( EFsScrollbarLayoutSetScrollbarVisibilityCommand,
       
   271         scrollbarSet );
       
   272     }
       
   273 
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Resolve the scrollbar visibility.
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 EXPORT_C TFsScrollbarVisibility CFsAlfScrollbarLayout::VisibilityMode(
       
   280     TFsScrollbar aScrollbar )
       
   281     {
       
   282     FUNC_LOG;
       
   283     TFsScrollbarSet scrollbarSet;
       
   284     TFsScrollbarSet paramScrollbarSet;
       
   285     paramScrollbarSet.iScrollbar = aScrollbar;
       
   286     SendCommand( EFsScrollbarLayoutGetScrollbarSettingsCommand,
       
   287         paramScrollbarSet, scrollbarSet );
       
   288     return scrollbarSet.iVisibility;
       
   289     }
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // Resolve if the specified scrollbar is visible.
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C TBool CFsAlfScrollbarLayout::IsScrollbarVisible(
       
   297     TFsScrollbar aScrollbar )
       
   298     {
       
   299     FUNC_LOG;
       
   300     TFsScrollbarSet scrollbarSet;
       
   301     TFsScrollbarSet paramScrollbarSet;
       
   302     paramScrollbarSet.iScrollbar = aScrollbar;
       
   303     SendCommand( EFsScrollbarLayoutGetScrollbarSettingsCommand,
       
   304         paramScrollbarSet, scrollbarSet );
       
   305     return scrollbarSet.iVisible;
       
   306     }
       
   307 
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // Change the bar image to custom image. Ownership of the brushes are changed.
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 EXPORT_C void CFsAlfScrollbarLayout::SetScrollbarImagesL(
       
   314     CAlfImageBrush* aBarBrush, CAlfImageBrush* aThumbBrush,
       
   315     TFsScrollbar aScrollbar )
       
   316     {
       
   317     FUNC_LOG;
       
   318     ReleaseCustomImage( aScrollbar );
       
   319 
       
   320     if ( EFsScrollbarVertical == aScrollbar )
       
   321         {
       
   322         iVBarBrush = aBarBrush;
       
   323         iVThumbBrush = aThumbBrush;
       
   324         }
       
   325     else
       
   326         {
       
   327         iHBarBrush = aBarBrush;
       
   328         iHThumbBrush = aThumbBrush;
       
   329         }
       
   330 
       
   331     TFsImageSet imageSet;
       
   332     imageSet.iBarBrushId = aBarBrush->Identifier();
       
   333     imageSet.iThumbBrushId = aThumbBrush->Identifier();
       
   334     imageSet.iScrollbar = aScrollbar;
       
   335 
       
   336     TPckgC<TFsImageSet> inBuf( imageSet );
       
   337     TBuf8<1> dummy;
       
   338 
       
   339     TInt err = Comms()->DoSynchronousCmd(
       
   340         EFsScrollbarLayoutSetScrollbarCustomImagesCommand,
       
   341         inBuf,
       
   342         dummy );
       
   343 
       
   344     __ASSERT_ALWAYS( KErrNone == err, User::Invariant() );
       
   345     }
       
   346 
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // Update the visibility of scrollbars.
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 EXPORT_C void CFsAlfScrollbarLayout::Update( TInt aLayoutTransitionTime )
       
   353     {
       
   354     FUNC_LOG;
       
   355     TPckgC<TInt> inBuf( aLayoutTransitionTime );
       
   356     TBuf8<1> outDum;
       
   357     TInt err = Comms()->DoSynchronousCmd(
       
   358         EFsScrollbarLayoutSetScrollbarUpdateCommand,
       
   359         inBuf,
       
   360         outDum );
       
   361 
       
   362     __ASSERT_ALWAYS( err == KErrNone, User::Invariant() );
       
   363     }
       
   364 
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // Get the target size of the scrolbar layout without the scrollbars.
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 EXPORT_C TAlfRealPoint CFsAlfScrollbarLayout::LayoutSize()
       
   371     {
       
   372     FUNC_LOG;
       
   373     TAlfRealPoint layoutSize;
       
   374 
       
   375     TBuf8<1> inBuf;
       
   376     TPckg<TAlfRealPoint> outBuf( layoutSize );
       
   377     TInt err = Comms()->DoSynchronousCmd(
       
   378         EFsScrollbarLayoutGetScrollbarLayoutSizeCommand,
       
   379         inBuf,
       
   380         outBuf );
       
   381 
       
   382     __ASSERT_ALWAYS( KErrNone == err, User::Invariant() );
       
   383 
       
   384     return layoutSize;
       
   385     }
       
   386 
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // Send a command to server.
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 void CFsAlfScrollbarLayout::SendCommand(
       
   393     TFsScrollbarCommand aCommandId,
       
   394     TFsScrollbarSet& aInScrollbarSet )
       
   395     {
       
   396     FUNC_LOG;
       
   397     TFsScrollbarSet dummySet;
       
   398     SendCommand( aCommandId, aInScrollbarSet, dummySet );
       
   399     }
       
   400 
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // Send a command to server.
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 void CFsAlfScrollbarLayout::SendCommand(
       
   407     TFsScrollbarCommand aCommandId,
       
   408     TFsScrollbarSet& aInScrollbarSet,
       
   409     TFsScrollbarSet& aOutScrollbarSet )
       
   410     {
       
   411     FUNC_LOG;
       
   412     TPckgC<TFsScrollbarSet> inBuf( aInScrollbarSet );
       
   413     TPckg<TFsScrollbarSet> outBuf( aOutScrollbarSet );
       
   414     TInt err = Comms()->DoSynchronousCmd(
       
   415         aCommandId,
       
   416         inBuf,
       
   417         outBuf );
       
   418 
       
   419     __ASSERT_ALWAYS( err == KErrNone, User::Invariant() );
       
   420     }
       
   421 
       
   422 
       
   423 // ---------------------------------------------------------------------------
       
   424 // Release custom image reserved memory.
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 void CFsAlfScrollbarLayout::ReleaseCustomImage( TFsScrollbar aScrollbar )
       
   428     {
       
   429     FUNC_LOG;
       
   430     TFsScrollbarSet scrollbarSet;
       
   431     scrollbarSet.iScrollbar = aScrollbar;
       
   432     SendCommand( EFsScrollbarLayoutSetScrollbarClearCustomImagesCommand,
       
   433         scrollbarSet );
       
   434     if ( EFsScrollbarVertical == aScrollbar )
       
   435         {
       
   436         delete iVBarBrush;
       
   437         iVBarBrush = NULL;
       
   438         delete iVThumbBrush;
       
   439         iVThumbBrush = NULL;
       
   440         }
       
   441     else
       
   442         {
       
   443         delete iHBarBrush;
       
   444         iHBarBrush = NULL;
       
   445         delete iHThumbBrush;
       
   446         iHThumbBrush = NULL;
       
   447         }
       
   448     }
       
   449