home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / sharemnu / LMenuSharing.cp next >
Encoding:
Text File  |  1998-04-08  |  4.9 KB  |  169 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 "LMenuSharing.h" // ALWAYS put the .h file first.  This ensures that it compiles.
  20.  
  21. #include "MenuSharing.h" // This is the UserLand header.
  22. #include "uapp.h"
  23. #include "uerrmgr.h"
  24. #include "PascalString.h"
  25. #include "MercutioAPI.h"
  26.  
  27. #include "CTargetedUpdateMenuRegistry.h"
  28.  
  29. // Menu sharing callbacks
  30. static pascal void ErrorDialog (Str255 s);
  31. static pascal void EventFilter (EventRecord *ev);
  32.  
  33. static pascal void ErrorDialog (Str255 s)
  34. {
  35.     ErrorManager::PlainAlert(s, NULL, NULL, NULL);
  36.  
  37. static pascal void EventFilter (EventRecord *ev)
  38. {
  39.     (CFrontApp::GetApplication())->DispatchEvent(*ev);
  40. }
  41.  
  42. // ===========================================================================
  43. // LMenuSharing.cp                                         
  44. // ===========================================================================
  45. //    MenuShring class. Based upon Frontier and draper@usis.com code
  46.     
  47. LMenuSharingAttachment::LMenuSharingAttachment(
  48.     MessageT    inMessage,
  49.     Boolean        inExecuteHost,Int16    resIDofLastMenu)
  50.         : LAttachment(inMessage, inExecuteHost)
  51. {
  52.     mCanMenuShare = ::InitSharedMenus (ErrorDialog, EventFilter);    
  53.     mInsertAfterMenuID = resIDofLastMenu + 1;
  54. }
  55.  
  56.  
  57. void LMenuSharingAttachment::ExecuteSelf( MessageT inMessage, void* ioParam)
  58. {
  59.     if (!mCanMenuShare)
  60.             return; // Don't bother if we can't menu share...
  61.     mExecuteHost = true;
  62.     switch (inMessage)
  63.     {
  64.     case msg_Event:
  65.         
  66.         EventRecord *    ev = (EventRecord*)ioParam;
  67.         ResIDT            menuId;
  68.         Int16            menuItem;
  69.         MenuHandle        menuH;
  70.         CommandT        command;
  71.         LMenuBar*        menubar;
  72.         WindowPtr         w;
  73.         Int16            part;
  74.         LCommander*        commander;
  75.         
  76.         
  77.         CheckSharedMenus(mInsertAfterMenuID);
  78.         
  79.         if (ev->what== mouseDown)
  80.         {
  81.             part = FindWindow (ev->where, &w);
  82.              if (part == inMenuBar) 
  83.             {
  84.                 // (CFrontApp::GetApplication())->UpdateMenus();
  85.                 // myoung: Do this instead.
  86.                 CTargetedUpdateMenuRegistry::SetCommands(CFrontApp::GetCommandsToUpdateBeforeSelectingMenu());
  87.                 CTargetedUpdateMenuRegistry::UpdateMenus();
  88.                 
  89.                 menubar = LMenuBar::GetCurrentMenuBar();
  90.  
  91.                 Int32 theMenuChoice;
  92.                 command = menubar->MenuCommandSelection(*ev, theMenuChoice);
  93.             
  94.                 menubar->FindMenuItem(command,menuId,menuH,menuItem);
  95.                 mExecuteHost = false;
  96.                 if (command != cmd_Nothing)
  97.                 {
  98.                     if (LCommander::IsSyntheticCommand(command,menuId, menuItem))
  99.                     {
  100.                         if (SharedMenuHit (menuId, menuItem))
  101.                         {
  102.                             HiliteMenu(0);
  103.                             break;
  104.                         }
  105.                     }
  106.                     commander = LCommander::GetTarget();
  107.                     commander->ProcessCommand(command, nil);
  108.                     mExecuteHost = false;
  109.                 }
  110.                 HiliteMenu(0);
  111.             }
  112.             break;
  113.         }
  114.         else if (ev->what!=keyDown)    //On keyDown, just drop through the attachments
  115.             break;
  116.     case msg_KeyPress:
  117.  
  118.         ev = (EventRecord*)ioParam;
  119.         char         ch;
  120.  
  121.         mExecuteHost = true;
  122.         command = cmd_Nothing;
  123.         ch = (*ev).message & charCodeMask;
  124.         menubar = LMenuBar::GetCurrentMenuBar();
  125.         if (menubar->CouldBeKeyCommand(*ev))
  126.         {
  127.             // I moved this in here so it is only called when the command key is down.
  128.             // It was making editing unusable.  Also, we only need the menu stuff, not
  129.             // the side effects (like button updates), so call the base class method.
  130.             // --- 97/01/21 jrm
  131.             
  132.             // (CFrontApp::GetApplication())->LApplication::UpdateMenus();
  133.             // myoung: Don't do this here.
  134.  
  135.             //    Use code similar to CFrontApp::EventKeyDown which calls MDEF_MenuKey
  136.             //    instead of calling LMenuBar::FindKeyCommand which calls MenuKey.
  137.             //    DDM 06-JUN-96
  138.             Int32 theMenuChoice = MDEF_MenuKey(ev->message, ev->modifiers, ::GetMenu(666));
  139.             
  140.             if (HiWord(theMenuChoice) != 0)
  141.             {
  142.                 command = LMenuBar::GetCurrentMenuBar()->FindCommand(HiWord(theMenuChoice), LoWord(theMenuChoice));
  143.                 
  144.                 if (LCommander::IsSyntheticCommand(command,menuId, menuItem))
  145.                 {
  146.                     if (SharedMenuHit (menuId, menuItem))// someone is running a script from a commandKey
  147.                     {
  148.                         HiliteMenu(0);
  149.                         mExecuteHost = false;                        
  150.                         break;
  151.                     }
  152.                 }
  153.             }
  154.             if (ch == '.')
  155.             {
  156.                 if (SharedScriptRunning ()) /*cmd-period terminates the script*/
  157.                                 CancelSharedScript (); /*cancel the shared menu script*/
  158.             }
  159.         }
  160.         break;    
  161.     default:
  162.         break;
  163.     }
  164. }
  165.  
  166.     
  167.     
  168.