home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / ncapiurl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.0 KB  |  199 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 "wfedde.h"
  21.  
  22. //    This file used to define the ncapi_data structure
  23. //        in the URL_Struct.
  24.  
  25. //    Initialize
  26. CNcapiUrlData::CNcapiUrlData(CAbstractCX *pCX, URL_Struct *pUrl)
  27. {
  28.     ASSERT(pCX);
  29.     ASSERT(pUrl);
  30.  
  31.     //    Can delete the URL_Struct initially.
  32.     m_bDelete = TRUE;
  33.  
  34.     //    Assign in the URL, both ways.
  35.     m_pUrl = pUrl;
  36.     m_pUrl->ncapi_data = (void *)this;
  37.  
  38.     //    Assign in the context, both ways.
  39.     m_pCX = pCX;
  40.     m_pCX->m_pNcapiUrlData = this;
  41.  
  42.     //    Set up so that we haven't initialized any progress.
  43.     m_bInitializedProgress = FALSE;
  44.     m_dwTransactionID = 0;
  45. }
  46.  
  47. //    Destroy
  48. CNcapiUrlData::~CNcapiUrlData()
  49. {
  50.     //    Clear us out of the URL struct.
  51.     m_pUrl->ncapi_data = NULL;
  52.  
  53.     //    Clear us out of the context.
  54.     m_pCX->m_pNcapiUrlData = NULL;
  55. }
  56.  
  57. //    Return whether or not it's ok to NET_FreeUrlStruct
  58. BOOL CNcapiUrlData::CanFreeUrl() const
  59. {
  60.     return(m_bDelete);
  61. }
  62.  
  63. //    Set that we shouldn't delete the URL in the exit routine.
  64. void CNcapiUrlData::DontFreeUrl()
  65. {
  66.     m_bDelete = FALSE;
  67. }
  68.  
  69. //    Change contexts.
  70. void CNcapiUrlData::ChangeContext(CAbstractCX *pNewCX)
  71. {
  72.     ASSERT(pNewCX);
  73.  
  74.     //    Clear out the old context.
  75.     m_pCX->m_pNcapiUrlData = NULL;
  76.  
  77.     //    Bring in the new.
  78.     m_pCX = pNewCX;
  79.     m_pCX->m_pNcapiUrlData = this;
  80. }
  81.  
  82. //    Set a DDE progress server for alert and progress messages.
  83. //    An empty CString will clear the progress server if it needs to be that way.
  84. void CNcapiUrlData::SetProgressServer(CString& csProgressServer)
  85. {
  86.     //    Just copy it.
  87.     m_csProgressServer = csProgressServer;
  88. }
  89.  
  90. //    Report whether or not we have a progress server to report to.
  91. BOOL CNcapiUrlData::HasProgressServer() const
  92. {
  93.     return(m_csProgressServer.IsEmpty() == FALSE);
  94. }
  95.  
  96. //    Clear the progress server.
  97. void CNcapiUrlData::ClearProgressServer()
  98. {
  99.     m_csProgressServer.Empty();
  100. }
  101.  
  102. //    Initialize the progress of the progress app.
  103. void CNcapiUrlData::InitializeProgress()
  104. {
  105.     //    Only do this if we have a progress server.
  106.     if(HasProgressServer() && m_bInitializedProgress == FALSE)    {
  107.         m_dwTransactionID = CDDEWrapper::BeginProgress(this,
  108.             (const char *)m_csProgressServer,
  109.             m_pCX->GetContextID(),
  110.             szLoadString(IDS_LOADING));
  111.  
  112.         //    If it didn't work, it would have cleared the progress server.
  113.         if(HasProgressServer())    {
  114.             //    Set the range.
  115.             CDDEWrapper::SetProgressRange(this,
  116.                 (const char *)m_csProgressServer,
  117.                 m_dwTransactionID,
  118.                 100);
  119.         }
  120.     }
  121.  
  122.     //    Mark progress as being attempted to initialize.
  123.     m_bInitializedProgress = TRUE;
  124. }
  125.  
  126. //    Tell the progress server about our progress.
  127. void CNcapiUrlData::MakingProgress(const char *pMessage, int iPercent)
  128. {
  129.     //    Only do this if need be.
  130.     if(HasProgressServer() && m_bInitializedProgress == TRUE)    {
  131.         if(CDDEWrapper::MakingProgress(this,
  132.             (const char *)m_csProgressServer,
  133.             m_dwTransactionID,
  134.             pMessage,
  135.             (DWORD)iPercent))    {
  136.             //    They would like us to discontinue the load.
  137.             m_pCX->Interrupt();
  138.         }
  139.     }
  140. }
  141.  
  142. //    End the progress.
  143. void CNcapiUrlData::EndProgress()
  144. {
  145.     //    Only do if need be.
  146.     if(HasProgressServer() && m_bInitializedProgress == TRUE)    {
  147.         CDDEWrapper::EndProgress(this,
  148.             (const char *)m_csProgressServer,
  149.             m_dwTransactionID);
  150.     }
  151. }
  152.  
  153. //    Attempt to pass off any alerts to the external app.
  154. //    Return non zero on their handling of the message.
  155. BOOL CNcapiUrlData::Alert(const char *pMessage)
  156. {
  157.     //    Only do this if need be.
  158.     if(HasProgressServer())    {
  159.         return((BOOL)CDDEWrapper::AlertProgress(this,
  160.             (const char *)m_csProgressServer,
  161.             pMessage));
  162.     }
  163.  
  164.     return(FALSE);
  165. }
  166.  
  167. //    Attempt to pass off any confirms to the external app.
  168. //    Return a non BOOL value to indicate failure.
  169. BOOL CNcapiUrlData::Confirm(const char *pMessage)
  170. {
  171.     //    Only do this if need be.
  172.     if(HasProgressServer())    {
  173.         DWORD dwResult = CDDEWrapper::ConfirmProgress(this,
  174.             (const char *)m_csProgressServer,
  175.             pMessage);
  176.  
  177.         //    Convert to a return value.
  178.         if(dwResult == CDDEWrapper::m_PushedYes)    {
  179.             return(TRUE);
  180.         }
  181.         else if(dwResult == CDDEWrapper::m_PushedNo)    {
  182.             return(FALSE);
  183.         }
  184.     }
  185.  
  186.     return((BOOL)-1);
  187. }
  188.  
  189. //    Return our transaction ID.
  190. //    Value of 0 is invalid.
  191. DWORD CNcapiUrlData::GetTransactionID() const
  192. {
  193.     if(HasProgressServer() && m_bInitializedProgress)    {
  194.         return(m_dwTransactionID);
  195.     }
  196.  
  197.     return(0);
  198. }
  199.