1 /* |
|
2 * Copyright (c) 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: Content Control example |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Includes |
|
20 #include <aknlists.h> |
|
21 #include <akncontext.h> |
|
22 #include <akntitle.h> |
|
23 #include <aknnavi.h> |
|
24 #include <aknnavide.h> |
|
25 #include <akntabgrp.h> |
|
26 #include <aknstyluspopupmenu.h> |
|
27 |
|
28 #include <aknsinglestyletreelist.h> |
|
29 #include <aknsbasicbackgroundcontrolcontext.h> |
|
30 |
|
31 #include <hsccapiclient.h> |
|
32 #include <hscontentinfo.h> |
|
33 #include <hscontentinfoarray.h> |
|
34 |
|
35 #include "HsContentControlListBox.h" |
|
36 |
|
37 // Constants |
|
38 const TInt KFlags( CAknSingleStyleTreeList::EPersistent | |
|
39 CAknSingleStyleTreeList::EExpanded ); |
|
40 |
|
41 _LIT( KActivate, "Activate" ); |
|
42 |
|
43 enum TTabs |
|
44 { |
|
45 ETabFirst = 0, |
|
46 ETabActiveConfiguration = ETabFirst, |
|
47 ETabConfigurations, |
|
48 ETabViews, |
|
49 ETabWidgets, |
|
50 ETabLast = ETabWidgets |
|
51 }; |
|
52 |
|
53 // ============================ LOCAL FUNCTIONS ================================ |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS =============================== |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CHsContentControlListBox::CHsContentControlListBox |
|
59 // |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CHsContentControlListBox::CHsContentControlListBox() |
|
63 { |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CHsContentControlListBox::~CHsContentControlListBox |
|
68 // |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CHsContentControlListBox::~CHsContentControlListBox() |
|
72 { |
|
73 delete iHsCcApiClient; |
|
74 delete iCallback; |
|
75 delete iPopup; |
|
76 delete iListBox; |
|
77 delete iBgContext; |
|
78 delete iArray; |
|
79 delete iDecorator; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CHsContentControlListBox::NewL |
|
84 // |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CHsContentControlListBox* CHsContentControlListBox::NewL( const TRect& aRect, |
|
88 const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ) |
|
89 { |
|
90 CHsContentControlListBox* self = |
|
91 CHsContentControlListBox::NewLC( aRect, aParent, aCommandObserver ); |
|
92 CleanupStack::Pop( self ); |
|
93 |
|
94 return self; |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CHsContentControlListBox::NewLC |
|
99 // |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 CHsContentControlListBox* CHsContentControlListBox::NewLC( const TRect& aRect, |
|
103 const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ) |
|
104 { |
|
105 CHsContentControlListBox* self = new ( ELeave ) CHsContentControlListBox(); |
|
106 CleanupStack::PushL( self ); |
|
107 |
|
108 self->ConstructL( aRect, aParent, aCommandObserver ); |
|
109 |
|
110 return self; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CHsContentControlListBox::ConstructL |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CHsContentControlListBox::ConstructL( const TRect& aRect, |
|
119 const CCoeControl* aParent, MEikCommandObserver* /*aCommandObserver*/ ) |
|
120 { |
|
121 iHsCcApiClient = CHsCcApiClient::NewL( this ); |
|
122 |
|
123 TCallBack cb( PopulateList, this ); |
|
124 |
|
125 iCallback = new ( ELeave ) CAsyncCallBack( cb, CActive::EPriorityStandard ); |
|
126 |
|
127 if ( !aParent ) |
|
128 { |
|
129 CreateWindowL(); |
|
130 } |
|
131 else |
|
132 { |
|
133 SetContainerWindowL( *aParent ); |
|
134 } |
|
135 |
|
136 InitializeControlsL(); |
|
137 |
|
138 SetRect( aRect ); |
|
139 |
|
140 ActivateL(); |
|
141 |
|
142 PopulateListL(); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CHsContentControlListBox::CountComponentControls |
|
147 // |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CHsContentControlListBox::CountComponentControls() const |
|
151 { |
|
152 return 1; |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CHsContentControlListBox::CHsContentControlListBox |
|
157 // |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 CCoeControl* CHsContentControlListBox::ComponentControl( TInt aIndex ) const |
|
161 { |
|
162 if ( aIndex == 0 ) |
|
163 { |
|
164 return iListBox; |
|
165 } |
|
166 |
|
167 return NULL; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CHsContentControlListBox::OfferKeyEventL |
|
172 // |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 TKeyResponse CHsContentControlListBox::OfferKeyEventL( |
|
176 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
177 { |
|
178 if ( iListBox->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed ) |
|
179 { |
|
180 return EKeyWasConsumed; |
|
181 } |
|
182 |
|
183 return CCoeControl::OfferKeyEventL( aKeyEvent, aType ); |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CHsContentControlListBox::HandleResourceChange |
|
188 // |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CHsContentControlListBox::HandleResourceChange( TInt aType ) |
|
192 { |
|
193 CCoeControl::HandleResourceChange( aType ); |
|
194 |
|
195 SetRect( iAvkonAppUi->ClientRect() ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CHsContentControlListBox::SizeChanged |
|
200 // |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CHsContentControlListBox::SizeChanged() |
|
204 { |
|
205 CCoeControl::SizeChanged(); |
|
206 |
|
207 LayoutControls(); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CHsContentControlListBox::MopSupplyObject |
|
212 // |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 TTypeUid::Ptr CHsContentControlListBox::MopSupplyObject( TTypeUid aId ) |
|
216 { |
|
217 if ( aId.iUid == MAknsControlContext::ETypeId && iBgContext ) |
|
218 { |
|
219 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
220 } |
|
221 |
|
222 return CCoeControl::MopSupplyObject( aId ); |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CHsContentControlListBox::HandleTreeListEvent |
|
227 // |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CHsContentControlListBox::HandleTreeListEvent( |
|
231 CAknTreeList& /*aList*/, |
|
232 TAknTreeItemID aItem, |
|
233 TEvent aEvent ) |
|
234 { |
|
235 if ( aEvent == EItemSelected ) |
|
236 { |
|
237 if ( !iListBox->IsLeaf( aItem ) && !iListBox->IsMarked( aItem ) ) |
|
238 { |
|
239 return KErrNone; |
|
240 } |
|
241 |
|
242 const TWsEvent& event( iCoeEnv->LastEvent() ); |
|
243 |
|
244 if ( event.Type() == EEventPointer ) |
|
245 { |
|
246 TInt x, y; |
|
247 |
|
248 TPointerEvent& pointer( *event.Pointer() ); |
|
249 |
|
250 x = pointer.iParentPosition.iX; |
|
251 y = pointer.iParentPosition.iY; |
|
252 |
|
253 delete iPopup; |
|
254 iPopup = NULL; |
|
255 |
|
256 iPopup = CAknStylusPopUpMenu::NewL( this, TPoint( x, y ) ); |
|
257 |
|
258 if ( iTabIndex == ETabConfigurations ) |
|
259 { |
|
260 iSelectedItem = aItem; |
|
261 |
|
262 iPopup->AddMenuItemL( KActivate, 1 ); |
|
263 |
|
264 iPopup->SetPosition( TPoint( x, y ), |
|
265 CAknStylusPopUpMenu::EPositionTypeRightBottom ); |
|
266 |
|
267 iPopup->ShowMenu(); |
|
268 } |
|
269 } |
|
270 } |
|
271 |
|
272 return KErrNone; |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CHsContentControlListBox::ProcessCommandL |
|
277 // |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void CHsContentControlListBox::ProcessCommandL( TInt aCommandId ) |
|
281 { |
|
282 TAknTreeItemID item( iSelectedItem ); |
|
283 |
|
284 iSelectedItem = KAknTreeIIDNone; |
|
285 |
|
286 if ( item == KAknTreeIIDNone || aCommandId == KErrCancel ) |
|
287 { |
|
288 return; |
|
289 } |
|
290 |
|
291 // Resolve selected item |
|
292 if ( iTabIndex == ETabConfigurations ) |
|
293 { |
|
294 TAknTreeItemID id = iListBox->Child( KAknTreeIIDRoot, 0 ); |
|
295 |
|
296 TInt count( iListBox->ChildCount( id ) ); |
|
297 |
|
298 for ( TInt i = 0; i < count; i++ ) |
|
299 { |
|
300 if ( iListBox->Child( id, i ) == item ) |
|
301 { |
|
302 CHsContentInfo* info( iArray->Array()[i] ); |
|
303 |
|
304 TRAP_IGNORE( iHsCcApiClient->ActivateAppL( *info ) ); |
|
305 |
|
306 break; |
|
307 } |
|
308 } |
|
309 } |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CHsContentControlListBox::SetEmphasis |
|
314 // |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CHsContentControlListBox::SetEmphasis( CCoeControl* /*aMenuControl*/, |
|
318 TBool /*aEmphasis*/ ) |
|
319 { |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CHsContentControlListBox::TabChangedL |
|
324 // |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 void CHsContentControlListBox::TabChangedL( TInt aIndex ) |
|
328 { |
|
329 if ( aIndex != iTabIndex ) |
|
330 { |
|
331 iTabIndex = aIndex; |
|
332 |
|
333 iDecorator->SetScrollButtonDimmed( |
|
334 CAknNavigationDecorator::ERightButton, EFalse ); |
|
335 |
|
336 iDecorator->SetScrollButtonDimmed( |
|
337 CAknNavigationDecorator::ELeftButton, EFalse ); |
|
338 |
|
339 if ( iTabIndex == ETabFirst ) |
|
340 { |
|
341 iDecorator->SetScrollButtonDimmed( |
|
342 CAknNavigationDecorator::ELeftButton, ETrue ); |
|
343 } |
|
344 else if ( iTabIndex == ETabLast ) |
|
345 { |
|
346 iDecorator->SetScrollButtonDimmed( |
|
347 CAknNavigationDecorator::ERightButton, ETrue ); |
|
348 } |
|
349 |
|
350 iCallback->Cancel(); |
|
351 iCallback->CallBack(); |
|
352 } |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CHsContentControlListBox::NotifyWidgetListChanged |
|
357 // |
|
358 // ----------------------------------------------------------------------------- |
|
359 // |
|
360 void CHsContentControlListBox::NotifyWidgetListChanged() |
|
361 { |
|
362 iCallback->Cancel(); |
|
363 iCallback->CallBack(); |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CHsContentControlListBox::NotifyViewListChanged |
|
368 // |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CHsContentControlListBox::NotifyViewListChanged() |
|
372 { |
|
373 iCallback->Cancel(); |
|
374 iCallback->CallBack(); |
|
375 } |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // CHsContentControlListBox::NotifyAppListChanged |
|
379 // |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 void CHsContentControlListBox::NotifyAppListChanged() |
|
383 { |
|
384 iCallback->Cancel(); |
|
385 iCallback->CallBack(); |
|
386 } |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // CHsContentControlListBox::InitializeControlsL |
|
390 // |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 void CHsContentControlListBox::InitializeControlsL() |
|
394 { |
|
395 iListBox = CAknSingleStyleTreeList::NewL( *this ); |
|
396 iListBox->SetContainerWindowL( *this ); |
|
397 iListBox->AddObserverL( this ); |
|
398 iListBox->SetFocus( ETrue ); |
|
399 |
|
400 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
401 KAknsIIDQsnBgScreen, TRect(), ETrue ); |
|
402 |
|
403 CEikStatusPane* sp( iAvkonAppUi->StatusPane() ); |
|
404 |
|
405 TUid naviPaneUid( TUid::Uid( EEikStatusPaneUidNavi ) ); |
|
406 |
|
407 CAknNavigationControlContainer* naviPane = |
|
408 static_cast< CAknNavigationControlContainer* >( sp->ControlL( naviPaneUid ) ); |
|
409 |
|
410 iDecorator = naviPane->ResourceDecorator(); |
|
411 |
|
412 iDecorator->MakeScrollButtonVisible( ETrue ); |
|
413 |
|
414 iDecorator->SetScrollButtonDimmed( |
|
415 CAknNavigationDecorator::ELeftButton, ETrue ); |
|
416 |
|
417 iDecorator->SetScrollButtonDimmed( |
|
418 CAknNavigationDecorator::ERightButton, EFalse ); |
|
419 |
|
420 iTabGroup = static_cast< CAknTabGroup* > ( iDecorator->DecoratedControl() ); |
|
421 iTabGroup->SetObserver( this ); |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CHsContentControlListBox::LayoutControls |
|
426 // |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CHsContentControlListBox::LayoutControls() |
|
430 { |
|
431 iListBox->SetRect( Rect() ); |
|
432 |
|
433 TRect rect; |
|
434 |
|
435 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, rect ); |
|
436 |
|
437 iBgContext->SetRect( rect ); |
|
438 } |
|
439 |
|
440 // ----------------------------------------------------------------------------- |
|
441 // CHsContentControlListBox::PopulateListL |
|
442 // |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 void CHsContentControlListBox::PopulateListL() |
|
446 { |
|
447 if ( !iListBox->IsEmpty( KAknTreeIIDRoot ) ) |
|
448 { |
|
449 // Remove all |
|
450 iListBox->RemoveItem( KAknTreeIIDRoot, EFalse ); |
|
451 } |
|
452 |
|
453 delete iArray; |
|
454 iArray = NULL; |
|
455 |
|
456 if ( iTabIndex == ETabActiveConfiguration ) |
|
457 { |
|
458 CHsContentInfo* activeApp = CHsContentInfo::NewL(); |
|
459 CleanupStack::PushL( activeApp ); |
|
460 |
|
461 // Get active homescreen configuration |
|
462 iHsCcApiClient->ActiveAppL( *activeApp ); |
|
463 |
|
464 _LIT( KActiveConfiguration, "Active configuration" ); |
|
465 |
|
466 TAknTreeItemID root = iListBox->AddNodeL( |
|
467 KAknTreeIIDRoot, KActiveConfiguration, KFlags, EFalse ); |
|
468 |
|
469 CHsContentInfoArray* viewList = CHsContentInfoArray::NewL(); |
|
470 CleanupStack::PushL( viewList ); |
|
471 |
|
472 // Get view list from the active configuration |
|
473 iHsCcApiClient->ViewListL( *activeApp, *viewList ); |
|
474 |
|
475 _LIT( KView, "View " ); |
|
476 |
|
477 for ( TInt j = 0; j < viewList->Array().Count(); j++ ) |
|
478 { |
|
479 TBuf< 32 > viewname; |
|
480 viewname = KView(); |
|
481 viewname.AppendNum( j + 1 ); |
|
482 |
|
483 CHsContentInfo* view( viewList->Array()[j] ); |
|
484 |
|
485 TAknTreeItemID parent = iListBox->AddNodeL( |
|
486 root, viewname, KFlags, EFalse ); |
|
487 |
|
488 CHsContentInfoArray* widgetList = CHsContentInfoArray::NewL(); |
|
489 CleanupStack::PushL( widgetList ); |
|
490 |
|
491 // Get widget list from the view |
|
492 iHsCcApiClient->WidgetListL( *view, *widgetList ); |
|
493 |
|
494 for ( TInt k = 0; k < widgetList->Array().Count(); k++ ) |
|
495 { |
|
496 CHsContentInfo* widget( widgetList->Array()[k] ); |
|
497 |
|
498 iListBox->AddLeafL( parent, widget->Name(), KFlags, EFalse ); |
|
499 } |
|
500 |
|
501 CleanupStack::PopAndDestroy( widgetList ); |
|
502 } |
|
503 |
|
504 CleanupStack::PopAndDestroy( viewList ); |
|
505 |
|
506 CleanupStack::PopAndDestroy( activeApp ); |
|
507 } |
|
508 else if ( iTabIndex == ETabConfigurations ) |
|
509 { |
|
510 _LIT( KConfigurations, "Configurations" ); |
|
511 |
|
512 TAknTreeItemID root = iListBox->AddNodeL( |
|
513 KAknTreeIIDRoot, KConfigurations, KFlags, EFalse ); |
|
514 |
|
515 iArray = CHsContentInfoArray::NewL(); |
|
516 |
|
517 // Get all homescreen configurations |
|
518 iHsCcApiClient->AppListL( *iArray ); |
|
519 |
|
520 _LIT( KConfiguration, "Configuration " ); |
|
521 |
|
522 for ( TInt i = 0; i < iArray->Array().Count(); i++ ) |
|
523 { |
|
524 TBuf< 32 > confname; |
|
525 confname = KConfiguration(); |
|
526 confname.AppendNum( i + 1 ); |
|
527 |
|
528 CHsContentInfo* app( iArray->Array()[i] ); |
|
529 |
|
530 iListBox->AddLeafL( root, confname, KFlags, EFalse ); |
|
531 } |
|
532 } |
|
533 |
|
534 else if ( iTabIndex == ETabViews ) |
|
535 { |
|
536 _LIT( KViews, "Views" ); |
|
537 |
|
538 TAknTreeItemID root = iListBox->AddNodeL( |
|
539 KAknTreeIIDRoot, KViews, KFlags, EFalse ); |
|
540 |
|
541 iArray = CHsContentInfoArray::NewL(); |
|
542 |
|
543 // Get all homescreen views |
|
544 iHsCcApiClient->ViewListL( *iArray ); |
|
545 |
|
546 _LIT( KView, "View " ); |
|
547 |
|
548 for ( TInt i = 0; i < iArray->Array().Count(); i++ ) |
|
549 { |
|
550 TBuf< 32 > viewname; |
|
551 viewname = KView(); |
|
552 viewname.AppendNum( i + 1 ); |
|
553 |
|
554 CHsContentInfo* view( iArray->Array()[i] ); |
|
555 |
|
556 iListBox->AddLeafL( root, viewname, KFlags, EFalse ); |
|
557 } |
|
558 } |
|
559 |
|
560 else if ( iTabIndex == ETabWidgets ) |
|
561 { |
|
562 _LIT( KWidgets, "Widgets" ); |
|
563 |
|
564 TAknTreeItemID root = iListBox->AddNodeL( |
|
565 KAknTreeIIDRoot, KWidgets, KFlags, EFalse ); |
|
566 |
|
567 iArray = CHsContentInfoArray::NewL(); |
|
568 |
|
569 // Get all homescreen widgets |
|
570 iHsCcApiClient->WidgetListL( *iArray ); |
|
571 |
|
572 for ( TInt i = 0; i < iArray->Array().Count(); i++ ) |
|
573 { |
|
574 CHsContentInfo* widget( iArray->Array()[i] ); |
|
575 |
|
576 iListBox->AddLeafL( root, widget->Name(), KFlags, EFalse ); |
|
577 } |
|
578 } |
|
579 |
|
580 DrawNow(); |
|
581 } |
|
582 |
|
583 // ----------------------------------------------------------------------------- |
|
584 // CHsContentControlListBox::PopulateList |
|
585 // |
|
586 // ----------------------------------------------------------------------------- |
|
587 // |
|
588 /*static*/ TInt CHsContentControlListBox::PopulateList( TAny* aAny ) |
|
589 { |
|
590 CHsContentControlListBox* self = |
|
591 static_cast< CHsContentControlListBox* >( aAny ); |
|
592 |
|
593 TRAP_IGNORE( self->PopulateListL() ); |
|
594 |
|
595 return KErrNone; |
|
596 } |
|
597 |
|
598 // End of file |
|