|
1 /* |
|
2 * Copyright (c) 2006 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: Button class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <aknappui.h> |
|
22 #include <AknIconArray.h> |
|
23 #include <aknsoundsystem.h> // CAknKeySoundSystem |
|
24 #include <AknsConstants.h> |
|
25 #include <aknconsts.h> |
|
26 #include <AknsUtils.h> |
|
27 #include <barsread.h> |
|
28 #include <gulicon.h> |
|
29 #include <coedef.h> |
|
30 #include <eiksvdef.h> |
|
31 #include <AknsDrawUtils.h> |
|
32 #include "mpxbutton.h" |
|
33 #include "mpxplaybackviewlayoutinterface.h" |
|
34 #include "mpxcommonplaybackview.hrh" |
|
35 #include "mpxlog.h" |
|
36 |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CMPXButton::CMPXButton |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CMPXButton::CMPXButton( |
|
45 TMPXPbvButton aButtonId, |
|
46 MMPXButtonCmdObserver* aObserver, |
|
47 MMPXPlaybackViewLayout* aLayout ) |
|
48 : iButtonId( aButtonId ), |
|
49 iCurrentStateIndex( KErrNotFound ), |
|
50 iObserver( aObserver ), |
|
51 iVisible( ETrue ), |
|
52 iLayout( aLayout ) |
|
53 { |
|
54 MPX_FUNC("CMPXButton::CMPXButton()"); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CMPXButton::NewLC |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CMPXButton* CMPXButton::NewLC( |
|
62 TMPXPbvButton aButtonId, |
|
63 MMPXButtonCmdObserver* aObserver, |
|
64 MMPXPlaybackViewLayout* aLayout ) |
|
65 { |
|
66 MPX_FUNC("CMPXButton::NewLC()"); |
|
67 CMPXButton* self = new (ELeave) CMPXButton( |
|
68 aButtonId, |
|
69 aObserver, |
|
70 aLayout ); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CMPXButton::NewL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CMPXButton* CMPXButton::NewL( |
|
81 TMPXPbvButton aButtonId, |
|
82 MMPXButtonCmdObserver* aObserver, |
|
83 MMPXPlaybackViewLayout* aLayout ) |
|
84 { |
|
85 MPX_FUNC("CMPXButton::NewL()"); |
|
86 CMPXButton* self = CMPXButton::NewLC( |
|
87 aButtonId, |
|
88 aObserver, |
|
89 aLayout ); |
|
90 CleanupStack::Pop(self); |
|
91 return self; |
|
92 } |
|
93 |
|
94 // Destructor |
|
95 CMPXButton::~CMPXButton() |
|
96 { |
|
97 MPX_FUNC("CMPXButton::~CMPXButton()"); |
|
98 FreeIcons(); |
|
99 iButtonArray.ResetAndDestroy(); |
|
100 |
|
101 if (iTimer) |
|
102 { |
|
103 iTimer->Cancel(); |
|
104 delete iTimer; |
|
105 } |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CMPXButton::ConstructL |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CMPXButton::ConstructL() |
|
113 { |
|
114 MPX_FUNC("CMPXButton::ConstructL()"); |
|
115 iKeySoundSystem = static_cast<CAknAppUi*>( |
|
116 CEikonEnv::Static()->AppUi())->KeySounds(); |
|
117 |
|
118 iTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
119 } |
|
120 |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CMPXButton::AddStateL |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CMPXButton::AddStateL( |
|
127 TInt aState, |
|
128 TInt aEnterCommand, |
|
129 TInt aExitCommand, |
|
130 TInt aLongEnterCommand, |
|
131 TInt aLongExitCommand ) |
|
132 { |
|
133 MPX_DEBUG1("CMPXButton::AddStateL() entering"); |
|
134 TMPXButtonInfo* info = new (ELeave) TMPXButtonInfo; |
|
135 CleanupStack::PushL( info ); |
|
136 info->iState = aState; |
|
137 info->iEnterCommand = aEnterCommand; |
|
138 info->iExitCommand = aExitCommand; |
|
139 info->iLongEnterCommand = aLongEnterCommand; |
|
140 info->iLongExitCommand = aLongExitCommand; |
|
141 info->iBitmap = LoadIconL( aState ); |
|
142 iButtonArray.AppendL(info); |
|
143 CleanupStack::Pop( info ); |
|
144 MPX_DEBUG1("CMPXButton::AddStateL() exiting"); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CMPXButton::Id |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TMPXPbvButton CMPXButton::Id() const |
|
152 { |
|
153 return iButtonId; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CMPXButton::MakeVisible |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CMPXButton::MakeVisible( |
|
161 TBool aVisible ) |
|
162 { |
|
163 iVisible = aVisible; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CMPXButton::IsVisible |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 TBool CMPXButton::IsVisible() const |
|
171 { |
|
172 return iVisible; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CMPXButton::SetButtonState |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CMPXButton::SetButtonState( |
|
180 TInt aState, |
|
181 TBool aNotifyExit /*=EFalse=*/, |
|
182 TBool aNotifyEnter /*=EFalse*/ ) |
|
183 { |
|
184 MPX_DEBUG4("CMPXButton::SetButtonState(%d, %d, %d): entering", aState, aNotifyExit, aNotifyEnter); |
|
185 |
|
186 TInt index( KErrNotFound ); |
|
187 TMPXButtonInfo* info( NULL ); |
|
188 |
|
189 // Find the new state |
|
190 for (TInt i = 0; i < iButtonArray.Count(); i++) |
|
191 { |
|
192 info = iButtonArray[i]; |
|
193 if ( info->iState == aState ) |
|
194 { |
|
195 index = i; |
|
196 } |
|
197 } |
|
198 |
|
199 if ( KErrNotFound != index && |
|
200 iCurrentStateIndex != index ) |
|
201 { |
|
202 if ( aNotifyExit || aNotifyEnter ) |
|
203 { |
|
204 if ( aNotifyExit ) |
|
205 { |
|
206 // Execute the previous state's exit command |
|
207 info = iButtonArray[iCurrentStateIndex]; |
|
208 if ( iIsLongPress ) |
|
209 { |
|
210 if ( info->iLongExitCommand != KErrNone ) |
|
211 { |
|
212 TRAP_IGNORE( |
|
213 iObserver->HandleButtonCommandL( info->iLongExitCommand )); |
|
214 } |
|
215 } |
|
216 else if ( info->iExitCommand != KErrNone ) |
|
217 { |
|
218 TRAP_IGNORE( |
|
219 iObserver->HandleButtonCommandL( info->iExitCommand )); |
|
220 } |
|
221 // Reset long press flag |
|
222 iIsLongPress = EFalse; |
|
223 } |
|
224 |
|
225 info = iButtonArray[index]; |
|
226 if ( aNotifyEnter ) |
|
227 { |
|
228 // Now execute the new state's enter command |
|
229 if ( info->iEnterCommand != KErrNone ) |
|
230 { |
|
231 TRAP_IGNORE( |
|
232 iObserver->HandleButtonCommandL( info->iEnterCommand )); |
|
233 } |
|
234 } |
|
235 |
|
236 // start the timer |
|
237 iTimer->Cancel(); |
|
238 if ( info->iLongEnterCommand != KErrNone ) |
|
239 { |
|
240 iTimer->Start( KAknKeyboardRepeatInitialDelay, |
|
241 KAknKeyboardRepeatInitialDelay, |
|
242 TCallBack(TimerCallback, this )); |
|
243 } |
|
244 } |
|
245 |
|
246 iCurrentStateIndex = index; |
|
247 iNeedRedraw = ETrue; |
|
248 } |
|
249 MPX_DEBUG1("CMPXButton::SetButtonState(): exiting"); |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CMPXButton::CurrentState |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 TInt CMPXButton::CurrentState() const |
|
257 { |
|
258 MPX_DEBUG1("CMPXButton::CurrentState() entering"); |
|
259 ASSERT( iCurrentStateIndex < iButtonArray.Count() ); |
|
260 TInt state( iButtonArray[iCurrentStateIndex]->iState ); |
|
261 MPX_DEBUG2("CMPXButton::CurrentState() exiting: %d", state); |
|
262 return state; |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CMPXButton::RedrawRect |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CMPXButton::RedrawRect( |
|
270 CBitmapContext& aGc, |
|
271 const TRect& aRect ) const |
|
272 { |
|
273 MPX_DEBUG1("CMPXButton::RedrawRect() entering"); |
|
274 |
|
275 if (iVisible && aRect.Intersects(iRect)) |
|
276 { |
|
277 if (iBackground) |
|
278 { |
|
279 MPX_DEBUG1("CMPXButton::RedrawRect() redrawing background"); |
|
280 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
281 AknsDrawUtils::DrawBackground( |
|
282 skin, |
|
283 iBackground, |
|
284 NULL, |
|
285 aGc, |
|
286 iRect.iTl, |
|
287 iRect, |
|
288 KAknsDrawParamDefault ); |
|
289 } |
|
290 |
|
291 MPX_DEBUG2("CMPXButton::RedrawRect(): iCurrentStateIndex = %d", iCurrentStateIndex); |
|
292 ASSERT( iCurrentStateIndex < iButtonArray.Count() ); |
|
293 TMPXButtonInfo* info( iButtonArray[iCurrentStateIndex] ); |
|
294 CGulIcon* icon( info->iBitmap ); |
|
295 |
|
296 if ( icon ) |
|
297 { |
|
298 ASSERT( icon->Bitmap() && icon->Mask() ); |
|
299 MPX_DEBUG1("CMPXButton::RedrawRect() redrawing icon"); |
|
300 aGc.BitBltMasked( |
|
301 iRect.iTl, // aPoint |
|
302 icon->Bitmap(), // aBitmap |
|
303 TRect(TPoint(), iRect.Size()), // aSourceRect |
|
304 icon->Mask(), |
|
305 EFalse); // aInvertMask |
|
306 } |
|
307 } |
|
308 MPX_DEBUG1("CMPXButton::RedrawRect() exiting"); |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CMPXButton::ReloadIconsL |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 void CMPXButton::ReloadIconsL( |
|
316 const TRect& aParentRect ) |
|
317 { |
|
318 MPX_DEBUG1("CMPXButton::ReloadIconsL() entering"); |
|
319 iParentRect = aParentRect; |
|
320 |
|
321 FreeIcons(); |
|
322 |
|
323 iRect = iLayout->ButtonLayout( aParentRect ); |
|
324 for (TInt i = 0; i < iButtonArray.Count(); i++) |
|
325 { |
|
326 TMPXButtonInfo* info( iButtonArray[i] ); |
|
327 info->iBitmap = LoadIconL( info->iState ); |
|
328 AknIconUtils::SetSize( |
|
329 info->iBitmap->Bitmap(), |
|
330 iRect.Size() ); |
|
331 } |
|
332 MPX_DEBUG1("CMPXButton::ReloadIconsL() exiting"); |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CMPXButton::SetBackground |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 void CMPXButton::SetBackground( |
|
340 MAknsControlContext* aBackground) |
|
341 { |
|
342 ASSERT( aBackground ); |
|
343 iBackground = aBackground; |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CMPXButton::NeedRedraw |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 TBool CMPXButton::NeedRedraw() const |
|
351 { |
|
352 return iNeedRedraw; |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CMPXButton::ClearRedrawFlag |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CMPXButton::ClearRedrawFlag() |
|
360 { |
|
361 iNeedRedraw = EFalse; |
|
362 } |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // CMPXButton::LoadIconL |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 CGulIcon* CMPXButton::LoadIconL( |
|
369 TInt aState ) |
|
370 { |
|
371 MPX_DEBUG1("CMPXButton::LoadIconL() entering"); |
|
372 CFbsBitmap* bitmap = NULL; |
|
373 CFbsBitmap* mask = NULL; |
|
374 |
|
375 iLayout->GetButtonBitmapsL( |
|
376 iButtonId, |
|
377 aState, |
|
378 bitmap, |
|
379 mask); |
|
380 CleanupStack::PushL(bitmap); |
|
381 CleanupStack::PushL(mask); |
|
382 |
|
383 CGulIcon* res = CGulIcon::NewL(bitmap, mask); |
|
384 CleanupStack::Pop(2); // bitmap, mask |
|
385 |
|
386 MPX_DEBUG1("CMPXButton::LoadIconL() exiting"); |
|
387 return res; |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CMPXButton::FreeIcons |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 void CMPXButton::FreeIcons() |
|
395 { |
|
396 MPX_DEBUG1("CMPXButton::FreeIcons() entering"); |
|
397 for ( TInt i = 0; i < iButtonArray.Count(); i++ ) |
|
398 { |
|
399 TMPXButtonInfo* info( iButtonArray[i] ); |
|
400 delete info->iBitmap; |
|
401 info->iBitmap = NULL; |
|
402 } |
|
403 MPX_DEBUG1("CMPXButton::FreeIcons() exiting"); |
|
404 } |
|
405 |
|
406 |
|
407 // ----------------------------------------------------------------------------- |
|
408 // CMPXButton::HandleKeyRepeat |
|
409 // ----------------------------------------------------------------------------- |
|
410 // |
|
411 void CMPXButton::HandleLongPress() |
|
412 { |
|
413 MPX_DEBUG1("CMPXButton::HandleLongPress() entering"); |
|
414 |
|
415 iIsLongPress = ETrue; |
|
416 |
|
417 TMPXButtonInfo* info( iButtonArray[iCurrentStateIndex] ); |
|
418 if ( info->iLongEnterCommand != KErrNone ) |
|
419 { |
|
420 if( !(info->iLongEnterCommand == EMPXPbvCmdIncreaseVolume || |
|
421 info->iLongEnterCommand == EMPXPbvCmdDecreaseVolume )) |
|
422 { |
|
423 iTimer->Cancel(); |
|
424 } |
|
425 |
|
426 TRAP_IGNORE(iObserver->HandleButtonCommandL( info->iLongEnterCommand )); |
|
427 } |
|
428 |
|
429 MPX_DEBUG1("CMPXButton::HandleLongPress() exiting"); |
|
430 } |
|
431 |
|
432 // ----------------------------------------------------------------------------- |
|
433 // CMPXButton::TimerCallback |
|
434 // ----------------------------------------------------------------------------- |
|
435 // |
|
436 TInt CMPXButton::TimerCallback( |
|
437 TAny* aPtr ) |
|
438 { |
|
439 MPX_DEBUG1("CMPXButton::TimerCallback() entering"); |
|
440 static_cast<CMPXButton*>(aPtr)->HandleLongPress(); |
|
441 MPX_DEBUG1("CMPXButton::TimerCallback() exiting"); |
|
442 return KErrNone; |
|
443 } |
|
444 |
|
445 // End of File |