home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / DraftWn.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  8KB  |  223 lines

  1. /* @(#)Z 1.37 com/src/docshell/DraftWn.cpp, odshell, od96os2, odos29712d 97/03/21 17:18:17 (97/01/20 16:48:26) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odshell
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. //
  30. //----------------------------------------------------------------------------
  31. // DraftWn.cpp - This file contains the DraftWindow class implementation.
  32. //               This class invokes and manages the draft history window.
  33. //----------------------------------------------------------------------------
  34. #include "DraftWn.h"
  35. #include "DocShell.h"
  36. #include "ShellUtl.h"
  37.  
  38. #undef LOGGING
  39. #define LOGGING 1
  40.  
  41. //////////////////////////////////////////////////////////////////////////////
  42. ////                           MEMBER FUNCTIONS                           ////
  43. //////////////////////////////////////////////////////////////////////////////
  44. //----------------------------------------------------------------------------
  45. // Constructor
  46. //----------------------------------------------------------------------------
  47. DraftWindow::DraftWindow(DocumentManager* docmgr, 
  48.                          WindowSystemData* wsdata,
  49.                          ODPlatformWindow hwnd)
  50.  
  51. {
  52.   Environment *ev = somGetGlobalEnvironment();
  53.  
  54.   fSelectedDraft         = kODNULL;
  55.  
  56.   // Have the document manager interalize all of the draft information.
  57.   fActiveDocumentManager = docmgr;
  58.   fActiveDocumentManager->InternalizeHistory(ev);
  59.  
  60.   // Save list of drafts associated with currently active document.
  61.   fDraftInfoList = fActiveDocumentManager->GetDraftList(ev);
  62.  
  63. #if defined(_PLATFORM_WIN32_) || defined (_PLATFORM_OS2_)
  64.   fWindow                = hwnd;
  65.   fInstance              = wsdata->resInstance;
  66. #elif defined(_PLATFORM_UNIX_)
  67.   fInstance              = wsdata->appShell;
  68. #endif
  69.  
  70. }
  71.  
  72. //----------------------------------------------------------------------------
  73. // Destructor
  74. //----------------------------------------------------------------------------
  75. DraftWindow::~DraftWindow() 
  76. {
  77.   Environment *ev = somGetGlobalEnvironment();
  78.   try
  79.   {
  80.     // Free the list of history records.
  81.     fActiveDocumentManager->DeleteDraftList(ev);
  82.   }
  83.   catch (ODException _exception)
  84.   {
  85.      LOG("Exception occured in DraftWindow::~DraftWindow\n");
  86.      throw;
  87.   }
  88. }
  89.  
  90. //----------------------------------------------------------------------------
  91. // DraftHistory - invokes the drafthistory dialog.
  92. //----------------------------------------------------------------------------
  93. void DraftWindow::DraftHistory()
  94. {
  95.   Environment *ev = somGetGlobalEnvironment();
  96.   DraftHistoryDlg(ev, this);
  97. }
  98.  
  99. //----------------------------------------------------------------------------
  100. //  FindDraftInList - Finds a particular draft info record based on a 
  101. //                    position passed in.
  102. //----------------------------------------------------------------------------
  103. DraftInfoRec* DraftWindow::FindDraftInList (int ItemSelected)
  104. {
  105.   DraftInfoRec* draftptr = NULL;
  106.  
  107.   // Find selected draft in fDraftInfoList.  Note: this method is not used
  108.   // for NT.
  109.  
  110. #if defined (_PLATFORM_UNIX_)
  111.   // AIX: the ItemSelected paramter is the position in the list
  112.   // of the selected draft.  Assumption is that list order reflects order 
  113.   // of draftinfo records in dialog list.  Therefore position is equivalent.
  114.   draftptr = fDraftInfoList;
  115.   for (int position = 0;
  116.        (draftptr != kODNULL) && (position < ItemSelected);
  117.        position++, draftptr = draftptr->GetNext());
  118. #elif defined(_PLATFORM_OS2_)
  119.   // On Os2 the ItemSelected parameter is the actual draft number, not
  120.   // the position in the list of the draft entry.  Therefore we search
  121.   // the list for the DraftInfoRec that matches the draft number.
  122.   for (draftptr=fDraftInfoList; 
  123.        (draftptr != kODNULL) && (draftptr->GetDraftNum() != ItemSelected); 
  124.        draftptr = draftptr->GetNext());
  125. #endif
  126.  
  127.   return draftptr;
  128. }
  129.  
  130. //----------------------------------------------------------------------------
  131. //  OpenDraft - Opens the selected draft.
  132. //----------------------------------------------------------------------------
  133. ODBoolean DraftWindow::OpenDraft(int ItemSelected, DraftInfoRec* dInfoRec)
  134. {
  135.   Environment*  ev = somGetGlobalEnvironment();
  136.   ODBoolean     retCode = kODFalse;
  137.   DraftInfoRec* draftrec;
  138.   
  139.   try
  140.   {
  141.     fSelectedDraft = kODNULL;
  142.  
  143.     // If a pointer to the DraftInfoRec is passed in, use it.  Otherwise
  144.     // an index was passed in and should be used to traverse the list to find
  145.     // the current DraftInfoRec.
  146.     if (dInfoRec)
  147.       draftrec = dInfoRec;
  148.     else
  149.       // Find draft in list
  150.       draftrec = this->FindDraftInList(ItemSelected);
  151.  
  152.     if (draftrec) 
  153.     {      
  154.       // save handle to locked draft.
  155.       if (fSelectedDraft = draftrec->GetDraft())
  156.       {
  157.         // Acquire the draft to increment the ref count.
  158.         fSelectedDraft->Acquire(ev);
  159.  
  160.         // Open it.
  161.         retCode = fActiveDocumentManager->OpenDraft(ev,fSelectedDraft,kODTrue);
  162.       }
  163.     }
  164.   
  165.   }
  166.   catch (ODException _exception)
  167.   {
  168.     LOG("Exception occured in DraftWn::OpenDraft\n");
  169.     if (fSelectedDraft)
  170.        SaveAndRestoreEv1(fSelectedDraft);
  171.     throw;
  172.   }
  173.  
  174.   return retCode;
  175. }
  176. //----------------------------------------------------------------------------
  177. //  RemoveDraft - Deletes the selected draft and removes it from the 
  178. //                list of draft info records.
  179. //----------------------------------------------------------------------------
  180. ODBoolean DraftWindow::RemoveDraft(int ItemSelected, DraftInfoRec* dInfoRec)
  181. {
  182.   Environment*  ev = somGetGlobalEnvironment();
  183.   ODBoolean     retCode = kODFalse;
  184.   DraftInfoRec* draftrec;
  185.   
  186.   try
  187.   {
  188.     fSelectedDraft = kODNULL;
  189.  
  190.     // If a pointer to the DraftInfoRec is passed in, use it.  Otherwise
  191.     // an index was passed in and should be used to traverse the list to find
  192.     // the current DraftInfoRec.
  193.     if (dInfoRec)
  194.       draftrec = dInfoRec;
  195.     else
  196.       // Find draft in list
  197.       draftrec = this->FindDraftInList(ItemSelected);
  198.  
  199.     if (draftrec) 
  200.     {
  201.       // save handle to locked draft.
  202.       if (fSelectedDraft = draftrec->GetDraft()) 
  203.       {
  204.         // Acquire the draft to increment the ref count.
  205.         // Note: Delete Draft takes care of releasing the draft.
  206.         fSelectedDraft->Acquire(ev);
  207.   
  208.         // Delete it.
  209.         retCode = fActiveDocumentManager->DeleteDraft(ev,draftrec);
  210.       }
  211.     }
  212.  
  213.   }
  214.   catch (ODException _exception)
  215.   {
  216.     LOG("Exception occured in DraftWn::RemoveDraft\n");
  217.     throw;
  218.   }
  219.  
  220.   return retCode;
  221. }
  222.  
  223.