commonuisupport/uikon/coresrc/EIKAPPUI.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <s32file.h>
       
    17 #include <basched.h>
       
    18 #include <w32std.h>
       
    19 #include <gulcolor.h>
       
    20 #include <gulutil.h>
       
    21 #include <coeutils.h>
       
    22 #include <apgtask.h>
       
    23 #include <apgwgnam.h>
       
    24 #include <eikappui.h>
       
    25 #include <eikenv.h>
       
    26 #include <eikdef.h>
       
    27 #include <eikdoc.h>
       
    28 #include <eikapp.h>
       
    29 #include <eikproc.h>
       
    30 #include <eikpanic.h>
       
    31 #include "EIKSHUT.H"
       
    32 #include <eikaufty.h>
       
    33 #include <eikbhelp.h>
       
    34 #include <uikon.hrh>
       
    35 #include <uiklafgt/eikcore.rsg>
       
    36 #include <uiklaf/private/lafappui.h>
       
    37 #include <apgcli.h>
       
    38 #include <eikserverapp.h>
       
    39 #include "eikprivate.h"
       
    40 #include <uiklaf/private/lafenv.h>
       
    41 #include "eikdefconst.h"
       
    42 
       
    43 /** This class provides additional members to CEikAppUi without breaking 
       
    44 binary compatibility An instance of this is owned by CEikAppUi and is not
       
    45 meant for external visibility
       
    46 
       
    47 @see CEikAppUi */
       
    48 NONSHARABLE_CLASS(CEikAppUiExtra) : public CBase
       
    49 	{
       
    50 public:
       
    51 	CEikAppUiExtra(CEikAppUi& aEikAppUi);
       
    52 	~CEikAppUiExtra();
       
    53 private:
       
    54 	CEikAppUi& iEikAppUi;
       
    55 	};
       
    56 
       
    57 CEikAppUiExtra::CEikAppUiExtra(CEikAppUi& aEikAppUi) : iEikAppUi(aEikAppUi)
       
    58 	{
       
    59 	}
       
    60 	
       
    61 CEikAppUiExtra::~CEikAppUiExtra()
       
    62 	{	
       
    63 	}
       
    64 
       
    65 /** Empty default constructor. */
       
    66 EXPORT_C CEikAppUi::CEikAppUi()
       
    67     {
       
    68     }
       
    69 
       
    70 /** Destructor.
       
    71 
       
    72 Deletes any resources allocated by this CEikAppUi during its construction. 
       
    73 */
       
    74 EXPORT_C CEikAppUi::~CEikAppUi()
       
    75     {
       
    76 	iCoeEnv->RemoveMessageObserver(*this);
       
    77 	if (LafEnv::PolicyItem(LafEnv::ELAfEnvPolicyDeferredEnvironmentDeletion))
       
    78         {
       
    79 	    if (!iContainerAppUi)
       
    80 	        iEikonEnv->PostAppUiDestroy();
       
    81         }
       
    82 
       
    83 	if (iContainerAppUi)
       
    84 		{
       
    85 		if(iFlags & EEmbedded)
       
    86 			{
       
    87 			MEikAppUiFactory* uiFactory = iEikonEnv->AppUiFactory(*this);
       
    88 			ASSERT(uiFactory);
       
    89 			if (uiFactory)
       
    90 				{
       
    91 				uiFactory->DestroyEmbedded(*iEikonEnv);				
       
    92 				}
       
    93 			}
       
    94 
       
    95 		iCoeEnv->SetAppUi(iContainerAppUi);
       
    96         TWsEvent event;
       
    97         event.SetType(EEventNull);
       
    98         TRAP_IGNORE(iContainerAppUi->HandleApplicationSpecificEventL( KEikHasBecomeCurrentAppUiWhileEmbeddedAppUiDeletes, event));
       
    99 		}
       
   100 
       
   101 	if (iDocument)
       
   102 		iDocument->NullAppUi();
       
   103 		
       
   104 	delete iAppUiExtra;
       
   105     }
       
   106 
       
   107 /** Handles changes to the model associated with this CEikAppUi's application. 
       
   108 
       
   109 The implementation is empty in CEikAppUi. 
       
   110 */
       
   111 EXPORT_C void CEikAppUi::HandleModelChangeL()
       
   112 	{
       
   113 	}	
       
   114 
       
   115 /** Completes construction. 
       
   116 
       
   117 This simply calls BaseConstructL(). 
       
   118 */
       
   119 EXPORT_C void CEikAppUi::ConstructL()
       
   120 	{
       
   121 	BaseConstructL();
       
   122 	}
       
   123 
       
   124 /** Initialises this app UI with standard values. 
       
   125 
       
   126 The application's standard resource file will be read unless either the 
       
   127 ENoAppResourceFile or ENonStandardResourceFile flag is specified.
       
   128 
       
   129 @param aAppUiFlags Application user interface flags, EStandardApp for example. 
       
   130 */
       
   131 EXPORT_C void CEikAppUi::BaseConstructL(TInt aAppUiFlags)
       
   132     {
       
   133     TWsEvent event;
       
   134     event.SetType(EEventNull);
       
   135     
       
   136 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   137 	ASSERT(appUiFactory);
       
   138     iContainerAppUi = static_cast<CEikAppUi*>(iCoeEnv->SetAppUi(this));
       
   139     iAppUiExtra = new (ELeave) CEikAppUiExtra(*this); 
       
   140 	if (iContainerAppUi)
       
   141 		{
       
   142         HandleApplicationSpecificEventL( KEikNotifyPreCreateEmbeddedL, event );
       
   143 		appUiFactory->CreateEmbeddedL(*iEikonEnv);
       
   144 		iFlags |= EEmbedded;
       
   145 		HandleApplicationSpecificEventL( KEikNotifyPostCreateEmbeddedL, event );
       
   146 		TRAP_IGNORE(iContainerAppUi->HandleResourceChangeL(KEikMessageEmbedLevelChange));
       
   147 		iContainerAppUi->HandleStackedControlsResourceChange(KEikMessageEmbedLevelChange);
       
   148 		}
       
   149 		
       
   150     CCoeAppUi::ConstructL(iContainerAppUi);
       
   151     HandleApplicationSpecificEventL( KEikPostCoeAppUiConstructL, event );
       
   152 	if (!iContainerAppUi)
       
   153 		iEikonEnv->ControlStackReadyL();
       
   154 	
       
   155 	if (!(aAppUiFlags&(ENoAppResourceFile|ENonStandardResourceFile)))
       
   156 	    ReadAppInfoResourceL();
       
   157 	
       
   158 	else if (!(aAppUiFlags&ENoScreenFurniture))
       
   159 		CreateResourceIndependentFurnitureL();
       
   160 	
       
   161 	iCoeEnv->AddMessageObserverL(*this);
       
   162 	iEikonEnv->PostAppUiInitializeL();
       
   163 	iCoeEnv->RootWin().EnableScreenChangeEvents();
       
   164     }
       
   165 
       
   166 EXPORT_C void CEikAppUi::ReadAppInfoResourceL(TInt aResourceFileOffset)
       
   167 /** Reads the application UI information at the specified offset in the 
       
   168 app's standard resource file.
       
   169 
       
   170 This function is called by BaseConstructL(), unless either of the ENoAppResourceFile or 
       
   171 ENonStandardResourceFile flags was specified.
       
   172 
       
   173 @param aResourceFileOffset Offset of the application information in the resource file. */
       
   174 	{
       
   175 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   176 	ASSERT(appUiFactory);
       
   177 	appUiFactory->ReadAppInfoResourceL(aResourceFileOffset, this);
       
   178 	}
       
   179 
       
   180 EXPORT_C TRect CEikAppUi::ClientRect() const
       
   181 /** Gets the area of the screen available to the application for drawing. 
       
   182 
       
   183 This does not include the space available for UI components like the 
       
   184 menu bar.
       
   185 
       
   186 The co-ordinates of the rectangle are relative to the whole screen 
       
   187 area so, for example, the co-ordinate for the top, left point of the area 
       
   188 available for drawing may be (0, 45).
       
   189 
       
   190 @return The area of the screen available to the application for drawing. */
       
   191 	{
       
   192 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   193 	ASSERT(appUiFactory);
       
   194 	return(appUiFactory->ClientRect());
       
   195 	}
       
   196 
       
   197 EXPORT_C TRect CEikAppUi::ApplicationRect() const
       
   198 /** Gets the total area of the screen available to the application. 
       
   199 
       
   200 This includes the space available for UI components like the menu bar.
       
   201 
       
   202 @return The total area of the screen available to the application. */
       
   203 	{
       
   204 	TRect rect(iCoeEnv->ScreenDevice()->SizeInPixels());
       
   205 	LafAppUi::ReduceRect(rect);
       
   206 	return rect;
       
   207 	}
       
   208 
       
   209 /**
       
   210 Checks for, and closes, popups and menubars before calling HandleCommandL()
       
   211 @see MEikCommandObserver::ProcessCommandL( TInt aCommand )
       
   212 @see CEikAppUi::HandleCommandL( TInt aCommand ) 
       
   213 */
       
   214 EXPORT_C void CEikAppUi::ProcessCommandL(TInt aCommand)
       
   215     {
       
   216 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   217 	ASSERT(appUiFactory);
       
   218 	if (appUiFactory->Popup())
       
   219 	    ClosePopup();
       
   220     else if (appUiFactory->MenuBar())
       
   221         StopDisplayingMenuBar();
       
   222     if (aCommand!=EEikCmdCanceled)
       
   223 	    HandleCommandL(aCommand);
       
   224     }
       
   225 
       
   226 /**
       
   227 Wrapper for MEikAppUiFactory::CreateResourceIndependentFurnitureL
       
   228 @internalComponent
       
   229 @see MEikAppUiFactory::CreateResourceIndependentFurnitureL(CEikAppUi* aAppUi)
       
   230 */
       
   231 void CEikAppUi::CreateResourceIndependentFurnitureL()
       
   232 	{
       
   233 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   234 	ASSERT(appUiFactory);
       
   235 	appUiFactory->CreateResourceIndependentFurnitureL(this);
       
   236 	}
       
   237 
       
   238 EXPORT_C void CEikAppUi::HandleCommandL(TInt /*aCommand*/)
       
   239 /** Handles user commands. 
       
   240 
       
   241 This is overridden by subclasses to handle commands passed on by the 
       
   242 application framework. This function is called by CEikAppUi::ProcessCommandL(), 
       
   243 and has an empty implementation. Commands can be invoked using a menu item, 
       
   244 a hotkey, or a button (for instance in a toolbar or dialog).
       
   245 
       
   246 @param aCommand The ID of the command. */
       
   247     {
       
   248     }
       
   249 
       
   250 EXPORT_C void CEikAppUi::CreateHotKeyControlL(TInt aResourceId)
       
   251 /** Creates a hotkey control.
       
   252 
       
   253 Constructs a CEikHotKeyControl whose CEikHotKeyTable is specified by a resource 
       
   254 ID, and adds it to the control stack.
       
   255 
       
   256 @param aResourceId ID of a hotkey table resource. */
       
   257     {
       
   258 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   259 	ASSERT(appUiFactory);
       
   260 	appUiFactory->CreateHotKeyControlL(aResourceId, this);
       
   261     }
       
   262 
       
   263 EXPORT_C void CEikAppUi::LaunchPopupMenuL(TInt aResourceId,const TPoint& aTargetPos,TPopupTargetPosType aTargetType,const CEikHotKeyTable* aHotKeyTable)
       
   264 /** Launches a popup menu. 
       
   265 
       
   266 This function is called by CEikAppUI::HandleSideBarMenuL(). 
       
   267 
       
   268 @param aResourceId ID of the menu resource. 
       
   269 @param aTargetPos Position of the corner of the menu identified by aTargetType. 
       
   270 @param aTargetType The corner of the menu by which the menu will be positioned. 
       
   271 @param aHotKeyTable Optional menu hotkey table. */
       
   272     {
       
   273 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   274 	ASSERT(appUiFactory);
       
   275 	appUiFactory->LaunchPopupMenuL(aResourceId,aTargetPos,aTargetType,aHotKeyTable, this);
       
   276     }
       
   277 
       
   278 EXPORT_C void CEikAppUi::ClosePopup()
       
   279 /** Closes any currently visible popup menu. */
       
   280     {
       
   281 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   282 	ASSERT(appUiFactory);
       
   283 	appUiFactory->ClosePopup(this);
       
   284     }
       
   285 
       
   286 EXPORT_C void CEikAppUi::StopDisplayingMenuBar()
       
   287 /** Stops displaying the application's menu bar. 
       
   288 
       
   289 If the application has no menu bar, or if the menu bar is not visible, 
       
   290 this function has no effect. */
       
   291 	{
       
   292 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   293 	ASSERT(appUiFactory);
       
   294 	appUiFactory->StopDisplayingMenuBar();
       
   295 	}
       
   296 
       
   297 EXPORT_C TBool CEikAppUi::FadeWhenInBackground()
       
   298 /** Tests whether the application is set to fade when in the background.
       
   299 
       
   300 @return ETrue if the application is set to fade when in the background, EFalse 
       
   301 if not. */
       
   302 	{
       
   303 	return LafAppUi::FadeWhenInBackground();
       
   304 	}
       
   305 
       
   306 
       
   307 /**
       
   308 This is a virtual function.
       
   309 The base class implemenatiation causes the root window and all of its children to change to the desired faded state.
       
   310 @param aFaded  The desired faded state
       
   311 */
       
   312 EXPORT_C void CEikAppUi::SetFadedL(TBool aFaded)
       
   313 	{
       
   314 	const TInt message=(aFaded? KEikMessageFadeAllWindows : KEikMessageUnfadeWindows);
       
   315 	HandleResourceChangeL(message);
       
   316 	HandleStackedControlsResourceChange(message);
       
   317 	iCoeEnv->RootWin().SetFaded(aFaded,RWindowTreeNode::EFadeIncludeChildren);
       
   318 	}
       
   319 
       
   320 /**
       
   321 @see MEikMenuObserver::SetEmphasis(CCoeControl* aMenuWindow,TBool aEmphasis)
       
   322 */
       
   323 EXPORT_C void CEikAppUi::SetEmphasis(CCoeControl* aMenuWindow,TBool aEmphasis)
       
   324     {
       
   325     UpdateStackedControlFlags(aMenuWindow,aEmphasis? 0: ECoeStackFlagRefusesFocus,ECoeStackFlagRefusesFocus);
       
   326     HandleStackChanged();
       
   327     }
       
   328 
       
   329 EXPORT_C void CEikAppUi::SetDocument(CEikDocument* aDocument)
       
   330 /** Sets this app UI's document. 
       
   331 
       
   332 The document associated with the app UI is initially owned by 
       
   333 CEikProcess, and there is usually no reason to change it with this function.
       
   334 
       
   335 @param aDocument The app UI's document. */
       
   336 	{
       
   337 	iDocument=aDocument;
       
   338 	}
       
   339 
       
   340 EXPORT_C void CEikAppUi::SetEmbeddedDocInfo(MApaEmbeddedDocObserver* aDoorObserver,TBool aReadOnly)
       
   341 /** Sets the embedded document's observer and read only state.
       
   342 
       
   343 @param aObserver Observer for the embedded document. 
       
   344 @param aReadOnly ETrue to set the embedded document as read-only. EFalse if not. */
       
   345 	{
       
   346 	iDoorObserver=aDoorObserver;
       
   347 	iEmbeddedAndReadOnly=aReadOnly;
       
   348 	}
       
   349 
       
   350 EXPORT_C CEikDocument* CEikAppUi::Document() const
       
   351 /** Gets a pointer to the app UI's associated document. 
       
   352 
       
   353 @return Pointer to the app UI's associated document. */
       
   354 	{
       
   355 	return iDocument;
       
   356 	}
       
   357 
       
   358 EXPORT_C void CEikAppUi::SetDocChanged()
       
   359 /** Marks the app UI's associated document as having changed. */
       
   360 	{
       
   361 	iDocument->SetChanged(ETrue);
       
   362 	}
       
   363 
       
   364 EXPORT_C void CEikAppUi::SaveAnyChangesL()
       
   365 /** Saves any changes made to the app UI's associated document, 
       
   366 if the document is marked as having changed. */
       
   367 	{
       
   368 	if (iDocument->HasChanged())
       
   369 		iDocument->SaveL();
       
   370 	}
       
   371 
       
   372 EXPORT_C CEikApplication* CEikAppUi::Application() const
       
   373 /** Gets a pointer to the application associated with this app UI.
       
   374 
       
   375 @return A pointer to the application associated with this app UI. */
       
   376 	{
       
   377 	CEikApplication* ret = NULL;
       
   378 	if (iDocument)
       
   379 		ret = ((CEikApplication*)(iDocument->Application()));
       
   380 	return ret;
       
   381 	}
       
   382 
       
   383 EXPORT_C void CEikAppUi::Exit()
       
   384 /** Closes the app UI. */
       
   385 	{
       
   386 	if (iContainerAppUi)
       
   387 		{
       
   388 		CEikAppUi* appUi=iContainerAppUi;
       
   389 		delete this;
       
   390 		TRAP_IGNORE(appUi->HandleResourceChangeL(KEikMessageEmbedLevelChange));
       
   391 		appUi->HandleStackedControlsResourceChange(KEikMessageEmbedLevelChange);
       
   392 		}
       
   393 	else
       
   394 		{
       
   395 		// default reason for exiting is EEikCmdExit. If server exists,
       
   396 		// clients must be told. Other exit reasons should be notified
       
   397 		// before they call Exit().
       
   398 		CEikAppServer* server = iEikonEnv->AppServer();
       
   399 		if (server)
       
   400 			server->NotifyServerExit(EEikCmdExit);
       
   401 		
       
   402 		CBaActiveScheduler::Exit();
       
   403 		}
       
   404 	}
       
   405 
       
   406 EXPORT_C void CEikAppUi::SaveL()
       
   407 /** Saves the app UI's associated document, or sets the document as changed, if 
       
   408 the app UI is embedded. */
       
   409 	{
       
   410 	if (iContainerAppUi)
       
   411 		iContainerAppUi->iDocument->SetChanged(ETrue);
       
   412 	else
       
   413 		iDocument->SaveL();
       
   414 	}
       
   415 
       
   416 EXPORT_C void CEikAppUi::HandleSideBarMenuL(TInt aResourceId,const TPoint& aPos,TInt /*aModifiers*/,const CEikHotKeyTable* aHotKeyTable)
       
   417 /** Handles sidebar menu commands. 
       
   418 
       
   419 This is called by the Uikon framework to handle invocation of a 
       
   420 sidebar menu. See also MEikMenuObserver::HandleSideBarMenuL().
       
   421 
       
   422 Note that not all UIs support a sidebar.
       
   423 
       
   424 @param aResourceId ID of the menu resource. 
       
   425 @param aPos Position of the menu's reference point. For sidebar menus, this 
       
   426 is the top-right corner. 
       
   427 @param aModifiers Bitwise OR of the modifiers held when the menu was invoked 
       
   428 by the user. 
       
   429 @param aTable Hotkey table for the menu. */
       
   430 	{
       
   431 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   432 	ASSERT(appUiFactory);
       
   433 	appUiFactory->HandleSideBarMenuL(aResourceId,aPos,aHotKeyTable, this);
       
   434 	}
       
   435 
       
   436 EXPORT_C TBool CEikAppUi::ProcessCommandParametersL(CApaCommandLine& aCommandLine)
       
   437 /** Processes shell commands. 
       
   438 
       
   439 This is the ProcessCommandParametersL() method that the Uikon application framework 
       
   440 will call at application startup. The implementation will extract the command, 
       
   441 document file name, and tail parameteres from the command line and call the 
       
   442 3-parameter version of this method. 
       
   443 
       
   444 The default implementation will simply returns whether or not the file aDocumentName exists. 
       
   445 
       
   446 @param aCommandLine The command line used to initialise the new application.
       
   447 @return Whether the final value of aDocumentName represents an existing file. 
       
   448 @see CEikAppUi::ProcessCommandParametersL(TApaCommand aCommand ,TFileName& aDocumentName, const TDesC8& aTail) */
       
   449 	{
       
   450 	const TPtrC documentName = aCommandLine.DocumentName();
       
   451 	
       
   452 	// Make a copy of the document file name from the command line
       
   453 	// using the TUnlimitedFileName to allow names longer than the usual TFileName
       
   454 	TUnlimitedFileName* const modifiedDocumentName = TUnlimitedFileName::NewLC(documentName);
       
   455 	// ...and allow the application code to modify it
       
   456 	const TBool documentFileExists = ProcessCommandParametersL(aCommandLine.Command(), modifiedDocumentName->AsFileName(), aCommandLine.TailEnd());
       
   457 	// ...then set it back on the command line
       
   458 	aCommandLine.SetDocumentNameL(*modifiedDocumentName);
       
   459 	
       
   460 	CleanupStack::PopAndDestroy(modifiedDocumentName);
       
   461 	return documentFileExists;
       
   462 	}
       
   463 
       
   464 EXPORT_C TBool CEikAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/ ,TFileName& aDocumentName, const TDesC8& /*aTail*/)
       
   465 /** Processes shell commands. 
       
   466 
       
   467 The Uikon application framework calls this overload when an application is 
       
   468 launched by the user opening a file from the shell or when a Create new file 
       
   469 command is issued.
       
   470 
       
   471 This overload simply returns whether or not the file aDocumentName exists. 
       
   472 
       
   473 Many document based applications will override this function to invoke the 2-parameter 
       
   474 utility version of this methid. 
       
   475 
       
   476 @param aCommand The shell command sent to the application. Not used in this implementation.
       
   477 @param aDocumentName At call time, the name of the document as specified on 
       
   478 the command line. On return, the name for the file which will be created by 
       
   479 the calling framework. 
       
   480 @param aTail Command line tail.  Not used in this implementation.
       
   481 @return Whether the final value of aDocumentName represents an existing file. 
       
   482 @see CEikAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName) */
       
   483 	{
       
   484 	Application()->GetDefaultDocumentFileName(aDocumentName);
       
   485 	return ConeUtils::FileExists(aDocumentName);
       
   486 	}
       
   487 
       
   488 EXPORT_C TBool CEikAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName)
       
   489 /** This is a convinience utility method that an application can call from an overriden version
       
   490 of the virtual ProcessCommandParametersL() taking three arguments. This method will not be called 
       
   491 unless explicitly used by the application in this way.
       
   492 
       
   493 This method is useful for applications that are used to view or edit document files, such as
       
   494 text documents or spreadsheets. 
       
   495 
       
   496 This method will make an application automatically open the document file that was last open
       
   497 in the application, unless a document file is explicitly defined as part of the command line, and
       
   498 the Open or Create commands are specified.
       
   499 
       
   500 This method will call CEikAppUi::ValidFileType() to find out if the specified document file can 
       
   501 be opened by this application.
       
   502 
       
   503 In detail:
       
   504 If aCommand is EApaCommandCreate, the function simply returns EFalse as the file does not yet exist.
       
   505 
       
   506 If aCommand is EApaCommandOpen, the function tests whether the specified document is valid and 
       
   507 exists. If not, the function attempts to generate a valid default filename and returns that in 
       
   508 aDocumentName provided the file name portion of the specified full path name has valid format.
       
   509 
       
   510 If aCommand is any other value, the function tests whether the most recently open document that 
       
   511 is valid for the application exists, and returns that in aDocumentName.
       
   512 
       
   513 The file must be a valid document file, as indicated by the UID value(s),otherwise the 
       
   514 function generates a new filename. An application may handle the request by overriding 
       
   515 CEikAppUi::ValidFileType() if required.
       
   516 
       
   517 @param aCommand The shell command sent to the application. 
       
   518 @param aDocumentName The name of the document as specified on the command line. 
       
   519 On return, this contains the name of the file which will be created by the calling framework. 
       
   520 @return Whether the returned value of aDocumentName represents an existing, valid file.
       
   521 @see CEikAppUi::ValidFileType()
       
   522 */
       
   523 	{ 
       
   524 	if (aCommand==EApaCommandCreate)
       
   525 		return EFalse; // assume aDocumentName is valid
       
   526 		
       
   527 	// Any command but EApaCommandOpen. 
       
   528 	// These commands are used to open the application without any file spcified,
       
   529 	// so try to find the file open last time the application ran.
       
   530 	if (aCommand!=EApaCommandOpen)	
       
   531 		{
       
   532 		TFileName fileName=iEikonEnv->Process()->LastUsedFileL(CEikProcess::ELastOpenFile);
       
   533 		if (ValidFileExistsL(fileName))
       
   534 			{
       
   535 			aDocumentName = fileName;
       
   536 			return ETrue;
       
   537 			}
       
   538 		}
       
   539 		
       
   540 	// aCommand == EApaCommandOpen
       
   541 	if (!ValidFileExistsL(aDocumentName))
       
   542 		CApaApplication::GenerateFileName(iEikonEnv->FsSession(),aDocumentName);
       
   543 	return ConeUtils::FileExists(aDocumentName);
       
   544 	}
       
   545 	
       
   546 /**
       
   547 A valid file has fileType which matches the applications Uid.
       
   548 @internalComponent
       
   549 @return EFalse if file or path not found.  Standard error code otherwise.
       
   550 */
       
   551 TBool CEikAppUi::ValidFileExistsL(const TDesC& aFileName)
       
   552 
       
   553 	{
       
   554 	// If the file doesn't exist, simply return EFalse
       
   555 	if (!ConeUtils::FileExists(aFileName))
       
   556 		return EFalse;
       
   557 	
       
   558 	// If it does exist, check whether it's valid
       
   559 	TEntry entry;
       
   560 	const TInt error = iEikonEnv->FsSession().Entry(aFileName, entry);
       
   561 	if(error==KErrNotFound || error==KErrPathNotFound)
       
   562 		return EFalse;
       
   563 
       
   564 	User::LeaveIfError(error);
       
   565 	
       
   566 	const TUid fileType = entry[2];
       
   567 	const TUid appType = Application()->AppDllUid();
       
   568 	return (fileType==appType || ValidFileType(fileType));
       
   569 	}
       
   570 
       
   571 
       
   572 /** This method is used in combination with CEikAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName).
       
   573 
       
   574 Override this method to return ETure if the application can handle documents associated 
       
   575 with the UID aFileUid. If not, return EFalse (default).
       
   576 
       
   577 @publishedAll 
       
   578 @released 
       
   579 @see CEikAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName)
       
   580 */
       
   581 EXPORT_C TBool CEikAppUi::ValidFileType(TUid /*aFileUid*/) const
       
   582 	{
       
   583 	return EFalse;
       
   584 	}
       
   585 
       
   586 
       
   587 /**
       
   588 @see MCoeMessageObserver::TMessageResponse HandleMessageL(TUint32 aClientHandleOfTargetWindowGroup, TUid aMessageUid, const TDesC8& aMessageParameters)
       
   589 */
       
   590 EXPORT_C MCoeMessageObserver::TMessageResponse CEikAppUi::HandleMessageL(TUint32, TUid aMessageUid, const TDesC8& aMessageParameters)
       
   591 	{
       
   592 	switch (aMessageUid.iUid)
       
   593 		{
       
   594 	case KUidApaMessageSwitchOpenFileValue:
       
   595 	case KUidApaMessageSwitchCreateFileValue:
       
   596 		CEikShutter::DeferredExecuteL(*iEikonEnv, aMessageUid, aMessageParameters);
       
   597 		return EMessageHandled;
       
   598 	default:
       
   599 		return EMessageNotHandled;
       
   600 		}
       
   601 	}
       
   602 
       
   603 EXPORT_C TTypeUid::Ptr CEikAppUi::MopSupplyObject(TTypeUid /*aId*/)
       
   604 /** Retrieves an object of the same type as that encapsulated in aId.
       
   605 
       
   606 This function is used to allow to ask owners for access to 
       
   607 other objects that they own.
       
   608 
       
   609 Other than in the case where NULL is returned, the object returned must be 
       
   610 of the same object type - that is, the ETypeId member of the object pointed 
       
   611 to by the pointer returned by this function must be equal to the iUid member 
       
   612 of aId.
       
   613 
       
   614 @param aId An encapsulated object type ID.
       
   615 @return Encapsulates the pointer to the object provided. Note that the encapsulated 
       
   616 pointer may be NULL. */
       
   617 	{
       
   618 	return TTypeUid::Null();
       
   619 	}
       
   620 
       
   621 EXPORT_C MObjectProvider* CEikAppUi::MopNext()
       
   622 /** Retrieves the parent.
       
   623 
       
   624 @return A pointer to an object provider, or NULL if none is defined. 
       
   625 @publishedAll 
       
   626 @released */
       
   627 	{
       
   628 	CEikonEnv* env=(CEikonEnv*)iCoeEnv;
       
   629 	return env->AppUiFactory();
       
   630 	}
       
   631 
       
   632 /**
       
   633 @see CCoeAppUi::HandleSystemEventL( const TWsEvent& aEvent )
       
   634 */
       
   635 EXPORT_C void CEikAppUi::HandleSystemEventL(const TWsEvent& aEvent)
       
   636 /** @see CCoeAppUi::HandleSystemEventL */
       
   637 	{
       
   638 	switch (*(TApaSystemEvent*)(aEvent.EventData()))
       
   639 		{
       
   640 	case EApaSystemEventShutdown:
       
   641 		if(static_cast<CEikonEnv*>(iCoeEnv)->IsSystem())
       
   642 			break;
       
   643 		// fall-through
       
   644 	case EApaSystemEventSecureShutdown:
       
   645 		CEikShutter::DeferredExecuteL(*iEikonEnv);
       
   646 		break;
       
   647 	case EApaSystemEventBroughtToForeground:
       
   648 		{
       
   649 		RArray<RWsSession::TWindowGroupChainInfo> wgIds;
       
   650 		User::LeaveIfError(iEikonEnv->WsSession().WindowGroupList(&wgIds));
       
   651 		CleanupClosePushL(wgIds);
       
   652 		TInt rootWgId=iEikonEnv->RootWin().Identifier();
       
   653 		const TInt wgCount=wgIds.Count();
       
   654 		TBool hasChild=EFalse;
       
   655 		for (TInt i=0;i<wgCount;i++)
       
   656 			{
       
   657 			// If the current app has a child window group in front of it
       
   658 			if (wgIds[i].iParentId==rootWgId)
       
   659 				{
       
   660 				hasChild=ETrue;
       
   661 				break;
       
   662 				}
       
   663 			}
       
   664 		CleanupStack::PopAndDestroy(&wgIds);
       
   665 		if (!hasChild)
       
   666 			{
       
   667 			ActivateTopViewL();
       
   668 			}
       
   669 		}
       
   670 		break;
       
   671 	default:
       
   672 		break;
       
   673 		}
       
   674 	}
       
   675 
       
   676 EXPORT_C void CEikAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
       
   677 /** Handles window server events.
       
   678 @see CCoeAppUi::HandleWsEventL
       
   679 
       
   680 @param aEvent The window server event that occurred. 
       
   681 @param aDestination The control associated with the event. */
       
   682 	{
       
   683 	switch (aEvent.Type())
       
   684 		{
       
   685 	case EEventModifiersChanged:
       
   686 		if ((aEvent.ModifiersChanged()->iChangedModifiers)&EModifierCapsLock)
       
   687 			{
       
   688 			HandleResourceChangeL(KEikMessageCapsLock);
       
   689 			HandleStackedControlsResourceChange(KEikMessageCapsLock);
       
   690 			}
       
   691 		break;
       
   692 	case EEventPointer:
       
   693 		if (LafAppUi::CancelBubbleHelpOnEvent(*aEvent.Pointer()))
       
   694 			{
       
   695 			EikBubbleHelp::Cancel();
       
   696 			}
       
   697 		break;
       
   698 	default:
       
   699 		break;
       
   700 		}
       
   701 	CCoeAppUi::HandleWsEventL(aEvent, aDestination);
       
   702 	}
       
   703 
       
   704 EXPORT_C void CEikAppUi::ProcessMessageL(TUid aUid,const TDesC8& aParams)
       
   705 /** Processes Application Architecture messages. 
       
   706 
       
   707 This is overridden by subclasses to handle messages sent from the Application 
       
   708 Architecture framework. This implementation only recognises the message UIDs 
       
   709 KUidApaMessageSwitchOpenFileValue and KUidApaMessageSwitchCreateFileValue. 
       
   710 It performs no action if the message contains other values.
       
   711 
       
   712 @param aUid The message's unique identifier. 
       
   713 @param aParams Message parameters. 
       
   714 @see CCoeAppUi::HandleMessageReadyL()
       
   715 @see CApaTask::SendMessage() */
       
   716 	{
       
   717 	switch (aUid.iUid)
       
   718 		{
       
   719 	case KUidApaMessageSwitchOpenFileValue:
       
   720 		OpenFileL(TPtrC(((TText*)aParams.Ptr()),aParams.Length()/sizeof(TText)));
       
   721 		break;
       
   722 	case KUidApaMessageSwitchCreateFileValue:
       
   723 		CreateFileL(TPtrC(((TText*)aParams.Ptr()),aParams.Length()/sizeof(TText)));
       
   724 		break;
       
   725 	default:
       
   726 		break;
       
   727 		}
       
   728 	}
       
   729 
       
   730 EXPORT_C void CEikAppUi::OpenFileL(const TDesC& /*aFileName*/)
       
   731 /** Opens the specified file. 
       
   732 
       
   733 The default implementation is empty. 
       
   734 
       
   735 @param aFileName The name of the file to open. 
       
   736 @see CEikAppUi::ProcessMessageL() */
       
   737 	{
       
   738 	}
       
   739 
       
   740 EXPORT_C void CEikAppUi::CreateFileL(const TDesC& /*aFileName*/)
       
   741 /** Creates and opens a file with the given name. 
       
   742 
       
   743 The default implementation is empty.
       
   744 
       
   745 @param aFileName The name of the file to create. 
       
   746 @see CEikAppUi::ProcessMessageL() */
       
   747 	{
       
   748 	}
       
   749 
       
   750 EXPORT_C TErrorHandlerResponse CEikAppUi::HandleError(TInt /*aError*/,const SExtendedError& /*aExtErr*/,TDes& /*aErrorText*/,TDes& /*aContextText*/)
       
   751 /** Handles errors. 
       
   752 
       
   753 The default implementation of this function returns EErrorNotHandled.
       
   754 
       
   755 @param aError The error code. 
       
   756 @param aExtErr For extended error messages. 
       
   757 @param aErrorText Error text.
       
   758 @param aContextText Text describing the context of the error.
       
   759 @return How the error was handled. */
       
   760 	{
       
   761 	return(EErrorNotHandled);
       
   762 	}
       
   763 
       
   764 EXPORT_C void CEikAppUi::HandleResourceChangeL(TInt aType)
       
   765 /** Handles a change to the application's resources which are shared 
       
   766 across the environment, for instance colours or fonts.
       
   767 
       
   768 @param aType The type of resources that have changed. */
       
   769 	{
       
   770 	MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(*this);
       
   771 	ASSERT(appUiFactory);
       
   772 	appUiFactory->HandleResourceChangeL(aType);
       
   773 	}
       
   774 
       
   775 /** Handles an application-specific event. 
       
   776 
       
   777 This implementation handles a change to the environment's colour scheme 
       
   778 and informs everything on the control stack of the change.
       
   779 
       
   780 @param aType The type of the event that occurred. This should be a unique 
       
   781 identifier constant. 
       
   782 @param aEvent The window server event that occurred. 
       
   783 @see CCoeAppUi::HandleApplicationSpecificEventL 
       
   784 @see KUidValueEikColorSchemeChangeEvent */
       
   785 EXPORT_C void CEikAppUi::HandleApplicationSpecificEventL(TInt aType, const TWsEvent& /*aEvent*/)
       
   786 	{
       
   787 	switch(aType)
       
   788 		{
       
   789 		case KUidValueEikColorSchemeChangeEvent:
       
   790 			{
       
   791 			TRAPD(err,iEikonEnv->UpdateColorListL());
       
   792 			if(err==KErrNone)
       
   793 				{
       
   794 				HandleResourceChangeL(KEikMessageColorSchemeChange);
       
   795 				HandleStackedControlsResourceChange(KEikMessageColorSchemeChange);
       
   796 				if(iEikonEnv->IsEiksrvThread())
       
   797 					{
       
   798 					UpdateViewServerBackgroundColor(iEikonEnv->ColorList().Color(EColorWindowBackground));
       
   799 					}
       
   800 				}
       
   801 			}
       
   802 		case KEikNotifyPreCreateEmbeddedL:
       
   803 			break;	// do nothing
       
   804 		case KEikNotifyPostCreateEmbeddedL:
       
   805 			break;	// do nothing
       
   806 		case KEikHasBecomeCurrentAppUiWhileEmbeddedAppUiDeletes:
       
   807 			break;	// do nothing
       
   808 		default:
       
   809 			break;	// do nothing
       
   810 		}
       
   811 	}
       
   812 
       
   813 EXPORT_C void CEikAppUi::ReportResourceChangedToAppL(TInt aType)
       
   814 /** Reports a resource change to the application.
       
   815 
       
   816 @param aType The type of resource that has changed. */
       
   817 	{
       
   818 	HandleResourceChangeL(aType);
       
   819 	HandleStackedControlsResourceChange(aType);
       
   820 	}
       
   821 
       
   822 EXPORT_C void CEikAppUi::HandleForegroundEventL(TBool aForeground)
       
   823 /** Handles changes to the application when it switches to or from 
       
   824 the foreground. 
       
   825 
       
   826 For instance it handles changes to the cursor visibility and to the 
       
   827 fade state.
       
   828 
       
   829 This function is called from HandleWsEventL() when an event 
       
   830 occurs of type EEventFocusLost or EEventFocusGained.
       
   831 
       
   832 Any application overriding this should first call this base implementation.
       
   833 
       
   834 @param aForeground ETrue to switch to the foreground. EFalse to switch from 
       
   835 the foreground.. */
       
   836 	{
       
   837 	if (LafAppUi::FadeWhenInBackground())
       
   838 		SetFadedL(!aForeground);
       
   839 	
       
   840 	if (aForeground)
       
   841 		iEikonEnv->VirtualCursor().HandleAppToForeground(*iEikonEnv);
       
   842 	}
       
   843 
       
   844 EXPORT_C void CEikAppUi::PrepareToExit()
       
   845 /** Performs pre-exit processing to ensure the application will exit cleanly. */
       
   846 	{
       
   847 	TVwsViewId viewId;
       
   848 	if (GetActiveViewId(viewId) != KErrNotFound)
       
   849 		{
       
   850 		TRAP_IGNORE(DeactivateActiveViewIfOwnerMatchL());
       
   851 		}
       
   852 	}
       
   853 
       
   854 EXPORT_C void CEikAppUi::HandleScreenDeviceChangedL()
       
   855 	{
       
   856 	// All status pane stuff must be handled in System Gui
       
   857 	}
       
   858 
       
   859 EXPORT_C void CEikAppUi::Reserved_3()
       
   860 	{}
       
   861 	
       
   862 EXPORT_C void CEikAppUi::Reserved_4()
       
   863 	{}
       
   864 	
       
   865 /** Determines the current language the application is using to display its
       
   866 user interface.
       
   867 
       
   868 @return The application language.
       
   869 */
       
   870 EXPORT_C TLanguage CEikAppUi::ApplicationLanguageL() const
       
   871 	{
       
   872 	return iEikonEnv->ApplicationLanguage();
       
   873 	}
       
   874 
       
   875 
       
   876 /**
       
   877 Calls ReportResourceChangedToAppL( aEventId ) on recursively on each ContainerAppUi.  
       
   878 For use with embedded applications (where iContanerAppUI != NULL)
       
   879 @param aTopApp AppUi of an embedded application.
       
   880 @param aEventId  The type of resource that has changed. 
       
   881 @see CEikAppUi::ReportResourceChangedToAppL(TInt aType)
       
   882 */
       
   883 EXPORT_C void CEikAppUi::ReportResourceChangedToAppStackL(CEikAppUi* aTopApp, TInt aEventId)
       
   884 	{
       
   885  	for (; aTopApp; aTopApp = aTopApp->iContainerAppUi)
       
   886  		 aTopApp->ReportResourceChangedToAppL(aEventId);
       
   887  	}
       
   888 
       
   889 
       
   890