home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CNSMenuBarManager.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  6.0 KB  |  186 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. //    CNSMenuBarManager.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #include "CNSMenuBarManager.h"
  24. #include "CWindowMediator.h"
  25. #include "CWindowMenu.h"
  26. #include "CHistoryMenu.h"
  27. #include "CBookmarksAttachment.h"
  28. #include "CToolsAttachment.h"
  29. #include "CFontMenuAttachment.h"
  30. #include "CRecentEditMenuAttachment.h"
  31. #include "Netscape_Constants.h"
  32. #ifdef MOZ_MAIL_NEWS
  33. #include "CMailFolderButtonPopup.h"
  34. #endif
  35. #include "CBrowserWindow.h" // need for MapWindowTypeToMBARResID - mjc
  36. #include "menusharing.h"
  37.  
  38. CNSMenuBarManager* CNSMenuBarManager::sManager = NULL;
  39.  
  40. CNSMenuBarManager::CNSMenuBarManager(
  41.     CWindowMediator* inWindowMediator) :
  42. mCurrentMenuBarID(MBAR_Initial)
  43. {
  44.     inWindowMediator->AddListener(this);
  45.     sManager = this;
  46. }
  47.  
  48. CNSMenuBarManager::~CNSMenuBarManager()
  49. {
  50.     sManager = NULL;
  51. }
  52.  
  53. void CNSMenuBarManager::ListenToMessage(MessageT inMessage, void* ioParam)
  54. {
  55.     switch (inMessage)
  56.     {
  57.         case msg_WindowActivated:
  58.         case msg_WindowMenuBarModeChanged:
  59.             {
  60.                 CMediatedWindow* inWindow = (CMediatedWindow*)ioParam;
  61.                 if (inWindow->HasAttribute(windAttr_Floating)) return;
  62.                 ResIDT newMenuBarID = MapWindowTypeToMBARResID(inWindow->GetWindowType(), inWindow);
  63.                 if (newMenuBarID > 0 && newMenuBarID != mCurrentMenuBarID)
  64.                     SwitchMenuBar(newMenuBarID);
  65.             }
  66.             break;
  67.             
  68.         case msg_WindowDisposed:
  69.             {
  70.                 // Switch to initial menubar under these conditions
  71.                 if (mCurrentMenuBarID != MBAR_Initial)
  72.                 {
  73.                     CWindowMediator* windowMediator = CWindowMediator::GetWindowMediator();
  74.                     CMediatedWindow* inWindow = (CMediatedWindow*)ioParam;
  75.                     // count the regular, visible, mediated windows of any type
  76.                     int count = windowMediator->CountOpenWindows(WindowType_Any, regularLayerType, false);
  77.                     // two cases to switch:
  78.                     // 1. there are no regular mediated windows (so we must be closing a mediated floater or modal)
  79.                     // 2. we're closing the last regular mediated window
  80.                     if (count == 0 || (count == 1 && inWindow->IsVisible() && inWindow->HasAttribute(windAttr_Regular)))
  81.                         SwitchMenuBar(MBAR_Initial);
  82.                 }
  83.             }
  84.             break;
  85.     }
  86. }
  87.  
  88. ResIDT CNSMenuBarManager::MapWindowTypeToMBARResID(Uint32 inWindowType, CMediatedWindow* inWindow)
  89. {
  90.     ResIDT result = -1;
  91.  
  92.     switch(inWindowType)
  93.     {
  94.         case WindowType_Browser:
  95.             if (inWindow != nil)
  96.             {   // ask the browser window what kind of menubar it wants - mjc
  97.                 CBrowserWindow* theBrWn = dynamic_cast<CBrowserWindow*>(inWindow);
  98.                 switch(theBrWn->GetMenubarMode())
  99.                 {
  100.                     case BrWn_Menubar_None: 
  101.                     // Ñ FIXME return a value which tells the manager to hide the menubar.
  102.                     // fall through for now
  103.                     case BrWn_Menubar_Minimal:
  104.                         result = cMinimalMenubar;
  105.                         break;
  106.                     case BrWn_Menubar_Default:
  107.                         result = cBrowserMenubar;
  108.                         break;
  109.                 }
  110.             }
  111.             else result = cBrowserMenubar;
  112.             break;
  113.         case WindowType_Editor:
  114.             result = cEditorMenubar;
  115.             break;
  116.         case WindowType_MailNews:
  117.         case WindowType_MailThread:
  118.         case WindowType_Message:
  119.             result = cMailNewsMenubar;
  120.             break;
  121.         case WindowType_NavCenter:
  122.             result = cBookmarksMenubar;
  123.             break;
  124.         case WindowType_Address:
  125.             result = cAddressBookMenubar;
  126.             break;
  127.         case WindowType_Compose:
  128.             result = cComposeMenubar;
  129.             break;
  130.     }
  131.     return result;
  132. }
  133.  
  134. void CNSMenuBarManager::SwitchMenuBar(ResIDT inMenuBarID)
  135. {
  136.     // remove go (history) and window menus from menubar so that it doesn't get deleted
  137.     CHistoryMenu* historyMenu = CHistoryMenu::sHistoryMenu;
  138.     CWindowMenu* windowMenu = CWindowMenu::sWindowMenu;
  139.     LMenuBar* currentMenuBar = LMenuBar::GetCurrentMenuBar();
  140.     currentMenuBar->RemoveMenu(windowMenu);
  141.  
  142. #ifdef EDITOR
  143.     LMenu *fontMenu = CFontMenuAttachment::GetMenu();
  144.     currentMenuBar->RemoveMenu(fontMenu);
  145. #endif // EDITOR
  146.  
  147.     CBookmarksAttachment::RemoveMenus();
  148. #ifdef EDITOR
  149.     CToolsAttachment::RemoveMenus();
  150.     CRecentEditMenuAttachment::RemoveMenus();
  151. #endif // EDITOR
  152. #ifdef MOZ_MAIL_NEWS
  153.     CMailFolderSubmenu::RemoveMailFolderSubmenus();
  154. #endif // MOZ_MAIL_NEWS
  155.     if (mCurrentMenuBarID == MBAR_Initial)
  156.         currentMenuBar->RemoveMenu(historyMenu);
  157.     delete (currentMenuBar);
  158.     DisposeSharedMenus();
  159.     // create new menubar
  160.     new LMenuBar( inMenuBarID );
  161.     // now put go and window menus into new menubar
  162.     currentMenuBar = LMenuBar::GetCurrentMenuBar();
  163.     if (inMenuBarID == MBAR_Initial)
  164.         currentMenuBar->InstallMenu(historyMenu, InstallMenu_AtEnd);
  165. #ifdef EDITOR
  166.     // put the tools menu in the editor menubar only
  167.     if ((inMenuBarID == cEditorMenubar) || (inMenuBarID == cComposeMenubar))
  168.     {
  169.         CFontMenuAttachment::InstallMenus();
  170.         CToolsAttachment::InstallMenus();
  171.         CRecentEditMenuAttachment::InstallMenus();
  172.     }
  173. #endif // EDITOR
  174.     if ((inMenuBarID != cBookmarksMenubar) && (inMenuBarID != cMinimalMenubar)) // don't put bookmarks menu in minimal menubar - mjc
  175.         CBookmarksAttachment::InstallMenus();
  176. #ifdef MOZ_MAIL_NEWS
  177.     if ( inMenuBarID == cMailNewsMenubar ) {
  178.         CMailFolderSubmenu::InstallMailFolderSubmenus();
  179.     }
  180. #endif // MOZ_MAIL_NEWS
  181.     if (inMenuBarID != cMinimalMenubar) // don't put window menu in minimal menubar - mjc
  182.         currentMenuBar->InstallMenu(windowMenu, InstallMenu_AtEnd);
  183.     // cache current menubar MBAR ID
  184.     mCurrentMenuBarID = inMenuBarID;
  185. }
  186.