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

  1. /* @(#)Z 1.14 com/src/binding/BindngH.cpp, odconfig, od96os2, odos29712d 97/03/21 17:18:03 (96/10/29 09:15:00) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odconfig
  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.   File:    BindngH.cpp
  31.  
  32.   Contains:  C++ Implementation for Binding Helper class.
  33.  
  34.   Owned by:  Caia Grisar
  35.  
  36.   Copyright:  ⌐ 1993-94 by Apple Computer, Inc., all rights reserved.
  37.  
  38.   Change IBM History (most recent first):
  39.  
  40.      <14> 04/29/96 LAW          further changes for NT version
  41.      <13> 04/11/96 CBH          Ported to NT platform
  42.      <12> 11/27/95 JSO 143039   Added check for editorexists in alphanumchooseeditor
  43.      <11> 11/01/95 JSO 142527   Added support track registry updates
  44.      <10> 09/29/95 JSO 123852   Added support for preferred categories
  45.      <9>  08/23/95 JSO 133968   port dr3
  46.      <8>  07/27/95 JSO 124094   Fix to prevent trap if dll is missing
  47.      <7>  07/21/95 JSO 130450   Removed old filetypepreferences code
  48.      <6>  07/14/95 JSO 123473   Added Pref FileType/Preferences calls
  49.      <5>  06/28/95 JSO 123479   Commented out Update Preferences call
  50.      <4>  06/09/95 JSO 125065   Updates for System Preferences
  51.      <3>  06/05/95 jso 123330     Fix for Kind/Category matching
  52.      <2>  04/28/95 jso 120604  B1C16 Port Apple Changes (24 - 28>
  53.      <1>  04/13/95 dcp # 117196 : Added null check for containerType in GetContainerSuite method.
  54.  
  55.   Change Apple History (most recent first):
  56.  
  57.     <37>   6/21/95  CC    1260937: BB: ODTypeListIterator must return
  58.                   copies of ODType values.
  59.     <36>   6/19/95  VL    1170098: Set return result for
  60.                   GetPreferredEditorForPart to kODNULL if the
  61.                   operation fails.
  62.     <35>   6/16/95  EL    #1254926: Don't return an editor that does
  63.                   not exists.
  64.     <34>   6/16/95  CC    1259719: Added ChangeEditor and
  65.                   ChangeKindAndEditor.
  66.     <33>   5/18/95  CG    #1249728 BB: BindingH.cpp needs to call
  67.                   StdTypIO routines for ISOStr
  68.                   #1249263 BB: BndNSUtl.cpp does not compile
  69.                   standalone.
  70.     <32>   4/27/95  CC    1243813: Removed ShowAlert and
  71.                   BindingDialogFilter; replaced by ShowAlert
  72.                   in DlogUtil.
  73.     <31>   4/26/95  CG    1210975 BB: 5$ Bugs need to be evaluatedand
  74.                   removed from Binding.
  75.     <30>   4/26/95  CG    1210975 BB: 5$ Bugs need to be evaluated
  76.                   and removed from Binding.
  77.     <29>   4/13/95  CG    Removed obsolete #include.
  78.     <28>   3/28/95      CG      #1211901 BB:  Binding methods check for
  79.                                 null storage unit.
  80.     <27>   2/16/95      CG      #1213926 BB:binding respects preferred
  81.                                 kinds.  #1210975 BB: $$$$$ fixes.
  82.     <26>   2/14/95      TJ      Fixed copyright date.
  83.     <25>   2/14/95      jpa     Fixed GetContainerSuite to always return
  84.                                 NULL on failure, and to use the
  85.                                 SysPrefContainerSuites namespace. [1205141]
  86.     <24>    2/2/95      CG      #1195019:  ValueNameSpace entries are now
  87.                                 copied in and out instead of pointers being
  88.                                 passed around.
  89.     <23>   1/25/95  jpa    Fixed no-prefs crashes [1214750]
  90.     <22>   1/24/95  CG    In GetContainerSuite now check return value
  91.                   of ValueNameSpaceGetEntry instead of return
  92.                   parameter.  broke last build.
  93.     <21>   1/23/95  CG    #1195019: ValueNameSpace methods now take
  94.                   ODByteArray parameter instead of ODPtr.
  95.     <20>   1/13/95  RR    Removed include of ODTypesM.xh
  96.     <19>   1/12/95  jpa    Don't use obsolete Toolbox names. [1211211]
  97.     <18>   1/10/95  CG    #1201731:  BB: Now get NoPart if a part
  98.                   can't be loaded because of an error.
  99.     <17>  12/20/94  VL    1195012: Make Storage calls be
  100.                   marshallable.
  101.     <16>  12/13/94  CG    #1193522: Warning dialog displayed if
  102.                   automatic binding has occurred.
  103.     <15>   10/7/94  CG    #1184728:  Broke NoPart with last fix!
  104.     <14>   10/7/94  CG    #1184728: Binding to another part that
  105.                   supports the same kind when original editor
  106.                   not found now works.
  107.     <13>    9/9/94  CG    1182933: changed NoPart editor id.
  108.     <12>    9/9/94  jpa    Fixed IsEditorLoaded to call new
  109.                   ODClassExists rather than use SOM; this fix
  110.                   re-enables debugging of parts. [1182105]
  111.     <11>   8/24/94  CG    #1181622: Updated file ownership.
  112.     <10>   8/17/94  CG    #1181440 The View and EditorKinds name
  113.                   spaces were changed to be of type
  114.                   ODObjectNameSpace.
  115.      <9>   7/29/94  CG    NameSpace API changes.
  116.      <8>   7/26/94  jpa    Don't call InitObject from InitBinding.
  117.      <7>    7/1/94  CG    Changes to IsEditorLoaded.
  118.      <6>    7/1/94  CG    Added som calls to IsEditorLoaded.
  119.      <5>   6/28/94  VL    Use Translt.cpp.
  120.      <4>   6/27/94  CG    Moved IsEditorLoaded here from Prefs.
  121.                   Removed fEv.
  122.      <3>   6/23/94  eeh    oops....include EditrSet.h
  123.      <2>   6/23/94  eeh    remove ODEditorSetIterator and EditorSet
  124.      <1>   6/20/94  CG    first checked in
  125.  
  126.   To Do:
  127.   In Progress:
  128. */
  129.  
  130. #ifndef _BINDNGH_
  131. #include "BindngH.h"
  132. #endif
  133.  
  134. #ifdef  _PLATFORM_MACINTOSH_
  135. #ifndef __ERRORS__
  136. #include <Errors.h>
  137. #endif
  138. #endif // _PLATFORM_MACINTOSH_
  139.  
  140. #ifdef _PLATFORM_OS2_ // For the updating preferences on OS2
  141. #include <sys\types.h>
  142. #define INCL_DOS
  143. #include <OS2.H>
  144. #endif // _PLATFORM_OS2_
  145.  
  146. #ifndef _EDITRSET_
  147. #include "EditrSet.h"
  148. #endif
  149.  
  150. #ifndef _ODMEMORY_
  151. #include "ODMemory.h"
  152. #endif
  153.  
  154. #ifndef SOM_ODStorageUnit_xh
  155. #include "StorageU.xh"
  156. #endif
  157.  
  158. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  159. #include "StdDefs.xh"
  160. #endif
  161.  
  162. #ifndef SOM_Module_OpenDoc_StdProps_defined
  163. #include "StdProps.xh"
  164. #endif
  165.  
  166. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  167. #include "StdTypes.xh"
  168. #endif
  169.  
  170. #ifndef _ODUTILS_
  171. #include "ODUtils.h"
  172. #endif
  173.  
  174. #ifndef SOM_ODTranslation_xh
  175. #include "Translt.xh"
  176. #endif
  177.  
  178. #ifndef _ODSESSN_
  179. #include "ODSessn.xh"
  180. #endif
  181.  
  182. #ifndef SOM_ODValueNameSpace_xh
  183. #include "ValueNS.xh"
  184. #endif
  185.  
  186. #ifndef SOM_ODObjectNameSpace_xh
  187. #include "ObjectNS.xh"
  188. #endif
  189.  
  190. #ifndef _ORDCOLL_
  191. #include "OrdColl.h"
  192. #endif
  193.  
  194. #ifndef SOM_ODNameSpaceManager_xh
  195. #include "NmSpcMg.xh"
  196. #endif
  197.  
  198. #ifndef _EXCEPT_
  199. #include "Except.h"
  200. #endif
  201.  
  202. #ifndef _PASCLSTR_
  203. #include "PasclStr.h"
  204. #endif
  205.  
  206. #ifndef _ISOSTR_
  207. #include "ISOStr.h"
  208. #endif
  209.  
  210. #ifndef SOM_Apple_NoPart_xh
  211. //#include <NoPart.xh>
  212. #endif
  213.  
  214. #ifndef SOM_ODTypeList_xh
  215. #include <TypeList.xh>
  216. #endif
  217.  
  218. #ifndef SOM_ODTypeListIterator_xh
  219. #include <TypLsItr.xh>
  220. #endif
  221.  
  222. #ifndef _BNDNSUTL_
  223. #include "BndNSUtl.h"
  224. #endif
  225.  
  226. #ifndef _ODNEWOBJ_
  227. #include <ODNewObj.h>
  228. #endif
  229.  
  230. #ifdef _PLATFORM_MACINTOSH_
  231. #ifndef __DIALOGS__
  232. #include <Dialogs.h>
  233. #endif
  234. #endif // _PLATFORM_MACINTOSH_
  235.  
  236. #ifndef SOM_ODWindowState_xh
  237. #include <WinStat.xh>
  238. #endif
  239.  
  240. #ifndef SOM_ODWindow_xh
  241. #include <Window.xh>
  242. #endif
  243.  
  244. #ifdef _PLATFORM_MACINTOSH_
  245. #ifndef _USERSRCM_
  246. #include <UseRsrcM.h>
  247. #endif
  248. #endif // _PLATFORM_MACINTOSH_
  249.  
  250. #ifndef _STORUTIL_
  251. #include <StorUtil.h>
  252. #endif
  253.  
  254. #ifndef _BNDNGDEF_
  255. #include "BndngDef.h"
  256. #endif
  257.  
  258. #ifndef SOM_ODFrame_xh
  259. #include <Frame.xh>
  260. #endif
  261.  
  262. #ifndef _NMSPCUTL_
  263. #include <NmSpcUtl.h>
  264. #endif
  265.  
  266. #ifndef SOM_ODDispatcher_xh
  267. #include <Disptch.xh>
  268. #endif
  269.  
  270. #ifndef _DLOGUTIL_
  271. #include <DlogUtil.h>
  272. #endif
  273.  
  274. #ifndef SOM_ODPartWrapper_xh
  275. #include <PartWrap.xh>
  276. #endif
  277.  
  278. #ifndef _STDTYPIO_
  279. #include <StdTypIO.h>
  280. #endif
  281.  
  282. #ifndef SOM_ODObjectIterator_xh
  283. #include <ObjctItr.xh>
  284. #endif
  285.  
  286. #ifndef _BARRAY_
  287. #include <BArray.h>
  288. #endif
  289.  
  290. #ifndef SOM_ODDraft_xh
  291. #include <Draft.xh>
  292. #endif
  293.  
  294. #ifndef _RManager_
  295. #include <RManager.xh>
  296. #endif
  297.  
  298. #ifndef _ODPrtRei_
  299. #include <ODPrtRei.xh>
  300. #endif
  301.  
  302. #ifndef _PartInfi_
  303. #include <PartInfi.xh>
  304. #endif
  305.  
  306. #include <somcls.xh>
  307. #include <somcm.xh>
  308. #include <sys/stat.h>
  309. #include <iostream.h>
  310. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_)
  311. #include <direct.h>
  312. #endif
  313.  
  314. #undef  LOGGING   // remove define of logging (off) from ODDebug.h
  315. #define LOGGING 1 // turn on logging
  316.  
  317. //==============================================================================
  318. // Constants
  319. //==============================================================================
  320. const int MAXSTR = 256;
  321.  
  322. //=========================================================================
  323. // Globals
  324. //=========================================================================
  325.  
  326.  
  327. //=========================================================================
  328. // Function Prototypes
  329. //=========================================================================
  330. #ifdef _PLATFORM_MACINTOSH_
  331.  
  332. pascal Boolean BindingDialogFilter(DialogPtr dialog,
  333.                                    EventRecord* event,
  334.                                    short* itemHit);
  335. #endif // _PLATFORM_MACINTOSH_
  336. //==============================================================================
  337. // Class Binding
  338. //==============================================================================
  339.  
  340. //------------------------------------------------------------------------------
  341. // Binding::Binding
  342. //------------------------------------------------------------------------------
  343. Binding::Binding()
  344. {
  345.   fSession    = (ODSession*) kODNULL;
  346.   fRManager   = 0;
  347.   fODRegistry = 0;
  348.   lastRegUpdate = 0;
  349.   fev = somGetGlobalEnvironment();
  350. }
  351.  
  352. //------------------------------------------------------------------------------
  353. // Binding::~Binding
  354. //------------------------------------------------------------------------------
  355. Binding::~Binding()
  356. {
  357. }
  358.  
  359. //------------------------------------------------------------------------------
  360. // Binding::InitBinding
  361. //------------------------------------------------------------------------------
  362. void Binding::InitBinding(ODSession* session )
  363. {
  364.   char *dirname;
  365.   struct stat statbuf;
  366.  
  367.   fSession = session;
  368.   fRManager = new RegistryManager;
  369.   fODRegistry = (ODPartHandlerRegistryInt*)fRManager->
  370.                         GetODPartHandlerRegistry(somGetGlobalEnvironment());
  371.  
  372.   // 24247: set global registry reference in session object
  373.   Environment* ev = somGetGlobalEnvironment ();
  374.   session->SetRegistry(ev, fODRegistry);
  375.  
  376.   dirname = getenv(ODRegistryPathEnvVar);
  377.   if ((dirname == NULL) || (*dirname == 0))
  378.      {
  379.      getcwd((char *) &completeRegFileName, MAXSTR);
  380.      strcat(completeRegFileName, "\\");
  381.      strcat(completeRegFileName, ODRegistryFileName);
  382.      }
  383.   else
  384.      {
  385.      strcpy(completeRegFileName, dirname);
  386.      strcat(completeRegFileName, "\\");
  387.      strcat(completeRegFileName, ODRegistryFileName);
  388.      }
  389. //   LOG("OpenDoc Registry file = %s\n", completeRegFileName);
  390.  
  391. #ifdef _PLATFORM_UNIX_
  392.   if(stat(this->completeRegFileName, &statbuf) == 0)
  393. #else
  394.   if(_stat(this->completeRegFileName, &statbuf) == 0)
  395. #endif
  396.      this->lastRegUpdate = statbuf.st_atime;
  397.   else
  398.      this->lastRegUpdate = 0;
  399. }
  400.  
  401. //------------------------------------------------------------------------------
  402. // Binding::Purge
  403. //------------------------------------------------------------------------------
  404. ODSize Binding::Purge(ODSize size)
  405. {
  406. ODUnused(size);
  407.   // The only memory that Binding has to purge is owned by NmSpcMgr and
  408.   // should be purged from there.
  409.   return 0;
  410. }
  411.  
  412.  
  413.   //---------------------------------
  414.   // Direct editor bindings
  415.  
  416. //------------------------------------------------------------------------------
  417. // Binding::ChooseEditorForPart
  418. //------------------------------------------------------------------------------
  419. ODEditor Binding::ChooseEditorForPart(ODStorageUnit* thePartSU, ODType newKind )
  420. {
  421.   struct stat statbuf;
  422.   ODEditor theEditor = (ODEditor)kODNULL;
  423.   ODBoolean noPreferredEditorProp = kODFalse;
  424.  
  425.   if (thePartSU)
  426.      theEditor = GetPreferredEditorForPart(thePartSU, &noPreferredEditorProp);
  427.   if (theEditor) return theEditor;
  428.  
  429.  // check the last update of the registry file
  430.   long update = 0;
  431. #ifdef _PLATFORM_UNIX_
  432.   if(stat(this->completeRegFileName, &statbuf) == 0)
  433. #else
  434.   if(_stat(this->completeRegFileName, &statbuf) == 0)
  435. #endif
  436.   {
  437.      update = statbuf.st_atime;
  438.      if(update > this->lastRegUpdate)
  439.      {
  440.        fODRegistry = (ODPartHandlerRegistryInt*) fRManager->RefreshODPartHandlerRegistry (fev);
  441.        fSession->SetRegistry(fev, fODRegistry);
  442.        this->lastRegUpdate = update;
  443.        ODNameSpaceManager *nsm = fSession->GetNameSpaceManager(fev);
  444.        nsm->SynchNSTable(fev);
  445.      }
  446.   }
  447.  
  448.   if (thePartSU)
  449.      theEditor = ChooseDirectEditorForPart(thePartSU, newKind);
  450.  
  451. /*
  452.   // NO AUTOMATIC TRANSLATION in v1
  453.   if (!theEditor && AutomaticTranslation())
  454.     theEditor = TranslateAndChooseEditorForPart(thePartSU);
  455. */
  456.  
  457.   if( !theEditor)
  458.       theEditor = ChooseEditorForOSType(thePartSU);
  459.  
  460.   if( !theEditor)
  461.       theEditor = ChooseEditorForOSfilenameFilter(thePartSU);
  462.  
  463.   if (!theEditor)
  464.   {
  465.     theEditor = (ODEditor) kODBlackBoxHandlerOfLastResort;
  466.   }
  467.   else
  468.   {
  469.         if (thePartSU)
  470.         {
  471.                 ODDraft* draft = thePartSU->GetDraft(fev);
  472.                 if (draft->GetPermissions(fev) == kODDPExclusiveWrite)
  473.                 {
  474.                         ODSetISOStrProp(fev, thePartSU,
  475.                                         kODPropPreferredEditor,
  476.                                         kODEditor,
  477.                                         theEditor);
  478.                 }
  479.                 if (!noPreferredEditorProp) this->BindingWarning();
  480.         }
  481.   }
  482.   return theEditor;
  483. }
  484.  
  485. //------------------------------------------------------------------------------
  486. // Binding::TranslateAndChooseEditorForPart
  487. //------------------------------------------------------------------------------
  488.  
  489. ODEditor Binding::TranslateAndChooseEditorForPart(ODStorageUnit* thePartSU)
  490. {
  491. ODUnused(thePartSU);
  492.   return (ODEditor)kODNULL;
  493. }
  494.  
  495. //------------------------------------------------------------------------------
  496. // Binding::ChooseDirectEditorForPart
  497. //------------------------------------------------------------------------------
  498.  
  499. ODEditor Binding::ChooseDirectEditorForPart(ODStorageUnit* thePartSU,
  500.                                 ODType newKind )
  501. {
  502. // NOTE: This method does NOT check the preferred editor of the given part
  503.  
  504.   ODEditor theEditor = kODNULL;
  505.  
  506.    if (thePartSU)
  507.    {
  508.       // Check for preferredKind property
  509.       if (thePartSU->Exists(fev, kODPropPreferredKind, kODISOStr, 0))
  510.       {
  511.         ODULong size;
  512.         ODType preferredKind = ODGetISOStrProp(fev, thePartSU,
  513.                   kODPropPreferredKind, kODISOStr, kODNULL, &size);
  514.         theEditor = ChooseDirectEditorForKind(preferredKind,thePartSU);
  515.         ODDisposePtr(preferredKind);
  516.       }
  517.       if (theEditor) return theEditor;
  518.  
  519.       // Attempt to bind using the content values in their fidelity order
  520.       for (ODValueIndex valueIndex = 1;
  521.         thePartSU->Exists(fev, kODPropContents,(ODValueType)kODNULL,valueIndex)
  522.                                 && (theEditor == kODNULL);
  523.         valueIndex++)
  524.       {
  525.         thePartSU->Focus(fev, kODPropContents,kODPosSame,(ODValueType)kODNULL,
  526.                                  valueIndex,kODPosSame);
  527.         theEditor = ChooseDirectEditorForKind(thePartSU->GetType(fev),thePartSU);
  528.       }
  529.       if (theEditor) return theEditor;
  530.    }
  531.  
  532.    theEditor = ChooseDirectEditorForKind(newKind,thePartSU);
  533.  
  534.    if (theEditor) return theEditor;
  535.    else return kODNULL;
  536. }
  537.  
  538. //------------------------------------------------------------------------------
  539. // Binding::ChooseDirectEditorForKind
  540. //------------------------------------------------------------------------------
  541.  
  542. ODEditor Binding::ChooseDirectEditorForKind(ODType aKind,
  543.                              ODStorageUnit* thePartSU)
  544. {
  545.  
  546.   ISOString partHandler = NULL;
  547.   ODPartHandlerInfo* partHandlerInfo = kODNULL;
  548.   ODEditor theEditor = kODNULL;
  549.   ODSShort               i = 0;
  550.   _IDL_SEQUENCE_string CategoryList;
  551.   _IDL_SEQUENCE_ISOString PartHandlerList;
  552.   ODBoolean   editorFound = kODFalse;
  553.   Environment* ev = somGetGlobalEnvironment ();
  554.  
  555.   if (!aKind )
  556.     return theEditor;
  557.  
  558.  
  559.    // Check for the preferred editor first
  560.    partHandler = fODRegistry->GetPreferredPartHandler(fev, aKind);
  561.    if(partHandler)
  562.    {
  563.       partHandlerInfo = fODRegistry->GetPartHandlerInfo( fev, partHandler);
  564.       theEditor = (ISOString) ODNewPtr(MAXSTR);
  565.       string className = partHandlerInfo->GetPartHandlerClassName(fev);
  566.       strcpy(theEditor, className);
  567.  
  568.       SOMFree(partHandler);
  569.       SOMFree(partHandlerInfo);
  570.       SOMFree(className);
  571.  
  572. //      if (theEditor && EditorExists(theEditor))
  573.       if (theEditor)
  574.         return theEditor;
  575.       else
  576.       {
  577.         ODDisposePtr( theEditor );
  578.         theEditor = kODNULL;
  579.       }
  580.    }
  581.  
  582.   // retrieve Category list from Registry
  583.   // this is a buffer that the Registry allocates and we need to dispose of.
  584.   CategoryList = fODRegistry-> GetCategoryList( ev, 0, aKind);
  585.  
  586.   if (CategoryList. _length )
  587.   {
  588.      // search the Category list for  Editiors with matching kind
  589.      for ( i = 0; i < (CategoryList. _length); i++)
  590.      {
  591.          // Check for the preferred editor first
  592.          partHandler = fODRegistry-> GetPreferredPartHandlerForCategory(fev,
  593.                                         CategoryList. _buffer[i]);
  594.          if(partHandler)
  595.          {
  596.             partHandlerInfo = fODRegistry->GetPartHandlerInfo( fev, partHandler);
  597.             theEditor = (ISOString) ODNewPtr(MAXSTR);
  598.             string className = partHandlerInfo->GetPartHandlerClassName(fev);
  599.             strcpy(theEditor, className);
  600.  
  601.             SOMFree(partHandler);
  602.             SOMFree(partHandlerInfo);
  603.             SOMFree(className);
  604.  
  605.             editorFound = (theEditor &&
  606.                  EditorSupportsKind_Reg(theEditor,  aKind, fSession ) );
  607.          }
  608.  
  609.      }
  610.  
  611.      // now free up the buffer we got from the Registry
  612.      for ( i = 0; i < CategoryList. _length; i++)
  613.      {
  614.          SOMFree( CategoryList. _buffer[i]);
  615.      }
  616.      SOMFree( CategoryList. _buffer);
  617.  
  618.      if (editorFound) return theEditor;
  619.      else
  620.      {
  621.        ODDisposePtr( theEditor ); // [120604]
  622.        theEditor = kODNULL;
  623.      }
  624.   }
  625.  
  626.   EditorSet* editorSet = new EditorSet;
  627.   editorSet->InitEditorSet();
  628.  
  629.   // retrieve PartHandler list from Registry
  630.   // this is a buffer that the Registry allocates and we need to dispose of.
  631.   // ODSession* session = thePartSU->GetSession(ev);
  632.   PartHandlerList = fODRegistry-> GetPartHandlerList( ev, aKind, 0);
  633.   if ( PartHandlerList. _length )
  634.   {
  635.      // search the Category list for  Editiors with matching kind
  636.      for ( i = 0; i < ( PartHandlerList. _length); i++)
  637.      {
  638.        editorSet->AddEditor(PartHandlerList. _buffer[i]);
  639.      }
  640.     theEditor = AlphaNumChooseEditor(editorSet);
  641.   }
  642.   else
  643.   {
  644.     ODDisposePtr( theEditor );
  645.     theEditor = kODNULL;
  646.   }
  647.  
  648.   // now free up the buffer we got from the Registry
  649.   for ( i = 0; i < PartHandlerList. _length; i++)
  650.   {
  651.       SOMFree( PartHandlerList. _buffer[i]);
  652.   }
  653.   SOMFree( PartHandlerList. _buffer);
  654.  
  655.  
  656.   ODDeleteObject( editorSet );
  657.   return theEditor;
  658. }
  659.  
  660.   //---------------------------------
  661.   // Editor related utility methods
  662.  
  663. //------------------------------------------------------------------------------
  664. // Binding::EditorExists
  665. //
  666. //   lookup editor in editorkinds namespace and return kODTrue if it exists
  667. //------------------------------------------------------------------------------
  668.  
  669. ODBoolean Binding::EditorExists(ODEditor editor)
  670. {
  671.  
  672. /* defect 22716 - just use Registry
  673.   ODNameSpaceManager *nsm = fSession->GetNameSpaceManager(fev);
  674. */
  675.  
  676.   /*  Try twice to find the editor. If the first search fails, re-synch the
  677.         name-space (by hitting the disk and searching all available "Editors"
  678.         folders) and try again. If the second search fails, give up. --jpa */
  679.  
  680.   /*    ????? This could be slow if we are called many times in a row with
  681.         genuinely nonexistent editors. If this turns out to be a real problem,
  682.         one could keep around the time of last synching, and not synch more than
  683.         once every five seconds. */
  684.  
  685. /* defect 22716 - just use Registry
  686.  
  687.   ODBoolean synched = kODFalse;
  688.   for( ;; ) {
  689.         ODNameSpace* editorkindsNameSpace = fSession->
  690.                 GetNameSpaceManager(fev)->HasNameSpace( fev, kODEditorKinds );
  691.  
  692.         if ( editorkindsNameSpace &&
  693.              editorkindsNameSpace->Exists(fev, (ODISOStr)editor) &&
  694.              this->IsEditorLoaded(editor) )
  695.                 return kODTrue;
  696.  
  697.         if( !synched ) {
  698.                 synched = kODTrue;
  699.                 nsm->SynchNSTable(fev);
  700.                 continue;
  701.         }
  702.         else return kODFalse;
  703.   }
  704. */
  705.   ODPartHandlerInfo* pinfo = kODNULL;
  706.   pinfo = fODRegistry->GetPartHandlerInfo(fev, (ODISOStr)editor);
  707.   if (pinfo)  // the editor is registered
  708.         return kODTrue;
  709.   else
  710.         return kODFalse;
  711.  
  712. }
  713.  
  714. //------------------------------------------------------------------------------
  715. // Binding::IsEditorLoaded
  716. //------------------------------------------------------------------------------
  717. ODBoolean Binding::IsEditorLoaded(ODEditor editor)
  718. {
  719.   return ODClassExists(editor);
  720. }
  721.  
  722. //------------------------------------------------------------------------------
  723. // Binding::GetPreferredEditorForPart
  724. //------------------------------------------------------------------------------
  725. ODEditor Binding::GetPreferredEditorForPart(ODStorageUnit* thePartSU,
  726.                         ODBoolean* noPreferredEditorProp)
  727. {
  728.   // read preferred editor from thePartSU
  729.   ODEditor preferredEditor = kODNULL;
  730.  
  731.   // does the PreferredEditor property exist for this SU?
  732.   if (thePartSU->Exists(fev, kODPropPreferredEditor,kODEditor,0))
  733.   {
  734.     ODULong size;
  735.     preferredEditor = ODGetISOStrProp(fev, thePartSU,
  736.                                         kODPropPreferredEditor,
  737.                                         kODEditor, kODNULL, &size);
  738.     if (preferredEditor)
  739.     {
  740.         if (EditorExists(preferredEditor))
  741.                 *noPreferredEditorProp = kODFalse;
  742.         else
  743.         {
  744.                 ODDisposePtr(preferredEditor);
  745.                 preferredEditor = kODNULL;
  746.         }
  747.     }
  748.   }
  749.   else // no PreferredEditor property for this SU, make one
  750.   {
  751.     ODDraft* draft = thePartSU->GetDraft(fev);
  752.  
  753.     if (draft->GetPermissions(fev) == kODDPExclusiveWrite)
  754.         thePartSU->AddProperty(fev, kODPropPreferredEditor)->
  755.                         AddValue(fev, kODEditor);
  756.  
  757.     *noPreferredEditorProp = kODTrue;
  758.   }
  759.   return preferredEditor;
  760. }
  761.  
  762.  
  763. //------------------------------------------------------------------------------
  764. // Binding::GetKindsSupported
  765. //
  766. //   lookup editor in editorkinds namespace and return kinds supported
  767. //------------------------------------------------------------------------------
  768.  
  769. ODTypeList* Binding::GetKindsSupported(ODEditor editor)
  770. {
  771.   ODTypeList*  kindsList = kODNULL;
  772.  
  773.   // get the editorkinds namespace
  774.   ODObjectNameSpace* editorkindsNameSpace = (ODObjectNameSpace*)fSession->
  775.                 GetNameSpaceManager(fev)->HasNameSpace( fev, kODEditorKinds );
  776.  
  777.   if (editorkindsNameSpace)
  778.   {
  779.     // Lookup the kinds list by editor class ID
  780.     if (editorkindsNameSpace->
  781.         GetEntry( fev, (ODISOStr)editor, (ODObject**)&kindsList ))
  782.                 return kindsList;
  783.   }
  784.  
  785.   return kindsList;
  786. }
  787.  
  788. //------------------------------------------------------------------------------
  789. // Binding::AlphaNumChooseEditor
  790. //------------------------------------------------------------------------------
  791.  
  792. ODEditor Binding::AlphaNumChooseEditor(EditorSet* editorSet)
  793. {
  794.   ODEditor bestEditor = (ODEditor)kODBlackBoxHandlerOfLastResort;
  795.  
  796.   EditorSetIterator* eit = editorSet->CreateIterator();
  797.  
  798.   for (ODEditor editor = eit->First();
  799.     eit->IsNotComplete();
  800.     editor = eit->Next())
  801.   {
  802.     if(!EditorExists(editor))
  803.        continue;
  804.     bestEditor = AlphaNumChooseAnEditorFromTwo(editor,bestEditor);
  805.   }
  806.  
  807.   ODDeleteObject( eit );
  808.   return bestEditor;
  809. }
  810.  
  811. //------------------------------------------------------------------------------
  812. // Binding::AlphaNumChooseAnEditorFromTwo
  813. //------------------------------------------------------------------------------
  814.  
  815. ODEditor Binding::AlphaNumChooseAnEditorFromTwo(ODEditor e1, ODEditor e2)
  816. {
  817.   ODObjectNameSpace*  theViewerNameSpace = ViewerNameSpace();
  818.   ODObject*  ignore;
  819.   ODBoolean e1IsViewer = kODFalse;
  820.   ODBoolean e2IsViewer = kODFalse;
  821.  
  822.   if (theViewerNameSpace)
  823.   {
  824.     // determine if e1 or e2 are viewers (as opposed to editors)
  825.     e1IsViewer = theViewerNameSpace->GetEntry(fev, (ODISOStr)e1, &ignore);
  826.     e2IsViewer = theViewerNameSpace->GetEntry(fev, (ODISOStr)e2, &ignore);
  827.   }
  828.  
  829.   // if e1 is not a viewer and e2 is, use e1
  830.   if (!e1IsViewer && e2IsViewer) return e1;
  831.  
  832.   // if e2 is not a viewer and e1 is, use e2
  833.   if (!e2IsViewer && e1IsViewer) return e2;
  834.  
  835.   // which editor name comes first, alphanumerically?
  836.   if ( strcmp( (char*)e1, (char*)e2 ) >= 0)
  837.     return e1;
  838.   else
  839.     return e2;
  840. }
  841.  
  842. //------------------------------------------------------------------------------
  843. // Binding::DraftRestrictsEditors
  844. //------------------------------------------------------------------------------
  845.  
  846. ODBoolean Binding::DraftRestrictsEditors(ODDraft* draft)
  847. {
  848. ODUnused(draft);
  849.   // return whether or not restrictedEditors property exists
  850.   return kODFalse;
  851. }
  852.  
  853. //------------------------------------------------------------------------------
  854. // Binding::GetAllRestrictedEditorsForKind
  855. //------------------------------------------------------------------------------
  856.  
  857. EditorSet* Binding::GetAllRestrictedEditorsForKind(ODDraft* draft, ODType kind)
  858. {
  859. ODUnused(draft);
  860. ODUnused(kind);
  861.   // read and return restrictedEditors property of draftProperties
  862.   return kODNULL;
  863. }
  864.  
  865.   //---------------------------------
  866.   // Category and kind mappings
  867.  
  868. //------------------------------------------------------------------------------
  869. // Binding::ViewerNameSpace
  870. //------------------------------------------------------------------------------
  871. ODObjectNameSpace*  Binding::ViewerNameSpace()
  872. {
  873.   return (ODObjectNameSpace*)fSession->
  874.                 GetNameSpaceManager(fev)->HasNameSpace( fev, kODViewer );
  875. }
  876.  
  877. ODContainerSuite Binding::GetContainerSuite(ODContainerType containerType)
  878. {
  879.  
  880.  
  881.   /* Two things can happen here. If containerType is the name of an actual
  882.     container suite, we look it up in the ContainerSuite namespace and
  883.     return the classname. But containerType might also be a constant
  884.     indicating a type of default container suite (e.g. kODDefaultFileContainer)
  885.     in which case we have to first look it up in the system-preferred
  886.     ContainerSuite namespace to get the real container suite name, then
  887.     do the lookup as above to get the classname. */
  888.  
  889.   ODContainerSuite   theContainerSuite;
  890.  
  891.   // First look it up in the ContainerSuite namespace:
  892.   theContainerSuite = ValueNameSpaceGetString(fSession,
  893.                                                 kODContainerSuite,
  894.                                                 containerType);
  895.   if( !theContainerSuite ) {
  896.     ODContainerSuite realType;
  897.     ODBoolean isDefault = kODFalse;
  898.     // Not found, look it up in the System-preferred Container Suites namespace:
  899.     realType = ValueNameSpaceGetString(fSession,kODSysPrefContainerSuites,containerType);
  900.     if( !realType ) {
  901.       // Not found there either, check some hardcoded defaults:
  902.       isDefault = kODTrue;
  903.       if( ODISOStrEqual(containerType,kODDefaultMemoryContainer) )
  904.         realType = kODBentoMemoryContainer;
  905.       else if( ODISOStrEqual(containerType,kODDefaultFileContainer) )
  906.         realType = kODBentoFileContainer;
  907.     }
  908.     if( realType ) {
  909.       // Now that we have a real containerType, look it up in ContainerSuite:
  910.       theContainerSuite = ValueNameSpaceGetString(fSession,kODContainerSuite,realType);
  911.       if( !isDefault )
  912.         ODDisposePtr(realType);
  913.     }
  914.   }
  915.   return theContainerSuite;
  916. }
  917.  
  918.  
  919. //------------------------------------------------------------------------------
  920. // Binding::BindingWarning
  921. //------------------------------------------------------------------------------
  922.  
  923. void Binding::BindingWarning()
  924. {
  925.  
  926. #ifdef _PLATFORM_MACINTOSH_
  927.   // [120604] begin changes
  928.   Environment* ev = somGetGlobalEnvironment ();
  929.  
  930.   fSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  931.   ShowAlert(ev, kBindingWarning, GetODButtonKeyFilterProc(), fSession);
  932.   fSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  933.  
  934.   ResetAlertStage();
  935. #endif
  936. }
  937.  
  938. //------------------------------------------------------------------------------
  939. // IsNoPart
  940. //------------------------------------------------------------------------------
  941.  
  942. ODBoolean EXPENTRY  IsNoPart(Environment* ev, ODPart* rootPart)
  943. {
  944.   // ask the PartWrapper what editor it is using
  945.   ODEditor editor = ((ODPartWrapper*)rootPart)->GetEditor(ev);
  946.  
  947.   // get the length of the editor name
  948.   ODUShort length = (ODUShort)ODISOStrLength(editor);
  949.  
  950.   // return true if name == "NoPart", false otherwise
  951.   return
  952.      (ODISOStrNCompare(editor, kODBlackBoxHandlerOfLastResort, length) == 0);
  953. }
  954.  
  955. //------------------------------------------------------------------------------
  956. // GetCurrentEditorForPart
  957. //------------------------------------------------------------------------------
  958. ODEditor EXPENTRY  GetCurrentEditorForPart(ODPart* part )
  959. {
  960.   Environment* fev = somGetGlobalEnvironment();
  961.  
  962.   // call the PartWrapper and ask what editor it is using
  963.   ODEditor theEditor = ((ODPartWrapper*)part)->GetEditor(fev);
  964.  
  965.   // allocate a buffer to hold the editor name and copy the name
  966.   ODUShort length = (ODUShort)ODISOStrLength(theEditor);
  967.   ODEditor partName = (ODEditor)ODNewPtrClear( length+1 );;
  968.   ODBlockMove(theEditor,  partName, length+1 );
  969.  
  970.   return partName;
  971. }
  972.  
  973. //------------------------------------------------------------------------------
  974. // Binding::ChooseEditorForOSType
  975. //------------------------------------------------------------------------------
  976.  
  977. ODEditor Binding::ChooseEditorForOSType(ODStorageUnit* thePartSU )
  978. {
  979.  
  980. // This method chooses an editor for a dropped-in filetype based on
  981. // the fileTypeEA, if it has one which matches a part's filetypeFilter
  982.  
  983.    ODEditor theEditor = kODNULL;
  984.    ODULong size = 0;
  985.    char  fileType[MAXSTR];
  986.  
  987. // Extended Attributes not supported on any platform except OS/2
  988. #ifdef _PLATFORM_OS2_
  989.  
  990.    if(thePartSU->Exists(fev, kODPropContents,kODFileTypeEA,0) )
  991.    {
  992.        thePartSU->Focus(fev, kODPropContents, kODPosUndefined,
  993.                            (ODValueType)kODFileTypeEA, 0, kODPosUndefined);
  994.        size = thePartSU->GetSize(fev);
  995.        if(!size)
  996.           return theEditor;
  997.        StorageUnitGetValue(thePartSU, fev, size, fileType);
  998.  
  999.        if(!strcmp("OpenDoc Document", fileType) )
  1000.           return theEditor;
  1001.  
  1002.        // Check for the preferred editor first
  1003.        ISOString partHandler = NULL;
  1004.        ODPartHandlerInfo* partHandlerInfo;
  1005.        partHandler = fODRegistry-> GetPreferredPartHandlerForFileType(fev,
  1006.                                       fileType);
  1007.        if(partHandler)
  1008.        {
  1009.           partHandlerInfo = fODRegistry->GetPartHandlerInfo( fev, partHandler);
  1010.           theEditor = (ISOString) ODNewPtr(256);
  1011.           string className = partHandlerInfo->GetPartHandlerClassName(fev);
  1012.           strcpy(theEditor, className);
  1013.  
  1014.           SOMFree(partHandler);
  1015.           SOMFree(partHandlerInfo);
  1016.           SOMFree(className);
  1017.  
  1018.           return theEditor;
  1019.  
  1020.        }
  1021.     }
  1022. #endif  // _PLATFORM_OS2_
  1023.  
  1024.     return theEditor;
  1025. }
  1026. //------------------------------------------------------------------------------
  1027. // Binding::ChooseEditorForOSfilenameFilter
  1028. //------------------------------------------------------------------------------
  1029.  
  1030. ODEditor Binding::ChooseEditorForOSfilenameFilter(ODStorageUnit* thePartSU )
  1031. {
  1032.  
  1033. // This method chooses an editor for a dropped-in filetype based
  1034. // on the fileExtension, if it has one which matches a part's filetypeFilter
  1035.  
  1036.    ODEditor theEditor = kODNULL;
  1037.    ODULong size = 0;
  1038.    char  fileName[MAXSTR];
  1039.    int found = kODFalse;
  1040.  
  1041.     if(thePartSU->Exists(fev, kODPropContents,kODFileType,0) )
  1042.     {
  1043.         thePartSU->Focus(fev, kODPropContents, kODPosUndefined,
  1044.                                   kODFileType,  0, kODPosUndefined);
  1045.         size = thePartSU->GetSize(fev);
  1046.         if(!size || size > MAXSTR) return theEditor;
  1047.  
  1048.         StorageUnitGetValue(thePartSU, fev, size, fileName);
  1049.         char * b = fileName;
  1050.         char * searchPointer = strchr(fileName, '\0');
  1051.         while(searchPointer >= b)
  1052.         {
  1053.                 if(*searchPointer == '.')
  1054.                 {
  1055.                    found = kODTrue;
  1056.                    break;
  1057.                 }
  1058.                 searchPointer--;
  1059.         }
  1060.  
  1061.         if(!found) return theEditor;
  1062.  
  1063.        char *  searchString = (char *)ODNewPtrClear(strlen(searchPointer)+1, 0);
  1064.        strcpy(searchString, "*");
  1065.        strcat(searchString, searchPointer);
  1066.  
  1067.        // Check for the preferred editor first
  1068.        ISOString partHandler = NULL;
  1069.        ODPartHandlerInfo* partHandlerInfo;
  1070.        partHandler = fODRegistry-> GetPreferredPartHandlerForFileExt(fev,
  1071.                                       searchString);
  1072.        if(partHandler)
  1073.        {
  1074.           partHandlerInfo = fODRegistry->GetPartHandlerInfo( fev, partHandler);
  1075.           theEditor = (ISOString) ODNewPtr(MAXSTR);
  1076.           string className = partHandlerInfo->GetPartHandlerClassName(fev);
  1077.           strcpy(theEditor, className);
  1078.  
  1079.           SOMFree(partHandler);
  1080.           SOMFree(partHandlerInfo);
  1081.           SOMFree(className);
  1082.  
  1083.           return theEditor;
  1084.        }
  1085.     }
  1086.  
  1087.     return theEditor;
  1088. }
  1089.