home *** CD-ROM | disk | FTP | other *** search
- // PDF.CPP
- //
- // Copyright (c) 1999 Sander van der Wal. All rights reserved.
- //
- // $Id: pdf.cpp 1.1 2000-09-17 13:18:08+02 svdwal Exp svdwal $
- //
- // $Log: pdf.cpp $
- // Revision 1.1 2000-09-17 13:18:08+02 svdwal
- // Initial checkin
- //
-
- #include "pdf.h"
-
- // --o EIKON
- #include <eikapp.h>
- #include <eikenv.h>
- #include <eikproc.h>
-
- // User interface
- #include "PdfAppUi.h"
-
- // Engine
- #include "PdfDocument.h"
-
- // --o PDFLib
- #include "PDFDoc.h"
- #include "PDFGlobal.h"
- #include <sys/reent.h> // for CloseSTDLIB
-
- #include "Pdf.rsg"
-
- // Profiling
- #include "PROFILE.H"
-
-
- // locals
- static const TInt KBusyInitialDelay=1000000; // in microseconds
-
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // CPdfDocument
- //
- /////////////////////////////////////////////////////////////////////////////
- CPdfDocument::CPdfDocument(CEikApplication& aApp)
- : CEikDocument(aApp)
- {}
-
-
- CPdfDocument::~CPdfDocument()
- {
- delete iDoc;
-
- // release all of the STDLIB resources associated with this thread
- // Satisfies the CONE policy that the heap should be balanced across
- // the lifetime of a CCoeEnv.
- CloseSTDLIB();
- }
-
-
- CEikAppUi* CPdfDocument::CreateAppUiL()
- {
- return new(ELeave) CPdfAppUi;
- }
-
-
- CFileStore* CPdfDocument::OpenFileL(TBool aDoOpen,const TDesC& aFilename,RFs& /* aFs */)
- {
- if (aDoOpen)
- DoOpenFileL(aFilename);
- return 0;
- }
-
-
- void CPdfDocument::DoOpenFileL(const TFileName& aFileName)
- {
- PROFILE_START(CPDFDOCUMENT__DOOPENFILEL);
-
- CEikonEnv::Static()->BusyMsgL(R_OPENING_DOC, KBusyInitialDelay);
-
- PDFDoc* newDoc = new(ELeave) PDFDoc();
- CleanupStack::PushL(newDoc);
- newDoc->ConstructL(Process()->FsSession(), aFileName);
- CleanupStack::Pop(); // newDoc
-
- if (newDoc->isOk()) {
-
- // now it is safe to replace the old doc with the new doc
- delete iDoc;
- iDoc=newDoc;
-
- // reset the main store
- ((CEikProcess*)Process())->SetMainStore(0);
-
- // Set the file name as the main file name
- Process()->SetMainDocFileName(aFileName);
- }
- else
- delete newDoc;
-
- CEikonEnv::Static()->BusyMsgCancel();
-
- PROFILE_STOP(CPDFDOCUMENT__DOOPENFILEL);
- }
-
-
- PDFDoc* CPdfDocument::Model() const
- {
- return iDoc;
- }
-
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // CPdfApplication
- //
- //////////////////////////////////////////////////////////////////////////////
-
- class CPdfApplication: public CEikApplication
- {
- // -- CEikApplication
- private:
- TUid AppDllUid() const { return(KUidpdf); } ;
- CApaDocument* CreateDocumentL();
- void GetDefaultDocumentFileName(TFileName& aDocumentName) const;
- };
-
-
- CApaDocument* CPdfApplication::CreateDocumentL()
- {
- return new(ELeave) CPdfDocument(*this);
- }
-
-
- // We do not want a default document created
- void CPdfApplication::GetDefaultDocumentFileName(TFileName& aDocumentName) const
- {
- aDocumentName.Zero();
- }
-
-
- //
- // EXPORTed functions
- //
- EXPORT_C CApaApplication* NewApplication()
- {
- PROFILE_INIT();
-
- return(new CPdfApplication);
- }
-
- //
- // EpocFontInfoGlobal
- //
- EpocFontInfoGlobal::EpocFontInfoGlobal()
- {
- iWindowsLatin1Encoding = 0;
- }
-
- TInt EpocFontInfoGlobal::Construct()
- {
- // create the EPOC encodings, just the normal encoding
- iWindowsLatin1Encoding = new FontEncoding();
- if (!iWindowsLatin1Encoding)
- return KErrNoMemory;
- iWindowsLatin1Encoding->Construct(KEpocLatin1EncodingNames, KEpocLatin1EncodingSize);
-
- return KErrNone;
- }
-
- EpocFontInfoGlobal::~EpocFontInfoGlobal()
- {
- delete iWindowsLatin1Encoding;
- }
-
-
- //
- // PdfGlobal
- //
- PdfGlobal::PdfGlobal(){}
-
- TInt PdfGlobal::Construct()
- {
- TInt res = FontFile.Construct();
-
- if (res == KErrNone)
- res = GfxFont.Construct();
-
- if (res == KErrNone)
- res = Epoc.Construct();
-
- return res;
- }
-
- PdfGlobal::~PdfGlobal(){}
-
-
- ////////////////////////////////////////////////
- //
- // DLL entry point
- //
- ////////////////////////////////////////////////
- //
- // There are problems with allocation under WINS. The workaround is
- // to allocate one global data area and access it through a pointer
- // as under MARM. This way we minimize platform differences.
- //
- #if defined(__WINS__)
-
- PdfGlobal __globalData;
- static TBool __globalData_init = EFalse;
-
- GLDEF_C TInt E32Dll(TDllReason /* aReason */)
- {
- if (__globalData_init)
- return KErrNone;
-
- __globalData_init = ETrue;
- return __globalData.Construct();
-
- }
-
- #endif
-
-
- #if defined(__MARM__)
-
- GLDEF_C TInt E32Dll(TDllReason aReason)
- {
- TInt res=KErrNone;
- PdfGlobal* globalData;
- switch (aReason) {
- case EDllThreadAttach:
- globalData=new PdfGlobal;
- if (globalData == 0)
- res = KErrNoMemory;
- else {
- res = globalData->Construct();
- if (res != KErrNone)
- delete globalData;
- else
- Dll::SetTls(globalData);
- }
- break;
-
- case EDllThreadDetach:
- delete &Global();
- Dll::SetTls(NULL);
- break;
-
- default:
- break;
- }
- return res;
- }
-
- #endif
-
-
- #if defined(__WINS__)
-
- /////////////////////////////////////////////////////
- //
- // Visual C++ 6.0 Introductionary version wants this
- //
- /////////////////////////////////////////////////////
- extern "C" void __pfnBkCheck() {}
-
-
- /////////////////////////////////////////////////////
- //
- // Otherwise it will not link. Don't know why
- //
- /////////////////////////////////////////////////////
- #include <stdlib_r.h>
- #undef atexit
- extern "C" int atexit(void (* /* func */)(void))
- {
- return 0; //_epoc32_atexit(func);
- }
-
- #endif
-
-