|
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 #include <AknsDrawUtils.h> |
|
18 |
|
19 #include "peninputlayoutmicfcustomdraw.h" |
|
20 #include "peninputlayoutmultilineicf.h" |
|
21 #include "peninputlayoutsmiley.h" |
|
22 |
|
23 CFepLayoutMIcfCustomDraw::CFepLayoutMIcfCustomDraw(CFepLayoutMultiLineIcfEditor* aParentControl) |
|
24 :iParentControl(aParentControl) |
|
25 { |
|
26 } |
|
27 |
|
28 CFepLayoutMIcfCustomDraw::~CFepLayoutMIcfCustomDraw() |
|
29 { |
|
30 } |
|
31 |
|
32 void CFepLayoutMIcfCustomDraw::DrawBackground(const TParam& aParam, |
|
33 const TRgb& /*aRgb*/, |
|
34 TRect& aDrawn) const |
|
35 { |
|
36 CFbsBitGc& gc = (CFbsBitGc&)(aParam.iGc); |
|
37 |
|
38 TRect drawrect = iParentControl->Rect(); |
|
39 aDrawn = aParam.iDrawRect; |
|
40 gc.SetClippingRect(aDrawn); |
|
41 gc.Clear(drawrect); |
|
42 |
|
43 if (iParentControl->BgImgSkinId() != KAknsIIDNone) |
|
44 { |
|
45 // set clipping rect, make sure text is not hide by drawframe |
|
46 |
|
47 AknsDrawUtils::DrawFrame(AknsUtils::SkinInstance(), |
|
48 gc, |
|
49 drawrect, |
|
50 drawrect, |
|
51 iParentControl->BgImgSkinId(), |
|
52 KAknsIIDDefault); |
|
53 |
|
54 |
|
55 } |
|
56 else |
|
57 { |
|
58 iParentControl->DrawIcfBackground( gc, aDrawn ); |
|
59 } |
|
60 |
|
61 gc.CancelClippingRect(); |
|
62 } |
|
63 |
|
64 void CFepLayoutMIcfCustomDraw::DrawText( const TParam& aParam, const TLineInfo& aLineInfo, |
|
65 const TCharFormat& aFormat, const TDesC& aText, |
|
66 const TPoint& aTextOrigin, TInt aExtraPixels ) const |
|
67 { |
|
68 if ( !iParentControl->SmileyEnabled() ) |
|
69 { |
|
70 MFormCustomDraw::DrawText( aParam, aLineInfo, aFormat, aText, |
|
71 aTextOrigin, aExtraPixels ); |
|
72 return; |
|
73 } |
|
74 |
|
75 //get count of smileys |
|
76 TInt count = 0; |
|
77 for ( TInt i = 0; i < aText.Length(); i ++ ) |
|
78 { |
|
79 if ( iParentControl->SmileyManager()->IsSmileyCode(aText[i] ) ) |
|
80 { |
|
81 count++; |
|
82 break; |
|
83 } |
|
84 } |
|
85 |
|
86 if ( count < 1 ) |
|
87 { |
|
88 //no smiley found, call default draw |
|
89 MFormCustomDraw::DrawText( aParam, aLineInfo, aFormat, aText, |
|
90 aTextOrigin, aExtraPixels ); |
|
91 return; |
|
92 } |
|
93 |
|
94 //custom draw |
|
95 TInt topline = aParam.iDrawRect.iTl.iY; |
|
96 TInt bottomline = aParam.iDrawRect.iBr.iY; |
|
97 TInt baseline = aLineInfo.iBaseline; |
|
98 TPoint basepoint = aParam.iDrawRect.iTl; |
|
99 basepoint.iY = baseline; |
|
100 |
|
101 CFont* font = NULL; |
|
102 aParam.iMap.GetNearestFontInTwips( font, aFormat.iFontSpec ); |
|
103 |
|
104 //cut off regions occupied by smiley characters. |
|
105 //smiley character is displayed as a rectangle if not supported by current font. |
|
106 RRegion rgn; |
|
107 TRAP_IGNORE( |
|
108 iParentControl->CalcSmileyClipRegionL( |
|
109 rgn, aParam.iGc, *font, |
|
110 aText, basepoint, topline, |
|
111 bottomline ) |
|
112 ); |
|
113 |
|
114 //call default drawing first |
|
115 aParam.iGc.SetClippingRegion( rgn ); |
|
116 |
|
117 MFormCustomDraw::DrawText( aParam, aLineInfo, aFormat, aText, |
|
118 aTextOrigin, aExtraPixels ); |
|
119 |
|
120 aParam.iGc.CancelClippingRegion(); |
|
121 |
|
122 rgn.Close(); |
|
123 |
|
124 //fill in smiley icons |
|
125 TRAP_IGNORE( |
|
126 iParentControl->CustomDrawSmileyL( |
|
127 aParam.iGc, *font, aText, |
|
128 basepoint, topline, bottomline ) |
|
129 ); |
|
130 |
|
131 aParam.iMap.ReleaseFont( font ); |
|
132 } |
|
133 |
|
134 void CFepLayoutMIcfCustomDraw::DrawText( const TParam& aParam, const TLineInfo& aLineInfo, |
|
135 const TCharFormat& aFormat, const TDesC& aText, |
|
136 const TInt aStart, const TInt aEnd, |
|
137 const TPoint& aTextOrigin,TInt aExtraPixels) const |
|
138 { |
|
139 TPtrC text = aText.Mid( aStart, aEnd - aStart ); |
|
140 DrawText( aParam, aLineInfo, aFormat, text, aTextOrigin, aExtraPixels ); |
|
141 } |
|
142 |
|
143 |
|
144 TBool CFepLayoutMIcfCustomWrap::LineBreakPossible(TUint aPrevClass, TUint aNextClass, |
|
145 TBool aHaveSpaces) const |
|
146 { |
|
147 if( aHaveSpaces ) |
|
148 { |
|
149 return ETrue; |
|
150 } |
|
151 return MFormCustomWrap::LineBreakPossible( aPrevClass, aNextClass, aHaveSpaces ); |
|
152 } |
|
153 |
|
154 TUint CFepLayoutMIcfCustomWrap::LineBreakClass(TUint aCode, TUint& aRangeStart, |
|
155 TUint& aRangeEnd) const |
|
156 { |
|
157 aRangeStart = aCode; |
|
158 aRangeEnd = aCode + 1; |
|
159 |
|
160 switch (aCode) |
|
161 { |
|
162 case 0x0020: // unicode for space |
|
163 return MTmCustom::EBkLineBreakClass;//ELineBreakClasses; |
|
164 default: |
|
165 break; // carry on |
|
166 } |
|
167 |
|
168 return MFormCustomWrap::LineBreakClass(aCode,aRangeStart,aRangeEnd); |
|
169 } |
|
170 |
|
171 // End Of File |