home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / Epoc / Palmtime / files / FrotzCE2_src.ZIP / FrotzCE / FrotzCEDoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-11  |  2.3 KB  |  104 lines

  1. // FrotzCEDoc.cpp : implementation of the CFrotzCEDoc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "FrotzCE.h"
  6.  
  7. #include "FrotzCEDoc.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CFrotzCEDoc
  17.  
  18. IMPLEMENT_DYNCREATE(CFrotzCEDoc, CDocument)
  19.  
  20. BEGIN_MESSAGE_MAP(CFrotzCEDoc, CDocument)
  21.     //{{AFX_MSG_MAP(CFrotzCEDoc)
  22.         // NOTE - the ClassWizard will add and remove mapping macros here.
  23.         //    DO NOT EDIT what you see in these blocks of generated code!
  24.     //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CFrotzCEDoc construction/destruction
  29.  
  30. CFrotzCEDoc::CFrotzCEDoc()
  31. {
  32. }
  33.  
  34. CFrotzCEDoc::~CFrotzCEDoc()
  35. {
  36. }
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CFrotzCEDoc diagnostics
  40.  
  41. #ifdef _DEBUG
  42. void CFrotzCEDoc::AssertValid() const
  43. {
  44.     CDocument::AssertValid();
  45. }
  46.  
  47. void CFrotzCEDoc::Dump(CDumpContext& dc) const
  48. {
  49.     CDocument::Dump(dc);
  50. }
  51. #endif //_DEBUG
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CFrotzCEDoc commands
  55.  
  56. BOOL CFrotzCEDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  57. {
  58. CString strStoryFile = lpszPathName;
  59. char *pszStoryFile = FROTZCEAPP->m_achStoryFile;
  60.  
  61.     // Z machine not running?
  62.     if (!FROTZCEAPP->m_bZmachineRunning)
  63.     {
  64.     LPTSTR pszDefDir;
  65.     int i;
  66.  
  67.         if (!CDocument::OnOpenDocument(lpszPathName))
  68.             return FALSE;
  69.  
  70.         // Copy file name
  71.         FROTZCEAPP->m_strDefaultDir = strStoryFile;
  72.  
  73.         // Get file name buffer
  74.         i = FROTZCEAPP->m_strDefaultDir.GetLength();
  75.         pszDefDir = FROTZCEAPP->m_strDefaultDir.GetBuffer( i + 1 );
  76.  
  77.         // Go backwards in file name until first '\' is found
  78.         for (; i >= 0; i--)
  79.         {
  80.             // Found a directory specifier?
  81.             if (pszDefDir[i] == _T('\\') || pszDefDir[i] == _T('/'))
  82.             {
  83.                 pszDefDir[i] = 0;
  84.                 break;
  85.             }
  86.         }
  87.         // Resize string
  88.         FROTZCEAPP->m_strDefaultDir.ReleaseBuffer();
  89.  
  90.         // Convert wide char file name to single byte chars
  91.         for (i = 0; i < strStoryFile.GetLength(); i++)
  92.         {
  93.             pszStoryFile[i] = (char) strStoryFile[i];
  94.         }
  95.         pszStoryFile[strStoryFile.GetLength()] = '\0';
  96.  
  97.         // Start Z machine
  98.         FROTZCEAPP->StartZMachine();    
  99.     
  100.         return TRUE;
  101.     }
  102.     else return FALSE;
  103. }
  104.