home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / talk.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.6 KB  |  271 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. // CTalkSiteMgr and CTalkNav: implementation file
  20. //
  21. #include "stdafx.h"
  22.  
  23. #ifdef EDITOR
  24. #ifdef _WIN32
  25.  
  26. #include "Talk.h"
  27.  
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33.  
  34. ////////////////////////////////////////////////////////////////
  35. //   Callback to find an instance of SiteManager
  36. //
  37. BOOL CALLBACK EXPORT FindSiteMgr( HWND hwnd, LPARAM lParam )
  38. {
  39.     if ( 0x015DEAD0 == ::SendMessage( hwnd, WM_SITE_MANAGER, SM_QUERY_WINDOW, 0 ) )
  40.     {
  41.         // We found it quit enumerating
  42.         *((BOOL*)lParam) = TRUE;
  43.         return FALSE;
  44.     }
  45.     return TRUE;
  46. }
  47.  
  48. //  Called at app startup during InitInstance().
  49. //  Return TRUE if we found sitemanager running
  50. BOOL FE_FindSiteMgr()
  51. {
  52.     BOOL bRetVal = 0;
  53.     EnumWindows( FindSiteMgr, LPARAM(&bRetVal) );
  54.     return bRetVal;
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CTalkNav  OLE Automation Server so SiteManager can invoke us
  59.  
  60. IMPLEMENT_DYNCREATE(CTalkNav, CCmdTarget)
  61.  
  62. CTalkNav::CTalkNav()
  63. {
  64.     EnableAutomation();
  65.     
  66.     // To keep the application running as long as an OLE automation 
  67.     //    object is active, the constructor calls AfxOleLockApp.
  68.     AfxOleLockApp();
  69. }
  70.  
  71. CTalkNav::~CTalkNav()
  72. {
  73.     // To terminate the application when all objects created with
  74.     //     with OLE automation, the destructor calls AfxOleUnlockApp.
  75.     
  76.     AfxOleUnlockApp();
  77. }
  78.  
  79.  
  80. void CTalkNav::OnFinalRelease()
  81. {
  82.     // When the last reference for an automation object is released
  83.     // OnFinalRelease is called.  The base class will automatically
  84.     // deletes the object.  Add additional cleanup required for your
  85.     // object before calling the base class.
  86.  
  87.     CCmdTarget::OnFinalRelease();
  88. }
  89.  
  90.  
  91. BEGIN_MESSAGE_MAP(CTalkNav, CCmdTarget)
  92.     //{{AFX_MSG_MAP(CTalkNav)
  93.         // NOTE - the ClassWizard will add and remove mapping macros here.
  94.     //}}AFX_MSG_MAP
  95. END_MESSAGE_MAP()
  96.  
  97. BEGIN_DISPATCH_MAP(CTalkNav, CCmdTarget)
  98.     //{{AFX_DISPATCH_MAP(CTalkNav)
  99.     DISP_FUNCTION(CTalkNav, "BrowseURL", BrowseURL, VT_I4, VTS_BSTR)
  100.     DISP_FUNCTION(CTalkNav, "EditURL", EditURL, VT_I4, VTS_BSTR)
  101.     //}}AFX_DISPATCH_MAP
  102. END_DISPATCH_MAP()
  103.  
  104. // Note: we add support for IID_ITalkNav to support typesafe binding
  105. //  from VBA.  This IID must match the GUID that is attached to the 
  106. //  dispinterface in the .ODL file.
  107.  
  108. // {E328732B-9DC9-11CF-92D0-004095E27A10}
  109. static const IID IID_ITalkNav =
  110. { 0xe328732b, 0x9dc9, 0x11cf, { 0x92, 0xd0, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } };
  111.  
  112. BEGIN_INTERFACE_MAP(CTalkNav, CCmdTarget)
  113.     INTERFACE_PART(CTalkNav, IID_ITalkNav, Dispatch)
  114. END_INTERFACE_MAP()
  115.  
  116. // {E328732C-9DC9-11CF-92D0-004095E27A10}
  117. IMPLEMENT_OLECREATE(CTalkNav, "Netscape.TalkNav.1", 0xe328732c, 0x9dc9, 0x11cf, 0x92, 0xd0, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10)
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CTalkNav message handlers
  121.  
  122. long CTalkNav::BrowseURL(LPCTSTR url) 
  123. {
  124.     FE_LoadUrl( (char*)url, LOAD_URL_NAVIGATOR);
  125.     return 1;
  126. }
  127.  
  128. long CTalkNav::EditURL(LPCTSTR url) 
  129. {
  130.     FE_LoadUrl( (char*)url, LOAD_URL_COMPOSER);
  131.     return 1;
  132. }
  133. ////////////////////////////////////////////////////////////
  134. //
  135. // Sitemanager has an OLE automation server that responds to this
  136. //
  137. /////////////////////////////////////////////////////////////////////////////
  138. // ITalkSMClient operations
  139.  
  140. ITalkSMClient::ITalkSMClient(void) :
  141.     m_alive(FALSE),
  142.     m_connected(FALSE),
  143.     m_retried(FALSE)
  144. {
  145.     CLSID clsid;
  146.     m_registered = 0;
  147. #if defined(MSVC4) 
  148.     USES_CONVERSION;
  149.     LPCOLESTR pOleStr = A2CW("Netscape.TalkSiteMgr.1");
  150. #else
  151.     const char * pOleStr[] = "Netscape.TalkSiteMgr.1";
  152. #endif
  153.  
  154.     if (S_OK == CLSIDFromProgID(pOleStr, &clsid))
  155.         m_registered = 1;
  156. }
  157.  
  158. ITalkSMClient::~ITalkSMClient(void)
  159. {
  160.     Disconnect();
  161. }
  162.  
  163. BOOL ITalkSMClient::Connect(void)
  164. {
  165.     m_connected = CreateDispatch("Netscape.TalkSiteMgr.1");
  166.     m_retried = FALSE;
  167.     m_alive = m_connected;
  168.     return m_connected;
  169. }
  170.  
  171. void ITalkSMClient::Disconnect(void)
  172. {
  173.     if (m_connected) ReleaseDispatch();
  174.     m_connected = FALSE;
  175. }
  176.  
  177. BOOL ITalkSMClient::Reconnect(void)
  178. {
  179.     if (m_retried) return FALSE;
  180.     Disconnect();
  181.     Connect();
  182.     m_retried = TRUE;
  183.     return m_connected;
  184. }
  185.  
  186. BOOL ITalkSMClient::IsConnected(void)
  187. {
  188.     if (!m_registered) return FALSE;
  189.     if (!m_connected) Connect();
  190.     return m_connected;
  191. }
  192.  
  193. long ITalkSMClient::LoadingURL(LPCTSTR url)
  194. {
  195.     if (!m_alive) return 0;
  196.     if (!IsConnected()) return 0;
  197.  
  198.     BOOL failed;
  199.  
  200. Retry:
  201.     long result = 0;
  202.     static BYTE BASED_CODE parms[] = VTS_BSTR;
  203.     TRY
  204.     {
  205.         failed = FALSE;
  206.         InvokeHelper(0x1, DISPATCH_METHOD, VT_I4, (void*)&result, parms, url);
  207.     }
  208.     CATCH(CException, e)
  209.     {
  210.         failed = TRUE;
  211.     }
  212.     END_CATCH;
  213.  
  214.     if (!failed) return result;
  215.     if (!Reconnect()) return 0;
  216.     goto Retry;
  217. }
  218.  
  219. long ITalkSMClient::SavedURL(LPCTSTR url)
  220. {
  221.     if (!m_alive) return 0;
  222.     if (!IsConnected()) return 0;
  223.  
  224.     BOOL failed;
  225.  
  226. Retry:
  227.     long result = 0;
  228.     static BYTE BASED_CODE parms[] = VTS_BSTR;
  229.     TRY
  230.     {
  231.         failed = FALSE;
  232.         InvokeHelper(0x2, DISPATCH_METHOD, VT_I4, (void*)&result, parms, url);
  233.     }
  234.     CATCH(CException, e)
  235.     {
  236.         failed = TRUE;
  237.     }
  238.     END_CATCH;
  239.  
  240.     if (!failed) return result;
  241.     if (!Reconnect()) return 0;
  242.     goto Retry;
  243. }
  244.  
  245. long ITalkSMClient::BecomeActive()
  246. {
  247.     if (!IsConnected()) return 0;
  248.  
  249.     BOOL failed;
  250.  
  251. Retry:
  252.     long result = 0;
  253.     TRY
  254.     {
  255.         failed = FALSE;
  256.         InvokeHelper(0x3, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
  257.     }
  258.     CATCH(CException, e)
  259.     {
  260.         failed = TRUE;
  261.     }
  262.     END_CATCH;
  263.  
  264.     if (!failed) return result;
  265.     if (!Reconnect()) return 0;
  266.     goto Retry;
  267. }
  268.  
  269. #endif // _WIN32
  270. #endif // EDITOR
  271.