home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / winclose.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.5 KB  |  274 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.  
  21. #include "winclose.h"
  22. #include "wfedde.h"
  23. #include "mainfrm.h"
  24.  
  25. //    Static property.
  26. CPtrList CWindowChangeRegistry::m_Registry;
  27.  
  28. CWindowChangeItem::CWindowChangeItem(DWORD dwWindowID, int iType) : CWindowChangeRegistry()    {
  29.         m_dwWindowID = dwWindowID;
  30.         m_iType = iType;
  31. }
  32.     
  33. void CWindowChangeItem::Closing(DWORD dwWindowID)    {
  34. //    Purpose:    Go through all registered windows, and tell them if they are the one closing.
  35. //    Arguments:    dwWindowID    The window closing.
  36. //    Returns:    void
  37. //    Comments:
  38. //    Revision History:
  39. //        01-19-95    created GAB
  40. //
  41.  
  42.     //    Go through the registry, call the member WindowClosing, vtables call the correct class.
  43.     POSITION rIndex = m_Registry.GetHeadPosition();
  44.     CWindowChangeItem *pClose;
  45.     while(rIndex != NULL)    {
  46.         pClose = (CWindowChangeItem *)m_Registry.GetNext(rIndex);
  47.         if(pClose->GetWindowID() == dwWindowID)    {
  48.             pClose->WindowClosing(theApp.m_bExit);
  49.             
  50.             //    Remove it from the list, no longer needed, as window doesn't exist.
  51.             delete pClose;
  52.         }
  53.     }
  54. }
  55.  
  56. void CWindowChangeItem::Sizing(DWORD dwWindowID, DWORD dwX, DWORD dwY, DWORD dwCX, DWORD dwCY)    {
  57. //    Purpose:    Go through all registered windows, and tell them if they are the one is changing.
  58. //    Arguments:    dwWindowID    The window sizing.
  59. //              dw* The sizes.
  60. //    Returns:    void
  61. //    Comments:
  62. //    Revision History:
  63. //        02-01-95    created GAB
  64. //
  65.  
  66.     //    Go through the registry, call the member WindowSizing, vtables call the correct class.
  67.     POSITION rIndex = m_Registry.GetHeadPosition();
  68.     CWindowChangeItem *pClose;
  69.     while(rIndex != NULL)    {
  70.         pClose = (CWindowChangeItem *)m_Registry.GetNext(rIndex);
  71.         if(pClose->GetWindowID() == dwWindowID)    {
  72.             pClose->WindowSizing(dwX, dwY, dwCX, dwCY);
  73.         }
  74.     }
  75. }
  76.  
  77. void CWindowChangeItem::Maximizing(DWORD dwWindowID)    {
  78. //    Purpose:    Go through all registered windows, and tell them if they are the one is changing.
  79. //    Arguments:    dwWindowID    The window maximizing.
  80. //    Returns:    void
  81. //    Comments:
  82. //    Revision History:
  83. //        02-01-95    created GAB
  84. //
  85.  
  86.     //    Go through the registry, call the member WindowMaximizing, vtables call the correct class.
  87.     POSITION rIndex = m_Registry.GetHeadPosition();
  88.     CWindowChangeItem *pClose;
  89.     while(rIndex != NULL)    {
  90.         pClose = (CWindowChangeItem *)m_Registry.GetNext(rIndex);
  91.         if(pClose->GetWindowID() == dwWindowID)    {
  92.             pClose->WindowMaximizing();
  93.         }
  94.     }
  95. }
  96.  
  97. void CWindowChangeItem::Minimizing(DWORD dwWindowID)    {
  98. //    Purpose:    Go through all registered windows, and tell them if they are the one is changing.
  99. //    Arguments:    dwWindowID    The window minimizing.
  100. //    Returns:    void
  101. //    Comments:
  102. //    Revision History:
  103. //        02-01-95    created GAB
  104. //
  105.  
  106.     //    Go through the registry, call the member WindowMinimizing, vtables call the correct class.
  107.     POSITION rIndex = m_Registry.GetHeadPosition();
  108.     CWindowChangeItem *pClose;
  109.     while(rIndex != NULL)    {
  110.         pClose = (CWindowChangeItem *)m_Registry.GetNext(rIndex);
  111.         if(pClose->GetWindowID() == dwWindowID)    {
  112.             pClose->WindowMinimizing();
  113.         }
  114.     }
  115. }
  116.  
  117. void CWindowChangeItem::Normalizing(DWORD dwWindowID)    {
  118. //    Purpose:    Go through all registered windows, and tell them if they are the one is changing.
  119. //    Arguments:    dwWindowID    The window maximizing.
  120. //    Returns:    void
  121. //    Comments:
  122. //    Revision History:
  123. //        02-01-95    created GAB
  124. //
  125.  
  126.     //    Go through the registry, call the member WindowNormalizing, vtables call the correct class.
  127.     POSITION rIndex = m_Registry.GetHeadPosition();
  128.     CWindowChangeItem *pClose;
  129.     while(rIndex != NULL)    {
  130.         pClose = (CWindowChangeItem *)m_Registry.GetNext(rIndex);
  131.         if(pClose->GetWindowID() == dwWindowID)    {
  132.             pClose->WindowNormalizing();
  133.         }
  134.     }
  135. }
  136.  
  137. CDDEWindowChangeItem::CDDEWindowChangeItem(CString& csServiceName, DWORD dwWindowID) : CWindowChangeItem(dwWindowID, m_DDE)    {
  138.         m_rIndex = m_Registry.AddTail(this);
  139.         m_csServiceName = csServiceName;
  140. }
  141.  
  142. void CDDEWindowChangeItem::WindowClosing(BOOL bExiting)    {
  143. //    Purpose:    Tell the DDE implementation that the window is closing, and the exit status.
  144. //    Arguments:    bExiting    If the app is exiting, this is TRUE.
  145. //    Returns:    void
  146. //    Comments:
  147. //    Revision History:
  148. //        01-19-95    created GAB
  149. //
  150.  
  151.     //    Just call the DDE implementation, it will handle the details.
  152.     CDDEWrapper::WindowChange(this, m_Close, (TwoByteBool)bExiting);
  153. }
  154.  
  155. void CDDEWindowChangeItem::WindowSizing(DWORD dwX, DWORD dwY, DWORD dwCX, DWORD dwCY)   {
  156. //    Purpose:    Tell the DDE implementation that the window is resized, and the new coordinates.
  157. //    Arguments:    dwX The x position.
  158. //              dwY The y position.
  159. //              dwCX    The width.
  160. //              dwCY    The height.
  161. //    Returns:    void
  162. //    Comments:
  163. //    Revision History:
  164. //        02-01-95    created GAB
  165. //
  166.  
  167.     //    Just call the DDE implementation, it will handle the details.
  168.     CDDEWrapper::WindowChange(this, m_Size, FALSE, dwX, dwY, dwCX, dwCY);
  169. }
  170.  
  171. void CDDEWindowChangeItem::WindowMaximizing()   {
  172. //    Purpose:    Tell the DDE implementation that the window is resized, and the new coordinates.
  173. //    Arguments:  void
  174. //    Returns:    void
  175. //    Comments:
  176. //    Revision History:
  177. //        02-01-95    created GAB
  178. //
  179.  
  180.     //    Just call the DDE implementation, it will handle the details.
  181.     CDDEWrapper::WindowChange(this, m_Maximize);
  182. }
  183.  
  184. void CDDEWindowChangeItem::WindowMinimizing()   {
  185. //    Purpose:    Tell the DDE implementation that the window is resized, and the new coordinates.
  186. //    Arguments:  void
  187. //    Returns:    void
  188. //    Comments:
  189. //    Revision History:
  190. //        02-01-95    created GAB
  191. //
  192.  
  193.     //    Just call the DDE implementation, it will handle the details.
  194.     CDDEWrapper::WindowChange(this, m_Minimize);
  195. }
  196.  
  197. void CDDEWindowChangeItem::WindowNormalizing()   {
  198. //    Purpose:    Tell the DDE implementation that the window is resized, and the new coordinates.
  199. //    Arguments:  void
  200. //    Returns:    void
  201. //    Comments:
  202. //    Revision History:
  203. //        02-01-95    created GAB
  204. //
  205.  
  206.     //    Just call the DDE implementation, it will handle the details.
  207.     CDDEWrapper::WindowChange(this, m_Normalize);
  208. }
  209.  
  210. BOOL CDDEWindowChangeItem::DDERegister(CString& csServiceName, DWORD dwWindowID)    {
  211. //    Purpose:    Register a server to monitor when a window closes.
  212. //    Arguments:    csServiceName    The server to callback.
  213. //                dwWindowID    The window to monitor.
  214. //    Returns:    BOOL    Wether or not registration was successful.
  215. //    Comments:    Constructor, basically.
  216. //    Revision History:
  217. //        01-19-95    created GAB
  218. //
  219.  
  220.     //  Don't allow the mimimized window to be monitored.
  221.     if(dwWindowID == 0) {
  222.         return(FALSE);
  223.     }
  224.  
  225.     //    Make sure such a window exists.
  226.     CAbstractCX *pCX = CAbstractCX::FindContextByID(dwWindowID);
  227.     if(NULL == pCX)    {
  228.         return(FALSE);
  229.     }
  230.     if(pCX->GetContext()->type != MWContextBrowser)    {
  231.         return(FALSE);
  232.     }
  233.  
  234.     //    Looks like it will work.
  235.     CDDEWindowChangeItem *pDontCare = new CDDEWindowChangeItem(csServiceName, dwWindowID);
  236.     return(TRUE);
  237. }
  238.  
  239. BOOL CDDEWindowChangeItem::DDEUnRegister(CString& csServiceName, DWORD dwWindowID)    {
  240. //    Purpose:    UnRegister a server to monitor when a window closes.
  241. //    Arguments:    csServiceName    The server not wanting to monitor.
  242. //                dwWindowID    The window to stop monitoring.
  243. //    Returns:    BOOL    False if never registered, otherwise TRUE.
  244. //    Comments:    Destructor, basically.
  245. //    Revision History:
  246. //        01-19-95    created GAB
  247. //
  248.  
  249.     //    Allright, we need to go through ever entry in our registry.
  250.     POSITION rIndex = m_Registry.GetHeadPosition();
  251.     CWindowChangeItem *pCmp;
  252.     CDDEWindowChangeItem *pDelme = NULL;
  253.     while(rIndex != NULL)    {
  254.         pCmp = (CWindowChangeItem *)m_Registry.GetNext(rIndex);
  255.         if(pCmp->GetType() != m_DDE)    {
  256.             continue;
  257.         }
  258.         pDelme = (CDDEWindowChangeItem *)pCmp;
  259.         
  260.         if(pDelme->GetServiceName() == csServiceName && pDelme->GetWindowID() == dwWindowID)    {
  261.             break;
  262.         }
  263.         pDelme = NULL;
  264.     }
  265.     
  266.     if(pDelme == NULL)    {
  267.         return(FALSE);
  268.     }
  269.     else    {
  270.         delete(pDelme);
  271.         return(TRUE);
  272.     }
  273. }
  274.