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 / CAWindow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  9.7 KB  |  435 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CAWindow.cpp
  3.  
  4.     Contains:    Window management code for CALib
  5.  
  6.     Written by:    Jens Alfke, Rick Badertscher
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <21>     5/19/95    SJF        Clean up CAGetFront...Window calls
  13.         <16>     5/15/95    RB        Adding CA_CATCH
  14.         <15>      5/6/95    SJF        WWDC bug fix session with Rick
  15.         <11>      5/5/95    SJF        Remove include of PartWrap.xh
  16.          <10>     4/22/95    RB        Enabling & Fixing CARegisterFloatingWindow()
  17.          <8>     4/19/95    RB        Fixing CAInstallWindowActivateHandler to call the
  18.                                      Proxy Extension
  19.          <7>     4/07/95    RB        Small mods to CARegisterRootWindow()
  20.          <6>     4/01/95    RB        Added support for CAWindowActivateProc callback.
  21.          <5>     3/31/95    RB        Fixed bug in CARegisterRootWindow()
  22.                                      Added support for multiple document partitions
  23.          <4+>     2/28/95    SJF        Add debug stuff to API calls
  24.          <4>     2/20/95    SJF        Merge in changes from RickB
  25.          <3>     2/13/95    SJF        Interim checkin to update project database
  26.          <2)    12/15/94    SJF        change somGetGlobalEnvironment to _gpProxyShell->GetGlobalEnvironment
  27.          <1>    10/30/94    GCA,DHN    All mods to make project compile with no
  28.                                      errors under OpenDoc b1 (with SOM).
  29.          <0>    10/30/94    SV        SOMverted
  30.          
  31.     To Do:
  32. */
  33.  
  34. #ifndef _CASESSN_
  35. #include "CASessn.h"
  36. #endif
  37.  
  38. #ifndef _CAERROR_
  39. #include "CAError.h"
  40. #endif
  41.  
  42. #ifndef _CADEBUG_
  43. #include "CADebug.h"
  44. #endif
  45.  
  46. #ifndef _CADOCPRIV_
  47. #include "CADocPriv.h"
  48. #endif
  49.  
  50. #ifndef SOM_ODWindow_xh
  51. #include <Window.xh>
  52. #endif
  53.  
  54. #ifndef SOM_ODWindowIterator_xh
  55. #include <WinIter.xh>
  56. #endif
  57.  
  58. #ifndef SOM_ODSession_xh
  59. #include <ODSessn.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODWindowState_xh
  63. #include <WinStat.xh>
  64. #endif
  65.  
  66. #ifndef _ODUTILS_
  67. #include <ODUtils.h>
  68. #endif
  69.  
  70. #ifndef _STORUTIL_
  71. #include <StorUtil.h>
  72. #endif
  73.  
  74. #ifndef _StdTypIO_
  75. #include <StdTypIO.h>
  76. #endif
  77.  
  78. #ifndef _CAPROXYPARTDEF_
  79. #include "CAProxyPartDef.h"
  80. #endif
  81.  
  82. #ifndef CAProxyExtension_API
  83. #include "CAProxyExtension.xh"
  84. #endif
  85.  
  86. #ifndef _TEMPOBJ_
  87. #include <TempObj.h>
  88. #endif
  89.  
  90.  
  91. #pragma segment CALib
  92.  
  93.  
  94. //-------------------------------------------------------------------------
  95. //    Static variables 
  96. //-------------------------------------------------------------------------
  97.  
  98.  
  99. static CAWindowActivateHandler    gWindowActivateHandler        = NULL;
  100.  
  101.  
  102. //-------------------------------------------------------------------------
  103. //    Window Management
  104. //-------------------------------------------------------------------------
  105.  
  106.  
  107. pascal Boolean
  108. CAIsPartWindow( WindowPtr window )
  109. {
  110.     Environment*        ev                = gCASession->GetEV();
  111.     ODWindowState*        windowState        = gCASession->GetODSession()->GetWindowState(ev);
  112.     Boolean                retval            = false;
  113.     
  114.     if (window == NULL)
  115.         return false;                    // Not a window!
  116.     else if (((WindowPeek)window)->windowKind < userKind)
  117.         return false;                    // DA or dialog window!
  118.     else
  119.     {
  120.  
  121.         CA_TRY
  122.  
  123.             TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
  124.             
  125.             if (tempWindow && !tempWindow->IsFloating(ev) && !tempWindow->IsRootWindow(ev) )
  126.                 retval = true;
  127.             
  128.         CA_CATCH_ALL
  129.         CA_ENDTRY
  130.         
  131.     }
  132.     
  133.     return (retval);
  134. }
  135.  
  136.  
  137. //-------------------------------------------------------------------------
  138.  
  139. pascal WindowPtr
  140. CAGetFrontDocWindow( void )
  141. {
  142.  
  143.     Environment*        ev            = gCASession->GetEV();
  144.     WindowPtr            macWindow    = kODNULL;
  145.     
  146.     CA_TRY
  147.     
  148.         TempODWindow tempWindow = gCASession->GetODSession()->GetWindowState(ev)->AcquireActiveWindow(ev);
  149.         
  150.         if (tempWindow)
  151.             macWindow =  tempWindow->GetPlatformWindow(ev);
  152.         
  153.     CA_CATCH_ALL
  154.     CA_ENDTRY
  155.     
  156.     return macWindow;
  157.     
  158. }
  159.  
  160.  
  161. //-------------------------------------------------------------------------
  162.  
  163. pascal WindowPtr
  164. CAGetFrontFloatingWindow( void )
  165. {
  166.     Environment*        ev            = gCASession->GetEV();
  167.     WindowPtr            macWindow    = kODNULL;
  168.     
  169.     CA_TRY
  170.     
  171.         TempODWindow tempWindow = gCASession->GetODSession()->GetWindowState(ev)->AcquireFrontFloatingWindow(ev);
  172.         
  173.         if (tempWindow)
  174.             macWindow =  tempWindow->GetPlatformWindow(ev);
  175.         
  176.     CA_CATCH_ALL
  177.     CA_ENDTRY
  178.     
  179.     return macWindow;
  180.         
  181. }
  182.  
  183.  
  184. //-------------------------------------------------------------------------
  185.  
  186. pascal void
  187. CASelectWindow( WindowPtr window )
  188. {
  189.     Environment*    ev = gCASession->GetEV();
  190.     
  191.     if (!window) return;
  192.  
  193.     CA_TRY
  194.     
  195.         TempODWindow tempWindow = gCASession->GetODSession()->GetWindowState(ev)->AcquireODWindow(ev, window);
  196.         
  197.         if (tempWindow)
  198.             tempWindow->Select(ev);
  199.         else
  200.             SelectWindow(window);
  201.     
  202.     CA_CATCH_ALL
  203.     CA_ENDTRY
  204.     
  205. }
  206.  
  207. #pragma segment Main
  208. pascal void  CARegisterRootWindow(    WindowPtr        rootWindow,
  209.                                     CADocumentRef    document)
  210. {
  211.     Environment*        ev                = gCASession->GetEV();
  212.     ODWindowState*        windowState     = gCASession->GetODSession()->GetWindowState(ev);
  213.     ODStorageUnit*        rootPartSU        = kODNULL;
  214.     ODWindow*            anODWindow        = kODNULL;
  215.     CADocument*            docRef            = kODNULL;
  216.     
  217.  
  218.     docRef = (CADocument*) document;
  219.  
  220.     TempODFrame tempFrame = docRef->AcquireDisplayFrame();
  221.     
  222.     if (tempFrame)
  223.     {
  224.     
  225.         CA_TRY
  226.         
  227.             anODWindow = windowState->RegisterWindowForFrame (ev, (ODPlatformWindow) rootWindow,
  228.                     tempFrame, kODTrue, kODTrue, kODFalse, kODTrue, kODFalse, kODNULL);
  229.             
  230.             THROW_IF_NULL (anODWindow);
  231.  
  232.         CA_CATCH_ALL
  233.         CA_ENDTRY
  234.         
  235.         TRACE (3, "CARegisterRootWindow - draft contained display frame %x", anODWindow->GetRootFrame(ev));
  236.         
  237.  
  238.     }
  239.     else
  240.     {
  241.     
  242.         CA_TRY
  243.             
  244.             TempODPart tempPart = docRef->AcquireRootPart();
  245.     
  246.             anODWindow = windowState->RegisterWindow (ev, (ODPlatformWindow) rootWindow,
  247.                     kODFrameObject, kODTrue, kODTrue, kODFalse, kODFalse, kODFalse, tempPart, 
  248.                     gCASession->GetODSession()->Tokenize(ev, kODViewAsFrame),
  249.                     gCASession->GetODSession()->Tokenize(ev, kODPresDefault),
  250.                     (ODFrame*) kODNULL);
  251.             
  252.             THROW_IF_NULL (anODWindow);
  253.     
  254.             TRACE (3, "CARegisterRootWindow - root frame created, %x", anODWindow->GetRootFrame(ev));
  255.  
  256.         CA_CATCH_ALL
  257.         CA_ENDTRY
  258.  
  259.     }
  260.     
  261.     TRACE (3, "CARegisterRootWindow - window, %x", anODWindow);
  262.  
  263.     docRef->SetWindow(anODWindow);
  264.  
  265.     anODWindow->Open(ev);
  266.     anODWindow->Show(ev);
  267.     anODWindow->Select(ev);
  268.     anODWindow->Release(ev);
  269.  
  270. }
  271.  
  272. pascal void  CARegisterFloatingWindow(WindowPtr floatingWindow)
  273. {
  274.  
  275.     Environment*        ev            = gCASession->GetEV();
  276.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  277.     ODPart*                floatingWindowHandlerPart;
  278.     ODWindow*            anODWindow;
  279.         
  280.     CA_TRY
  281.     
  282.         floatingWindowHandlerPart = gCASession->GetFloatingWindowHandlerPart ();
  283.     
  284.         anODWindow = windowState->RegisterWindow (ev, (ODPlatformWindow) floatingWindow,
  285.                     kODFrameObject, kODFalse, kODFalse, kODTrue, kODFalse, kODFalse, floatingWindowHandlerPart, 
  286.                     gCASession->GetODSession()->Tokenize(ev, kODViewAsFrame),
  287.                     gCASession->GetODSession()->Tokenize(ev, kODPresDefault),
  288.                     (ODFrame*) kODNULL);
  289.  
  290.         THROW_IF_NULL (anODWindow);
  291.  
  292.     CA_CATCH_ALL
  293.     CA_ENDTRY
  294.     
  295.     if (anODWindow)
  296.     {
  297.         anODWindow->Open(ev);
  298.         anODWindow->Show(ev);
  299.         anODWindow->Select(ev);
  300.         anODWindow->Release(ev);
  301.  
  302.     }
  303.     
  304. }
  305.  
  306.  
  307.  
  308. pascal void  CAUnregisterWindow( WindowPtr window ) 
  309. {
  310.     Environment*        ev            = gCASession->GetEV();
  311.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  312.     ODWindow*            anODWindow    = kODNULL;
  313.     CADocument*            docRef;
  314.     
  315.     CA_TRY
  316.     
  317.         anODWindow = windowState->AcquireODWindow (ev, window);
  318.         THROW_IF_NULL (anODWindow);
  319.         
  320.         // Hide the window so the OD window state doesn't muck with stuff
  321.         HideWindow (window);
  322.         
  323.         if (anODWindow->IsFloating(ev))
  324.             anODWindow->CloseAndRemove (ev);
  325.         else
  326.         {
  327.             // FIrst have the root frame acquire focus
  328.             CARequestStandardFocusSet (window);
  329.             
  330.             docRef = gCASession->FindCADocumentRefForWindow (anODWindow);
  331.             
  332.             if (docRef)
  333.             {
  334.             
  335.                 ODWindowIterator* iter = windowState->CreateWindowIterator(ev);
  336.         
  337.                 for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev); window = iter->Next(ev))
  338.                 {
  339.                     if (( window != anODWindow) && 
  340.                         (ODObjectsAreEqual(ev,
  341.                             window->GetRootFrame(ev)->GetStorageUnit(ev)->GetDraft(ev),
  342.                             docRef->GetDraft() )))
  343.                     {
  344.                         window->Acquire(ev); // Close Releases
  345.                         window->Close(ev);
  346.                     }
  347.                 }
  348.                 ODDeleteObject(iter);
  349.                 
  350.                 anODWindow->CloseAndRemove (ev);
  351.             }
  352.             else
  353.                 anODWindow->CloseAndRemove (ev);
  354.             
  355.         }
  356.         
  357.         windowState->ActivateFrontWindows(ev);
  358.         
  359.     CA_CATCH_ALL
  360.     CA_ENDTRY
  361.     
  362.  
  363. }
  364.  
  365.  
  366. //-------------------------------------------------------------------------
  367.  
  368. pascal OSErr CAInstallFloatingWindowHandlers (    CASelectWindowHandler    handler1,
  369.                                                 CAFrontWindowHandler    handler2,
  370.                                                 CAIsFloaterHandler        handler3)
  371. {
  372.     Environment*        ev            = gCASession->GetEV();
  373.     OSErr                result        = noErr;
  374.  
  375.     CASelectWindowHandlerUPP    handler1UPP;
  376.     CAFrontWindowHandlerUPP        handler2UPP;
  377.     CAIsFloaterHandlerUPP        handler3UPP;
  378.     
  379.     CA_TRY
  380.     
  381.         handler1UPP = (CASelectWindowHandlerUPP) NewRoutineDescriptor((ProcPtr)handler1, 
  382.                                                 uppCASelectWindowHandlerInfo, 
  383.                                                 GetCurrentISA());
  384.  
  385.         handler2UPP = (CAFrontWindowHandlerUPP) NewRoutineDescriptor((ProcPtr)handler2, 
  386.                                                 uppCAFrontWindowHandlerInfo, 
  387.                                                 GetCurrentISA());
  388.  
  389.         handler3UPP = (CAIsFloaterHandlerUPP) NewRoutineDescriptor((ProcPtr)handler3, 
  390.                                                 uppCAIsFloaterHandlerInfo, 
  391.                                                 GetCurrentISA());
  392.  
  393.  
  394.     CA_CATCH_ALL
  395.     CA_ENDTRY
  396.     
  397.     return result;
  398.  
  399. }
  400.  
  401.  
  402. //-------------------------------------------------------------------------
  403.  
  404. pascal OSErr CAInstallWindowActivateHandler (CAWindowActivateHandler theHandler,
  405.                                             CADocumentRef document)
  406. {
  407.     Environment*        ev            = gCASession->GetEV();
  408.     CAProxyExtension*    proxyExt    = kODNULL;
  409.     OSErr                result        = noErr;
  410.  
  411.     
  412.     CA_TRY
  413.     
  414.         TempODPart tempPart = ((CADocument*)document)->AcquireRootPart();
  415.         proxyExt = (CAProxyExtension*)tempPart->AcquireExtension( ev, kCAProxyPartExtension );
  416.     
  417.         THROW_IF_NULL (proxyExt);        // kODErrUnsupportedExtension
  418.  
  419.         CAWindowActivateHandlerUPP theUPPHandler;
  420.         theUPPHandler = (CAWindowActivateHandlerUPP) NewRoutineDescriptor((ProcPtr)theHandler, 
  421.                                                 uppCAWindowActivateHandlerInfo, 
  422.                                                 GetCurrentISA());
  423.  
  424.         proxyExt->InstallCAWindowActivateHandler( ev, theUPPHandler);
  425.  
  426.     CA_CATCH_ALL
  427.     CA_ENDTRY
  428.     
  429.     ODReleaseObject (ev, proxyExt);
  430.  
  431.     return result;
  432. }
  433.  
  434.  
  435.