home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / UI / StdDispM.cpp < prev    next >
Encoding:
Text File  |  1996-04-22  |  41.8 KB  |  1,332 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StdDispM.cpp
  3.  
  4.     Contains:    Implementation of standard dispatch module for Macintosh events
  5.  
  6.     Owned by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <48>    10/10/95    DM        1277216: GM:API: Dont return ODPoint from
  13.                                     GetWindowPoint()
  14.         <47>    10/10/95    RR        1289924    Now get kODEvtMouseUpEmbedded with
  15.                                     bundled embedded frames
  16.         <46>     9/21/95    RR        #1286167 Suppress mouse up after bg
  17.                                     mousedown. Renamed fInvalidClick to
  18.                                     fSuppressMouseUp
  19.         <45>     9/13/95    DM        1277216 GM:API return no ODPoints nor
  20.                                     ODPolygons
  21.         <44>     9/12/95    DM        1280020 FB1 part trans dlg mem leaks
  22.         <43>     9/12/95    JBS        1283337 use TempOD<Object>s to make
  23.                                     refcounting exception safe
  24.         <42>     9/12/95    RR        Changed some somPrintfs
  25.         <41>     8/29/95    DM        1221778, 1276165: [ShowLinkUpdateAlert]
  26.                                     call LinkMgr SuspendResume()
  27.         <40>     8/29/95    RR        #1267251 handle synthesized activate events
  28.         <39>     7/26/95    DM        #1270320: Memory leak fixes.
  29.         <38>     6/28/95    RR        #1242642. Ref counting fixes
  30.         <37>     6/28/95    JBS        1262900 if click in icon view root frame,
  31.                                     pass to shell instead of Redispatch
  32.         <36>     6/26/95    TÇ        1242642 BB:Fix refcounting bugs
  33.         <35>     6/25/95    TÇ        1242642 BB: Turn on ODDebug warning if
  34.                                     refcount is wrong in
  35.                                     ODRefCntObjectsomUninit.
  36.         <34>     6/20/95    JBS        1257315 change Facet::AcquireWindow to
  37.                                     GetWindow
  38.         <33>     6/15/95    RR        #1256879 Get->AcquireCurrentMenuBar
  39.         <32>     5/31/95    RR        #1251403 Release after AcquirePart
  40.         <31>     5/26/95    RR        #1251403: Multithreading naming support
  41.         <30>     5/25/95    jpa        Fixed usage of ODDebug. [1253321]
  42.         <29>     5/17/95    RR        #1250135/1250137/1250143 Getters increment
  43.                                     refcount
  44.         <28>     5/15/95    RR        # 1249142 Added checks for NULL to
  45.                                     PropagateTheEvent
  46.         <27>     5/10/95    RR        # 1242893, 1245692 Fixed Mouse up
  47.                                     dispatching
  48.         <26>     5/10/95    JBS        1241913 ODPart::AdjustBorderShape is not
  49.                                     called with null shape; 1224727 Facet
  50.                                     hit-testing calls should take point param
  51.                                     in frame coords
  52.         <25>      5/2/95    RR        # 1226050 Added fLastBorderFrame.
  53.         <24>     4/28/95    RR        1211085 Remove 5$ comments
  54.         <23>      4/6/95    RR        #1220104 Use of ODObjectsAreEqual, #1211085
  55.                                     Remove 5$ comments
  56.         <22>      4/4/95    RR        1220104 Use ODObjectsAreEqual, 1227750
  57.                                     local coords for mouseUp
  58.         <21>     3/13/95    NP        1221979: Remove incorrect comment.
  59.         <20>     3/10/95    RR        # 1199122 Dispatch Null Menu Events
  60.         <19>      3/7/95    RR        # 122649 WindowToLocal on eventInfo->where
  61.         <18>      3/1/95    RR        # 1224776 Disabled dispatching of activate
  62.                                     events, since it interferes with floating
  63.                                     window strategy.
  64.         <17>     2/28/95    jpa        Removed a bit o' test code accidentally
  65.                                     left in [1220704]
  66.         <16>     2/24/95    jpa        Dispatch kODEvtBGMouseDown &
  67.                                     kODEvtBGMouseDownEmbedded [1220704]
  68.         <15>     2/22/95    RR        # 1213850 Dispatch menu events to root part
  69.                                     of active window if not handled by menu
  70.                                     focus
  71.         <14>     2/20/95    TÇ        #1221861 BB: Incomplete AOCE support needs
  72.                                     to be removed from OpenDoc
  73.         <13>     1/31/95    RR        # 1162080 delete facet iterator in
  74.                                     GetActiveFacetWithBorderUnderPoint
  75.         <12>     1/13/95    RR        Added eventInfo to event handling methods.
  76.                                     Remove calls to HandleEventInEmbedded
  77.         <11>     11/1/94    RR        #1196756 Don't call DialogSelect for
  78.                                     updates and activates
  79.         <10>    10/27/94    eeh        #1191434 for RR: handle dlogs with the
  80.                                     modal focus correctly
  81.          <9>    10/27/94    RR        # 1191434 Check for ViewAsIcon etc in
  82.                                     DispatchToFacetUnderPoint. No longer handle
  83.                                     dialog updates and activates
  84.          <8>    10/21/94    NP        1187682: TSM support.
  85.          <7>    10/18/94    RR        Check for null containing facet in
  86.                                     DispatchToFacetUnderPoint
  87.          <6>     9/30/94    RR        #1188888, #1171182 For mouse clicks,
  88.                                     respect icon views, selected and dragging
  89.                                     states.
  90.          <5>     9/20/94    RR        #1167854. Rewrote DispatchKeyDown so that
  91.                                     unmatched command keys are passed to part
  92.                                     as a keystroke
  93.          <4>      9/6/94    RR        #1183392. Call HandleEventInEmbedded where
  94.                                     appropriate
  95.          <3>     8/10/94    JBS        1179919: coordinate system bias changes
  96.          <2>     7/26/94    eeh        ODQDPoint->Point
  97.          <1>     6/24/94    RR        first checked in
  98.          <7>      5/4/94    SS        #1160449: fixes for ModalFocus dialogs
  99.          <6>      4/8/94    RR        #1144767
  100.          <5>      4/1/94    TÇ        #1154941: Get OpenDoc source to actually
  101.                                     compile for PowerPC
  102.          <4>     3/28/94    CG        1153547: Renamed XMPSessn.h to XMPSessM.h
  103.          <3>     3/16/94    RR        #1151144. Made global functions static
  104.          <2>     2/16/94    JA        Include new AltPoint.h.
  105.         <38>      2/7/94    NP        Tiger Team doings.
  106.         <37>      2/7/94    NP        Tiger Team doings.
  107.         <36>     1/21/94    RR        Restored Dispatch() signature
  108.         <35>     1/20/94    RR        Handle AOCE Mailer events
  109.         <34>     1/18/94    RR        Use scrolling focus for pageUp etc., add
  110.                                     propagation
  111.         <33>     1/15/94    RR        WinState.h->WinStat.h,
  112.                                     Dispatch.h->Disptch.h
  113.         <32>     1/15/94    RR        Updated DispatchMenuEvent (command no. is
  114.                                     no longer in event)
  115.         <31>     1/14/94    RR        Shift-click in active border beeps
  116.         <30>     1/11/94    TÇ        Init... changes
  117.         <29>     1/10/94    RR        Added HiliteMenu calls
  118.         <28>    12/20/93    RR        New init strategy
  119.         <27>    12/16/93    RR        Various methods respect modal focus. Update
  120.                                     and activate events in dialogs are handled.
  121.                                     DispatchToFacetUnderPoint became a member
  122.                                     function.
  123.         <26>    12/15/93    JBS        activeShape & window now in facet not frame
  124.         <25>    12/13/93    RR        Remove warning.
  125.         <24>     12/6/93    RR        Call WindowState->SuspendResume
  126.         <23>     12/3/93    CC        SuspendResume: Moved call to
  127.                                     ExportClipboard() into the shell; no longer
  128.                                     modifies its event parameter so shell can
  129.                                     post-process the event.
  130.         <22>     12/2/93    CC        SuspendResume: Catch errors thrown by
  131.                                     ExportClipboard().
  132.         <21>     12/2/93    RR        Fixed some bugs in handling of mouse events
  133.         <20>    11/24/93    CC        Call ExportClipboard() on suspend events
  134.         <19>    11/19/93    RR        Correctly set "handled"
  135.         <18>    11/19/93    RR        Use correct event codes. Handle command
  136.                                     keys. Dispatch mouse downs in title bar to
  137.                                     root part.
  138.         <17>    11/18/93    JBS        use activeFrame->AcquireWindow()
  139.         <16>    11/16/93    RR        Central Casting for CFront
  140.         <15>    11/16/93    RR        Quick hack in MouseDownInContent until
  141.                                     Frame/Facet/Active Border is sorted out
  142.         <14>    11/16/93    RR        Shell now constructs menu events. Also
  143.                                     update for cursor-tracking and idling
  144.         <13>    11/12/93    JBS        use Facets
  145.         <12>    10/27/93    RR        Use Window::AcquireFrameUnderPoint instead of
  146.                                     local routine.
  147.         <11>    10/12/93    PH        Do some cleanup for VodooMonkey
  148.         <10>     10/8/93    RR        Use IsXMPWindow
  149.          <9>     10/6/93    JA        Use new fixed-point XMPPoint.
  150.          <8>     10/1/93    RR        Ignore 0 result of MenuSelect()
  151.          <7>     9/16/93    RR        Menu event uses command number
  152.          <6>     9/15/93    RR        Use command number in menu event (currently
  153.                                     commented out)
  154.          <5>      9/3/93    JBS        updated to use new Layout class
  155.          <4>     8/24/93    TÇ        commented out ifdef PROTOTYPEBUILD so
  156.                                     implementation could use hit detection code
  157.                                     from prototype
  158.          <3>     8/24/93    RR        Got rid of some CFront warnings
  159.          <2>     8/11/93    RR        Included hit detection code from prototype,
  160.                                     for now
  161.          <1>     8/10/93    RCR        first checked in
  162.  
  163.     To Do:
  164.     In Progress:
  165. */
  166.  
  167. #ifndef _ALTPOINT_
  168. #include "AltPoint.h"            // Use C++ savvy ODPoint and ODRect
  169. #endif
  170.  
  171.  
  172. #ifndef _STDDISPM_
  173. #include "StdDispM.h"
  174. #endif
  175.  
  176. #ifndef _TEMPOBJ_
  177. #include <TempObj.h>
  178. #endif
  179.  
  180. #ifndef _ODSESSN_
  181. #include "ODSessn.xh"
  182. #endif
  183.  
  184. #ifndef SOM_ODDispatcher_xh
  185. #include "Disptch.xh"
  186. #endif
  187.  
  188. #ifndef SOM_ODWindow_xh
  189. #include "Window.xh"
  190. #endif
  191.  
  192. #ifndef SOM_ODFacet_xh
  193. #include "Facet.xh"
  194. #endif
  195.  
  196. #ifndef SOM_ODWindowState_xh
  197. #include "WinStat.xh"
  198. #endif
  199.  
  200. #ifndef SOM_ODMenuBar_xh
  201. #include "MenuBar.xh"
  202. #endif
  203.  
  204. #ifndef SOM_Module_OpenDoc_Commands_defined
  205. #include "CmdDefs.xh"
  206. #endif
  207.  
  208. #ifndef SOM_LinkMgr_xh
  209. #include <LinkMgr.xh>
  210. #endif
  211.  
  212. #ifndef SOM_ODArbitrator_xh
  213. #include "Arbitrat.xh"
  214. #endif
  215.  
  216. #ifndef SOM_ODPart_xh
  217. #include "Part.xh"
  218. #endif
  219.  
  220. #ifndef SOM_Module_OpenDoc_Foci_defined
  221. #include "Foci.xh"
  222. #endif
  223.  
  224. #ifndef SOM_ODFrame_xh
  225. #include "Frame.xh"
  226. #endif
  227.  
  228. #ifndef SOM_ODFrameFacetIterator_xh
  229. #include "FrFaItr.xh"
  230. #endif
  231.  
  232. #ifndef SOM_ODFacetIterator_xh
  233. #include "FacetItr.xh"
  234. #endif
  235.  
  236. #ifndef _DSPUTILM_
  237. #include "DspUtilM.h"
  238. #endif
  239.  
  240. #ifndef __EPPC__
  241. #include <EPPC.h>
  242. #endif
  243.  
  244. #ifndef __MENUS__
  245. #include <Menus.h>
  246. #endif
  247.  
  248. #ifndef __DIALOGS__
  249. #include <Dialogs.h>
  250. #endif
  251.  
  252. #ifndef __TOOLUTILS__
  253. #include <ToolUtils.h>
  254. #endif
  255.  
  256. #ifndef __TEXTSERVICES_
  257. #include "TextServices.h"
  258. #endif
  259.  
  260. #pragma segment ODStdDispatchModule
  261.  
  262. #define ODDebugMenuEvents 0
  263. #define ODDebugLayerEvents 0
  264. #define ODDebugTitleBarEvents 0
  265. #define ODLogEvents 0
  266.  
  267. //=====================================================================================
  268. // CONSTANTS
  269. //=====================================================================================
  270.  
  271. const short     kSuspendResumeMessage = 0x01;    // High byte suspend/resume event 
  272. const short     kClipConvertMask      = 0x02;    // Bit of message field clip conversion
  273. const short     kResumeMask           = 0x01;    // Resume vs. suspend mask
  274. const short     kMouseMovedMessage    = 0xFA;    // High byte mouse-moved event message
  275.  
  276. //----------------------------------------------------------------------------------------
  277. // Enumeration for ASCII Character Constants
  278. //----------------------------------------------------------------------------------------
  279.  
  280. enum EAsciiControlCode {
  281.     chBackspace = 8,                    // ASCII code for Backspace character  
  282.     chClear = 27,                        // ASCII code for Clear key (aka ESC)  
  283.     chDown = 31,                        // ASCII code for down arrow  
  284.     chEnd = 4,                            // ASCII code for the End key  
  285.     chEnter = 3,                        // ASCII code for Enter character  
  286.     chEscape = 27,                        // ASCII code for Escape (aka Clear) key  
  287.     chFunction = 16,                    // ASCII code for any function key  
  288.     chFwdDelete = 127,                    // ASCII code for forward delete  
  289.     chHelp = 5,                            // ASCII code for Help key  
  290.     chHome = 1,                            // ASCII code for the Home key  
  291.     chLeft = 28,                        // ASCII code for left arrow  
  292.     chPageDown = 12,                    // ASCII code for Page Down key  
  293.     chPageUp = 11,                        // ASCII code for Page Up key  
  294.     chReturn = 13,                        // ASCII code for Return character  
  295.     chRight = 29,                        // ASCII code for right arrow  
  296.     chSpace = 32,                        // ASCII code for Space character  
  297.     chTab = 9,                            // ASCII code for Tab character  
  298.     chUp = 30                            // ASCII code for up arrow
  299. };
  300.  
  301.  
  302. //----------------------------------------------------------------------------------------
  303. // Enumeration for Virtual Key Code Constants
  304. //----------------------------------------------------------------------------------------
  305.  
  306. enum EVirtualKeyCode {
  307.     kClearVirtualCode = 71,                // Clear key virtual code  
  308.     kEscapeVirtualCode = 53,            // Escape key virtual code  
  309.     kF10VirtualCode = 109,                // F10 virtual key code  
  310.     kF11VirtualCode = 103,                // F11 virtual key code  
  311.     kF12VirtualCode = 111,                // F12 virtual key code  
  312.     kF13VirtualCode = 105,                // F13 virtual key code  
  313.     kF14VirtualCode = 107,                // F14 virtual key code  
  314.     kF15VirtualCode = 113,                // F15 virtual key code  
  315.     kF1VirtualCode = 122,                // F1 virtual key code  
  316.     kF2VirtualCode = 120,                // F2 virtual key code  
  317.     kF3VirtualCode = 99,                // F3 virtual key code  
  318.     kF4VirtualCode = 118,                // F4 virtual key code  
  319.     kF5VirtualCode = 96,                // F5 virtual key code  
  320.     kF6VirtualCode = 97,                // F6 virtual key code  
  321.     kF7VirtualCode = 98,                // F7 virtual key code  
  322.     kF8VirtualCode = 100,                // F8 virtual key code  
  323.     kF9VirtualCode = 101,                // F9 virtual key code  
  324.     kFwdDelVirtualCode = 117            // Forward Delete virtual code
  325. };
  326.  
  327. //=====================================================================================
  328. // Class MacDispatchModule
  329. //=====================================================================================
  330.  
  331. //-------------------------------------------------------------------------------------
  332. // MacDispatchModule::MacDispatchModule
  333. //
  334. // Description
  335. //-------------------------------------------------------------------------------------
  336.  
  337. MacDispatchModule::MacDispatchModule()
  338. {
  339.     fArbitrator = kODNULL;
  340.     fWindowState = kODNULL;
  341.  
  342.     fMouseDownFacet = kODNULL;
  343. }
  344.  
  345. //-------------------------------------------------------------------------------------
  346. // MacDispatchModule::~MacDispatchModule
  347. //
  348. // Description
  349. //-------------------------------------------------------------------------------------
  350.  
  351. MacDispatchModule::~MacDispatchModule()
  352. {
  353. }
  354.  
  355. //-------------------------------------------------------------------------------------
  356. // MacDispatchModule::InitStandardDispatchModule
  357. //
  358. // Description
  359. //-------------------------------------------------------------------------------------
  360.  
  361. void MacDispatchModule::InitMacDispatchModule(Environment* ev, ODSession* session)
  362. {    
  363.     fSession = session;
  364.     // Cache tokenized focus names
  365.     fKeyFocusToken = fSession->Tokenize(ev, kODKeyFocus);
  366.     fMenuFocusToken = fSession->Tokenize(ev, kODMenuFocus);
  367.     fSelectionFocusToken = fSession->Tokenize(ev, kODSelectionFocus);
  368.     fModalFocusToken = fSession->Tokenize(ev, kODModalFocus);
  369.     fMouseFocusToken = fSession->Tokenize(ev, kODMouseFocus);
  370.     fScrollingFocusToken = fSession->Tokenize(ev, kODScrollingFocus);
  371.     
  372.     fLargeIconViewToken = fSession->Tokenize(ev, kODViewAsLargeIcon);
  373.     fSmallIconViewToken = fSession->Tokenize(ev, kODViewAsSmallIcon);
  374.     fThumbnailViewToken = fSession->Tokenize(ev, kODViewAsThumbnail);
  375.     
  376.     // Cache session globals for easy access
  377.     
  378.     fArbitrator = fSession->GetArbitrator(ev);
  379.     fWindowState = fSession->GetWindowState(ev);
  380.     fDispatcher = fSession->GetDispatcher(ev);
  381. }
  382.  
  383. //-------------------------------------------------------------------------------------
  384. // MacDispatchModule::Dispatch
  385. //
  386. // Description
  387. //-------------------------------------------------------------------------------------
  388.  
  389. ODBoolean MacDispatchModule::Dispatch(Environment* ev, ODEventData* event, ODEventInfo* eventInfo)
  390. {
  391.     ODEventType eventType = event->what;
  392.     
  393.     switch (eventType)
  394.     {
  395.         case nullEvent:
  396.             break;        // Currently handled in ODDispatcher
  397.             
  398.         case mouseDown:
  399.         case kODEvtBGMouseDown:
  400.             return this->DispatchMouseDownEvent(ev, event, eventInfo);
  401.             
  402.         case kODEvtMouseDownBorder:    // via Redispatch
  403.             return this->DispatchMouseDownInBorder(ev, event, eventInfo);     
  404.  
  405.         case kODEvtMouseDownEmbedded:
  406.         case kODEvtBGMouseDownEmbedded:
  407.             return this->DispatchMouseDownEmbedded(ev, event, eventInfo);     
  408.  
  409.         case kODEvtMouseUpEmbedded:
  410.             return this->DispatchMouseUpEmbedded(ev, event, eventInfo);     
  411.                     
  412.         case mouseUp:
  413.             return this->DispatchMouseUpEvent (ev, event, eventInfo);
  414.             
  415.         case keyDown:
  416.             return this->DispatchKeyDownEvent(ev, event, eventInfo);
  417.  
  418.         case autoKey:
  419.             return this->DispatchKeyDownEvent(ev, event, eventInfo);
  420.             
  421.         case keyUp:
  422.             return this->DispatchKeyUpEvent(ev, event, eventInfo);
  423.             
  424.         case updateEvt:
  425.             return this->DispatchUpdateEvent(ev, event);
  426.             
  427.         case activateEvt:
  428.             return this->DispatchActivateEvent(ev, event);
  429.             
  430.         case osEvt:
  431.             this->DispatchOSEvent(ev, event);
  432.             return kODTrue;
  433.     
  434.         case kHighLevelEvent:
  435.             break;    // Handled by shell
  436.                         
  437.         case kODEvtMenu:
  438.             return this->DispatchMenuEvent(ev, event, eventInfo);
  439.             
  440.         default:
  441.             return kODFalse;
  442.     }
  443.     return kODFalse;
  444. }
  445.  
  446. //-------------------------------------------------------------------------------------
  447. // MacDispatchModule::DispatchOSEvent
  448. // 
  449. // Description
  450. //-------------------------------------------------------------------------------------
  451.  
  452. void MacDispatchModule::DispatchOSEvent(Environment* ev, ODEventData* theEvent)
  453. {
  454.     unsigned char     typeOSEvent;
  455.     
  456.     // • Is it a multifinder event?
  457.     typeOSEvent = (unsigned char) ( theEvent->message >> 24 ) & 0x00FF;
  458.     
  459.     // • Switch on the type of OSEvent that occurred, high byte of message is event type
  460.     switch ( typeOSEvent ) 
  461.     {     
  462.         case kMouseMovedMessage:
  463.             this->MouseMoved(ev, theEvent);
  464.             break;
  465.             
  466.         case kSuspendResumeMessage:
  467.             this->SuspendResume(ev, theEvent);
  468.             break;
  469.     }
  470. }    
  471.  
  472. //-------------------------------------------------------------------------------------
  473. // MacDispatchModule::MouseMoved
  474. // 
  475. // Description
  476. //-------------------------------------------------------------------------------------
  477.  
  478. void MacDispatchModule::MouseMoved(Environment* ev, ODEventData* theEvent)
  479. {
  480.     ODUnused(theEvent);
  481.     
  482.     fDispatcher->InvalidateMouseRegion(ev);
  483. }
  484.  
  485. //-------------------------------------------------------------------------------------
  486. // MacDispatchModule::SuspendResume
  487. // 
  488. // Description
  489. //-------------------------------------------------------------------------------------
  490.  
  491. void MacDispatchModule::SuspendResume(Environment* ev, ODEventData* theEvent)
  492. {
  493.     fWindowState->SuspendResume(ev, theEvent);
  494.  
  495.     ODLinkManager* linkMgr = fSession->GetLinkManager(ev);
  496.     linkMgr->SuspendResume(ev, theEvent);
  497. }
  498.  
  499. //-------------------------------------------------------------------------------------
  500. // MacDispatchModule::DispatchMenuEvent
  501. // 
  502. // Description
  503. //-------------------------------------------------------------------------------------
  504.  
  505. ODBoolean MacDispatchModule::DispatchMenuEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  506. {
  507.     ODBoolean handled = kODFalse;
  508.  
  509.     long menuResult = theEvent->message;
  510.     short menu = HiWord(menuResult);
  511.     short item = LoWord(menuResult);
  512.     
  513.     //if (menu != 0) // #
  514.     {
  515.         TempODFrame targetFrame = fArbitrator->AcquireFocusOwner(ev, fMenuFocusToken);
  516.         
  517. #if ODDebug && ODDebugMenuEvents
  518.     somPrintf("Menu Event %d, %d for frame %x\n",menu, item, (ODFrame*)targetFrame);
  519. #endif
  520.         
  521.         if ( targetFrame )
  522.         {
  523.             handled = this->DispatchTheEvent(ev, theEvent, targetFrame, kODNULL, eventInfo);
  524.         }
  525.         // Note: To support root menu items like Print. We could add a new focus for this
  526.         if (!handled)
  527.         {
  528.             TempODWindow window = fWindowState->AcquireActiveWindow(ev);
  529.             ODFrame* rootFrame = window ? window->GetRootFrame(ev) : kODNULL;
  530.             if (rootFrame && (rootFrame != targetFrame))
  531.             {
  532.                 TempODPart rootPart = rootFrame->AcquirePart(ev);
  533. #if ODDebug && ODLogEvents
  534.     LogEvent(theEvent, eventInfo, rootFrame, kODNULL);
  535. #endif
  536.                 handled = rootPart->HandleEvent(ev, theEvent, rootFrame, kODNULL, eventInfo);
  537.             }
  538.         }
  539.     }
  540.     //else
  541.     //    handled = kODTrue;
  542.     
  543.     //if (handled)
  544.     HiliteMenu(0);
  545.  
  546.     return handled;
  547. }
  548.  
  549. //-------------------------------------------------------------------------------------
  550. // MacDispatchModule::DispatchMouseDownInContent
  551. // 
  552. // Description
  553. //-------------------------------------------------------------------------------------
  554.  
  555.     static ODBoolean IsContained(Environment* ev, ODFrame* frame, ODFrame* container)
  556.     {
  557.         if ( (frame == kODNULL) || (container == kODNULL))
  558.             return kODFalse;
  559.         if (ODObjectsAreEqual(ev, frame, container))
  560.             return kODTrue;
  561.             
  562.         ODFrame* tempFrame = frame;
  563.         ODFrame* tempContainer = kODNULL;
  564.         tempFrame->Acquire(ev);    // -- TÇ added
  565.         while (tempFrame != kODNULL)
  566.         {
  567.             tempContainer = tempFrame->AcquireContainingFrame(ev);
  568.             tempFrame->Release(ev); // -- TÇ added
  569.             if (ODObjectsAreEqual(ev, tempContainer, container))
  570.             {
  571.                 tempContainer->Release(ev); // -- TÇ added
  572.                 return kODTrue;
  573.             }
  574.             tempFrame = tempContainer;        
  575.         }
  576.         return kODFalse;
  577.     }
  578.     
  579.     static ODFacet* GetActiveFacet(Environment* ev, ODFrame* frame, ODWindow* window, ODPoint& windowPoint)
  580.     // Could be a frame method
  581.     // Return the facet of "frame" which contains the point, or kODNULL
  582.     {
  583.         ODFacet* foundFacet = kODNULL;
  584.         ODPoint framePoint;
  585.     
  586.         if ( frame && window )
  587.         {
  588.             ODFrameFacetIterator* iter = frame->CreateFacetIterator(ev);
  589.     
  590.             for (ODFacet* facet = iter->First(ev);
  591.                     iter->IsNotComplete(ev);
  592.                     facet = iter->Next(ev))
  593.             {
  594.                 {
  595.                     // get windowPoint in frame coords for hit-testing
  596.                     TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  597.                     framePoint = windowPoint;
  598.                     winToFrame->InvertPoint(ev, &framePoint);
  599.                 }
  600.                 if (ODObjectsAreEqual(ev, facet->GetWindow(ev), window)
  601.                     && facet->ContainsPoint(ev, &framePoint, kODNULL) )
  602.                 {
  603.                     foundFacet = facet;
  604.                     break;
  605.                 }
  606.             }
  607.     
  608.             delete iter;
  609.         }
  610.         return foundFacet;
  611.     }
  612.     
  613.     
  614.     static ODFacet* GetFirstFacetUnderPoint(Environment* ev, ODWindow* window, ODFacet* root, ODPoint& windowPoint)
  615.     {
  616.     // returns NULL, root or an embedded facet of root
  617.     
  618.         ODFacet* foundFacet = kODNULL;
  619.         ODPoint framePoint;
  620.     
  621.         if (window && root && (ODObjectsAreEqual(ev, root->GetWindow(ev),window)))
  622.         {
  623.             ODFacetIterator* t = root->CreateFacetIterator(ev, kODTopDown, kODFrontToBack);
  624.             TempODObject tempIterator(t); // DMc - ensure deletion despite return/exceptions
  625.     
  626.             ODFacet* facet = t->First(ev);
  627.             
  628.             // get windowPoint in frame coords for hit-testing
  629.             {
  630.                 TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  631.                 framePoint = windowPoint;
  632.                 winToFrame->InvertPoint(ev, &framePoint);
  633.             }
  634.  
  635.             if ( !facet->ContainsPoint(ev, &framePoint, kODNULL) )
  636.                 return kODNULL;
  637.     
  638.             for ( facet = t->Next(ev);
  639.                     t->IsNotComplete(ev);
  640.                     facet = t->Next(ev) )
  641.             {
  642.                 // get windowPoint in frame coords for hit-testing
  643.                 {
  644.                     TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  645.                     framePoint = windowPoint;
  646.                     winToFrame->InvertPoint(ev, &framePoint);
  647.                 }
  648.                 if (facet->ContainsPoint(ev, &framePoint, kODNULL))
  649.                 {
  650.                     foundFacet = facet;
  651.                     break;
  652.                 }
  653.                 else
  654.                     t->SkipChildren(ev); 
  655.             }
  656.             // delete t; // now deleted by TempODObject
  657.         }
  658.         if ( foundFacet )
  659.             return foundFacet;
  660.         else
  661.             return root;
  662.     }
  663.  
  664. ODBoolean MacDispatchModule::DispatchToFacetUnderPoint(Environment* ev, ODWindow* window, ODPoint& windowPt, 
  665.                                                     ODEventData* theEvent, ODEventInfo* eventInfo)
  666. {
  667.     ODBoolean handled = kODFalse;
  668.     ODFacet* facet = window->GetFacetUnderPoint(ev, &windowPt);
  669.     ODFrame* frame = facet ? facet->GetFrame(ev) : kODNULL;
  670.  
  671.     if (facet && frame)
  672.     {
  673.         TempODFrame modalFocus = fArbitrator->AcquireFocusOwner(ev, fModalFocusToken);
  674.         if ( modalFocus && !IsContained(ev, frame, modalFocus))
  675.         {
  676.             TempODPart part = modalFocus->AcquirePart(ev); // -- TÇ tempobj'd
  677.             if (part)
  678.             {
  679. #if ODDebug && ODLogEvents
  680.     LogEvent(theEvent, eventInfo, modalFocus, kODNULL);
  681. #endif
  682.                 handled = part->HandleEvent(ev, theEvent, modalFocus, kODNULL, eventInfo);
  683.             }
  684.         }
  685.         else
  686.         {
  687.             ODTypeToken frameView = frame->GetViewType(ev);
  688.             ODBoolean isFrozen = frame->IsFrozen(ev);
  689.             ODBoolean isSelected = facet->IsSelected(ev);
  690.             ODBoolean isIcon = (frameView == fLargeIconViewToken ||
  691.                                 frameView == fSmallIconViewToken ||
  692.                                 frameView == fThumbnailViewToken);
  693.             ODBoolean isDragging = frame->IsDragging(ev);
  694.             ODBoolean isMouseDown = (theEvent->what != mouseUp);
  695.  
  696.             if ( isFrozen 
  697.                 || isSelected && isMouseDown
  698.                 || isIcon
  699.                 || isDragging && !isMouseDown)
  700.             {
  701.                 //PRINT("Mouse Down or Up to container\n");
  702.                 switch( theEvent->what ) 
  703.                 {
  704.                     case mouseDown:            theEvent->what = kODEvtMouseDownEmbedded; break;
  705.                     case kODEvtBGMouseDown:    theEvent->what = kODEvtBGMouseDownEmbedded; break;
  706.                     default:                theEvent->what = kODEvtMouseUpEmbedded; break;
  707.                 }
  708.                 eventInfo->embeddedFrame = frame;
  709.                 eventInfo->embeddedFacet = facet;
  710.                 
  711.                 ODFacet* containingFacet = kODNULL;
  712.                 containingFacet = facet->GetContainingFacet(ev);
  713.                 
  714.                 
  715.                 if ( containingFacet == kODNULL )
  716.                     return kODFalse;  // pass to shell/containerApp if this is a root frame
  717.                 else
  718.                 {
  719.                     // Cache the mouse down facet for use in mouse up dispatching, except
  720.                     // if the facet is selected, in which case the mouse up should go to the facet
  721.                     // under the mouse, provided the container doesn't do a drag.
  722.                     if (isMouseDown && (isFrozen || isIcon))
  723.                     {
  724.                         fMouseDownFacet = containingFacet;
  725.                         fEmbeddedFacet = facet;
  726.                     }
  727.                     handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  728.                 }
  729.             }
  730.             else
  731.             {
  732.                 fMouseDownFacet = facet;
  733.                 handled = this->DispatchTheEvent(ev, theEvent, frame, facet, eventInfo);
  734.             }
  735.         }
  736.     }
  737.     return handled;
  738. }
  739.  
  740. ODBoolean MacDispatchModule::DispatchMouseDownInContent (Environment* ev, ODWindow* theWindow,
  741.                                                                 ODEventData* theEvent, ODEventInfo* eventInfo)
  742. {
  743.     ODBoolean handled = kODFalse;
  744.     ODFacet* activeFacet = kODNULL;
  745.  
  746.     ODPoint windowPt; 
  747.     theWindow->GetWindowPoint(ev, &theEvent->where, &windowPt);
  748.     
  749.     ODBoolean modified = ((theEvent->modifiers & cmdKey) || (theEvent->modifiers & shiftKey)) != 0;
  750.     ODBoolean tooModified = ((theEvent->modifiers & optionKey) || (theEvent->modifiers & controlKey) ) != 0;
  751.     modified = modified && !tooModified;
  752.     eventInfo->where = windowPt;
  753.  
  754.     TempODFrame activeFrame = fArbitrator->AcquireFocusOwner(ev, fSelectionFocusToken); // -- TÇ tempobj'd
  755.     if ((ODFrame*)activeFrame ) 
  756.         activeFacet = GetActiveFacetWithBorderUnderPoint(ev, activeFrame, theWindow, ODPoint(windowPt));
  757.         
  758.     if ( activeFacet ) // Mouse down in border
  759.     {
  760.         if( theEvent->what==kODEvtBGMouseDown )
  761.             handled = kODFalse;
  762.         else
  763.         {
  764.             theEvent->what = kODEvtMouseDownBorder;
  765.             eventInfo->embeddedFrame = activeFrame;
  766.             eventInfo->embeddedFacet = activeFacet;
  767.             handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  768.         }
  769.     }
  770.     else // Click not in border
  771.     {
  772.         if (modified)
  773.         {
  774.             ODFacet* rootFacet = activeFrame ? GetActiveFacet(ev, activeFrame, theWindow, windowPt) 
  775.                 : (ODFacet*) kODNULL;
  776.             ODFacet* facet = GetFirstFacetUnderPoint(ev, theWindow, rootFacet, windowPt);
  777.             // returns NULL, rootFacet or embeddedFrame
  778.             
  779.             if (facet)
  780.             {
  781.                 if (ODObjectsAreEqual(ev, facet, rootFacet))
  782.                 {
  783.                     fMouseDownFacet = rootFacet;
  784.                     handled = this->DispatchTheEvent(ev, theEvent, activeFrame, rootFacet, eventInfo);
  785.                 }
  786.                 else // frame is embedded in active frame
  787.                 {
  788.                     theEvent->what = (theEvent->what==kODEvtBGMouseDown) ? kODEvtBGMouseDownEmbedded
  789.                                                                          : kODEvtMouseDownEmbedded;
  790.                     eventInfo->embeddedFrame = facet->GetFrame(ev);
  791.                     eventInfo->embeddedFacet = facet;
  792.                     fMouseDownFacet = rootFacet;
  793.                     fEmbeddedFacet = facet;
  794.                     //handled = this->DispatchTheEvent(ev, theEvent, activeFrame, rootFacet, eventInfo);
  795.                     handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  796.                 }
  797.             }    
  798.             else // Modified click outside active frame
  799.             {
  800.                 SysBeep(2);
  801.                 fSuppressMouseUp = kODTrue;
  802.             }
  803.         }
  804.         else // No modifiers
  805.         {
  806.             handled = DispatchToFacetUnderPoint(ev, theWindow, windowPt, theEvent, eventInfo);
  807.         }
  808.     }
  809.     return handled;
  810. } // MouseDownInContent
  811.  
  812. ODBoolean MacDispatchModule::DispatchMouseDownInBorder(Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  813. {    
  814.     ODBoolean handled = kODFalse;
  815.     ODBoolean modified = ((theEvent->modifiers & cmdKey) || (theEvent->modifiers & shiftKey) ||
  816.                           (theEvent->modifiers & optionKey) || (theEvent->modifiers & controlKey) ) != 0;
  817.     
  818.     if (modified)
  819.     {
  820.         SysBeep(2); // Shift-click or Command-click in border
  821.         fSuppressMouseUp = kODTrue;
  822.         handled = kODTrue;
  823.     }
  824.     else
  825.     {    
  826.         ODFacet* containingFacet = eventInfo->embeddedFacet->GetContainingFacet(ev);
  827.         fMouseDownFacet = containingFacet;
  828.         
  829.         handled = this->DispatchTheEvent(ev, theEvent, containingFacet->GetFrame(ev), containingFacet, eventInfo);
  830.     }
  831.     return handled;
  832. }
  833.  
  834. ODBoolean MacDispatchModule::DispatchMouseDownEmbedded(Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  835. {    
  836.     ODBoolean handled = kODFalse;
  837.  
  838.     ODFacet* containingFacet = eventInfo->embeddedFacet->GetContainingFacet(ev);
  839.  
  840.     // We don't cache mouse down facet here, because the mouse up goes to the embedded part in some cases
  841.     
  842.     handled = this->DispatchTheEvent(ev, theEvent, containingFacet->GetFrame(ev), containingFacet, eventInfo);
  843.  
  844.     return handled;
  845. }
  846.  
  847. ODBoolean MacDispatchModule::DispatchMouseUpEmbedded(Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  848. {    
  849.     ODBoolean handled = kODFalse;
  850.     
  851.     if (fSuppressMouseUp)
  852.         return kODTrue;
  853.  
  854.     if (fMouseDownFacet && fEmbeddedFacet)
  855.         handled = this->DispatchTheEvent(ev, theEvent, fMouseDownFacet->GetFrame(ev), fMouseDownFacet, eventInfo);
  856.     else
  857.         handled = kODTrue;
  858.         
  859.     return handled;
  860. }
  861.  
  862. //-------------------------------------------------------------------------------------
  863. // MacDispatchModule::DispatchMouseDownEvent
  864. // 
  865. // Description
  866. //-------------------------------------------------------------------------------------
  867.  
  868. ODBoolean MacDispatchModule::DispatchMouseDownEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  869. {
  870.  
  871.     ODBoolean handled = kODFalse;
  872.  
  873.     TempODFrame mouseFocusFrame = fArbitrator->AcquireFocusOwner(ev, fMouseFocusToken); 
  874.     if (mouseFocusFrame)
  875.     {
  876.         TempODPart part = mouseFocusFrame->AcquirePart(ev); 
  877.         if ((ODPart*)part)
  878.         {
  879. #if ODDebug && ODLogEvents
  880.     LogEvent(theEvent, eventInfo, mouseFocusFrame, fMouseDownFacet);
  881. #endif
  882.             handled = part->HandleEvent(ev, theEvent, mouseFocusFrame, fMouseDownFacet, eventInfo);
  883.         }
  884.         return handled;
  885.     }
  886.  
  887.     WindowPtr platformWindow = kODNULL;
  888.     TempODWindow aWindow = kODNULL;
  889.     short         partCode;
  890.     
  891.     fMouseDownFacet = kODNULL;
  892.     fEmbeddedFacet = kODNULL;
  893.     fSuppressMouseUp = kODFalse;
  894.     
  895.     partCode = FindWindow ( theEvent->where, &platformWindow );
  896.     
  897.     
  898.     if (platformWindow && fWindowState->IsODWindow(ev, platformWindow))
  899.         aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  900.     
  901.     // Handle only clicks in OD content if this is a bg click:
  902.     if( theEvent->what==kODEvtBGMouseDown )
  903.     {
  904.         fSuppressMouseUp = kODTrue;
  905.         if( aWindow==kODNULL || partCode!=inContent )
  906.             return kODFalse;
  907.     }
  908.     if (partCode == inMenuBar)
  909.     {
  910.         long menuResult = MenuSelect(theEvent->where);
  911.         
  912.         if (!TSMMenuSelect(menuResult))
  913.         {
  914.             theEvent->what = kODEvtMenu;        
  915.             theEvent->message = menuResult;
  916.             handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  917.         }
  918.     }
  919.     else if (aWindow)
  920.     {
  921.         switch (partCode)
  922.         {
  923.             case inContent:
  924.                 handled = this->DispatchMouseDownInContent(ev, aWindow, theEvent, eventInfo);
  925.                 break;
  926.                 
  927.             case inGoAway:
  928.                 if (TrackGoAway (platformWindow, theEvent->where))
  929.                     handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  930.                 else
  931.                     handled = kODTrue;
  932.                 break;
  933.                 
  934.             case inDrag:
  935.                 handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  936.                 break;
  937.  
  938.             case inGrow:
  939.                 handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  940.                 break;
  941.                 
  942.             case inZoomIn:
  943.             case inZoomOut:
  944.                 if (TrackBox(platformWindow, theEvent->where, partCode))
  945.                     handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  946.                 else
  947.                     handled = kODTrue;
  948.                 break;
  949.                 
  950.             default:
  951.                 break;
  952.         }
  953.     }
  954.  
  955.     return handled;
  956.  
  957. }    //    MacDispatchModule::DispatchMouseDownEvent
  958.  
  959. //-------------------------------------------------------------------------------------
  960. // MacDispatchModule::DispatchWindowEvent
  961. // 
  962. // Description
  963. //-------------------------------------------------------------------------------------
  964.  
  965. ODBoolean MacDispatchModule::DispatchWindowEvent(Environment* ev, ODWindow* window, short partCode, 
  966.                                                     ODEventData* theEvent, ODEventInfo* eventInfo)
  967. {
  968.     ODBoolean handled = kODFalse;
  969.  
  970.     TempODFrame modalFocus = fArbitrator->AcquireFocusOwner(ev, fModalFocusToken);
  971.     if (modalFocus && !IsContained(ev, window->GetRootFrame(ev), modalFocus))
  972.     {
  973.         TempODPart part = modalFocus->AcquirePart(ev); // -- TÇ tempobj'd
  974.         if ((ODPart*)part)
  975.         {
  976. #if ODDebug && ODLogEvents
  977.     LogEvent(theEvent, eventInfo, modalFocus, kODNULL);
  978. #endif
  979.             handled = part->HandleEvent(ev, theEvent, modalFocus, kODNULL, eventInfo);
  980.         }
  981.     }
  982.     else
  983.     {
  984.         ODFacet* rootFacet = window->GetRootFacet(ev);
  985.         ODFrame* rootFrame = window->GetRootFrame(ev);
  986.     
  987.         theEvent->what = kODEvtWindow; 
  988.         theEvent->message = partCode;
  989. #if ODDebug && ODDebugTitleBarEvents
  990.         somPrintf("Title Bar Event for root frame %x\n", rootFrame);
  991. #endif
  992.         handled = this->DispatchTheEvent(ev, theEvent, rootFrame, rootFacet, eventInfo);
  993.     }
  994.     return handled;
  995. }
  996.  
  997. //-------------------------------------------------------------------------------------
  998. // MacDispatchModule::DispatchMouseUpEvent
  999. // 
  1000. // Description
  1001. //-------------------------------------------------------------------------------------
  1002.  
  1003. ODBoolean MacDispatchModule::DispatchMouseUpEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  1004. {
  1005.     ODBoolean handled = kODFalse;
  1006.     WindowPtr platformWindow = kODNULL;
  1007.     TempODWindow aWindow = kODNULL;
  1008.     short         partCode;
  1009.     
  1010.     if (fSuppressMouseUp)
  1011.         return kODTrue;
  1012.  
  1013.     TempODFrame mouseFocusFrame = fArbitrator->AcquireFocusOwner(ev, fMouseFocusToken); 
  1014.     if (mouseFocusFrame)
  1015.     {
  1016.         TempODPart part = mouseFocusFrame->AcquirePart(ev); 
  1017.         if ((ODPart*)part)
  1018.         {
  1019. #if ODDebug && ODLogEvents
  1020.     LogEvent(theEvent, eventInfo, mouseFocusFrame, fMouseDownFacet);
  1021. #endif
  1022.             handled = part->HandleEvent(ev, theEvent, mouseFocusFrame, fMouseDownFacet, eventInfo);
  1023.         }
  1024.         return handled;
  1025.     }
  1026.     
  1027. #ifdef ODDebug    
  1028. //somPrintf("Mouse Up\n");
  1029. #endif
  1030.  
  1031.     partCode = FindWindow ( theEvent->where, &platformWindow );
  1032.     ODBoolean modified = ((theEvent->modifiers & cmdKey) || (theEvent->modifiers & shiftKey)) != 0;
  1033.     ODBoolean tooModified = ((theEvent->modifiers & optionKey) || (theEvent->modifiers & controlKey) ) != 0;
  1034.     modified = modified && !tooModified;
  1035.     
  1036.     
  1037.     if (platformWindow)
  1038.         aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  1039.     
  1040.     if (aWindow)
  1041.     {
  1042.         ODPoint windowPt;
  1043.         aWindow->GetWindowPoint(ev, &theEvent->where, &windowPt);
  1044.         
  1045.         eventInfo->where = windowPt;
  1046.         
  1047.         switch ( partCode )
  1048.         {
  1049.                 case inContent:
  1050.                     // if (!modified)    // #1242893: What if it is?
  1051.                     {
  1052.                         if (fMouseDownFacet)
  1053.                         {
  1054.                             if (fEmbeddedFacet)
  1055.                             {
  1056.                                 theEvent->what = kODEvtMouseUpEmbedded;
  1057.                                 eventInfo->embeddedFacet = fEmbeddedFacet;
  1058.                                 eventInfo->embeddedFrame = fEmbeddedFacet->GetFrame(ev);
  1059.                                 handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  1060.                             }
  1061.                             else 
  1062.                                 handled = this->DispatchTheEvent(ev, theEvent, fMouseDownFacet->GetFrame(ev), fMouseDownFacet, eventInfo);
  1063.                         }
  1064.                         else 
  1065.                             handled = DispatchToFacetUnderPoint(ev, aWindow, windowPt, theEvent, eventInfo);
  1066.                     }
  1067.                     break;
  1068.                 
  1069.                 default:
  1070.                     break;
  1071.         }
  1072.     }
  1073.     return handled;
  1074. }    //    MacDispatchModule::DispatchMouseUpEvent
  1075.  
  1076. //-------------------------------------------------------------------------------------
  1077. // MacDispatchModule::DispatchKeyDownEvent
  1078. // 
  1079. // Description
  1080. //-------------------------------------------------------------------------------------
  1081.  
  1082. ODBoolean MacDispatchModule::DispatchKeyDownEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  1083. {
  1084.     ODBoolean handled = kODFalse;
  1085.     const short kNotAllowed =  shiftKey | optionKey | controlKey;
  1086.     char key = (char) (theEvent->message & charCodeMask) ;
  1087.     
  1088.     if ( (theEvent->modifiers & cmdKey) && !(theEvent->modifiers & kNotAllowed) )
  1089.     {
  1090.         long menuResult = MenuKey(key);
  1091.         short menu = HiWord(menuResult);
  1092.         short item = LoWord(menuResult);
  1093.  
  1094.         if (menu == 0)     // Unmatched command keys, eg. Command-Period or Disabled Item
  1095.                         // Sent to part as keystroke
  1096.         {
  1097.             TempODFrame keyFrame = fArbitrator->AcquireFocusOwner(ev, fKeyFocusToken);
  1098.             handled = this->DispatchTheEvent(ev, theEvent, keyFrame, kODNULL, eventInfo);
  1099.         }
  1100.         else    // Turn it into a menu event
  1101.         {
  1102.             theEvent->what = kODEvtMenu;        
  1103.             theEvent->message = menuResult;
  1104.             handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  1105.  
  1106.             if (!handled)    // Deal with Close as a special case
  1107.             {
  1108.                 ODMenuBar* menuBar = fWindowState->AcquireCurrentMenuBar(ev);
  1109.                 ODCommandID command = menuBar ? menuBar->GetCommand(ev, menu, item) : 0;
  1110.                 menuBar->Release(ev);
  1111.                 
  1112.                 if (command == kODCommandClose)
  1113.                 {
  1114.                     TempODWindow activeWindow = fWindowState->AcquireActiveWindow(ev);
  1115.                     ODFrame* rootFrame = activeWindow ? activeWindow->GetRootFrame(ev) : kODNULL;
  1116.                     TempODPart rootPart = rootFrame ? rootFrame->AcquirePart(ev) : kODNULL;  // -- TÇ tempobj'd
  1117.                     
  1118.                     if (rootPart)
  1119.                     {
  1120. #if ODDebug && ODLogEvents
  1121.     LogEvent(theEvent, eventInfo, rootFrame, kODNULL);
  1122. #endif
  1123.                         handled = rootPart->HandleEvent(ev, theEvent,rootFrame, kODNULL, eventInfo);
  1124.                     }
  1125.                 }
  1126.             }
  1127.         }
  1128.     }
  1129.     else    // Regular unmodified keystrokes
  1130.     {
  1131.         TempODFrame scrollingFrame = fArbitrator->AcquireFocusOwner(ev, fScrollingFocusToken);
  1132.         if (scrollingFrame && 
  1133.             ((key == chPageUp) || (key == chPageDown) || (key == chHome) || (key == chEnd)))
  1134.         {
  1135.             handled = this->DispatchTheEvent(ev, theEvent, scrollingFrame, kODNULL, eventInfo);
  1136.         }    
  1137.         
  1138.         if (!handled)
  1139.         {
  1140.             TempODFrame keyFrame = fArbitrator->AcquireFocusOwner(ev, fKeyFocusToken);
  1141.             handled = this->DispatchTheEvent(ev, theEvent, keyFrame, kODNULL, eventInfo);
  1142.         }
  1143.     }
  1144.     return handled;
  1145. }    //    MacDispatchModule::DispatchKeyDownEvent
  1146.  
  1147. //-------------------------------------------------------------------------------------
  1148. // MacDispatchModule::DispatchKeyUpEvent
  1149. // 
  1150. // Description
  1151. //-------------------------------------------------------------------------------------
  1152.  
  1153. ODBoolean MacDispatchModule::DispatchKeyUpEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  1154. {
  1155.     ODBoolean handled = kODFalse;
  1156.     {
  1157.         TempODFrame targetFrame = fArbitrator->AcquireFocusOwner(ev, fKeyFocusToken);
  1158.         handled = this->DispatchTheEvent(ev, theEvent, targetFrame, kODNULL, eventInfo);
  1159.     }    
  1160.     return handled;
  1161. }    
  1162.  
  1163. //-------------------------------------------------------------------------------------
  1164. // MacDispatchModule::DispatchUpdateEvent
  1165. // 
  1166. // Description
  1167. //-------------------------------------------------------------------------------------
  1168.  
  1169. ODBoolean MacDispatchModule::DispatchUpdateEvent (Environment* ev, ODEventData* theEvent)
  1170. {
  1171.     ODBoolean handled = kODFalse;
  1172.     
  1173.     WindowPtr platformWindow = (WindowPtr) theEvent->message;
  1174.     TempODWindow aWindow = kODNULL;
  1175.     
  1176.     if (platformWindow && fWindowState->IsODWindow(ev, platformWindow))
  1177.         aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  1178.     
  1179.     if ( aWindow )
  1180.     {
  1181.         aWindow->HandleUpdateEvent(ev, theEvent);
  1182.         handled = kODTrue;
  1183.     }
  1184.     return handled;
  1185. }    //    MacDispatchModule::DispatchUpdateEvent
  1186.  
  1187. //-------------------------------------------------------------------------------------
  1188. // MacDispatchModule::DispatchActivateEvent
  1189. // 
  1190. // Description
  1191. //-------------------------------------------------------------------------------------
  1192.  
  1193. ODBoolean MacDispatchModule::DispatchActivateEvent    (Environment* ev, ODEventData* theEvent)
  1194. {
  1195.     ODBoolean handled = kODFalse;
  1196.  
  1197.     WindowPtr platformWindow = (WindowPtr) theEvent->message;
  1198.     TempODWindow aWindow = kODNULL;
  1199.     
  1200.     if (platformWindow)
  1201.         aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  1202.  
  1203.     if (aWindow )
  1204.     {
  1205. #if ODDebug && ODDebugLayerEvents
  1206.     //if ( ((WindowPeek)platformWindow)->windowKind != dialogKind)
  1207.     //{ 
  1208.         if ((theEvent->modifiers & activeFlag) != 0)
  1209.             somPrintf("Ignoring Activate Event from event loop for root frame %x\n", aWindow->GetRootFrame(ev));
  1210.         else
  1211.             somPrintf("Ignoring Deactivate Event from event loop for root frame %x\n", aWindow->GetRootFrame(ev));
  1212.     //}
  1213. #endif
  1214.         // Note: Ignoring activate events solves the following problem:
  1215.         // When using the Drafts dialog to select an existing draft,
  1216.         // the dialog would generate an activate event for the window below it
  1217.         // when closed. The shell then opens the selected draft which brings its 
  1218.         // window to the front using ODWindow::Select (i.e. no events).
  1219.         // But then the activate event  comes in for the window which is no
  1220.         // longer frontmost.
  1221.  
  1222.         // Bit 1 (starting from 0) of the modifiers field is set in ODWindow::Activate/Deactivate 
  1223.         // to alert the dispatcher that this is an OpenDoc-generated activate event. Toolbox-generated
  1224.         // activates are ignored.
  1225.  
  1226.         if (IsODActivateEvent(*theEvent))
  1227.         {
  1228. #if ODDebug && ODDebugLayerEvents
  1229.         if ((theEvent->modifiers & activeFlag) != 0)
  1230.             somPrintf("OD Activate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1231.         else
  1232.             somPrintf("OD Deactivate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1233. #endif
  1234.             aWindow->HandleActivateEvent(ev, theEvent);
  1235.         }
  1236.         else
  1237.         {
  1238. #if ODDebug && ODDebugLayerEvents
  1239.         if ((theEvent->modifiers & activeFlag) != 0)
  1240.             somPrintf("MacOS Activate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1241.         else
  1242.             somPrintf("MacOS Deactivate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1243. #endif
  1244.         }
  1245.         
  1246.         handled = kODTrue;
  1247.     }
  1248.     return handled;    
  1249. }    //    MacDispatchModule::DispatchActivateEvent
  1250.  
  1251. //-------------------------------------------------------------------------------------
  1252. // MacDispatchModule::DispatchTheEvent
  1253. // 
  1254. // Dispatches the event to the initial target, or to a containing frame/facet,
  1255. // if the initial target doesn't handle it, and the containing part has
  1256. // set the "DoesPropagateEvents" flag of the embedded frame
  1257. //-------------------------------------------------------------------------------------
  1258.  
  1259. ODBoolean MacDispatchModule::DispatchTheEvent(Environment* ev, 
  1260.                             ODEventData* theEvent, 
  1261.                             ODFrame* targetFrame,
  1262.                             ODFacet* targetFacet,
  1263.                             ODEventInfo* eventInfo)
  1264. {
  1265.     ODBoolean handled = kODFalse;
  1266.     TempODPart targetPart = targetFrame ? targetFrame->AcquirePart(ev) : kODNULL; // -- TÇ tempobj'd
  1267.  
  1268.     if ((ODPart*)targetPart)
  1269.     {
  1270.         if (eventInfo && targetFacet)
  1271.             WindowToLocal(ev, eventInfo->where, targetFacet);
  1272. #if ODDebug && ODLogEvents
  1273.     LogEvent(theEvent, eventInfo, targetFrame, targetFacet);
  1274. #endif
  1275.         if (eventInfo && eventInfo->embeddedFrame)
  1276.         {
  1277.             handled = targetPart->HandleEvent(ev, theEvent, targetFrame, targetFacet, eventInfo);
  1278.         }
  1279.         else
  1280.             handled = targetPart->HandleEvent(ev, theEvent, targetFrame, targetFacet, eventInfo);
  1281.         if (!handled)
  1282.         {
  1283.             handled = PropagateTheEvent(ev, theEvent,targetFrame, targetFacet, eventInfo);
  1284.         }
  1285.     }
  1286.     return handled;
  1287. }
  1288.  
  1289. ODBoolean MacDispatchModule::PropagateTheEvent(Environment* ev, 
  1290.                             ODEventData* theEvent, 
  1291.                             ODFrame* initialFrame,
  1292.                             ODFacet* initialFacet,
  1293.                             ODEventInfo* eventInfo)
  1294. {    
  1295.     ODFacet* targetFacet = initialFacet;
  1296.     TempODFrame targetFrame = initialFacet ? initialFacet->GetFrame(ev) : initialFrame; // DMc refcount - temp
  1297.     // ODPart* targetPart = initialFrame ? initialFrame->AcquirePart(ev) : kODNULL; // Appears to be obsolete -TÇ
  1298.     ODBoolean handled = kODFalse;
  1299.         
  1300.     targetFrame->Acquire(ev);    // -- TÇ added
  1301.     while (targetFrame)
  1302.     {
  1303.         if (handled  || (!targetFrame->DoesPropagateEvents(ev)))
  1304.             break;
  1305.             
  1306.         if (targetFacet)
  1307.         {
  1308.             targetFacet = targetFacet->GetContainingFacet(ev);
  1309.             ODReleaseObject(ev, targetFrame); // DMc: about to reassign
  1310.             targetFrame = targetFacet ? targetFacet->GetFrame(ev) : kODNULL;
  1311.         }
  1312.         else
  1313.         {
  1314.             ODFrame* contFrame = targetFrame->AcquireContainingFrame(ev);     // -- TÇ added
  1315.             ODReleaseObject(ev, targetFrame);                                // -- TÇ added
  1316.             targetFrame = contFrame;
  1317.         }
  1318.         
  1319.         {    
  1320.             TempODPart targetPart = targetFrame ? targetFrame->AcquirePart(ev) : kODNULL; // -- TÇ tempobj'd
  1321.             if ((ODPart*)targetPart)
  1322.             {
  1323.                 eventInfo->propagated = kODTrue;
  1324.                 handled = targetPart->HandleEvent(ev, theEvent, targetFrame, targetFacet, eventInfo);
  1325.             }
  1326.         }
  1327.     }
  1328.         
  1329.     return handled;
  1330. }
  1331.  
  1332.