home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / olehelp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.6 KB  |  156 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20. #include "olehelp.h"
  21.  
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // COleHelp
  30.  
  31. #ifndef _AFXDLL
  32. #undef new
  33. #endif
  34. IMPLEMENT_DYNCREATE(COleHelp, CCmdTarget)
  35. #ifndef _AFXDLL
  36. #define new DEBUG_NEW
  37. #endif
  38.  
  39. COleHelp::COleHelp()
  40. {
  41.     EnableAutomation();
  42.     
  43.     // To keep the application running as long as an OLE automation 
  44.     //    object is active, the constructor calls AfxOleLockApp.
  45.     TRACE("Creating COleHelp\n");
  46.     
  47.     AfxOleLockApp();
  48.  
  49.     //  Create a slave context for us to use.
  50.     m_pSlaveCX = new CStubsCX(::HtmlHelp, MWContextHTMLHelp);
  51. }
  52.  
  53. COleHelp::~COleHelp()
  54. {
  55.     // To terminate the application when all objects created with
  56.     //     with OLE automation, the destructor calls AfxOleUnlockApp.
  57.     TRACE("Destroying COleHelp\n");
  58.     
  59.     AfxOleUnlockApp();
  60.  
  61.     //  Destroy the slave context.
  62.     if(m_pSlaveCX)  {
  63.         m_pSlaveCX->NiceDestroyContext();
  64.     }
  65. }
  66.  
  67.  
  68. void COleHelp::OnFinalRelease()
  69. {
  70.     // When the last reference for an automation object is released
  71.     // OnFinalRelease is called.  The base class will automatically
  72.     // deletes the object.  Add additional cleanup required for your
  73.     // object before calling the base class.
  74.  
  75.     CCmdTarget::OnFinalRelease();
  76. }
  77.  
  78.  
  79. BEGIN_MESSAGE_MAP(COleHelp, CCmdTarget)
  80.     //{{AFX_MSG_MAP(COleHelp)
  81.         // NOTE - the ClassWizard will add and remove mapping macros here.
  82.     //}}AFX_MSG_MAP
  83. END_MESSAGE_MAP()
  84.  
  85. BEGIN_DISPATCH_MAP(COleHelp, CCmdTarget)
  86.     //{{AFX_DISPATCH_MAP(COleHelp)
  87.     DISP_FUNCTION(COleHelp, "HtmlHelp", HtmlHelp, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BSTR)
  88.     //}}AFX_DISPATCH_MAP
  89. END_DISPATCH_MAP()
  90.  
  91. // Note: we add support for IID_IOleHelp to support typesafe binding
  92. //  from VBA.  This IID must match the GUID that is attached to the 
  93. //  dispinterface in the .ODL file.
  94.  
  95. #ifndef MOZ_COMMUNICATOR_IIDS
  96. /* 2e696aa0-f8ad-11d0-b09a-00805f8a1db7 */
  97. static const IID IID_IOleHelp =
  98. { 0x2e696aa0, 0xf8ad, 0x11d0, {0xb0, 0x9a, 0x00, 0x80, 0x5f, 0x8a, 0x1d, 0xb7} };
  99. #else
  100. // {60403D80-872B-11CF-ACC8-0080C82BE3B6}
  101. static const IID IID_IOleHelp =
  102. { 0x60403d80, 0x872b, 0x11cf, { 0xac, 0xc8, 0x0, 0x80, 0xc8, 0x2b, 0xe3, 0xb6 } };
  103. #endif /* MOZ_COMMUNICATOR_IIDS */
  104.  
  105. BEGIN_INTERFACE_MAP(COleHelp, CCmdTarget)
  106.     INTERFACE_PART(COleHelp, IID_IOleHelp, Dispatch)
  107. END_INTERFACE_MAP()
  108.  
  109. #ifndef MOZ_COMMUNICATOR_IIDS
  110. // {60403D81-872B-11CF-ACC8-0080C82BE3B6}
  111. IMPLEMENT_OLECREATE(COleHelp, "Netscape.Help.1", 0xd0b2c060, 0xf8ad, 0x11d0, 0xb0, 0x9a, 0x0, 0x80, 0x5f, 0x8a, 0x1d, 0xb7)
  112. #else
  113. // {60403D81-872B-11CF-ACC8-0080C82BE3B6}
  114. IMPLEMENT_OLECREATE(COleHelp, "Netscape.Help.1", 0x60403d81, 0x872b, 0x11cf, 0xac, 0xc8, 0x0, 0x80, 0xc8, 0x2b, 0xe3, 0xb6)
  115. #endif // MOZ_COMMUNICATOR_IIDS
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // COleHelp message handlers
  119.  
  120. void COleHelp::HtmlHelp(LPCTSTR pMapFileUrl, LPCTSTR pId, LPCTSTR pSearch) 
  121. {
  122.     //  Make sure we have a slave context for us to use.
  123.     if(m_pSlaveCX && !m_pSlaveCX->IsDestroyed())  {
  124.         char *p_Map = NULL;
  125.         char *p_Id = NULL;
  126.         char *p_Search = NULL;
  127.  
  128.         if(pMapFileUrl) {
  129.             p_Map = XP_STRDUP(pMapFileUrl);
  130.  
  131.             CString csUrl;
  132.             WFE_ConvertFile2Url(csUrl, p_Map);
  133.             XP_FREE(p_Map);
  134.             p_Map = XP_STRDUP(csUrl);
  135.         }
  136.         if(pId) {
  137.             p_Id = XP_STRDUP(pId);
  138.         }
  139.         if(pSearch) {
  140.             p_Search = XP_STRDUP(pSearch);
  141.         }
  142.  
  143.         NET_GetHTMLHelpFileFromMapFile(m_pSlaveCX->GetContext(), p_Map, p_Id, p_Search);
  144.  
  145.         if(p_Map) {
  146.             XP_FREE(p_Map);
  147.         }
  148.         if(p_Id) {
  149.             XP_FREE(p_Id);
  150.         }
  151.         if(p_Search) {
  152.             XP_FREE(p_Search);
  153.         }
  154.     }
  155. }
  156.