launcher/src/launchercontainerapps.cpp
branchRCL_3
changeset 22 fad26422216a
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
       
     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 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "launchercontainerapps.h"
       
    21 #include "launcherengine.h"
       
    22 
       
    23 
       
    24 #include <eikclb.h>
       
    25 #include <eikclbd.h>
       
    26 #include <aknconsts.h>
       
    27 #include <AknUtils.h>
       
    28 #include <aknnotewrappers.h>
       
    29 #include <AknIconArray.h> 
       
    30 #include <f32file.h>
       
    31 #include <avkon.mbg>
       
    32 #include <AknIconUtils.h>
       
    33 #include <AknDef.h>
       
    34 
       
    35 
       
    36 _LIT(KTab,"\t");
       
    37 
       
    38 
       
    39 // ================= MEMBER FUNCTIONS =======================
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CLauncherContainerApps::ConstructL(const TRect& aRect)
       
    43 // EPOC two phased constructor
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 void CLauncherContainerApps::ConstructL(const TRect& aRect, CLauncherEngine* aEngine)
       
    47     {
       
    48     iEngine = aEngine;
       
    49 
       
    50     CreateWindowL();
       
    51     Window().SetShadowDisabled(EFalse);
       
    52     SetRect(aRect);
       
    53 
       
    54     iListBox = new(ELeave) CAknSingleStyleListBox;
       
    55     iListBox->SetContainerWindowL(*this);
       
    56     iListBox->ConstructL(this, EAknListBoxMarkableList);
       
    57     iListBox->View()->SetListEmptyTextL(_L("No apps found"));
       
    58 
       
    59     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
       
    60 
       
    61     CAknIconArray* iconArray = new(ELeave) CAknIconArray(1);
       
    62     CleanupStack::PushL(iconArray);
       
    63     CFbsBitmap* markBitmap = NULL;
       
    64     CFbsBitmap* markBitmapMask = NULL;
       
    65     
       
    66     TRgb defaultColor;
       
    67     defaultColor = CEikonEnv::Static()->Color(EColorControlText);
       
    68 
       
    69     AknsUtils::CreateColorIconL(AknsUtils::SkinInstance(),
       
    70             KAknsIIDQgnIndiMarkedAdd,
       
    71             KAknsIIDQsnIconColors,
       
    72             EAknsCIQsnIconColorsCG13,
       
    73             markBitmap,
       
    74             markBitmapMask,
       
    75             AknIconUtils::AvkonIconFileName(),
       
    76             EMbmAvkonQgn_indi_marked_add,
       
    77             EMbmAvkonQgn_indi_marked_add_mask,
       
    78             defaultColor
       
    79             );
       
    80      
       
    81     CGulIcon* markIcon = CGulIcon::NewL(markBitmap,markBitmapMask);
       
    82     iconArray->AppendL(markIcon);                       
       
    83     CleanupStack::Pop(); // iconArray
       
    84 
       
    85     iListBox->ItemDrawer()->ColumnData()->SetIconArray(iconArray);
       
    86 
       
    87     iListBox->CreateScrollBarFrameL(ETrue);
       
    88     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
    89     iListBox->SetListBoxObserver(this);
       
    90     
       
    91     // set size of the listbox
       
    92     TSize outputRectSize;
       
    93     AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, outputRectSize);
       
    94     TRect outputRect(outputRectSize);
       
    95     iListBox->SetRect(outputRect);
       
    96 
       
    97 
       
    98     iListBox->ActivateL();
       
    99    
       
   100     //ActivateL();  
       
   101     }
       
   102 
       
   103 // Destructor
       
   104 CLauncherContainerApps::~CLauncherContainerApps()
       
   105     {
       
   106     delete iListBox;
       
   107     iListBox = NULL;
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 
       
   112 const CArrayFix<TInt>* CLauncherContainerApps::SelectedApps()
       
   113     {
       
   114     const CListBoxView::CSelectionIndexArray* indices = iListBox->SelectionIndexes();
       
   115     
       
   116     return static_cast<const CArrayFix<TInt>*>(indices);
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 
       
   121 void CLauncherContainerApps::UpdateFileListL()
       
   122     {
       
   123     // get list of all apps from the engine
       
   124 	CDesCArray* appFullPathsArray = iEngine->ListOfAllAppsL();
       
   125 		
       
   126     // get an instance of the listbox's item array
       
   127 	MDesCArray* tempArray = iListBox->Model()->ItemTextArray();
       
   128 	CDesCArray* listBoxArray = (CDesCArray*)tempArray;
       
   129 	listBoxArray->Reset();
       
   130 
       
   131 	for ( TInt i=0; i<appFullPathsArray->Count(); i++)
       
   132 	    {
       
   133         // parse the filename
       
   134         TParse nameParser;
       
   135         TInt err = nameParser.SetNoWild((*appFullPathsArray)[i], NULL, NULL);
       
   136         
       
   137         if (!err)
       
   138 		    {
       
   139             TFileName name;
       
   140             name.Copy(KTab);
       
   141             name.Append(nameParser.Drive());
       
   142             name.Append(nameParser.NameAndExt());
       
   143             name.Append(KTab);
       
   144             name.Append(KTab);
       
   145 
       
   146 		    listBoxArray->AppendL( name );
       
   147             }
       
   148         else
       
   149             {
       
   150 		    listBoxArray->AppendL( _L("\t*invalid file*\t\t") );
       
   151             }
       
   152         }
       
   153 
       
   154     // updates the listbox
       
   155     iListBox->HandleItemAdditionL();
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CLauncherContainerApps::SizeChanged()
       
   160 // Called by framework when the view size is changed
       
   161 // ---------------------------------------------------------
       
   162 //
       
   163 void CLauncherContainerApps::SizeChanged()
       
   164 {
       
   165     TSize outputRectSize;
       
   166     AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, outputRectSize);
       
   167     TRect outputRect(outputRectSize);
       
   168     
       
   169     if (iListBox)
       
   170         iListBox->SetRect(outputRect);
       
   171 }
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CLauncherContainerApps::CountComponentControls() const
       
   176 // ---------------------------------------------------------
       
   177 //
       
   178 TInt CLauncherContainerApps::CountComponentControls() const
       
   179     {
       
   180     return 1; // return nbr of controls inside this container
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // CLauncherContainerApps::ComponentControl(TInt aIndex) const
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 CCoeControl* CLauncherContainerApps::ComponentControl(TInt /*aIndex*/) const
       
   188     {
       
   189     return iListBox;
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------
       
   193 // CBCAppMainContainer::Draw(const TRect& aRect) const
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 void CLauncherContainerApps::Draw(const TRect& aRect) const
       
   197     {
       
   198     CWindowGc& gc = SystemGc();
       
   199     gc.Clear(aRect);
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CLauncherContainerApps::HandleControlEventL(
       
   204 //     CCoeControl* aControl,TCoeEvent aEventType)
       
   205 // ---------------------------------------------------------
       
   206 //
       
   207 void CLauncherContainerApps::HandleControlEventL(
       
   208     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   209     {
       
   210     }
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------
       
   214 // CLauncherContainerApps::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   215 //                                    TEventCode aType)
       
   216 // Handle key event. Only up and down key arrow events are
       
   217 // consumed in order to enable scrolling in output window.
       
   218 // ---------------------------------------------------------
       
   219 //
       
   220 TKeyResponse CLauncherContainerApps::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   221     {
       
   222     if(aType != EEventKey)
       
   223         return EKeyWasNotConsumed;
       
   224 
       
   225     // handle OK key
       
   226     if (aKeyEvent.iCode == EKeyOK)
       
   227         {
       
   228         if (iListBox->View()->ItemIsSelected(iListBox->CurrentItemIndex()))
       
   229             {
       
   230             AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdUnmark, iListBox );
       
   231             }
       
   232         else
       
   233             {
       
   234             AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdMark, iListBox );
       
   235             }
       
   236 
       
   237         return EKeyWasNotConsumed;
       
   238         }
       
   239     
       
   240     // left and right keys are needed by other class
       
   241     else if (aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow)
       
   242         return EKeyWasNotConsumed;
       
   243 
       
   244     else
       
   245         return iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------
       
   249 
       
   250 void CLauncherContainerApps::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
   251     {
       
   252     switch (aEventType)
       
   253         {
       
   254         case EEventEnterKeyPressed:
       
   255         case EEventItemDoubleClicked:
       
   256             {
       
   257             if (iListBox->View()->ItemIsSelected(iListBox->CurrentItemIndex()))
       
   258                 {
       
   259                 AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdUnmark, iListBox );
       
   260                 }
       
   261             else
       
   262                 {
       
   263                 AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdMark, iListBox );
       
   264                 }            
       
   265             }
       
   266             break;
       
   267         default:
       
   268             break;
       
   269         }
       
   270     }
       
   271     
       
   272 // ---------------------------------------------------------
       
   273 //
       
   274 
       
   275 void CLauncherContainerApps::HandleResourceChange(TInt aType)
       
   276     {
       
   277     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   278         {
       
   279         TRect mainPaneRect;
       
   280         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   281         SetRect(mainPaneRect);
       
   282 
       
   283         TSize outputRectSize;
       
   284         AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, outputRectSize);
       
   285         TRect outputRect(outputRectSize);
       
   286         iListBox->SetRect(outputRect);
       
   287         }
       
   288     else
       
   289         {
       
   290         CCoeControl::HandleResourceChange(aType);
       
   291         }
       
   292     }
       
   293 
       
   294 
       
   295 // End of File