home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CWindowMediator.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  10.7 KB  |  369 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. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  20. //    CWindowMediator.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #ifdef PowerPlant_PCH
  24. #include PowerPlant_PCH
  25. #endif
  26.  
  27. #include "CWindowMediator.h"
  28.  
  29. #include "CCloseAllAttachment.h"    // MGY: added CCloseAllAttachment stuff
  30. #include "resgui.h"                    // MGY: added CCloseAllAttachment stuff
  31. #include "CBrowserWindow.h"
  32.  
  33. CAutoPtr<CWindowMediator> CWindowMediator::sMediator;
  34.  
  35. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  36. //    Ñ    
  37. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  38.  
  39. CMediatedWindow::CMediatedWindow(LStream* inStream, DataIDT inWindowType)
  40.     :    LWindow(inStream)
  41. {
  42.     mWindowType = inWindowType;
  43.     (CWindowMediator::GetWindowMediator())->NoteWindowCreated(this);
  44.  
  45.     // MGY: added CCloseAllAttachment stuff
  46.  
  47.     if (HasAttribute(windAttr_Regular | windAttr_CloseBox))
  48.     {
  49.         AddAttachment(new CCloseAllAttachment(CLOSE_WINDOW, CLOSE_ALL_WINDOWS));
  50.     }
  51. }
  52.  
  53. CMediatedWindow::~CMediatedWindow()
  54. {
  55.     (CWindowMediator::GetWindowMediator())->NoteWindowDisposed(this);
  56. }
  57.  
  58. DataIDT CMediatedWindow::GetWindowType(void) const
  59. {
  60.     return mWindowType;
  61. }
  62.  
  63. void CMediatedWindow::SetWindowType(DataIDT inWindowType)
  64. {
  65.     mWindowType = inWindowType;
  66. }
  67.  
  68. void CMediatedWindow::SetDescriptor(ConstStr255Param inDescriptor)
  69. {
  70.     LWindow::SetDescriptor(inDescriptor);
  71.     (CWindowMediator::GetWindowMediator())->NoteWindowDescriptorChanged(this);
  72. }
  73.  
  74. void CMediatedWindow::ActivateSelf(void)
  75. {
  76.     LWindow::ActivateSelf();
  77.     (CWindowMediator::GetWindowMediator())->NoteWindowActivated(this);
  78. }
  79.  
  80. void CMediatedWindow::DeactivateSelf(void)
  81. {
  82.     LWindow::DeactivateSelf();
  83.     (CWindowMediator::GetWindowMediator())->NoteWindowDeactivated(this);
  84. }    
  85.         
  86. void
  87. CMediatedWindow::NoteWindowMenubarModeChanged()
  88. {
  89.     (CWindowMediator::GetWindowMediator())->NoteWindowMenubarModeChanged(this);
  90. }
  91.  
  92. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  93. //    Ñ    
  94. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  95.  
  96. CWindowIterator::CWindowIterator(DataIDT inWindowType)
  97. {
  98.     mWindowType = inWindowType;
  99.     mIndexWindow = NULL;
  100. }
  101.     
  102. Boolean CWindowIterator::Next(CMediatedWindow*& outWindow)
  103. {
  104.     WindowPtr theStartWindow;
  105.     if (mIndexWindow == NULL)
  106.         theStartWindow = (WindowPtr)LMGetWindowList();
  107.     else
  108.         {
  109.         theStartWindow = mIndexWindow->GetMacPort();
  110.         theStartWindow = (WindowPtr) ((WindowPeek) theStartWindow)->nextWindow;
  111.         }
  112.         
  113.     CMediatedWindow *theWindow, *theFoundWindow = NULL;
  114.     while (theStartWindow != NULL)
  115.         {
  116.         theWindow = dynamic_cast<CMediatedWindow*>(LWindow::FetchWindowObject(theStartWindow));
  117.         if (theWindow == NULL)
  118.             {
  119.             theStartWindow = (WindowPtr) ((WindowPeek) theStartWindow)->nextWindow;
  120.             continue;
  121.             }
  122.  
  123.         if ((mWindowType == WindowType_Any) || (theWindow->GetWindowType() == mWindowType))
  124.             {
  125.             theFoundWindow = theWindow;
  126.             break;
  127.             }
  128.  
  129.         theStartWindow = (WindowPtr)((WindowPeek)theStartWindow)->nextWindow;
  130.         }
  131.         
  132.     outWindow = theFoundWindow;
  133.     mIndexWindow = theFoundWindow;
  134.     
  135.     return (theFoundWindow != NULL);    
  136. }
  137.  
  138.  
  139. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  140. //    Ñ    
  141. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  142.  
  143. CWindowMediator* CWindowMediator::GetWindowMediator(void)
  144. {
  145.     if (!sMediator.get())
  146.     {
  147.         sMediator.reset(new CWindowMediator);
  148.     }
  149.     
  150.     return sMediator.get();
  151. }
  152.  
  153. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  154. //    Ñ    
  155. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  156.  
  157. Int16 CWindowMediator::CountOpenWindows(Int32 inWindType)
  158. {
  159.     return CountOpenWindows(inWindType, dontCareLayerType);
  160. }
  161.  
  162.  
  163. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  164. //    Ñ Count windows of a type in a layer
  165. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  166. Int16 CWindowMediator::CountOpenWindows(Int32 inWindType, LayerType inLayerType, Boolean inIncludeInvisible)
  167. {
  168.     Int16 theWindowCount = 0;
  169.     
  170.     CMediatedWindow *theWindow = NULL;
  171.     WindowPtr macWindowP = (WindowPtr) LMGetWindowList();
  172.     while (macWindowP != NULL)
  173.         {
  174.         if ((theWindow = dynamic_cast<CMediatedWindow*>(LWindow::FetchWindowObject(macWindowP))) == NULL)
  175.             {
  176.             macWindowP = (WindowPtr) ((WindowPeek) macWindowP)->nextWindow;
  177.             continue;
  178.             }
  179.  
  180.         if ((inWindType == WindowType_Any) || (theWindow->GetWindowType() == inWindType))
  181.             {
  182.             if (inIncludeInvisible || theWindow->IsVisible())
  183.                 {
  184.                 switch (inLayerType)
  185.                     {
  186.                     case dontCareLayerType:
  187.                         theWindowCount++;
  188.                         break;
  189.                     case modalLayerType:
  190.                         if (theWindow->HasAttribute(windAttr_Modal))
  191.                             theWindowCount++;
  192.                         break;
  193.                     case floatingLayerType:
  194.                         if (theWindow->HasAttribute(windAttr_Floating))
  195.                             theWindowCount++;
  196.                         break;
  197.                     case regularLayerType:
  198.                         if (theWindow->HasAttribute(windAttr_Regular))
  199.                             theWindowCount++;
  200.                         break;
  201.                     }
  202.                 }
  203.             }
  204.                  
  205.         macWindowP = (WindowPtr) ((WindowPeek) macWindowP)->nextWindow;
  206.         }
  207.         
  208.     return theWindowCount;
  209. }
  210.  
  211. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  212. //    Ñ    
  213. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  214.             
  215. CMediatedWindow* CWindowMediator::FetchTopWindow(Int32 inWindType)
  216. {
  217.     CMediatedWindow *theFoundWindow = NULL;
  218.  
  219.     CWindowIterator theIterator(inWindType);
  220.     theIterator.Next(theFoundWindow);
  221.     
  222.     return theFoundWindow;
  223. }
  224.  
  225. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  226. //    Ñ Returns the topmost mediated window in a given layer
  227. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  228. CMediatedWindow* CWindowMediator::FetchTopWindow(LayerType inLayerType)
  229. {
  230.     return FetchTopWindow(WindowType_Any, inLayerType);
  231. }
  232.  
  233. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  234. //    Ñ Returns the topmost mediated window of a given type in a given layer
  235. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  236. CMediatedWindow* CWindowMediator::FetchTopWindow(Int32 inWindType, LayerType inLayerType)
  237. {
  238.     return FetchTopWindow(inWindType, inLayerType, true);
  239. }
  240.  
  241. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  242. //    Ñ Returns the topmost mediated window of a given type in a given layer, with
  243. //    the option of excluding windows which are restricted targets (created by javascript).
  244. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  245. CMediatedWindow* CWindowMediator::FetchTopWindow(Int32 inWindType, LayerType inLayerType, Boolean inIncludeRestrictedTargets)
  246. {
  247.     CMediatedWindow *theFoundWindow = NULL;
  248.  
  249.     CWindowIterator theIterator(inWindType);
  250.     theIterator.Next(theFoundWindow);
  251.     
  252.     while (theFoundWindow != NULL)
  253.         {
  254.         if (!inIncludeRestrictedTargets && (inWindType == WindowType_Browser))
  255.         {
  256.             CBrowserWindow* theBrWn = dynamic_cast<CBrowserWindow*>(theFoundWindow);
  257.             if ((theBrWn != nil) && theBrWn->IsRestrictedTarget())
  258.             {
  259.                 theIterator.Next(theFoundWindow);
  260.                 continue;
  261.             }
  262.         }
  263.         switch (inLayerType)
  264.             {
  265.             case dontCareLayerType:
  266.                 return theFoundWindow;
  267.             case modalLayerType:
  268.                 if (theFoundWindow->HasAttribute(windAttr_Modal))
  269.                     return theFoundWindow;
  270.                 else break;
  271.             case floatingLayerType:
  272.                 if (theFoundWindow->HasAttribute(windAttr_Floating))
  273.                     return theFoundWindow;
  274.                 else break;
  275.             case regularLayerType:
  276.                 if (theFoundWindow->HasAttribute(windAttr_Regular))
  277.                     return theFoundWindow;
  278.                 else break;
  279.             }
  280.         theIterator.Next(theFoundWindow);
  281.         }
  282.     return theFoundWindow;
  283. }
  284.  
  285. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  286. //    Ñ Returns the bottommost mediated window.
  287. //    If inIncludeAlwaysLowered is false, returns the window above the topmost alwaysLowered
  288. //    window.
  289. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  290. CMediatedWindow* CWindowMediator::FetchBottomWindow(Boolean inIncludeAlwaysLowered)
  291. {
  292.     CMediatedWindow *theFoundWindow = NULL;
  293.     CMediatedWindow *lastFoundWindow = NULL;
  294.  
  295.     CWindowIterator theIterator(WindowType_Any);
  296.     theIterator.Next(theFoundWindow);
  297.     
  298.     while (theFoundWindow != NULL)
  299.         {
  300.         if (!inIncludeAlwaysLowered)
  301.             {
  302.             CBrowserWindow* theBrWn = dynamic_cast<CBrowserWindow*>(theFoundWindow);
  303.             if ((theBrWn != nil) && theBrWn->IsAlwaysLowered())
  304.                 return lastFoundWindow;
  305.             }
  306.         lastFoundWindow = theFoundWindow;
  307.         theIterator.Next(theFoundWindow);
  308.         }
  309.     return lastFoundWindow;
  310. }
  311.  
  312. void CWindowMediator::CloseAllWindows(Int32 inWindType)
  313. {
  314.     CMediatedWindow* theWindow;
  315.     
  316.     CWindowIterator theIterator(inWindType);
  317.     theIterator.Next(theWindow);
  318.     
  319.     while (theWindow != NULL)
  320.         {
  321.         CMediatedWindow* theNextWindow;
  322.         theIterator.Next(theNextWindow);
  323.         
  324.         theWindow->AttemptClose();
  325.         theWindow = theNextWindow;
  326.         }
  327. }
  328.  
  329. CWindowMediator::CWindowMediator()
  330. {
  331. }
  332.  
  333. CWindowMediator::~CWindowMediator()
  334. {
  335. }
  336.     
  337. void CWindowMediator::NoteWindowCreated(CMediatedWindow* inWindow)
  338. {
  339.     BroadcastMessage(msg_WindowCreated, inWindow);
  340.     mWindowList.InsertItemsAt(1, LArray::index_First, &inWindow);
  341. }
  342.  
  343. void CWindowMediator::NoteWindowDisposed(CMediatedWindow* inWindow)
  344. {
  345.     BroadcastMessage(msg_WindowDisposed, inWindow);
  346.     mWindowList.Remove(&inWindow);
  347. }
  348.  
  349. void CWindowMediator::NoteWindowDescriptorChanged(CMediatedWindow* inWindow)
  350. {
  351.     BroadcastMessage(msg_WindowDescriptorChanged, inWindow);
  352. }
  353.  
  354. void CWindowMediator::NoteWindowActivated(CMediatedWindow* inWindow)
  355. {
  356.     BroadcastMessage(msg_WindowActivated, inWindow);
  357. }
  358.  
  359. void CWindowMediator::NoteWindowDeactivated(CMediatedWindow* inWindow)
  360. {
  361.     BroadcastMessage(msg_WindowDeactivated, inWindow);
  362. }
  363.  
  364. void CWindowMediator::NoteWindowMenubarModeChanged(CMediatedWindow* inWindow)
  365. {
  366.     BroadcastMessage(msg_WindowMenuBarModeChanged, inWindow);
  367. }
  368.  
  369.