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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #if !defined(__E32STD_H__)
22 #if !defined(__E32BASE_H__)
25 #if !defined(__F32FILE_H__)
28 #if !defined(__GDI_H__)
31 #if !defined(__APADEF_H__)
34 #if !defined(__APAID_H__)
39 class CApaApplication;
42 class MApaEmbeddedDocObserver;
44 // classes referenced:
51 class CPersistentStore;
52 class CStreamDictionary;
53 class CDictionaryStore;
54 class TApaAppHolderInfo;
55 class CImplementationInformation;
56 class TApaApplicationFactory;
60 /** Creates an application interface object.
62 Provides the basic roles of an application class as a factory that
63 creates concrete document objects, and supplies utility functions
64 not specific to any particular instance of a document.
69 typedef CApaApplication* (*CreateCApaApplication)();
74 class CApaApplication : public CBase
75 // base class for applications; allows creation of documents & file stores + display of app icon and name.
76 /** Defines the basic behaviour for applications.
78 The class defines the basic twin roles of an application class as a factory
79 that creates concrete document objects, and as a supplier of utility functions
80 not specific to any particular instance of a document. For example, returning
81 an application's caption, or accessing its .ini file.
83 The class is derived from by the UI framework and is further derived from
84 by the UI application.
88 @see CEikApplication */
91 /** Completes construction of this application object.
93 The function is called after an instance of a derived class has been successfully
94 created using the ordinal 1 function of the application DLL.
96 After calling this function, an application can create document objects.
98 An implementation of this function is supplied by the UI framework.
100 @see CEikApplication */
101 virtual void PreDocConstructL()=0; // call once before creating document
103 /** Creates a document object.
105 The function is called by the application process when a new document is required.
106 The application process adds the new document to its list of documents.
108 An implementation of this function is supplied by the UI framework.
110 @param aProcess A pointer to the process associated with the application.
111 @return A pointer to the newly created document.
112 @see CApaProcess::AddNewDocumentL() */
113 virtual CApaDocument* CreateDocumentL(CApaProcess* aProcess)=0;
115 /** Gets the application specific UID.
117 The UID is used to differentiate between UI applications.
119 An implementation of this function must be supplied by the UI application.
121 @return The application specific UID. */
122 virtual TUid AppDllUid()const=0;
126 IMPORT_C static TInt GenerateFileName(RFs& aFs,TFileName& aRootName);
127 IMPORT_C CDictionaryStore* OpenIniFileL(RFs& aFs)const;
129 /** Opens the .ini file associated with the application, constructs the dictionary
130 store object, returns a pointer to it and puts the pointer onto the cleanupstack.
132 The .ini file must be created, if it does not already exist.
134 An implementation of this function is supplied by the UI framework.
136 @param aFs Handle to a file server session
137 @return A pointer to the dictionary store object that represents the application's
139 @see CEikApplication */
140 virtual CDictionaryStore* OpenIniFileLC(RFs& aFs)const=0;
143 IMPORT_C virtual TFileName AppFullName()const; // returns the full path and name of the app
144 /** Returns the capabilities of the application.
146 Application capability information is represented by an instance of a TApaAppCapability
147 object wrapped in a packaged modifiable buffer descriptor.
149 The function is called from a number of places within the application framework.
151 An implementation of this function is supplied by the UI framework.
153 @param aInfo A packaged modifiable buffer descriptor (a TPckgBuf), encapsulating
154 a TApaAppCapability object.
156 @see TApaAppCapability
158 virtual void Capability(TDes8& aInfo)const=0;
161 IMPORT_C TFileName DllName()const;
163 IMPORT_C ~CApaApplication();
165 // formerly a reserved virtual, Reserved_1()
166 IMPORT_C virtual void NewAppServerL(CApaAppServer*& aAppServer);
168 IMPORT_C CApaApplication();
170 IMPORT_C virtual void CApaApplication_Reserved1();
171 IMPORT_C virtual void CApaApplication_Reserved2();
174 CApaAppHolder* iAppHolder; // the CApaAppHolder that owns me
175 TUid iDtorKey; // TInt iSpare;
176 friend class CApaAppHolder;
177 friend class CApaProcess;
178 friend class TApaApplicationFactory; // so that it can access iDtorKey
181 TInt iCApaApplication_Reserved1;
184 class CApaDocument : public CBase
185 // base class for documents; allows insertion of glass doors.
186 /** Defines basic behaviour for documents.
188 This is the base class for all documents. A document contains the data associated
189 with the application's content.
191 The class is derived from by the UI framework and is further derived from
192 by the UI application.
200 /** CApaDocument capabilities.*/
203 IMPORT_C TCapability();
205 inline TBool CanDrawGlass()const;
206 inline TBool CanPrint()const;
207 inline void SetCanDrawGlass();
208 inline void SetCanPrint();
217 TInt TCapability_Reserved1;
221 // document instantiation functions
222 /** Initialises a new, empty, document with a default setup.
224 This can be the main document or an embedded document. The function is called
225 by the UI framework when it creates a default document file.
227 An implementation of this function must be supplied by the UI application.
229 If initialisation fails, the document must be left in the same state as it
230 was before the function was called. */
231 virtual void NewDocumentL()=0; // builds a new embedded or main document without loading from a store (may create the content from eg code or a template file).
233 /** Creates and fully initialises a new filestore and stores the document into it,
234 replacing any existing file of the same name.
236 The function should put the pointer to the filestore object onto the cleanup
239 An implementation of this function is supplied by the UI framework.
241 @param aFs Handle to a file server session.
242 @param aFileName The full path name of the file to be created.
243 @return A pointer to the newly constructed file store.
245 virtual CFileStore* CreateFileStoreLC(RFs& aFs,const TDesC& aFileName)=0; // creates a file for a document and stores itself to that store (store should be put on cleanup stack).
247 // interaction functions
248 IMPORT_C virtual CPicture* GlassPictureL(); // Does nothing by default, override to return handle to glass picture.
250 /** Starts an editing session on an embedded document.
252 The function should cause the application's UI to be created and the document
253 to be fully restored for editing.
255 An implementation of this function is supplied by the UI framework.
257 @param aContainer This document's observer.
258 @param aReadOnly True, the document should be opened in read-only mode and
259 should not persist any changes made to the content. False, the document can
260 be opened in read/write mode; this is the default.
262 virtual void EditL(MApaEmbeddedDocObserver* aContainer,TBool aReadOnly=EFalse)=0; // Edit the document in the context of the container's environment. If aContainer is null, edit as the main document
264 /** Prints the document without a need for it to be open for editing.
266 Typically, this is called from a shell or a file manager type application
267 that wants to print the document without opening it fully.
269 An empty implementation of this function is supplied by the UI framework.
271 The UI application can provide its own implementation.
273 @param aSourceStore A reference to the store containing the document.
275 virtual void PrintL(const CStreamStore& aSourceStore)=0; // default print parameters, assume print context supplied by environment
277 // persistence functions
279 /** Stores the document to the current file, commits the changes, and marks the
280 document status as unchanged.
282 Typically, the function is called by the application when it implements a
283 "Save" type menu option in its User Interface.
285 An implementation of this function is supplied by the UI framework. This is
286 adequate for direct file store applications. Applications using a permanent
287 file store model, need to provide their own implementation.
289 If the function leaves, an implementation should ensure that any changes made
290 to the file are rolled back, leaving the file in the state it was in before
291 the function was called.
294 virtual void SaveL()=0; // save the doc to the file in the custody of iAppProcess. This fn should be called by any "Save" menu option. store->Commit() should be called within it.
295 /** Stores the document's content and state to the specified store, recording the
296 identity of any headstreams created in the specified stream dictionary.
298 The store must be fully constructed before this function is called.
300 An empty implementation of this function is supplied by the UI framework.
301 UI applications that need to persist any data must provide their own implementation.
303 If the function leaves, an implementation should ensure that the store and
304 the stream dictionary are returned to the state they were in before the function
307 @param aStore The store into which document data is to be stored.
308 @param aStreamDic The stream dictionary into which stream IDs and associated
309 UIDs are to be recorded.
311 virtual void StoreL(CStreamStore& aStore,CStreamDictionary& aStreamDic) const=0; // store to aStore, lodging the headstream in aStreamDic
313 /** Restores the document's content and state from data persisted in the specified
316 An empty implementation of this function is supplied by the UI framework.
317 UI applications that need to restore data must provide their own implementation.
319 If the function leaves, an implementation should ensure that the store and
320 the stream dictionary are returned to the state they were in before the function
323 @param aStore The store from which document data is to be restored.
324 @param aStreamDic The stream dictionary containing stream IDs and associated
327 virtual void RestoreL(const CStreamStore& aStore,const CStreamDictionary& aStreamDic)=0; // restore from aStore using aStreamDic
329 /** Restores the document to the extent that it does not need the store
332 A document only keeps a pointer to a store if it implements deferred
333 loading. This also tells the document that any store pointer that it
334 might have is just about to become invalid.
336 An empty implementation of this function is supplied by the UI framework.
337 UI applications that support deferred loading or embedding should provide an
340 If a document supports embedding, then it should
341 propagate the DetachFromStoreL() call on to all embedded objects that
344 If the function leaves, the operation should be aborted
345 because the document has not successfully detached from the store.
346 Continuing with the operation may leave the document in an unsafe
347 state or cause user data to be lost.
349 @param aDegree The degree of detachment required. */
350 virtual void DetachFromStoreL(CPicture::TDetach /*aDegree*/=CPicture::EDetachFull) {} // supply an implementation if you support deferred loading or embedding
352 IMPORT_C virtual void ExternalizeL(RWriteStream& aStream)const;
356 /** Tests whether the document is empty.
358 The UI framework provides a default implementation which always returns a
361 The UI application can provide its own implementation. Typically, any application
362 that has editable content should supply an implementation that acts according
363 to the state of that content. Applications without associated document data
364 need not supply an implementation.
366 @return True if the document is empty, false otherwise.
368 virtual TBool IsEmpty()const=0; // return ETrue if the document is empty
369 IMPORT_C virtual void ValidatePasswordL()const; // return EFalse if there *is* a password *and* the user doesn't get it right, ETrue otherwise (ie they get it right or there isn't one). Returns ETrue by default
371 IMPORT_C virtual TCapability Capability()const; // returns "cant do anything" by default
372 inline CApaApplication* Application()const;
373 inline CApaProcess* Process()const;
375 /** Tests whether the document has changed since it was last persisted.
377 An implementation of this function is supplied by the UI framework and need
378 not be changed by the UI application.
380 @return True, if the document has changed since the last time that it was
381 persisted, false, otherwise.
383 virtual TBool HasChanged()const =0;
385 IMPORT_C virtual ~CApaDocument();
387 IMPORT_C CApaDocument();
388 IMPORT_C CApaDocument(CApaApplication& aApp,CApaProcess& aProcess);
390 IMPORT_C virtual void OpenFileL(CFileStore*& aFileStore, RFile& aFile); // was previously Reserved_1
391 // Reserved virtual functions...
392 IMPORT_C virtual void Reserved_2();
394 MApaEmbeddedDocObserver* iContainer; // null unless this is an embedded object currently being edited
396 CApaApplication* iApplication; // the doc's associated application
397 CApaProcess* iApaProcess;
403 class TApaApplicationFactory
404 /** Encapsulates the functionality of creating an application, whether it be via a factory function
405 or an ECOM plugin. Instances of this class can usually be created implicitly when required as
406 function parameters - just specify the function pointer, ECOM plugin UID or CImplementationInformation
415 typedef CApaApplication* (*TFunction)();
417 IMPORT_C TApaApplicationFactory();
418 IMPORT_C TApaApplicationFactory(TFunction aFunction);
419 IMPORT_C TApaApplicationFactory(const CImplementationInformation& aEmbeddedApplicationInformation);
420 IMPORT_C TApaApplicationFactory(TUid aEmbeddedApplicationUid);
421 CApaApplication* CreateApplicationL() const;
422 HBufC* AppFileNameL() const;
423 TUid AppFileUid() const;
427 ETypeFunction, // if iType is this, iData is a TFunction
428 ETypeEmbeddedApplicationInformation, // if iType is this, iData is an ECOM CImplementationInformation
429 ETypeEmbeddedApplicationUid // if iType is this, iData is an ECOM implementation TUid
432 static CApaApplication* CreateEmbeddedApplicationL(TUid aUid);
433 static HBufC* EmbeddedApplicationDisplayNameLC(TUid aUid);
434 static HBufC* FullAppFileNameL(const TDesC& aAppName);
435 static void CleanupImplementationArray(TAny* aImplementationArray);
439 mutable CApaApplication* iApplication; // used to be iSpare1
443 class CApaParentProcessMonitor;
445 class CApaProcess : public CBase
446 /** Maintains a list of documents and all of the potentially shared resources used
449 This includes the application DLLs. The class also supplies utility functions
450 that provide the basic structure for persisted document files.
452 The class deals with the loading of application DLLs and manages the creation
453 and destruction of application (CApaApplication) objects and document (CApaDocument)
456 The class is derived from by the UI framework and further derivation by the
457 UI application is not necessary unless it needs to add extra utility functions
458 for the use of applications.
466 IMPORT_C static CApaProcess* NewL(const RFs& aFs);
467 IMPORT_C void ResetL();
469 // static utility functions
470 IMPORT_C static CStreamDictionary* ReadRootStreamLC(RFs& aFs,CFileStore*& aStore,const TDesC& aDocFullFileName,TUint aFileMode); // opens aDocFileName as aStore and returns the stream dictionary contained in its root stream on the cleanup stack
471 IMPORT_C static CStreamDictionary* ReadRootStreamLC(CFileStore*& aStore, const RFile& aFile);
472 IMPORT_C static void WriteRootStreamL(CPersistentStore& aStore,CStreamDictionary& aStreamDic,const CApaApplication& aApp);
473 IMPORT_C static void WriteRootStreamL(CPersistentStore& aStore,CStreamDictionary& aStreamDic,const TApaAppIdentifier& aAppId);
474 IMPORT_C static TApaAppIdentifier ReadAppIdentifierL(const CStreamStore& aStore,const CStreamDictionary& aStreamDic);
475 IMPORT_C static void WriteAppIdentifierL(CStreamStore& aStore,CStreamDictionary& aStreamDic,const TApaAppIdentifier& aAppId);
477 // document management
478 IMPORT_C CApaDocument* AddNewDocumentL(TApaApplicationFactory aApplicationFactory);
479 IMPORT_C CApaDocument* OpenNewDocumentL(CFileStore*& aStore,CStreamDictionary*& aStreamDic,const TDesC& aDocFullFileName,TUint aFileMode); // Open a file and restore the contained document
480 IMPORT_C void DestroyDocument(CApaDocument* aDoc); // Removes a doc (identified by the object) from the list and destroys it. Also removes the app and closes the AppDll if appropriate.
483 IMPORT_C void SetMainDocument(CApaDocument* aDocument);
484 IMPORT_C void SetMainDocFileName(const TDesC& aMainDocFileName); // panics if the descriptor is too long
485 IMPORT_C void SetMainDocFileNameL(const TDesC& aMainDocFileName);
487 // accessor functions
488 IMPORT_C TPtrC MainDocFileName()const;
489 inline RFs& FsSession()const;
490 inline CApaDocument* MainDocument()const;
492 IMPORT_C ~CApaProcess();
494 IMPORT_C CApaProcess();
495 IMPORT_C CApaProcess(const RFs& aFs);
496 IMPORT_C void ConstructL();
497 IMPORT_C void ConstructL(TProcessId aParentProcessId);
499 IMPORT_C virtual void CApaProcess_Reserved1();
500 IMPORT_C virtual void CApaProcess_Reserved2();
502 static TInt IdleRemoveApplications(TAny* aThis);
503 void RemoveMarkedApplications();
505 CApaDll* AddAppDllL(const TDesC& aDllFullPath);
506 CApaExe* AddAppExeL(TApaApplicationFactory aApplicationFactory);
507 void RemoveApp(CApaAppHolder* aAppHolder);
508 CApaDocument* CreateDocL(CApaApplication* aApp);
509 CApaAppHolder* FindAppInListL(const TDesC& aAppFileName,TUid aUid)const; // returns NULL if not in list
510 void DeleteAllDocs();
511 void MarkApplicationForRemoval(const CApaApplication* aApp);
512 static void DoReadRootStreamL(CStreamDictionary& aStreamDictionary, const CFileStore& aStore);
514 CArrayFixFlat<TApaAppHolderInfo>* iAppList; // array of apps in use
515 CArrayFixFlat<CApaDocument*>* iDocList; // array of documents (1 main + n embedded)
516 CApaDocument* iMainDoc;
517 HBufC* iMainDocFileName;
518 RFs iFsSession; // file server session for doc store
519 CIdle* iApplicationRemover;
520 CApaParentProcessMonitor* iMonitor;
521 TInt iCApaProcess_Reserved1;
525 class MApaEmbeddedDocObserver
526 /** An interface class for handling the completion of the editing of an embedded
531 @see CApaDocument::EditL() */
534 /** Defines the state of the embedded document on completion of editing. */
536 /** Changes to the embedded document must be saved. */
538 /** Reverts back to the saved version of the embedded document, i.e. reloads the
541 /** No changes have been made to the embedded document. */
543 /** The embedded document is empty. */
547 /** Implements the required behaviour when the editing of an embedded document completes.
549 @param aMode Indicates the state of the document. */
550 virtual void NotifyExit(TExitMode aMode)=0; // called on completion of editing of an embedded document
552 IMPORT_C MApaEmbeddedDocObserver();
554 IMPORT_C virtual void MApaEmbeddedDocObserver_Reserved1();
555 IMPORT_C virtual void MApaEmbeddedDocObserver_Reserved2();
557 TInt iMApaEmbeddedDocObserver_Reserved1;
562 inline CApaApplication* CApaDocument::Application()const
563 /** Returns a pointer to the application that created the document.
565 @return A pointer to the document's associated application. */
566 { return iApplication; }
568 inline CApaProcess* CApaDocument::Process()const
569 /** Returns a pointer to the application process associated with this document.
571 @return A pointer to the application process associated with this document. */
572 { return iApaProcess; }
574 inline TBool CApaDocument::TCapability::CanDrawGlass()const
575 /** Tests whether the document supports being embedded as a glass door.
577 @return True if embedding as a glass door is supported; false otherwise. */
578 { return iCapability&ECanDrawGlass; }
580 inline TBool CApaDocument::TCapability::CanPrint()const
581 /** Tests whether the document supports being printed without using the full application
584 @return True, if printing is supported; false, otherwise. */
585 { return iCapability&ECanPrint; }
587 inline void CApaDocument::TCapability::SetCanDrawGlass()
588 /** Sets the document as being capable of being embedded as a glass door. */
589 { iCapability = iCapability|ECanDrawGlass; }
591 inline void CApaDocument::TCapability::SetCanPrint()
592 /** Sets the document as being capable of being printed without using the full application
594 { iCapability = iCapability|ECanPrint; }
596 inline RFs& CApaProcess::FsSession()const
597 /** Returns a handle to the file server session used by this application process.
599 @return The file server session. */
600 { return (RFs&)iFsSession; } //lint !e1536 Exposing low access member - Kept for backward BC
602 inline CApaDocument* CApaProcess::MainDocument()const
603 /** Returns a pointer to the main document.
605 @return A pointer to the main document. */