home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / Disptch.cpp < prev    next >
Text File  |  1997-03-21  |  63KB  |  1,629 lines

  1. /* @(#)Z 1.27 com/src/ui/Disptch.cpp, odui, od96os2, odos29712d 97/03/21 17:20:17 (97/03/12 18:28:07) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odui
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. /********************************************************************/
  30. /*  Licensed Materials - Property of IBM                            */
  31. /*                                                                  */
  32. /*                                                                  */
  33. /* Copyright (C) International Business Machines Corp., 1994.       */
  34. /* Copyright (C) Apple Computer, Inc., 1994                         */
  35. /*                                                                  */
  36. /*  US Government Users Restricted Rights -                         */
  37. /*  Use, duplication, or disclosure restricted                      */
  38. /*  by GSA ADP Schedule Contract with IBM Corp.                     */
  39. /*                                                                  */
  40. /*  IBM Change History (most recent first):                         */
  41. /*  133968  8/23/95 pfe  DR3 port of Apple code                     */
  42. /*  129403  7/28/95 aml  Added WM_HSCROLL and WM_VSCROLL to the     */
  43. /*                       standard dispatch event table              */
  44. /*  125850  7/18/95 aml  Changed kODErrDispatchModuleAlreadyExists  */
  45. /*                       to kODErrExistingDispatchModule and        */
  46. /*                       kODErrDispatchModuleNotInitialized to      */
  47. /*                       kODErrInvalidDispatchModule, as per class  */
  48. /*                       reference                                  */
  49. /*  107613  5/25/95 aml  Throw if adding an uninitialized dispatch  */
  50. /*                       module (AddDispatchModule & AddMonitor)    */
  51. /*  107617  5/25/95 aml  Throw if adding an existing event/dispatch */
  52. /*                       module (AddDispatchModule )                */
  53. /*  107819  5/25/95 aml  Added RemoveDispatchModuleEntries method   */
  54. /*  120604  4/28/95 ced  Merge with B1C16 Apple code.               */
  55. /*  04/11/95  BLG   Added support for WM_MENUSELECT for status line */
  56. /*                  display                                         */
  57. /*  04/07/95  BLG   added support for Opendoc message OD_HELP       */
  58. /*                                                                  */
  59. /********************************************************************/
  60. /*
  61.         File:           Disptch.cpp
  62.  
  63.         Contains:       Implementation of class ODDispatcher
  64.  
  65.         Owned by:       Richard Rodseth
  66.  
  67.         Copyright:      ⌐ 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  68.  
  69.         Change History (most recent first):
  70.  
  71.                 <50>    10/17/95        jpa             1292659: Ignore exceptions sending null
  72.                                                                         events to parts
  73.                 <49>    10/10/95        DM              1277216: GM:API: Dont return ODPoint from
  74.                                                                         GetWindowPoint()
  75.                 <48>     10/3/95        TJ              Changes done by RefBall Team
  76.                 <47>      9/6/95        RR              #1282075 ADded ODVolatile
  77.                 <46>     8/29/95        RR              # 1276401 Respect Mouse Focus
  78.                 <45>     8/26/95        Té              1274606 FB2: Patching Remarks
  79.                 <44>     8/23/95        NP              1264142: Don't Release null object.
  80.                 <43>     8/15/95        RR              #1222870 Moved NULL handling to end of
  81.                                                                         method to allow patching/monitors
  82.                 <42>      8/3/95        RR              #1257260: Collapse B classes. Remove
  83.                                                                         somInit methods. Don't call IsInitialized
  84.                                                                         or SubclassResponsibility
  85.                 <41>     6/29/95        NP              1263893: Fix TSM support.
  86.                 <40>     6/25/95        Té              1242642 BB: Turn on ODDebug warning if
  87.                                                                         refcount is wrong in
  88.                                                                         ODRefCntObjectsomUninit.
  89.                 <39>     6/23/95        CC              1256943: MouseRegionIsInvalid: Replaced
  90.                                                                         StillDown with Button.
  91.                 <38>     6/22/95        NP              1260250: Set up correctly for call to
  92.                                                                         CallEventHandler.
  93.                 <37>     6/20/95        JP              1251250: ChangedReleaseExtension into
  94.                                                                         Release
  95.                 <36>     6/15/95        RR              #1254828/1255536 Added Redispatch
  96.                 <35>      6/8/95        RR              #1257260 Collapse base classes. #1214898
  97.                                                                         StdTypes.r -> ODTypes.r
  98.                 <34>     5/31/95        RR              #1251403 Release after AcquirePart
  99.                 <33>     5/26/95        RR              #1251403: Multithreading naming support
  100.                 <32>     5/25/95        jpa             Fixed usage of ODDebug. [1253321]
  101.                 <31>     5/21/95        NP              1251212: Wrap procs with UPPs.
  102.                 <30>     5/17/95        RR              #1250135/1250137/1250143 Getters increment
  103.                                                                         refcount
  104.                 <29>     5/10/95        RR              #1239139 MouseEnter etc.  over active
  105.                                                                                                                                                 border go to container. Don't send
  106.                                                                         until mouse up.
  107.                 <28>     5/10/95        RR               #1239139 MouseEnter etc.  over active
  108.                                                                         border go to container. Don't send until mouse up.
  109.                 <27>     4/27/95        eeh             1230798: call part::ReleaseExtension
  110.                 <26>      4/7/95        RR              #1216618 Added SOM_TRY etc.
  111.                 <25>      4/4/95        RR              # 1211085 Removed fThreadsAvailable,
  112.                                                                         #1220104 Use ODObjectsAreEqual, #1228161
  113.                                                                         RegisterIdle does not update frequency if
  114.                                                                         called twice
  115.                 <24>     3/20/95        jpa             Cooperative thread support [1167943]. Moved
  116.                                                                         bg click handler installation to private
  117.                                                                         impl file [1220704].
  118.                 <23>     3/10/95        RR              # 1187137 Set Cursor to arrow in
  119.                                                                         InvalidateFacetUnderMouse
  120.                 <22>     2/24/95        jpa             Install BG-mouse-down handler [1220704].
  121.                                                                         Use ODNewRgn. [1220810]
  122.                 <21>     2/20/95        Té              #1221861 BB: Incomplete AOCE support needs
  123.                                                                         to be removed from OpenDoc
  124.                 <20>     1/31/95        RR              # 1206909 Pass ev to
  125.                                                                         RemoveUnregisteredIdlers
  126.                 <19>     1/25/95        jpa             Include StdExts.xh [1206907]
  127.                 <18>     1/13/95        RR              Replace calls to MouseEnter etc with calls
  128.                                                                         to HandleEvent
  129.                 <17>     1/12/95        jpa             Don't use obsolete Toolbox names [1211211].
  130.                                                                         Change qd --> ODQDGlobals [1210936]
  131.                 <16>      1/9/95        NP              1194880: SemtIntf name changes.
  132.                 <15>    11/28/94        RR              Prepare for thread support
  133.                 <14>     9/30/94        RR              #1167950 Allow unregistering while idling.
  134.                                                                         Call RemoveUnregisteredIdlers in
  135.                                                                         HandleNULLEvent
  136.                 <13>     9/29/94        RA              1189812: Mods for 68K build.
  137.                 <12>     9/20/94        NP              1187682: Initial TSM support.
  138.                 <11>     9/20/94        RR              #1154046 Moved ref counting into IdleList
  139.                                                                         methods so that an unregistered part is not
  140.                                                                         released. #1156594 Call
  141.                                                                         WindowState->HandleAOCEMailerEvent instead
  142.                                                                         of calling SMPMailerEvent directly.
  143.                 <10>      9/2/94        eeh             #?: added SMPMailerEvent call to enable use
  144.                                                                         of mailer until Richard and I agree on a
  145.                                                                         cleaner fix to a bug in his hamper.
  146.                  <9>     8/31/94        Té              #1183129, #1183116, #1183119, #1183111:
  147.                                                                         Lots of ErrorCode cleanup.
  148.                  <8>     8/15/94        JBS             1181156: UI API Cleanup
  149.                  <7>     8/10/94        JBS             1179919: coordinate system bias changes
  150.                  <6>      8/4/94        eeh             bug 1177981: add
  151.                                                                         ODDispatcherGetDispatchModule
  152.                  <5>     7/27/94        eeh             Changes necessitated by WinStat.idl changes
  153.                  <4>     7/26/94        eeh             ODQDPoint->Point
  154.                  <3>     6/30/94        CG              Moved InitStandardDispatchModule to
  155.                                                                         InitDispatch from InitSession.
  156.                  <2>     9/27/94        RR              Call InitBaseDispatcher
  157.                  <1>     9/26/94        RR              first checked in
  158.  
  159.         To Do:
  160.                 * Get Gestalt bit for gestaltHasBGMouseDown.
  161.                 * Call SetBgndMouseHandler via PrivateInterfaceLib if it's exported therefrom.
  162.                 * Check whether bg mousedown handler calls are exported from PrivateInterfaceLib
  163.                         and use those if they are (for Copland compatibility)
  164.  
  165.         In Progress:
  166.  
  167. */
  168.  
  169.  
  170. /*
  171.  *  This file was generated by the SOM Compiler.
  172.  *  Generated using:
  173.  *      SOM Emitter emitxtm.dll: somc/smmain.c
  174.  */
  175.  
  176. // ------------------------
  177. #ifdef _PLATFORM_OS2_
  178. #include <ODOs2.h>
  179. #endif // _PLATFORM_OS2_
  180. // ------------------------
  181.  
  182. #define ODDispatcher_Class_Source
  183. #define VARIABLE_MACROS
  184. #include <Disptch.xih>
  185.  
  186. // Platform-independent include files
  187.  
  188. #ifndef SOM_ODDispatchModule_xh
  189. #include "DispMod.xh"
  190. #endif
  191.  
  192. #ifndef SOM_ODWindowState_xh
  193. #include "WinStat.xh"
  194. #endif
  195.  
  196. #ifndef SOM_ODWindow_xh
  197. #include "Window.xh"
  198. #endif
  199.  
  200. #ifndef SOM_ODSession_xh
  201. #include "ODSessn.xh"
  202. #endif
  203.  
  204. #ifndef _DISPTABL_
  205. #include "DispTabl.h"
  206. #endif
  207.  
  208. #ifndef SOM_ODFacet_xh
  209. #include "Facet.xh"
  210. #endif
  211.  
  212. #ifndef SOM_ODFrame_xh
  213. #include "Frame.xh"
  214. #endif
  215.  
  216. #ifndef SOM_ODPart_xh
  217. #include "Part.xh"
  218. #endif
  219.  
  220. #ifndef _EXCEPT_
  221. #include "Except.h"
  222. #endif
  223.  
  224. #ifndef SOM_ODStandardDispatchModule_xh
  225. #include <StdDisp.xh>
  226. #endif
  227.  
  228. #ifndef _ODDEBUG_
  229. #include "ODDebug.h"
  230. #endif
  231.  
  232. #ifndef SOM_ODArbitrator_xh
  233. #include <Arbitrat.xh>
  234. #endif
  235.  
  236. #ifndef SOM_Module_OpenDoc_Foci_defined
  237. #include <Foci.xh>
  238. #endif
  239.  
  240. #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
  241. #include <StdExts.xh>
  242. #endif
  243.  
  244. #ifndef _DSPUTILM_
  245. #include "DspUtilM.h"
  246. #endif
  247.  
  248. #ifndef _ODUtils_
  249. #include <ODUtils.h>
  250. #endif
  251.  
  252. #ifdef _PLATFORM_MACINTOSH_
  253. // -------------------------------------
  254. // Mac-only include files & declarations
  255. // -------------------------------------
  256.  
  257. #ifndef _TEMPOBJ_
  258. #include <TempObj.h>
  259. #endif
  260.  
  261. #ifndef _IDLELIST_
  262. #include "IdleList.h"
  263. #endif
  264.  
  265. #ifndef _ORDCOLL_
  266. #include "OrdColl.h"
  267. #endif
  268.  
  269. #ifndef SOM_ODSemanticInterface_xh
  270. #include <SemtIntB.xh>
  271. #endif
  272.  
  273. #ifndef SOM_ODAppleEvent_xh
  274. #include <ODAplEvt.xh>
  275. #endif
  276.  
  277. #ifndef _BARRAY_
  278. #include "BArray.h"
  279. #endif
  280.  
  281. #ifndef _ODDESUTL_
  282. #include "ODDesUtl.h"
  283. #endif
  284.  
  285. #ifndef _BGCLICKM_
  286. #include "BGClickM.h"
  287. #endif
  288.  
  289. #ifndef _ODTHREDM_
  290. #include "ODThredM.h"
  291. #endif
  292.  
  293. #ifndef __TEXTSERVICES_
  294. #include "TextServices.h"
  295. #endif
  296.  
  297. #ifndef __GESTALTEQU__
  298. #include <GestaltEqu.h>
  299. #endif
  300.  
  301. #define ODLogEvents 0
  302.  
  303. #pragma segment ODDispatcher
  304.  
  305. /* Define event types handled by Standard Mac Dispatch Module */
  306.  
  307. ODEventType StdMacEventTypes[] = {
  308.         mouseDown,
  309.         mouseUp,
  310.         keyDown,
  311.         keyUp,
  312.         autoKey,
  313.         updateEvt,
  314.         diskEvt,
  315.         activateEvt,
  316.         osEvt,
  317.         kHighLevelEvent,
  318.         kODEvtMenu,
  319.         kODEvtBGMouseDown,
  320.         kODEvtMouseDownBorder,
  321.         kODEvtMouseDownEmbedded,
  322.         kODEvtBGMouseDownEmbedded,
  323.         kODEvtMouseUpEmbedded
  324. };
  325.  
  326. ODULong NumStdMacEventTypes = sizeof(StdMacEventTypes) / sizeof(ODEventType);
  327.  
  328. #endif // _PLATFORM_MACINTOSH_
  329.  
  330. #ifdef _PLATFORM_OS2_ //CED
  331. // --------------------------------------
  332. // OS/2-only include files & declarations
  333. // --------------------------------------
  334.  
  335. #ifndef _ORDCOLL_
  336. #include "OrdColl.h"
  337. #endif
  338.  
  339. #ifndef _PLFMDEF_
  340. #include "PlfmDef.h"
  341. #endif
  342.  
  343. #ifndef _ERRORDEF_
  344. #include "ErrorDef.xh"
  345. #endif
  346.  
  347. #ifndef _DSPLITEM_
  348. #include "dsplitem.h"
  349. #endif
  350.  
  351. /* Define event types handled by Standard OS/2 Dispatch Module */
  352.  
  353. ODEventType StdOS2EventTypes[] = {
  354.       WM_BUTTON1DOWN
  355.      ,WM_BUTTON2DOWN
  356.      ,WM_BUTTON3DOWN
  357.      ,WM_BUTTON1UP
  358.      ,WM_BUTTON2UP
  359.      ,WM_BUTTON3UP
  360.      ,WM_MOUSEMOVE
  361.      ,WM_CHORD
  362.      ,WM_BUTTON1MOTIONSTART
  363.      ,WM_BUTTON1MOTIONEND
  364.      ,WM_BUTTON2MOTIONSTART
  365.      ,WM_BUTTON2MOTIONEND
  366.      ,WM_BUTTON3MOTIONSTART
  367.      ,WM_BUTTON3MOTIONEND
  368.      ,WM_CONTEXTHELP
  369.      ,WM_BUTTON1CLICK
  370.      ,WM_BUTTON2CLICK
  371.      ,WM_BUTTON3CLICK
  372.      ,WM_BUTTON1DBLCLK
  373.      ,WM_BUTTON2DBLCLK
  374.      ,WM_BUTTON3DBLCLK
  375.      ,WM_BEGINDRAG
  376.      ,WM_ENDDRAG
  377.      ,WM_SINGLESELECT
  378.      ,WM_CONTEXTMENU
  379.      ,WM_BEGINSELECT
  380.      ,WM_ENDSELECT
  381.      ,WM_OPEN
  382.      ,WM_TEXTEDIT
  383.      ,WM_CHAR
  384.      ,kODEvtKeyUp
  385.      ,kODEvtKeyDown
  386.      ,WM_PAINT
  387.      ,WM_ACTIVATE
  388.      ,WM_COMMAND
  389.      ,WM_INITMENU
  390.      ,WM_TIMER
  391.      ,WM_SIZE
  392.      ,WM_MOVE
  393.      ,WM_RENDERFMT
  394.      ,DM_DRAGOVER
  395.      ,DM_DRAGLEAVE
  396.      ,DM_DROP
  397.      ,DM_RENDER
  398.      ,DM_RENDERCOMPLETE
  399.      ,DM_ENDCONVERSATION
  400.      ,WM_MENUSELECT
  401.      ,WM_DRAWITEM
  402.      ,WM_MEASUREITEM
  403.      ,OD_HELP
  404.      ,WM_QUERYCONVERTPOS  // [124535]
  405.      ,WM_REALIZEPALETTE   // [129147]
  406.      ,WM_PRESPARAMCHANGED // [129147]
  407.      ,WM_HSCROLL          // [129403]
  408.      ,WM_VSCROLL          // [129403]
  409. };
  410.  
  411. ODULong NumStdOS2EventTypes = sizeof(StdOS2EventTypes) / sizeof(ODEventType);
  412.  
  413. #endif // _PLATFORM_OS2_ //CED
  414.  
  415. #ifdef _PLATFORM_WIN32_
  416. // ---------------------------------------
  417. // WIN32-only include files & declarations
  418. // ---------------------------------------
  419.  
  420. #ifndef _ORDCOLL_
  421. #include "OrdColl.h"
  422. #endif
  423.  
  424. #ifndef _STDDISPWIN_
  425. #include <StdDispW.xh>
  426. #endif
  427.  
  428. /* Define event types handled by Standard Win32 Dispatch Module */
  429.  
  430. ODEventType StdWinEventTypes[] = {
  431.   WM_RBUTTONDOWN,
  432.   WM_MBUTTONDOWN,
  433.   WM_LBUTTONDOWN,
  434.   WM_RBUTTONUP,
  435.   WM_MBUTTONUP,
  436.   WM_LBUTTONUP,
  437.   WM_RBUTTONDBLCLK,
  438.   WM_MBUTTONDBLCLK,
  439.   WM_LBUTTONDBLCLK,
  440.   WM_KEYDOWN,
  441.   WM_KEYUP,
  442.   WM_CHAR,
  443.   WM_MOUSEMOVE,
  444.   WM_VSCROLL,
  445.   WM_HSCROLL,
  446.   WM_PAINT,
  447.   WM_ACTIVATE,
  448.   WM_COMMAND,
  449.   WM_ERASEBKGND,
  450.   WM_NCCREATE,
  451.   WM_SETFOCUS,
  452.   WM_SIZE,
  453.   WM_WINDOWPOSCHANGED,
  454.   WM_SETCURSOR,
  455.   kODEvtMouseDownEmbedded,
  456.   kODEvtMouseDownBorder,
  457.   kODEvtMouseUpEmbedded,
  458.   OD_HELP
  459. };
  460.  
  461. ODULong NumStdWinEventTypes = sizeof(StdWinEventTypes) / sizeof(ODEventType);
  462.  
  463. #endif // _PLATFORM_WIN32_
  464.  
  465. #ifdef _PLATFORM_UNIX_
  466. // ---------------------------------------
  467. // UNIX-only include files & declarations
  468. // ---------------------------------------
  469.  
  470. #ifndef X_H
  471. #include "X.h"
  472. #endif
  473.  
  474. #ifndef _ORDCOLL_
  475. #include "OrdColl.h"
  476. #endif
  477.  
  478. #ifndef _STDDISPX11_
  479. #include <StdDispX.xh>
  480. #endif
  481.  
  482. /* Define event types handled by Standard X11 Dispatch Module */
  483.  
  484. ODEventType StdX11EventTypes[] = {
  485.         ButtonPress,
  486.         ButtonRelease,
  487.         KeyPress,
  488.         KeyRelease,
  489.         Expose,
  490.         ConfigureNotify,
  491.         FocusIn,
  492.         FocusOut,
  493.         MotionNotify,
  494.         kODEvtMouseDownEmbedded,
  495.         kODEvtMouseUpEmbedded,
  496.         kODEvtMouseDownBorder,
  497.         kODEvtMenu
  498. };
  499.  
  500. ODULong NumStdX11EventTypes = sizeof(StdX11EventTypes) / sizeof(ODEventType);
  501.  
  502. #endif // _PLATFORM_UNIX_
  503.  
  504. //------------------------------------------------------------------------------
  505. //      ODDispatcher
  506. //------------------------------------------------------------------------------
  507.  
  508. #ifdef _PLATFORM_MACINTOSH_
  509. //------------------------------------------------------------------------------
  510. //      RegisterIdle (Mac-only)
  511. //------------------------------------------------------------------------------
  512. SOM_Scope void  SOMLINK ODDispatcherRegisterIdle(ODDispatcher *somSelf, Environment *ev,
  513.                 ODPart* part,
  514.                 ODFrame* frame,
  515.                 ODIdleFrequency frequency)
  516. {
  517.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  518.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherRegisterIdle");
  519.  
  520.         SOM_TRY
  521.  
  522.                 if (part)
  523.                         _fIdleList->AddIdle(ev, part, frame, frequency);
  524.  
  525.         SOM_CATCH_ALL
  526.         SOM_ENDTRY
  527. }
  528.  
  529. //------------------------------------------------------------------------------
  530. //      UnregisterIdle (Mac-only)
  531. //------------------------------------------------------------------------------
  532. SOM_Scope void  SOMLINK ODDispatcherUnregisterIdle(ODDispatcher *somSelf, Environment *ev,
  533.                 ODPart* part,
  534.                 ODFrame* frame)
  535. {
  536.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  537.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherUnregisterIdle");
  538.  
  539.         SOM_TRY
  540.  
  541.                 if (part)
  542.                         _fIdleList->RemoveIdle(ev, part, frame);
  543.  
  544.         SOM_CATCH_ALL
  545.         SOM_ENDTRY
  546. }
  547.  
  548. //------------------------------------------------------------------------------
  549. //      SetIdleFrequency (Mac-only)
  550. //------------------------------------------------------------------------------
  551. SOM_Scope void  SOMLINK ODDispatcherSetIdleFrequency(ODDispatcher *somSelf, Environment *ev,
  552.                 ODPart* part,
  553.                 ODFrame* frame,
  554.                 ODIdleFrequency frequency)
  555. {
  556.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  557.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherSetIdleFrequency");
  558.  
  559.         SOM_TRY
  560.  
  561.                 if (part)
  562.                         _fIdleList->SetIdleFrequency(ev, part, frame, frequency);
  563.  
  564.         SOM_CATCH_ALL
  565.         SOM_ENDTRY
  566. }
  567.  
  568. //------------------------------------------------------------------------------
  569. //      Yield (Mac-only)
  570. //------------------------------------------------------------------------------
  571. SOM_Scope void  SOMLINK ODDispatcherYield(ODDispatcher *somSelf, Environment *ev,
  572.                 ODFrame* frame)
  573. {
  574.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  575.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherYield");
  576.  
  577.         SOM_TRY
  578.  
  579.         /*
  580.                 Will Call WaitNextEvent(), masking out all but null and update events.
  581.                 Idle events are sent to all but the part that yielded
  582.         */
  583.                 const   ODSLong         kODSleepTicks                   =       20L;//  Number sleep ticks
  584.  
  585.                 EventRecord             eventRec;
  586.                 WaitNextEvent ( updateMask, &eventRec, somSelf->GetSleepTime(ev), somSelf->GetMouseRegion(ev) ) ;
  587.                 if (eventRec.what == nullEvent)
  588.                         somSelf->HandleNullEvent(ev, (ODEventData*) &eventRec, frame);  // Note Cast
  589.                 else
  590.                         somSelf->Dispatch(ev, (ODEventData*) &eventRec);
  591.  
  592.  
  593.         SOM_CATCH_ALL
  594.         SOM_ENDTRY
  595. }
  596.  
  597. //------------------------------------------------------------------------------
  598. //      SetMouseRegion (Mac-only)
  599. //------------------------------------------------------------------------------
  600. SOM_Scope void  SOMLINK ODDispatcherSetMouseRegion(ODDispatcher *somSelf, Environment *ev,
  601.                 ODRgnHandle area)
  602. {
  603.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  604.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherSetMouseRegion");
  605.  
  606.         if (area && _fPartMouseRegion)
  607.         {
  608.                 CopyRgn(area, _fPartMouseRegion);
  609.         }
  610.  
  611. }
  612.  
  613. //------------------------------------------------------------------------------
  614. //      GetMouseRegion (Mac-only)
  615. //------------------------------------------------------------------------------
  616. SOM_Scope ODRgnHandle  SOMLINK ODDispatcherGetMouseRegion(ODDispatcher *somSelf, Environment *ev)
  617. {
  618.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  619.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetMouseRegion");
  620.  
  621.         SOM_TRY
  622.  
  623.                 if (somSelf->MouseRegionIsInvalid(ev))
  624.                         somSelf->ComputeMouseRegion(ev);
  625.  
  626.  
  627.         /*
  628.  
  629.                         CGrafPort desktopPort;                                  // Used for showing cursor region
  630.                         long ticks;                                                             // Used for showing cursor region
  631.                         GrafPtr savedPort;                                              // Used for showing cursor region
  632.  
  633.                         // Cursor region is in global coords. Need to create desktop port
  634.                         GetPort(&savedPort);
  635.                         OpenCPort(&desktopPort);
  636.                         CopyRgn(GetGrayRgn(), desktopPort.visRgn);
  637.                         desktopPort.portRect = (*(desktopPort.visRgn))->rgnBBox;
  638.  
  639.                         PenNormal();
  640.                         PenMode(patXor);
  641.  
  642.                         PaintRgn(_fPartMouseRegion);
  643.                         Delay(30, &ticks);
  644.                         PaintRgn(_fMouseRegion);
  645.  
  646.                         CloseCPort(&desktopPort);
  647.                         SetPort(savedPort);
  648.  
  649.  
  650.         */
  651.  
  652.         return _fMouseRegion;
  653.  
  654.         SOM_CATCH_ALL
  655.  
  656.                 return kODNULL;
  657.  
  658.         SOM_ENDTRY
  659.  
  660.         return kODNULL;
  661. }
  662.  
  663. //------------------------------------------------------------------------------
  664. //      InvalidateFacetUnderMouse (Mac-only)
  665. //------------------------------------------------------------------------------
  666. SOM_Scope void  SOMLINK ODDispatcherInvalidateFacetUnderMouse(ODDispatcher *somSelf, Environment *ev)
  667. {
  668.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  669.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherInvalidateFacetUnderMouse");
  670.  
  671.         SOM_TRY
  672.  
  673.                 _fFacetUnderMouse = kODNULL;
  674.                 somSelf->InvalidateMouseRegion(ev);
  675.                 SetCursor(&ODQDGlobals.arrow);
  676.  
  677.         SOM_CATCH_ALL
  678.         SOM_ENDTRY
  679. }
  680.  
  681. //------------------------------------------------------------------------------
  682. //      GetSleepTime (Mac-only)
  683. //------------------------------------------------------------------------------
  684. SOM_Scope ODSLong  SOMLINK ODDispatcherGetSleepTime(ODDispatcher *somSelf, Environment *ev)
  685. {
  686.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  687.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetSleepTime");
  688.  
  689.         SOM_TRY
  690.  
  691.                 // Don't sleep at all if another thread is ready to run:
  692.                 if( ODAnyThreadsReady() )
  693.                         return 0;
  694.  
  695.                 const ODSLong kMaxLong = 2147483647;
  696.                 const ODTicks kMaxIdleTime = kMaxLong;
  697.  
  698.  
  699.                 ODTicks waitTicks = kMaxIdleTime;
  700.  
  701.                 IdleListIterator iter(_fIdleList);
  702.  
  703.                 for (IdleInfo* idleInfo = iter.First(); iter.IsNotComplete(); idleInfo = iter.Next())
  704.                 {
  705.                         waitTicks = Min(waitTicks, idleInfo->NextIdle(TickCount()));
  706.                 }
  707.                 return waitTicks;
  708.  
  709.         SOM_CATCH_ALL
  710.  
  711.                 return 0;
  712.  
  713.         SOM_ENDTRY
  714.  
  715.         return 0;
  716. }
  717.  
  718. //------------------------------------------------------------------------------
  719. //      HandleTSMEvents (Mac-only) (non-SOM)
  720. //------------------------------------------------------------------------------
  721. static OSErr pascal HandleTSMEvents(const AppleEvent *theAppleEvent,
  722.                                                                                 AppleEvent *reply,
  723.                                                                                 long handlerRefcon)
  724. {
  725.         ODSession*              session = (ODSession*)handlerRefcon;
  726.         Environment*    ev = somGetGlobalEnvironment();
  727. //      DescType                eventID;
  728. //      DescType                actualType;
  729.         Size                    maxSize = sizeof(DescType);
  730. //      Size                    actualSize;
  731.         OSErr                   result = noErr;
  732.         ODSemanticInterface* semtIntf = kODNULL; ODVolatile(semtIntf);
  733.         ODPart* keyPart = kODNULL; ODVolatile(keyPart);
  734.  
  735.         TRY
  736.                 TempODFrame keyFrame
  737.                         = session->GetArbitrator(ev)->AcquireFocusOwner(ev,
  738.                                                                                                 session->Tokenize(ev,
  739.                                                                                                                                         kODKeyFocus));
  740.                         // -- Té tempobj'd
  741.                 if ((ODFrame*)keyFrame != kODNULL)
  742.                 {
  743.                         keyPart = keyFrame->AcquirePart(ev);
  744.                         if (keyPart->HasExtension(ev, kODExtSemanticInterface))
  745.                         {
  746.                                 semtIntf = (ODSemanticInterface*)keyPart->AcquireExtension(ev,
  747.                                                                                                                 kODExtSemanticInterface);
  748.                                 // WHAT WAS I GOING TO DO WITH THIS INFO? - NP 6/21/95
  749. //                              result = AEGetAttributePtr(theAppleEvent, keyEventIDAttr,
  750. //                                                                                                      typeType, &actualType,
  751. //                                                                                                      (Ptr)&eventID, maxSize,
  752. //                                                                                                      &actualSize);
  753. //                              if (result || actualType != typeType || actualSize != maxSize)
  754. //                                      THROW(errAEEventNotHandled);
  755.  
  756.                                 // CREATE NEW ODAPPLEEVENTS FOR THE PARAMETERS
  757.                                 ODAppleEvent*   odEvent = new ODAppleEvent;
  758.                                 THROW_IF_NULL(odEvent);
  759.                                 odEvent->InitODAppleEvent(ev);
  760.                                 AEDescToODDesc((AEDesc*)theAppleEvent, odEvent);
  761.                                 ODAppleEvent*   odReply = new ODAppleEvent;
  762.                                 THROW_IF_NULL(odReply);
  763.                                 odReply->InitODAppleEvent(ev);
  764.                                 AEDescToODDesc((AEDesc*)reply, odReply);
  765.  
  766.                                 // PASS THE EVENT TO THE PART
  767.                                 TRY
  768.                                         semtIntf->CallEventHandler(ev, keyPart, odEvent, odReply);
  769.                                 CATCH_ALL
  770.                                         result = ErrorCode();
  771.                                 ENDTRY
  772.  
  773.                                 // CLEAN UP. NOTE, WE MUST UPDATE THE REPLY DATAHANDLE SO THAT
  774.                                 //      THE APPLE EVENTS MANAGER SEES THE CHANGE (IF ANY).
  775.                                 delete odEvent;
  776.                                 if (reply->descriptorType != typeNull
  777.                                                 && reply->dataHandle != kODNULL
  778.                                                 && !result)
  779.                                 {
  780.                                         ODByteArray data = odReply->GetRawData(ev);
  781.                                         SetHandleSize(reply->dataHandle, data._length);
  782.                                         THROW_IF_ERROR(MemError());
  783.                                         ODBlockMove(data._buffer, *(reply->dataHandle),
  784.                                                                         data._length);
  785.                                         DisposeByteArrayStruct(data);
  786.                                 }
  787.                                 delete odReply;
  788.                         }
  789.                         else
  790.                                 result = errAEEventNotHandled;
  791.                 }
  792.                 else
  793.                         result = errAEEventNotHandled;
  794.         CATCH_ALL
  795.                 result = ErrorCode();
  796.         ENDTRY
  797.  
  798.         if ( semtIntf != kODNULL )
  799.                 semtIntf->Release(ev);
  800.         if ( keyPart != kODNULL )
  801.                 keyPart->Release(ev);
  802.  
  803.         return result;
  804. }
  805.  
  806. #endif // _PLATFORM_MACINTOSH_
  807.  
  808. #ifdef _PLATFORM_UNIX_
  809. //------------------------------------------------------------------------------
  810. //      SetXtDispatchMode (UNIX-only)
  811. //------------------------------------------------------------------------------
  812. SOM_Scope void  SOMLINK ODDispatcherSetXtDispatchMode(ODDispatcher *somSelf,
  813.                               Environment *ev,
  814.                               ODBoolean mode)
  815. {
  816.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  817.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherSetXtDispatchMode");
  818.  
  819.     _fXtDispatchMode = mode;
  820. }
  821.  
  822. //------------------------------------------------------------------------------
  823. //      GetXtDispatchMode (UNIX-only)
  824. //------------------------------------------------------------------------------
  825. SOM_Scope ODBoolean  SOMLINK ODDispatcherGetXtDispatchMode(ODDispatcher *somSelf,
  826.                               Environment *ev)
  827. {
  828.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  829.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetXtDispatchMode");
  830.  
  831.     return _fXtDispatchMode;
  832. }
  833. #endif // PLATFORM_UNIX
  834.  
  835. //------------------------------------------------------------------------------
  836. //      InitDispatcher
  837. //------------------------------------------------------------------------------
  838. SOM_Scope void  SOMLINK ODDispatcherInitDispatcher(ODDispatcher *somSelf, Environment *ev,
  839.                 ODSession* session)
  840. {
  841.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  842.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherInitDispatcher");
  843.  
  844.     const ODBoolean     kIsSysHandler = kODTrue;
  845.  
  846.     try {
  847.  
  848.         /* Moved from somInit. SOM itself sets fields to zero
  849.         // _fExit = kODFalse;
  850.  
  851.         // _fDispatchModules = kODNULL;
  852.         // _fMonitors = kODNULL;
  853.         // _fDispatchTable = kODNULL;
  854.  
  855.         // _fSession = kODNULL;
  856.         // _fIdleList = kODNULL;
  857.  
  858.         // _fMouseRegion = kODNULL;
  859.         // _fPartMouseRegion = kODNULL;
  860.         // _fFacetUnderMouse = kODNULL;
  861.         */
  862.  
  863.         somSelf->InitObject(ev);
  864.  
  865.         _fSession = session;
  866.  
  867.         /* Create dispatch table */
  868.  
  869.         _fDispatchTable = new DispatchTable;
  870.         THROW_IF_NULL(_fDispatchTable);
  871.  
  872.         /* Create idle list and mouse regions (Mac only) */
  873.  
  874. #ifdef _PLATFORM_MACINTOSH_
  875.         _fIdleList = new IdleList;
  876.         THROW_IF_NULL(_fIdleList);
  877.  
  878.         _fMouseRegion = ODNewRgn();
  879.         _fPartMouseRegion = ODNewRgn();
  880. #endif // _PLATFORM_MACINTOSH_
  881.  
  882.         /* Create platform-specific standard dispatch modules */
  883.  
  884. #ifdef _PLATFORM_MACINTOSH_
  885.         ODStandardDispatchModule* stdMacModule = new ODStandardDispatchModule();
  886.         THROW_IF_NULL(stdMacModule);
  887.         stdMacModule->InitStandardDispatchModule(ev,session);
  888.  
  889.         for (int i = 0; i < NumStdMacEventTypes; i++)
  890.         {
  891.             somSelf->AddDispatchModule(ev, StdMacEventTypes[i], stdMacModule);
  892.         }
  893.  
  894.         THROW_IF_ERROR(AEInstallEventHandler(kTextServiceClass,
  895.         kOffset2Pos, proc, (long)_fSession, !kIsSysHandler));
  896.  
  897.         THROW_IF_ERROR(AEInstallEventHandler(kTextServiceClass,
  898.         kShowHideInputWindow, proc, (long)_fSession, !kIsSysHandler));
  899.  
  900.         // Background mouse-down support:
  901.         ODInstallBGMouseDownHandler(session);
  902.  
  903.         // Thread support:
  904.         ODInitThreads();
  905. #endif // _PLATFORM_MACINTOSH_
  906.  
  907. #ifdef _PLATFORM_OS2_
  908.         ODStandardDispatchModule* stdOS2Module = new ODStandardDispatchModule();
  909.         THROW_IF_NULL(stdOS2Module);
  910.         stdOS2Module->InitStandardDispatchModule(ev,session);
  911.  
  912.         for (int i = 0; i < NumStdOS2EventTypes; i++)
  913.         {
  914.             somSelf->AddDispatchModule(ev, StdOS2EventTypes[i], stdOS2Module);
  915.         }
  916. #endif // _PLATFORM_OS2_
  917.  
  918. #ifdef _PLATFORM_WIN32_
  919.         ODStdWinDispatchModule* stdWinModule = new ODStdWinDispatchModule();
  920.         THROW_IF_NULL(stdWinModule);
  921.         stdWinModule->InitStdWinDispatchModule(ev, session, somSelf);
  922.  
  923.         for (int i = 0; i < NumStdWinEventTypes; i++)
  924.         {
  925.             somSelf->AddDispatchModule(ev, StdWinEventTypes[i], stdWinModule);
  926.         }
  927. #endif // _PLATFORM_WIN32_
  928.  
  929. #ifdef _PLATFORM_UNIX_
  930.         ODStdX11DispatchModule* stdX11Module = new ODStdX11DispatchModule();
  931.         THROW_IF_NULL(stdX11Module);
  932.         stdX11Module->InitStdX11DispatchModule(ev, session, somSelf);
  933.  
  934.         for (int i = 0; i < NumStdX11EventTypes; i++)
  935.         {
  936.             somSelf->AddDispatchModule(ev, StdX11EventTypes[i], stdX11Module);
  937.         }
  938.  
  939.         // cache a pointer to the Xt display
  940.         WindowSystemData* winSysData = kODNULL;
  941.  
  942.         if (_fSession)
  943.             winSysData = _fSession->GetWindowSystemData(ev);
  944.  
  945.         if (winSysData)
  946.             _fXtDisplay = winSysData->display;
  947.  
  948.         _fXtDispatchMode = kODFalse;
  949.  
  950. #endif // _PLATFORM_UNIX_
  951.  
  952.     }
  953.     catch (ODException _exception)
  954.     {
  955.         ODDeleteObject(_fDispatchTable);
  956.         ODSetSOMException(ev, _exception);
  957.     }
  958. }
  959.  
  960. #ifdef _PLATFORM_MACINTOSH_
  961.  
  962. //------------------------------------------------------------------------------
  963. //      InvalidateMouseRegion (Mac-only)
  964. //------------------------------------------------------------------------------
  965. SOM_Scope void  SOMLINK ODDispatcherInvalidateMouseRegion(ODDispatcher *somSelf, Environment *ev)
  966. {
  967.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  968.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherInvalidateMouseRegion");
  969.  
  970.         SOM_TRY
  971.  
  972.                 ASSERT(_fPartMouseRegion != kODNULL, kODErrDispatcherNotInitialized);
  973.                 SetEmptyRgn(_fPartMouseRegion);
  974.  
  975.         SOM_CATCH_ALL
  976.         SOM_ENDTRY
  977. }
  978.  
  979. //------------------------------------------------------------------------------
  980. //      GetFacetUnderMouse (Mac-only)
  981. //------------------------------------------------------------------------------
  982. SOM_Scope ODFacet*  SOMLINK ODDispatcherGetFacetUnderMouse(ODDispatcher *somSelf, Environment *ev)
  983. {
  984.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  985.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetFacetUnderMouse");
  986.  
  987.         return _fFacetUnderMouse;
  988. }
  989.  
  990. //------------------------------------------------------------------------------
  991. //      SetFacetUnderMouse (Mac-only)
  992. //------------------------------------------------------------------------------
  993. SOM_Scope void  SOMLINK ODDispatcherSetFacetUnderMouse(ODDispatcher *somSelf, Environment *ev,
  994.                 ODFacet* facet)
  995. {
  996.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  997.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherSetFacetUnderMouse");
  998.  
  999.  
  1000.         _fFacetUnderMouse = facet;
  1001.  
  1002. }
  1003.  
  1004. //------------------------------------------------------------------------------
  1005. //      HandleNullEvent (Mac-only)
  1006. //------------------------------------------------------------------------------
  1007. SOM_Scope ODBoolean  SOMLINK ODDispatcherHandleNullEvent(ODDispatcher *somSelf, Environment *ev,
  1008.                 ODEventData* event,
  1009.                 ODFrame* skipFrame)
  1010. {
  1011.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1012.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherHandleNullEvent");
  1013.  
  1014.         ODBoolean handled = kODFalse;
  1015.  
  1016.         SOM_TRY
  1017.  
  1018.                 // Give threads time to run:
  1019.                 ODYield();
  1020.  
  1021.                 IdleListIterator iter(_fIdleList);
  1022.                 ODFrame* frame = kODNULL;
  1023.  
  1024.                 for (IdleInfo* idleInfo = iter.First(); iter.IsNotComplete(); idleInfo = iter.Next())
  1025.                 {
  1026.                         if ( (idleInfo->NeedsIdle(TickCount())))
  1027.                         {
  1028.                                 frame = idleInfo->GetFrame();
  1029.                                 if ( (frame == kODNULL) || !ODObjectsAreEqual(ev, frame,skipFrame) )
  1030.                                 {
  1031.                                         TRY{
  1032.                                                 idleInfo->GetPart()->HandleEvent(ev,event, frame, kODNULL, kODNULL);
  1033.                                         }CATCH_ALL{
  1034.                                                 // ignore exception
  1035.                                         }ENDTRY
  1036.                                         idleInfo->SetLastIdle(TickCount());
  1037.                                 }
  1038.                         }
  1039.                 }
  1040.                 _fIdleList->RemoveUnregisteredIdlers(ev);
  1041.                 handled = kODTrue;
  1042.  
  1043.         SOM_CATCH_ALL
  1044.         SOM_ENDTRY
  1045.  
  1046.         return handled;
  1047. }
  1048.  
  1049. //------------------------------------------------------------------------------
  1050. //      MouseRegionIsInvalid (Mac-only)
  1051. //------------------------------------------------------------------------------
  1052. SOM_Scope ODBoolean  SOMLINK ODDispatcherMouseRegionIsInvalid(ODDispatcher *somSelf, Environment *ev)
  1053. {
  1054.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1055.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherMouseRegionIsInvalid");
  1056.  
  1057.         ODBoolean isInvalid = kODTrue;
  1058.  
  1059.         if (Button())
  1060.                 return kODFalse;
  1061.  
  1062.         SOM_TRY
  1063.  
  1064.                 ASSERT(_fPartMouseRegion != kODNULL, kODErrDispatcherNotInitialized);
  1065.                 isInvalid = EmptyRgn(_fPartMouseRegion);
  1066.  
  1067.         SOM_CATCH_ALL
  1068.         SOM_ENDTRY
  1069.  
  1070.         return isInvalid;
  1071. }
  1072.  
  1073. //------------------------------------------------------------------------------
  1074. //      ComputeMouseRegion (Mac-only)
  1075. //------------------------------------------------------------------------------
  1076. SOM_Scope void  SOMLINK ODDispatcherComputeMouseRegion(ODDispatcher *somSelf, Environment *ev)
  1077. {
  1078.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1079.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherComputeMouseRegion");
  1080.  
  1081.         SOM_TRY
  1082.  
  1083.                 somSelf->CheckFacetUnderMouse(ev); // A Part may call SetMouseRegion
  1084.                 /*
  1085.                         if no frame is under the mouse, compute an appropriate big region
  1086.                         either way, add the current mouse location?
  1087.                         And clip region to frame shape?
  1088.                 */
  1089.  
  1090.                 // Add the current mouse location to whatever region is computed by the part
  1091.                 Point globalMouse;
  1092.                 GetMouse(&globalMouse);
  1093.                 LocalToGlobal(&globalMouse);
  1094.  
  1095.                 SetRectRgn(_fMouseRegion, globalMouse.h, globalMouse.v, globalMouse.h + 1, globalMouse.v + 1);
  1096.                 UnionRgn(_fPartMouseRegion, _fMouseRegion, _fPartMouseRegion);
  1097.  
  1098.         SOM_CATCH_ALL
  1099.         SOM_ENDTRY
  1100. }
  1101.  
  1102. //------------------------------------------------------------------------------
  1103. //      CheckFacetUnderMouse (Mac-only)
  1104. //------------------------------------------------------------------------------
  1105. SOM_Scope void  SOMLINK ODDispatcherCheckFacetUnderMouse(ODDispatcher *somSelf, Environment *ev)
  1106. {
  1107.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1108.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherCheckFacetUnderMouse");
  1109.  
  1110.         SOM_TRY
  1111.  
  1112.                 Point globalPoint;
  1113.                 ODPoint windowPoint;
  1114.  
  1115.                 GetMouse(&globalPoint);
  1116.                 LocalToGlobal(&globalPoint);
  1117.  
  1118.                 if (!SetTSMCursor(globalPoint)) // NP: temporary. dispatcher really needs
  1119.                                                                                 //      to set a 1-pixel mouse region so that
  1120.                                                                                 //      SetTSMCursor can be called every time
  1121.                                                                                 //      the mouse moves.
  1122.                 {
  1123.                         ODWindow* odWindow = kODNULL;
  1124.                         ODFacet* foundFacet = kODNULL;
  1125.  
  1126.                         ODWindowState* _fWindowState = _fSession->GetWindowState(ev); // temp
  1127.  
  1128.                         TempODFrame mouseFocusFrame = kODNULL;
  1129.                         mouseFocusFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSession->Tokenize(ev,kODMouseFocus));
  1130.  
  1131.                         if (mouseFocusFrame)
  1132.                         {
  1133.  
  1134.                                         if (_fFacetUnderMouse && ODObjectsAreEqual(ev, mouseFocusFrame, _fFacetUnderMouse->GetFrame(ev)))
  1135.                                         {
  1136.                                                 odWindow = _fFacetUnderMouse->GetWindow(ev);
  1137.                                                 odWindow->GetWindowPoint(ev, &globalPoint, &windowPoint);
  1138.  
  1139.                                                 ODEventData event;
  1140.                                                 SetEvent(event,kODEvtMouseWithin, globalPoint);
  1141.                                                 ODEventInfo info;
  1142.                                                 SetEventInfo(info, windowPoint);
  1143.                                                 WindowToLocal(ev, info.where, _fFacetUnderMouse);
  1144.  
  1145.                                                 TempODPart part = mouseFocusFrame->AcquirePart(ev);
  1146. #if ODDebug && ODLogEvents
  1147.         LogEvent(&event, &info, mouseFocusFrame, _fFacetUnderMouse);
  1148. #endif
  1149.                                                 part->HandleEvent(ev, &event, mouseFocusFrame, _fFacetUnderMouse, &info);
  1150.                                         }
  1151.                                         return;
  1152.                         }
  1153.  
  1154.                         odWindow = _fWindowState->FindODWindow(ev, &globalPoint);
  1155.  
  1156.                         if (odWindow)
  1157.                         {
  1158.                                 TempODWindow tempWindow = odWindow; // ensure it's released
  1159.                                 odWindow->GetWindowPoint(ev, &globalPoint, &windowPoint);
  1160.                                 TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSession->Tokenize(ev,kODSelectionFocus));
  1161.                                 ODFacet* activeFacet = activeFrame ? GetActiveFacetWithBorderUnderPoint(ev, activeFrame, odWindow, windowPoint) : kODNULL;
  1162.  
  1163.                                 if (activeFacet)
  1164.                                         foundFacet = activeFacet->GetContainingFacet(ev);
  1165.                                 else
  1166.                                 {
  1167.                                         foundFacet = odWindow->GetFacetUnderPoint(ev, &windowPoint);
  1168.                                         if (foundFacet && (foundFacet->GetFrame(ev)->IsFrozen(ev) || foundFacet->IsSelected(ev)))
  1169.                                                 foundFacet = foundFacet->GetContainingFacet(ev);
  1170.                                 }
  1171.                         }
  1172.  
  1173.  
  1174.                         if (ODObjectsAreEqual(ev, foundFacet, _fFacetUnderMouse))
  1175.                         {
  1176.                                 if (foundFacet)
  1177.                                 {
  1178.                                         ODEventData event;
  1179.                                         SetEvent(event,kODEvtMouseWithin, globalPoint);
  1180.                                         ODEventInfo info;
  1181.                                         SetEventInfo(info, windowPoint);
  1182.                                         WindowToLocal(ev, info.where, _fFacetUnderMouse);
  1183.  
  1184.                                         ODFrame* frame = _fFacetUnderMouse->GetFrame(ev);
  1185. #if ODDebug && ODLogEvents
  1186.         LogEvent(&event, &info, frame, _fFacetUnderMouse);
  1187. #endif
  1188.                                         TempODPart part = frame->AcquirePart(ev);
  1189.                                         part->HandleEvent(ev, &event, frame, _fFacetUnderMouse, &info);
  1190.                                 }
  1191.                         }
  1192.                         else
  1193.                         {
  1194.                                 if (_fFacetUnderMouse)
  1195.                                 {
  1196.                                         ODEventData event;
  1197.                                         SetEvent(event,kODEvtMouseLeave, globalPoint);
  1198.                                         ODEventInfo info;
  1199.                                         SetEventInfo(info, windowPoint);
  1200.                                         WindowToLocal(ev, info.where, _fFacetUnderMouse);
  1201.  
  1202.                                         ODFrame* frame = _fFacetUnderMouse->GetFrame(ev);
  1203. #if ODDebug && ODLogEvents
  1204.         LogEvent(&event, &info, frame, _fFacetUnderMouse);
  1205. #endif
  1206.                                         TempODPart part = frame->AcquirePart(ev);
  1207.                                         part->HandleEvent(ev, &event, frame, _fFacetUnderMouse, &info);
  1208.                                 }
  1209.                                 if (foundFacet)
  1210.                                 {
  1211.                                         ODEventData event;
  1212.                                         SetEvent(event,kODEvtMouseEnter, globalPoint);
  1213.                                         ODEventInfo info;
  1214.                                         SetEventInfo(info, windowPoint);
  1215.                                         WindowToLocal(ev, info.where, foundFacet);
  1216.  
  1217.                                         ODFrame* frame = foundFacet->GetFrame(ev);
  1218. #if ODDebug && ODLogEvents
  1219.         LogEvent(&event, &info, frame, foundFacet);
  1220. #endif
  1221.                                         TempODPart part = frame->AcquirePart(ev);
  1222.                                         part->HandleEvent(ev, &event,frame,foundFacet, &info);
  1223.                                 }
  1224.                                 _fFacetUnderMouse = foundFacet;
  1225.                         }
  1226.                 }
  1227.  
  1228.         SOM_CATCH_ALL
  1229.         SOM_ENDTRY
  1230. }
  1231. #endif // _PLATFORM_MACINTOSH_
  1232.  
  1233. //------------------------------------------------------------------------------
  1234. //      somUninit
  1235. //------------------------------------------------------------------------------
  1236. SOM_Scope void  SOMLINK ODDispatchersomUninit(ODDispatcher *somSelf)
  1237. {
  1238.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1239.     ODDispatcherMethodDebug("ODDispatcher","ODDispatchersomUninit");
  1240.  
  1241.     /* free dispatch table (or OS/2 dispatcher lists) */
  1242.  
  1243.     ODDeleteObject(_fDispatchTable);
  1244.  
  1245.     /* free Mac-only instance variables  */
  1246.  
  1247. #ifdef _PLATFORM_MACINTOSH_
  1248.         ODDeleteObject(_fIdleList);
  1249.         ODDisposeHandle((Handle)_fMouseRegion);
  1250.         ODDisposeHandle((Handle)_fPartMouseRegion);
  1251. #endif // _PLATFORM_MACINTOSH_
  1252.  
  1253.         parent_somUninit(somSelf);
  1254. }
  1255.  
  1256. //------------------------------------------------------------------------------
  1257. //      Purge
  1258. //------------------------------------------------------------------------------
  1259. SOM_Scope ODSize  SOMLINK ODDispatcherPurge(ODDispatcher *somSelf, Environment *ev,
  1260.                 ODSize size)
  1261. {
  1262.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1263.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherPurge");
  1264.  
  1265.         return 0;
  1266. }
  1267.  
  1268. //------------------------------------------------------------------------------
  1269. //      AddDispatchModule
  1270. //------------------------------------------------------------------------------
  1271. SOM_Scope void  SOMLINK ODDispatcherAddDispatchModule(ODDispatcher *somSelf, Environment *ev,
  1272.                 ODEventType eventType,
  1273.                 ODDispatchModule* dispatchModule)
  1274. {
  1275.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1276.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherAddDispatchModule");
  1277.  
  1278.     try {
  1279.  
  1280.         ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
  1281.  
  1282.         if (!dispatchModule)
  1283.             THROW(kODErrIllegalNullDispatchModuleInput);
  1284.  
  1285.         _fDispatchTable->AddDispatchModule(eventType,dispatchModule);
  1286.  
  1287.     }
  1288.     catch (ODException _exception) {
  1289.         ODSetSOMException(ev, _exception);
  1290.     }
  1291. }
  1292.  
  1293. //------------------------------------------------------------------------------
  1294. //      GetDispatchModule
  1295. //------------------------------------------------------------------------------
  1296. SOM_Scope ODDispatchModule*  SOMLINK ODDispatcherGetDispatchModule(ODDispatcher *somSelf, Environment *ev,
  1297.                 ODEventType eventType)
  1298. {
  1299.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1300.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetDispatchModule");
  1301.  
  1302.     ODDispatchModule* m = kODNULL;
  1303.  
  1304.     try {
  1305.  
  1306.         ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
  1307.  
  1308.         m = _fDispatchTable->GetDispatchModule( eventType );
  1309.  
  1310.     }
  1311.     catch (ODException _exception) {
  1312.         ODSetSOMException(ev, _exception);
  1313.     }
  1314.  
  1315.     return m;
  1316. }
  1317.  
  1318. //------------------------------------------------------------------------------
  1319. //      RemoveDispatchModule
  1320. //------------------------------------------------------------------------------
  1321. SOM_Scope void  SOMLINK ODDispatcherRemoveDispatchModule(ODDispatcher *somSelf, Environment *ev,
  1322.                 ODEventType eventType)
  1323. {
  1324.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1325.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherRemoveDispatchModule");
  1326.  
  1327.     try {
  1328.  
  1329.         ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
  1330.  
  1331.         _fDispatchTable->RemoveDispatchModule(eventType);
  1332.  
  1333.     }
  1334.     catch (ODException _exception) {
  1335.         ODSetSOMException(ev, _exception);
  1336.     }
  1337. }
  1338.  
  1339. //------------------------------------------------------------------------------
  1340. //      AddMonitor
  1341. //------------------------------------------------------------------------------
  1342. SOM_Scope void  SOMLINK ODDispatcherAddMonitor(ODDispatcher *somSelf, Environment *ev,
  1343.                 ODEventType eventType,
  1344.                 ODDispatchModule* dispatchModule)
  1345. {
  1346.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1347.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherAddMonitor");
  1348.  
  1349.     try {
  1350.  
  1351.         ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
  1352.  
  1353.         if (!dispatchModule)
  1354.             THROW(kODErrIllegalNullDispatchModuleInput);
  1355.  
  1356.         _fDispatchTable->AddMonitor(eventType,dispatchModule);
  1357.  
  1358.     }
  1359.     catch (ODException _exception) {
  1360.         ODSetSOMException(ev, _exception);
  1361.     }
  1362. }
  1363.  
  1364. //------------------------------------------------------------------------------
  1365. //      RemoveMonitor
  1366. //------------------------------------------------------------------------------
  1367. SOM_Scope void  SOMLINK ODDispatcherRemoveMonitor(ODDispatcher *somSelf, Environment *ev,
  1368.                 ODEventType eventType,
  1369.                 ODDispatchModule* dispatchModule)
  1370. {
  1371.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1372.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherRemoveMonitor");
  1373.  
  1374.     try {
  1375.  
  1376.         ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
  1377.  
  1378.         _fDispatchTable->RemoveMonitor(eventType, dispatchModule);
  1379.  
  1380.     }
  1381.     catch (ODException _exception) {
  1382.         ODSetSOMException(ev, _exception);
  1383.     }
  1384. }
  1385.  
  1386.  
  1387. #ifdef _PLATFORM_MACINTOSH_
  1388. //------------------------------------------------------------------------------
  1389. //      IntlTSMEvent (Mac-only) (non-SOM)
  1390. //------------------------------------------------------------------------------
  1391. static Boolean IntlTSMEvent(EventRecord *event) // NP: from TE 27.
  1392. {
  1393.         short oldFont;
  1394.         ScriptCode keyboardScript;
  1395.  
  1396.         // make sure we have a port and it's not the Window Manager port
  1397.         if (ODQDGlobals.thePort != nil && FrontWindow() != nil)
  1398.         {
  1399.                 oldFont = ODQDGlobals.thePort->txFont;
  1400.                 keyboardScript = GetScriptManagerVariable(smKeyScript);
  1401.                 if (FontToScript(oldFont) != keyboardScript)
  1402.                         TextFont(GetScriptVariable(keyboardScript, smScriptAppFond));
  1403.         };
  1404.         return TSMEvent(event);
  1405. }
  1406. #endif // _PLATFORM_MACINTOSH_
  1407.  
  1408. //------------------------------------------------------------------------------
  1409. //      Dispatch
  1410. //------------------------------------------------------------------------------
  1411. SOM_Scope ODBoolean  SOMLINK ODDispatcherDispatch(ODDispatcher *somSelf, Environment *ev,
  1412.                 ODEventData* eventData)
  1413. {
  1414.         ODBoolean handled = kODFalse;
  1415.  
  1416.         try {
  1417.  
  1418.                 ODEventInfo eventInfo;  // Note: Need some utility functions
  1419.                 eventInfo.embeddedFrame = kODNULL;
  1420.                 eventInfo.embeddedFacet = kODNULL;
  1421.                 eventInfo.where.x = 0;
  1422.                 eventInfo.where.y = 0;
  1423.  
  1424.         #ifdef _PLATFORM_OS2_
  1425.                 eventInfo.flags = 0;
  1426.         #else
  1427.                 eventInfo.propagated = kODFalse;
  1428.         #endif
  1429.  
  1430.         #ifdef _PLATFORM_OS2_
  1431.                 eventInfo.originalType = eventData->msg;
  1432.         #endif
  1433.         #ifdef _PLATFORM_WIN32_
  1434.                 eventInfo.originalType = eventData->message;
  1435.         #endif
  1436.         #ifdef _PLATFORM_UNIX_
  1437.                 eventInfo.originalType = eventData->type;
  1438.         #endif
  1439.  
  1440.         #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_) || defined(_PLATFORM_UNIX_)
  1441.                 // Save away the original type in a local variable so we can restore it
  1442.                 // after the Redispatch call
  1443.                 ODEventType originalType = eventInfo.originalType;
  1444.         #endif
  1445.  
  1446.                 handled =somSelf->Redispatch(ev, eventData, &eventInfo);
  1447.  
  1448.         #ifdef _PLATFORM_OS2_
  1449.                 // Restore the original type
  1450.                 eventData->msg = originalType;
  1451.         #endif
  1452.         #ifdef _PLATFORM_WIN32_
  1453.                 eventData->message = originalType;
  1454.         #endif
  1455.         #ifdef _PLATFORM_UNIX_
  1456.                 eventData->type = originalType;
  1457.         #endif
  1458.  
  1459.         }
  1460.         catch (ODException _exception) {
  1461.             ODSetSOMException(ev, _exception);
  1462.         }
  1463.  
  1464.         return handled;
  1465. }
  1466.  
  1467. //------------------------------------------------------------------------------
  1468. //      Redispatch
  1469. //------------------------------------------------------------------------------
  1470. SOM_Scope ODBoolean  SOMLINK ODDispatcherRedispatch(ODDispatcher *somSelf, Environment *ev,
  1471.                 ODEventData* eventData,
  1472.                 ODEventInfo* eventInfo)
  1473. {
  1474.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1475.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherDispatch");
  1476.  
  1477.     ODBoolean handled = kODFalse;
  1478.     ODEventType eventType;
  1479.  
  1480. #ifdef _PLATFORM_MACINTOSH_
  1481.     eventType = eventData->what;
  1482. #endif
  1483.  
  1484. #ifdef _PLATFORM_OS2_
  1485.     eventType = eventData->msg;
  1486. #endif
  1487.  
  1488. #ifdef _PLATFORM_WIN32_
  1489.     eventType = eventData->message;
  1490. #endif
  1491.  
  1492. #if defined(_PLATFORM_UNIX_)
  1493.     eventType = eventData->type;
  1494. #endif
  1495.  
  1496.     try {
  1497.  
  1498.         ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
  1499.  
  1500.         ODBoolean isMacNullEvent = kODFalse;
  1501.  
  1502.         #ifdef _PLATFORM_MACINTOSH_
  1503.         isMacNullEvent = (eventType == nullEvent);
  1504.         #endif // _PLATFORM_MACINTOSH_
  1505.  
  1506.         if (isMacNullEvent)
  1507.         {
  1508.         #ifdef _PLATFORM_MACINTOSH_
  1509.             somSelf->HandleNullEvent(ev,eventData, kODNULL);
  1510.         #endif // _PLATFORM_MACINTOSH_
  1511.             handled = kODTrue;
  1512.         }
  1513.         else
  1514.         {
  1515.             OrderedCollection* monitors = kODNULL;
  1516.             ODDispatchModule* module = kODNULL;
  1517.  
  1518.             monitors = _fDispatchTable->GetMonitors(eventType);
  1519.             if (monitors)
  1520.             {
  1521.                 OrderedCollectionIterator iter(monitors);
  1522.  
  1523.                 for (module = (ODDispatchModule*) iter.First();
  1524.                         iter.IsNotComplete();
  1525.                         module = (ODDispatchModule*) iter.Next())
  1526.                 {
  1527.                     module->Dispatch(ev, eventData, eventInfo);
  1528.                 }
  1529.             }
  1530.  
  1531.             ODBoolean isMacTSMevent = kODFalse; // we hope
  1532.  
  1533.         #ifdef _PLATFORM_MACINTOSH_
  1534.             isMacTSMevent = (IntlTSMEvent((EventRecord*)eventData));
  1535.         #endif // _PLATFORM_MACINTOSH_
  1536.  
  1537.             if (! isMacTSMevent)
  1538.             {
  1539.  
  1540.             #ifdef _PLATFORM_UNIX_
  1541.                 // offer modal X11 mouse/kb events (for menus, popup dialogs, etc.)
  1542.         // to the Xt event dispatcher first
  1543.         // ----------------------------------------------------------------
  1544.         if ((_fXtDispatchMode)    &&
  1545.             (eventData)        &&
  1546.             (eventData->display == _fXtDisplay))
  1547.         {
  1548.             switch (eventData->type)
  1549.             {
  1550.             case MotionNotify:
  1551.             case ButtonPress:
  1552.             case ButtonRelease:
  1553.             case KeyPress:
  1554.             case KeyRelease:
  1555.                     XtDispatchEvent((XEvent*)eventData);
  1556.                     handled = kODTrue;
  1557.                     break;
  1558.  
  1559.             // to do: what about synthetic border/embedded mouse events?
  1560.  
  1561.             default:    break;
  1562.             }
  1563.         }
  1564.             #endif // _PLATFORM_UNIX_
  1565.  
  1566.                 // offer events to the appropriate dispatch module
  1567.         // ------------------------------------------------
  1568.                 if (!handled)
  1569.             module = _fDispatchTable->GetDispatchModule(eventType);
  1570.  
  1571.                 if (module)
  1572.                     handled = module->Dispatch(ev, eventData, eventInfo);
  1573.  
  1574.             #ifdef _PLATFORM_UNIX_
  1575.                 // offer leftover X11 events to the Xt dispatcher
  1576.         // ----------------------------------------------
  1577.  
  1578.                 if ((!handled)         &&
  1579.             (eventData)         &&
  1580.                     (eventData->display == _fXtDisplay))
  1581.                 {
  1582.                     XtDispatchEvent((XEvent *)eventData);
  1583.                     handled = kODTrue;
  1584.                 }
  1585.             #endif // _PLATFORM_UNIX_
  1586.  
  1587.             }
  1588.         }
  1589.  
  1590.         // Moved to the end so that dispatch modules can monitor or patch
  1591.         // null event handling
  1592.         if ((isMacNullEvent) && (!handled))
  1593.         {
  1594.         #ifdef _PLATFORM_MACINTOSH_
  1595.             somSelf->HandleNullEvent(ev,eventData, kODNULL);
  1596.         #endif // _PLATFORM_MACINTOSH_
  1597.             handled = kODTrue;
  1598.         }
  1599.  
  1600.     }
  1601.     catch (ODException _exception) {
  1602.         ODSetSOMException(ev, _exception);
  1603.     }
  1604.  
  1605.     return handled;
  1606. }
  1607.  
  1608. //------------------------------------------------------------------------------
  1609. //      Exit
  1610. //------------------------------------------------------------------------------
  1611. SOM_Scope void  SOMLINK ODDispatcherExit(ODDispatcher *somSelf, Environment *ev)
  1612. {
  1613.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1614.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherExit");
  1615.  
  1616.         _fExit = kODTrue;
  1617. }
  1618.  
  1619. //------------------------------------------------------------------------------
  1620. //      ShouldExit
  1621. //------------------------------------------------------------------------------
  1622. SOM_Scope ODBoolean  SOMLINK ODDispatcherShouldExit(ODDispatcher *somSelf, Environment *ev)
  1623. {
  1624.     ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
  1625.     ODDispatcherMethodDebug("ODDispatcher","ODDispatcherShouldExit");
  1626.  
  1627.         return _fExit;
  1628. }
  1629.