|
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 return; |
|
84 |
|
85 // button index |
|
86 // 1 2 OR 1 2 3 4 |
|
87 // 3 4 |
|
88 TInt i = 0; |
|
89 |
|
90 TInt rows = 0; |
|
91 TInt columns = 0; |
|
92 BubbleLayout6::button_grp_row_column_count(0, rows, columns); |
|
93 for ( TInt row = 0; row < rows; row++ ) |
|
94 { |
|
95 for ( TInt col = 0; col < columns; col++ ) |
|
96 { |
|
97 TAknLayoutRect buttonPane; |
|
98 buttonPane.LayoutRect( |
|
99 Rect(), |
|
100 BubbleLayout6::cell_call6_button_pane(0, col, row) ); |
|
101 |
|
102 if ( i < iButtons.Count() && iButtons[i] ) |
|
103 { |
|
104 // Button control layout according to background |
|
105 AknLayoutUtils::LayoutControl( |
|
106 iButtons[i], |
|
107 buttonPane.Rect(), |
|
108 BubbleLayout6::button_call6_background_graphics(0)); |
|
109 |
|
110 TAknLayoutText text; |
|
111 text.LayoutText( buttonPane.Rect(), |
|
112 BubbleLayout6::button_call6_function_text(0)); |
|
113 |
|
114 TAknLayoutRect icon; |
|
115 icon.LayoutRect( buttonPane.Rect(), |
|
116 BubbleLayout6::button_call6_function_graphics(0)); |
|
117 |
|
118 iButtons[i]->SetIconSize( icon.Rect().Size() ); |
|
119 iButtons[i++]->SetLayout( text, icon.Rect() ); |
|
120 } |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CountComponentControls |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 TInt CBubbleTouchPane::CountComponentControls( ) const |
|
130 { |
|
131 return iButtons.Count(); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // ComponentControl |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 CCoeControl* CBubbleTouchPane::ComponentControl( TInt aIndex ) const |
|
139 { |
|
140 return iButtons[ aIndex ]; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // HandlePointerEventL |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CBubbleTouchPane::HandlePointerEventL |
|
148 ( const TPointerEvent& aPointerEvent ) |
|
149 { |
|
150 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // HandleControlEventL |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CBubbleTouchPane::HandleControlEventL( |
|
158 CCoeControl* aControl, |
|
159 TCoeEvent aEventType) |
|
160 { |
|
161 if ( aEventType != EEventStateChanged ) |
|
162 { |
|
163 return; |
|
164 } |
|
165 |
|
166 CBubbleTouchPaneButton* tappedButton = NULL; |
|
167 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
168 { |
|
169 if ( iButtons[i] == aControl ) |
|
170 { |
|
171 tappedButton = iButtons[i]; |
|
172 break; |
|
173 } |
|
174 } |
|
175 if ( tappedButton ) |
|
176 { |
|
177 iDeleteButtonsAsync = ETrue; |
|
178 CEikAppUi* appUi = CEikonEnv::Static()->EikAppUi(); |
|
179 appUi->HandleCommandL( tappedButton->CommandId( ETrue ) ); |
|
180 iDeleteButtonsAsync = EFalse; |
|
181 } |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // HandleResourceChange |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 void CBubbleTouchPane::HandleResourceChange( TInt aType ) |
|
189 { |
|
190 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
191 { |
|
192 iButtons[i]->HandleResourceChange( aType ); |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // SetUpdating |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CBubbleTouchPane::SetUpdating( TBool aUpdating ) |
|
201 { |
|
202 iUpdating = aUpdating; |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // IdleCallback |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 TInt CBubbleTouchPane::IdleCallback( TAny* aThis ) |
|
210 { |
|
211 CBubbleTouchPane* self = |
|
212 static_cast<CBubbleTouchPane*>( aThis ); |
|
213 self->DoDeleteButtonsInIdle(); |
|
214 return KErrNone; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // DoDeleteButtonsInIdle |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CBubbleTouchPane::DoDeleteButtonsInIdle() |
|
222 { |
|
223 iButtonsToBeDeleted.ResetAndDestroy(); |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // SetButtonSet |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CBubbleTouchPane::SetButtonSet( TInt aResourceId ) |
|
231 { |
|
232 TRAPD( err, SetButtonSetL( aResourceId ) ); |
|
233 |
|
234 return err; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // SetButtonSetL |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void CBubbleTouchPane::SetButtonSetL( TInt aResourceId ) |
|
242 { |
|
243 // reset touch pane |
|
244 if ( iDeleteButtonsAsync ) |
|
245 { |
|
246 // swap buttons to another array |
|
247 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
248 { |
|
249 iButtonsToBeDeleted.AppendL( iButtons[i] ); |
|
250 } |
|
251 |
|
252 iButtons.Reset(); |
|
253 } |
|
254 else |
|
255 { |
|
256 iButtons.ResetAndDestroy(); |
|
257 } |
|
258 |
|
259 if ( iButtonsToBeDeleted.Count() ) |
|
260 { |
|
261 if ( !iIdleProcessor ) |
|
262 { |
|
263 iIdleProcessor = CIdle::NewL( CActive::EPriorityIdle ); |
|
264 } |
|
265 |
|
266 if ( !iIdleProcessor->IsActive() ) |
|
267 { |
|
268 TCallBack idleCallback( IdleCallback, this ); |
|
269 iIdleProcessor->Start( idleCallback ); |
|
270 } |
|
271 } |
|
272 |
|
273 iCurrentButtonSetId = 0; |
|
274 |
|
275 // load new buttons |
|
276 if ( aResourceId ) |
|
277 { |
|
278 TResourceReader reader; |
|
279 iCoeEnv->CreateResourceReaderLC( reader, aResourceId ); |
|
280 LoadButtonsFromResourceL( reader ); |
|
281 CleanupStack::PopAndDestroy(); |
|
282 iCurrentButtonSetId = aResourceId; |
|
283 } |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // LoadButtonsFromResourceL |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 void CBubbleTouchPane::LoadButtonsFromResourceL( TResourceReader& aReader ) |
|
291 { |
|
292 __ASSERT_DEBUG( (iButtons.Count() == 0), Panic( EBMPanicTouchPane ) ); |
|
293 |
|
294 TInt flags = aReader.ReadInt16(); |
|
295 |
|
296 TInt buttonCount = aReader.ReadInt16(); |
|
297 for ( TInt i=0; i < buttonCount; i++ ) |
|
298 { |
|
299 TInt buttonId( aReader.ReadInt32() ); |
|
300 TResourceReader buttonReader; |
|
301 iCoeEnv->CreateResourceReaderLC( buttonReader, buttonId ); |
|
302 |
|
303 CBubbleTouchPaneButton* button = CBubbleTouchPaneButton::NewL( |
|
304 iIconProvider, flags ); |
|
305 CleanupStack::PushL( button ); |
|
306 button->ConstructFromResouceL( buttonReader ); |
|
307 |
|
308 CleanupStack::Pop( button ); |
|
309 CleanupStack::PopAndDestroy(); // buttonReader |
|
310 |
|
311 iButtons.Append( button ); |
|
312 } |
|
313 |
|
314 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
315 { |
|
316 CBubbleTouchPaneButton* button = iButtons[i]; |
|
317 button->SetContainerWindowL( *this ); |
|
318 button->SetObserver( this ); |
|
319 button->ActivateL(); |
|
320 } |
|
321 |
|
322 SizeChanged(); |
|
323 if ( IsVisible() ) |
|
324 { |
|
325 if ( iUpdating ) |
|
326 { |
|
327 DrawDeferred(); |
|
328 } |
|
329 else |
|
330 { |
|
331 DrawNow(); |
|
332 } |
|
333 } |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // SetButtonState |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CBubbleTouchPane::SetButtonState( TInt aCommand ) |
|
341 { |
|
342 for ( TInt i=0; i < iButtons.Count(); i++ ) |
|
343 { |
|
344 TBool drawNow = ( IsVisible() && !iUpdating ) ? ETrue : EFalse; |
|
345 iButtons[i]->SetState( aCommand, drawNow ); |
|
346 } |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // SetButtonDimmed |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 void CBubbleTouchPane::SetButtonDimmed( TInt aCommand, TBool aDimmed ) |
|
354 { |
|
355 TInt buttonCount = iButtons.Count(); |
|
356 |
|
357 for ( TInt i=0; i < buttonCount; i++ ) |
|
358 { |
|
359 if ( iButtons[i]->CommandId() == aCommand ) |
|
360 { |
|
361 iButtons[i]->SetDimmed( aDimmed ); |
|
362 } |
|
363 } |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // NumberOfButtonsInPane |
|
368 // --------------------------------------------------------------------------- |
|
369 // |
|
370 TInt CBubbleTouchPane::NumberOfButtonsInPane() const |
|
371 { |
|
372 return CountComponentControls(); |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // ButtonCommandId |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 TInt CBubbleTouchPane::ButtonCommandId( TInt aButtonIndex ) const |
|
380 { |
|
381 return iButtons[ aButtonIndex ]->CommandId(); |
|
382 } |
|
383 |
|
384 // --------------------------------------------------------------------------- |
|
385 // ButtonHasState |
|
386 // --------------------------------------------------------------------------- |
|
387 // |
|
388 TBool CBubbleTouchPane::ButtonHasState( TInt aButtonIndex, TInt aCommand ) const |
|
389 { |
|
390 return iButtons[ aButtonIndex ]->HasState( aCommand ); |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------------------------- |
|
394 // ReplaceButton |
|
395 // --------------------------------------------------------------------------- |
|
396 // |
|
397 TInt CBubbleTouchPane::ReplaceButton( TInt aButtonIndex, TInt aResourceId ) |
|
398 { |
|
399 TInt err; |
|
400 |
|
401 if ( 0 <= aButtonIndex && aButtonIndex < iButtons.Count() && |
|
402 aResourceId ) |
|
403 { |
|
404 TRAP( err, ReplaceButtonL( aButtonIndex, aResourceId ) ); |
|
405 } |
|
406 else |
|
407 { |
|
408 err = KErrGeneral; |
|
409 } |
|
410 |
|
411 return err; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // ReplaceButton |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 void CBubbleTouchPane::ReplaceButtonL( TInt aButtonIndex, TInt aResourceId ) |
|
419 { |
|
420 TResourceReader reader; |
|
421 iCoeEnv->CreateResourceReaderLC( reader, aResourceId ); |
|
422 |
|
423 CBubbleTouchPaneButton* button = CBubbleTouchPaneButton::NewL( |
|
424 iIconProvider); |
|
425 CleanupStack::PushL( button ); |
|
426 button->ConstructFromResouceL( reader ); |
|
427 |
|
428 CleanupStack::Pop( button ); |
|
429 CleanupStack::PopAndDestroy(); // reader |
|
430 |
|
431 button->SetContainerWindowL( *this ); |
|
432 button->SetObserver( this ); |
|
433 button->ActivateL(); |
|
434 |
|
435 if ( !iDeleteButtonsAsync ) |
|
436 { |
|
437 delete iButtons[ aButtonIndex ]; |
|
438 iButtons[ aButtonIndex ] = NULL; |
|
439 } |
|
440 else |
|
441 { |
|
442 iButtonsToBeDeleted.Append( iButtons[ aButtonIndex ] ); |
|
443 iButtons[ aButtonIndex ] = NULL; |
|
444 if ( !iIdleProcessor ) |
|
445 { |
|
446 iIdleProcessor = CIdle::NewL( CActive::EPriorityIdle ); |
|
447 } |
|
448 |
|
449 if ( !iIdleProcessor->IsActive() ) |
|
450 { |
|
451 TCallBack idleCallback( IdleCallback, this ); |
|
452 iIdleProcessor->Start( idleCallback ); |
|
453 } |
|
454 } |
|
455 |
|
456 iButtons[ aButtonIndex ] = button; |
|
457 |
|
458 SizeChanged(); |
|
459 if ( IsVisible() ) |
|
460 { |
|
461 DrawDeferred(); |
|
462 } |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------------------------- |
|
466 // SetIconProvider |
|
467 // --------------------------------------------------------------------------- |
|
468 // |
|
469 void CBubbleTouchPane::SetIconProvider( |
|
470 MBubbleTouchPaneIconProvider* aIconProvider ) |
|
471 { |
|
472 iIconProvider = aIconProvider; |
|
473 } |