stifui/stifui/src/MainMenuContainer.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 CMainMenuContainer class
       
    15 * definition.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknlists.h>  // ListBox
       
    21 
       
    22 #include <barsread.h> // for TResourceReader
       
    23 
       
    24 #include <aknnotewrappers.h>
       
    25 
       
    26 #include "MainMenuContainer.h"
       
    27 #include "Stifui.hrh"
       
    28 #include <Stifui.rsg>
       
    29 #include "MenuListBox.h"
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CMainMenuContainer::ConstructL
       
    35 // 
       
    36 // Symbian OS two phased constructor
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 void CMainMenuContainer::ConstructL(const TRect& aRect)
       
    40     {
       
    41     CreateWindowL();
       
    42 
       
    43 	iListBox = CMenuListBox::NewL(EMainMenuViewId);
       
    44 	iListBox->SetContainerWindowL( *this );
       
    45 	TResourceReader reader;
       
    46 	iCoeEnv->CreateResourceReaderLC( reader, R_MAIN_MENU_LISTBOX );
       
    47 	iListBox->SetListBoxObserver( this );
       
    48 	iListBox->ConstructFromResourceL( reader );
       
    49 	CleanupStack::PopAndDestroy(); // resource stuffs. 
       
    50 	iListBox->ActivateL(); // Sets control as ready to be drawn
       
    51 	
       
    52 	// retrieve previous position of focus for this view/continer and set focus to this value
       
    53 	((CMenuListBox*)iListBox)->SetPreviousFocus();
       
    54 
       
    55     SetRect(aRect);
       
    56     ActivateL();
       
    57     }
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CMainMenuContainer::~CMainMenuContainer
       
    62 //
       
    63 // Destructor
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CMainMenuContainer::~CMainMenuContainer()
       
    67     {
       
    68 	if( iListBox )
       
    69 		{
       
    70 		delete iListBox;
       
    71 		iListBox = NULL;
       
    72 		}
       
    73 	}
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CMainMenuContainer::SizeChanged
       
    77 // 
       
    78 // Called by framework when the view size is changed
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 void CMainMenuContainer::SizeChanged()
       
    82     {
       
    83     if ( iListBox )
       
    84 		{
       
    85 		iListBox->SetRect( Rect() ); // Sets rectangle of listbox.
       
    86 		}
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------
       
    90 // CMainMenuContainer::CountComponentControls
       
    91 //
       
    92 // Returns number of controls indside this container.
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 TInt CMainMenuContainer::CountComponentControls() const
       
    96     {
       
    97     return 1;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CMainMenuContainer::ComponentControl
       
   102 // 
       
   103 // Gets the specified component of a compound control.
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 CCoeControl* CMainMenuContainer::ComponentControl(TInt aIndex) const
       
   107     {
       
   108     switch ( aIndex )
       
   109         {
       
   110 		case 0: 
       
   111 			return iListBox;
       
   112         default:
       
   113             return NULL;
       
   114         }
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // CMainMenuContainer::Draw
       
   119 // 
       
   120 // Draw a control, called by window server.
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 void CMainMenuContainer::Draw(const TRect& /*aRect*/) const
       
   124     {
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CMainMenuContainer::HandleListBoxEventL
       
   129 //
       
   130 // Handles list box events.
       
   131 // ---------------------------------------------------------
       
   132 //
       
   133 void CMainMenuContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
       
   134 	{
       
   135 
       
   136 	if ( ( aEventType == EEventEnterKeyPressed ) || ( aEventType == EEventItemDoubleClicked ) )
       
   137 		{	
       
   138         HandleSelectedListItemL( aListBox->CurrentItemIndex() );
       
   139 		}
       
   140 
       
   141 	}
       
   142 	
       
   143 // ----------------------------------------------------------------------------
       
   144 // CMainMenuContainer::HandleSelectedListItemL
       
   145 //
       
   146 // Method HandleSelectedListItemL handles valix index.
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 void CMainMenuContainer::HandleSelectedListItemL( TInt aIndex )
       
   150 	{	 
       
   151 		TInt selection = aIndex;
       
   152         
       
   153         // Change active view.
       
   154 	    switch ( selection )
       
   155         {
       
   156 		    case 0:
       
   157 				( (CEikAppUi*)iCoeEnv->AppUi() )->HandleCommandL(EAppUIGoToTestCaseMenu);
       
   158 				break;
       
   159 			case 1:
       
   160 				( (CEikAppUi*)iCoeEnv->AppUi() )->HandleCommandL(EAppUIGoToModulesMenu);
       
   161 				break;
       
   162 			case 2: 
       
   163 				( (CEikAppUi*)iCoeEnv->AppUi() )->HandleCommandL(EAppUIGoToTestSetsMenu);
       
   164 				break;
       
   165 	        default:
       
   166 				break;
       
   167 		}
       
   168 	}
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CMainMenuContainer::OfferKeyEventL
       
   172 // 
       
   173 // Handles key events.
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 TKeyResponse CMainMenuContainer::OfferKeyEventL(
       
   177 	const TKeyEvent& aKeyEvent, TEventCode aType)
       
   178 {
       
   179 	if (aType != EEventKey)
       
   180 	{
       
   181 		return EKeyWasNotConsumed;
       
   182 	}
       
   183 
       
   184 	// Offers key events to list box
       
   185 	if (iListBox)
       
   186 	{
       
   187 		return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   188 	}
       
   189 	else
       
   190 	{
       
   191 		return EKeyWasNotConsumed;
       
   192 	}
       
   193 }
       
   194 
       
   195 // ----------------------------------------------------------------------------
       
   196 // CMainMenuContainer:::GetActiveLine
       
   197 //
       
   198 // Get currently selected items index.
       
   199 // ----------------------------------------------------------------------------
       
   200 //
       
   201 TInt CMainMenuContainer::GetActiveLine()
       
   202 	{
       
   203 	return iListBox->CurrentItemIndex();
       
   204 	}
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CMainMenuContainer:::SaveActiveLine
       
   208 //
       
   209 // Makes the iListBox member save its focus position
       
   210 // ----------------------------------------------------------------------------
       
   211 //
       
   212 void CMainMenuContainer::SaveActiveLine()
       
   213 	{
       
   214 	((CMenuListBox*)iListBox)->SaveFocusPosition();
       
   215 	}
       
   216 
       
   217 // End of File