stifui/stifui/src/TestSetMenuContainer.cpp
branchRCL_3
changeset 9 404ad6c9bc20
parent 8 87e9ebfbe96a
child 11 454d022d514b
equal deleted inserted replaced
8:87e9ebfbe96a 9:404ad6c9bc20
     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: This file contains CTestSetMenuContainer class 
       
    15 * definition.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknlists.h>  // ListBox
       
    21 #include <AknIconArray.h> // CAknIconArray
       
    22 #include <aknnotewrappers.h>
       
    23 
       
    24 #include <eikclbd.h> // CColumnListBoxData
       
    25 
       
    26 #include "TestSetMenuContainer.h"
       
    27 #include "TestSetMenuView.h"
       
    28 #include "StartCasesContainer.h"
       
    29 #include <Stifui.rsg>
       
    30 #include "Stifui.hrh"
       
    31 #include "AppUIAppUi.h"
       
    32 
       
    33 #include "MenuListBox.h"
       
    34 
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 // ----------------------------------------------------------------------------
       
    38 // CTestSetMenuContainer::ConstructL
       
    39 // 
       
    40 // Symbian OS two phased constructor.
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 void CTestSetMenuContainer::ConstructL(const TRect& aRect, MEikListBoxObserver* aListBoxObserver)
       
    44     {
       
    45     ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("TestSetMenuContainer: ConstructL"));
       
    46 
       
    47 	iParentView = (CTestSetMenuView*)aListBoxObserver;
       
    48     CreateWindowL();
       
    49 
       
    50     iUIStore = ( (CAppUIAppUi*)iCoeEnv->AppUi() )->UIStoreHandler();
       
    51 
       
    52     iTestCasesInView.Reset();
       
    53         //((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("TestSetMenuContainer: iTCInV Reset"));
       
    54     
       
    55 	iListBox = CMenuListBox::NewL(ETestSetMenuViewId);
       
    56 	iListBox->SetContainerWindowL( *this );
       
    57 	iListBox->SetListBoxObserver( aListBoxObserver /*this*/ ); // jos peritty MEikListBoxObserver:sta
       
    58     iListBox->ConstructL(this, EAknListBoxMarkableList /*EAknListBoxSelectionList*/);
       
    59 
       
    60     ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("TestSetMenuContainer: ListBox constructed"));
       
    61 
       
    62     //Create Scroller control for ListBox and set its visibility
       
    63     iListBox->CreateScrollBarFrameL(ETrue);
       
    64     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
       
    65     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
    66     iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
       
    67                      iListBox->HandleItemAdditionL();   
       
    68 
       
    69     if ( iUIStore )
       
    70         {
       
    71         //RRefArray<const CTestInfo> allCases;
       
    72         //CTestSetInfo* testSetInfo;
       
    73         //IMPORT_C const CTestSetInfo& TestSetL( const TDesC& aSetName  );
       
    74         
       
    75         TPtrC ptr = iParentView->CurrentTestSet();
       
    76         
       
    77         const CTestSetInfo* testSetInfo = 
       
    78         	&iUIStore->TestSetL( ptr );
       
    79         
       
    80         //inline const RRefArray<const CTestInfo>& TestCases() const
       
    81    		const RRefArray<const CTestInfo>* allCases = &testSetInfo->TestCases();
       
    82         
       
    83         /*if( ret != KErrNone )
       
    84             {
       
    85             ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("iUIStore->TestCases() fails"));
       
    86             // Leave
       
    87             }
       
    88 		*/
       
    89 
       
    90         const TInt KTestCaseCount = allCases->Count();
       
    91         for (TInt i=0; i < KTestCaseCount; i++)
       
    92             {
       
    93             iTestCasesInView.Append( &allCases->operator[](i) );
       
    94             }
       
    95 
       
    96         iListBoxModel = CTestCaseListBoxModel::NewL(&iTestCasesInView);
       
    97              ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("TestSetMenuContainer: ListBox model"));
       
    98 
       
    99         iListBox->Model()->SetItemTextArray(iListBoxModel);
       
   100              ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("TestSetMenuContainer: ListBox model set"));
       
   101 
       
   102         }
       
   103     else
       
   104         {
       
   105         //User::Leave( syy?? )
       
   106         }
       
   107 
       
   108     // Creates graphic.
       
   109     SetGraphicIconL( iListBox );
       
   110        ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("TestSetMenuContainer: icons created"));
       
   111 
       
   112     iListBox->ActivateL();
       
   113     ((CMenuListBox*)iListBox)->SetPreviousFocus();
       
   114 
       
   115     SetRect(aRect);
       
   116     ActivateL();
       
   117     }
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // CTestSetMenuContainer::SetGraphicIconL
       
   121 // 
       
   122 // Sets graphic icon using listbox as CEikColumnListBox.
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 void CTestSetMenuContainer::SetGraphicIconL( CEikColumnListBox* aListBox )
       
   126     {
       
   127 	if ( aListBox )
       
   128         {
       
   129         // Creates gul icon.
       
   130         CAknIconArray* iconArray = new(ELeave) CAknIconArray(1);
       
   131         CleanupStack::PushL( iconArray );
       
   132         
       
   133         GraphicIconL( iconArray ); // Appends graphic data.
       
   134         
       
   135         // Sets graphics as ListBox icon.
       
   136         aListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
   137         
       
   138         CleanupStack::Pop();
       
   139         }
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CTestSetMenuContainer::CurrentItemIndex
       
   144 // 
       
   145 // Returns current item index in list box.
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 TInt CTestSetMenuContainer::CurrentItemIndex()
       
   149     {
       
   150     return iListBox->CurrentItemIndex();
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // CTestSetMenuContainer::SetCurrentItemIndex
       
   155 // 
       
   156 // Sets current item index in list box.
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CTestSetMenuContainer::SetCurrentItemIndex(TInt aCurrentTestCase)
       
   160     {
       
   161     iListBox->SetCurrentItemIndexAndDraw(aCurrentTestCase);
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // CTestSetMenuContainer::GraphicIconL
       
   166 // 
       
   167 // Appends graphics data.
       
   168 // ----------------------------------------------------------------------------
       
   169 //
       
   170 void CTestSetMenuContainer::GraphicIconL( CArrayPtr<CGulIcon>* aIcons )
       
   171     {
       
   172     if ( aIcons )
       
   173         {
       
   174         CFbsBitmap* markBitmap = NULL;
       
   175         CFbsBitmap* markBitmapMask = NULL;
       
   176 	
       
   177         TRgb defaultColor;
       
   178         defaultColor = CEikonEnv::Static()->Color(EColorControlText);
       
   179 	
       
   180         AknsUtils::CreateColorIconL(AknsUtils::SkinInstance(),
       
   181         		KAknsIIDQgnIndiMarkedAdd,
       
   182         		KAknsIIDQsnIconColors,
       
   183         		EAknsCIQsnIconColorsCG13,
       
   184         		markBitmap,
       
   185         		markBitmapMask,
       
   186         		AknIconUtils::AvkonIconFileName(),
       
   187         		EMbmAvkonQgn_indi_marked_add,
       
   188         		EMbmAvkonQgn_indi_marked_add_mask,
       
   189         		defaultColor );
       
   190         
       
   191         CGulIcon* markIcon = CGulIcon::NewL(markBitmap,markBitmapMask);
       
   192         aIcons->AppendL(markIcon); 
       
   193         }
       
   194     }
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CTestSetMenuContainer::~CTestSetMenuContainer
       
   198 // 
       
   199 // Destructor.
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 CTestSetMenuContainer::~CTestSetMenuContainer()
       
   203     {
       
   204     iTestCasesInView.Close(); // does not delete objects whose pointers are contained in the array
       
   205     delete iListBox;
       
   206     }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CTestSetMenuContainer::SizeChanged
       
   210 // 
       
   211 // Called by framework when the view size is changed.
       
   212 // ----------------------------------------------------------------------------
       
   213 //
       
   214 void CTestSetMenuContainer::SizeChanged()
       
   215     {
       
   216     if ( iListBox )
       
   217 		{
       
   218 		iListBox->SetRect( Rect() ); // Sets rectangle of listbox.
       
   219 		}
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // CTestSetMenuContainer::CountComponentControls
       
   224 // 
       
   225 // Gets a count of the component controls of this list box control.
       
   226 // ----------------------------------------------------------------------------
       
   227 //
       
   228 TInt CTestSetMenuContainer::CountComponentControls() const
       
   229     {
       
   230     return 1; // return nbr of controls inside this container
       
   231     }
       
   232 
       
   233 // ----------------------------------------------------------------------------
       
   234 // CTestSetMenuContainer::ComponentControl
       
   235 // 
       
   236 // Gets a pointer to the specified component control.
       
   237 // ----------------------------------------------------------------------------
       
   238 //
       
   239 CCoeControl* CTestSetMenuContainer::ComponentControl(TInt aIndex) const
       
   240     {
       
   241     switch ( aIndex )
       
   242         {
       
   243 		case 0: 
       
   244 			return iListBox;
       
   245         default:
       
   246             return NULL;
       
   247         }
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // CTestSetMenuContainer::Draw
       
   252 // 
       
   253 // Draw a control, called by window server.
       
   254 // ----------------------------------------------------------------------------
       
   255 //
       
   256 void CTestSetMenuContainer::Draw(const TRect& /*aRect*/) const
       
   257     {
       
   258     // CWindowGc& gc = SystemGc();
       
   259     }
       
   260 
       
   261 // ----------------------------------------------------------------------------
       
   262 // CTestSetMenuContainer::SelectedTestCases
       
   263 // 
       
   264 // Returns pointers to selected test cases.
       
   265 // ----------------------------------------------------------------------------
       
   266 //
       
   267 void CTestSetMenuContainer::SelectedTestCases
       
   268                             (RPointerArray<CTestInfo>& aSelectedTestCases)
       
   269     {
       
   270     aSelectedTestCases.Append( iTestCasesInView[iListBox->CurrentItemIndex()] );
       
   271     }
       
   272 
       
   273 // ----------------------------------------------------------------------------
       
   274 // CTestSetMenuContainer::OfferKeyEventL
       
   275 // 
       
   276 // Handles key events.
       
   277 // ----------------------------------------------------------------------------
       
   278 //
       
   279 TKeyResponse CTestSetMenuContainer::OfferKeyEventL(
       
   280 	const TKeyEvent& aKeyEvent, TEventCode aType )
       
   281     {
       
   282 	if (aType != EEventKey)
       
   283 	    {
       
   284 		return EKeyWasNotConsumed;
       
   285 	    }
       
   286 
       
   287 	if (iListBox)
       
   288 		{
       
   289 		//if multiple items selected
       
   290 		if ( iListBox->SelectionIndexes()->Count() > 0 )
       
   291 			{
       
   292 			TUint mask = 0x40488;
       
   293 			
       
   294 			//if event is enter key,
       
   295 			//donīt send it to listbox
       
   296 			if ( aKeyEvent.iScanCode == 0xa7 
       
   297 				&& ( aKeyEvent.iModifiers & mask ) == 0 )
       
   298 				{
       
   299 				iParentView->HandleListBoxEventL( iListBox, MEikListBoxObserver::EEventEnterKeyPressed );
       
   300 				return EKeyWasConsumed;	
       
   301 				}
       
   302 			}
       
   303 			
       
   304 		return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   305 		}
       
   306 	else
       
   307 		{
       
   308 		return EKeyWasNotConsumed;
       
   309 		}
       
   310     }
       
   311     
       
   312 // ----------------------------------------------------------------------------
       
   313 // CTestSetMenuContainer::HandleMarkCommandL
       
   314 // 
       
   315 // Handles mark commands.
       
   316 // ----------------------------------------------------------------------------
       
   317 //
       
   318 void CTestSetMenuContainer::HandleMarkCommandL( TInt aCommand )
       
   319 	{
       
   320 	if (iListBox)
       
   321 		{
       
   322 		AknSelectionService::HandleMarkableListProcessCommandL( aCommand, iListBox );		
       
   323 		}
       
   324 	}
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // CTestSetMenuContainer::ProcessCommandL
       
   328 // 
       
   329 // Processes user commands.
       
   330 // ----------------------------------------------------------------------------
       
   331 //
       
   332 void CTestSetMenuContainer::ProcessCommandL( TInt  aCommand )
       
   333 	{
       
   334 	AknSelectionService::HandleMarkableListProcessCommandL( aCommand, iListBox );
       
   335     }
       
   336     
       
   337 // ----------------------------------------------------------------------------
       
   338 // CTestSetMenuContainer::SelectionListProcessCommandL
       
   339 // 
       
   340 // Processes user commands.
       
   341 // ----------------------------------------------------------------------------
       
   342 //    
       
   343 void CTestSetMenuContainer::SelectionListProcessCommandL( TInt  aCommand )
       
   344 	{
       
   345 	AknSelectionService::HandleSelectionListProcessCommandL( aCommand, iListBox );
       
   346     }
       
   347     
       
   348 // ----------------------------------------------------------------------------
       
   349 // CTestSetMenuContainer::FilterCasesByModuleL
       
   350 // 
       
   351 // Show only testcases which are defined is specified module.
       
   352 // ----------------------------------------------------------------------------
       
   353 //
       
   354 void CTestSetMenuContainer::FilterCasesByModuleL( TName aModuleName )
       
   355     {
       
   356     iTestCasesInView.Reset(); // Clear testCasesInView pointer array
       
   357    
       
   358     RRefArray<CTestInfo> allCases;
       
   359     TInt ret = iUIStore->TestCases( allCases );
       
   360     if( KErrNone != ret )
       
   361         {
       
   362         ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("FilterCasesByModuleL(): iUIStore->TestCases() fails"));
       
   363         allCases.Reset();
       
   364         allCases.Close();
       
   365         User::Leave( ret );
       
   366         }
       
   367     const TInt KTestCaseCount = allCases.Count();
       
   368     for( TInt i=0; i < KTestCaseCount; i++ )
       
   369         {
       
   370         if ( allCases[i].ModuleName() == aModuleName )
       
   371             {
       
   372             iTestCasesInView.Append( &( allCases[i] ) );
       
   373             }
       
   374         }
       
   375     allCases.Reset();
       
   376     allCases.Close();
       
   377 
       
   378     iListBox->Reset();
       
   379     iListBox->DrawNow();
       
   380     }
       
   381 
       
   382 // ----------------------------------------------------------------------------
       
   383 // CTestSetMenuContainer::FilterCasesByTCFileNameL
       
   384 // 
       
   385 // Show only testcases which are defined is specified test case file.
       
   386 // ----------------------------------------------------------------------------
       
   387 //
       
   388 void CTestSetMenuContainer::FilterCasesByTCFileNameL( 
       
   389                                                 TFileName aTestCaseFileName )
       
   390     {
       
   391 
       
   392     iTestCasesInView.Reset(); // Clear testCasesInView pointer array
       
   393   
       
   394     RRefArray<CTestInfo> allCases;
       
   395     TInt ret = iUIStore->TestCases( allCases );
       
   396     if( KErrNone != ret )
       
   397         {
       
   398         ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("FilterCasesByModuleL(): iUIStore->TestCases() fails"));
       
   399         allCases.Reset();
       
   400         allCases.Close();
       
   401         User::Leave( ret );
       
   402         }
       
   403     const TInt KTestCaseCount = allCases.Count();
       
   404     for( TInt i=0; i < KTestCaseCount; i++ )
       
   405         {
       
   406         if ( allCases[i].TestCaseFile() == aTestCaseFileName )
       
   407             {
       
   408             iTestCasesInView.Append( &( allCases[i] ) );
       
   409             }
       
   410         }
       
   411 
       
   412     allCases.Reset();
       
   413     allCases.Close();
       
   414 
       
   415     iListBox->Reset();
       
   416     iListBox->DrawNow();
       
   417     }
       
   418 
       
   419 // ----------------------------------------------------------------------------
       
   420 // CTestSetMenuContainer::NoFilteringL
       
   421 // 
       
   422 // Remove possible filtering of test cases -> show all test cases.
       
   423 // ----------------------------------------------------------------------------
       
   424 //
       
   425 void CTestSetMenuContainer::NoFilteringL()
       
   426     {
       
   427     iTestCasesInView.Reset(); // Clear testCasesInView pointer array
       
   428 
       
   429     RRefArray<CTestInfo> allCases;
       
   430     TInt ret = iUIStore->TestCases( allCases );
       
   431     if( KErrNone != ret )
       
   432         {
       
   433         ((CAppUIAppUi*)iCoeEnv->AppUi())->iLogger->Log(_L("FilterCasesByModuleL(): iUIStore->TestCases() fails"));
       
   434         allCases.Reset();
       
   435         allCases.Close();
       
   436         User::Leave( ret );
       
   437         }
       
   438     const TInt KTestCaseCount = allCases.Count();
       
   439 
       
   440     // Add all cases to iTestCasesInView pointer array
       
   441     for( TInt i=0; i < KTestCaseCount; i++ )
       
   442         {
       
   443         iTestCasesInView.Append( &( allCases[i] ) );
       
   444         }
       
   445 
       
   446     allCases.Reset();
       
   447     allCases.Close();
       
   448 
       
   449     iListBox->Reset();
       
   450     iListBox->DrawNow();
       
   451     }
       
   452 
       
   453 // ----------------------------------------------------------------------------
       
   454 // CTestSetMenuContainer::RemoveListBoxItemsL
       
   455 // 
       
   456 // Removes items from list box.
       
   457 // ----------------------------------------------------------------------------
       
   458 //
       
   459 void CTestSetMenuContainer::RemoveListBoxItemL( TInt aSelected )
       
   460 	{
       
   461 	TInt currentItem(0);
       
   462     TBool remCurr(EFalse);
       
   463 	
       
   464 	currentItem = iListBox->CurrentItemIndex();
       
   465 	if( aSelected == currentItem )
       
   466 	    {
       
   467 	    remCurr = ETrue;
       
   468 	    }
       
   469 	    
       
   470 	iTestCasesInView.Remove( aSelected );
       
   471 	AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iListBox, aSelected, remCurr);
       
   472 	 iListBox->HandleItemAdditionL();
       
   473 	}
       
   474 
       
   475 // ----------------------------------------------------------------------------
       
   476 // CTestSetMenuContainer::SaveActiveLine
       
   477 //
       
   478 // Makes the iListBox member save its focus position
       
   479 // ----------------------------------------------------------------------------
       
   480 //	
       
   481 void CTestSetMenuContainer::SaveActiveLine()
       
   482 	{
       
   483 	((CMenuListBox*)iListBox)->SaveFocusPosition();
       
   484 	}
       
   485 
       
   486 // End of File