1 /* |
|
2 * Copyright (c) 2005-2007 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: vkb control extension |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System includes |
|
20 #include <barsread.h> |
|
21 #include <peninputlayout.h> |
|
22 #include <AknIconUtils.h> |
|
23 #include <AknsUtils.h> |
|
24 #include <coemain.h> |
|
25 |
|
26 // User includes |
|
27 #include "peninputvkbctrlext.h" |
|
28 #include "peninputvkbctrllayout.h" |
|
29 |
|
30 // Constants |
|
31 const TUint32 KDefaultTextColor = 0x000000; |
|
32 const TInt32 KInvalidResId = -1; |
|
33 const TInt KInvalidImg = -1 ; |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 |
|
37 |
|
38 // -------------------------------------------------------------------------- |
|
39 // CPeninputVkbCtrlExt::CPeninputVkbCtrlExt |
|
40 // (other items were commented in a header) |
|
41 // -------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C CPeninputVkbCtrlExt::CPeninputVkbCtrlExt( const TRect& aRect, |
|
44 CFepUiLayout* aUiLayout, TInt aControlId, const TFontSpec& aFontSpec,TBool aIrregular ) |
|
45 : CVirtualKeyboard( aRect, aUiLayout, aControlId, aFontSpec, aIrregular ) |
|
46 { |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CPeninputVkbCtrlExt::NewL |
|
51 // (other items were commented in a header) |
|
52 // -------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CPeninputVkbCtrlExt* CPeninputVkbCtrlExt::NewL( const TRect& aRect, |
|
55 CFepUiLayout* aUiLayout, TInt aControlId, const CFont* aFont,TBool aIrregular) |
|
56 { |
|
57 TFontSpec fontSpec; |
|
58 |
|
59 CPeninputVkbCtrlExt* vkb = new (ELeave) |
|
60 CPeninputVkbCtrlExt( aRect, aUiLayout, aControlId, fontSpec,aIrregular ); |
|
61 CleanupStack::PushL( vkb ); |
|
62 vkb->ConstructL(); |
|
63 vkb->SetFont( aFont ); |
|
64 CleanupStack::Pop( vkb ); |
|
65 |
|
66 return vkb; |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CPeninputVkbCtrlExt::~CPeninputVkbCtrlExt |
|
71 // (other items were commented in a header) |
|
72 // -------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C CPeninputVkbCtrlExt::~CPeninputVkbCtrlExt() |
|
75 { |
|
76 Reset(); |
|
77 if( iResourceId == KInvalidImg ) |
|
78 { |
|
79 SetBackgroundBmp( NULL ); |
|
80 SetBackgroundMaskBmp( NULL ); |
|
81 } |
|
82 } |
|
83 |
|
84 // -------------------------------------------------------------------------- |
|
85 // CPeninputVkbCtrlExt::SizeChanged |
|
86 // (other items were commented in a header) |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C void CPeninputVkbCtrlExt::SizeChanged( const TInt aUnitWidth, |
|
90 const TInt aUnitHeight, |
|
91 const TPoint& aLeftTopPoint ) |
|
92 { |
|
93 iUnitWidth = aUnitWidth; |
|
94 iUnitHeight = aUnitHeight; |
|
95 iLeftTopPoint = aLeftTopPoint; |
|
96 |
|
97 if ( iVkbLayoutInfo ) |
|
98 { |
|
99 // 1.Reset the size and position of Vkb ctrl and keys |
|
100 TRect rect = TRect( iLeftTopPoint, TSize( iUnitWidth * iVkbLayoutInfo->Columns(), |
|
101 iUnitHeight * iVkbLayoutInfo->Rows() ) ); |
|
102 SetRect( rect ); |
|
103 |
|
104 // 2.Move all keys(Needn't change size, because it has been |
|
105 } |
|
106 } |
|
107 |
|
108 // -------------------------------------------------------------------------- |
|
109 // CPeninputVkbCtrlExt::SizeChanged |
|
110 // (other items were commented in a header) |
|
111 // -------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C void CPeninputVkbCtrlExt::SizeChanged( const TRect& aRect ) |
|
114 { |
|
115 SetRect( aRect ); |
|
116 } |
|
117 |
|
118 |
|
119 // CPeninputVkbCtrlExt::ReorganizeVkbKeys |
|
120 // (other items were commented in a header) |
|
121 // -------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C void CPeninputVkbCtrlExt::ReorganizeVkbKeys( |
|
124 CPeninputVkbLayoutInfo* aVkbLayoutInfo ) |
|
125 { |
|
126 Reset(); |
|
127 |
|
128 iVkbLayoutInfo = aVkbLayoutInfo; |
|
129 |
|
130 TRect rect = TRect( iLeftTopPoint, TSize( iUnitWidth * iVkbLayoutInfo->Columns(), |
|
131 iUnitHeight * iVkbLayoutInfo->Rows() ) ); |
|
132 if( iResourceId != KInvalidImg ) |
|
133 { |
|
134 if( BackgroundBmp() && BackgroundBmp()->SizeInPixels() != Rect().Size() ) |
|
135 AknIconUtils::SetSize(BackgroundBmp(), Rect().Size(), EAspectRatioNotPreserved); |
|
136 if( BkMaskBmp() && BkMaskBmp()->SizeInPixels() != Rect().Size() ) |
|
137 AknIconUtils::SetSize(BkMaskBmp(), Rect().Size(), EAspectRatioNotPreserved); |
|
138 } |
|
139 else |
|
140 { |
|
141 if ( iVkbLayoutInfo->BgBmp() ) |
|
142 { |
|
143 SetBackgroundBmp( iVkbLayoutInfo->BgBmp() ) ; |
|
144 } |
|
145 |
|
146 if ( iVkbLayoutInfo->BgMaskBmp() ) |
|
147 { |
|
148 SetBackgroundMaskBmp( iVkbLayoutInfo->BgMaskBmp() ); |
|
149 } |
|
150 } |
|
151 // SetRect( rect ); |
|
152 |
|
153 // According the information in vkbLayout to construct all keys and |
|
154 // then add into the keys. |
|
155 /* |
|
156 if ( iVkbLayoutInfo->BgBmp() ) |
|
157 { |
|
158 TRAP_IGNORE( SetBackgroundBitmapL( iVkbLayoutInfo->BgBmp() ) ); |
|
159 } |
|
160 |
|
161 if ( iVkbLayoutInfo->BgMaskBmp() ) |
|
162 { |
|
163 TRAP_IGNORE( SetBackgroundMaskBitmapL( iVkbLayoutInfo->BgMaskBmp() ) ); |
|
164 } |
|
165 */ |
|
166 if ( iVkbLayoutInfo->DimBmp() ) |
|
167 { |
|
168 SetDimKeyBmp( iVkbLayoutInfo->DimBmp() ); |
|
169 } |
|
170 |
|
171 if ( iVkbLayoutInfo->DimMaskBmp() ) |
|
172 { |
|
173 SetDimKeyMaskBmp( iVkbLayoutInfo->DimMaskBmp() ); |
|
174 } |
|
175 |
|
176 TInt count = iVkbLayoutInfo->HighlightBmps().Count(); |
|
177 |
|
178 TRAP_IGNORE( |
|
179 for ( TInt i = 0; i < count; i++ ) |
|
180 { |
|
181 AddKeyHighLightBitmapL(iVkbLayoutInfo->HighlightBmps()[i]); |
|
182 } |
|
183 ); |
|
184 |
|
185 count = iVkbLayoutInfo->HighlightMaskBmps().Count(); |
|
186 |
|
187 TRAP_IGNORE( |
|
188 for ( TInt i = 0; i < count; i++ ) |
|
189 { |
|
190 AddKeyHighLightMaskBitmapL(iVkbLayoutInfo->HighlightMaskBmps()[i]); |
|
191 } |
|
192 ); |
|
193 |
|
194 count = iVkbLayoutInfo->KeyInfoList().Count(); |
|
195 TRAP_IGNORE( |
|
196 for ( TInt i = 0; i < count; i++ ) |
|
197 { |
|
198 iVkbLayoutInfo->KeyInfoList()[i]->Key()->SetDimmed( EFalse ); |
|
199 AddKeyL( iVkbLayoutInfo->KeyInfoList()[i]->Key() ); |
|
200 } |
|
201 ); |
|
202 |
|
203 TRgb textColor; |
|
204 TInt error = AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), |
|
205 textColor, |
|
206 KAknsIIDQsnTextColors, |
|
207 EAknsCIQsnTextColorsCG59); |
|
208 if (error != KErrNone) |
|
209 { |
|
210 textColor = TRgb( KDefaultTextColor ); |
|
211 } |
|
212 SetFontColor( textColor ); |
|
213 |
|
214 Draw(); |
|
215 } |
|
216 |
|
217 // -------------------------------------------------------------------------- |
|
218 // CPeninputVkbCtrlExt::Reset |
|
219 // (other items were commented in a header) |
|
220 // -------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C void CPeninputVkbCtrlExt::Reset() |
|
223 { |
|
224 const RPointerArray<CVirtualKey>& keys = KeyArray(); |
|
225 for(TInt i = keys.Count() - 1 ; i >= 0 ; --i) |
|
226 { |
|
227 RemoveKey(keys[i]); |
|
228 } |
|
229 |
|
230 const RPointerArray<CFbsBitmap>& bmps = KeyHighlightBmpList(); |
|
231 for(TInt i = bmps.Count() - 1 ; i >= 0 ; --i) |
|
232 { |
|
233 RemoveKeyHighLightBitmap(i); |
|
234 } |
|
235 |
|
236 const RPointerArray<CFbsBitmap>& maskbmps = KeyHighlightMaskBmpList(); |
|
237 for(TInt i = maskbmps.Count() - 1 ; i >= 0 ; --i) |
|
238 { |
|
239 RemoveKeyHighLightMaskBitmap(i); |
|
240 } |
|
241 |
|
242 SetDimKeyBmp( NULL ); |
|
243 SetDimKeyMaskBmp( NULL ); |
|
244 |
|
245 iVkbLayoutInfo = NULL; |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CPeninputVkbCtrlExt::Move |
|
250 // (other items were commented in a header) |
|
251 // -------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C void CPeninputVkbCtrlExt::Move( const TPoint& aOffset ) |
|
254 { |
|
255 TRect rect = Rect(); |
|
256 rect.Move( aOffset ); |
|
257 SetRect( rect ); |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // CPeninputVkbCtrlExt::DimKeys |
|
262 // (other items were commented in a header) |
|
263 // -------------------------------------------------------------------------- |
|
264 // |
|
265 EXPORT_C void CPeninputVkbCtrlExt::DimKeys( const HBufC* aPermitted ) |
|
266 { |
|
267 TInt count = iVkbLayoutInfo->KeyInfoList().Count(); |
|
268 |
|
269 for ( TInt i = 0; i < count ; i++ ) |
|
270 { |
|
271 TChar ch = TChar( (TUint)( KeyArray()[i]->KeyCode() ) ); |
|
272 TInt index = aPermitted->Locate( ch ) ; |
|
273 |
|
274 if ( index == KErrNotFound ) |
|
275 { |
|
276 DimKey( KeyArray()[i], ETrue ); |
|
277 } |
|
278 } |
|
279 } |
|
280 |
|
281 // -------------------------------------------------------------------------- |
|
282 // CPeninputVkbCtrlExt::DimKeySet |
|
283 // (other items were commented in a header) |
|
284 // -------------------------------------------------------------------------- |
|
285 // |
|
286 EXPORT_C void CPeninputVkbCtrlExt::DimKeySet( const HBufC* aSet, TBool aDim ) |
|
287 { |
|
288 TInt keyCount = iVkbLayoutInfo->KeyInfoList().Count(); |
|
289 TInt setCount = const_cast<HBufC*>(aSet)->Des().Length(); |
|
290 TInt findNum = 0; |
|
291 |
|
292 for ( TInt i = 0; i < keyCount ; i++ ) |
|
293 { |
|
294 TChar ch = TChar( (TUint)( KeyArray()[i]->KeyCode() ) ); |
|
295 TInt index = aSet->Locate( ch ) ; |
|
296 |
|
297 if ( index != KErrNotFound ) |
|
298 { |
|
299 findNum++; |
|
300 DimKey( KeyArray()[i], aDim ); |
|
301 } |
|
302 |
|
303 if ( findNum == setCount ) |
|
304 { |
|
305 break; |
|
306 } |
|
307 } |
|
308 } |
|
309 |
|
310 // -------------------------------------------------------------------------- |
|
311 // CPeninputVkbCtrlExt::CancelDims |
|
312 // (other items were commented in a header) |
|
313 // -------------------------------------------------------------------------- |
|
314 // |
|
315 EXPORT_C void CPeninputVkbCtrlExt::CancelDims() |
|
316 { |
|
317 TInt count = iVkbLayoutInfo->KeyInfoList().Count(); |
|
318 |
|
319 for ( TInt i = 0; i < count ; i++ ) |
|
320 { |
|
321 DimKey( KeyArray()[i], EFalse ); |
|
322 } |
|
323 } |
|
324 |
|
325 // -------------------------------------------------------------------------- |
|
326 // CPeninputVkbCtrlExt::ConstructFromResourceL |
|
327 // (other items were commented in a header) |
|
328 // -------------------------------------------------------------------------- |
|
329 // |
|
330 EXPORT_C void CPeninputVkbCtrlExt::ConstructFromResourceL() |
|
331 { |
|
332 if (iResourceId == KInvalidResId) |
|
333 { |
|
334 return; |
|
335 } |
|
336 |
|
337 // Release original resource |
|
338 if( BackgroundBmp() ) |
|
339 { |
|
340 CFbsBitmap* bkBmp = BackgroundBmp(); |
|
341 delete bkBmp; |
|
342 SetBackgroundBmp( NULL ); |
|
343 } |
|
344 if( BkMaskBmp() ) |
|
345 { |
|
346 CFbsBitmap* bkMaskBmp = BkMaskBmp(); |
|
347 delete bkMaskBmp; |
|
348 SetBackgroundMaskBmp( NULL ); |
|
349 } |
|
350 |
|
351 TResourceReader resReader; |
|
352 CCoeEnv::Static()->CreateResourceReaderLC( resReader, iResourceId ); |
|
353 |
|
354 TPtrC bmpFileName = resReader.ReadTPtrC(); |
|
355 TInt32 imgMajorSkinId = resReader.ReadInt32(); |
|
356 |
|
357 TAknsItemID id; |
|
358 TInt skinitemid; |
|
359 |
|
360 MAknsSkinInstance* skininstance = AknsUtils::SkinInstance(); |
|
361 const TInt16 bmpId = resReader.ReadInt16(); |
|
362 const TInt16 bmpMskId = resReader.ReadInt16(); |
|
363 skinitemid = resReader.ReadInt16(); |
|
364 id.Set(TInt(imgMajorSkinId), skinitemid); |
|
365 |
|
366 if (bmpId != KInvalidImg) |
|
367 { |
|
368 CFbsBitmap* backgroundImg = NULL; |
|
369 CFbsBitmap* backgroundMaskImg = NULL; |
|
370 if (bmpMskId != KInvalidImg) |
|
371 { |
|
372 AknsUtils::CreateIconL(skininstance, |
|
373 id, |
|
374 backgroundImg, |
|
375 backgroundMaskImg, |
|
376 bmpFileName, |
|
377 bmpId, |
|
378 bmpMskId); |
|
379 } |
|
380 else |
|
381 { |
|
382 AknsUtils::CreateIconL(skininstance, |
|
383 id, |
|
384 backgroundImg, |
|
385 bmpFileName, |
|
386 bmpId); |
|
387 } |
|
388 |
|
389 SetBackgroundBmp( backgroundImg ); |
|
390 SetBackgroundMaskBmp( backgroundMaskImg ); |
|
391 } |
|
392 CleanupStack::PopAndDestroy( 1 ); |
|
393 } |
|