home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CCloseAllAttachment.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.8 KB  |  181 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. // Written by Mark G. Young
  20.  
  21. //    Add the CApplicationEventAttachment attachment to the application object.
  22. //    Add the CCloseAllAttachment attachment to the application object.
  23. //    Add the CCloseAllAttachment attachment to each "regular" closeable window.
  24.  
  25. #include "CCloseAllAttachment.h"
  26.  
  27. #ifndef __EVENTS__
  28. #include <Events.h>
  29. #endif
  30.  
  31. #include <LCommander.h>
  32. #include <UDesktop.h>
  33. #include "PascalString.h"
  34. #include <LStream.h>
  35. #include <LWindow.h>
  36.  
  37. #include "CApplicationEventAttachment.h"
  38. #include "CDesktop.h"
  39.  
  40. #include "uerrmgr.h"
  41.  
  42. // ---------------------------------------------------------------------------
  43. //        Ñ CCloseAllAttachment
  44. // ---------------------------------------------------------------------------
  45.  
  46. CCloseAllAttachment::CCloseAllAttachment(
  47.     ResIDT        inCloseStringID,
  48.     ResIDT        inCloseAllStringID)
  49.     :     mCloseStringID(inCloseStringID),
  50.         mCloseAllStringID(inCloseAllStringID)
  51. {
  52. }
  53.  
  54. // ---------------------------------------------------------------------------
  55. //        Ñ CCloseAllAttachment
  56. // ---------------------------------------------------------------------------
  57.  
  58. CCloseAllAttachment::CCloseAllAttachment(
  59.     LStream*    inStream)
  60.     :    super(inStream)
  61. {
  62.     inStream->ReadData(&mCloseStringID, sizeof(mCloseStringID));
  63.     inStream->ReadData(&mCloseAllStringID, sizeof(mCloseAllStringID));
  64. }
  65.  
  66. // ---------------------------------------------------------------------------
  67. //        Ñ ~CCloseAllAttachment
  68. // ---------------------------------------------------------------------------
  69.  
  70. CCloseAllAttachment::~CCloseAllAttachment()
  71. {
  72. }
  73.  
  74. // ---------------------------------------------------------------------------
  75. //        Ñ ExecuteSelf
  76. // ---------------------------------------------------------------------------
  77.  
  78. void
  79. CCloseAllAttachment::ExecuteSelf(
  80.     MessageT    inMessage,
  81.     void*        ioParam)
  82. {
  83.     switch (inMessage)
  84.     {
  85.         case msg_CommandStatus:
  86.             FindCommandStatus(static_cast<SCommandStatus*>(ioParam));
  87.             break;
  88.             
  89.         case cmd_Close:
  90.             ObeyCommand();
  91.             break;
  92.     }
  93. }
  94.  
  95. // ---------------------------------------------------------------------------
  96. //        Ñ FindCommandStatus
  97. // ---------------------------------------------------------------------------
  98.  
  99. void
  100. CCloseAllAttachment::FindCommandStatus(
  101.     SCommandStatus*    ioCommandStatus)
  102. {
  103.     if (ioCommandStatus->command == cmd_Close)
  104.     {
  105.         Boolean isCloseAll = false;
  106.         
  107.         mExecuteHost = true;
  108.  
  109.         LWindow* theTopRegular = UDesktop::FetchTopRegular();
  110.         if (theTopRegular && theTopRegular->HasAttribute(windAttr_CloseBox))
  111.         {
  112.             *ioCommandStatus->enabled = true;
  113.         }
  114.  
  115.         if (CApplicationEventAttachment::CurrentEventHasModifiers(optionKey))
  116.         {
  117.             isCloseAll = true;
  118.  
  119.             if (mCloseAllStringID)
  120.                 *(CStr255*)ioCommandStatus->name = ::GetPString(mCloseAllStringID);
  121.             else
  122.                 *(CStr255*)ioCommandStatus->name = "Close All"; // not seen by user?
  123.         }
  124.         
  125.         if (!isCloseAll)
  126.         {
  127.             if (mCloseStringID)
  128.                 *(CStr255*)ioCommandStatus->name = ::GetPString(mCloseStringID);
  129.             else
  130.                 *(CStr255*)ioCommandStatus->name = "Close";
  131.         }
  132.     }
  133.     else
  134.     {
  135.         mExecuteHost = true;
  136.     }
  137. }    
  138.  
  139. // ---------------------------------------------------------------------------
  140. //        Ñ ObeyCommand
  141. // ---------------------------------------------------------------------------
  142.  
  143. void
  144. CCloseAllAttachment::ObeyCommand()
  145. {
  146.     LWindow* theNextWindow = UDesktop::FetchTopRegular();
  147.     LWindow* theWindow = nil;
  148.  
  149.     mExecuteHost = true;
  150.  
  151.     if (theNextWindow)
  152.     {    
  153.         // Note: we always skip the original front most regular window (it will
  154.         // be handled by PowerPlant after we close all the other windows).
  155.         
  156.         theNextWindow = CDesktop::FetchNextRegular(*theNextWindow);
  157.     }
  158.     
  159.     if (theNextWindow)
  160.     {
  161.         try
  162.         {
  163.             if (CApplicationEventAttachment::CurrentEventHasModifiers(optionKey))
  164.             {
  165.                 while (theNextWindow)
  166.                 {
  167.                     theWindow        = theNextWindow;
  168.                     
  169.                     theNextWindow    = CDesktop::FetchNextRegular(*theWindow);    
  170.                                 
  171.                     if (theWindow && theWindow->HasAttribute(windAttr_CloseBox))
  172.                         theWindow->ObeyCommand(cmd_Close, nil);
  173.                 }
  174.             }
  175.         }
  176.         catch (...)
  177.         {
  178.         }
  179.     }
  180. }
  181.