|
1 /* |
|
2 * Copyright (c) 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: Container for touch controls. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <layoutmetadata.cdl.h> |
|
20 #include <barsread.h> |
|
21 |
|
22 #include "BMTouchPane.h" |
|
23 #include "BMPanic.h" |
|
24 #include "BMLayout4.h" |
|
25 #include "BMLayout6.h" |
|
26 #include "BMTouchPaneButton.h" |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // C++ default constructor |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CBubbleTouchPane::CBubbleTouchPane() |
|
38 { |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // ConstructL |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CBubbleTouchPane::ConstructL() |
|
46 { |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // NewL |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CBubbleTouchPane* CBubbleTouchPane::NewL() |
|
54 { |
|
55 CBubbleTouchPane* self = new(ELeave) CBubbleTouchPane; |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Destructor |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CBubbleTouchPane::~CBubbleTouchPane() |
|
67 { |
|
68 iButtons.ResetAndDestroy(); |
|
69 iButtons.Close(); |
|
70 |
|
71 iButtonsToBeDeleted.ResetAndDestroy(); |
|
72 iButtonsToBeDeleted.Close(); |
|
73 delete iIdleProcessor; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // SizeChanged |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CBubbleTouchPane::SizeChanged( ) |
|
81 { |
|
82 if ( !iButtons.Count() ) |
|
83 { |
|
84 return; |
|
85 } |
|
86 |
|
87 // button index |
|
88 // 1 2 OR 1 2 3 4 |
|
89 // 3 4 |
|
90 TInt buttonInd = 0; |
|
91 |
|
92 TInt rows = 0; |
|
93 TInt columns = 0; |
|
94 BubbleLayout6::button_grp_row_column_count(0, rows, columns); |
|
95 if ( Layout_Meta_Data::IsLandscapeOrientation() && |
|
96 !Layout_Meta_Data::IsMirrored() ) |
|
97 { |
|
98 // Set places of the touch buttons so that they correspond places in portrait. |
|
99 // However, don't change order if mirrored display is used. |
|
100 for ( TInt col = 0; col < columns; col++ ) |
|
101 { |
|
102 for ( TInt row = rows - 1; row >= 0; row-- ) |
|
103 { |
|
104 SetButtonLayout( buttonInd, col, row ); |
|
105 buttonInd++; |
|
106 } |
|
107 } |
|
108 } |
|
109 else |
|
110 { |
|
111 for ( TInt row = 0; row < rows; row++ ) |
|
112 { |
|
113 for ( TInt col = 0; col < columns; col++ ) |
|
114 { |
|
115 SetButtonLayout( buttonInd, col, row ); |
|
116 buttonInd++; |
|
117 } |
|
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // SetButtonLayout |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CBubbleTouchPane::SetButtonLayout( TInt aButtonIndex, TInt aColumn, TInt aRow ) |
|
127 { |
|
128 TAknLayoutRect buttonPane; |
|
129 buttonPane.LayoutRect( |
|
130 Rect(), |
|
131 BubbleLayout6::cell_call6_button_pane(0, aColumn, aRow) ); |
|
132 |
|
133 if ( aButtonIndex < iButtons.Count() && iButtons[aButtonIndex] ) |
|
134 { |
|
135 // Button control layout according to background |
|
136 AknLayoutUtils::LayoutControl( |
|
137 iButtons[aButtonIndex], |
|
138 buttonPane.Rect(), |
|
139 BubbleLayout6::button_call6_background_graphics(0)); |
|
140 |
|
141 TAknLayoutText text; |
|
142 text.LayoutText( buttonPane.Rect(), |
|
143 BubbleLayout6::button_call6_function_text(0)); |
|
144 |
|
145 TAknLayoutRect icon; |
|
146 icon.LayoutRect( buttonPane.Rect(), |
|
147 BubbleLayout6::button_call6_function_graphics(0)); |
|
148 |
|
149 iButtons[aButtonIndex]->SetIconSize( icon.Rect().Size() ); |
|
150 iButtons[aButtonIndex]->SetLayout( text, icon.Rect() ); |
|
151 } |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CountComponentControls |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 TInt CBubbleTouchPane::CountComponentControls( ) const |
|
159 { |
|
160 return iButtons.Count(); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // ComponentControl |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 CCoeControl* CBubbleTouchPane::ComponentControl( TInt aIndex ) const |
|
168 { |
|
169 return iButtons[ aIndex ]; |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // HandlePointerEventL |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CBubbleTouchPane::HandlePointerEventL |
|
177 ( const TPointerEvent& aPointerEvent ) |
|
178 { |
|
179 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // HandleControlEventL |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CBubbleTouchPane::HandleControlEventL( |
|
187 CCoeControl* aControl, |
|
188 TCoeEvent aEventType) |
|
189 { |
|
190 if ( aEventType != EEventStateChanged ) |
|
191 { |
|
192 return; |
|
193 } |
|
194 |
|
195 CBubbleTouchPaneButton* tappedButton = NULL; |
|
196 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
197 { |
|
198 if ( iButtons[i] == aControl ) |
|
199 { |
|
200 tappedButton = iButtons[i]; |
|
201 break; |
|
202 } |
|
203 } |
|
204 if ( tappedButton ) |
|
205 { |
|
206 iDeleteButtonsAsync = ETrue; |
|
207 CEikAppUi* appUi = CEikonEnv::Static()->EikAppUi(); |
|
208 appUi->HandleCommandL( tappedButton->CommandId( ETrue ) ); |
|
209 iDeleteButtonsAsync = EFalse; |
|
210 } |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // HandleResourceChange |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CBubbleTouchPane::HandleResourceChange( TInt aType ) |
|
218 { |
|
219 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
220 { |
|
221 iButtons[i]->HandleResourceChange( aType ); |
|
222 } |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // SetUpdating |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 void CBubbleTouchPane::SetUpdating( TBool aUpdating ) |
|
230 { |
|
231 iUpdating = aUpdating; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // IdleCallback |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 TInt CBubbleTouchPane::IdleCallback( TAny* aThis ) |
|
239 { |
|
240 CBubbleTouchPane* self = |
|
241 static_cast<CBubbleTouchPane*>( aThis ); |
|
242 self->DoDeleteButtonsInIdle(); |
|
243 return KErrNone; |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // DoDeleteButtonsInIdle |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CBubbleTouchPane::DoDeleteButtonsInIdle() |
|
251 { |
|
252 iButtonsToBeDeleted.ResetAndDestroy(); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // SetButtonSet |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 TInt CBubbleTouchPane::SetButtonSet( TInt aResourceId ) |
|
260 { |
|
261 TRAPD( err, SetButtonSetL( aResourceId ) ); |
|
262 |
|
263 return err; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // SetButtonSetL |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 void CBubbleTouchPane::SetButtonSetL( TInt aResourceId ) |
|
271 { |
|
272 // reset touch pane |
|
273 if ( iDeleteButtonsAsync ) |
|
274 { |
|
275 // swap buttons to another array |
|
276 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
277 { |
|
278 iButtonsToBeDeleted.AppendL( iButtons[i] ); |
|
279 } |
|
280 |
|
281 iButtons.Reset(); |
|
282 } |
|
283 else |
|
284 { |
|
285 iButtons.ResetAndDestroy(); |
|
286 } |
|
287 |
|
288 if ( iButtonsToBeDeleted.Count() ) |
|
289 { |
|
290 if ( !iIdleProcessor ) |
|
291 { |
|
292 iIdleProcessor = CIdle::NewL( CActive::EPriorityIdle ); |
|
293 } |
|
294 |
|
295 if ( !iIdleProcessor->IsActive() ) |
|
296 { |
|
297 TCallBack idleCallback( IdleCallback, this ); |
|
298 iIdleProcessor->Start( idleCallback ); |
|
299 } |
|
300 } |
|
301 |
|
302 iCurrentButtonSetId = 0; |
|
303 |
|
304 // load new buttons |
|
305 if ( aResourceId ) |
|
306 { |
|
307 TResourceReader reader; |
|
308 iCoeEnv->CreateResourceReaderLC( reader, aResourceId ); |
|
309 LoadButtonsFromResourceL( reader ); |
|
310 CleanupStack::PopAndDestroy(); |
|
311 iCurrentButtonSetId = aResourceId; |
|
312 } |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------------------------- |
|
316 // LoadButtonsFromResourceL |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CBubbleTouchPane::LoadButtonsFromResourceL( TResourceReader& aReader ) |
|
320 { |
|
321 __ASSERT_DEBUG( (iButtons.Count() == 0), Panic( EBMPanicTouchPane ) ); |
|
322 |
|
323 TInt flags = aReader.ReadInt16(); |
|
324 |
|
325 TInt buttonCount = aReader.ReadInt16(); |
|
326 for ( TInt i=0; i < buttonCount; i++ ) |
|
327 { |
|
328 TInt buttonId( aReader.ReadInt32() ); |
|
329 TResourceReader buttonReader; |
|
330 iCoeEnv->CreateResourceReaderLC( buttonReader, buttonId ); |
|
331 |
|
332 CBubbleTouchPaneButton* button = CBubbleTouchPaneButton::NewL( |
|
333 iIconProvider, flags ); |
|
334 CleanupStack::PushL( button ); |
|
335 button->ConstructFromResouceL( buttonReader ); |
|
336 |
|
337 CleanupStack::Pop( button ); |
|
338 CleanupStack::PopAndDestroy(); // buttonReader |
|
339 |
|
340 iButtons.Append( button ); |
|
341 } |
|
342 |
|
343 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
344 { |
|
345 CBubbleTouchPaneButton* button = iButtons[i]; |
|
346 button->SetContainerWindowL( *this ); |
|
347 button->SetObserver( this ); |
|
348 button->ActivateL(); |
|
349 } |
|
350 |
|
351 SizeChanged(); |
|
352 if ( IsVisible() ) |
|
353 { |
|
354 if ( iUpdating ) |
|
355 { |
|
356 DrawDeferred(); |
|
357 } |
|
358 else |
|
359 { |
|
360 DrawNow(); |
|
361 } |
|
362 } |
|
363 } |
|
364 |
|
365 // --------------------------------------------------------------------------- |
|
366 // SetButtonState |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 void CBubbleTouchPane::SetButtonState( TInt aCommand ) |
|
370 { |
|
371 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
372 { |
|
373 TBool drawNow = ( IsVisible() && !iUpdating ) ? ETrue : EFalse; |
|
374 iButtons[i]->SetState( aCommand, drawNow ); |
|
375 } |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // SetButtonDimmed |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 void CBubbleTouchPane::SetButtonDimmed( TInt aCommand, TBool aDimmed ) |
|
383 { |
|
384 TInt buttonCount = iButtons.Count(); |
|
385 |
|
386 for ( TInt i=0; i < buttonCount; i++ ) |
|
387 { |
|
388 if ( iButtons[i]->CommandId() == aCommand ) |
|
389 { |
|
390 iButtons[i]->SetDimmed( aDimmed ); |
|
391 } |
|
392 } |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // NumberOfButtonsInPane |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 TInt CBubbleTouchPane::NumberOfButtonsInPane() const |
|
400 { |
|
401 return CountComponentControls(); |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // ButtonCommandId |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 TInt CBubbleTouchPane::ButtonCommandId( TInt aButtonIndex ) const |
|
409 { |
|
410 return iButtons[ aButtonIndex ]->CommandId(); |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // ButtonHasState |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 TBool CBubbleTouchPane::ButtonHasState( TInt aButtonIndex, TInt aCommand ) const |
|
418 { |
|
419 return iButtons[ aButtonIndex ]->HasState( aCommand ); |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // ReplaceButton |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 TInt CBubbleTouchPane::ReplaceButton( TInt aButtonIndex, TInt aResourceId ) |
|
427 { |
|
428 TInt err; |
|
429 |
|
430 if ( 0 <= aButtonIndex && aButtonIndex < iButtons.Count() && |
|
431 aResourceId ) |
|
432 { |
|
433 TRAP( err, ReplaceButtonL( aButtonIndex, aResourceId ) ); |
|
434 } |
|
435 else |
|
436 { |
|
437 err = KErrGeneral; |
|
438 } |
|
439 |
|
440 return err; |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // ReplaceButton |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 void CBubbleTouchPane::ReplaceButtonL( TInt aButtonIndex, TInt aResourceId ) |
|
448 { |
|
449 TResourceReader reader; |
|
450 iCoeEnv->CreateResourceReaderLC( reader, aResourceId ); |
|
451 |
|
452 CBubbleTouchPaneButton* button = CBubbleTouchPaneButton::NewL( |
|
453 iIconProvider); |
|
454 CleanupStack::PushL( button ); |
|
455 button->ConstructFromResouceL( reader ); |
|
456 |
|
457 CleanupStack::Pop( button ); |
|
458 CleanupStack::PopAndDestroy(); // reader |
|
459 |
|
460 button->SetContainerWindowL( *this ); |
|
461 button->SetObserver( this ); |
|
462 button->ActivateL(); |
|
463 |
|
464 if ( !iDeleteButtonsAsync ) |
|
465 { |
|
466 delete iButtons[ aButtonIndex ]; |
|
467 iButtons[ aButtonIndex ] = NULL; |
|
468 } |
|
469 else |
|
470 { |
|
471 iButtonsToBeDeleted.Append( iButtons[ aButtonIndex ] ); |
|
472 iButtons[ aButtonIndex ] = NULL; |
|
473 if ( !iIdleProcessor ) |
|
474 { |
|
475 iIdleProcessor = CIdle::NewL( CActive::EPriorityIdle ); |
|
476 } |
|
477 |
|
478 if ( !iIdleProcessor->IsActive() ) |
|
479 { |
|
480 TCallBack idleCallback( IdleCallback, this ); |
|
481 iIdleProcessor->Start( idleCallback ); |
|
482 } |
|
483 } |
|
484 |
|
485 iButtons[ aButtonIndex ] = button; |
|
486 |
|
487 SizeChanged(); |
|
488 if ( IsVisible() ) |
|
489 { |
|
490 DrawDeferred(); |
|
491 } |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // SetIconProvider |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 void CBubbleTouchPane::SetIconProvider( |
|
499 MBubbleTouchPaneIconProvider* aIconProvider ) |
|
500 { |
|
501 iIconProvider = aIconProvider; |
|
502 } |