// TSTAPP.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#ifndef __TSTAPP_H__
#define __TSTAPP_H__

#if !defined(__APPARC_H__)
#include <apparc.h>
#endif

#include <apgdoor.h>

// classes defined:
class CTestApp;
class CTestAppDoc;
//

#define KTestAppDefaultFileName _L("TestApp.doc")
const TInt KTestAppUidValue=10;
const TUid KUidTestApp={KTestAppUidValue};
const TUid KUidTestAppHeadStream={200};
const TInt KNarrowRelUidValue=268435578;
const TUid KUidNarrowRel={KNarrowRelUidValue}; // so it'll run under arm...
#define KTestAppUidType TUidType(KUidNarrowRel,KUidApp,KUidTestApp)


class CTestApp : public CApaApplication
	{
public:
	static CTestApp* NewL(); // the gated function
	// from CApaApplication
	void PreDocConstructL();
	CApaDocument* CreateDocumentL(CApaProcess* aProcess);
	TDesC& Caption(); // return the app title in current system language
	TUid AppDllUid()const;
	CApaAppInfoFileReader* OpenAppInfoFileLC() const;
	CDictionaryStore* OpenIniFileLC(RFs& aFs)const;
	void Capability(TDes8& aInfo)const;
	//
	~CTestApp();
protected:
	CTestApp();
private:
	TBuf<8> iCaption;
	TApaAppCapabilityBuf* iCapabilityBuf;
	};

class CTestAppDoc : public CApaDocument, public MApaEmbeddedDocObserver
	{
public:
	static CTestAppDoc* NewL(CApaApplication& aApp,CApaProcess& aProcess);
	~CTestAppDoc();
	//
	inline void EmbedNewDocL(const TDesC& aDllFileName); // exported so I can call it from testcode
	inline void EditEmbeddedDocL(TInt aDocNum) {EmbeddedDoor(aDocNum)->DocumentL()->EditL(this);}
	inline CApaDoor* EmbeddedDoor(TInt aDocNum)const {return (CApaDoor*)((*iEmbedList)[aDocNum].iPicture.AsPtr());}
	//
// from MApaEmbeddedDocObserver
	void NotifyExit(MApaEmbeddedDocObserver::TExitMode aMode);
// from CApaDocument
	void NewDocumentL(); 
	CFileStore* CreateFileStoreLC(RFs& aFs,const TDesC& aFileName);
	void SaveL();
	//
	void PrintL(const CStreamStore& aSourceStore);
	void EditL(MApaEmbeddedDocObserver* aContainer,TBool aReadOnly); 
	TBool IsEmpty()const; // return ETrue if the document is empty
	TBool HasChanged()const;
	//
	// storage functions
	void StoreL(CStreamStore& aStore,CStreamDictionary& aStreamDic)const;
	void RestoreL(const CStreamStore& aStore,const CStreamDictionary& aStreamDic);
	void DetachFromStoreL(CPicture::TDetach aDegree);
protected:
	CTestAppDoc(CApaApplication& aApp,CApaProcess& aProcess);
	void ConstructL();
	//
	void InternalizeL(RReadStream& aStream);
	void ExternalizeL(RWriteStream& aStream)const;
	void StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap)const;
	void RestoreComponentsL(const CStreamStore& aStore);
	//
	// utility functions
public:
	TInt iValue; // the "contents" of this test document
	CArrayFixFlat<TPictureHeader>* iEmbedList;
	CStreamStore* iStore;
	TBool iHasChanged;
	};


inline void CTestAppDoc::EmbedNewDocL(const TDesC& aDllFileName)
	{
	TPictureHeader header;
	header.iPictureType = KUidPictureTypeDoor;
	//
	CApaDocument* doc=Process()->AddNewDocumentL(aDllFileName);
	//
	header.iPicture = CApaDoor::NewLC(*doc,TSize(500,500));
	//
	iEmbedList->AppendL(header);
	CleanupStack::Pop(); // iPicture
	}


#endif