|
1 /* |
|
2 * Copyright (c) 2002-2004 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 * Provides the CAknFepUICtrlCandidateSelected methods. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
30 #include <uikon/eikdefmacros.h> |
|
31 #endif |
|
32 #include <eiklabel.h> |
|
33 #include <AknUtils.h> |
|
34 #include <AknsDrawUtils.h> |
|
35 #include "AknFepUIAvkonCtrlCandidateSelected.h" |
|
36 #include "AknFepUIAvkonCtrlPinyinPopup.h" |
|
37 #include "AknFepUiInterfacePanic.h" |
|
38 #include <skinlayout.cdl.h> |
|
39 |
|
40 class CEikLabel; |
|
41 |
|
42 CAknFepUICtrlCandidateSelected* CAknFepUICtrlCandidateSelected::NewL(RWindowTreeNode& aParent) |
|
43 { |
|
44 CAknFepUICtrlCandidateSelected* self = new(ELeave) CAknFepUICtrlCandidateSelected; |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(aParent); |
|
47 CleanupStack::Pop(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CAknFepUICtrlCandidateSelected::~CAknFepUICtrlCandidateSelected() |
|
52 { |
|
53 delete iOrdinalLabel; |
|
54 delete iCandidateLabel; |
|
55 } |
|
56 |
|
57 void CAknFepUICtrlCandidateSelected::SetText(TPtrC aCharacter) |
|
58 { |
|
59 // make sure that we only copy as many characters as we can show |
|
60 TInt textLen = aCharacter.Length(); |
|
61 TInt textLength = textLen > EMaxSelectedCandidateLength? EMaxSelectedCandidateLength:textLen; |
|
62 TPtrC newText = aCharacter.Left(textLength); |
|
63 TPtr ptr = iBuffer.Des(); |
|
64 if(ptr != newText) |
|
65 { |
|
66 ptr.Copy(newText); |
|
67 // ignore any errors... we have guaranteed that the descriptor already has sufficient characters to avoid a realloc |
|
68 TRAP_IGNORE( iCandidateLabel->SetTextL(iBuffer)); |
|
69 } |
|
70 } |
|
71 |
|
72 void CAknFepUICtrlCandidateSelected::SetOrdinal(TInt aOrdinal) |
|
73 { |
|
74 __ASSERT_DEBUG(aOrdinal < CAknFepUICtrlPinyinPopup::EMaxPhraseCandidate, AknFepUiInterfacePanic(EAknFepUiInterfacePanicNewVisibleCountExceedsRange)); |
|
75 __ASSERT_DEBUG(aOrdinal >= 0, AknFepUiInterfacePanic(EAknFepUiInterfacePanicNewVisibleCountExceedsRange)); |
|
76 |
|
77 TBuf<2> buf; |
|
78 buf.Format(_L("%d"), aOrdinal); |
|
79 TRAP_IGNORE(iOrdinalLabel->SetTextL(buf)); |
|
80 } |
|
81 |
|
82 void CAknFepUICtrlCandidateSelected::SetCandidateMode(CAknFepUICtrlCandidatePane::TCandidateMode aMode) |
|
83 { |
|
84 if(iCandidateMode != aMode) |
|
85 { |
|
86 iCandidateMode = aMode; |
|
87 |
|
88 LayoutRects(); |
|
89 LayoutContainedControls(); |
|
90 DrawDeferred(); |
|
91 } |
|
92 } |
|
93 |
|
94 void CAknFepUICtrlCandidateSelected::SetLayout(CAknFepUICtrlContainerChinese::TPaneLayout aLayout) |
|
95 { |
|
96 iPaneLayout = aLayout; |
|
97 } |
|
98 |
|
99 void CAknFepUICtrlCandidateSelected::ShowOrdinal(TBool aValue) |
|
100 { |
|
101 if(!COMPARE_BOOLS(iShowOrdinal,aValue)) |
|
102 { |
|
103 iShowOrdinal = aValue; |
|
104 UpdateLabelVisibility(); |
|
105 } |
|
106 } |
|
107 |
|
108 void CAknFepUICtrlCandidateSelected::SizeChanged() |
|
109 { |
|
110 LayoutRects(); |
|
111 LayoutContainedControls(); |
|
112 } |
|
113 |
|
114 TInt CAknFepUICtrlCandidateSelected::CountComponentControls() const |
|
115 { |
|
116 CCoeControl* controls[] = |
|
117 { |
|
118 iOrdinalLabel, |
|
119 iCandidateLabel |
|
120 } ; |
|
121 |
|
122 TInt count = 0 ; |
|
123 for (TUint ii = 0 ; ii < (sizeof(controls) / sizeof(CCoeControl*)) ; ii++) |
|
124 if(controls[ii]) |
|
125 count++ ; |
|
126 return count ; |
|
127 } |
|
128 |
|
129 CCoeControl* CAknFepUICtrlCandidateSelected::ComponentControl(TInt aIndex) const |
|
130 { |
|
131 CCoeControl* controls[] = |
|
132 { |
|
133 iOrdinalLabel, |
|
134 iCandidateLabel |
|
135 } ; |
|
136 |
|
137 for (TUint ii = 0; (ii < sizeof(controls) / sizeof(CCoeControl*)) ; ii++) |
|
138 if (controls[ii] && aIndex-- == 0) |
|
139 return controls[ii] ; |
|
140 // shouldn't be called while no components. |
|
141 return NULL ; |
|
142 } |
|
143 |
|
144 void CAknFepUICtrlCandidateSelected::Draw(const TRect& /*aRect*/) const |
|
145 { |
|
146 CWindowGc& gc = SystemGc(); |
|
147 |
|
148 TBool skinnedDraw = EFalse; |
|
149 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
150 TRect outerRect; |
|
151 TRect innerRect; |
|
152 CalculateFrameRects(outerRect, innerRect); |
|
153 |
|
154 // draw the whole frame background according to the containing context, which in this case |
|
155 // is the candidate pane, to avoid corner drawing mess and to cope with masked grid frame centre |
|
156 MAknsControlContext* cc = AknsDrawUtils::ControlContext(this); |
|
157 AknsDrawUtils::DrawBackground(skin, cc, this, gc, |
|
158 outerRect.iTl, outerRect, KAknsDrawParamDefault); |
|
159 |
|
160 skinnedDraw = AknsDrawUtils::DrawFrame(skin, gc, outerRect, innerRect, |
|
161 KAknsIIDQsnFrGrid, KAknsIIDQsnFrGridCenter); |
|
162 |
|
163 if(!skinnedDraw) |
|
164 { |
|
165 iRectShadow.DrawRect(gc); |
|
166 iRectHighlight.DrawRect(gc); |
|
167 } |
|
168 } |
|
169 |
|
170 void CAknFepUICtrlCandidateSelected::ConstructL(RWindowTreeNode& aParent) |
|
171 { |
|
172 CreateWindowL(aParent); |
|
173 |
|
174 iOrdinalLabel = new(ELeave) CEikLabel; |
|
175 iOrdinalLabel->SetBufferReserveLengthL(EOneCandidate); |
|
176 iOrdinalLabel->SetContainerWindowL(*this); |
|
177 |
|
178 // force label to contain required number of characters from the outset |
|
179 iCandidateLabel = new(ELeave) CEikLabel; |
|
180 iCandidateLabel->SetBufferReserveLengthL(EMaxSelectedCandidateLength); // this will do a realloc now, so no need to later |
|
181 iCandidateLabel->SetContainerWindowL(*this); |
|
182 } |
|
183 |
|
184 CAknFepUICtrlCandidateSelected::CAknFepUICtrlCandidateSelected() |
|
185 : |
|
186 iCandidateMode(CAknFepUICtrlCandidatePane::ECandidateModeNormal), |
|
187 iPaneLayout(CAknFepUICtrlContainerChinese::ELayoutCandidate), |
|
188 iShowOrdinal(ETrue) |
|
189 { |
|
190 } |
|
191 |
|
192 void CAknFepUICtrlCandidateSelected::LayoutRects() |
|
193 { |
|
194 TRect rect = Rect(); |
|
195 iRectShadow.LayoutRect(rect, AKN_LAYOUT_WINDOW_Candidate_selection_highlight_Line_1(rect)); |
|
196 iRectHighlight.LayoutRect(rect, AKN_LAYOUT_WINDOW_Candidate_selection_highlight_Line_2(rect)); |
|
197 } |
|
198 |
|
199 void CAknFepUICtrlCandidateSelected::LayoutContainedControls() |
|
200 { |
|
201 TRect rect = Rect(); |
|
202 |
|
203 // layout candidate label |
|
204 TAknTextLineLayout candidateLayout = AKN_LAYOUT_TEXT_Chinese_universal_FEP_candidate_pane_texts_Line_1; |
|
205 TAknTextLineLayout ordinalLayout = AKN_LAYOUT_TEXT_Chinese_universal_FEP_candidate_pane_texts_Line_3; |
|
206 candidateLayout.il = candidateLayout.il - ordinalLayout.il; |
|
207 |
|
208 TAknLayoutText layoutCandidate; |
|
209 layoutCandidate.LayoutText(rect,candidateLayout); |
|
210 |
|
211 const CFont* font = layoutCandidate.Font(); |
|
212 TInt labelWidthInPixels = 0; |
|
213 if(font) |
|
214 { |
|
215 TInt bufLength = iBuffer.Length(); |
|
216 if(bufLength != 0) |
|
217 { |
|
218 TPtrC newChars = iBuffer.Left(bufLength); |
|
219 labelWidthInPixels = font->TextWidthInPixels(newChars); |
|
220 } |
|
221 } |
|
222 TRect rectCandidate = layoutCandidate.TextRect(); |
|
223 if(labelWidthInPixels == 0) |
|
224 { |
|
225 rectCandidate.iTl.iX = 0; |
|
226 } |
|
227 rectCandidate.SetWidth(labelWidthInPixels); |
|
228 iCandidateLabel->SetRect(rectCandidate); |
|
229 iCandidateLabel->SetFont(font); |
|
230 |
|
231 // layout ordinal label |
|
232 TBufC16<1> buf; |
|
233 TPtr16 ptr = buf.Des(); |
|
234 ptr = (*(iOrdinalLabel->Text())).Left(EOneCandidate); |
|
235 |
|
236 TAknLayoutText layoutOrdinal; |
|
237 ordinalLayout.il = 0; |
|
238 |
|
239 layoutOrdinal.LayoutText(rect,ordinalLayout); |
|
240 |
|
241 const CFont* fontOrdinal = layoutOrdinal.Font(); |
|
242 |
|
243 TRect ordinalRect = layoutOrdinal.TextRect(); |
|
244 |
|
245 // inserted in 2006.03.29 |
|
246 TPoint ordinalPosition; |
|
247 // end inserting |
|
248 TInt ordinalWidth = fontOrdinal->TextWidthInPixels(ptr); |
|
249 |
|
250 /* removing in 2006.03.29 |
|
251 ordinalRect.iTl.iX = rectCandidate.iTl.iX - ordinalWidth; |
|
252 ordinalRect.iTl.iY = rectCandidate.iTl.iY; |
|
253 |
|
254 ordinalRect.SetWidth(ordinalWidth); |
|
255 ordinalRect.SetHeight(fontOrdinal->HeightInPixels()); |
|
256 */ // end removing |
|
257 |
|
258 // inserted in 2006.03.29 |
|
259 ordinalPosition.iX = rectCandidate.iTl.iX - ordinalWidth; |
|
260 ordinalPosition.iY = rectCandidate.iTl.iY; |
|
261 |
|
262 ordinalRect = TRect(ordinalPosition, |
|
263 TPoint(ordinalPosition.iX + ordinalRect.Width(), |
|
264 ordinalPosition.iY + ordinalRect.Height())); |
|
265 // end inserting |
|
266 |
|
267 iOrdinalLabel->SetRect(ordinalRect); |
|
268 iOrdinalLabel->SetFont(fontOrdinal); |
|
269 |
|
270 // override with skin text color |
|
271 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
272 TRgb labelTextColor; |
|
273 |
|
274 AknsUtils::GetCachedColor(skin, labelTextColor, |
|
275 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11); |
|
276 |
|
277 TRAP_IGNORE( |
|
278 iCandidateLabel->OverrideColorL(EColorLabelText, labelTextColor); |
|
279 iOrdinalLabel->OverrideColorL(EColorLabelText, labelTextColor); |
|
280 ); |
|
281 } |
|
282 |
|
283 void CAknFepUICtrlCandidateSelected::CalculateFrameRects(TRect& aOuterRect, TRect& aInnerRect) const |
|
284 { |
|
285 TRect windowRect = Rect(); |
|
286 |
|
287 TAknLayoutRect topLeft; |
|
288 topLeft.LayoutRect(windowRect, SkinLayout::Highlight_skin_placing__grid__Line_2()); |
|
289 |
|
290 TAknLayoutRect bottomRight; |
|
291 bottomRight.LayoutRect(windowRect, SkinLayout::Highlight_skin_placing__grid__Line_5()); |
|
292 |
|
293 aOuterRect = TRect(topLeft.Rect().iTl, bottomRight.Rect().iBr); |
|
294 aInnerRect = TRect(topLeft.Rect().iBr, bottomRight.Rect().iTl); |
|
295 } |
|
296 |
|
297 void CAknFepUICtrlCandidateSelected::UpdateLabelVisibility() |
|
298 { |
|
299 if(iShowOrdinal) |
|
300 { |
|
301 iOrdinalLabel->MakeVisible(ETrue); |
|
302 } |
|
303 else |
|
304 { |
|
305 iOrdinalLabel->MakeVisible(EFalse); |
|
306 } |
|
307 } |
|
308 |
|
309 // End of file |