home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / gw / oddev.exe / DOCUMENT.CPP < prev    next >
C/C++ Source or Header  |  1994-07-15  |  5KB  |  199 lines

  1. /* document.cpp - Document class for ODMA sample DMS.
  2.  *
  3.  * COPYRIGHT (C) 1994
  4.  * SoftSolutions Technology Corporation
  5.  * Orem, Utah  USA
  6.  * All Rights Reserved
  7.  */
  8.  
  9. #include <windows.h>
  10. #include <dos.h>
  11. #include "odmasamp.h"
  12.  
  13.  
  14. Document::Document()
  15. {
  16.     Init();
  17. }
  18.  
  19. Document::Document( LPSTR lpszFormat, LPSTR lpszDocLocation )
  20. {
  21.     Init();
  22.     strncpy( Format, lpszFormat, sizeof(Format) );
  23.     Format[sizeof(Format)-1] = '\0';
  24.     if (lpszDocLocation) {
  25.         strncpy( DocLocation, lpszDocLocation, sizeof(DocLocation) );
  26.         DocLocation[sizeof(DocLocation)-1] = '\0';
  27.         DocAccessed = 1;
  28.     }
  29. }
  30.  
  31. Document::Document( Document *pOldDoc )
  32. {
  33.     Init();
  34.     strcpy( Author, pOldDoc->Author );
  35.     strcpy( Name, pOldDoc->Name );
  36.     strcpy( DocType, pOldDoc->DocType );
  37.     strcpy( Format, pOldDoc->Format );
  38. }
  39.  
  40.  
  41. // Load a document saved from a previous session
  42. Document::Document( LPSTR lpszDocId )
  43. {
  44.     strcpy( DocId, lpszDocId );
  45.     SaveFlag = 0;
  46.     OpenCount = 0;
  47.     DocAccessed = 1;    // It was accessed in a previous session.
  48.     GetPrivateProfileString( DocId, "Author", "", Author, sizeof(Author), "ODMASAMP.INI" );
  49.     GetPrivateProfileString( DocId, "Name", "", Name, sizeof(Name), "ODMASAMP.INI" );
  50.     GetPrivateProfileString( DocId, "DocType", "", DocType, sizeof(DocType), "ODMASAMP.INI" );
  51.     GetPrivateProfileString( DocId, "Format", "", Format, sizeof(Format), "ODMASAMP.INI" );
  52.     GetPrivateProfileString( DocId, "DocLocation", "", DocLocation, sizeof(DocLocation), "ODMASAMP.INI" );
  53. }
  54.  
  55. void Document::Init( void )
  56. {
  57. #ifdef __BORLANDC__
  58.     struct time tm;
  59. #else
  60.     struct _dostime_t tm;
  61. #endif
  62.  
  63.     SaveFlag = 0;
  64.     Author[0] = '\0';
  65.     Name[0] = '\0';
  66.     DocType[0] = '\0';
  67.     OpenCount = 0;
  68.     Format[0] = '\0';
  69.     DocLocation[0] = '\0';
  70.     DocAccessed = 0;
  71.  
  72. #ifdef __BORLANDC__
  73.     gettime( &tm );
  74.     wsprintf( DocId, "%02d-%02d-%02d-%02d",
  75.         tm.ti_hour, tm.ti_min, tm.ti_sec, tm.ti_hund );
  76. #else
  77.     _dos_gettime( &tm );
  78.     wsprintf( DocId, "%02d-%02d-%02d-%02d",
  79.         tm.hour, tm.minute, tm.second, tm.hsecond );
  80. #endif
  81.  
  82. }
  83.  
  84. ODMSTATUS Document::Open( LPSTR lpszFileName )
  85. {
  86.     OpenCount++;
  87.     if (DocLocation[0] == '\0') {
  88.         GetTempFileName( 0, "ODM", 0, DocLocation );
  89.     }
  90.     strcpy( lpszFileName, DocLocation );
  91.     DocAccessed = 1;
  92.     return 0;
  93. }
  94.  
  95. ODMSTATUS Document::Close( DWORD activeTime, DWORD pagesPrinted,
  96.     LPVOID sessionData, WORD dataLen )
  97. {
  98.     OpenCount--;
  99.     return 0;
  100. }
  101.  
  102. ODMSTATUS Document::EditAttributes( HWND hParent )
  103. {
  104.     ProDlgData pdData;
  105.     int err;
  106.  
  107.     pdData.pDocument = this;
  108.     pdData.Mode = PROFILE_EDIT;
  109.  
  110.     err = DialogBoxParam( hInst, MAKEINTRESOURCE(PROFILE_DIALOG), hParent, (DLGPROC)ProfileProc,
  111.           (LPARAM)&pdData );
  112.     if (err == IDOK)
  113.         err = 0;
  114.     else
  115.         err = ODM_E_CANCEL;
  116.  
  117.     return err;
  118. }
  119.  
  120. ODMSTATUS Document::ShowAttributes( HWND hParent )
  121. {
  122.     ProDlgData pdData;
  123.  
  124.     pdData.pDocument = this;
  125.     pdData.Mode = 0;
  126.  
  127.     DialogBoxParam( hInst, MAKEINTRESOURCE(PROFILE_DIALOG), hParent, (DLGPROC)ProfileProc,
  128.           (LPARAM)&pdData );
  129.     return 0;
  130. }
  131.  
  132. ODMSTATUS Document::GetInfo( WORD item, LPSTR lpszData, WORD dataLen )
  133. {
  134.     ODMSTATUS err;
  135.     char *dataSource;
  136.     char buff[165];
  137.  
  138.     switch( item ) {
  139.         case ODM_AUTHOR: dataSource = Author; break;
  140.         case ODM_NAME: dataSource = Name; break;
  141.         case ODM_TYPE: dataSource = DocType; break;
  142.         case ODM_TITLETEXT:
  143.             wsprintf( buff, "%s - %s", (LPSTR)DocId, (LPSTR)Name );
  144.             dataSource = buff;
  145.             break;
  146.         case ODM_CONTENTFORMAT: dataSource = Format; break;
  147.         default: dataSource = NULL;
  148.     }
  149.  
  150.     if (dataSource) {
  151.         strncpy( lpszData, dataSource, dataLen );
  152.         lpszData[dataLen-1] = '\0';
  153.         err = 0;
  154.     } else
  155.         err = ODM_E_ITEM;
  156.  
  157.     return err;
  158. }
  159.  
  160. ODMSTATUS Document::SetInfo( WORD item, LPSTR lpszData )
  161. {
  162.     char *target;
  163.     int len;
  164.     ODMSTATUS err;
  165.  
  166.     switch( item ) {
  167.         case ODM_AUTHOR: target = Author; len = sizeof(Author); break;
  168.         case ODM_NAME: target = Name; len = sizeof(Name); break;
  169.         case ODM_TYPE: target = DocType; len = sizeof(DocType); break;
  170.         case ODM_CONTENTFORMAT: target = Format; len = sizeof(Format); break;
  171.         default: target = NULL;
  172.     }
  173.  
  174.     if (target) {
  175.         strncpy( target, lpszData, len );
  176.         target[len-1] = '\0';
  177.         err = 0;
  178.     } else
  179.         err = ODM_E_ITEM;
  180.  
  181.     return err;
  182. }
  183.  
  184.  
  185. void Document::SaveInfo( void )
  186. {
  187.     // Put the docId into the DocList section.
  188.     WritePrivateProfileString( "DocList", DocId, "", "ODMASAMP.INI" );
  189.  
  190.     // Put the document's info. into its own section
  191.     WritePrivateProfileString( DocId, "Author", Author, "ODMASAMP.INI" );
  192.     WritePrivateProfileString( DocId, "Name", Name, "ODMASAMP.INI" );
  193.     WritePrivateProfileString( DocId, "DocType", DocType, "ODMASAMP.INI" );
  194.     WritePrivateProfileString( DocId, "Format", Format, "ODMASAMP.INI" );
  195.     WritePrivateProfileString( DocId, "DocLocation", DocLocation, "ODMASAMP.INI" );
  196. }
  197.  
  198.  
  199.