home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CALib / Implementation / UI / CAArbitr.cpp next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  7.1 KB  |  280 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CAArbitr.cpp
  3.  
  4.     Contains:    Container Application Library source - Arbitration
  5.  
  6.     Written by:    Steve Foley, Greg Ames, David Nelson
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <15>     11/21/95    RB        Made all acquire operation use temp objects
  13.          <14>     5/19/95    SJF        Fix RequestModalFocus
  14.          <8>     5/15/95    RB        Adding CA_CATCH
  15.          <7>     5/12/95    RB        Implementing CARequestStandardFocus() and
  16.                                      CARelinquishStandardFocus()
  17.          <6>     4/23/95    RB        Implementing CAInstallFocusNotification
  18.          <5>     4/23/95    RB        Added GetFocusOwner() routine.
  19.          <4>     4/23/95    RB        Implemented Modal focus routines
  20.          <3+>     2/28/95    SJF        Add debug stuff to API functions.
  21.          <3>     2/13/95    SJF        Interim checkin to update project database
  22.          <3)    12/15/94    SJF        change somGetGlobalEnvironment to _gpProxyShell->GetGlobalEnvironment
  23.          <2>    10/30/94    GCA,DHN    All mods to make project compile with no
  24.                                      errors under OpenDoc b1 (with SOM).
  25.          <1>    10/16/94    SJF        first written
  26.          
  27.     To Do:
  28.         implement
  29. */
  30.  
  31.  
  32. #ifndef _CASESSN_
  33. #include "CASessn.h"
  34. #endif
  35.  
  36. #ifndef _CADEBUG_
  37. #include "CADebug.h"
  38. #endif
  39.  
  40. #ifndef _CAERROR_
  41. #include "CAError.h"
  42. #endif
  43.  
  44. #ifndef _CADOCPRIV_
  45. #include "CADocPriv.h"
  46. #endif
  47.  
  48. #ifndef _CAFRMUTL_
  49. #include "CAFrmUtl.h"
  50. #endif
  51.  
  52. #ifndef _ODUTILS_
  53. #include <ODUtils.h>
  54. #endif
  55.  
  56. #ifndef SOM_ODWindowState_xh
  57. #include <WinStat.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODPart_xh
  61. #include <Part.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODFoci_xh
  65. #include <Foci.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODFocusSet_xh
  69. #include <FocusSet.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODWindow_xh
  73. #include <Window.xh>
  74. #endif
  75.  
  76. #ifndef _CAPROXYPARTDEF_
  77. #include "CAProxyPartDef.h"
  78. #endif
  79.  
  80. #ifndef CAProxyExtension_API
  81. #include "CAProxyExtension.xh"
  82. #endif
  83.  
  84. #ifndef _TEMPOBJ_
  85. #include <TempObj.h>
  86. #endif
  87.  
  88. #pragma segment CALib
  89.  
  90.  
  91. //-------------------------------------------------------------------------
  92. // Arbitration ***
  93. //-------------------------------------------------------------------------
  94.  
  95. pascal    Boolean        CARequestStandardFocusSet( WindowPtr window )
  96. {
  97.  
  98.     Environment*        ev            = gCASession->GetEV();
  99.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  100.     Boolean                result        = false;
  101.     ODFrame*            rootFrame;
  102.     ODFocusSet*         focusSet;
  103.     
  104.     CA_TRY
  105.     
  106.         if (!window) THROW (kCAErrInvalidParameter);
  107.  
  108.         // Get the OD window
  109.         TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
  110.         THROW_IF_NULL (tempWindow);
  111.         
  112.         focusSet = gCASession->GetArbitrator()->CreateFocusSet(ev);
  113.         THROW_IF_NULL (focusSet);
  114.         
  115.         focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODKeyFocus));
  116.         focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODMenuFocus));
  117.         focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus));
  118.  
  119.         // Need some error checking
  120.         
  121.         rootFrame = tempWindow->GetRootFrame(ev);
  122.         
  123.         TempODPart tempPart = rootFrame->AcquirePart(ev);
  124.         THROW_IF_NULL (tempPart);
  125.                             
  126.         result = gCASession->GetArbitrator()->RequestFocusSet(ev, focusSet, rootFrame);
  127.                     
  128.         if (result)
  129.         {
  130.             tempPart->FocusAcquired(ev, gCASession->GetODSession()->Tokenize(ev, kODKeyFocus), rootFrame);
  131.             tempPart->FocusAcquired(ev, gCASession->GetODSession()->Tokenize(ev, kODMenuFocus), rootFrame);
  132.             tempPart->FocusAcquired(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus), rootFrame);
  133.         }
  134.         
  135.  
  136.     CA_CATCH_ALL
  137.     CA_ENDTRY
  138.     
  139.     ODDeleteObject (focusSet);
  140.  
  141.     return    result;
  142. }
  143.  
  144.  
  145. //-------------------------------------------------------------------------
  146. pascal    Boolean        CARequestModalFocus( WindowPtr window )
  147. {
  148.  
  149.     // If the window is nil (no front doc window) return TRUE
  150.     
  151.     Environment*        ev            = gCASession->GetEV();
  152.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  153.     ODArbitrator*        arbitrator    = gCASession->GetArbitrator();;
  154.     Boolean                result        = true;
  155.     ODFrame*            rootFrame;
  156.  
  157.     if (!window) return (true);
  158.     if (!windowState->IsODWindow(ev, window)) return (true);;
  159.  
  160.     CA_TRY
  161.     
  162.         TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
  163.         THROW_IF_NULL (tempWindow);
  164.         
  165.         rootFrame = tempWindow->GetRootFrame(ev);
  166.                                 
  167.         result = arbitrator->RequestFocus(ev,
  168.                 gCASession->GetODSession()->Tokenize(ev, kODModalFocus), rootFrame);
  169.  
  170.     CA_CATCH_ALL
  171.     CA_ENDTRY    
  172.     
  173.     return    result;
  174. }
  175.  
  176.  
  177. //-------------------------------------------------------------------------
  178. pascal    void        CARelinquishStandardFocusSet( WindowPtr window )
  179. {
  180.  
  181.     Environment*        ev            = gCASession->GetEV();
  182.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  183.     Boolean                result        = false;
  184.     ODFrame*            rootFrame;
  185.     ODFocusSet*         focusSet;
  186.  
  187.     CA_TRY
  188.     
  189.         if (!window) THROW (kCAErrInvalidParameter);
  190.  
  191.         TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
  192.         THROW_IF_NULL (tempWindow);
  193.  
  194.         focusSet = gCASession->GetArbitrator()->CreateFocusSet(ev);
  195.         focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODKeyFocus));
  196.         focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODMenuFocus));
  197.         focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus));
  198.  
  199.         // Need some error checking
  200.         
  201.         rootFrame = tempWindow->GetRootFrame(ev);
  202.                                 
  203.         gCASession->GetArbitrator()->RelinquishFocusSet(ev, focusSet, rootFrame);
  204.  
  205.     CA_CATCH_ALL
  206.     CA_ENDTRY
  207.     
  208.     ODDeleteObject (focusSet);
  209.         
  210.  
  211. }
  212.  
  213.  
  214. //-------------------------------------------------------------------------
  215. pascal    void        CARelinquishModalFocus( WindowPtr window )
  216. {
  217.     Environment*        ev            = gCASession->GetEV();
  218.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  219.     ODArbitrator*        arbitrator    = gCASession->GetArbitrator();;
  220.     Boolean                result        = false;
  221.     ODFrame*            rootFrame;
  222.  
  223.     if (!window) return;
  224.     if (!windowState->IsODWindow(ev, window)) return;
  225.     
  226.     CA_TRY
  227.     
  228.         TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
  229.         THROW_IF_NULL (tempWindow);
  230.         
  231.         rootFrame = tempWindow->GetRootFrame(ev);
  232.                                 
  233.         arbitrator->RelinquishFocus(ev,
  234.                     gCASession->GetODSession()->Tokenize(ev, kODModalFocus), rootFrame);
  235.                     
  236.     CA_CATCH_ALL
  237.     CA_ENDTRY
  238.     
  239. }
  240.  
  241.  
  242.  
  243. //-------------------------------------------------------------------------
  244.  
  245. pascal    void        CAInstallFocusNotification( CAFocusAcquiredProc    focusAquiredProc,
  246.                                                 CAFocusLostProc      focusLostProc,
  247.                                                 CADocumentRef        document )
  248. {
  249.     Environment*        ev = gCASession->GetEV();
  250.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  251.     CAProxyExtension*    proxyExt = kODNULL;
  252.  
  253.     CA_TRY
  254.     
  255.         TempODPart tempPart = ((CADocument*)document)->AcquireRootPart();
  256.         proxyExt = (CAProxyExtension*)tempPart->AcquireExtension( ev, kCAProxyPartExtension );
  257.         THROW_IF_NULL (proxyExt);        // kODErrUnsupportedExtension
  258.  
  259.         CAFocusAcquiredProcUPP focusAquiredUPPHandler;
  260.         CAFocusLostProcUPP focusLostUPPHandler;
  261.         
  262.         focusAquiredUPPHandler = (CAFocusAcquiredProcUPP) NewRoutineDescriptor((ProcPtr)focusAquiredProc, 
  263.                                                 uppCAFocusAcquiredProcInfo, 
  264.                                                 GetCurrentISA());
  265.  
  266.         focusLostUPPHandler = (CAFocusLostProcUPP) NewRoutineDescriptor((ProcPtr)focusLostProc, 
  267.                                                 uppCAFocusLostProcInfo, 
  268.                                                 GetCurrentISA());
  269.  
  270.         proxyExt->InstallCAFocusHandlers( ev, focusAquiredUPPHandler, focusLostUPPHandler, document);
  271.  
  272.     CA_CATCH_ALL
  273.     CA_ENDTRY
  274.     
  275.     ODRelease (ev, proxyExt);
  276.     
  277.  
  278. }
  279.  
  280.