home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / urlpad / paddoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-29  |  3.6 KB  |  143 lines

  1. //=------------------------------------------------------------------------=
  2. // PadDoc.Cpp
  3. //=------------------------------------------------------------------------=
  4. // Copyright 1992-1996 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // implementation of the CPadDoc class
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "superpad.h"
  17. #include "paddoc.h"
  18. #include "paditem.h"
  19. #include "linkitem.h"
  20.  
  21. #include <wpapi.h>
  22.  
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char BASED_CODE THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CPadDoc
  30.  
  31. IMPLEMENT_DYNCREATE(CPadDoc, COleServerDoc)
  32.  
  33. BEGIN_MESSAGE_MAP(CPadDoc, COleServerDoc)
  34.     //{{AFX_MSG_MAP(CPadDoc)
  35.     ON_COMMAND(ID_VIEW_UPDATENOW, OnViewUpdatenow)
  36.     ON_COMMAND(ID_CANCEL_INPLACE, OnCancelInplace)
  37.     ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  38.     //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CPadDoc delegation to CEditView
  43.  
  44. CPadDoc::CPadDoc()
  45. {
  46.     m_urlflag=FALSE;
  47. }
  48.  
  49. CPadDoc::~CPadDoc()
  50. {
  51.     if (m_urlflag!=FALSE)    
  52.         DeleteFile(GetPathName());
  53. }
  54.  
  55. void CPadDoc::DeleteContents()
  56. {
  57.     COleServerDoc::DeleteContents();
  58.     if (m_viewList.IsEmpty())
  59.         return;
  60.     CEditView* pView = (CEditView*)m_viewList.GetHead();
  61.     ASSERT_KINDOF(CEditView, pView);
  62.     pView->DeleteContents();
  63. }
  64.  
  65. void CPadDoc::Serialize(CArchive& ar)
  66. {
  67.     CEditView* pView = (CEditView*)m_viewList.GetHead();
  68.     ASSERT_KINDOF(CEditView, pView);
  69.     pView->SerializeRaw(ar);
  70. }
  71.  
  72. COleServerItem* CPadDoc::OnGetEmbeddedItem()
  73. {
  74.     CEmbeddedItem* pItem = new CEmbeddedItem(this);
  75.     ASSERT_VALID(pItem);
  76.     return pItem;
  77. }
  78.  
  79. COleServerItem* CPadDoc::OnGetLinkedItem(LPCTSTR lpszItemName)
  80. {
  81.     CPadLinkItem *pItem =
  82.         (CPadLinkItem*)COleServerDoc::OnGetLinkedItem(lpszItemName);
  83.     if (pItem == NULL)
  84.         pItem = new CPadLinkItem(this, lpszItemName);
  85.  
  86.     ASSERT_VALID(pItem);
  87.     return pItem;
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91.  
  92. void CPadDoc::OnViewUpdatenow()
  93. {
  94.     UpdateAllItems(NULL);
  95. }
  96.  
  97. // Note: both the server and the container should have a keyboard method
  98. //  of deactivating an active in-place item.
  99.  
  100. void CPadDoc::OnCancelInplace()
  101. {
  102.     if (IsInPlaceActive())
  103.         OnDeactivateUI(FALSE);
  104. }
  105.  
  106. void CPadDoc::SetSelection(int nBeg, int nEnd)
  107. {
  108.     CEditView* pView = (CEditView*)m_viewList.GetHead();
  109.     ASSERT_KINDOF(CEditView, pView);
  110.     pView->GetEditCtrl().SetSel(nBeg, nEnd);
  111. }
  112.  
  113. void CPadDoc::OnFileSave() 
  114. {
  115.     // If the file being saved is not URL file then call standard save
  116.     if (m_urlflag==FALSE)
  117.     {
  118.         CDocument::OnFileSave();
  119.         return;
  120.     }
  121.  
  122.     // Make a local copy of the file so that you can post by the same name
  123.     // as that of URL and not the temporary file name.
  124.     LONG lRet;
  125.     LPTSTR lpszFileName=m_urlfile.GetBuffer(MAX_PATH);
  126.     LPTSTR tempPath= new CHAR[MAX_PATH];
  127.     ::GetTempPath(MAX_PATH,tempPath);
  128.     strcat(tempPath,lpszFileName);
  129.     CDocument::OnSaveDocument(tempPath);
  130.  
  131.     // Call WebPost Wizard
  132.     lRet = WpPost(    NULL,        // hWin
  133.                     1,        // count of files
  134.                     &tempPath,    // file list
  135.                     NULL,        // lpcbSiteName
  136.                     NULL,        // lpszSiteName
  137.                     NULL,        // lpcbURL
  138.                     NULL,        // lpszURL
  139.                     0 );        // flags
  140.     DeleteFile(tempPath);  // Delete the temporary file which holds the HTM file
  141.     return;
  142. }
  143.