uifw/EikStd/coctlsrc/Aknscbut.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 <aknscbut.h>
       
    20 #include <eiksfont.h>
       
    21 #include <gulutil.h>
       
    22 #include <eikenv.h>
       
    23 #include <gulcolor.h>
       
    24 #include <aknscind.h>
       
    25 
       
    26 #include <AknsUtils.h>
       
    27 #include <AknUtils.h>
       
    28 #include <aknappui.h>
       
    29 
       
    30 // const TInt KAknScrollButtonBorderWidth=0;
       
    31 // const TInt KAknScrollButtonWidth=9;
       
    32 // const TInt KAknScrollButtonHeight=10;
       
    33 
       
    34 const TInt KTypeOfScrollBarMask = 0x000f;
       
    35 
       
    36 EXPORT_C CAknScrollButton* CAknScrollButton::NewL(TType aType)
       
    37 	{
       
    38 	CAknScrollButton* self = new (ELeave) CAknScrollButton(aType);
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL();
       
    41 	CleanupStack::Pop();
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 EXPORT_C CAknScrollButton::~CAknScrollButton()
       
    46 	{
       
    47     AknsUtils::DeregisterControlPosition( iScrollIndicator );
       
    48 	delete iScrollIndicator;
       
    49 	}
       
    50 
       
    51 EXPORT_C CAknScrollButton::TType CAknScrollButton::Type() const
       
    52 	{
       
    53 	return iType;
       
    54 	}
       
    55 
       
    56 EXPORT_C void CAknScrollButton::CreateWindowOnlyForArrowsL(const CCoeControl* aParent)
       
    57 	{
       
    58 	CreateWindowL(aParent);
       
    59     // "Parent absolute" skin layout requires every window to have a container window.
       
    60     iScrollIndicator->SetContainerWindowL(*this);
       
    61     if ( AknLayoutUtils::PenEnabled() )
       
    62     	{
       
    63     	iScrollIndicator->SetWindowOwning( ETrue );
       
    64     	}
       
    65 	}
       
    66 
       
    67 EXPORT_C TBool CAknScrollButton::IsNormalScrollBarUsingButton() const
       
    68 	{
       
    69     if( AknLayoutUtils::PenEnabled() )
       
    70         {
       
    71         // correction: AND with 0x0 is always false!
       
    72         return (iFlag == ENormal);
       
    73         }
       
    74     else
       
    75         {
       
    76     	return (iFlag&ENormal);
       
    77         }
       
    78 	}
       
    79 
       
    80 /*
       
    81  * Set the type of scroll bar which owns the button.
       
    82  */
       
    83 EXPORT_C void CAknScrollButton::SetTypeOfScrollBarUsingButton(TTypeOfScrollBar aTypeOfScrollBar)
       
    84 	{
       
    85     iFlag &= (~KTypeOfScrollBarMask);
       
    86 	iFlag |= aTypeOfScrollBar;
       
    87 	}
       
    88 
       
    89 EXPORT_C void CAknScrollButton::SetPosition(TInt aThumbPosition, TInt aScrollSpan)
       
    90 	{
       
    91 	iScrollIndicator->SetPosition(aThumbPosition, aScrollSpan); 
       
    92 	DrawDeferred() ;
       
    93 	}
       
    94 
       
    95 CAknScrollButton::CAknScrollButton(CAknScrollButton::TType aType)
       
    96 	: iType(aType)
       
    97 	{
       
    98 	}
       
    99 
       
   100 void CAknScrollButton::ConstructL()
       
   101 	{
       
   102 	iScrollIndicator = CAknScrollIndicator::NewL(iType);
       
   103 	iScrollIndicator->SetContainerWindowL(*this);
       
   104 	SetNonFocusing();
       
   105 	}
       
   106 
       
   107 void CAknScrollButton::Draw(const TRect& /*aRect*/) const
       
   108 	{
       
   109     CWindowGc& gc=SystemGc();
       
   110 
       
   111 	if (!IsNormalScrollBarUsingButton())
       
   112 	    {	    
       
   113 		gc.SetBrushColor( iEikonEnv->ControlColor(EColorMenuPaneBackground, *this) );
       
   114 	    }
       
   115 	else
       
   116 	    {	    
       
   117 		gc.SetBrushColor(KRgbWhite);
       
   118 	    }
       
   119 	    
       
   120 	DrawIndicator();
       
   121 	}
       
   122 
       
   123 void CAknScrollButton::SizeChanged()
       
   124 	{
       
   125 	iScrollIndicator->SetRect( Rect() );
       
   126 	if (iOldRect != Rect())
       
   127 	    {	    
       
   128 	    AknsUtils::RegisterControlPosition( iScrollIndicator );
       
   129 	    }
       
   130 	iOldRect = Rect();
       
   131 	}
       
   132 
       
   133 void CAknScrollButton::DrawIndicator() const
       
   134 	// Draws the indicator on the button 
       
   135 	{
       
   136     if( AknLayoutUtils::PenEnabled() )
       
   137         {
       
   138         if(IsNormalScrollBarUsingButton())
       
   139             {
       
   140             // The rect has already been set by CAknDoubleSpanScrollBar
       
   141             iScrollIndicator->DrawScrollIndicator( Rect() );
       
   142             }
       
   143         }
       
   144     if ( iFlag == EArrowHead )
       
   145         {
       
   146         iScrollIndicator->DrawScrollIndicator( Rect() );
       
   147         }
       
   148 	}
       
   149 
       
   150 
       
   151 EXPORT_C CAknScrollButton* CAknScrollButton::NewL(TType aType, TTypeOfScrollBar aTypeOfScrollBar)
       
   152 	{
       
   153 	CAknScrollButton* self = new (ELeave) CAknScrollButton(aType);
       
   154 	CleanupStack::PushL(self);
       
   155 	self->ConstructL(aTypeOfScrollBar);
       
   156 	CleanupStack::Pop();
       
   157 	return self;
       
   158 	}
       
   159 
       
   160 
       
   161 void CAknScrollButton::ConstructL(TTypeOfScrollBar aTypeOfScrollBar)
       
   162 	{
       
   163 	SetTypeOfScrollBarUsingButton(aTypeOfScrollBar);
       
   164 	iScrollIndicator = CAknScrollIndicator::NewL(iType, aTypeOfScrollBar);
       
   165 	iScrollIndicator->SetContainerWindowL(*this);
       
   166 	SetNonFocusing();
       
   167 	}
       
   168 
       
   169 void CAknScrollButton::SetContainerWindowL( const CCoeControl& aControl )
       
   170     {
       
   171     CCoeControl::SetContainerWindowL( aControl );
       
   172     if ( iScrollIndicator )
       
   173         {
       
   174         iScrollIndicator->SetContainerWindowL( *this );
       
   175         }
       
   176     }
       
   177 
       
   178 TInt CAknScrollButton::CountComponentControls() const
       
   179     {
       
   180     if ( iScrollIndicator )
       
   181         {
       
   182         return 1; 
       
   183         }
       
   184     return 0;
       
   185     }
       
   186     
       
   187 CCoeControl* CAknScrollButton::ComponentControl( TInt aIndex ) const
       
   188     {
       
   189     if ( iScrollIndicator && aIndex == 0 )
       
   190         {
       
   191         return iScrollIndicator;
       
   192         }
       
   193     return NULL;           
       
   194     }
       
   195