home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / ExcFocus.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  24KB  |  720 lines

  1. /* @(#)Z 1.14 com/src/ui/ExcFocus.cpp, odui, od96os2, odos29712d 97/03/21 17:20:18 (96/09/03 12:21:13) */
  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.     File:           ExcFocus.cpp
  30.  
  31.     Contains:       Implementation of ODExclusiveFocusModule
  32.  
  33.     Owned by:       Richard Rodseth
  34.  
  35.     Copyright:      ⌐ 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37.     Change History (most recent first):
  38.  
  39.         <24>    10/24/95        jpa             1293441: Eat exceptions in
  40.                                     ResolveClipboardPromises
  41.         <23>     10/8/95        TJ              Fixes Recomended by Refball
  42.         <22>     10/3/95        TJ              Changes done by RefBall Team
  43.         <21>      8/3/95        RR              #1257260: Collapse B classes. Remove
  44.                                     somInit methods. Don't call IsInitialized
  45.                                     or SubclassResponsibility
  46.         <20>     6/28/95        RR              1242642 BB Mostly ref counting. Release
  47.                                     border shape
  48.         <19>     6/25/95        Té              1242642 BB: Turn on ODDebug warning if
  49.                                     refcount is wrong in
  50.                                     ODRefCntObjectsomUninit.
  51.         <18>     5/31/95        RR              #1251403 Release after AcquirePart
  52.         <17>     5/26/95        RR              #1251403: Multithreading naming support
  53.         <16>     5/17/95        RR              #1250135/1250137/1250143 Getters increment
  54.                                     refcount
  55.         <15>     5/16/95        CC              1248632, 1244940: SetFocusOwnership:
  56.                                     Externalize the current clipboard draft to
  57.                                     force resolution of promises.
  58.         <14>     5/10/95        JBS             1241913 ODPart::AdjustBorderShape is not
  59.                                     called with null shape
  60.         <13>     4/28/95        RR              1211085 Remove 5$ comments
  61.         <12>      4/7/95        RR              #1216618 Added SOM_TRY etc.
  62.         <11>      4/6/95        RR              #1220104 Use of ODObjectsAreEqual, #1211085
  63.                                     Remove 5$ comments
  64.         <10>     3/13/95        NP              1228158: Always call UseInputWindow when
  65.                                     losing keystroke focus.
  66.          <9>      3/7/95        RR              #1220929 Added cache for selection focus
  67.          <8>      3/1/95        NP              1187682: Call UseInputWindow when keystroke
  68.                                     focus is lost.
  69.          <7>    10/27/94        RR              Call FocusLost in TransferFocus #1192168
  70.          <6>    10/18/94        RR              Added fSession. Detect change in selection
  71.                                     focus. Override BRF, CRF, ARF.
  72.          <5>     9/20/94        RR              When assigning a new frame to fFrame, call
  73.                                     Acquire on the new frame BEFORe
  74.                                     calling Release on the old, in case they're
  75.                                     the same frame.
  76.          <4>      9/2/94        RR              #1184275 Pass transferringFrame and
  77.                                     newOwner to focusModule::TransferFocus
  78.          <3>     8/24/94        RR              Fixed ref counting in SetFocusOwnership
  79.          <2>     8/23/94        RR              Call Acquire and Release
  80.          <1>     6/23/94        RR              first checked in
  81.  
  82.     To Do:
  83.     In Progress:
  84.         
  85. */
  86.  
  87.  
  88. #define ODExclusiveFocusModule_Class_Source
  89. #define VARIABLE_MACROS
  90. /*
  91. class ODHandle; */  // CJC
  92. /* class ODPlatformWindow; */  // CJC
  93. #include <ExcFocus.xih>
  94.  
  95. #ifndef _PLFMDEF_
  96. #include "PlfmDef.h"
  97. #endif
  98.  
  99. #ifndef _TEMPOBJ_
  100. #include <TempObj.h>
  101. #endif
  102.  
  103. #ifndef SOM_ODFrame_xh
  104. #include "Frame.xh"
  105. #endif
  106.  
  107. #ifndef SOM_Module_OpenDoc_Foci_defined
  108. #include "Foci.xh"
  109. #endif
  110.  
  111. #ifndef _ODSESSN_
  112. #include "ODSessn.xh"
  113. #endif
  114.  
  115. #ifndef SOM_ODPart_xh
  116. #include "Part.xh"
  117. #endif
  118.  
  119. #ifndef SOM_ODFrame_xh
  120. #include "Frame.xh"
  121. #endif
  122.  
  123. #ifdef _PLATFORM_WIN32_
  124. #include "facet.xh"
  125. #endif
  126.  
  127. #ifndef SOM_ODFrameFacetIterator_xh
  128. #include "FrFaItr.xh"
  129. #endif
  130.  
  131. #ifndef SOM_ODArbitrator_xh
  132. #include <Arbitrat.xh>
  133. #endif
  134.  
  135. #ifndef SOM_ODClipboard_xh
  136. #include <Clipbd.xh>
  137. #endif
  138.  
  139. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_)
  140. #ifndef __TEXTSERVICES__
  141. #include <TextServices.h>       // Platform-dependent
  142. #endif
  143. #endif
  144.  
  145.  
  146. #ifdef _PLATFORM_OS2_
  147. #define INCL_ODAPI
  148. #include <os2.h>
  149.  
  150. #ifndef _WINDOW_
  151. #include "Window.xh"
  152. #endif
  153.  
  154. #ifndef _FACET_
  155. #include "Facet.xh"
  156. #endif
  157.  
  158. #ifndef _PASCLSTR_
  159. #include "PasclStr.h"
  160. #endif
  161.  
  162. #ifndef _STDTYPIO_
  163. #include "StdTypIO.h"
  164. #endif
  165.  
  166. #ifndef _BNDNSUTL_
  167. #include "BndNSUtl.h"
  168. #endif
  169.  
  170. #ifndef _ODUTILS_
  171. #include "odutils.h"
  172. #endif
  173. #endif  // _PLATFORM_OS2_
  174.  
  175. #ifndef SOM_ODStorageUnit_xh
  176. #include <StorageU.xh>
  177. #endif
  178.  
  179.  
  180. #ifdef _PLATFORM_WIN32_
  181. #ifndef _ODUTILS_
  182. #include <odutils.h>
  183. #endif
  184. #include <olewrap.h>
  185. #include <olemgrw.h>
  186. #include <docMgr.xh>
  187. #endif
  188.  
  189. //==============================================================================
  190. // Local function declarations
  191. //==============================================================================
  192. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_)
  193. ODStatic void ResolveClipboardPromises(Environment *ev,
  194.                 ODFrame* selectionFrame,
  195.                 ODSession* session);
  196. #endif
  197.  
  198. #ifdef _UNICODE_
  199. UniChar*        UniStr;
  200. char*           CharStr;
  201. ODConvertText*  convert;
  202. UconvObject     co;
  203. #endif
  204.  
  205. //==============================================================================
  206. // Class ODExclusiveFocusModule
  207. //==============================================================================
  208.  
  209. SOM_Scope void  SOMLINK ODExclusiveFocusModuleInitExclusiveFocusModule(ODExclusiveFocusModule *somSelf, Environment *ev,
  210.         ODSession* session)
  211. {
  212.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  213.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","InitExclusiveFocusModule");
  214.  
  215.     SOM_TRY
  216.     
  217.         /* Moved from somInit. SOM itself sets fields to zero
  218.         _fFrame = kODNULL;
  219.         _fSession = kODNULL;
  220.         _fSelectionFocus = 0;
  221.         _fKeyFocus = 0;
  222.         */
  223.         
  224.         somSelf->InitFocusModule(ev, session);
  225.         _fSession = session;
  226.         _fSelectionFocus = session->Tokenize(ev,kODSelectionFocus);
  227.         _fKeyFocus = _fSession->Tokenize(ev, kODKeyFocus);
  228.  
  229.     SOM_CATCH_ALL
  230.     SOM_ENDTRY
  231. }
  232.  
  233.  
  234. SOM_Scope void  SOMLINK ODExclusiveFocusModulesomUninit(ODExclusiveFocusModule *somSelf)
  235. {
  236.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  237.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","somUninit");
  238.  
  239.     parent_somUninit(somSelf);
  240. }
  241.  
  242. SOM_Scope ODBoolean  SOMLINK ODExclusiveFocusModuleIsFocusExclusive(ODExclusiveFocusModule *somSelf, Environment *ev,
  243.         ODTypeToken focus)
  244. {
  245.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  246.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","IsFocusExclusive");
  247.  
  248.     ODUnused(focus);
  249.     return kODTrue;
  250. }
  251.  
  252. SOM_Scope void  SOMLINK ODExclusiveFocusModuleSetFocusOwnership(ODExclusiveFocusModule *somSelf, Environment *ev,
  253.         ODTypeToken focus,
  254.         ODFrame* frame)
  255. {
  256.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  257.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","SetFocusOwnership");
  258. #if !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_WIN32_)
  259.     ODFacet* facet = kODNULL;
  260.     ODFrameFacetIterator* facets = kODNULL;
  261. #endif
  262.     SOM_TRY
  263.     
  264.         if (focus == _fSelectionFocus)
  265.         {
  266.             if (_fFrame)
  267.                 _fFrame->InvalidateActiveBorder(ev);
  268. #if !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_WIN32_)
  269.                 TempODFrame contFrame = _fFrame->AcquireContainingFrame(ev); // -- Té tempobj'd
  270.                 if ((ODFrame*) contFrame )
  271.                 {
  272.                     TempODPart contPart = contFrame->AcquirePart(ev); // -- Té tempobj'd
  273.                     facets = _fFrame->CreateFacetIterator(ev);
  274.                     for ( facet = facets->First(ev);
  275.                     facets->IsNotComplete(ev);
  276.                             facet = facets->Next(ev) )
  277.                     {
  278.                         ODShape* border = contPart->AdjustBorderShape(ev, facet, kODNULL);
  279.                         ODReleaseObject(ev, border);
  280.                     }
  281.                     ODDeleteObject(facets);
  282.                 }
  283.             }
  284.             // Note:  window->Update(ev);
  285.             if (frame)
  286.                 frame->DrawActiveBorder(ev);
  287.             ResolveClipboardPromises(ev, _fFrame, _fSession);
  288. #endif //  !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_WIN32_)
  289. #ifdef _PLATFORM_OS2_  // [124872] - ced  OS2 TASK LIST MODIFICATION CODE
  290.      {
  291. #if 0  // was not implemented in OS2 code
  292. // if selection focus changes update the Title bar and Window List
  293. // with the active editor name.
  294.      USHORT nopreferredparteditor, rc;
  295.      ULONG size=0;
  296.     // Str255 edt;
  297.      CHAR   string[256];
  298.      CHAR * edt, *str ;
  299.      ODName * name;
  300. //       HWND hwndplat = _fSession->GetPlatformWindow(ev);                          // ced
  301.      TempODWindow aWindow = frame->AcquireWindow(ev);
  302.      HWND hwndplat = aWindow->GetPlatformWindow(ev); // ced
  303.  
  304.      ODNameSpaceMana ger*  nsm = _fSession->GetNameSpaceManager(ev);
  305.      TempODPart party1 = frame->AcquirePart(ev);
  306.      ODStorageUnit * psu = party1->GetStorageUnit(ev);
  307.      ODType  pEdit =(ODType) ODGetISOStrProp(ev,psu, kODPropPreferredEditor,kODEditor,kODNULL,&size);
  308. //                        GetPreferredEditorForPart(psu,&nopreferredparteditor);
  309.      rc = GetUserEditorFromEditor(nsm, pEdit,&name);
  310. #ifdef _UNICODE_
  311.       convert = ConvertFromUnicode(((ODPlainITextData *)name->text._buffer)->theText,
  312.                    CharStr,
  313.                    UniStrlen(((ODPlainITextData *)name->text._buffer)->theText),
  314.                    co);
  315.       edt = CharStr;
  316. #else
  317.       edt =  ((ODPlainITextData *)name->text._buffer)->theText;
  318. #endif
  319. // get the root part
  320.       ODFrame * contFrame, * newFrame;
  321.       SWCNTRL swctl;
  322.       newFrame = frame;
  323.       do {
  324.      contFrame = newFrame;
  325.      newFrame = contFrame->AcquireContainingFrame(ev);
  326.  
  327.       } while ( newFrame ); /* enddo */
  328.       TempODPart party2 = contFrame->AcquirePart(ev);
  329. // get window list data
  330.       HSWITCH  hswitch = WinQuerySwitchHandle(hwndplat,0);
  331.       WinQuerySwitchEntry ( hswitch, &swctl);
  332.       strcpy (string,swctl.szSwtitle);
  333.       USHORT i=0;
  334.       while (string[i] != '\0') {
  335.     if (string[i]== '-' ) {
  336.        if ((string[i-1]==' ')&&(string[i+1]==' ')) {
  337.           break;
  338.        } /* endif */
  339.     } /* endif */
  340.     i++;
  341.       } /* endwhile */
  342.       string[i] = '\0';
  343.  
  344. //    get part name
  345.       ODName * pname = kODNULL;            // [127087]
  346.       pname = ODGetPOName(ev,party2,pname);    // [127087]
  347.         if (pname != kODNULL)
  348.             {
  349.             str =  GetCStringFromIText(pname);   // [127087]
  350.             strcat(string, " - ");
  351.             strcat(string,str);
  352.      DisposeIText(pname);                 // [127087]
  353.             }
  354.         strcat(string, " - ");
  355.         strcat(string,edt);
  356.        // change the Window List Text
  357.       strcpy(swctl.szSwtitle,string);
  358. //    WinChangeSwitchEntry (hswitch, &swctl);
  359. //      WinSetWindowText(hwndplat,string);
  360. #endif // #if 0
  361.       frame->DrawActiveBorder(ev);
  362.     }
  363.       frame->DrawActiveBorder(ev);
  364. #endif // _PLATFORM_OS2
  365.  
  366. #ifdef _PLATFORM_WIN32_
  367.  // ********* OLE Interop start ******
  368.   TempODPart part = frame->AcquirePart(ev);
  369.   OleWrapper* wrapper = ODOLEManager::GetShell()->GetDocumentManagerOfDraft(ev, part->GetStorageUnit(ev)->GetDraft(ev))->GetOleWrapper(ev);
  370.   if (wrapper) {
  371.      if ((wrapper->fWFlg & WFLG_UIACTIVATED) && (wrapper->fActiveDocumentWindow == wrapper->fRootDocumentWindow))
  372.           wrapper->ActiveFocusChanging(frame);
  373.   }
  374.  // **********OLE Interop end
  375.    if(frame)
  376.       frame->DrawActiveBorder(ev);
  377. #endif // _PLATFORM_WIN32_
  378.  
  379.   }  // end for - if (focus == _fSelectionFocus)
  380.         
  381. #ifdef _PLATFORM_OS2_  // [124960] - ced
  382.   if (focus == _fKeyFocus)
  383.   {
  384.       /* Restore PM focus to docshell client window. */
  385.       TempODWindow window = frame->AcquireWindow(ev);
  386.       if (window)
  387.       {
  388.      HWND hwndFrame, hwnd, hwndFocus;
  389.      hwndFrame = window->GetPlatformWindow(ev);
  390.      if (WinQueryActiveWindow(HWND_DESKTOP) == hwndFrame)
  391.      {
  392.         hwnd = WinWindowFromID(hwndFrame, FID_CLIENT);
  393.         if (!hwnd)
  394.            /* No client window!  Odd.  Just use hwndFrame then. */
  395.            hwnd = hwndFrame;
  396.         /*
  397.          * If the window that currently has the PM focus is a child of one of
  398.          * the facet windows that belongs to the frame receiving the key focus,
  399.          * then do nothing.  Otherwise, set the PM focus to the shell client
  400.          * window.
  401.          */
  402.         hwndFocus = WinQueryFocus(HWND_DESKTOP);
  403.         if (hwndFocus != hwnd)
  404.         {
  405.            ODFacet* facet = kODNULL;
  406.            while (hwndFocus && hwndFocus != hwnd && hwndFocus != HWND_DESKTOP)
  407.            {
  408.           if ((facet = _ODFacet->clsGetFacetFromHWND(ev, hwndFocus)) != kODNULL)
  409.              break;
  410.           hwndFocus = WinQueryWindow(hwndFocus, QW_PARENT);
  411.            }
  412.            if (!(facet && facet->GetFrame(ev) == frame))
  413.           WinSetFocus(HWND_DESKTOP, hwnd);
  414.         }
  415.      }
  416.       }
  417.   }
  418. #endif // _PLATFORM_OS2_
  419. #ifdef _PLATFORM_WIN32_
  420.  
  421.   if (focus == _fKeyFocus)
  422.   {
  423.       /* Restore Window focus to docshell client window. */
  424.       TempODWindow window = frame->AcquireWindow(ev);
  425.       if (window)
  426.       {
  427.      HWND hwndFrame, hwnd, hwndFocus;
  428.      hwndFrame = window->GetPlatformWindow(ev);
  429. //         if (WinQueryActiveWindow(HWND_DESKTOP) == hwndFrame)
  430.      // gets Active window handle for this thread - and compares to current frame handle?
  431.      if (GetActiveWindow() == hwndFrame)  // NT/95 call
  432.      {
  433. #ifndef _PLATFORM_WIN32_  // don't need to get client in NT use frame
  434. //            hwnd = WinWindowFromID(hwndFrame, FID_CLIENT); /* gets client window handle */
  435.         /* is there a win32 api to get handle to client ???????? call below gets child not client */
  436.         hwnd = GetWindow(hwndFrame, GW_CHILD);   // NT/95 call try and get child window if one exists
  437.         if (!hwnd)
  438.            /* No client window!  Odd.  Just use hwndFrame then. */
  439. #endif // _PLATFORM_WIN32_
  440.            hwnd = hwndFrame;
  441.         /*
  442.          * If the window that currently has the PM focus is a child of one of
  443.          * the facet windows that belongs to the frame receiving the key focus,
  444.          * then do nothing.  Otherwise, set the PM focus to the shell client
  445.          * window.
  446.          */
  447. //            hwndFocus = WinQueryFocus(HWND_DESKTOP);
  448.         // retrieves the handle of the keyboard focus window associated with the thread that called the function.
  449.         hwndFocus = GetFocus(); // NT/95 call
  450.     
  451. //#ifndef _PLATFORM_WIN32_ // *** work around CJC - clsGetFacetFromHWND not implemented yet.
  452. //            if (hwndFocus != hwnd)   // CJC if window with focus != this one(current one)
  453. //                SetFocus(hwnd);  // NT/95 call
  454. //#else
  455.         if (hwndFocus != hwnd)   // CJC if window with focus != this one(current one)
  456.         {
  457.            ODFacet* facet = kODNULL;
  458.          // (not null) && (focus != current) && (focus != owning window)
  459.            while (hwndFocus && hwndFocus != hwnd && hwndFocus != HWND_DESKTOP)
  460.            {
  461.           if ((facet = _ODFacet->clsGetFacetFromHWND(ev, hwndFocus)) != kODNULL)
  462.              break;
  463.           //                  hwndFocus = WinQueryWindow(hwndFocus, QW_PARENT);
  464.           hwndFocus = GetParent(hwndFocus); // NT/95 call - get parent handle of hwndFocus
  465.            }
  466.         // if (face != NULL) && facet Frame == current frame) then set focus
  467.            if (!(facet && facet->GetFrame(ev) == frame))
  468.           SetFocus(hwnd);  // NT/95 call
  469.         //                  WinSetFocus(HWND_DESKTOP, hwnd);
  470.         }
  471. //#endif
  472.      }
  473.       }
  474.   }
  475. #endif // _PLATFORM_WIN32_
  476.  
  477.         if (frame)
  478.             frame->Acquire(ev);
  479.         if (_fFrame)
  480.             _fFrame->Release(ev);
  481.         _fFrame = frame;
  482.  
  483.     SOM_CATCH_ALL
  484.     SOM_ENDTRY
  485. }
  486.  
  487. SOM_Scope void  SOMLINK ODExclusiveFocusModuleUnsetFocusOwnership(ODExclusiveFocusModule *somSelf, Environment *ev,
  488.         ODTypeToken focus,
  489.         ODFrame* frame)
  490. {
  491.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  492.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","UnsetFocusOwnership");
  493.  
  494.     SOM_TRY
  495.     if (focus == _fKeyFocus)
  496.     {
  497. #ifdef _PLATFORM_OS2_  // [124960] - ced
  498.       /* Restore PM focus to docshell client window. */
  499.       TempODWindow window = frame->AcquireWindow(ev);
  500.       if (window)
  501.       {
  502.      HWND hwndFrame, hwnd;
  503.      hwndFrame = window->GetPlatformWindow(ev);
  504.      if (WinQueryActiveWindow(HWND_DESKTOP) == hwndFrame)
  505.      {
  506.         hwnd = WinWindowFromID(hwndFrame, FID_CLIENT);
  507.         if (!hwnd)
  508.            /* No client window!  Strange.  Just use hwndFrame then. */
  509.            hwnd = hwndFrame;
  510.  
  511.         WinSetFocus(HWND_DESKTOP, hwnd);
  512.      }
  513.       }
  514. #endif
  515. // ** The following is the windows code but it is not complete
  516. // due to the frame and facet design dependency.
  517. #if !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_WIN32_)
  518.       /* Restore focus to docshell client window. */
  519.       TempODWindow window = frame->AcquireWindow(ev);
  520.       if (window)
  521.       {
  522.      HWND hwndFrame, hwnd;
  523.      hwndFrame = window->GetPlatformWindow(ev);
  524.      if (GetActiveWindow() == hwndFrame)  // NT/95 call
  525. //         if (WinQueryActiveWindow(HWND_DESKTOP) == hwndFrame)
  526.      {
  527. //            hwnd = WinWindowFromID(hwndFrame, FID_CLIENT);
  528. //            hwnd = GetWindow(hwndFrame, GW_CHILD);   // NT/95 call try and get child window if one exists
  529. //            if (!hwnd)
  530.            /* No client window!  Strange.  Just use hwndFrame then. */
  531.            hwnd = hwndFrame;
  532.  
  533.         SetFocus(hwnd);
  534. //            WinSetFocus(HWND_DESKTOP, hwnd);
  535.      }
  536.       }
  537. #endif
  538. #if !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_WIN32_)
  539.             const TSMDocumentID     kAnyDoc = kODNULL;
  540.         
  541.             // Make sure to set this back to a safe state.
  542.             UseInputWindow(kAnyDoc, kODTrue);
  543. #endif
  544.         }
  545.     
  546.         if (ODObjectsAreEqual(ev, frame, _fFrame))
  547.         {
  548.             if (focus == _fSelectionFocus)
  549.             {
  550.                 if ( _fFrame )
  551.                     _fFrame->InvalidateActiveBorder(ev);
  552.                 // Note: window->Update(ev);
  553. #ifdef _PLATFORM_WIN32_
  554.    // ********* OLE Interop start ******
  555.  
  556.   TempODPart part = frame->AcquirePart(ev);
  557.   OleWrapper* wrapper = ODOLEManager::GetShell()->GetDocumentManagerOfDraft(ev, part->GetStorageUnit(ev)->GetDraft(ev))->GetOleWrapper(ev);
  558.  
  559.   if (wrapper) {
  560.       if ((wrapper->fWFlg & WFLG_UIACTIVATED) && (wrapper->fActiveDocumentWindow == wrapper->fRootDocumentWindow))
  561.            wrapper->ActiveFocusChanging(NULL);
  562.   }
  563.    // **********OLE Interop end
  564. #endif
  565.             }
  566.         
  567.             if (_fFrame)
  568.                 _fFrame->Release(ev);
  569.             _fFrame = kODNULL;
  570.         }
  571.  
  572.     SOM_CATCH_ALL
  573.     SOM_ENDTRY
  574. }
  575.  
  576. SOM_Scope void  SOMLINK ODExclusiveFocusModuleTransferFocusOwnership(ODExclusiveFocusModule *somSelf, Environment *ev,
  577.         ODTypeToken focus,
  578.         ODFrame* transferringFrame,
  579.         ODFrame* newOwner)
  580. {
  581.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  582.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","ODExclusiveFocusModuleTransferFocusOwnership");
  583.  
  584.     SOM_TRY
  585.  
  586.         TempODFrame oldOwner = somSelf->AcquireFocusOwner(ev, focus);
  587.         somSelf->SetFocusOwnership(ev, focus, newOwner);
  588.         
  589.         if (oldOwner && (oldOwner != transferringFrame))
  590.         {
  591.             TempODPart part = oldOwner->AcquirePart(ev);
  592.             part->FocusLost(ev, focus, oldOwner);
  593.         }
  594.         if (newOwner && (newOwner != transferringFrame))
  595.         {
  596.             TempODPart part = newOwner->AcquirePart(ev);
  597.             part->FocusAcquired(ev, focus, newOwner);
  598.         }
  599.  
  600.     SOM_CATCH_ALL
  601.     SOM_ENDTRY
  602. }
  603.  
  604. SOM_Scope ODFrame*  SOMLINK ODExclusiveFocusModuleAcquireFocusOwner(ODExclusiveFocusModule *somSelf, Environment *ev,
  605.         ODTypeToken focus)
  606. {
  607.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  608.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","AcquireFocusOwner");
  609.  
  610.     ODUnused(focus);
  611.     if (_fFrame) {
  612.         SOM_TRY
  613.             _fFrame->Acquire(ev);
  614.         SOM_CATCH_ALL
  615.         SOM_ENDTRY
  616.     }
  617.     return _fFrame;
  618. }
  619.  
  620. SOM_Scope ODBoolean  SOMLINK ODExclusiveFocusModuleBeginRelinquishFocus(ODExclusiveFocusModule *somSelf, Environment *ev,
  621.         ODTypeToken focus,
  622.         ODFrame* requestingFrame)
  623. {
  624.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  625.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","ODExclusiveFocusModuleBeginRelinquishFocus");
  626.  
  627.     ODBoolean canRelinquish = kODTrue;
  628.     
  629.     SOM_TRY
  630.  
  631.         TempODFrame currentOwner = somSelf->AcquireFocusOwner(ev, focus);
  632.     
  633.         if (currentOwner && (!ODObjectsAreEqual(ev, currentOwner, requestingFrame)))
  634.         {
  635.             TempODPart part = currentOwner->AcquirePart(ev); // -- Té tempobj'd
  636.             if ((ODPart*)part)
  637.                 canRelinquish = part->BeginRelinquishFocus(ev, focus, currentOwner, requestingFrame);
  638.         }
  639.  
  640.     SOM_CATCH_ALL
  641.     SOM_ENDTRY
  642.     
  643.     return canRelinquish;
  644. }
  645.  
  646. SOM_Scope void  SOMLINK ODExclusiveFocusModuleCommitRelinquishFocus(ODExclusiveFocusModule *somSelf, Environment *ev,
  647.         ODTypeToken focus,
  648.         ODFrame* requestingFrame)
  649. {
  650.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  651.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","ODExclusiveFocusModuleCommitRelinquishFocus");
  652.  
  653.     SOM_TRY
  654.  
  655.         TempODFrame currentOwner = somSelf->AcquireFocusOwner(ev, focus);
  656.         
  657.         if ((currentOwner)  && (!ODObjectsAreEqual(ev, currentOwner,requestingFrame)))
  658.         {
  659.             TempODPart part = currentOwner->AcquirePart(ev); // -- Té tempobj'd
  660.             if ((ODPart*)part)
  661.                 part->CommitRelinquishFocus(ev, focus, currentOwner, requestingFrame);
  662.         }
  663.  
  664.     SOM_CATCH_ALL
  665.     SOM_ENDTRY
  666. }
  667.  
  668. SOM_Scope void  SOMLINK ODExclusiveFocusModuleAbortRelinquishFocus(ODExclusiveFocusModule *somSelf, Environment *ev,
  669.         ODTypeToken focus,
  670.         ODFrame* requestingFrame)
  671. {
  672.     ODExclusiveFocusModuleData *somThis = ODExclusiveFocusModuleGetData(somSelf);
  673.     ODExclusiveFocusModuleMethodDebug("ODExclusiveFocusModule","ODExclusiveFocusModuleAbortRelinquishFocus");
  674.  
  675.     SOM_TRY
  676.  
  677.         TempODFrame currentOwner = somSelf->AcquireFocusOwner(ev, focus);
  678.         if (currentOwner && (!ODObjectsAreEqual(ev, currentOwner,requestingFrame)))
  679.         {
  680.             TempODPart part = currentOwner->AcquirePart(ev); // -- Té tempobj'd
  681.             if ((ODPart*)part)
  682.                 part->AbortRelinquishFocus(ev, focus, currentOwner,requestingFrame);
  683.         }
  684.  
  685.     SOM_CATCH_ALL
  686.     SOM_ENDTRY
  687. }
  688.  
  689.  
  690. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_)
  691. ODStatic void ResolveClipboardPromises(Environment *ev,
  692.                 ODFrame* selectionFrame,
  693.                 ODSession* session)
  694. {
  695.     ODArbitrator* arbitrator = session->GetArbitrator(ev);
  696.  
  697.     ODToken         clipboardFocus = session->Tokenize(ev, kODClipboardFocus);
  698.     TempODFrame clipOwner = arbitrator->AcquireFocusOwner(ev, clipboardFocus);
  699.  
  700.     if ( (clipOwner == selectionFrame) || arbitrator->RequestFocus(ev, clipboardFocus, selectionFrame) )
  701.     {
  702.         ODClipboard* clipboard = session->GetClipboard(ev);
  703.         TRY{
  704.             ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
  705. #ifndef _PLATFORM_WIN32_
  706.             ODDraft* draft = su->GetDraft(ev);
  707.             draft->Externalize(ev);
  708. #endif
  709.         }CATCH_ALL{
  710.             WARNMSG("Error %d externalizing clipboard",ErrorCode());
  711.             // If this failed the Clipboard is probably hosed now.
  712.             clipboard->DiscardClipboard(ev);
  713.         }ENDTRY
  714.  
  715.         if ( clipOwner != selectionFrame )
  716.             arbitrator->RelinquishFocus(ev, clipboardFocus, selectionFrame);
  717.     }
  718. }
  719. #endif
  720.