|
1 /* |
|
2 * Copyright (c) 2009 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 #include <e32std.h> |
|
19 #include <w32std.h> |
|
20 #include "laflbd.h" |
|
21 |
|
22 EXPORT_C void LafListBoxData::DrawSearchText(const TRect& aItemTextRect, |
|
23 CWindowGc& aGc,const CFont& aItemFont,const CFont& aBoldFont, |
|
24 const TDesC& aItemText,const TInt aStrPos,const TInt aStrLen, |
|
25 const TInt aBaseLineOffset,const CGraphicsContext::TTextAlign aAlign) |
|
26 {//static |
|
27 const TPtrC textHead = TPtrC(aItemText.Left(aStrPos)); |
|
28 const TPtrC searchStr= TPtrC(aItemText.Mid(aStrPos,aStrLen)); |
|
29 const TPtrC textTail = TPtrC(aItemText.Right(aItemText.Length()-aStrPos-aStrLen)); |
|
30 |
|
31 const TInt headLen = aItemFont.TextWidthInPixels(textHead); |
|
32 const TInt strLen = aBoldFont.TextWidthInPixels(searchStr); |
|
33 const TInt tailLen = aItemFont.TextWidthInPixels(textTail); |
|
34 |
|
35 // adjust text alignment by drawing empty rect before text if necessary |
|
36 TRect rect = aItemTextRect; |
|
37 const TInt textLen = headLen + strLen + tailLen; |
|
38 TInt emptyLen = rect.Width() - textLen; |
|
39 if ((aAlign==CGraphicsContext::ELeft) || (emptyLen<=0)) |
|
40 emptyLen = 0; |
|
41 else |
|
42 { |
|
43 if (aAlign==CGraphicsContext::ECenter) emptyLen = (emptyLen>>1); |
|
44 } |
|
45 |
|
46 // draw item head up to search string |
|
47 rect.iBr.iX = rect.iTl.iX + emptyLen + headLen; |
|
48 aGc.DrawText( textHead, rect, aBaseLineOffset, CGraphicsContext::ERight ); |
|
49 |
|
50 // draw item tail after the search string |
|
51 rect.iTl.iX = rect.iBr.iX + strLen; |
|
52 rect.iBr.iX = aItemTextRect.iBr.iX; |
|
53 aGc.DrawText( textTail, rect, aBaseLineOffset ); |
|
54 |
|
55 // change font and set undelining on |
|
56 aGc.UseFont(&aBoldFont); |
|
57 aGc.SetUnderlineStyle(EUnderlineOn); |
|
58 |
|
59 // draw the search string part of the item with different font |
|
60 rect.iBr.iX = rect.iTl.iX; |
|
61 rect.iTl.iX = rect.iBr.iX - strLen; |
|
62 aGc.DrawText( searchStr, rect, aBaseLineOffset ); |
|
63 } |
|
64 |