uifw/uiklaf/src/LAFSCBUT.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 <gulbordr.h>
       
    20 #include <gulcolor.h>
       
    21 #include <gulutil.h>
       
    22 #include <coecntrl.h>
       
    23 #include <gulfont.h>
       
    24 
       
    25 #include "LAFSTD.H"
       
    26 #include "LAFSCBUT.H"
       
    27 #include "LAFSCRLB.H"
       
    28 #include "lafmain.h"
       
    29 #include <uiklaf/private/lafenv.h>
       
    30 #include "lafcommn.h"
       
    31 
       
    32 
       
    33 #include "eiksfont.h"
       
    34 
       
    35 const TInt KArrowHeadScrollBarHeight=15;
       
    36 
       
    37 
       
    38 //
       
    39 // local functions specific to our type of scrollbar button
       
    40 //
       
    41 LOCAL_C TRgb IconColor(const MLafEnv& aLafEnv, const CCoeControl& aScrollButton,TBool aPressed)
       
    42 	{
       
    43 	TLogicalColor color=EColorScrollButtonIcon;
       
    44 	if (aScrollButton.IsDimmed())
       
    45 		color=EColorScrollButtonIconDimmed;
       
    46 	else if (aPressed)
       
    47 		color=EColorScrollButtonIconPressed;
       
    48 	return aLafEnv.ControlColor(color,aScrollButton);
       
    49 	}
       
    50 
       
    51 LOCAL_C void DrawIcon(const MLafEnv& aLafEnv,CWindowGc& aGc,TRect& aRect,const CCoeControl& aScrollButton,TInt aButtonType,TBool aPressed)
       
    52 	{
       
    53 	TInt charCode=0;
       
    54 	switch (aButtonType)
       
    55 		{
       
    56     default:
       
    57         break;
       
    58 	case SLafScrollButton::ENudgeUp:
       
    59 		charCode=ESymFontScrollUp;
       
    60 		break;
       
    61 	case SLafScrollButton::ENudgeDown:
       
    62 		charCode=ESymFontScrollDown;
       
    63 		break;
       
    64 	case SLafScrollButton::ENudgeLeft:
       
    65 		charCode=ESymFontScrollLeft;
       
    66 		break;
       
    67 	case SLafScrollButton::ENudgeRight:
       
    68 		charCode=ESymFontScrollRight;
       
    69 		break;
       
    70 	case SLafScrollButton::EPageUp:
       
    71 		charCode=ESymFontScrollPageUp;
       
    72 		break;
       
    73 	case SLafScrollButton::EPageDown:
       
    74 		charCode=ESymFontScrollPageDown;
       
    75 		break;
       
    76 	case SLafScrollButton::EPageLeft:
       
    77 		charCode=ESymFontScrollPageLeft;
       
    78 		break;
       
    79 	case SLafScrollButton::EPageRight:
       
    80 		charCode=ESymFontScrollPageRight;
       
    81 		break;
       
    82 	case SLafScrollButton::ETop:
       
    83 		charCode=ESymFontScrollToTop;
       
    84 		break;
       
    85 	case SLafScrollButton::EBottom:
       
    86 		charCode=ESymFontScrollToBottom;
       
    87 		break;
       
    88 	case SLafScrollButton::EHome:
       
    89 		charCode=ESymFontScrollToLeftEnd;
       
    90 		break;
       
    91 	case SLafScrollButton::EEnd:
       
    92 		charCode=ESymFontScrollToRightEnd;
       
    93 		break;
       
    94 		}
       
    95 	TBuf<1> symbol;
       
    96 	symbol.Append(TChar(charCode));
       
    97 	TLogicalFont logicalFont;
       
    98 	logicalFont.iFontId=TUid::Uid(KLafUidSymbolFontVal);
       
    99 	const CFont* symFont=aLafEnv.Font(logicalFont);
       
   100 	aGc.UseFont(symFont);
       
   101 	aGc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   102 	aGc.SetPenColor(IconColor(aLafEnv,aScrollButton,aPressed));
       
   103 	const TInt extraVerticalSpace=(aRect.Height() - symFont->HeightInPixels());
       
   104 	const TInt baselineOffset=Max(symFont->AscentInPixels(),extraVerticalSpace/2 + symFont->AscentInPixels());
       
   105 	aGc.DrawText(symbol,aRect,baselineOffset,CGraphicsContext::ECenter);
       
   106 	aGc.DiscardFont();
       
   107 	}
       
   108 
       
   109 //
       
   110 // Class LafScrollButton
       
   111 //
       
   112 EXPORT_C void LafScrollButton::GetBorder(TGulBorder& aBorder, TBool aIsPressed)
       
   113 	{
       
   114 	TInt adj = aBorder.Adjacent();
       
   115 	aBorder=TGulBorder(aIsPressed ? TGulBorder::EShallowSunken : TGulBorder::EDeepRaised);
       
   116 	aBorder.SetAdjacent(adj);
       
   117 	}
       
   118 
       
   119 /**
       
   120  * Gets the set of border colors for the matched control in aBorderColors. The RGB values of the colors obtained
       
   121  * may depend on the the display mode, the environment color list and the instance of the
       
   122  * matched control aMatchedControl. Called by the matched control from its Draw() method and passed on to the
       
   123  * Draw() method of TGulBorder. 
       
   124  */
       
   125 EXPORT_C void LafScrollButton::GetBorderColors(TGulBorder::TColors& aBorderColors, const MLafEnv& aLafEnv, const CCoeControl& aMatchedControl)
       
   126 	{
       
   127 	LafCommonUtils::GetRgbDerivedBorderColors( aBorderColors,
       
   128 			EColorScrollButtonThumbBackground, aLafEnv,aMatchedControl );
       
   129 	}
       
   130 
       
   131 EXPORT_C TInt LafScrollButton::ButtonBreadth()
       
   132 	{ // should this be allowed...
       
   133 	return LafScrollBar::DefaultBreadth();
       
   134 	}
       
   135 
       
   136 EXPORT_C void LafScrollButton::DrawButton(const MLafEnv& aLafEnv,CWindowGc& aGc,const CCoeControl& aScrollButton,const TRect& aRect,TInt aButtonType,TBool aPressed)
       
   137 	{
       
   138 	TRect rect(aRect);
       
   139 	const TRgb brushColor=aLafEnv.ControlColor((aPressed? EColorScrollButtonThumbBackgroundPressed : EColorScrollButtonThumbBackground),aScrollButton);
       
   140 	aGc.SetBrushColor(brushColor);
       
   141 	aGc.Clear(rect);
       
   142 //
       
   143 	if (aPressed)
       
   144 		rect.iTl+=TPoint(2,2);
       
   145 
       
   146 	DrawIcon(aLafEnv,aGc,rect,aScrollButton,aButtonType,aPressed);
       
   147 	}
       
   148 
       
   149 EXPORT_C void LafScrollButton::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList)
       
   150 	{ // static
       
   151 	TInt commonAttributes = TCoeColorUse::ESurrounds|TCoeColorUse::ENormal|TCoeColorUse::ENeutral;
       
   152 	TCoeColorUse colorUse;
       
   153 
       
   154 	colorUse.SetLogicalColor(EColorScrollButtonThumbBackgroundPressed);
       
   155 	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EPressed|commonAttributes);
       
   156 	aColorUseList.AppendL(colorUse);
       
   157 
       
   158 	colorUse.SetLogicalColor(EColorScrollButtonThumbBackground);
       
   159 	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EActive|commonAttributes);
       
   160 	aColorUseList.AppendL(colorUse);
       
   161 
       
   162 	colorUse.SetLogicalColor(EColorScrollButtonIcon);
       
   163 	colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EActive|commonAttributes);
       
   164 	aColorUseList.AppendL(colorUse);
       
   165 
       
   166 	colorUse.SetLogicalColor(EColorScrollButtonIconDimmed);
       
   167 	colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EDimmed|commonAttributes);
       
   168 	aColorUseList.AppendL(colorUse);
       
   169 
       
   170 	colorUse.SetLogicalColor(EColorScrollButtonIconPressed);
       
   171 	colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EPressed|commonAttributes);
       
   172 	aColorUseList.AppendL(colorUse);
       
   173 	}
       
   174 
       
   175 //
       
   176 // class LafArrowHeadScrollButton
       
   177 //
       
   178 
       
   179 EXPORT_C void LafArrowHeadScrollButton::GetBorder(TGulBorder& aBorder, TBool /*aIsPressed*/)
       
   180 	{
       
   181 	aBorder=TGulBorder(TGulBorder::ENone);
       
   182 	}
       
   183 
       
   184 /**
       
   185  * Gets the set of border colors for the matched control in aBorderColors. The RGB values of the colors obtained
       
   186  * may depend on the the display mode, the environment color list and the instance of the
       
   187  * matched control aMatchedControl. Called by the matched control from its Draw() method and passed on to the
       
   188  * Draw() method of TGulBorder. 
       
   189  */
       
   190 EXPORT_C void LafArrowHeadScrollButton::GetBorderColors(TGulBorder::TColors& aBorderColors, const MLafEnv& aLafEnv, const CCoeControl& aMatchedControl)
       
   191 	{
       
   192 	LafCommonUtils::GetRgbDerivedBorderColors( aBorderColors,
       
   193 			EColorScrollButtonThumbBackground, aLafEnv,aMatchedControl );
       
   194 	}
       
   195 
       
   196 EXPORT_C TInt LafArrowHeadScrollButton::ButtonBreadth()
       
   197 	{
       
   198 	return KArrowHeadScrollBarHeight;
       
   199 	}
       
   200 
       
   201 EXPORT_C void LafArrowHeadScrollButton::DrawButton(const MLafEnv& aLafEnv,CWindowGc& aGc,const CCoeControl& aScrollButton,const TRect& aRect,TInt aButtonType,TBool aPressed)
       
   202 	{
       
   203 	TRect rect(aRect);
       
   204 	const TRgb brushColor=aLafEnv.ControlColor(EColorMenuPaneBackground,aScrollButton);
       
   205 	aGc.SetBrushColor(brushColor);
       
   206 	aGc.Clear(rect);
       
   207 //
       
   208 	if (aPressed)
       
   209 		rect.iTl+=TPoint(2,2);
       
   210 
       
   211 	DrawIcon(aLafEnv,aGc,rect,aScrollButton,aButtonType,aPressed);
       
   212 	}