|
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 CAknFepUICtrlCandidateCharacter methods. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 #include <AknUtils.h> |
|
30 #include <AknsDrawUtils.h> |
|
31 #include <eiklabel.h> |
|
32 #include <skinlayout.cdl.h> |
|
33 #include <aknlayoutscalable_avkon.cdl.h> |
|
34 |
|
35 #include "AknFepUiInputStateBase.h" |
|
36 #include "AknFepUIAvkonCtrlCandidateCharacter.h" |
|
37 #include "AknFepUIAvkonCtrlPinyinPopup.h" |
|
38 #include "AknFepUiInterfacePanic.h" |
|
39 #include "AknFepUIAvkonCtrlCandidatePane.h" |
|
40 |
|
41 |
|
42 CAknFepUICtrlCandidateCharacter* CAknFepUICtrlCandidateCharacter::NewL( RWindowTreeNode& aParent, |
|
43 MAknFepUIEventObserver* aObserver ) |
|
44 { |
|
45 CAknFepUICtrlCandidateCharacter* self = new(ELeave) CAknFepUICtrlCandidateCharacter; |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL( aParent, aObserver ); |
|
48 CleanupStack::Pop(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CAknFepUICtrlCandidateCharacter::~CAknFepUICtrlCandidateCharacter() |
|
53 { |
|
54 delete iCandidateLabel; |
|
55 } |
|
56 |
|
57 const TDesC* CAknFepUICtrlCandidateCharacter::Text() const |
|
58 { |
|
59 return iCandidateLabel->Text(); |
|
60 } |
|
61 |
|
62 void CAknFepUICtrlCandidateCharacter::SetText( const TDesC& aCharacter ) |
|
63 { |
|
64 // make sure that we only copy as many characters as we can show |
|
65 TInt textLen = aCharacter.Length(); |
|
66 TInt textLength = textLen > EMaxSelectedCandidateLength? EMaxSelectedCandidateLength:textLen; |
|
67 TPtrC newText = aCharacter.Left( textLength ); |
|
68 TPtr ptr = iBuffer.Des(); |
|
69 if ( ptr.Compare( newText ) != 0 ) |
|
70 { |
|
71 ptr.Copy( newText ); |
|
72 |
|
73 // ignore any errors... we have guaranteed that the descriptor already has sufficient characters to avoid a realloc |
|
74 TRAP_IGNORE( iCandidateLabel->SetTextL( iBuffer )); |
|
75 } |
|
76 } |
|
77 |
|
78 void CAknFepUICtrlCandidateCharacter::SizeChanged() |
|
79 { |
|
80 LayoutRects(); |
|
81 LayoutContainedControls(); |
|
82 } |
|
83 |
|
84 TInt CAknFepUICtrlCandidateCharacter::CountComponentControls() const |
|
85 { |
|
86 CCoeControl* controls[] = |
|
87 { |
|
88 iCandidateLabel |
|
89 } ; |
|
90 |
|
91 TInt count = 0 ; |
|
92 for ( TUint ii = 0; ii < ( sizeof(controls) / sizeof(CCoeControl*)) ;ii++ ) |
|
93 { |
|
94 if(controls[ii]) |
|
95 { |
|
96 count++; |
|
97 } |
|
98 } |
|
99 return count ; |
|
100 } |
|
101 |
|
102 CCoeControl* CAknFepUICtrlCandidateCharacter::ComponentControl( TInt aIndex ) const |
|
103 { |
|
104 CCoeControl* controls[] = |
|
105 { |
|
106 iCandidateLabel |
|
107 } ; |
|
108 |
|
109 for (TUint ii = 0; ( ii < sizeof(controls) / sizeof(CCoeControl*)); ii++ ) |
|
110 { |
|
111 if ( controls[ii] && aIndex-- == 0 ) |
|
112 { |
|
113 return controls[ii]; |
|
114 } |
|
115 } |
|
116 // shouldn't be called while no components. |
|
117 return NULL ; |
|
118 } |
|
119 |
|
120 void CAknFepUICtrlCandidateCharacter::Draw( const TRect& /*aRect*/ ) const |
|
121 { |
|
122 CWindowGc& gc = SystemGc(); |
|
123 |
|
124 TBool skinnedDraw = EFalse; |
|
125 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
126 TRect outerRect; |
|
127 TRect innerRect; |
|
128 CalculateFrameRects( outerRect, innerRect ); |
|
129 |
|
130 // draw the whole frame background according to the containing context, which in this case |
|
131 // is the candidate pane, to avoid corner drawing mess and to cope with masked grid frame centre |
|
132 MAknsControlContext* cc = AknsDrawUtils::ControlContext(this); |
|
133 |
|
134 // Set highlight color to gray |
|
135 if( iIsHighligt ) |
|
136 { |
|
137 |
|
138 skinnedDraw = AknsDrawUtils::DrawFrame( skin, gc, outerRect, innerRect, |
|
139 KAknsIIDQsnFrKeypadButtonFrPressed, |
|
140 KAknsIIDDefault ); |
|
141 } |
|
142 else |
|
143 { |
|
144 |
|
145 skinnedDraw = AknsDrawUtils::DrawFrame( skin, gc, outerRect, innerRect, |
|
146 KAknsIIDQsnFrKeypadButtonFrNormal, |
|
147 KAknsIIDDefault ); |
|
148 } |
|
149 |
|
150 if ( !skinnedDraw ) |
|
151 { |
|
152 iRectShadow.DrawRect( gc ); |
|
153 iRectHighlight.DrawRect( gc ); |
|
154 } |
|
155 } |
|
156 |
|
157 void CAknFepUICtrlCandidateCharacter::ConstructL( RWindowTreeNode& aParent, MAknFepUIEventObserver* aObserver ) |
|
158 { |
|
159 CreateWindowL( aParent ); |
|
160 |
|
161 iCandidateLabel = new(ELeave) CEikLabel; |
|
162 iCandidateLabel->SetBufferReserveLengthL( EMaxSelectedCandidateLength ); // this will do a realloc now, so no need to later |
|
163 iCandidateLabel->SetContainerWindowL( *this ); |
|
164 iCandidateLabel->SetLabelAlignment( ELayoutAlignCenter ); |
|
165 } |
|
166 |
|
167 CAknFepUICtrlCandidateCharacter::CAknFepUICtrlCandidateCharacter() |
|
168 { |
|
169 } |
|
170 |
|
171 void CAknFepUICtrlCandidateCharacter::LayoutRects() |
|
172 { |
|
173 TRect rect = Rect(); |
|
174 iRectShadow.LayoutRect( rect, AKN_LAYOUT_WINDOW_Candidate_selection_highlight_Line_1(rect)); |
|
175 iRectHighlight.LayoutRect( rect, AKN_LAYOUT_WINDOW_Candidate_selection_highlight_Line_2(rect)); |
|
176 iRectShadow.LayoutRect( rect, AknLayoutScalable_Avkon::cell_hyb_candi_pane_g1( 0 )); |
|
177 } |
|
178 |
|
179 |
|
180 void CAknFepUICtrlCandidateCharacter::LayoutContainedControls() |
|
181 { |
|
182 TRect rect = Rect(); |
|
183 |
|
184 TAknTextLineLayout candidateLayout = AknLayoutScalable_Avkon::cell_hyb_candi_pane_t1(0); |
|
185 |
|
186 TAknLayoutText layoutText; |
|
187 layoutText.LayoutText( rect, candidateLayout ); |
|
188 TRect rectText = layoutText.TextRect(); |
|
189 const CFont* font = layoutText.Font(); |
|
190 |
|
191 iCandidateLabel->SetRect( rectText ); |
|
192 iCandidateLabel->SetFont( font ); |
|
193 |
|
194 // override with skin text color |
|
195 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
196 TRgb labelTextColor; |
|
197 |
|
198 AknsUtils::GetCachedColor( skin, labelTextColor, |
|
199 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 ); |
|
200 |
|
201 TRAP_IGNORE( |
|
202 iCandidateLabel->OverrideColorL(EColorLabelText, labelTextColor); |
|
203 ); |
|
204 } |
|
205 |
|
206 void CAknFepUICtrlCandidateCharacter::CalculateFrameRects(TRect& aOuterRect, TRect& aInnerRect) const |
|
207 { |
|
208 TRect windowRect = Rect(); |
|
209 |
|
210 TAknLayoutRect topLeft; |
|
211 topLeft.LayoutRect( windowRect, SkinLayout::Highlight_skin_placing__grid__Line_2()); |
|
212 |
|
213 TAknLayoutRect bottomRight; |
|
214 bottomRight.LayoutRect( windowRect, SkinLayout::Highlight_skin_placing__grid__Line_5()); |
|
215 |
|
216 aOuterRect = TRect( topLeft.Rect().iTl, bottomRight.Rect().iBr ); |
|
217 aInnerRect = TRect( topLeft.Rect().iBr, bottomRight.Rect().iTl ); |
|
218 } |
|
219 |
|
220 void CAknFepUICtrlCandidateCharacter::SetHighlight( TBool bHighlight ) |
|
221 { |
|
222 iIsHighligt = bHighlight; |
|
223 DrawDeferred(); |
|
224 } |
|
225 |
|
226 // End of file |