diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_menu_app_8cpp-source.html --- a/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_menu_app_8cpp-source.html Tue Mar 30 11:56:28 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ - -
-00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). -00002 // All rights reserved. -00003 // This component and the accompanying materials are made available -00004 // under the terms of "Eclipse Public License v1.0" -00005 // which accompanies this distribution, and is available -00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". -00007 // -00008 // Initial Contributors: -00009 // Nokia Corporation - initial contribution. -00010 // -00011 // Contributors: -00012 // -00013 // Description: -00014 // -00015 -00016 -00017 #include "MenuApp.h" -00018 -00019 -00020 const TUid KUidMenuApp = { 0xE800008C }; -00021 -00022 // Called by the UI framework to get the application's UID -00023 TUid CExampleApplication::AppDllUid() const -00024 { -00025 return KUidMenuApp; -00026 } -00027 -00028 // Called by the UI framework at application start-up to -00029 // create an instance of the document class. -00030 CApaDocument* CExampleApplication::CreateDocumentL() -00031 { -00032 return new (ELeave) CExampleDocument(*this); -00033 } -00034 -00035 CExampleDocument::CExampleDocument(CEikApplication& aApp) -00036 : CEikDocument(aApp) -00037 {} -00038 -00039 // Called by the UI framework to construct -00040 // the application UI class. Note that the app UI's -00041 // ConstructL() is called by the UI framework. -00042 CEikAppUi* CExampleDocument::CreateAppUiL() -00043 { -00044 return new(ELeave) CExampleAppUi; -00045 } -00046 -00047 // Second phase constructor of the application UI class. -00048 // It creates and owns a single view. -00049 void CExampleAppUi::ConstructL() -00050 { -00051 BaseConstructL(); -00052 iAppView = CExampleAppView::NewL(ClientRect()); -00053 // Connect to the application architecture server -00054 User::LeaveIfError(iApaLsSession.Connect()); -00055 } -00056 -00057 // The application UI class owns one view, and is responsible -00058 // for destroying it. -00059 CExampleAppUi::~CExampleAppUi() -00060 { -00061 // Close the session with the apparc server -00062 iApaLsSession.Close(); -00063 delete iAppView; -00064 } -00065 -00066 // Called by the UI framework when a command has been issued. -00067 void CExampleAppUi::HandleCommandL(TInt aCommand) -00068 { -00069 switch (aCommand) -00070 { -00071 // Handles the exit command -00072 case EEikCmdExit: -00073 Exit(); -00074 break; -00075 -00076 // any other command is the UID of a selected application -00077 default: -00078 TUid appUid; -00079 // Get the application Uid -00080 appUid.iUid = aCommand; -00081 TApaAppInfo info; -00082 -00083 // Get the application info based on the application UID -00084 TInt ret = iApaLsSession.GetAppInfo(info,appUid); -00085 if(ret==KErrNone) -00086 { -00087 CApaCommandLine* cmdLn = CApaCommandLine::NewLC(); -00088 // Launch the application -00089 cmdLn->SetExecutableNameL(info.iFullName); -00090 User::LeaveIfError(iApaLsSession.StartApp(*cmdLn)); -00091 CleanupStack::PopAndDestroy(cmdLn); -00092 } -00093 } -00094 } -00095 -00096 // Called by the UI framework to initialise the menu pane dynamically -00097 void CExampleAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane) -00098 { -00099 if(aResourceId == R_EXAMPLE_FIRST_MENU) -00100 { -00101 CEikMenuPaneItem::SData extraItem; -00102 TRequestStatus status; -00103 // Notify when the application list is fully populated -00104 iApaLsSession.RegisterListPopulationCompleteObserver(status); -00105 User::WaitForRequest(status); -00106 -00107 if (status == KErrNone) -00108 { -00109 // Get the list of applications present on the device -00110 TInt ret = iApaLsSession.GetAllApps(); -00111 if(ret==KErrNone) -00112 { -00113 -00114 TApaAppInfo appInfo; -00115 // Retrieve the next application in the application list -00116 while ((iApaLsSession.GetNextApp(appInfo)) == KErrNone) -00117 { -00118 // Set the menu item flags -00119 extraItem.iCascadeId = 0; -00120 extraItem.iFlags = EEikMenuItemSymbolIndeterminate|EEikMenuItemSymbolOn; -00121 // Set the command Id with the application Uid value -00122 extraItem.iCommandId = appInfo.iUid.iUid; -00123 // Set the application name in the menu pane item -00124 extraItem.iText = appInfo.iCaption; -00125 // Create the application menu item in the menu pane -00126 aMenuPane->AddMenuItemL(extraItem); -00127 } -00128 } -00129 } -00130 // Set the exit command Id -00131 extraItem.iCommandId = EEikCmdExit; -00132 _LIT(KText,"Close"); -00133 extraItem.iText = KText; -00134 // Create the close menu item in the menu pane -00135 aMenuPane->AddMenuItemL(extraItem); -00136 } -00137 } -00138 -00139 -00140 CExampleAppView::CExampleAppView() -00141 {} -00142 -00143 // Static function wraps up two-phase construction for the view. -00144 CExampleAppView* CExampleAppView::NewL(const TRect& aRect) -00145 { -00146 CExampleAppView* self = new(ELeave) CExampleAppView(); -00147 CleanupStack::PushL(self); -00148 self->ConstructL(aRect); -00149 CleanupStack::Pop(); -00150 return self; -00151 } -00152 -00153 CExampleAppView::~CExampleAppView() -00154 {} -00155 -00156 // Standard initialisation for a window-owning control. -00157 void CExampleAppView::ConstructL(const TRect& aRect) -00158 { -00159 // Create the window owned by the view. -00160 CreateWindowL(); -00161 // Set the view's size and position. -00162 SetRect(aRect); -00163 // Activate the view. -00164 ActivateL(); -00165 } -00166 -00167 // Draws the view with a simple outline rectangle and then -00168 // draws the welcome text centred. -00169 void CExampleAppView::Draw(const TRect& /*aRect*/) const -00170 { -00171 CWindowGc& gc = SystemGc(); -00172 TRect drawRect = Rect(); -00173 const CFont* fontUsed; -00174 gc.Clear(); -00175 drawRect.Shrink(10,10); -00176 gc.DrawRect(drawRect); -00177 fontUsed = iEikonEnv->TitleFont(); -00178 gc.UseFont(fontUsed); -00179 TInt baselineOffset=(drawRect.Height())/2; -00180 _LIT(KText,"Welcome to the menu application example"); -00181 gc.DrawText(KText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0); -00182 gc.DiscardFont(); -00183 } -