examples/AppFramework/Apparc/MenuApp/MenuApp.cpp

00001 /*
00002 Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 
00032 #include "MenuApp.h"
00033 
00034 
00035 const TUid KUidMenuApp = { 0xE800008C };
00036 
00037 // Called by the UI framework to get the application's UID
00038 TUid CExampleApplication::AppDllUid() const
00039         {
00040         return KUidMenuApp;
00041         }
00042 
00043 // Called by the UI framework at application start-up to
00044 // create an instance of the document class.
00045 CApaDocument* CExampleApplication::CreateDocumentL()
00046         {
00047         return new (ELeave) CExampleDocument(*this);
00048         }
00049 
00050 CExampleDocument::CExampleDocument(CEikApplication& aApp)
00051                 : CEikDocument(aApp)
00052         {}
00053 
00054 // Called by the UI framework to construct
00055 // the application UI class. Note that the app UI's
00056 // ConstructL() is called by the UI framework.
00057 CEikAppUi* CExampleDocument::CreateAppUiL()
00058         {
00059         return new(ELeave) CExampleAppUi;
00060         }
00061 
00062 // Second phase constructor of the application UI class.
00063 // It creates and owns a single view.
00064 void CExampleAppUi::ConstructL()
00065         {
00066         BaseConstructL();
00067         iAppView = CExampleAppView::NewL(ClientRect());
00068         // Connect to the application architecture server
00069         User::LeaveIfError(iApaLsSession.Connect());
00070         }
00071 
00072 // The application UI class owns one view, and is responsible
00073 // for destroying it. 
00074 CExampleAppUi::~CExampleAppUi()
00075         {
00076         // Close the session with the apparc server
00077         iApaLsSession.Close();
00078         delete iAppView;
00079         }
00080 
00081 // Called by the UI framework when a command has been issued.
00082 void CExampleAppUi::HandleCommandL(TInt aCommand)
00083         {
00084         switch (aCommand)
00085                 {
00086                 // Handles the exit command
00087                 case EEikCmdExit:
00088                         Exit();
00089                         break;
00090 
00091                 // any other command is the UID of a selected application
00092                 default:
00093                         TUid appUid;
00094                         // Get the application Uid
00095                         appUid.iUid = aCommand;
00096                         TApaAppInfo info;
00097                         
00098                         // Get the application info based on the application UID
00099                         TInt ret = iApaLsSession.GetAppInfo(info,appUid);
00100                         if(ret==KErrNone)
00101                                 {
00102                                 CApaCommandLine* cmdLn = CApaCommandLine::NewLC();
00103                                 // Launch the application
00104                                 cmdLn->SetExecutableNameL(info.iFullName);
00105                                 User::LeaveIfError(iApaLsSession.StartApp(*cmdLn));
00106                                 CleanupStack::PopAndDestroy(cmdLn);
00107                                 }
00108                 }
00109         }
00110         
00111 // Called by the UI framework to initialise the menu pane dynamically
00112 void CExampleAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
00113         {
00114         if(aResourceId == R_EXAMPLE_FIRST_MENU)
00115                 {       
00116                 CEikMenuPaneItem::SData extraItem;
00117                 TRequestStatus status;
00118                 // Notify when the application list is fully populated
00119                 iApaLsSession.RegisterListPopulationCompleteObserver(status);
00120                 User::WaitForRequest(status);
00121 
00122                 if (status == KErrNone)         
00123                         {       
00124                         // Get the list of applications present on the device
00125                         TInt ret = iApaLsSession.GetAllApps();
00126                         if(ret==KErrNone)
00127                                 {                       
00128                 
00129                                 TApaAppInfo appInfo;
00130                                 // Retrieve the next application in the application list
00131                                 while ((iApaLsSession.GetNextApp(appInfo)) == KErrNone)
00132                                         {
00133                                         // Set the menu item flags
00134                                         extraItem.iCascadeId = 0;
00135                                         extraItem.iFlags = EEikMenuItemSymbolIndeterminate|EEikMenuItemSymbolOn;
00136                                         // Set the command Id with the application Uid value
00137                                         extraItem.iCommandId = appInfo.iUid.iUid;
00138                                         // Set the application name in the menu pane item
00139                                         extraItem.iText = appInfo.iCaption;
00140                                         // Create the application menu item in the menu pane
00141                                         aMenuPane->AddMenuItemL(extraItem);
00142                                         }
00143                                 }
00144                         }
00145                 // Set the exit command Id
00146                 extraItem.iCommandId = EEikCmdExit;
00147                 _LIT(KText,"Close");
00148                 extraItem.iText = KText;
00149                 // Create the close menu item in the menu pane  
00150                 aMenuPane->AddMenuItemL(extraItem);
00151                 }
00152         }
00153 
00154 
00155 CExampleAppView::CExampleAppView()
00156         {}
00157 
00158 // Static function wraps up two-phase construction for the view.
00159 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
00160         {
00161         CExampleAppView* self = new(ELeave) CExampleAppView();
00162         CleanupStack::PushL(self);
00163         self->ConstructL(aRect);
00164         CleanupStack::Pop();
00165         return self;
00166         }
00167 
00168 CExampleAppView::~CExampleAppView()
00169         {}
00170 
00171 // Standard initialisation for a window-owning control.
00172 void CExampleAppView::ConstructL(const TRect& aRect)
00173     {
00174         // Create the window owned by the view.
00175         CreateWindowL();
00176         // Set the view's size and position.
00177         SetRect(aRect);
00178         // Activate the view.
00179         ActivateL();
00180         }
00181         
00182 // Draws the view with a simple outline rectangle and then
00183 // draws the welcome text centred.
00184 void CExampleAppView::Draw(const TRect& /*aRect*/) const
00185         {
00186         CWindowGc& gc = SystemGc();
00187         TRect      drawRect = Rect();
00188         const CFont*     fontUsed;
00189         gc.Clear();
00190         drawRect.Shrink(10,10);
00191         gc.DrawRect(drawRect);
00192         fontUsed = iEikonEnv->TitleFont();
00193         gc.UseFont(fontUsed);
00194         TInt   baselineOffset=(drawRect.Height())/2;
00195         _LIT(KText,"Welcome to the menu application example");
00196         gc.DrawText(KText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
00197         gc.DiscardFont();
00198         }

Generated by  doxygen 1.6.2