widgetmanager/src/wmmaincontainer.cpp
changeset 1 5315654608de
parent 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
0:f72a12da539e 1:5315654608de
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 * Implementation of the container control for WidgetManager application.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknViewAppUi.h>
       
    21 #include <eikappui.h>
       
    22 #include <widgetmanagerview.rsg>
       
    23 #include <coemain.h>
       
    24 #include <eikenv.h>
       
    25 #include <barsread.h>
       
    26 #include <AknUtils.h>
       
    27 #include <barsread.h>
       
    28 #include <StringLoader.h>
       
    29 #include <eikenv.h>
       
    30 #include <AknIconArray.h>
       
    31 #include <aknstyluspopupmenu.h> 
       
    32 #include <avkon.loc>
       
    33 #include <aknlayout.cdl.h>
       
    34 #include <layoutmetadata.cdl.h>
       
    35 #include <aknlayoutscalable_avkon.cdl.h>
       
    36 #include <AknsSkinInstance.h>
       
    37 #include <apgicnfl.h>
       
    38 #include <AknIconUtils.h>
       
    39 #include <AknsDrawUtils.h>
       
    40 #include <aknenv.h>
       
    41 #include <aknlists.h>
       
    42 #include <eikclbd.h>
       
    43 #include <aknsfld.h>
       
    44 #include <AknLayout.lag>
       
    45 #include <aknlayoutscalable_avkon.cdl.h>
       
    46 #include <AknsBasicBackgroundControlContext.h>
       
    47 #include <apgcli.h>
       
    48 #include <widgetmanager.mbg>
       
    49 #include <avkon.rsg>
       
    50 #include <coecobs.h>
       
    51 #include <coecntrl.h>
       
    52 #include <SWInstApi.h> //installer
       
    53 #include <WidgetRegistryClient.h> // widgetreqistry
       
    54 #include <aknbutton.h> // CAknButton
       
    55 #include <SchemeHandler.h> // for starting the OVI client
       
    56 #include <featmgr.h>     // FeatureManager
       
    57 #include <hlplch.h>      // HlpLauncher
       
    58 #include <csxhelp/hmsc.hlp.hrh>
       
    59 #include <aisystemuids.hrh>
       
    60 
       
    61 #include "wmcommon.h"
       
    62 #include "wmplugin.h"
       
    63 #include "wmmaincontainer.h"
       
    64 #include "wmmaincontainerview.h"
       
    65 #include "wmresourceloader.h"
       
    66 #include "widgetmanager.hrh"
       
    67 #include "wmlistbox.h"
       
    68 #include "wmpersistentwidgetorder.h"
       
    69 #include "wmdetailsdlg.h"
       
    70 #include "wmwidgetloaderao.h"
       
    71 
       
    72 // CONSTANTS
       
    73 const TInt KTextLimit = 40; // Text-limit for find-field
       
    74 const TInt KMinWidgets = 1; // minimum number of widgets to show findpane
       
    75 _LIT8( KWrtMime, "application/x-nokia-widget");
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CWmMainContainer::CWmMainContainer()
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 CWmMainContainer::CWmMainContainer( CWmPlugin& aWmPlugin )
       
    82     :iWmPlugin( aWmPlugin )
       
    83 	{
       
    84     iWidgetsList = NULL;
       
    85     iFindbox = NULL;
       
    86     iFindPaneIsVisible = EFalse;
       
    87     iBgContext = NULL;
       
    88     iFocusMode = ENowhere;
       
    89     iClosingDown = EFalse;
       
    90 	}
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // CWmMainContainer::~CWmMainContainer()
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 CWmMainContainer::~CWmMainContainer()
       
    97 	{
       
    98 	RemoveCtrlsFromStack();
       
    99     Components().ResetAndDestroy();
       
   100     delete iWidgetLoader;
       
   101     iWidgetsList = NULL;
       
   102     iOviPortal = NULL;
       
   103     iFindbox = NULL;
       
   104 	delete iBgContext;
       
   105 	}
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // CWmMainContainer::NewL
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 CWmMainContainer* CWmMainContainer::NewL( 
       
   112 		const TRect& aRect, 
       
   113 		const CCoeControl* aParent, 
       
   114 		MEikCommandObserver* aCommandObserver,
       
   115 		CWmPlugin& aWmPlugin )
       
   116 	{
       
   117 	CWmMainContainer* self = CWmMainContainer::NewLC( 
       
   118 			aRect, 
       
   119 			aParent, 
       
   120 			aCommandObserver,
       
   121 			aWmPlugin );
       
   122 	CleanupStack::Pop( self );
       
   123 	return self;
       
   124 	}
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CWmMainContainer::NewLC
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 CWmMainContainer* CWmMainContainer::NewLC( 
       
   131 		const TRect& aRect, 
       
   132 		const CCoeControl* aParent, 
       
   133     MEikCommandObserver* aCommandObserver,
       
   134     CWmPlugin& aWmPlugin )
       
   135 	{
       
   136 	CWmMainContainer* self = new ( ELeave ) CWmMainContainer( aWmPlugin );
       
   137 	CleanupStack::PushL( self );
       
   138 	self->ConstructL( aRect, aParent, aCommandObserver );
       
   139 	return self;
       
   140 	}
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // ScreenRect
       
   144 // rectangle representing the screen
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 TRect ScreenRect()
       
   148     {
       
   149     TRect screen;
       
   150     CCoeEnv* env = CCoeEnv::Static();
       
   151     if ( env )
       
   152         {
       
   153         CWsScreenDevice* screenDevice = env->ScreenDevice();
       
   154         if ( screenDevice )
       
   155             screen.SetRect( TPoint(0,0), screenDevice->SizeInPixels() );
       
   156         }
       
   157     return screen;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // CWmMainContainer::ConstructL
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 void CWmMainContainer::ConstructL( 
       
   165 		const TRect& aRect, 
       
   166 		const CCoeControl* aParent, 
       
   167         MEikCommandObserver* /*aCommandObserver*/ )
       
   168 	{
       
   169     // Initialize control array
       
   170 	InitComponentArrayL();
       
   171 	Components().SetControlsOwnedExternally( ETrue );
       
   172 
       
   173 	// create the UI
       
   174 	if ( aParent == NULL )
       
   175 	    {
       
   176 		CreateWindowL();
       
   177 		iParent = this;
       
   178 	    }
       
   179 	else
       
   180 	    {
       
   181 	    SetContainerWindowL( *aParent );
       
   182 	    iParent = aParent;
       
   183 	    }
       
   184 
       
   185 	// background context
       
   186 	iBgContext = CAknsBasicBackgroundControlContext::NewL( 
       
   187 	        KAknsIIDQsnBgScreen, ScreenRect() , ETrue);
       
   188 
       
   189 	// set up controls
       
   190 	InitializeControlsL( aRect );
       
   191 
       
   192 	// set size and activate
       
   193 	SetRect( aRect );
       
   194 	if ( !aParent )
       
   195         {
       
   196         ActivateL();
       
   197         }
       
   198 	
       
   199 	}
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CWmMainContainer::SizeChanged
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 void CWmMainContainer::SizeChanged()
       
   206 	{
       
   207 	CCoeControl::SizeChanged();
       
   208     iBgContext->SetRect( ScreenRect() );
       
   209 	TRAP_IGNORE( LayoutControlsL() );
       
   210 	}
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CWmMainContainer::LayoutControlsL
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 void CWmMainContainer::LayoutControlsL()
       
   217 	{
       
   218 	TRect rect = Rect();
       
   219 	TBool landscape = ( rect.Width() > rect.Height() );
       
   220 
       
   221     // calculate layout (different in landscape and portrait)
       
   222 	TRect oviButtonRect;
       
   223 	TRect widgetsListRect;
       
   224 	if ( landscape )
       
   225 	    {
       
   226 	    iLayout = ELandscape;
       
   227         const TInt KOffset = 2;
       
   228         TInt oviButtonWidth = rect.Width() / 6;
       
   229         widgetsListRect.SetRect(
       
   230                 TPoint( 0, 0 ),
       
   231                 TPoint( rect.Width() - oviButtonWidth - KOffset, rect.Height() ) );
       
   232         oviButtonRect.SetRect(
       
   233                 TPoint( rect.Width() - oviButtonWidth, KOffset ),
       
   234                 TPoint( rect.Width() - KOffset, rect.Height() - KOffset ) );
       
   235 	    }
       
   236 	else
       
   237 	    {
       
   238 	    iLayout = EPortrait;
       
   239 	    const TInt KOffset = 2;
       
   240 	    TInt oviButtonHeight = rect.Height() / 8;
       
   241 	    oviButtonRect.SetRect(
       
   242 	            TPoint( KOffset, KOffset ),
       
   243 	            TPoint( rect.Width() - KOffset, oviButtonHeight ) );
       
   244 	    widgetsListRect.SetRect(
       
   245 	            TPoint( 0, oviButtonHeight + KOffset ),
       
   246 	            TPoint( rect.Width(), rect.Height() ) );
       
   247 	    }
       
   248 
       
   249     // Apply layout to child controls
       
   250 	iOviPortal->SetRect( oviButtonRect );
       
   251 	iOviPortal->SetHighlightRect( oviButtonRect );
       
   252     iWidgetsList->SetRect( widgetsListRect );
       
   253     if( iFindbox && iFindPaneIsVisible )
       
   254         {
       
   255         // resizes listbox/searchfield
       
   256         HandleFindSizeChanged();
       
   257         }
       
   258 
       
   259     // change OVI portal button style
       
   260     if ( landscape )
       
   261         {
       
   262         // vertical style button
       
   263         iOviPortal->State()->SetTextL( KNullDesC() );
       
   264         TInt iconDimension = oviButtonRect.Width() * 2 / 3;
       
   265         iOviPortal->SetIconSize( TSize( iconDimension, iconDimension ) );
       
   266         iOviPortal->SetTextVerticalAlignment( 
       
   267                 CAknButton::ECenter );
       
   268         iOviPortal->SetTextAndIconAlignment(
       
   269                 CAknButton::EIconOverText );
       
   270         }
       
   271     else
       
   272         {
       
   273         // horizontal style button
       
   274         HBufC* oviText = StringLoader::LoadLC( R_QTN_WM_GO_TO_OVI_STORE );
       
   275         iOviPortal->State()->SetTextL( *oviText );
       
   276         CleanupStack::PopAndDestroy( oviText );
       
   277         TInt iconDimension = oviButtonRect.Height() * 2 / 3;
       
   278         iOviPortal->SetIconSize( TSize( iconDimension, iconDimension ) );
       
   279         iOviPortal->SetTextHorizontalAlignment( 
       
   280                 CGraphicsContext::ECenter );
       
   281         iOviPortal->SetTextAndIconAlignment(
       
   282                 CAknButton::EIconBeforeText );
       
   283         }
       
   284 
       
   285     DrawDeferred();
       
   286 	}
       
   287 
       
   288 // ---------------------------------------------------------
       
   289 // CWmMainContainer::OfferKeyEventL
       
   290 // ---------------------------------------------------------
       
   291 //
       
   292 TKeyResponse CWmMainContainer::OfferKeyEventL( 
       
   293 		const TKeyEvent& aKeyEvent, 
       
   294 		TEventCode aType )
       
   295 	{
       
   296     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   297     
       
   298     if ( iFindbox )
       
   299         {
       
   300         // open search field with alpha digit numbers
       
   301         if ( aType == EEventKeyDown && !iFindPaneIsVisible && 
       
   302         aKeyEvent.iScanCode < EStdKeyF1 &&
       
   303             TChar(aKeyEvent.iScanCode).IsAlphaDigit() )
       
   304             {
       
   305             ActivateFindPaneL();
       
   306             
       
   307             if ( iFindPaneIsVisible )
       
   308                 {
       
   309                 return EKeyWasConsumed;
       
   310                 }
       
   311             }
       
   312         
       
   313         if ( iFindPaneIsVisible )
       
   314             {
       
   315             // deactive the FindPane when Back has been pressed
       
   316             if ( aType == EEventKeyDown && 
       
   317                 aKeyEvent.iScanCode == EStdKeyBackspace )
       
   318                 {
       
   319                 TBuf<KTextLimit> searchText;
       
   320                 iFindbox->GetSearchText( searchText );
       
   321                 if ( searchText == KNullDesC )
       
   322                     {
       
   323                     DeactivateFindPaneL();
       
   324                     return EKeyWasConsumed;
       
   325                     }
       
   326                 }
       
   327             
       
   328             // Cancel-selected need to unfocus findbox 
       
   329             // to receive event in ProcessCommand
       
   330             if ( aType == EEventKeyDown 
       
   331             && aKeyEvent.iScanCode == EStdKeyDevice1 )
       
   332                 {
       
   333                 iFindbox->SetFocus( EFalse );
       
   334                 UpdateFocusMode();
       
   335                 return EKeyWasConsumed;
       
   336                 }
       
   337 
       
   338             if ( aKeyEvent.iScanCode == EStdKeyNo ||
       
   339                 aKeyEvent.iCode == EKeyNo )
       
   340                 {
       
   341                 DeactivateFindPaneL();
       
   342                 return EKeyWasConsumed;
       
   343                 }
       
   344 
       
   345             // find items with all event codes (that's the reason why there is EEventKey instead of aType)
       
   346             TBool needsRefresh( EFalse );
       
   347             keyResponse = AknFind::HandleFindOfferKeyEventL( 
       
   348                                                 aKeyEvent, EEventKey, this, 
       
   349                                 iWidgetsList, iFindbox, ETrue, needsRefresh );            
       
   350             if ( needsRefresh )
       
   351                 {
       
   352                 DrawNow();
       
   353                 }
       
   354             }
       
   355         }
       
   356 
       
   357     // check special cases for movement between controls
       
   358     if ( keyResponse == EKeyWasNotConsumed && !iFindPaneIsVisible )
       
   359          {
       
   360          keyResponse = MoveFocusByKeys( aKeyEvent, aType );
       
   361          }
       
   362 
       
   363     // pass key event except backpace or delete key event to widgets list if focused
       
   364     if ( keyResponse == EKeyWasNotConsumed && iWidgetsList->IsFocused() )
       
   365         {
       
   366         if ( (aType == EEventKey) && (aKeyEvent.iCode == EKeyBackspace || aKeyEvent.iCode == EKeyDelete))
       
   367             {
       
   368             if( CanDoUninstall() )
       
   369                 {
       
   370                 UninstallWidgetL();
       
   371                 }
       
   372             else
       
   373                 {
       
   374                 CWmWidgetData* data = iWidgetsList->WidgetData();
       
   375                 if( data != NULL )
       
   376                     iWmPlugin.ResourceLoader().InfoPopupL(
       
   377                          R_QTN_WM_UNINST_NOT_ALLOWED, data->Name() );
       
   378                 }
       
   379             }
       
   380         else 
       
   381             {
       
   382 			//passing to listbox handler
       
   383             keyResponse = iWidgetsList->OfferKeyEventL( 
       
   384                     aKeyEvent, aType );
       
   385             }
       
   386         }
       
   387 
       
   388     // pass key event to OVI portal if focused
       
   389     if ( keyResponse == EKeyWasNotConsumed && iOviPortal->IsFocused() )
       
   390         {
       
   391         keyResponse = iOviPortal->OfferKeyEventL( 
       
   392                             aKeyEvent, aType );
       
   393         }
       
   394 
       
   395     if ( keyResponse == EKeyWasConsumed )
       
   396         DrawDeferred();
       
   397 
       
   398 	// Do not let UI framework forward the keys to child controls as
       
   399 	// we have already done that.
       
   400     return EKeyWasConsumed;
       
   401 	}
       
   402 
       
   403 
       
   404 // ---------------------------------------------------------
       
   405 // CWmMainContainer::MoveFocusByKeys
       
   406 // ---------------------------------------------------------
       
   407 //
       
   408 TKeyResponse CWmMainContainer::MoveFocusByKeys(
       
   409                         const TKeyEvent& aKeyEvent, 
       
   410                         TEventCode aType )
       
   411     {
       
   412     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   413 
       
   414     if ( iWidgetsList->IsFocused() )
       
   415         {
       
   416         // ------------------------------------
       
   417         // focus is in the WIDGETS LIST
       
   418         // ------------------------------------
       
   419         if ( iLayout == EPortrait &&
       
   420                 aKeyEvent.iScanCode == EStdKeyUpArrow &&
       
   421                 iWidgetsList->CurrentItemIndex() == 0 )
       
   422             {
       
   423             // widget list top -> up -> ovi button (portrait)
       
   424             if ( aType == EEventKey )
       
   425                 SetFocusToOviButton();
       
   426             keyResponse = EKeyWasConsumed;
       
   427             }
       
   428         else if ( iLayout == EPortrait &&
       
   429                 aKeyEvent.iScanCode == EStdKeyDownArrow &&
       
   430                 iWidgetsList->CurrentItemIndex() ==
       
   431                    iWidgetsList->Model()->NumberOfItems() - 1 )
       
   432             {
       
   433             // widget list bottom -> down -> ovi button (portrait)
       
   434             if ( aType == EEventKey )
       
   435                 SetFocusToOviButton();
       
   436             keyResponse = EKeyWasConsumed;
       
   437             }
       
   438         else if ( iLayout == ELandscape &&
       
   439                 aKeyEvent.iScanCode == EStdKeyRightArrow )
       
   440             {
       
   441             // widget list -> right -> ovi button (landscape)
       
   442             if ( aType == EEventKey )
       
   443                 SetFocusToOviButton();
       
   444             keyResponse = EKeyWasConsumed;
       
   445             }
       
   446         else if ( iLayout == ELandscapeMirrored &&
       
   447                 aKeyEvent.iScanCode == EStdKeyLeftArrow )
       
   448             {
       
   449             // widget list -> left -> ovi button (landscape mirrored)
       
   450             if ( aType == EEventKey )
       
   451                 SetFocusToOviButton();
       
   452             keyResponse = EKeyWasConsumed;
       
   453             }
       
   454         }
       
   455     else if ( iOviPortal->IsFocused() )
       
   456         {
       
   457         // ------------------------------------
       
   458         // focus is in the OVI PORTAL BUTTON
       
   459         // ------------------------------------
       
   460         if ( iLayout == EPortrait &&
       
   461                 aKeyEvent.iScanCode == EStdKeyDownArrow )
       
   462             {
       
   463             // ovi button -> down -> widget list top (portrait)
       
   464             if ( aType == EEventKey )
       
   465                 SetFocusToWidgetList( 0 );
       
   466             keyResponse = EKeyWasConsumed;
       
   467             }
       
   468         else if ( iLayout == EPortrait &&
       
   469                 aKeyEvent.iScanCode == EStdKeyUpArrow )
       
   470             {
       
   471             // obi button -> up -> widget list bottom (portrait)
       
   472             if ( aType == EEventKey )
       
   473                 SetFocusToWidgetList( iWidgetsList->Model()->NumberOfItems()-1 );
       
   474             keyResponse = EKeyWasConsumed;
       
   475             }
       
   476         else if ( iLayout == ELandscape &&
       
   477                 aKeyEvent.iScanCode == EStdKeyLeftArrow )
       
   478             {
       
   479             // ovi button -> left -> widget list (landscape)
       
   480             if ( aType == EEventKey )
       
   481                 SetFocusToWidgetList();
       
   482             keyResponse = EKeyWasConsumed;
       
   483             }
       
   484         else if ( iLayout == ELandscapeMirrored &&
       
   485                 aKeyEvent.iScanCode == EStdKeyRightArrow )
       
   486             {
       
   487             // ovi button -> right -> widget list (landscape mirrored)
       
   488             if ( aType == EEventKey )
       
   489                 SetFocusToWidgetList();
       
   490             keyResponse = EKeyWasConsumed;
       
   491             }
       
   492         }
       
   493     else
       
   494         {
       
   495         // ------------------------------------
       
   496         // focus is NOWHERE
       
   497         // ------------------------------------
       
   498         if ( aKeyEvent.iScanCode == EStdKeyUpArrow ||
       
   499                 aKeyEvent.iScanCode == EStdKeyDownArrow ||
       
   500                 aKeyEvent.iScanCode == EStdKeyLeftArrow ||
       
   501                 aKeyEvent.iScanCode == EStdKeyRightArrow )
       
   502             {
       
   503             // no focus -> key hit -> focus list
       
   504             if ( aType == EEventKey )
       
   505                 SetFocusToWidgetList();
       
   506             keyResponse = EKeyWasConsumed;
       
   507             }
       
   508         }
       
   509 
       
   510     return keyResponse;
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------
       
   514 // CWmMainContainer::SetFocusToOviButton
       
   515 // ---------------------------------------------------------
       
   516 //
       
   517 void CWmMainContainer::SetFocusToOviButton()
       
   518     {
       
   519     iWidgetsList->SetFocus(EFalse);
       
   520     iOviPortal->SetFocus(ETrue);
       
   521     DrawDeferred();
       
   522     UpdateFocusMode();
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------
       
   526 // CWmMainContainer::SetFocusToWidgetList
       
   527 // ---------------------------------------------------------
       
   528 //
       
   529 void CWmMainContainer::SetFocusToWidgetList( TInt aIndex )
       
   530     {
       
   531     iOviPortal->SetFocus(EFalse);
       
   532     iWidgetsList->SetFocus(ETrue);
       
   533     if ( aIndex >= 0 && aIndex < iWidgetsList->Model()->NumberOfItems() )
       
   534         {
       
   535         iWidgetsList->SetCurrentItemIndex( aIndex );
       
   536         }
       
   537     DrawDeferred();
       
   538     UpdateFocusMode();
       
   539     }
       
   540 
       
   541 // ---------------------------------------------------------
       
   542 // CWmMainContainer::UpdateFocusMode
       
   543 // ---------------------------------------------------------
       
   544 //
       
   545 void CWmMainContainer::UpdateFocusMode()
       
   546     {
       
   547     if ( iOviPortal->IsFocused() )
       
   548         {
       
   549         // OVI BUTTON is focused 
       
   550         iFocusMode = EOvi;
       
   551         }
       
   552     else if( ( iFindPaneIsVisible ) && 
       
   553         ( iFindbox->IsFocused() || iWidgetsList->IsFocused() ) )
       
   554         {
       
   555         // FIND MODE
       
   556         iFocusMode = EFind;
       
   557         }
       
   558     else if ( iWidgetsList->IsFocused() )
       
   559         {
       
   560         // WIDGETS LIST is focused 
       
   561         iFocusMode = EList;
       
   562         }
       
   563     else
       
   564         {
       
   565         // NO focus
       
   566         iFocusMode = ENowhere;
       
   567         }
       
   568     }
       
   569 
       
   570 // ---------------------------------------------------------
       
   571 // CWmMainContainer::FindChildControlByPoint
       
   572 // ---------------------------------------------------------
       
   573 //
       
   574 CCoeControl* CWmMainContainer::FindChildControlByPoint(
       
   575         const TPoint& aPoint )
       
   576     {
       
   577     CCoeControl* theControl = NULL;
       
   578     CCoeControlArray::TCursor cursor = Components().Begin();
       
   579     CCoeControl* c;
       
   580     while((c=cursor.Control<CCoeControl>()) != NULL )
       
   581         {
       
   582         if(c->IsVisible())
       
   583             {
       
   584             if ( c->Rect().Contains( aPoint ) ) theControl = c;
       
   585             }
       
   586         cursor.Next();
       
   587         }
       
   588     return theControl;
       
   589     }
       
   590 
       
   591 // ---------------------------------------------------------
       
   592 // CWmMainContainer::HandlePointerEventL
       
   593 // ---------------------------------------------------------
       
   594 //
       
   595 void CWmMainContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   596     {
       
   597     if ( !iClosingDown  )
       
   598         {
       
   599 		
       
   600 		if (aPointerEvent.iType == TPointerEvent::EButton1Down)
       
   601 			{
       
   602 	        // Check if user clicked a child control
       
   603 	        CCoeControl* control = FindChildControlByPoint( aPointerEvent.iPosition );
       
   604 	        if ( control && !control->IsFocused() )
       
   605 	            {
       
   606 	            // Set focus to the control that was clicked
       
   607 	            control->SetFocus( ETrue );
       
   608 	            // remove focus from ALL other child controls.
       
   609 	            CCoeControlArray::TCursor cursor = Components().Begin();
       
   610 	            CCoeControl* c;
       
   611 	            while ((c=cursor.Control<CCoeControl>()) != NULL )
       
   612 	                {
       
   613 	                if ( c != control && c->IsFocused() ) c->SetFocus( EFalse );
       
   614 	                cursor.Next();
       
   615 	                }
       
   616 	            // update focus mode accordingly
       
   617 	            UpdateFocusMode();
       
   618 	            // repaint
       
   619 	            DrawDeferred();
       
   620 	            }
       
   621 			}
       
   622         
       
   623         CCoeControl::HandlePointerEventL( aPointerEvent );
       
   624         }
       
   625     }
       
   626 
       
   627 // ---------------------------------------------------------
       
   628 // CWmMainContainer::InitializeControlsL
       
   629 // ---------------------------------------------------------
       
   630 //
       
   631 void CWmMainContainer::InitializeControlsL( const TRect& /*aRect*/ )
       
   632 	{
       
   633 	// Create OVI STORE button
       
   634     iOviPortal = CAknButton::NewL();
       
   635     iWmPlugin.ResourceLoader().LoadButtonL( *iOviPortal,
       
   636             R_WM_PORTAL_BUTTON );
       
   637     iOviPortal->SetMopParent( this );
       
   638     iOviPortal->SetFocusing( ETrue );
       
   639     AddControlL( iOviPortal, EOviPortal );
       
   640     iOviPortal->SetContainerWindowL( *this );
       
   641 	// ToDo : replace 3-10 IID with real one when available (wk46)
       
   642 	iOviPortal->SetFrameAndCenterIds( 
       
   643 						KAknsIIDQgnHomeWmButton,
       
   644 						KAknsIIDQgnHomeWmButtonCenter,
       
   645 						KAknsIIDDefault,
       
   646 						KAknsIIDDefault,
       
   647 						KAknsIIDDefault,
       
   648 						KAknsIIDDefault,
       
   649 						KAknsIIDDefault,
       
   650 						KAknsIIDDefault,
       
   651 						KAknsIIDDefault,
       
   652 						KAknsIIDDefault );
       
   653     iOviPortal->ActivateL();
       
   654     iOviPortal->SetObserver( this );
       
   655 
       
   656     // Create widget list box
       
   657     iWidgetsList = CWmListBox::NewL(
       
   658             iWmPlugin,
       
   659             TRect(),
       
   660             iParent );
       
   661     iWidgetsList->SetMopParent( this );
       
   662     AddControlL( iWidgetsList, EWidgetsList );
       
   663 	iWidgetsList->ActivateL();
       
   664     iWidgetsList->SetListBoxObserver( this );
       
   665     
       
   666     // Create scroll bar.
       
   667     iWidgetsList->CreateScrollBarFrameL( ETrue );
       
   668     iWidgetsList->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   669         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   670     iWidgetsList->UpdateScrollBarsL(); 
       
   671     
       
   672     // search field
       
   673     iFindbox = CAknSearchField::NewL( *this,
       
   674                         CAknSearchField::EAdaptiveSearch,
       
   675                         0, KTextLimit );
       
   676     AddControlL( iFindbox, EFindBox );
       
   677 
       
   678     UpdateFocusMode();
       
   679     StartLoadingWidgetsL();
       
   680     }
       
   681 
       
   682 // ---------------------------------------------------------
       
   683 // CWmMainContainer::HandleWidgetListChanged
       
   684 // ---------------------------------------------------------
       
   685 //
       
   686 void CWmMainContainer::HandleWidgetListChanged()
       
   687     {
       
   688     TRAP_IGNORE( StartLoadingWidgetsL(); );
       
   689     }
       
   690 
       
   691 // ---------------------------------------------------------
       
   692 // CWmMainContainer::StartLoadingWidgetsL
       
   693 // ---------------------------------------------------------
       
   694 //
       
   695 void CWmMainContainer::StartLoadingWidgetsL()
       
   696     {
       
   697     if ( !iWidgetLoader )
       
   698         {
       
   699         // create the widget loader AO
       
   700         iWidgetLoader = CWmWidgetLoaderAo::NewL( iWmPlugin, *iWidgetsList );
       
   701         }
       
   702     iWidgetLoader->StartLoading();
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------
       
   706 // CWmMainContainer::HandleResourceChange
       
   707 // ---------------------------------------------------------
       
   708 //
       
   709 void CWmMainContainer::HandleResourceChange( TInt aType )
       
   710 	{
       
   711     CCoeControl::HandleResourceChange( aType );
       
   712 	
       
   713     if ( KEikDynamicLayoutVariantSwitch == aType )
       
   714         {
       
   715         TRect rect;
       
   716         AknLayoutUtils::LayoutMetricsRect( 
       
   717                             AknLayoutUtils::EMainPane, rect );
       
   718         SetRect( rect );
       
   719         
       
   720         // notify widgetlist
       
   721         iWidgetsList->HandleLayoutChanged();
       
   722         }
       
   723 	}
       
   724 
       
   725 
       
   726 // ---------------------------------------------------------
       
   727 // CWmMainContainer::MopSupplyObject
       
   728 // ---------------------------------------------------------
       
   729 //
       
   730 TTypeUid::Ptr CWmMainContainer::MopSupplyObject( TTypeUid aId )
       
   731     {
       
   732     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   733         {
       
   734         return MAknsControlContext::SupplyMopObject( 
       
   735                                             aId, iBgContext );
       
   736         }
       
   737     return CCoeControl::MopSupplyObject( aId );
       
   738     }
       
   739 
       
   740 // ---------------------------------------------------------
       
   741 // CWmMainContainer::Draw
       
   742 // ---------------------------------------------------------
       
   743 //
       
   744 void CWmMainContainer::Draw( const TRect& /*aRect*/ ) const
       
   745 	{
       
   746 	CWindowGc& gc = SystemGc();	
       
   747     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   748     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   749     AknsDrawUtils::Background( skin, cc, this, gc, Rect() );
       
   750 	}
       
   751 
       
   752 // ---------------------------------------------------------
       
   753 // CWmMainContainer::AddControlL
       
   754 // ---------------------------------------------------------
       
   755 //
       
   756 void CWmMainContainer::AddControlL( 
       
   757                                 CCoeControl* aControl, 
       
   758                                 TInt aControlId )
       
   759     {
       
   760     Components().AppendLC( aControl, aControlId ); // Ownership transfered 
       
   761     CleanupStack::Pop(aControl);    
       
   762     iWmPlugin.ViewAppUi().AddToStackL( aControl );
       
   763     aControl->MakeVisible( ETrue );
       
   764     }
       
   765 
       
   766 // ---------------------------------------------------------
       
   767 // CWmMainContainer::PortalSelected
       
   768 // ---------------------------------------------------------
       
   769 //
       
   770 TBool CWmMainContainer::PortalSelected()
       
   771     {    
       
   772     return ( iFocusMode == EOvi );
       
   773     }
       
   774 
       
   775 // ---------------------------------------------------------
       
   776 // CWmMainContainer::WidgetSelected
       
   777 // ---------------------------------------------------------
       
   778 //
       
   779 TBool CWmMainContainer::WidgetSelected() 
       
   780     {
       
   781     return ( iFocusMode == EList ) || ( iFocusMode == EFind );
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------
       
   785 // CWmMainContainer::CanDoAdd
       
   786 // ---------------------------------------------------------
       
   787 //
       
   788 TBool CWmMainContainer::CanDoAdd()
       
   789     {
       
   790     TBool retVal = EFalse;
       
   791     CWmWidgetData* data = iWidgetsList->WidgetData();
       
   792     if ( WidgetSelected() && data )
       
   793         {
       
   794         if ( data->HsContentInfo().CanBeAdded() )
       
   795             retVal = ETrue;
       
   796         }
       
   797     return retVal;
       
   798     }
       
   799 
       
   800 // ---------------------------------------------------------
       
   801 // CWmMainContainer::CanDoUninstall
       
   802 // ---------------------------------------------------------
       
   803 //
       
   804 TBool CWmMainContainer::CanDoUninstall() 
       
   805     {
       
   806     TBool retVal( EFalse );
       
   807     CWmWidgetData* data = iWidgetsList->WidgetData();
       
   808     if ( WidgetSelected() && data )
       
   809         {
       
   810         if ( data->WidgetType() == CWmWidgetData::ECps &&
       
   811                 data->PublisherUid() != KNullUid )
       
   812             {
       
   813             retVal = ETrue;
       
   814             }
       
   815         }
       
   816     return retVal;
       
   817     }
       
   818 
       
   819 // ---------------------------------------------------------
       
   820 // CWmMainContainer::CanDoLaunch
       
   821 // ---------------------------------------------------------
       
   822 //
       
   823 TBool CWmMainContainer::CanDoLaunch() 
       
   824     {
       
   825     TBool retVal(EFalse);
       
   826     if ( WidgetSelected() )
       
   827         {
       
   828         CWmWidgetData* data = iWidgetsList->WidgetData();        
       
   829         if ( data->WidgetType() == CWmWidgetData::ECps &&
       
   830             data->PublisherUid() != KNullUid )
       
   831             {
       
   832             retVal = ETrue;
       
   833             }
       
   834         }
       
   835     return retVal;
       
   836     }
       
   837 
       
   838 // ---------------------------------------------------------
       
   839 // CWmMainContainer::CanDoFind
       
   840 // ---------------------------------------------------------
       
   841 //
       
   842 TBool CWmMainContainer::CanDoFind()
       
   843     {
       
   844     TBool canDo( !iFindPaneIsVisible );
       
   845     if ( canDo )
       
   846         {
       
   847         canDo = ( iFocusMode == EList || iFocusMode == ENowhere );
       
   848         }
       
   849     return canDo;
       
   850     }
       
   851 
       
   852 // ---------------------------------------------------------
       
   853 // CWmMainContainer::CanDoSort
       
   854 // ---------------------------------------------------------
       
   855 //
       
   856 TBool CWmMainContainer::CanDoSort()
       
   857     {
       
   858     return !iFindPaneIsVisible;
       
   859     }
       
   860 
       
   861 // ---------------------------------------------------------
       
   862 // CWmMainContainer::CanDoDetails
       
   863 // ---------------------------------------------------------
       
   864 //
       
   865 TBool CWmMainContainer::CanDoDetails()
       
   866     {
       
   867     return WidgetSelected();
       
   868     }
       
   869 
       
   870 // ---------------------------------------------------------
       
   871 // CWmMainContainer::CanDoHelp
       
   872 // ---------------------------------------------------------
       
   873 //
       
   874 TBool CWmMainContainer::CanDoHelp()
       
   875     {
       
   876     return FeatureManager::FeatureSupported( KFeatureIdHelp );
       
   877     }
       
   878 
       
   879 // ---------------------------------------------------------------------------
       
   880 // CWmMainContainer::AddWidgetToHomeScreenL
       
   881 // ---------------------------------------------------------------------------
       
   882 //
       
   883 void CWmMainContainer::AddWidgetToHomeScreenL()
       
   884     {
       
   885     CWmWidgetData* data = iWidgetsList->WidgetData();
       
   886     if ( data )
       
   887         {
       
   888         if ( iFindbox && iFindPaneIsVisible )
       
   889             {
       
   890             DeactivateFindPaneL();
       
   891             }
       
   892 
       
   893         SetExitStatus( iWmPlugin.ContentController().AddWidgetL(
       
   894             data->HsContentInfo() ) );
       
   895         
       
   896         iWmPlugin.Deactivate();
       
   897         }
       
   898 
       
   899     }
       
   900 
       
   901 // ---------------------------------------------------------------------------
       
   902 // CWmMainContainer::SetExitStatus
       
   903 // ---------------------------------------------------------------------------
       
   904 //
       
   905 void CWmMainContainer::SetExitStatus( TInt aExitStatus )
       
   906     {
       
   907     iExitStatus = aExitStatus;
       
   908     }
       
   909 
       
   910 // ---------------------------------------------------------------------------
       
   911 // CWmMainContainer::ExitStatus
       
   912 // ---------------------------------------------------------------------------
       
   913 //
       
   914 TInt CWmMainContainer::ExitStatus( )
       
   915     {
       
   916     return iExitStatus;
       
   917     }
       
   918 	
       
   919 // ---------------------------------------------------------------------------
       
   920 // CWmMainContainer::LaunchWidgetL
       
   921 // ---------------------------------------------------------------------------
       
   922 //
       
   923 void CWmMainContainer::LaunchWidgetL()
       
   924     {
       
   925     if ( CanDoLaunch() )
       
   926         {
       
   927         CWmWidgetData* data = iWidgetsList->WidgetData();
       
   928         
       
   929         HBufC* param = KNullDesC().AllocLC(); // launch params
       
   930         
       
   931         RApaLsSession appArc;
       
   932         User::LeaveIfError( appArc.Connect() ); // connect to AppArc server
       
   933         CleanupClosePushL( appArc );
       
   934         TThreadId id;
       
   935         User::LeaveIfError( appArc.StartDocument(
       
   936             *param, data->PublisherUid(), id ) );
       
   937     
       
   938         CleanupStack::PopAndDestroy( &appArc );      
       
   939         CleanupStack::PopAndDestroy( param );
       
   940         }
       
   941     }
       
   942 
       
   943 // ---------------------------------------------------------------------------
       
   944 // CWmMainContainer::ActivateFindPaneL
       
   945 // ---------------------------------------------------------------------------
       
   946 //
       
   947 void CWmMainContainer::ActivateFindPaneL()
       
   948     {
       
   949     if ( iFindbox && !iFindPaneIsVisible &&
       
   950             iWidgetsList->Model()->NumberOfItems() > KMinWidgets )
       
   951         {
       
   952 		// enable filtering
       
   953         CAknFilteredTextListBoxModel* m = 
       
   954                 static_cast <CAknFilteredTextListBoxModel*> ( iWidgetsList->Model() );
       
   955         if ( m )
       
   956             {
       
   957             m->CreateFilterL( iWidgetsList, iFindbox );
       
   958             if ( m->Filter() )
       
   959                 {
       
   960                 m->Filter()->SetParentControl( this );
       
   961                 }
       
   962             }
       
   963 
       
   964         iFindbox->ActivateL();
       
   965         iFindbox->ResetL();
       
   966         iFindbox->SetSearchTextL( KNullDesC );
       
   967         iFindbox->SetSkinEnabledL( ETrue );
       
   968 
       
   969         iFindPaneIsVisible = ETrue;
       
   970         iFindbox->MakeVisible( ETrue );
       
   971         
       
   972         // layout listbox and findbox
       
   973         LayoutControlsL();        
       
   974         
       
   975         iFindbox->SetFocus( ETrue );
       
   976         iWidgetsList->SetFindPaneIsVisible( ETrue );
       
   977 
       
   978         // set soft key set
       
   979         CEikButtonGroupContainer* cbaGroup =
       
   980             CEikButtonGroupContainer::Current();
       
   981         cbaGroup->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_CANCEL__SELECT );
       
   982         cbaGroup->DrawNow();
       
   983 
       
   984         UpdateFocusMode();
       
   985         }
       
   986     }
       
   987 
       
   988 // ---------------------------------------------------------------------------
       
   989 // CWmMainContainer::DeactivateFindPaneL
       
   990 // ---------------------------------------------------------------------------
       
   991 //
       
   992 void CWmMainContainer::DeactivateFindPaneL()
       
   993     {
       
   994     if( iFindbox && iFindPaneIsVisible )
       
   995 	    {
       
   996         // notify search field we're shutting down
       
   997         TKeyEvent keyEvent = { EKeyNo, EStdKeyNo, 0, 0  };
       
   998         iFindbox->OfferKeyEventL( keyEvent, EEventKey );
       
   999         
       
  1000         // reset findbox
       
  1001         iFindbox->ResetL();
       
  1002 
       
  1003         // reset filter
       
  1004         CAknFilteredTextListBoxModel* m = 
       
  1005                 static_cast <CAknFilteredTextListBoxModel*> ( iWidgetsList->Model() );
       
  1006         if ( m && m->Filter() )
       
  1007             {
       
  1008             m->Filter()->ResetFilteringL();
       
  1009             m->RemoveFilter();
       
  1010             }
       
  1011 
       
  1012         iFindbox->MakeVisible( EFalse );
       
  1013         iFindbox->SetFocus( EFalse );
       
  1014         iFindPaneIsVisible = EFalse;
       
  1015         iWidgetsList->SetFindPaneIsVisible( EFalse );
       
  1016         
       
  1017         LayoutControlsL();
       
  1018         iWidgetsList->SetFocus( ETrue );
       
  1019 
       
  1020         // set soft key set
       
  1021         CEikButtonGroupContainer* cbaGroup =
       
  1022             CEikButtonGroupContainer::Current();
       
  1023         cbaGroup->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK__SELECT );
       
  1024         cbaGroup->DrawNow();
       
  1025 
       
  1026         UpdateFocusMode();
       
  1027         DrawNow();
       
  1028         }
       
  1029     }
       
  1030 
       
  1031 // ---------------------------------------------------------------------------
       
  1032 // CWmMainContainer::SortListAlphabeticallyL
       
  1033 // ---------------------------------------------------------------------------
       
  1034 //
       
  1035 void CWmMainContainer::SortListAlphabeticallyL()
       
  1036     {
       
  1037     if ( iWidgetsList )
       
  1038         {
       
  1039         iWidgetsList->SetSortOrderL( CWmListBox::EAlphabetical );
       
  1040        
       
  1041         //store changed list order
       
  1042         CWmPersistentWidgetOrder* widgetOrder =
       
  1043             CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() );
       
  1044         CleanupStack::PushL( widgetOrder );
       
  1045         widgetOrder->StoreL( iWidgetsList->WidgetDataArray() );
       
  1046         CleanupStack::PopAndDestroy( widgetOrder );
       
  1047 
       
  1048         }
       
  1049     }
       
  1050 
       
  1051 // ---------------------------------------------------------------------------
       
  1052 // CWmMainContainer::UninstallWidgetL
       
  1053 // ---------------------------------------------------------------------------
       
  1054 //
       
  1055 void CWmMainContainer::UninstallWidgetL()
       
  1056     {
       
  1057     if ( CanDoUninstall() )
       
  1058         {
       
  1059         CWmWidgetData* data = iWidgetsList->WidgetData();
       
  1060         
       
  1061         SwiUI::RSWInstLauncher installer;
       
  1062         User::LeaveIfError( installer.Connect() );
       
  1063         
       
  1064         installer.Uninstall( data->PublisherUid(), KWrtMime );
       
  1065         installer.Close();
       
  1066         }
       
  1067     }
       
  1068 
       
  1069 // ---------------------------------------------------------------------------
       
  1070 // CWmMainContainer::OpenOviPortalL
       
  1071 // ---------------------------------------------------------------------------
       
  1072 //
       
  1073 void CWmMainContainer::OpenOviPortalL()
       
  1074     {
       
  1075     _LIT( KParam, "{\"Parameters\": {\"cmd\": \"channel\", \"id\": \"tag:mosh.nokia.com,2009-04:atom/2.0/channels/10\" }}" );
       
  1076     _LIT( KHtmlFile, "C:\\private\\102829a0\\com.nokia.ovi.juniper.WRTClient\\Juniper\\Main.html" );
       
  1077     _LIT( KFileName, "securewidgetui.exe" );
       
  1078     _LIT( KUrl, "4 https://store.ovi.com/applications/");
       
  1079     
       
  1080     RApaLsSession appArcSession;
       
  1081     User::LeaveIfError( appArcSession.Connect() );
       
  1082     CleanupClosePushL( appArcSession );
       
  1083     
       
  1084     HBufC* param = HBufC::NewLC( KParam().Length() );
       
  1085     param->Des().Copy(KParam);
       
  1086     
       
  1087     TThreadId id;
       
  1088     CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); 
       
  1089     cmdLine->SetCommandL( EApaCommandOpen ); 
       
  1090     cmdLine->SetExecutableNameL( KFileName );
       
  1091     cmdLine->SetDocumentNameL( KHtmlFile );
       
  1092     HBufC8* buf8 = HBufC8::NewLC( param->Des().Length() );
       
  1093     buf8->Des().Copy( *param );
       
  1094     cmdLine->SetOpaqueDataL( *buf8 );
       
  1095     cmdLine->SetTailEndL( *buf8 );
       
  1096     
       
  1097     TInt err = appArcSession.StartApp( *cmdLine, id );
       
  1098     if ( err == KErrNone )
       
  1099         {
       
  1100         _LIT( KSchemeTemplate, "ecwrtservices:command=launch&app=com.nokia.ovi.juniper.WRTClient&commandLine=");
       
  1101         const TInt KSecureWidgetWebAppSchemeHandlerUid = 0x102829B2;
       
  1102         
       
  1103         // Create scheme url to launch the widget
       
  1104         HBufC* schemeUrl = HBufC::NewLC( KSchemeTemplate().Length() + 
       
  1105                 param->Des().Length() );
       
  1106         
       
  1107         schemeUrl->Des().Copy( KSchemeTemplate );
       
  1108         schemeUrl->Des().Append( *param );
       
  1109         
       
  1110         // Initialize scheme handler plugin
       
  1111         TUid dtorId;
       
  1112         CSchemeHandler* schemeHandler = reinterpret_cast<CSchemeHandler*>(
       
  1113                     REComSession::CreateImplementationL( 
       
  1114                             TUid::Uid( KSecureWidgetWebAppSchemeHandlerUid ), 
       
  1115                             dtorId, schemeUrl ) );
       
  1116         CleanupStack::PushL( schemeHandler );
       
  1117         
       
  1118         // Handle the scheme url
       
  1119         schemeHandler->HandleUrlEmbeddedL();
       
  1120         
       
  1121         CleanupStack::PopAndDestroy( schemeHandler );
       
  1122         REComSession::FinalClose();
       
  1123         CleanupStack::PopAndDestroy( schemeUrl );     
       
  1124         }
       
  1125     else
       
  1126         {
       
  1127         // Ovi store not found start browser
       
  1128         const TUid KOSSBrowserUidValue = { 0x10008D39 };
       
  1129         HBufC* param = HBufC::NewLC( KUrl().Length() );
       
  1130         param->Des().Copy( KUrl );
       
  1131         TUid id( KOSSBrowserUidValue );
       
  1132         
       
  1133         TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
  1134         TApaTask task = taskList.FindApp(id);
       
  1135         if( task.Exists() )
       
  1136             {
       
  1137             task.BringToForeground();
       
  1138             HBufC8* param8 = HBufC8::NewLC(param->Length());
       
  1139             param8->Des().Append(*param);
       
  1140             task.SendMessage(TUid::Uid(0), *param8); // UID not used
       
  1141             CleanupStack::PopAndDestroy(param8);
       
  1142             }
       
  1143         else
       
  1144             {
       
  1145             if( !appArcSession.Handle() )
       
  1146                 {
       
  1147                 User::LeaveIfError( appArcSession.Connect() );
       
  1148                 }
       
  1149             TThreadId thread;
       
  1150             User::LeaveIfError(appArcSession.StartDocument(*param, KOSSBrowserUidValue, thread));
       
  1151             appArcSession.Close();   
       
  1152             }
       
  1153         CleanupStack::PopAndDestroy( param );
       
  1154         }
       
  1155     
       
  1156     CleanupStack::PopAndDestroy( buf8 );
       
  1157     CleanupStack::PopAndDestroy( cmdLine );
       
  1158     CleanupStack::PopAndDestroy( param );
       
  1159     CleanupStack::PopAndDestroy( &appArcSession );
       
  1160 
       
  1161     // unfocus OVI button
       
  1162 	iOviPortal->SetFocus( EFalse );
       
  1163 	iOviPortal->DrawDeferred();
       
  1164     UpdateFocusMode();
       
  1165     }
       
  1166 
       
  1167 // ---------------------------------------------------------------------------
       
  1168 // CWmMainContainer::SelectL
       
  1169 // ---------------------------------------------------------------------------
       
  1170 //
       
  1171 void CWmMainContainer::SelectL()
       
  1172     {
       
  1173     if ( WidgetSelected() )
       
  1174         AddWidgetToHomeScreenL();
       
  1175     else if ( PortalSelected() )
       
  1176         OpenOviPortalL();
       
  1177     else
       
  1178         SetFocusToWidgetList();
       
  1179     }
       
  1180 
       
  1181 // ---------------------------------------------------------------------------
       
  1182 // CWmMainContainer::ShowHelpL
       
  1183 // ---------------------------------------------------------------------------
       
  1184 //
       
  1185 void CWmMainContainer::ShowHelpL()
       
  1186     {
       
  1187     TUid fwUid = TUid::Uid( AI_UID3_AIFW_COMMON );
       
  1188     // retrieve resolve host application help context
       
  1189     CArrayFix<TCoeHelpContext>* helpContext =
       
  1190         iEikonEnv->EikAppUi()->AppHelpContextL();
       
  1191 
       
  1192     // add the widget manager entry into the help context
       
  1193     CleanupStack::PushL( helpContext );
       
  1194     helpContext->InsertL( 0, TCoeHelpContext(
       
  1195             fwUid, KWM_HLP_WIDGET_COLLECTION ) );
       
  1196     CleanupStack::Pop( helpContext );
       
  1197 
       
  1198     // launch help
       
  1199     HlpLauncher::LaunchHelpApplicationL(
       
  1200           iEikonEnv->WsSession(),
       
  1201           helpContext );
       
  1202     helpContext = 0; // HlpLauncher takes ownership of helpContext
       
  1203     }
       
  1204 
       
  1205 // ---------------------------------------------------------------------------
       
  1206 // CWmMainContainer::RemoveCtrlsFromStack
       
  1207 // ---------------------------------------------------------------------------
       
  1208 //
       
  1209 void CWmMainContainer::RemoveCtrlsFromStack()
       
  1210     {    
       
  1211     for ( TInt i=0; i < CountComponentControls(); i++ ) 
       
  1212         {
       
  1213         CCoeControl* ctl = ComponentControl( i ) ;
       
  1214         if ( ctl )
       
  1215             {
       
  1216             iWmPlugin.ViewAppUi().RemoveFromStack( ctl );
       
  1217             }
       
  1218         }
       
  1219     }
       
  1220 
       
  1221 // ---------------------------------------------------------------------------
       
  1222 // CWmMainContainer::HandleListBoxEventL
       
  1223 // ---------------------------------------------------------------------------
       
  1224 //
       
  1225 void CWmMainContainer::HandleListBoxEventL(
       
  1226         CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
  1227     {
       
  1228     if ( !iClosingDown && ( aEventType == EEventEnterKeyPressed ||
       
  1229             aEventType == EEventItemSingleClicked ) )
       
  1230         {
       
  1231         AddWidgetToHomeScreenL();
       
  1232         }
       
  1233     }
       
  1234 
       
  1235 // ---------------------------------------------------------------------------
       
  1236 // CWmMainContainer::HandleControlEventL
       
  1237 // ---------------------------------------------------------------------------
       
  1238 //
       
  1239 void CWmMainContainer::HandleControlEventL(
       
  1240         CCoeControl* aControl, TCoeEvent aEventType )
       
  1241     {
       
  1242     if ( !iClosingDown && aControl == iOviPortal && aEventType == EEventStateChanged )
       
  1243         {
       
  1244         OpenOviPortalL();
       
  1245         }
       
  1246     }
       
  1247 
       
  1248 // ----------------------------------------------------
       
  1249 // CWmMainContainer::LaunchDetailsDialogL
       
  1250 // ----------------------------------------------------
       
  1251 //
       
  1252 void CWmMainContainer::LaunchDetailsDialogL()
       
  1253     {
       
  1254     CWmWidgetData* data = iWidgetsList->WidgetData();
       
  1255     if ( data )
       
  1256         {
       
  1257         const CFbsBitmap* logo = ( data->LogoImage() ) ? 
       
  1258                     data->LogoImage() : iWidgetsList->DefaultLogo();
       
  1259         const CFbsBitmap* mask = ( data->LogoImageMask() ) ? 
       
  1260                     data->LogoImageMask() : iWidgetsList->DefaultMask();
       
  1261         
       
  1262         TPtrC description = ( data->Description().Length() > 0 ) ? 
       
  1263             data->Description() : iWmPlugin.ResourceLoader().NoDescriptionText();
       
  1264         CWmDetailsDlg* dlg = CWmDetailsDlg::NewL(
       
  1265                 data->Name(), description, 
       
  1266                 data->HsContentInfo().CanBeAdded(),
       
  1267                 logo, mask, iBgContext );
       
  1268 
       
  1269         if ( dlg && dlg->ExecuteLD() == ECbaAddToHs )
       
  1270             {
       
  1271             AddWidgetToHomeScreenL();
       
  1272             }
       
  1273         }
       
  1274     }
       
  1275 
       
  1276 // ----------------------------------------------------
       
  1277 // CWmMainContainer::SetClosingDown
       
  1278 // ----------------------------------------------------
       
  1279 //
       
  1280 void CWmMainContainer::SetClosingDown( TBool aClosingDown )
       
  1281     {
       
  1282     iClosingDown = aClosingDown;
       
  1283     }
       
  1284 
       
  1285 // ----------------------------------------------------
       
  1286 // CWmMainContainer::ClosingDown
       
  1287 // ----------------------------------------------------
       
  1288 //
       
  1289 TBool CWmMainContainer::ClosingDown()
       
  1290     {
       
  1291     return iClosingDown;
       
  1292     }
       
  1293 
       
  1294 // ----------------------------------------------------
       
  1295 // CWmMainContainer::HandleFindSizeChanged
       
  1296 // ----------------------------------------------------
       
  1297 //
       
  1298 void CWmMainContainer::HandleFindSizeChanged()
       
  1299     {    
       
  1300     TAknWindowLineLayout findPane = 
       
  1301             AknLayoutScalable_Avkon::find_pane().LayoutLine();
       
  1302 
       
  1303     TAknWindowLineLayout listPane;
       
  1304 
       
  1305     TRect listRect = iWidgetsList->Rect();
       
  1306     listPane.il = listRect.iTl.iX;
       
  1307     listPane.it = listRect.iTl.iY;
       
  1308     listPane.ib = 0;
       
  1309     listPane.iH = TUint16( listRect.Height() - ( findPane.iH - 1 ) );
       
  1310     listPane.iW = listRect.Width();
       
  1311     listPane.ir = ELayoutEmpty;
       
  1312     findPane.iW = listPane.iW;
       
  1313 
       
  1314     TRect rect = Rect();
       
  1315     AknLayoutUtils::LayoutControl( iFindbox, rect, findPane );
       
  1316     AknLayoutUtils::LayoutControl( iWidgetsList, rect, listPane );
       
  1317     
       
  1318     iWidgetsList->DrawNow();
       
  1319     }
       
  1320 
       
  1321 
       
  1322 // End of File
       
  1323