|
Nokia N97 SDK Example Applications Guide |
00001 00002 /* 00003 * ============================================================================== 00004 * Name : MyViewAppUi.cpp 00005 * Part of : MyView 00006 * Interface : 00007 * Description : Handle user interaction. CAknViewAppUi view handling methods added to 00008 * CAknAppUi. 00009 * HandleCommandL has (menu+softkey) commands applicable for the entire 00010 * application. 00011 * In HandleKeyEvent the application switches between view 1 and view 2. 00012 * Navipane tabs are not automatically handled, they need to be 00013 * taken care of separately. 00014 * HandleForeGroundEventL is called when the application view loses or 00015 * gains focus. 00016 * DynInitMenuPaneL allows you to manipulate menu items dynamically. 00017 * Not used in this example. 00018 * InfoMessages work only in the emulator, not on the device. 00019 * Version : 00020 * 00021 * Copyright (c) 2002 - 2007 Nokia Corporation. 00022 * This material, including documentation and any related 00023 * computer programs, is protected by copyright controlled by 00024 * Nokia Corporation. 00025 * ============================================================================== 00026 */ 00027 00028 // INCLUDE FILES 00029 #include "MyViewAppUi.h" 00030 #include "MyViewView.h" 00031 #include "MyViewView2.h" 00032 #include <MyView.rsg> 00033 #include "myview.hrh" 00034 #include "MSVSTD.HRH" 00035 #include <avkon.hrh> 00036 00037 00038 // ================= MEMBER FUNCTIONS ======================= 00039 // 00040 // ---------------------------------------------------------- 00041 // CMyViewAppUi::ConstructL() 00042 // ---------------------------------------------------------- 00043 // 00044 void CMyViewAppUi::ConstructL() 00045 { 00046 //Initialises this app UI with standard values. 00047 //The application’s standard resource file will be read unless 00048 //the ENoAppResourceFile or ENonStandardResourceFile flags are passed. 00049 BaseConstructL(0x08 | EAknEnableSkin); // Use ELayoutAwareAppFlag (0x08) to make the application support scalable UI on FP3 devices. 00050 00051 00052 // Show tabs for main views from resources 00053 CEikStatusPane* sp = StatusPane(); 00054 00055 // Fetch pointer to the default navi pane control 00056 iNaviPane = (CAknNavigationControlContainer*)sp->ControlL( 00057 TUid::Uid(EEikStatusPaneUidNavi)); 00058 00059 // Tabgroup has been read from resource and it was pushed to the navi pane. 00060 // Get pointer to the navigation decorator with the ResourceDecorator() function. 00061 // Application owns the decorator and it has responsibility to delete the object. 00062 iDecoratedTabGroup = iNaviPane->ResourceDecorator(); 00063 if (iDecoratedTabGroup) 00064 { 00065 iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl(); 00066 } 00067 00068 CMyViewView* view1 = new (ELeave) CMyViewView; 00069 00070 CleanupStack::PushL( view1 ); 00071 view1->ConstructL(iTabGroup); 00072 AddViewL( view1 ); // transfer ownership to CAknViewAppUi 00073 CleanupStack::Pop( view1 ); 00074 iViewId1 = view1->Id(); // view id to get view from CAknViewAppUi 00075 00076 00077 CMyViewView2* view2 = new (ELeave) CMyViewView2; 00078 00079 CleanupStack::PushL( view2 ); 00080 view2->ConstructL(); 00081 AddViewL( view2 ); // transfer ownership to CAknViewAppUi 00082 CleanupStack::Pop( view2 ); 00083 iViewId2 = view2->Id(); // view id to get view from CAknViewAppUi 00084 00085 00086 SetDefaultViewL( *view1 ); 00087 } 00088 00089 // ---------------------------------------------------- 00090 // CMyViewAppUi::~CMyViewAppUi() 00091 // Destructor 00092 // Frees reserved resources 00093 // ---------------------------------------------------- 00094 // 00095 CMyViewAppUi::~CMyViewAppUi() 00096 { 00097 delete iDecoratedTabGroup; 00098 } 00099 00100 // ------------------------------------------------------------------------------ 00101 // CMyViewAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane) 00102 // This function is called by the EIKON framework just before it displays 00103 // a menu pane. Its default implementation is empty, and by overriding it, 00104 // the application can set the state of menu items dynamically according 00105 // to the state of application data. 00106 // ------------------------------------------------------------------------------ 00107 // 00108 void CMyViewAppUi::DynInitMenuPaneL( 00109 TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/) 00110 { 00111 } 00112 00113 00114 // ------------------------------------------------------------------------------ 00115 // CMyViewAppUi::HandleForegroundEventL(TBool aForeground) 00116 // This function is called by the framework when the screen loses or gains focus. 00117 // i.e. when it goes to the background or to the foreground. Incoming call 00118 // softnote is an example. 00119 // This event applies to the entire application, all views. 00120 // ------------------------------------------------------------------------------ 00121 // 00122 void CMyViewAppUi::HandleForegroundEventL(TBool aForeground) 00123 { 00124 if (aForeground==TRUE) 00125 iEikonEnv->InfoMsg(_L("Foreground true")); 00126 else 00127 iEikonEnv->InfoMsg(_L("Foreground false")); 00128 00129 } 00130 00131 00132 00133 // ---------------------------------------------------- 00134 // CMyViewAppUi::HandleKeyEventL( 00135 // const TKeyEvent& aKeyEvent,TEventCode /*aType*/) 00136 // Here we handle key events: Right and left arrow key 00137 // to change view. 00138 // ---------------------------------------------------- 00139 // 00140 TKeyResponse CMyViewAppUi::HandleKeyEventL( 00141 const TKeyEvent& aKeyEvent,TEventCode /*aType*/) 00142 { 00143 if ( iTabGroup == NULL ) 00144 { 00145 return EKeyWasNotConsumed; 00146 } 00147 00148 TInt active = iTabGroup->ActiveTabIndex(); 00149 TInt count = iTabGroup->TabCount(); 00150 00151 switch ( aKeyEvent.iCode ) 00152 { 00153 case EKeyLeftArrow: 00154 if ( active > 0 ) 00155 { 00156 active--; 00157 iTabGroup->SetActiveTabByIndex( active ); 00158 // ActivateLocalViewL() is used to change the view. 00159 // To change view from another application we would use ActivateViewL() 00160 // Send an empty message 00161 ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active))); 00162 } 00163 break; 00164 case EKeyRightArrow: 00165 if( (active + 1) < count ) 00166 { 00167 active++; 00168 iTabGroup->SetActiveTabByIndex( active ); 00169 // ActivateLocalViewL() is used to change the view. 00170 // To change view from another application we would use ActivateViewL() 00171 ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active))); 00172 } 00173 break; 00174 default: 00175 return EKeyWasNotConsumed; 00176 } 00177 00178 return EKeyWasConsumed; 00179 } 00180 00181 // ---------------------------------------------------- 00182 // CMyViewAppUi::HandleCommandL(TInt aCommand) 00183 // Here we handle commands on the application level. 00184 // In addition, each view has their own HandleCommandL() 00185 // ---------------------------------------------------- 00186 // 00187 void CMyViewAppUi::HandleCommandL(TInt aCommand) 00188 { 00189 switch ( aCommand ) 00190 { 00191 case EEikCmdExit: 00192 { 00193 Exit(); 00194 break; 00195 } 00196 // You can add your all application applying commands here. 00197 // You would handle here menu commands that are valid for all views. 00198 } 00199 } 00200 00201 // ----------------------------------------------------------------------------- 00202 // CChatAppUi::HandleResourceChangeL( TInt aType ) 00203 // Called by framework when layout is changed. 00204 // ----------------------------------------------------------------------------- 00205 // 00206 void CMyViewAppUi::HandleResourceChangeL( TInt aType ) 00207 { 00208 CAknAppUi::HandleResourceChangeL( aType ); 00209 00210 // ADDED FOR SCALABLE UI SUPPORT 00211 // ***************************** 00212 if ( aType==KEikDynamicLayoutVariantSwitch ) 00213 { 00214 ((CMyViewView*) View( iViewId1) )->HandleClientRectChange( ); 00215 ((CMyViewView2*) View( iViewId2) )->HandleClientRectChange( ); 00216 } 00217 00218 } 00219 00220 // End of File
|
© Nokia 2009 |