|
1 /* |
|
2 * Copyright (c) 2009, 2010 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: Shows number keypad and generates keypress event when |
|
15 * buttons are pressed. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <gulicon.h> |
|
22 #include <aknutils.h> |
|
23 #include <aknbutton.h> |
|
24 #include <akncontrol.h> |
|
25 #include <aknsutils.h> |
|
26 #include <aknsskininstance.h> |
|
27 #include <aknsdrawutils.h> |
|
28 #include <data_caging_path_literals.hrh> // for KDC_APP_RESOURCE_DIR |
|
29 #include <touchfeedback.h> |
|
30 #include <aknlayoutscalable_avkon.cdl.h> |
|
31 #include <aknlayoutscalable_apps.cdl.h> |
|
32 #include <aknsframebackgroundcontrolcontext.h> |
|
33 |
|
34 #include "dialercommon.h" |
|
35 #include "dialertrace.h" |
|
36 #include "cdialerkeypadbutton.h" |
|
37 |
|
38 _LIT( KDialerMifFileName, "dialer.mif" ); |
|
39 static const TInt KIconMarginPercent = 5; |
|
40 static const TInt KCent = 100; |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // C++ default constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CDialerKeyPadButton::CDialerKeyPadButton( const TDesC& aNumberLabel, |
|
47 const TDesC& aPrimaryAlphaLabel, |
|
48 const TDesC& aSecondaryAlphaLabel, |
|
49 TInt aScanCode, |
|
50 TInt aKeyCode, |
|
51 TMifDialer aButtonIconId, |
|
52 TMifDialer aButtonIconMaskId, |
|
53 TInt aFlags ): |
|
54 CAknButton( aFlags ), |
|
55 iScanCode( aScanCode ), |
|
56 iKeyCode( aKeyCode ), |
|
57 iButtonIconId( aButtonIconId ), |
|
58 iButtonIconMaskId( aButtonIconMaskId ), |
|
59 iNumberLabel( aNumberLabel ), |
|
60 iPrimaryAlphaLabel( aPrimaryAlphaLabel ), |
|
61 iSecondaryAlphaLabel( aSecondaryAlphaLabel ) |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CDialerKeyPadButton::NewLC |
|
67 // Two-phased constructor. |
|
68 // Constructs dialer button. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 |
|
72 CDialerKeyPadButton* CDialerKeyPadButton::NewLC( const TDesC& aNumberLabel, |
|
73 const TDesC& aPrimaryAlphaLabel, |
|
74 const TDesC& aSecondaryAlphaLabel, |
|
75 TInt aScanCode, |
|
76 TInt aKeyCode, |
|
77 TMifDialer aButtonIconId, |
|
78 TMifDialer aButtonIconMaskId, |
|
79 TInt aFlags ) |
|
80 { |
|
81 CDialerKeyPadButton* self = new (ELeave) CDialerKeyPadButton( aNumberLabel, |
|
82 aPrimaryAlphaLabel, |
|
83 aSecondaryAlphaLabel, |
|
84 aScanCode, |
|
85 aKeyCode, |
|
86 aButtonIconId, |
|
87 aButtonIconMaskId, |
|
88 aFlags ); |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL( aFlags ); |
|
91 return self; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CDialerKeyPadButton::ConstructL |
|
96 // Symbian 2nd phase constructor for dialer button. |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CDialerKeyPadButton::ConstructL( TInt aFlags ) |
|
100 { |
|
101 CAknButton::ConstructL( NULL, NULL, NULL, NULL, KNullDesC, KNullDesC, aFlags ); |
|
102 UpdateIconL(); |
|
103 |
|
104 // button text color |
|
105 SetTextColorIds( KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG65 ); |
|
106 SetIconScaleMode( EAspectRatioPreserved ); |
|
107 SetMargins( TMargins8(0,0,0,0) ); |
|
108 AknsUtils::RegisterControlPosition( this ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Destructor |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 CDialerKeyPadButton::~CDialerKeyPadButton() |
|
116 { |
|
117 AknsUtils::DeregisterControlPosition( this ); |
|
118 |
|
119 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
120 if ( feedback ) |
|
121 { |
|
122 feedback->RemoveFeedbackForControl( this ); |
|
123 } |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // Draw dialer button, text and icon. |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CDialerKeyPadButton::Draw( const TRect& aRect ) const |
|
131 { |
|
132 TAknLayoutRect centerLayout; |
|
133 centerLayout.LayoutRect( aRect, |
|
134 AknLayoutScalable_Avkon::toolbar_button_pane_g1().LayoutLine() ); |
|
135 TRect innerRect = centerLayout.Rect(); |
|
136 |
|
137 CWindowGc& gc = SystemGc(); |
|
138 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
139 |
|
140 TAknsItemID frameId = KAknsIIDQsnFrButtonNormal; |
|
141 |
|
142 if ( iButtonPressed ) |
|
143 { |
|
144 frameId = KAknsIIDQsnFrButtonPressed; |
|
145 } |
|
146 else if ( IsDimmed() ) |
|
147 { |
|
148 frameId = KAknsIIDQsnFrButtonInactive; |
|
149 } |
|
150 |
|
151 iBgContext->SetFrame( frameId ); |
|
152 iBgContext->SetCenter( KAknsIIDQsnFrButtonCenterNormal ); |
|
153 iBgContext->SetFrameRects( aRect, innerRect ); |
|
154 |
|
155 TBool bgDrawn = AknsDrawUtils::Background( skin, |
|
156 iBgContext, |
|
157 NULL, |
|
158 gc, |
|
159 aRect, |
|
160 KAknsDrawParamNoClearUnderImage ); |
|
161 |
|
162 __ASSERT_DEBUG( bgDrawn, DialerPanic( EDialerPanicDrawingError ) ); |
|
163 |
|
164 DrawIconAndText( gc ); |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // Respond to changes in the button size |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CDialerKeyPadButton::SizeChanged() |
|
172 { |
|
173 CAknButton::SizeChanged(); |
|
174 AknsUtils::RegisterControlPosition( this ); |
|
175 |
|
176 TRect buttonRect = Rect(); |
|
177 TAknLayoutRect iconLayout; |
|
178 const CGulIcon* icon = GetCurrentIcon(); |
|
179 |
|
180 if ( iOperationMode == EModeEasyDialing ) |
|
181 { |
|
182 // Number layout. |
|
183 iNumberLayout.LayoutText( buttonRect, |
|
184 AknLayoutScalable_Apps::cell_dia3_key_num_pane_t1( iVariety ) ); |
|
185 // Use different number layout if key doens't contain any alphabets or icon. |
|
186 if ( !icon && !iPrimaryAlphaLabel.Length() && !iSecondaryAlphaLabel.Length() ) |
|
187 { |
|
188 iNumberLayout.LayoutText( buttonRect, |
|
189 AknLayoutScalable_Apps::cell_dialer2_keypad_pane_t1(), |
|
190 iNumberLayout.Font() ); |
|
191 } |
|
192 |
|
193 // Alphabet layout is different if two rows of alphabets are given |
|
194 if ( iSecondaryAlphaLabel.Length() ) |
|
195 { |
|
196 iPrimaryAlphaLayout.LayoutText( buttonRect, |
|
197 AknLayoutScalable_Apps::cell_dia3_key_num_pane_t3( iVariety ) ); |
|
198 iSecondaryAlphaLayout.LayoutText( buttonRect, |
|
199 AknLayoutScalable_Apps::cell_dia3_key_num_pane_t4( iVariety ) ); |
|
200 } |
|
201 else |
|
202 { |
|
203 iPrimaryAlphaLayout.LayoutText( buttonRect, |
|
204 AknLayoutScalable_Apps::cell_dia3_key_num_pane_t2( iVariety ) ); |
|
205 } |
|
206 |
|
207 // Icon layout |
|
208 iconLayout.LayoutRect( buttonRect, |
|
209 AknLayoutScalable_Apps::cell_dialer2_keypad_pane_g2( 1 ) ); |
|
210 iIconRect = iconLayout.Rect(); |
|
211 |
|
212 // Icon doesn't fit to location set in the layout if key has any alpha label. |
|
213 // In that case, move the icon to upper-right corner. |
|
214 if ( iPrimaryAlphaLabel.Length() || iSecondaryAlphaLabel.Length() ) |
|
215 { |
|
216 TSize iconSize = iIconRect.Size(); |
|
217 TInt xMargin = buttonRect.Width() * KIconMarginPercent / KCent; |
|
218 TInt yMargin = buttonRect.Height() * KIconMarginPercent / KCent; |
|
219 TPoint iconPos( buttonRect.iBr.iX - iconSize.iWidth - xMargin, |
|
220 buttonRect.iTl.iY + yMargin ); |
|
221 iIconRect.SetRect( iconPos, iconSize ); |
|
222 } |
|
223 } |
|
224 else if ( iOperationMode == EModeDialer ) |
|
225 { |
|
226 // Number layout |
|
227 iNumberLayout.LayoutText( buttonRect, |
|
228 AknLayoutScalable_Apps::cell_dialer2_keypad_pane_t1() ); |
|
229 |
|
230 // Icon layout |
|
231 iconLayout.LayoutRect( buttonRect, |
|
232 AknLayoutScalable_Apps::cell_dialer2_keypad_pane_g2( 1 ) ); |
|
233 iIconRect = iconLayout.Rect(); |
|
234 } |
|
235 else // video mode layout |
|
236 { |
|
237 // Number layout |
|
238 iNumberLayout.LayoutText( buttonRect, |
|
239 AknLayoutScalable_Apps::cell_video_dialer_keypad_pane_t1() ); |
|
240 |
|
241 // Icon layout |
|
242 iconLayout.LayoutRect( buttonRect, |
|
243 AknLayoutScalable_Apps::cell_video_dialer_keypad_pane_g2( 2 ) ); |
|
244 iIconRect = iconLayout.Rect(); |
|
245 } |
|
246 |
|
247 SetIconSize( iIconRect.Size() ); |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // Gets the correct text color. |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CDialerKeyPadButton::GetTextColors( TRgb& aPenColor, TRgb& aBrushColor ) const |
|
255 { |
|
256 aBrushColor = iEikonEnv->ControlColor( EColorControlBackground, *this ); |
|
257 |
|
258 if ( iButtonPressed ) |
|
259 { |
|
260 aPenColor = iEikonEnv->ControlColor( EColorButtonTextPressed, *this ); |
|
261 } |
|
262 else |
|
263 { |
|
264 aPenColor = iEikonEnv->ControlColor( EColorButtonText, *this ); |
|
265 } |
|
266 } |
|
267 |
|
268 // -------------------------------------------------------------------------- |
|
269 // Draw text and icon according to the layout. |
|
270 // -------------------------------------------------------------------------- |
|
271 // |
|
272 void CDialerKeyPadButton::DrawIconAndText( CWindowGc& aGc ) const |
|
273 { |
|
274 TRect parentRect( Rect() ); |
|
275 TAknLayoutText buttonText; |
|
276 TAknLayoutRect layoutRect; |
|
277 |
|
278 TRgb penColor; |
|
279 TRgb brushColor; |
|
280 GetTextColors( penColor, brushColor ); |
|
281 |
|
282 // Don't ues logical-to-visual conversion, strings in our keypad resources are already |
|
283 // in visual order. |
|
284 TBool logToVisConv = EFalse; |
|
285 |
|
286 iNumberLayout.DrawText( aGc, iNumberLabel, logToVisConv, penColor ); |
|
287 |
|
288 // Draw also alphabet label(s) in Easy Dialing mode |
|
289 if ( iOperationMode == EModeEasyDialing ) |
|
290 { |
|
291 if ( iPrimaryAlphaLabel.Length() ) |
|
292 { |
|
293 iPrimaryAlphaLayout.DrawText( aGc, iPrimaryAlphaLabel, logToVisConv, penColor ); |
|
294 } |
|
295 if ( iSecondaryAlphaLabel.Length() ) |
|
296 { |
|
297 iSecondaryAlphaLayout.DrawText( aGc, iSecondaryAlphaLabel, logToVisConv, penColor ); |
|
298 } |
|
299 } |
|
300 |
|
301 const CGulIcon* icon = GetCurrentIcon(); |
|
302 if ( icon ) |
|
303 { |
|
304 CFbsBitmap* buttonBmp = icon->Bitmap(); |
|
305 CFbsBitmap* buttonMask = icon->Mask(); |
|
306 |
|
307 if ( buttonBmp && buttonMask ) |
|
308 { |
|
309 aGc.BitBltMasked( iIconRect.iTl, buttonBmp, |
|
310 iIconRect.Size(), buttonMask, ETrue ); |
|
311 } |
|
312 } |
|
313 } |
|
314 |
|
315 // -------------------------------------------------------------------------- |
|
316 // Set layout data for text. |
|
317 // -------------------------------------------------------------------------- |
|
318 void CDialerKeyPadButton::SetVariety( TInt aVariety ) |
|
319 { |
|
320 iVariety = aVariety; |
|
321 } |
|
322 |
|
323 // -------------------------------------------------------------------------- |
|
324 // Set layout data for text. |
|
325 // -------------------------------------------------------------------------- |
|
326 void CDialerKeyPadButton::SetOperationMode( TDialerOperationMode aMode ) |
|
327 { |
|
328 iOperationMode = aMode; |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 void CDialerKeyPadButton::SetNumLabel( const TDesC& aLabel ) |
|
336 { |
|
337 iNumberLabel.Set( aLabel ); |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 void CDialerKeyPadButton::SetPrimaryAlphaLabel( const TDesC& aLabel ) |
|
345 { |
|
346 iPrimaryAlphaLabel.Set( aLabel ); |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 void CDialerKeyPadButton::SetSecondaryAlphaLabel( const TDesC& aLabel ) |
|
354 { |
|
355 iSecondaryAlphaLabel.Set( aLabel ); |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 TInt CDialerKeyPadButton::ScanCode() const |
|
363 { |
|
364 return iScanCode; |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 // --------------------------------------------------------------------------- |
|
370 // |
|
371 TInt CDialerKeyPadButton::KeyCode() const |
|
372 { |
|
373 return iKeyCode; |
|
374 } |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 void CDialerKeyPadButton::MapDialerIconToSkinIcon( |
|
380 TInt aDialerIcon, TAknsItemID& aItemId ) const |
|
381 { |
|
382 switch ( aDialerIcon ) |
|
383 { |
|
384 case EMbmDialerQgn_indi_dialer_voicemail: |
|
385 aItemId = KAknsIIDQgnIndiDialerVoicemail; |
|
386 break; |
|
387 default: |
|
388 break; |
|
389 } |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // Update icon when skin is changed |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 void CDialerKeyPadButton::UpdateIconL() |
|
397 { |
|
398 if ( KDialerNoIcon != iButtonIconId ) |
|
399 { |
|
400 TFileName mifPath( KDriveZ ); |
|
401 mifPath.Append( KDC_APP_BITMAP_DIR ); |
|
402 mifPath.Append( KDialerMifFileName ); |
|
403 |
|
404 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
405 CFbsBitmap* bitmap (NULL); |
|
406 CFbsBitmap* mask (NULL); |
|
407 |
|
408 // Get icon id. |
|
409 TAknsItemID skinItemId( KAknsIIDNone ); |
|
410 MapDialerIconToSkinIcon( iButtonIconId, skinItemId ); |
|
411 |
|
412 AknsUtils::CreateColorIconLC( |
|
413 skin, |
|
414 skinItemId, |
|
415 KAknsIIDQsnIconColors, |
|
416 EAknsCIQsnIconColorsCG30, |
|
417 bitmap, |
|
418 mask, |
|
419 mifPath, |
|
420 iButtonIconId, |
|
421 iButtonIconMaskId, |
|
422 KRgbBlack |
|
423 ); |
|
424 |
|
425 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
426 CleanupStack::Pop( 2 ); |
|
427 |
|
428 State()->SetIcon( icon ); // icon ownership transfered |
|
429 } |
|
430 } |
|
431 |
|
432 // --------------------------------------------------------------------------- |
|
433 // |
|
434 // Enable or disable audio but keep vibra feedback |
|
435 // --------------------------------------------------------------------------- |
|
436 // |
|
437 void CDialerKeyPadButton::EnableAudioFeedback( const TBool aEnable ) |
|
438 { |
|
439 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
440 if ( feedback ) |
|
441 { |
|
442 feedback->EnableFeedbackForControl( this, ETrue, aEnable ); |
|
443 } |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 // --------------------------------------------------------------------------- |
|
449 // |
|
450 void CDialerKeyPadButton::HandleResourceChange( TInt aType ) |
|
451 { |
|
452 CAknButton::HandleResourceChange( aType ); |
|
453 |
|
454 if ( KAknsMessageSkinChange == aType ) |
|
455 { |
|
456 TRAP_IGNORE( UpdateIconL() ); |
|
457 } |
|
458 } |
|
459 |
|
460 // End of File |