|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation of the class CFMRadioChannelListContainer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32math.h> |
|
21 #include <AknsSkinInstance.h> |
|
22 #include <AknsUtils.h> |
|
23 #include <AknsDrawUtils.h> |
|
24 #include <AknsBasicBackgroundControlContext.h> |
|
25 #include <gulutil.h> |
|
26 #include <w32std.h> |
|
27 #include <fmradio.rsg> |
|
28 #if defined __SERIES60_HELP || defined FF_S60_HELPS_IN_USE |
|
29 #include "radio.hlp.hrh" |
|
30 #endif |
|
31 #include <StringLoader.h> |
|
32 #include <eiklabel.h> |
|
33 #include <AknIconArray.h> |
|
34 #include <gulicon.h> |
|
35 #include <fmradiouids.h> |
|
36 |
|
37 #include "fmradioappui.h" |
|
38 #include "fmradiochannellistcontainer.h" |
|
39 #include "fmradiochannellistview.h" |
|
40 |
|
41 // CONSTANTS |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CFMRadioChannelListContainer::CFMRadioChannelListContainer |
|
48 // Default constructor |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 CFMRadioChannelListContainer::CFMRadioChannelListContainer( |
|
52 CRadioEngine& aRadioEngine, |
|
53 MChannelListHandler& aObserver ) : |
|
54 iRadioEngine( aRadioEngine ), |
|
55 iObserver( aObserver ) |
|
56 |
|
57 { |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------- |
|
61 // CFMRadioChannelListContainer::NewL |
|
62 // Two-phase constructor of CFMRadioChannelListContainer |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 CFMRadioChannelListContainer* CFMRadioChannelListContainer::NewL( const TRect& aRect, |
|
66 CRadioEngine& aRadioEngine, MChannelListHandler& aObserver ) |
|
67 { |
|
68 CFMRadioChannelListContainer* self = new (ELeave) CFMRadioChannelListContainer( aRadioEngine, |
|
69 aObserver ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL( aRect ); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // |
|
77 // ---------------------------------------------------- |
|
78 // CFMRadioChannelListContainer::ConstructL |
|
79 // EPOC two phased constructor |
|
80 // ---------------------------------------------------- |
|
81 // |
|
82 void CFMRadioChannelListContainer::ConstructL( const TRect& aRect ) |
|
83 { |
|
84 CreateWindowL(); |
|
85 CAknIconArray* radioTypeIcons = NULL; |
|
86 |
|
87 radioTypeIcons = new( ELeave ) CAknIconArray( 2 ); |
|
88 CleanupStack::PushL( radioTypeIcons ); |
|
89 |
|
90 radioTypeIcons->AppendFromResourceL( R_FMRADIO_CHANNEL_LIST_ICON_ARRAY ); |
|
91 |
|
92 // Instantiate a listbox for the channel list |
|
93 iChannelList = new ( ELeave ) CAknDoubleNumberStyleListBox(); |
|
94 iControls.Append( iChannelList ); |
|
95 iChannelList->SetContainerWindowL( *this ); |
|
96 iChannelList->SetListBoxObserver( this ); |
|
97 iChannelList->ConstructL( this, CEikListBox::ELoopScrolling | EAknListBoxSelectionList ); // Looped list |
|
98 iChannelList->SetRect( aRect ); // Set boundaries for listbox |
|
99 // Create scrollbars |
|
100 iChannelList->CreateScrollBarFrameL( ETrue ); |
|
101 iChannelList->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
102 HBufC* emptyString = NULL; |
|
103 emptyString = StringLoader::LoadLC( R_QTN_FMRADIO_LIST_NO_STATIONS, iEikonEnv ); |
|
104 |
|
105 iChannelList->View()->SetListEmptyTextL( *emptyString ); |
|
106 CleanupStack::PopAndDestroy( emptyString ); |
|
107 |
|
108 // The following line really takes the ownership -- must be the last item |
|
109 // there, as if leaves and the object is in cleanupstack, problems arise. |
|
110 // (Cleanup stack corruption!) |
|
111 // Set the icon array for this list. List takes ownership of the array. |
|
112 iChannelList->ItemDrawer()->FormattedCellData()->SetIconArrayL( radioTypeIcons ); |
|
113 CleanupStack::Pop( radioTypeIcons ); |
|
114 |
|
115 // Array for channels |
|
116 iChannelItemArray = new( ELeave ) CDesCArrayFlat( KMaxNumberOfChannelListItems ); |
|
117 InitializeChannelListL(); |
|
118 SetRect( aRect ); // Set its rectangle |
|
119 |
|
120 CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() ); |
|
121 iChannelView = static_cast<CFMRadioChannelListView*> ( appUi->View( KFMRadioChannelListViewId ) ); |
|
122 |
|
123 ActivateL(); |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------- |
|
127 // CFMRadioChannelListContainer::~CFMRadioChannelListContainer |
|
128 // Class destructor |
|
129 // ---------------------------------------------------- |
|
130 // |
|
131 CFMRadioChannelListContainer::~CFMRadioChannelListContainer() |
|
132 { |
|
133 iControls.ResetAndDestroy(); |
|
134 delete iChannelItemArray; |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------- |
|
138 // CFMRadioChannelListContainer::InitializeChannelListL |
|
139 // Create the channel list (initially all spots are set as empty) |
|
140 // ---------------------------------------------------- |
|
141 // |
|
142 void CFMRadioChannelListContainer::InitializeChannelListL() |
|
143 { |
|
144 TBuf<KLengthOfChannelItemString> textChannelItem; |
|
145 textChannelItem.SetLength( 0 ); |
|
146 |
|
147 // Pass the array to the listbox model and set the ownership type |
|
148 iChannelList->Model()->SetItemTextArray( (MDesCArray*)iChannelItemArray ); |
|
149 iChannelList->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
150 iChannelList->HandleItemAdditionL(); |
|
151 DrawDeferred(); |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------- |
|
155 // CFMRadioChannelListContainer::UpdateChannelListContentL |
|
156 // Update the content of the channel at aIndex with the |
|
157 // values specified |
|
158 // ---------------------------------------------------- |
|
159 // |
|
160 void CFMRadioChannelListContainer::UpdateChannelListContentL( TInt aIndex, const TDesC& aChannelName, TInt aChannelFrequency ) |
|
161 { |
|
162 TBuf<KLengthOfChannelItemString> textChannelItem; |
|
163 TBuf<KLengthOfChIndexStringChList> textChIndex; |
|
164 TBuf<KLengthOfChannelItemIconIndexString> textChIconIndex; |
|
165 |
|
166 textChIndex.Format( KChIndexFormatChList, aIndex+1 ); // One over index |
|
167 |
|
168 textChIconIndex.Format( KChIconIndexFormatChList, KNowPlayingIconIndexChList ); |
|
169 |
|
170 //Update to display Devnagari numbers for Text Index. |
|
171 AknTextUtils::LanguageSpecificNumberConversion( textChIndex ); |
|
172 // |
|
173 textChannelItem.Append( textChIndex ); |
|
174 textChannelItem.Append( KColumnListSeparator ); |
|
175 textChannelItem.Append( aChannelName ); |
|
176 textChannelItem.Append( KColumnListSeparator ); |
|
177 |
|
178 if ( aChannelFrequency ) |
|
179 { |
|
180 TReal frequency = static_cast<TReal>( aChannelFrequency / static_cast<TReal>( KHzConversionFactor )); |
|
181 // Gets locale decimal separator automatically |
|
182 TRealFormat format(KFrequencyMaxLength, iRadioEngine.DecimalCount() ); |
|
183 TBuf<30> frequencyString; |
|
184 frequencyString.Num( frequency, format ); |
|
185 |
|
186 HBufC* stringHolder = StringLoader::LoadLC( R_QTN_FMRADIO_DOUBLE2_FREQ, frequencyString, iEikonEnv ); |
|
187 //Update for display of Hindi Devnagari Numbers |
|
188 TPtr textItem2 = stringHolder->Des(); |
|
189 AknTextUtils::LanguageSpecificNumberConversion(textItem2); |
|
190 textChannelItem.Append( textItem2 ); |
|
191 CleanupStack::PopAndDestroy( stringHolder ); |
|
192 } |
|
193 |
|
194 // Set 'Now Playing' icon to the channel item |
|
195 textChannelItem.Append( KColumnListSeparator ); |
|
196 |
|
197 if ( iRadioEngine.GetPresetIndex() == aIndex ) |
|
198 { |
|
199 textChannelItem.Append( textChIconIndex ); |
|
200 } |
|
201 |
|
202 if( iChannelItemArray->Count() > 0 ) |
|
203 { |
|
204 iChannelItemArray->Delete( aIndex ); |
|
205 iChannelList->HandleItemRemovalL(); |
|
206 iChannelItemArray->InsertL( aIndex, textChannelItem ); |
|
207 //iChannelItemArray->AppendL( textChannelItem ); |
|
208 |
|
209 iChannelList->HandleItemAdditionL(); // Update list |
|
210 iChannelList->UpdateScrollBarsL(); |
|
211 iChannelList->DrawDeferred(); |
|
212 } |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------- |
|
216 // CFMRadioChannelListContainer::RemoveChannelL |
|
217 // Removes channel from container list |
|
218 // ---------------------------------------------------- |
|
219 // |
|
220 void CFMRadioChannelListContainer::RemoveChannelL( TInt aIndex ) |
|
221 { |
|
222 if ( iChannelItemArray->Count() > 0 ) |
|
223 { |
|
224 TInt presetIndex = iRadioEngine.GetPresetIndex(); |
|
225 |
|
226 iChannelItemArray->Delete( aIndex ); |
|
227 iChannelList->HandleItemRemovalL(); |
|
228 iChannelList->UpdateScrollBarsL(); |
|
229 iChannelList->DrawDeferred(); |
|
230 |
|
231 if ( iChannelItemArray->Count() > 0 ) |
|
232 { |
|
233 ReIndexAllL(); |
|
234 |
|
235 if ( presetIndex > aIndex ) |
|
236 { |
|
237 // update engine settings also |
|
238 iRadioEngine.SetCurrentPresetIndex( presetIndex - 1 ); |
|
239 UpdateItemIconL( presetIndex - 1, KNowPlayingIconIndexChList ); |
|
240 } |
|
241 else if ( presetIndex == aIndex ) |
|
242 { |
|
243 iRadioEngine.TunePresetL( 0 ); |
|
244 UpdateItemIconL( 0, KNowPlayingIconIndexChList ); |
|
245 } |
|
246 else |
|
247 { |
|
248 // NOP |
|
249 } |
|
250 iChannelList->SetCurrentItemIndex( 0 ); |
|
251 } |
|
252 else |
|
253 { |
|
254 // The last item was deleted, tune to current frequency, out of preset mode |
|
255 iRadioEngine.Tune( iRadioEngine.GetTunedFrequency(), CRadioEngine::ERadioTunerMode ); |
|
256 } |
|
257 } |
|
258 } |
|
259 |
|
260 // ---------------------------------------------------- |
|
261 // CFMRadioChannelListContainer::AddChannel |
|
262 // Adds channels to container list |
|
263 // ---------------------------------------------------- |
|
264 // |
|
265 void CFMRadioChannelListContainer::AddChannelL( |
|
266 const TDesC& aChannelName, TInt aChannelFrequency, TBool aNowPlaying ) |
|
267 { |
|
268 TBuf<KLengthOfChannelItemString> textChannelItem; |
|
269 TBuf<KLengthOfChIndexStringChList> textChIndex; |
|
270 TBuf<KLengthOfChannelItemIconIndexString> textChIconIndex; |
|
271 |
|
272 textChIndex.Format( KChIndexFormatChList, iChannelItemArray->Count()+1 ); // One over index |
|
273 |
|
274 if ( !AknLayoutUtils::PenEnabled() ) |
|
275 { |
|
276 textChIconIndex.Format( KChIconIndexFormatChList, KNowPlayingIconIndexChList ) ; |
|
277 } |
|
278 |
|
279 //Update to display Devnagari numbers for Text Index. |
|
280 AknTextUtils::LanguageSpecificNumberConversion(textChIndex); |
|
281 // |
|
282 textChannelItem.Append( textChIndex ); |
|
283 textChannelItem.Append( KColumnListSeparator ); |
|
284 |
|
285 TReal frequency = static_cast<TReal>( aChannelFrequency / static_cast<TReal>( KHzConversionFactor )); |
|
286 // Gets locale decimal separator automatically |
|
287 TRealFormat format(KFrequencyMaxLength, iRadioEngine.DecimalCount() ); |
|
288 TBuf<30> frequencyString; |
|
289 frequencyString.Num(frequency,format); |
|
290 |
|
291 TBool channelHasName = EFalse; |
|
292 TInt resId = 0; |
|
293 // if name exists, place it on the first line |
|
294 if ( aChannelName.Length() > 0 ) |
|
295 { |
|
296 textChannelItem.Append( aChannelName ); |
|
297 textChannelItem.Append( KColumnListSeparator ); |
|
298 channelHasName = ETrue; |
|
299 resId = R_QTN_FMRADIO_DOUBLE2_FREQ; |
|
300 } |
|
301 else // frequency goes to first line |
|
302 { |
|
303 resId = R_QTN_FMRADIO_DOUBLE1_FREQ; |
|
304 } |
|
305 |
|
306 HBufC* stringHolder = StringLoader::LoadLC( resId, frequencyString, iEikonEnv ); |
|
307 //Update for display of Hindi Devnagari Numbers |
|
308 TPtr textItem2 = stringHolder->Des(); |
|
309 AknTextUtils::LanguageSpecificNumberConversion(textItem2); |
|
310 textChannelItem.Append( textItem2 ); |
|
311 CleanupStack::PopAndDestroy( stringHolder ); |
|
312 |
|
313 if ( !channelHasName ) |
|
314 { |
|
315 // add placeholder for second line |
|
316 textChannelItem.Append( KColumnListSeparator ); |
|
317 } |
|
318 |
|
319 // Set 'Now Playing' icon to the channel item |
|
320 textChannelItem.Append( KColumnListSeparator ); |
|
321 |
|
322 if( !AknLayoutUtils::PenEnabled() && aNowPlaying ) |
|
323 { |
|
324 textChannelItem.Append( textChIconIndex ); |
|
325 } |
|
326 |
|
327 iChannelItemArray->AppendL( textChannelItem ); |
|
328 |
|
329 iChannelList->HandleItemAdditionL(); // Update list |
|
330 iChannelList->UpdateScrollBarsL(); |
|
331 iChannelList->DrawDeferred(); |
|
332 |
|
333 } |
|
334 // ---------------------------------------------------- |
|
335 // CFMRadioChannelListContainer::UpdateItemIconL |
|
336 // Adds icon to a list item |
|
337 // ---------------------------------------------------- |
|
338 // |
|
339 void CFMRadioChannelListContainer::UpdateItemIconL( TInt aIndex, TInt aIconIndex ) |
|
340 { |
|
341 HideIconsL(); |
|
342 |
|
343 if ( aIndex >= 0 && aIndex < iChannelItemArray->Count() ) |
|
344 { |
|
345 TBuf<KLengthOfChannelItemIconIndexString> textChIconIndex; |
|
346 textChIconIndex.Format( KChIconIndexFormatChList, aIconIndex ); |
|
347 HBufC* channelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
348 channelItem->Des().Copy( iChannelItemArray->MdcaPoint( aIndex ) ); |
|
349 TPtr ptr( channelItem->Des() ); |
|
350 ptr.Append( textChIconIndex ); // Add icon index |
|
351 |
|
352 iChannelItemArray->Delete( aIndex ); |
|
353 iChannelList->HandleItemRemovalL(); |
|
354 iChannelItemArray->InsertL( aIndex, *channelItem ); |
|
355 CleanupStack::PopAndDestroy( channelItem ); |
|
356 iChannelList->HandleItemAdditionL(); // Update list |
|
357 iChannelList->UpdateScrollBarsL(); |
|
358 } |
|
359 // use draw now so that view is up to date during fast channel switching |
|
360 iChannelList->DrawNow(); |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------- |
|
364 // CFMRadioChannelListContainer::HideIconsL |
|
365 // hide all icons from the list |
|
366 // ---------------------------------------------------- |
|
367 // |
|
368 void CFMRadioChannelListContainer::HideIconsL() |
|
369 { |
|
370 for ( TInt index = 0 ; index < iChannelItemArray->Count(); index++ ) |
|
371 { |
|
372 HBufC* channelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
373 channelItem->Des().Copy( iChannelItemArray->MdcaPoint( index ) ); |
|
374 TPtr ptr( channelItem->Des() ); |
|
375 |
|
376 TBuf<KLengthOfChannelItemIconIndexString> textChIconIndex; |
|
377 TPtrC iconIndexPtr( textChIconIndex ); |
|
378 TInt err = TextUtils::ColumnText( iconIndexPtr, 3, &ptr ); |
|
379 |
|
380 if ( iconIndexPtr.Length() > 0 ) |
|
381 { |
|
382 ptr.Delete( ptr.Length() - iconIndexPtr.Length(), iconIndexPtr.Length() ); // Remove icon index |
|
383 iChannelItemArray->Delete( index ); |
|
384 iChannelList->HandleItemRemovalL(); |
|
385 iChannelItemArray->InsertL( index, *channelItem ); |
|
386 iChannelList->HandleItemAdditionL(); // Update list |
|
387 iChannelList->UpdateScrollBarsL(); |
|
388 } |
|
389 CleanupStack::PopAndDestroy( channelItem ); |
|
390 } |
|
391 } |
|
392 |
|
393 // ---------------------------------------------------- |
|
394 // CFMRadioChannelListContainer::SetFaded |
|
395 // Fades the entire window and controls in the window owned |
|
396 // by this container control. |
|
397 // ---------------------------------------------------- |
|
398 // |
|
399 void CFMRadioChannelListContainer::SetFaded( TBool aFaded ) |
|
400 { |
|
401 iFadeStatus = aFaded; |
|
402 Window().SetFaded( aFaded, RWindowTreeNode::EFadeIncludeChildren ); |
|
403 } |
|
404 |
|
405 // ---------------------------------------------------- |
|
406 // CFMRadioChannelListContainer::UpdateLastListenedChannel |
|
407 // Updates channel index - the highlighted channel in the list. |
|
408 // ---------------------------------------------------- |
|
409 // |
|
410 void CFMRadioChannelListContainer::UpdateLastListenedChannel( TInt aIndex ) |
|
411 { |
|
412 iLastChIndex = aIndex; |
|
413 iChannelList->SetCurrentItemIndex( iLastChIndex ); |
|
414 iChannelList->ScrollToMakeItemVisible( iLastChIndex ); |
|
415 iChannelList->DrawDeferred(); |
|
416 } |
|
417 |
|
418 // ---------------------------------------------------- |
|
419 // CFMRadioChannelListContainer::CurrentlySelectedChannel |
|
420 // Returns the index of the selected channel item from the |
|
421 // channel list. |
|
422 // ---------------------------------------------------- |
|
423 // |
|
424 TInt CFMRadioChannelListContainer::CurrentlySelectedChannel() const |
|
425 { |
|
426 return iChannelList->CurrentItemIndex(); // Index of selected channel |
|
427 } |
|
428 |
|
429 // ---------------------------------------------------- |
|
430 // CFMRadioChannelListContainer::HandleListBoxEventL |
|
431 // For handling listbox-, in this case, channel list events. |
|
432 // The event equals to selecting a channel item from the list. |
|
433 // ---------------------------------------------------- |
|
434 // |
|
435 void CFMRadioChannelListContainer::HandleListBoxEventL( CEikListBox* /*aListBox*/, |
|
436 TListBoxEvent aEventType ) |
|
437 { |
|
438 // Check the event generated by keypress and report the event, |
|
439 // Also check for Pen Enabled touch screen event |
|
440 |
|
441 switch ( aEventType ) |
|
442 { |
|
443 case EEventEnterKeyPressed: |
|
444 { |
|
445 ReportEventL( MCoeControlObserver::EEventStateChanged ); |
|
446 break; |
|
447 } |
|
448 case EEventItemSingleClicked: |
|
449 { |
|
450 if ( iMoveAction ) |
|
451 { |
|
452 TouchMoveEventL( CurrentlySelectedChannel() ); |
|
453 } |
|
454 else |
|
455 { |
|
456 ReportEventL( MCoeControlObserver::EEventStateChanged ); |
|
457 } |
|
458 break; |
|
459 } |
|
460 default: |
|
461 { |
|
462 break; |
|
463 } |
|
464 } |
|
465 } |
|
466 |
|
467 // ----------------------------------------------------------------------------- |
|
468 // CFMRadioChannelListContainer::HandleResourceChange |
|
469 // ----------------------------------------------------------------------------- |
|
470 // |
|
471 void CFMRadioChannelListContainer::HandleResourceChange(TInt aType) |
|
472 { |
|
473 CCoeControl::HandleResourceChange(aType); |
|
474 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
475 { |
|
476 SizeChanged(); |
|
477 } |
|
478 } |
|
479 // --------------------------------------------------------- |
|
480 // CFMRadioChannelListContainer::SizeChanged |
|
481 // Called by framework when the view size is changed |
|
482 // --------------------------------------------------------- |
|
483 // |
|
484 void CFMRadioChannelListContainer::SizeChanged() |
|
485 { |
|
486 // The channel list fills the whole view |
|
487 iChannelList->SetRect( Rect() ); |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------- |
|
491 // CFMRadioChannelListContainer::CountComponentControls |
|
492 // Return the number of controls in the window owned by this container |
|
493 // --------------------------------------------------------- |
|
494 // |
|
495 TInt CFMRadioChannelListContainer::CountComponentControls() const |
|
496 { |
|
497 return iControls.Count(); |
|
498 } |
|
499 |
|
500 // --------------------------------------------------------- |
|
501 // CFMRadioChannelListContainer::ComponentControl |
|
502 // Return the control corresponding to the specified index |
|
503 // --------------------------------------------------------- |
|
504 // |
|
505 CCoeControl* CFMRadioChannelListContainer::ComponentControl( TInt aIndex ) const |
|
506 { |
|
507 return STATIC_CAST( CCoeControl *,iControls[aIndex] ); |
|
508 } |
|
509 |
|
510 // --------------------------------------------------------- |
|
511 // CFMRadioChannelListContainer::OfferKeyEventL |
|
512 // Allow the channel list to process key events |
|
513 // --------------------------------------------------------- |
|
514 // |
|
515 TKeyResponse CFMRadioChannelListContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
516 TEventCode aType ) |
|
517 { |
|
518 TKeyResponse response = EKeyWasNotConsumed; |
|
519 |
|
520 switch ( aKeyEvent.iCode ) |
|
521 { |
|
522 case EKeyLeftArrow: |
|
523 case EKeyRightArrow: |
|
524 { |
|
525 return EKeyWasNotConsumed; |
|
526 } |
|
527 case EKeyUpArrow: |
|
528 if ( iMoveAction ) |
|
529 { |
|
530 MoveUpL(); |
|
531 } |
|
532 else |
|
533 { |
|
534 response = iChannelList->OfferKeyEventL(aKeyEvent, aType); |
|
535 if (response == EKeyWasConsumed) |
|
536 { |
|
537 ReportEventL( MCoeControlObserver::EEventRequestFocus ); |
|
538 } |
|
539 } |
|
540 return response; |
|
541 case EKeyDownArrow: |
|
542 if ( iMoveAction ) |
|
543 { |
|
544 MoveDownL(); |
|
545 } |
|
546 else |
|
547 { |
|
548 response = iChannelList->OfferKeyEventL(aKeyEvent, aType); |
|
549 if (response == EKeyWasConsumed) |
|
550 { |
|
551 ReportEventL( MCoeControlObserver::EEventRequestFocus ); |
|
552 } |
|
553 } |
|
554 return response; |
|
555 default: |
|
556 switch ( aKeyEvent.iScanCode ) //we need to use the scan code, because we need to process the event wrt the keyUp and keyDown action |
|
557 { |
|
558 case EKeyboardKey1: // Timed key |
|
559 case EKeyboardKey2: // Normal keys |
|
560 case EKeyboardKey3: |
|
561 case EKeyboardKey4: |
|
562 case EKeyboardKey5: |
|
563 case EKeyboardKey6: |
|
564 case EKeyboardKey7: |
|
565 case EKeyboardKey8: |
|
566 case EKeyboardKey9: |
|
567 case EKeyboardKey0: |
|
568 return EKeyWasNotConsumed; |
|
569 default: |
|
570 break; |
|
571 } |
|
572 break; |
|
573 } |
|
574 return iChannelList->OfferKeyEventL(aKeyEvent, aType); |
|
575 } |
|
576 |
|
577 // --------------------------------------------------------- |
|
578 // CFMRadioChannelListContainer::Draw |
|
579 // Redraw the window owned by this container |
|
580 // --------------------------------------------------------- |
|
581 // |
|
582 void CFMRadioChannelListContainer::Draw( const TRect& aRect ) const |
|
583 { |
|
584 CWindowGc& gc = SystemGc(); |
|
585 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
586 gc.SetBrushColor( KRgbGray ); |
|
587 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
588 gc.DrawRect( aRect ); |
|
589 |
|
590 // Fade if needed |
|
591 Window().SetFaded( iFadeStatus, RWindowTreeNode::EFadeIncludeChildren ); |
|
592 } |
|
593 |
|
594 // --------------------------------------------------------------------------- |
|
595 // CFMRadioChannelListContainer::GetHelpContext |
|
596 // Gets Help |
|
597 // |
|
598 // --------------------------------------------------------------------------- |
|
599 // |
|
600 void CFMRadioChannelListContainer::GetHelpContext(TCoeHelpContext& aContext) const |
|
601 { |
|
602 #if defined __SERIES60_HELP || defined FF_S60_HELPS_IN_USE |
|
603 aContext.iMajor = TUid::Uid( KUidFMRadioApplication ); |
|
604 aContext.iContext = KFMRADIO_HLP_LIST; |
|
605 #endif |
|
606 } |
|
607 |
|
608 // --------------------------------------------------------- |
|
609 // CFMRadioChannelListContainer::FocusChanged(TDrawNow aDrawNow) |
|
610 // |
|
611 // --------------------------------------------------------- |
|
612 // |
|
613 void CFMRadioChannelListContainer::FocusChanged(TDrawNow aDrawNow) |
|
614 { |
|
615 CCoeControl::FocusChanged(aDrawNow); |
|
616 if ( iChannelList ) |
|
617 { |
|
618 iChannelList->SetFocus(IsFocused(), aDrawNow); |
|
619 } |
|
620 } |
|
621 |
|
622 // --------------------------------------------------------- |
|
623 // CFMRadioChannelListContainer::HandlePointerEventL |
|
624 // --------------------------------------------------------- |
|
625 // |
|
626 void CFMRadioChannelListContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
627 { |
|
628 // don't handle any pointer events if view is faded |
|
629 if ( !iFadeStatus ) |
|
630 { |
|
631 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
632 } |
|
633 } |
|
634 |
|
635 // --------------------------------------------------------- |
|
636 // CFMRadioChannelListContainer::ActivateMove |
|
637 // --------------------------------------------------------- |
|
638 // |
|
639 void CFMRadioChannelListContainer::ActivateMoveL() |
|
640 { |
|
641 |
|
642 iMoveAction = ETrue; |
|
643 iMoveIndex = iChannelList->CurrentItemIndex(); |
|
644 iTouchMoveIndex = iMoveIndex; |
|
645 UpdateItemIconL( iMoveIndex, KMoveIconIndexChList ); |
|
646 } |
|
647 |
|
648 // --------------------------------------------------------- |
|
649 // CFMRadioChannelListContainer::TouchMoveEventL |
|
650 // --------------------------------------------------------- |
|
651 // |
|
652 void CFMRadioChannelListContainer::TouchMoveEventL( TInt aIndex ) |
|
653 { |
|
654 HBufC* channelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
655 channelItem->Des().Copy( iChannelItemArray->MdcaPoint( iTouchMoveIndex ) ); |
|
656 TPtr ptr( channelItem->Des() ); |
|
657 |
|
658 TBuf<KLengthOfChannelItemIconIndexString> textChIconIndex; |
|
659 |
|
660 TPtrC iconIndexPtr( textChIconIndex ); |
|
661 |
|
662 TInt err = TextUtils::ColumnText( iconIndexPtr, 3, &ptr ); |
|
663 |
|
664 iChannelItemArray->Delete( iTouchMoveIndex ); |
|
665 iChannelList->HandleItemRemovalL(); |
|
666 |
|
667 iChannelItemArray->InsertL( aIndex, *channelItem ); |
|
668 iChannelList->HandleItemAdditionL(); |
|
669 iChannelList->UpdateScrollBarsL(); |
|
670 iChannelList->SetCurrentItemIndex( aIndex ); |
|
671 iChannelList->DrawDeferred(); |
|
672 |
|
673 iTouchMoveIndex = aIndex; |
|
674 |
|
675 CleanupStack::PopAndDestroy( channelItem ); |
|
676 |
|
677 ReIndexAllL(); |
|
678 UpdateItemIconL( aIndex, KMoveIconIndexChList ); |
|
679 iChannelView->MoveActionDoneL(); |
|
680 } |
|
681 |
|
682 // --------------------------------------------------------- |
|
683 // CFMRadioChannelListContainer::MoveDownL |
|
684 // --------------------------------------------------------- |
|
685 // |
|
686 void CFMRadioChannelListContainer::MoveDownL() |
|
687 { |
|
688 TInt index = iChannelList->CurrentItemIndex(); |
|
689 TInt originalindex = index; |
|
690 |
|
691 HBufC* channelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
692 channelItem->Des().Copy( iChannelItemArray->MdcaPoint( index ) ); |
|
693 TPtr ptr( channelItem->Des() ); |
|
694 |
|
695 iChannelItemArray->Delete( index ); |
|
696 iChannelList->HandleItemRemovalL(); |
|
697 |
|
698 if ( index < iChannelItemArray->Count() ) |
|
699 { |
|
700 index = index+1; |
|
701 |
|
702 TBuf<KLengthOfChIndexStringChList> channelindex; |
|
703 |
|
704 TPtrC indexPtr( channelindex ); |
|
705 |
|
706 TInt errori = TextUtils::ColumnText( indexPtr, 0, &ptr ); |
|
707 |
|
708 ptr.Delete( 0, indexPtr.Length() ); |
|
709 |
|
710 channelindex.Format( KChIndexFormatChList, index+1 ); |
|
711 |
|
712 AknTextUtils::LanguageSpecificNumberConversion( channelindex ); |
|
713 |
|
714 ptr.Insert( 0, channelindex ); |
|
715 |
|
716 iChannelItemArray->InsertL( index, *channelItem ); |
|
717 iChannelList->HandleItemAdditionL(); // Update list |
|
718 iChannelList->UpdateScrollBarsL(); |
|
719 iChannelList->SetCurrentItemIndex( index ); |
|
720 iChannelList->DrawDeferred(); |
|
721 |
|
722 HBufC* origchannelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
723 origchannelItem->Des().Copy( iChannelItemArray->MdcaPoint( originalindex ) ); |
|
724 TPtr origptr( origchannelItem->Des() ); |
|
725 |
|
726 iChannelItemArray->Delete( originalindex ); |
|
727 iChannelList->HandleItemRemovalL(); |
|
728 TBuf<KLengthOfChIndexStringChList> origchannelindex; |
|
729 |
|
730 TPtrC origindexPtr( origchannelindex ); |
|
731 |
|
732 TextUtils::ColumnText( origindexPtr, 0, &origptr ); |
|
733 origptr.Delete( 0, origindexPtr.Length() ); |
|
734 |
|
735 origchannelindex.Format( KChIndexFormatChList, originalindex+1 ); |
|
736 |
|
737 AknTextUtils::LanguageSpecificNumberConversion( origchannelindex ); |
|
738 origptr.Insert( 0, origchannelindex ); |
|
739 iChannelItemArray->InsertL( originalindex, *origchannelItem ); |
|
740 iChannelList->HandleItemAdditionL(); |
|
741 iChannelList->UpdateScrollBarsL(); |
|
742 iChannelList->DrawDeferred(); |
|
743 |
|
744 CleanupStack::PopAndDestroy( origchannelItem ); |
|
745 } |
|
746 else |
|
747 { |
|
748 index = 0; |
|
749 iChannelItemArray->InsertL( index, *channelItem ); |
|
750 iChannelList->HandleItemAdditionL(); // Update list |
|
751 iChannelList->UpdateScrollBarsL(); |
|
752 iChannelList->SetCurrentItemIndex( index ); |
|
753 iChannelList->DrawDeferred(); |
|
754 |
|
755 ReIndexAllL(); |
|
756 } |
|
757 |
|
758 iChannelList->ScrollToMakeItemVisible( index ); |
|
759 |
|
760 CleanupStack::PopAndDestroy( channelItem ); |
|
761 |
|
762 } |
|
763 // --------------------------------------------------------- |
|
764 // CFMRadioChannelListContainer::MoveUpL |
|
765 // --------------------------------------------------------- |
|
766 // |
|
767 void CFMRadioChannelListContainer::MoveUpL() |
|
768 { |
|
769 TInt index = iChannelList->CurrentItemIndex(); |
|
770 TInt originalindex = index; |
|
771 |
|
772 HBufC* channelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
773 channelItem->Des().Copy( iChannelItemArray->MdcaPoint( index ) ); |
|
774 TPtr ptr( channelItem->Des() ); |
|
775 |
|
776 iChannelItemArray->Delete( index ); |
|
777 iChannelList->HandleItemRemovalL(); |
|
778 |
|
779 if ( 0 == index ) |
|
780 { |
|
781 index = iChannelItemArray->Count(); |
|
782 |
|
783 TBuf<KLengthOfChIndexStringChList> channelindex; |
|
784 |
|
785 TPtrC indexPtr( channelindex ); |
|
786 |
|
787 iChannelItemArray->InsertL( index, *channelItem ); |
|
788 iChannelList->HandleItemAdditionL(); |
|
789 iChannelList->UpdateScrollBarsL(); |
|
790 |
|
791 iChannelList->SetCurrentItemIndex( index ); |
|
792 |
|
793 iChannelList->DrawItem( index ); |
|
794 |
|
795 ReIndexAllL(); |
|
796 } |
|
797 else |
|
798 { |
|
799 index = index-1; |
|
800 |
|
801 TBuf<KLengthOfChIndexStringChList> channelindex; |
|
802 |
|
803 TPtrC indexPtr( channelindex ); |
|
804 |
|
805 TInt errori = TextUtils::ColumnText( indexPtr, 0, &ptr ); |
|
806 |
|
807 ptr.Delete( 0, indexPtr.Length() ); |
|
808 |
|
809 channelindex.Format( KChIndexFormatChList, index+1 ); |
|
810 |
|
811 AknTextUtils::LanguageSpecificNumberConversion( channelindex ); |
|
812 ptr.Insert( 0, channelindex ); // Remove icon index |
|
813 |
|
814 iChannelItemArray->InsertL( index, *channelItem ); |
|
815 iChannelList->SetCurrentItemIndex( index ); |
|
816 iChannelList->HandleItemAdditionL(); |
|
817 iChannelList->UpdateScrollBarsL(); |
|
818 iChannelList->DrawItem( index ); |
|
819 |
|
820 HBufC* origchannelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
821 origchannelItem->Des().Copy( iChannelItemArray->MdcaPoint( originalindex ) ); |
|
822 TPtr origptr( origchannelItem->Des() ); |
|
823 |
|
824 iChannelItemArray->Delete( originalindex ); |
|
825 iChannelList->HandleItemRemovalL(); |
|
826 TBuf<KLengthOfChIndexStringChList> origchannelindex; |
|
827 |
|
828 TPtrC origindexPtr( origchannelindex ); |
|
829 |
|
830 TextUtils::ColumnText( origindexPtr, 0, &origptr ); |
|
831 |
|
832 origptr.Delete( 0, origindexPtr.Length() ); |
|
833 |
|
834 origchannelindex.Format( KChIndexFormatChList, originalindex+1 ); |
|
835 |
|
836 AknTextUtils::LanguageSpecificNumberConversion( origchannelindex ); |
|
837 origptr.Insert( 0, origchannelindex ); |
|
838 |
|
839 iChannelItemArray->InsertL( originalindex, *origchannelItem ); |
|
840 iChannelList->HandleItemAdditionL(); |
|
841 iChannelList->DrawDeferred(); |
|
842 |
|
843 iChannelList->UpdateScrollBarsL(); |
|
844 |
|
845 CleanupStack::PopAndDestroy( origchannelItem ); |
|
846 } |
|
847 |
|
848 iChannelList->ScrollToMakeItemVisible( index ); |
|
849 |
|
850 CleanupStack::PopAndDestroy( channelItem ); |
|
851 } |
|
852 |
|
853 // --------------------------------------------------------- |
|
854 // CFMRadioChannelListContainer::ReIndexAllL |
|
855 // --------------------------------------------------------- |
|
856 // |
|
857 void CFMRadioChannelListContainer::ReIndexAllL() |
|
858 { |
|
859 HBufC* channelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
860 |
|
861 for ( TInt index = 0; index < iChannelItemArray->Count(); index++ ) |
|
862 { |
|
863 channelItem->Des().Copy( iChannelItemArray->MdcaPoint( index ) ); |
|
864 TPtr ptr( channelItem->Des() ); |
|
865 |
|
866 iChannelItemArray->Delete( index ); |
|
867 iChannelList->HandleItemRemovalL(); |
|
868 |
|
869 TBuf<KLengthOfChIndexStringChList> channelindex; |
|
870 |
|
871 TPtrC indexPtr( channelindex ); |
|
872 |
|
873 TInt errori = TextUtils::ColumnText( indexPtr, 0, &ptr ); |
|
874 |
|
875 ptr.Delete( 0, indexPtr.Length() ); |
|
876 |
|
877 channelindex.Format( KChIndexFormatChList, index+1 ); |
|
878 |
|
879 AknTextUtils::LanguageSpecificNumberConversion( channelindex ); |
|
880 |
|
881 ptr.Insert( 0, channelindex ); // Remove icon index |
|
882 |
|
883 iChannelItemArray->InsertL( index, *channelItem ); |
|
884 |
|
885 iChannelList->HandleItemAdditionL(); |
|
886 iChannelList->DrawDeferred(); |
|
887 iChannelList->UpdateScrollBarsL(); |
|
888 } |
|
889 |
|
890 CleanupStack::PopAndDestroy( channelItem ); |
|
891 } |
|
892 |
|
893 // --------------------------------------------------------- |
|
894 // CFMRadioChannelListContainer::HandleDropL |
|
895 // --------------------------------------------------------- |
|
896 // |
|
897 void CFMRadioChannelListContainer::HandleDropL() |
|
898 { |
|
899 iMoveAction = EFalse; |
|
900 |
|
901 if ( iMoveIndex != iChannelList->CurrentItemIndex() ) |
|
902 { |
|
903 iObserver.UpdateChannelsL( EMoveChannels, |
|
904 iMoveIndex, |
|
905 iChannelList->CurrentItemIndex() ); |
|
906 } |
|
907 HideIconsL(); |
|
908 iChannelList->DrawDeferred(); |
|
909 } |
|
910 // --------------------------------------------------------- |
|
911 // CFMRadioChannelListContainer::MoveDoneL |
|
912 // --------------------------------------------------------- |
|
913 // |
|
914 void CFMRadioChannelListContainer::MoveDoneL() |
|
915 { |
|
916 if ( iMoveAction ) |
|
917 { |
|
918 iMoveAction = EFalse; |
|
919 } |
|
920 |
|
921 iObserver.UpdateChannelsL( EStoreAllToRepository, 0, 0 ); |
|
922 } |
|
923 |
|
924 // --------------------------------------------------------- |
|
925 // CFMRadioChannelListContainer::MoveCanceledL |
|
926 // --------------------------------------------------------- |
|
927 // |
|
928 TBool CFMRadioChannelListContainer::MoveCanceledL() |
|
929 { |
|
930 TBool wasmove = EFalse; |
|
931 |
|
932 if ( iMoveAction ) |
|
933 { |
|
934 iMoveAction = EFalse; |
|
935 |
|
936 TInt index = iChannelList->CurrentItemIndex(); |
|
937 |
|
938 HBufC* channelItem = HBufC::NewLC( KLengthOfChannelItemString ); |
|
939 channelItem->Des().Copy( iChannelItemArray->MdcaPoint( index ) ); |
|
940 TPtr ptr( channelItem->Des() ); |
|
941 |
|
942 TBuf<KLengthOfChannelItemIconIndexString> textChIconIndex; |
|
943 TPtrC iconIndexPtr( textChIconIndex ); |
|
944 TInt err = TextUtils::ColumnText( iconIndexPtr, 3, &ptr ); |
|
945 iChannelItemArray->Delete( index ); |
|
946 iChannelList->HandleItemRemovalL(); |
|
947 |
|
948 iChannelItemArray->InsertL( iMoveIndex, *channelItem ); |
|
949 iChannelList->HandleItemAdditionL(); |
|
950 iChannelList->SetCurrentItemIndex( iMoveIndex ); |
|
951 CleanupStack::PopAndDestroy( channelItem ); |
|
952 |
|
953 iChannelList->ScrollToMakeItemVisible( index ); |
|
954 HideIconsL(); |
|
955 iChannelList->UpdateScrollBarsL(); |
|
956 iChannelList->DrawDeferred(); |
|
957 wasmove = ETrue; |
|
958 } |
|
959 |
|
960 return wasmove; |
|
961 } |
|
962 |
|
963 // --------------------------------------------------------- |
|
964 // CFMRadioChannelListContainer::MoveAction() |
|
965 // --------------------------------------------------------- |
|
966 // |
|
967 TBool CFMRadioChannelListContainer::MoveAction() |
|
968 { |
|
969 return iMoveAction; |
|
970 |
|
971 } |
|
972 |
|
973 // End of File |