home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Windows 95 Special 1 / WINDOWS95_1.bin / internet / vogon / vogondoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-29  |  9.2 KB  |  299 lines

  1. // vogondoc.cpp : implementation of the CVogonDoc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "vogon.h"
  6.  
  7. #include "CntrInfo.h"
  8. #include "CntrItem.h"
  9. #include "Filter.h"
  10. #include "Slides.h"
  11. #include "Links.h"
  12. #include "TextDlg.h"
  13. #include "vogondoc.h"
  14. #include "vogonvw.h"
  15.  
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char BASED_CODE THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CVogonDoc
  23.  
  24. IMPLEMENT_DYNCREATE(CVogonDoc, COleDocument)
  25.  
  26. BEGIN_MESSAGE_MAP(CVogonDoc, COleDocument)
  27.    //{{AFX_MSG_MAP(CVogonDoc)
  28.     ON_COMMAND(ID_VIEW_SLIDESHOW_SETUP, OnSlideShowSetup)
  29.     ON_COMMAND(ID_VIEW_URLFILTER, OnUrlFilter)
  30.     ON_UPDATE_COMMAND_UI(ID_VIEW_URLFILTER, OnUpdateUrlFilter)
  31.     ON_COMMAND(ID_VIEW_REVEALPAGE, OnRevealPage)
  32.     ON_UPDATE_COMMAND_UI(ID_VIEW_REVEALPAGE, OnUpdateRevealPage)
  33.     ON_COMMAND(ID_VIEW_TEXTRETRIEVAL, OnTextRetrieval)
  34.     ON_UPDATE_COMMAND_UI(ID_VIEW_TEXTRETRIEVAL, OnUpdateTextRetrieval)
  35.     ON_COMMAND(ID_VIEW_HYPERLINKS, OnHyperlinks)
  36.     ON_UPDATE_COMMAND_UI(ID_VIEW_HYPERLINKS, OnUpdateHyperlinks)
  37.     //}}AFX_MSG_MAP
  38.    // Enable default OLE container implementation
  39.    ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, COleDocument::OnUpdatePasteMenu)
  40.    ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, COleDocument::OnUpdatePasteLinkMenu)
  41.    ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleDocument::OnUpdateEditLinksMenu)
  42.    ON_COMMAND(ID_OLE_EDIT_LINKS, COleDocument::OnEditLinks)
  43.    ON_UPDATE_COMMAND_UI(ID_OLE_VERB_FIRST, COleDocument::OnUpdateObjectVerbMenu)
  44.    ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleDocument::OnUpdateObjectVerbMenu)
  45.    ON_COMMAND(ID_OLE_EDIT_CONVERT, COleDocument::OnEditConvert)
  46. END_MESSAGE_MAP()
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CVogonDoc construction/destruction
  50.  
  51. CVogonDoc::CVogonDoc()
  52. {
  53.    // For most containers, using compound files is a good idea.
  54.    EnableCompoundFile();
  55.    // Default to 60-sec interval for the slide show, with loop
  56.    m_uintInterval = 60;
  57.    m_doLoop       = TRUE;
  58.    // Start out unfiltered
  59.    m_filterURL    = FALSE;
  60.    // TODO: add one-time construction code here
  61. }
  62.  
  63. CVogonDoc::~CVogonDoc()
  64. {
  65. }
  66.  
  67. BOOL CVogonDoc::OnNewDocument()
  68. {
  69.    if (!COleDocument::OnNewDocument())
  70.       return FALSE;
  71.  
  72.    // TODO: add reinitialization code here
  73.    // (SDI documents will reuse this document)
  74.  
  75.    return TRUE;
  76. }
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CVogonDoc serialization
  80.  
  81. void CVogonDoc::Serialize(CArchive& ar)
  82. {
  83.    if (ar.IsStoring())
  84.    {  // Store slide-show items
  85.       ar << m_uintInterval << m_doLoop;
  86.       m_stringSlides.Serialize(ar);
  87.    }
  88.    else
  89.    {  // Load slide-show items
  90.       ar >> m_uintInterval >> m_doLoop;
  91.       m_stringSlides.Serialize(ar);
  92.    }
  93.  
  94.    // Calling the base class COleDocument enables serialization
  95.    //  of the container document's COleClientItem objects.
  96.    COleDocument::Serialize(ar);
  97. }
  98.  
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CVogonDoc diagnostics
  102.  
  103. #ifdef _DEBUG
  104. void CVogonDoc::AssertValid() const
  105. {
  106.    COleDocument::AssertValid();
  107. }
  108.  
  109. void CVogonDoc::Dump(CDumpContext& dc) const
  110. {
  111.    COleDocument::Dump(dc);
  112. }
  113. #endif //_DEBUG
  114.  
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CVogonDoc commands
  117. BOOL CVogonDoc::SaveModified() 
  118. {  // We modify too many things, avoid irritating the user.
  119.    return TRUE;
  120. }
  121.  
  122. /////////////////////////////////////////////////////////////////////////////
  123. //
  124. void CVogonDoc::OnSlideShowSetup() 
  125. {  // Present the dialog box
  126.    CSlideShowDlg dlgSlideShow;
  127.  
  128.    // Initialize: interval, loop flag and slide array pointer
  129.    dlgSlideShow.m_uintInterval = m_uintInterval;
  130.    dlgSlideShow.m_doLoop       = m_doLoop;
  131.    dlgSlideShow.m_pSlideList   = &m_stringSlides;
  132.  
  133.    // Show the current URL in the edit box
  134.    POSITION pos = GetStartPosition();
  135.    
  136.    if (pos)
  137.    {  // Have an item:
  138.       CVogonCntrItem* pItem = (CVogonCntrItem*) GetNextClientItem(pos);
  139.       dlgSlideShow.m_stringSlideName = pItem->m_dWebster.GetPageURL();
  140.    }
  141.  
  142.    // Show the dialog
  143.    if (dlgSlideShow.DoModal())
  144.    {  // User selected OK: get the results back
  145.       m_uintInterval = dlgSlideShow.m_uintInterval;
  146.       m_doLoop       = dlgSlideShow.m_doLoop;
  147.    }
  148. }
  149.  
  150. /////////////////////////////////////////////////////////////////////////////
  151. //
  152. void CVogonDoc::OnUrlFilter() 
  153. {  // Toggle filtering state
  154.    m_filterURL = !m_filterURL;
  155. }
  156.  
  157. /////////////////////////////////////////////////////////////////////////////
  158. //
  159. void CVogonDoc::OnUpdateUrlFilter(CCmdUI* pCmdUI) 
  160. {  // Show filtering state
  161.    pCmdUI->SetCheck(m_filterURL);
  162. }
  163.  
  164. /////////////////////////////////////////////////////////////////////////////
  165. //
  166. void CVogonDoc::OnRevealPage() 
  167. {
  168.    // Get a pointer to our object - we need to converse with it
  169.    POSITION pos = GetStartPosition();
  170.    if (pos)
  171.    {  // Have an item:
  172.       CVogonCntrItem* pItem = (CVogonCntrItem*) GetNextClientItem(pos);
  173.       // Toggle the hide flag
  174.       pItem->m_dWebster.SetHiddenFlag(pItem->m_dWebster.GetPageURL(), 
  175.                                  !pItem->m_dWebster.GetHiddenFlag(pItem->m_dWebster.GetPageURL()));
  176.    }
  177. }
  178.  
  179. /////////////////////////////////////////////////////////////////////////////
  180. //
  181. void CVogonDoc::OnUpdateRevealPage(CCmdUI* pCmdUI) 
  182. {  
  183.    // Get a pointer to our object - we need to talk to it
  184.    POSITION pos = GetStartPosition();
  185.    
  186.    if (pos)
  187.    {  // Have an item:
  188.       CVogonCntrItem* pItem = (CVogonCntrItem*) GetNextClientItem(pos);
  189.       // Read the hide flag, enable if hidden
  190.       pCmdUI->Enable(pItem->m_dWebster.GetHiddenFlag(pItem->m_dWebster.GetPageURL()));
  191.    }
  192. }
  193.  
  194. /////////////////////////////////////////////////////////////////////////////
  195. //
  196. void CVogonDoc::OnTextRetrieval() 
  197. {
  198.    // Get a pointer to our object - we need to communicate with it
  199.    POSITION pos = GetStartPosition();
  200.    
  201.    if (pos)
  202.    {  // Have an item:
  203.       CVogonCntrItem* pItem = (CVogonCntrItem*) GetNextClientItem(pos);
  204.       // Show the text retrieval demo dialog
  205.       CTextRetrievalDlg(&pItem->m_dWebster).DoModal();
  206.    }
  207. }
  208.  
  209. /////////////////////////////////////////////////////////////////////////////
  210. //
  211. void CVogonDoc::OnUpdateTextRetrieval(CCmdUI* pCmdUI) 
  212. {  
  213.    // If we have a Webster, enable
  214.    pCmdUI->Enable(GetStartPosition() != NULL);
  215. }
  216.  
  217. /////////////////////////////////////////////////////////////////////////////
  218. //
  219. void CVogonDoc::OnHyperlinks() 
  220. {  
  221.    // Get a pointer to our object - we need to communicate with it
  222.    POSITION pos = GetStartPosition();
  223.    
  224.    if (pos)
  225.    {  // Have an item:
  226.       CVogonCntrItem* pItem = (CVogonCntrItem*) GetNextClientItem(pos);
  227.       // Do the hyperlink demo
  228.       CHyperlinkDlg dlgHyperlinks(&pItem->m_dWebster);
  229.  
  230.       // Show the dialog box
  231.       if (dlgHyperlinks.DoModal() == IDOK)
  232.       {  // User says jump: jump
  233.          pItem->m_dWebster.SetPageURL(dlgHyperlinks.m_stringLink);
  234.       }
  235.    }
  236. }
  237.  
  238. /////////////////////////////////////////////////////////////////////////////
  239. //
  240. void CVogonDoc::OnUpdateHyperlinks(CCmdUI* pCmdUI) 
  241. {
  242.    // If we have a Webster, enable
  243.    pCmdUI->Enable(GetStartPosition() != NULL);
  244. }
  245.  
  246. /////////////////////////////////////////////////////////////////////////////
  247. //
  248. // These are the Webster event handlers: they are hand-coded to match reality
  249. //
  250.  
  251. /////////////////////////////////////////////////////////////////////////////
  252. //
  253. void CVogonDoc::eventDoClickURL(BSTR* SelectedURL, SHORT* Cancel)
  254. {  // User has selected a URL: are we filtering ?
  255.    if (m_filterURL)
  256.    {  // Filter is active: show the URL filter dialog
  257.       CFilterDialog dlgFilter;
  258.       // Set up the URL
  259.       dlgFilter.m_editURL = *((LPCTSTR*) SelectedURL);
  260.       // Let the user decide
  261.       int filterButton = dlgFilter.DoModal();
  262.       if (filterButton == IDOK || filterButton == ID_OK_HIDE)
  263.       {  // Approval: get the latest user-entered value, could be new
  264.          SysReAllocString(SelectedURL, dlgFilter.m_editURL);
  265.          // Should we hide this page ?
  266.          if (filterButton == ID_OK_HIDE)
  267.          {  // No: first cancel this load, which whould be visible
  268.             *Cancel = TRUE;
  269.             // Get a pointer to our object - we need to talk back to it
  270.             POSITION pos = GetStartPosition();
  271.             CVogonCntrItem* pItem = (CVogonCntrItem*) GetNextClientItem(pos);
  272.             // Load the page, invisibly
  273.             pItem->m_dWebster.LoadPage(dlgFilter.m_editURL, TRUE);
  274.          }
  275.       }
  276.       else
  277.       {  // User says Cancel:
  278.          *Cancel = TRUE;
  279.       }
  280.       // Did user check the "Stop Me before I Show Again" box ?
  281.       m_filterURL = !dlgFilter.m_stopShowingMe;
  282.    }
  283. }
  284.  
  285. /////////////////////////////////////////////////////////////////////////////
  286. //
  287. void CVogonDoc::eventKeyDown(short* KeyCode, short Shift)
  288. {  // Ignore for now
  289. }
  290.  
  291. /////////////////////////////////////////////////////////////////////////////
  292. //
  293. void CVogonDoc::eventLoadComplete(BSTR* pageURL, short Status)
  294. {  // A page load has completed, visible or not
  295.    TRACE("CVogonDoc::eventLoadComplete(%s, %d)\n", *((LPCTSTR*)  pageURL), (int) Status);
  296. }
  297.  
  298.  
  299.