home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CWindowMenu.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.2 KB  |  198 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. //    CWindowMenu.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #ifdef PowerPlant_PCH
  24. #include PowerPlant_PCH
  25. #endif
  26.  
  27. #include "CWindowMenu.h"
  28. #include "CWindowMediator.h"
  29. #include "UMenuUtils.h"
  30. //#include "UAEGizmos.h"
  31.  
  32. //#include <LCommander.h>
  33. #include <LArrayIterator.h>
  34. #include <UAppleEventsMgr.h>
  35.  
  36. CWindowMenu* CWindowMenu::sWindowMenu = NULL;
  37.  
  38. //-----------------------------------
  39. CWindowMenu::CWindowMenu(ResIDT inMenuID)
  40. //-----------------------------------
  41.     :    LMenu(inMenuID)
  42.     ,    mWindowList(sizeof(const CMediatedWindow*))
  43.     ,    mDirty(true)
  44. {
  45.     MenuHandle macMenu = GetMacMenuH();
  46.     
  47.     if (macMenu)
  48.         UMenuUtils::ConvertToIconMenu(macMenu, 15550);
  49.     
  50.     mLastNonDynamicItem = ::CountMenuItems(macMenu);
  51.     sWindowMenu = this;
  52. }
  53.  
  54. //-----------------------------------
  55. CWindowMenu::~CWindowMenu()
  56. //-----------------------------------
  57. {
  58.     sWindowMenu = NULL;
  59. }
  60.  
  61. //-----------------------------------
  62. void CWindowMenu::ListenToMessage(MessageT inMessage, void *ioParam)
  63. //-----------------------------------
  64. {
  65.     switch (inMessage)
  66.         {
  67.         case msg_WindowCreated:
  68.             {
  69.             const CMediatedWindow* window = (CMediatedWindow*)ioParam;
  70.             AddWindow(window);
  71.             }
  72.             break;
  73.             
  74.         case msg_WindowDisposed:
  75.             {
  76.             const CMediatedWindow* window = (CMediatedWindow*)ioParam;
  77.             RemoveWindow(window);
  78.             }
  79.             break;
  80.                     
  81.         case msg_WindowDescriptorChanged:
  82.             {
  83.             LCommander::SetUpdateCommandStatus(true);
  84.             SetMenuDirty(true);
  85.             }
  86.             break;
  87.         }
  88. }
  89.  
  90. //-----------------------------------
  91. void CWindowMenu::AddWindow(const CMediatedWindow* inWindow)
  92. //-----------------------------------
  93. {
  94.     mWindowList.InsertItemsAt(1, LArray::index_Last, &inWindow);
  95.     LCommander::SetUpdateCommandStatus(true);
  96.     SetMenuDirty(true);
  97. }
  98.  
  99. //-----------------------------------
  100. void CWindowMenu::RemoveWindow(const CMediatedWindow* inWindow)
  101. //-----------------------------------
  102. {
  103.     mWindowList.Remove(&inWindow);
  104.     LCommander::SetUpdateCommandStatus(true);
  105.     SetMenuDirty(true);
  106. }
  107.  
  108. //-----------------------------------
  109. void CWindowMenu::Update()
  110. //----------------------------------
  111. {
  112.     if (!sWindowMenu || !sWindowMenu->IsMenuDirty())
  113.         return;
  114.     sWindowMenu->UpdateSelf();
  115. }
  116.  
  117. //-----------------------------------
  118. void CWindowMenu::UpdateSelf()
  119. //----------------------------------
  120. {
  121.     if (!sWindowMenu || !sWindowMenu->IsMenuDirty())
  122.         return;
  123.         
  124.     MenuHandle theMacMenu = GetMacMenuH();
  125.     Assert_(theMacMenu != NULL);
  126.  
  127.     UMenuUtils::PurgeMenuItems(theMacMenu, mLastNonDynamicItem);
  128.  
  129.     TString<Str255> windowName;
  130.     CMediatedWindow* window;
  131.     Boolean    bFirstTime = true;
  132.  
  133.     LArrayIterator theIterator(mWindowList, LArrayIterator::from_Start);
  134.     while (theIterator.Next(&window))
  135.     {
  136.  
  137.         if (bFirstTime)
  138.         {
  139.             UMenuUtils::AppendSeparator(theMacMenu);
  140.             bFirstTime = false;
  141.         }
  142.  
  143. //        if (window->GetWindowType() == WindowType_Browser)
  144.         {
  145.             window->GetDescriptor(windowName);
  146.             Int16 theAppendIndex = UMenuUtils::AppendMenuItem(theMacMenu, windowName);
  147.         }
  148.     }
  149.  
  150.     SetMenuDirty(false);
  151. }
  152.  
  153. //-----------------------------------
  154. Boolean CWindowMenu::ObeyWindowCommand(CommandT inCommand)
  155. //-----------------------------------
  156. {
  157.     if (!sWindowMenu)
  158.         return false;
  159.     ResIDT menuID;
  160.     Int16 menuItem;
  161.     if (LCommander::IsSyntheticCommand(inCommand, menuID, menuItem))
  162.         return sWindowMenu->ObeyWindowCommand(menuID, menuItem);
  163.     return false;
  164. }
  165.  
  166. //-----------------------------------
  167. Boolean CWindowMenu::ObeyWindowCommand(Int16 inMenuID, Int16 inMenuItem)
  168. //-----------------------------------
  169. {
  170.     if (inMenuID != GetMenuID())
  171.         return false;
  172.     inMenuItem -= (mLastNonDynamicItem + 1); // 1 for the separator
  173.     if (mLastNonDynamicItem <= 0)
  174.         return false;
  175.     const CMediatedWindow* window = NULL;
  176.     if (!mWindowList.FetchItemAt(inMenuItem, &window) || !window)
  177.         return false;
  178.     AppleEvent theSelectEvent;
  179.     //LAEStream theEventStream(kAEMiscStandards, kAESelect);
  180.     //StAEDescriptor windowDesc;
  181.     //window->MakeSpecifier(windowDesc.mDesc);        
  182.     //theEventStream.WriteKeyDesc(keyDirectObject, windowDesc);
  183.     //theEventStream.Close(&theSelectEvent);
  184.     //UAppleEventsMgr::SendAppleEvent(theSelectEvent);
  185.     return true;
  186. }
  187.  
  188. // called from CFrontApp to remove commands from the Window menu;
  189. // updates the item count if necessary.
  190. void CWindowMenu::RemoveCommand(CommandT inCommand)
  191. {
  192.     if (inCommand > 0) {
  193.         LMenu::RemoveCommand(inCommand);
  194.         mLastNonDynamicItem--;
  195.     }
  196. }
  197.  
  198.