home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / eikon / pdf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  5.6 KB  |  285 lines

  1. // PDF.CPP
  2. //
  3. // Copyright (c) 1999 Sander van der Wal.  All rights reserved.
  4. //
  5. // $Id: pdf.cpp 1.1 2000-09-17 13:18:08+02 svdwal Exp svdwal $
  6. //
  7. // $Log: pdf.cpp $
  8. // Revision 1.1  2000-09-17 13:18:08+02  svdwal
  9. // Initial checkin
  10. //
  11.  
  12. #include "pdf.h"
  13.  
  14. // --o EIKON
  15. #include <eikapp.h>
  16. #include <eikenv.h>
  17. #include <eikproc.h>
  18.  
  19. // User interface
  20. #include "PdfAppUi.h"
  21.  
  22. // Engine
  23. #include "PdfDocument.h"
  24.  
  25. // --o PDFLib
  26. #include "PDFDoc.h"
  27. #include "PDFGlobal.h"
  28. #include <sys/reent.h> // for CloseSTDLIB
  29.  
  30. #include "Pdf.rsg"
  31.  
  32. // Profiling
  33. #include "PROFILE.H"
  34.  
  35.  
  36. // locals
  37. static const TInt KBusyInitialDelay=1000000; // in microseconds
  38.  
  39.  
  40. ////////////////////////////////////////////////////////////////////////////
  41. //
  42. // CPdfDocument
  43. //
  44. /////////////////////////////////////////////////////////////////////////////
  45. CPdfDocument::CPdfDocument(CEikApplication& aApp)
  46.   : CEikDocument(aApp)
  47. {}
  48.  
  49.  
  50. CPdfDocument::~CPdfDocument()
  51. {
  52.   delete iDoc;
  53.  
  54.   // release all of the STDLIB resources associated with this thread
  55.   // Satisfies the CONE policy that the heap should be balanced across 
  56.   // the lifetime of a CCoeEnv.
  57.   CloseSTDLIB();
  58. }
  59.  
  60.  
  61. CEikAppUi* CPdfDocument::CreateAppUiL()
  62. {
  63.   return new(ELeave) CPdfAppUi;
  64. }
  65.  
  66.  
  67. CFileStore* CPdfDocument::OpenFileL(TBool aDoOpen,const TDesC& aFilename,RFs& /* aFs */)
  68. {
  69.   if (aDoOpen)
  70.     DoOpenFileL(aFilename);
  71.   return 0;
  72. }
  73.  
  74.  
  75. void CPdfDocument::DoOpenFileL(const TFileName& aFileName)
  76. {
  77.   PROFILE_START(CPDFDOCUMENT__DOOPENFILEL);
  78.   
  79.   CEikonEnv::Static()->BusyMsgL(R_OPENING_DOC, KBusyInitialDelay);
  80.    
  81.   PDFDoc* newDoc = new(ELeave) PDFDoc();
  82.   CleanupStack::PushL(newDoc);
  83.   newDoc->ConstructL(Process()->FsSession(), aFileName);
  84.   CleanupStack::Pop(); // newDoc
  85.  
  86.   if (newDoc->isOk()) {
  87.   
  88.     // now it is safe to replace the old doc with the new doc
  89.     delete iDoc;
  90.     iDoc=newDoc;
  91.     
  92.     // reset the main store
  93.     ((CEikProcess*)Process())->SetMainStore(0); 
  94.  
  95.     // Set the file name as the main file name
  96.     Process()->SetMainDocFileName(aFileName);
  97.   }
  98.   else
  99.     delete newDoc;
  100.   
  101.   CEikonEnv::Static()->BusyMsgCancel();
  102.   
  103.   PROFILE_STOP(CPDFDOCUMENT__DOOPENFILEL);
  104. }
  105.  
  106.  
  107. PDFDoc* CPdfDocument::Model() const
  108. {
  109.   return iDoc;
  110. }
  111.  
  112.  
  113.  
  114. //////////////////////////////////////////////////////////////////////////////
  115. //
  116. // CPdfApplication
  117. //
  118. //////////////////////////////////////////////////////////////////////////////
  119.  
  120. class CPdfApplication: public CEikApplication
  121. {
  122. // -- CEikApplication
  123. private:
  124.   TUid AppDllUid() const { return(KUidpdf); } ;
  125.   CApaDocument* CreateDocumentL();
  126.   void GetDefaultDocumentFileName(TFileName& aDocumentName) const;
  127. };
  128.  
  129.  
  130. CApaDocument* CPdfApplication::CreateDocumentL()
  131. {
  132.   return new(ELeave) CPdfDocument(*this);
  133. }
  134.  
  135.  
  136. // We do not want a default document created
  137. void CPdfApplication::GetDefaultDocumentFileName(TFileName& aDocumentName) const
  138. {
  139.   aDocumentName.Zero();
  140.  
  141.  
  142. //
  143. // EXPORTed functions
  144. //
  145. EXPORT_C CApaApplication* NewApplication()
  146. {
  147.   PROFILE_INIT();
  148.   
  149.   return(new CPdfApplication);
  150. }
  151.  
  152. //
  153. // EpocFontInfoGlobal
  154. //
  155. EpocFontInfoGlobal::EpocFontInfoGlobal()
  156. {
  157.   iWindowsLatin1Encoding = 0;
  158. }
  159.  
  160. TInt EpocFontInfoGlobal::Construct()
  161. {
  162.   // create the EPOC encodings, just the normal encoding
  163.   iWindowsLatin1Encoding = new FontEncoding();
  164.   if (!iWindowsLatin1Encoding)
  165.     return KErrNoMemory;
  166.   iWindowsLatin1Encoding->Construct(KEpocLatin1EncodingNames, KEpocLatin1EncodingSize);
  167.   
  168.   return KErrNone;
  169. }
  170.  
  171. EpocFontInfoGlobal::~EpocFontInfoGlobal()
  172. {
  173.   delete iWindowsLatin1Encoding;
  174. }
  175.  
  176.   
  177. //
  178. // PdfGlobal
  179. //
  180. PdfGlobal::PdfGlobal(){}
  181.  
  182. TInt PdfGlobal::Construct()
  183. {
  184.   TInt res = FontFile.Construct();
  185.  
  186.   if (res == KErrNone)
  187.     res = GfxFont.Construct();
  188.   
  189.   if (res == KErrNone)
  190.     res = Epoc.Construct();
  191.  
  192.   return res;
  193. }
  194.  
  195. PdfGlobal::~PdfGlobal(){}
  196.  
  197.  
  198. ////////////////////////////////////////////////
  199. //
  200. // DLL entry point
  201. //
  202. ////////////////////////////////////////////////
  203. //
  204. // There are problems with allocation under WINS. The workaround is 
  205. // to allocate one global data area and access it through a pointer
  206. // as under MARM. This way we minimize platform differences.
  207. //
  208. #if defined(__WINS__)
  209.  
  210. PdfGlobal __globalData;
  211. static TBool __globalData_init = EFalse;
  212.  
  213. GLDEF_C TInt E32Dll(TDllReason /* aReason */)
  214. {
  215.   if (__globalData_init)
  216.     return KErrNone;
  217.   
  218.   __globalData_init = ETrue;
  219.   return __globalData.Construct();
  220.    
  221. }
  222.  
  223. #endif
  224.  
  225.  
  226. #if defined(__MARM__)
  227.  
  228. GLDEF_C TInt E32Dll(TDllReason aReason)
  229. {
  230.   TInt res=KErrNone;
  231.   PdfGlobal* globalData;
  232.   switch (aReason) {
  233.   case EDllThreadAttach:
  234.     globalData=new PdfGlobal; 
  235.     if (globalData == 0)
  236.       res = KErrNoMemory;
  237.     else {
  238.       res = globalData->Construct();
  239.       if (res != KErrNone)
  240.         delete globalData; 
  241.       else
  242.         Dll::SetTls(globalData);
  243.     }
  244.     break;
  245.     
  246.   case EDllThreadDetach:
  247.     delete &Global();
  248.     Dll::SetTls(NULL);
  249.     break;
  250.     
  251.   default:
  252.     break;
  253.   }
  254.   return res;
  255. }
  256.  
  257. #endif
  258.  
  259.  
  260. #if defined(__WINS__)
  261.  
  262. /////////////////////////////////////////////////////
  263. //
  264. // Visual C++ 6.0 Introductionary version wants this
  265. //
  266. /////////////////////////////////////////////////////
  267. extern "C" void __pfnBkCheck() {}
  268.  
  269.  
  270. /////////////////////////////////////////////////////
  271. //
  272. // Otherwise it will not link. Don't know why
  273. //
  274. /////////////////////////////////////////////////////
  275. #include <stdlib_r.h>
  276. #undef atexit
  277. extern "C" int atexit(void (* /* func */)(void))
  278. {
  279.   return 0; //_epoc32_atexit(func);
  280. }
  281.  
  282. #endif
  283.  
  284.