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

  1. /* @(#) 1.19 com/src/utils/BndNSUtl.cpp, odconfig, od96os2, odos29712d 12/17/96 13:54:27 [3/21/97 17:20:50] */
  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:           BndNSUtl.cp
  31.  
  32.         Contains:       Binding utilities for EditorSetup.
  33.  
  34.         Owned by:       Caia Grisar
  35.  
  36.         Copyright:      ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  37.  
  38.  
  39. */
  40.  
  41. #ifndef _BNDNSUTL_
  42. #include "BndNSUtl.h"
  43. #endif
  44.  
  45. #ifndef _EDITRSET_
  46. #include "EditrSet.h"
  47. #endif
  48.  
  49. #ifndef _ODDEBUG_
  50. #include "ODDebug.h"
  51. #endif
  52.  
  53. #ifndef _ODMEMORY_
  54. #include "ODMemory.h"
  55. #endif
  56.  
  57. #ifndef SOM_ODValueNameSpace_xh
  58. #include "ValueNS.xh"
  59. #endif
  60.  
  61. #ifndef SOM_ODObjectNameSpace_xh
  62. #include "ObjectNS.xh"
  63. #endif
  64.  
  65. #ifndef _STORAGEU_
  66. #include "StorageU.xh"
  67. #endif
  68.  
  69. #ifndef _STDDEFS_
  70. #include "StdDefs.xh"
  71. #endif
  72.  
  73. #ifndef _STDPROPS_
  74. #include "StdProps.xh"
  75. #endif
  76.  
  77. #ifndef _STDTYPES_
  78. #include "StdTypes.xh"
  79. #endif
  80.  
  81. #ifndef _PART_
  82. #include "Part.xh"
  83. #endif
  84.  
  85. #ifndef SOM_ODValueIterator_xh
  86. #include <ValueItr.xh>
  87. #endif
  88.  
  89. #ifndef SOM_ODObjectIterator_xh
  90. #include <ObjctItr.xh>
  91. #endif
  92.  
  93. #ifndef _ISOSTR_
  94. #include "ISOStr.h"
  95. #endif
  96.  
  97. #ifndef SOM_ODStorageUnitView_xh
  98. #include <SUView.xh>
  99. #endif
  100.  
  101. #ifndef _EXCEPT_
  102. #include "Except.h"
  103. #endif
  104.  
  105. #ifndef _ODUTILS_
  106. #include <ODUtils.h>
  107. #endif
  108.  
  109. #ifndef SOM_ODNameSpaceManager_xh
  110. #include <NmSpcMg.xh>
  111. #endif
  112.  
  113. #ifndef SOM_ODTypeList_xh
  114. #include <TypeList.xh>
  115. #endif
  116.  
  117. #ifndef _STORUTIL_
  118. #include <StorUtil.h>
  119. #endif
  120.  
  121. #ifndef _NMSPCUTL_
  122. #include <NmSpcUtl.h>
  123. #endif
  124.  
  125. #ifndef _UTILERRS_
  126. #include <UtilErrs.h>
  127. #endif
  128.  
  129. #ifndef SOM_ODTypeListIterator_xh
  130. #include <TypLsItr.xh>
  131. #endif
  132.  
  133. #include <somcls.xh>
  134. #include <somcm.xh>
  135.  
  136. #if defined(_PLATFORM_WIN32_)
  137. #include <mapiwin.h>
  138. #include <wtypes.h>
  139. #include <winbase.h>
  140. #endif // defined(_PLATFORM_WIN32_)
  141.  
  142.  
  143. //phase1 - add following includes for additional InfoUtil functions
  144. #ifndef SOM_ODSession_xh
  145. #include <ODSessn.xh>
  146. #endif
  147.  
  148. #ifndef _STDTYPIO_
  149. #include "StdTypIO.h"
  150. #endif
  151.  
  152. #ifndef __STRING__
  153. #include <string.h>
  154. #endif
  155.  
  156. #ifndef SOM_ODTranslation_xh
  157. #include <Translt.xh>
  158. #endif
  159.  
  160. #ifndef SOM_ODWindowIterator_xh
  161. #include <WinIter.xh>
  162. #endif
  163.  
  164. #ifndef _UTILDEFS_
  165. #include "UtilDefs.h"
  166. #endif
  167.  
  168. #ifndef _TEMPOBJ_
  169. #include <TempObj.h>
  170. #endif
  171.  
  172. #ifndef SOM_ODPart_xh
  173. #include <Part.xh>
  174. #endif
  175.  
  176. #ifndef SOM_ODBinding_xh
  177. #include <ODBindng.xh>
  178. #endif
  179.  
  180. #ifndef _PASCLSTR_
  181. #include "PasclStr.h"
  182. #endif
  183.  
  184. #ifndef _PLFMFILE_
  185. #include <PlfmFile.h>
  186. #endif
  187.  
  188. #ifndef _ITEXT_
  189. #include <IText.h>
  190. #endif
  191.  
  192. #ifndef _ODPARTWRAPPER_
  193. #include <PartWrap.xh>
  194. #endif
  195.  
  196. #ifndef _ODPRTREG_
  197. #include <ODPrtReg.xh>
  198. #endif
  199.  
  200. #ifndef _ODPRTREI_
  201. #include <ODPrtRei.xh>
  202. #endif
  203.  
  204. #ifndef SOM_ODFrameFacetIterator_xh
  205. #include <FrFaItr.xh>
  206. #endif
  207.  
  208. #ifndef SOM_ODFrame_xh
  209. #include <Frame.xh>
  210. #endif
  211.  
  212. #ifdef _PLATFORM_OS2_
  213. #include <MMIO.H>
  214. #endif
  215.  
  216.  
  217. //==============================================================================
  218. // Constants
  219. //==============================================================================
  220. const ODPlatformType kODFileType_hfs = (ODPlatformType) 0x68667320;     // 'hfs '
  221.  
  222. //==============================================================================
  223. // Static Function declarations
  224. //==============================================================================
  225.  
  226. ODTime  ODGetDateProperty(Environment* ev, ODStorageUnit* su,
  227.                         ODPropertyName prop);
  228.  
  229. void    ODSetDateProperty(Environment* ev, ODStorageUnit* su,
  230.                           ODPropertyName prop, ODTime dateTime)
  231.  
  232. {       ODSetTime_TProp(ev, su, prop, kODTime_T, dateTime);}
  233.  
  234. //------------------------------------------------------------------------------
  235. // SetCategory
  236. //------------------------------------------------------------------------------
  237.  
  238. void SetCategory(ODEditor editorID, ODType  kindID,
  239.                           HWND  categoryItem, ODSession* session)
  240. {
  241.  
  242.     ODPartHandlerRegistryInt* ODRegistry;
  243.     _IDL_SEQUENCE_string CategoryList;
  244.  
  245.       ODName*         name;
  246.       ODPtr   strHandle = 0;
  247.       ODSShort i = 0;
  248.  
  249.       Environment* ev = somGetGlobalEnvironment();
  250.       ODRegistry = session -> GetRegistry(ev);
  251.  
  252.  
  253.       // retrieve Category list from Registry
  254.       // this is a buffer that the Registry allocates and we need to dispose of.
  255.       CategoryList = ODRegistry-> GetCategoryList( ev, editorID, kindID);
  256.  
  257.  
  258.       if (CategoryList. _length )
  259.       {
  260.            // Copy the Category name to dialog box and select it
  261.             i = 0;
  262. #if defined(_PLATFORM_WIN32_)
  263.           SendMessage(categoryItem, LB_ADDSTRING, 0, (LPARAM)CategoryList. _buffer[i]);
  264.           SendMessage(categoryItem, LB_SETCURSEL, (WPARAM)0, 0);
  265. #elif defined(_PLATFORM_OS2_)
  266.           WinSendMsg(categoryItem,  LM_INSERTITEM, MPFROMSHORT(LIT_END),
  267.             MPFROMP(CategoryList. _buffer[i]));
  268.           WinSendMsg(categoryItem,  LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
  269. #elif defined(_PLATFORM_UNIX_)
  270.          // need display call for aix implementation
  271. #endif
  272.  
  273.       }
  274.  
  275.       // now free up the buffer we got from the Registry
  276.       for ( i = 0; i < CategoryList. _length; i++)
  277.       {
  278.           SOMFree( CategoryList. _buffer[i]);
  279.       }
  280.       SOMFree( CategoryList. _buffer);
  281.  
  282. }
  283.  
  284. //------------------------------------------------------------------------------
  285. // GetUserKindFromKind
  286. //------------------------------------------------------------------------------
  287. ODBoolean GetUserKindFromKind( ODNameSpaceManager* theNmSpcMgr,
  288.                                                                         ODType kind, ODName** name )
  289. {
  290.         ODBoolean       result  = kODFalse ;
  291.  
  292.     Environment* ev = somGetGlobalEnvironment();
  293.  
  294.                 // look it up in the spaceName namespace
  295.         ODValueNameSpace* userStringNameSpace =
  296.                 (ODValueNameSpace*)theNmSpcMgr->HasNameSpace( ev, kODKindUserString );
  297.  
  298.         if (userStringNameSpace)
  299.                 result = ValueNameSpaceGetODName(userStringNameSpace, ev, kind, name );
  300.         return result ;
  301. }
  302.  
  303.  
  304. //------------------------------------------------------------------------------
  305. // GetUserEditorFromEditor
  306. //------------------------------------------------------------------------------
  307. ODBoolean GetUserEditorFromEditor( ODNameSpaceManager* theNmSpcMgr,
  308.                                                                         ODEditor editor, ODName** name )
  309. {
  310.         ODBoolean       result  = kODFalse ;
  311.  
  312.     Environment* ev = somGetGlobalEnvironment();
  313.  
  314.                 // look it up in the spaceName namespace
  315.         ODValueNameSpace* userStringNameSpace =
  316.                 (ODValueNameSpace*)theNmSpcMgr->HasNameSpace( ev, kODEditorUserString );
  317.  
  318.         if (userStringNameSpace)
  319.                 result = ValueNameSpaceGetODName(userStringNameSpace, ev, editor, name );
  320.         return result ;
  321. }
  322.  
  323. //------------------------------------------------------------------------------
  324. // GetCurrentEditorForPart
  325. //------------------------------------------------------------------------------
  326. ODEditor EXPENTRY  GetCurrentEditorForPart(ODPart* part )
  327. {
  328.   Environment* fev = somGetGlobalEnvironment();
  329.  
  330.   // call the PartWrapper and ask what editor it is using
  331.   ODEditor theEditor = ((ODPartWrapper*)part)->GetEditor(fev);
  332.  
  333.   // allocate a buffer to hold the editor name and copy the name
  334.   ODUShort length = (ODUShort)ODISOStrLength(theEditor);
  335.   ODEditor partName = (ODEditor)ODNewPtrClear( length+1 );;
  336.   ODBlockMove(theEditor,  partName, length+1 );
  337.  
  338.   return partName;
  339. }
  340.  
  341.  
  342. //------------------------------------------------------------------------------
  343. // ChangeEditor
  344. //------------------------------------------------------------------------------
  345.  
  346. void ChangeEditor(ODPart* part, ODEditor editorID)
  347. {
  348.         Environment* ev = somGetGlobalEnvironment();
  349.         ((ODPartWrapper*)part)->UseEditor(ev, editorID);
  350.  
  351.         // Need to acquire storage unit before using it. Put it in
  352.         // temp object so that the storage unit is released when
  353.         // the temp object is out of scope.
  354.         TempODStorageUnit thePartSU = part->GetStorageUnit(ev);
  355.         thePartSU->Acquire(ev);
  356.         if (thePartSU->Exists(ev, kODPropPreferredEditor, kODEditor, 0 ))
  357.                 thePartSU->Focus(ev, kODPropPreferredEditor,kODPosSame,kODEditor,0,kODPosSame);
  358.         else
  359.         {
  360.                 thePartSU->AddProperty(ev, kODPropPreferredEditor );
  361.                 thePartSU->AddValue( ev, kODEditor );
  362.         }
  363.         StorageUnitSetValue(thePartSU, ev, ODISOStrLength((const ODISOStr)editorID)+1,(ODValue)editorID);
  364.  
  365. }
  366.  
  367.  
  368. //------------------------------------------------------------------------------
  369. // EditorSupportsKind
  370. //------------------------------------------------------------------------------
  371. ODBoolean EditorSupportsKind( ODNameSpaceManager* theNmSpcMgr,
  372.                               ODEditor editor, ODType kind )
  373. {
  374.     ODTypeList*     kindsList = kODNULL;
  375.     Environment* ev = somGetGlobalEnvironment();
  376.  
  377.                 // get the editorkinds namespace
  378.         ODObjectNameSpace* editorkindsNameSpace =
  379.                 (ODObjectNameSpace*)theNmSpcMgr->HasNameSpace( ev, kODEditorKinds );
  380.  
  381.         if (editorkindsNameSpace)
  382.         {
  383.                         // Lookup the kinds list by editor class ID
  384.                 if (!editorkindsNameSpace->GetEntry( ev, (ODISOStr)editor,
  385.                                                                         (ODObject**)&kindsList ))
  386.                         kindsList = (ODTypeList*)kODNULL;
  387.         }
  388.  
  389.         return (kindsList && kindsList->Contains(ev, kind));
  390. }
  391.  
  392. //------------------------------------------------------------------------------
  393. // EditorSupportsKind_Reg
  394. //------------------------------------------------------------------------------
  395. ODBoolean EditorSupportsKind_Reg( ODEditor editor, ODType kind,
  396.                       ODSession* session)
  397. {
  398.         ODTypeList*     kindsList = kODNULL;
  399.        _IDL_SEQUENCE_ISOString PartKindList;
  400.         ODSShort  kind_found = FALSE;
  401.         Environment*            ev = somGetGlobalEnvironment();
  402.         ODPartHandlerRegistryInt* ODRegistry;
  403.         ODSShort                i;
  404.  
  405.         // retrieve PartKind list from Registry
  406.         // this is a buffer that the Registry allocates and we need to dispose of.
  407.         ODRegistry = session -> GetRegistry(ev);
  408.         PartKindList = ODRegistry-> GetPartKindList( ev, editor, 0);
  409.  
  410.  
  411.         // search the PartKind list for matching kind
  412.         for ( i = 0; i < PartKindList. _length; i++)
  413.         {
  414.  
  415.            if (strcmp(PartKindList. _buffer[i],kind) == 0 )
  416.            {
  417.               // set unique to false if duplicate editor exists in string array
  418.               kind_found = TRUE;
  419.            }
  420.         }
  421.  
  422.         return (kind_found);
  423. }
  424.  
  425. //------------------------------------------------------------------------------
  426. // ReadSize
  427. //------------------------------------------------------------------------------
  428.  
  429. ODULong  ReadSize(ODFileRefNum file, ODStorageUnitView* view)
  430. {
  431.         ODULong data;
  432.         ODSLong length = sizeof(data);
  433.         ODSLong savedLength = length;
  434.         Environment* ev = somGetGlobalEnvironment ();
  435.  
  436.         if (view)  // if a prefocused storage unit is passed in
  437.                 length = StorageUnitViewGetValue(view, ev, length, &data);
  438.         else { // a file ref has been passed in
  439.  
  440. #ifdef _PLATFORM_MACINTOSH_
  441.                 THROW_IF_ERROR(FSRead(file, &length, (long *)&data));
  442. #endif
  443.  
  444. #ifdef _PLATFORM_WIN32_
  445.         DWORD bytesRead;
  446.         BOOL successful;
  447.         successful = ReadFile(file, &data, length, &bytesRead, NULL);
  448.         if (!successful)
  449.                 THROW (GetLastError());
  450.         length = bytesRead;
  451. #endif  // defined _PLATFORM_WIN32_
  452.  
  453.         }
  454.         if (savedLength != length)
  455.                 THROW(kODErrReadErr);
  456.  
  457.         return data;
  458. }
  459.  
  460. //------------------------------------------------------------------------------
  461. // ReadBytes
  462. //------------------------------------------------------------------------------
  463.  
  464. void ReadBytes(ODFileRefNum file, ODStorageUnitView* view,
  465.                ODPtr bytes, ODULong* length)
  466. {
  467.         ODSLong savedLength = *length;
  468.         Environment* ev = somGetGlobalEnvironment ();
  469.  
  470.         if (view) // if a prefocused storage unit is passed in
  471.                 *length = StorageUnitViewGetValue(view, ev, *length, bytes);
  472.         else { // a file ref has been passed in
  473.  
  474. #ifdef _PLATFORM_MACINTOSH_
  475.                 THROW_IF_ERROR(FSRead(file, (long *)length, bytes));
  476. #endif
  477.  
  478. #ifdef _PLATFORM_WIN32_
  479.         DWORD bytesRead;
  480.         BOOL successful;
  481.         successful = ReadFile(file, bytes, *length, &bytesRead, NULL);
  482.         if (!successful)
  483.                 THROW (GetLastError());
  484.         *length = bytesRead;
  485. #endif // defined(_PLATFORM_WIN32_)
  486.  
  487.         }
  488.         if (savedLength != (ODSLong)*length)
  489.                 THROW(kODErrReadErr);
  490. }
  491.  
  492.  
  493. //------------------------------------------------------------------------------
  494. // ODGetEditorSetFromResFile
  495. //------------------------------------------------------------------------------
  496.  
  497. EditorSet* ODGetEditorSetFromResFile(ODSShort resRefNum)
  498. {
  499.         EditorSet*      theEditorSet = kODNULL;
  500.         ODBoolean       editorFound = kODFalse;
  501.  
  502.         return theEditorSet;
  503. }
  504.  
  505.  
  506. //------------------------------------------------------------------------------
  507. // add following dunctions from the defunct InfoUtil.cpp file
  508. // ODSetPOName        ODGetCategory      ODGetKindFromPartSU
  509. // ODGetCreationDate  ContentValueTypes  GetThisKindFromList
  510. // ODGetCatFromKind   ODGetDateProperty  ODGetCatFromPartSU
  511. // ODGetSUFromPstObj
  512. //------------------------------------------------------------------------------
  513. //------------------------------------------------------------------------------
  514. // ODSetPOName
  515. //------------------------------------------------------------------------------
  516. void            ODSetPOName(Environment* ev, ODPersistentObject* pstobj,ODIText* name)
  517. {
  518. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_OS2_)
  519.         ODSetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, 
  520.                        kODPlatformIText, name);
  521. #elif (defined _PLATFORM_MACINTOSH_)
  522.         ODSetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, 
  523.                        kODMacIText, name);
  524. #endif
  525. }
  526.  
  527. //------------------------------------------------------------------------------
  528. // ODGetKindFromPartSU
  529. //------------------------------------------------------------------------------
  530. ODType  ODGetKindFromPartSU(Environment* ev, ODStorageUnit* su)
  531. {
  532.    ODULong unused;
  533.    ODType kind = ODGetISOStrProp(ev, su, kODPropPreferredKind, kODISOStr, kODNULL, &unused);
  534.    if ( kind == kODNULL )
  535.       if ( su->Exists(ev, kODPropContents, (ODValueType) kODNULL,1) )
  536.       {
  537.           su->Focus(ev, kODPropContents, kODPosSame, (ODValueType) kODNULL,1, kODPosSame);
  538.           kind = su->GetType(ev);
  539.  
  540.           ODTranslation* translation = su->GetSession(ev)->GetTranslation(ev);
  541.           TempODType hfsType =
  542.                   translation->GetISOTypeFromPlatformType(ev, kODFileType_hfs, kODPlatformDataType);
  543.  
  544.           if ( ODISOStrEqual(kind, hfsType) )
  545.           {
  546.               ODDisposePtr(kind);
  547.               kind = kODNULL;
  548.               if ( su->Exists(ev, kODPropContents, (ODValueType) kODNULL,2) )
  549.               {
  550.                   su->Focus(ev, kODPropContents, kODPosSame, (ODValueType) kODNULL,2, kODPosSame);
  551.                   kind = su->GetType(ev);
  552.               }
  553.           }
  554.       }
  555.    return kind;
  556. }
  557.  
  558. //------------------------------------------------------------------------------
  559. // ODGetCreationDate
  560. //------------------------------------------------------------------------------
  561. ODULong ODGetCreationDate(Environment* ev,
  562.                                 ODStorageUnit* su)
  563. {       return ODGetDateProperty(ev, su, kODPropCreateDate);}
  564.  
  565. //------------------------------------------------------------------------------
  566. // ContentValueTypes
  567. //------------------------------------------------------------------------------
  568. void ContentValueTypes(ODStorageUnit* contentSU, ODTypeList* typeList)
  569. {
  570.     TempODType hfsType = kODNULL;
  571.  
  572.     TRY
  573.         ODULong         count;
  574.         ODULong         index;
  575.  
  576.         Environment* ev = somGetGlobalEnvironment();
  577.  
  578.         ODTranslation* translation = contentSU->GetSession(ev)->GetTranslation(ev);
  579.         hfsType = translation->GetISOTypeFromPlatformType(ev, kODFileType_hfs, kODPlatformDataType);
  580.  
  581.         contentSU->Focus(ev, kODPropContents, kODPosUndefined, 0, 0, kODPosUndefined);
  582.         count = contentSU->CountValues(ev);
  583.         for (index = 1; index <= count; ++index)
  584.         {
  585.             contentSU->Focus(ev, kODPropContents, kODPosUndefined, 0, index, kODPosUndefined);
  586.             TempODType type = contentSU->GetType(ev);
  587.             if ( !ODISOStrEqual(type, hfsType) )
  588.                     typeList->AddLast(ev, type);
  589.         }
  590.     CATCH_ALL
  591.     ENDTRY
  592. }
  593.  
  594. //------------------------------------------------------------------------------
  595. // GetThisKindFromList
  596. //------------------------------------------------------------------------------
  597. ODType GetThisKindFromList(ODSShort kindItem, ODTypeList* kindList)
  598. {
  599.         Environment* ev = somGetGlobalEnvironment();
  600.         ODType type = kODNULL;
  601.         ODTypeListIterator* kindIter = kindList->CreateTypeListIterator(ev);
  602.  
  603.         for ( type = kindIter->First(ev);
  604.                   (--kindItem > 0) && kindIter->IsNotComplete(ev);
  605.                   type = kindIter->Next(ev) )
  606.         {
  607.                 ODDisposePtr(type);
  608.                 type = kODNULL;
  609.         }
  610.  
  611.         ODDeleteObject(kindIter);
  612.  
  613.         return type;
  614. }
  615.  
  616. //------------------------------------------------------------------------------
  617. // ODGetCatFromPartSU
  618. //------------------------------------------------------------------------------
  619. ODName* ODGetCatFromPartSU(Environment* ev, ODStorageUnit* su, ODNameSpaceManager* nsm)
  620. {
  621.  
  622.    ODSShort      i;
  623.    _IDL_SEQUENCE_string CategoryList;
  624.    ODPartHandlerRegistryInt* ODRegistry;
  625.    ODName* category = kODNULL;
  626.  
  627.        ODType kindID = ODGetKindFromPartSU(ev, su);
  628.        ODSession* session = su->GetSession(ev);
  629.        ODRegistry = session -> GetRegistry(ev);
  630.  
  631.  
  632.        // retrieve Category list from Registry
  633.        // this is a buffer that the Registry allocates and we need to dispose of.
  634.  
  635.        CategoryList = ODRegistry-> GetCategoryList( ev, 0, kindID);
  636.  
  637.        if (CategoryList. _length )
  638.        {
  639.           i = 0;
  640.           // Set default Category type when NO part name was supplied by part
  641.  
  642.           category=StrToIntl((PSZ)CategoryList. _buffer[i], kODNULL);
  643.  
  644.           // now free up the buffer we got from the Registry
  645.           for ( i = 0; i < CategoryList. _length; i++)
  646.           {
  647.               SOMFree( CategoryList. _buffer[i]);
  648.           }
  649.           SOMFree( CategoryList. _buffer);
  650.  
  651.        }
  652.  
  653.        ODDisposePtr( kindID );
  654.  
  655.        return category;
  656. }
  657.  
  658. //------------------------------------------------------------------------------
  659. // ODGetSUFromPstObj
  660. //------------------------------------------------------------------------------
  661. ODStorageUnit* ODGetSUFromPstObj(Environment* ev, ODPersistentObject* pstobj)
  662. {
  663.         return pstobj->GetStorageUnit(ev);
  664. }
  665.  
  666. //------------------------------------------------------------------------------
  667. // ODGetDateProperty - static declaration above
  668. //------------------------------------------------------------------------------
  669. ODTime  ODGetDateProperty(Environment* ev,
  670.                         ODStorageUnit* su,
  671.                         ODPropertyName prop)
  672. {       return ODGetTime_TProp(ev, su, prop, kODTime_T);}
  673.  
  674. //--------------------------------------------------------------------
  675. //  IntlToStr
  676. //--------------------------------------------------------------------
  677.  
  678. PSZ IntlToStr(ODIText* intlText, PSZ pstr)
  679. {
  680.  
  681.  
  682.         if (pstr == NULL) return pstr;
  683.  
  684.         if (intlText == kODNULL) {
  685.            *pstr = '\0';
  686.             return pstr;
  687.            }
  688.  
  689.         PSZ   tmp = GetCStringFromIText(intlText);
  690.  
  691.         if (strlen(tmp) == 0)
  692.            *pstr = '\0';
  693.         else {
  694.            strcpy(pstr, tmp);
  695.            }
  696.  
  697.         return pstr;
  698.         }
  699.  
  700. //--------------------------------------------------------------------
  701. // StrToIntl
  702. //--------------------------------------------------------------------
  703. ODIText* StrToIntl(PSZ pstr, ODIText** intlText)
  704. {
  705.  
  706.         ODIText* result = kODNULL;
  707.  
  708.         if ( intlText )
  709.            result = *intlText ;
  710.  
  711.         if ( !result )
  712.            {
  713.            result = CreateIText(0, 0, pstr);
  714.            }
  715.         else
  716.            {
  717.            SetITextScriptCode(result, 0);
  718.            SetITextLangCode(result, 0);
  719.            SetITextString(result, pstr);
  720.            }
  721.  
  722.         if ( intlText )
  723.            *intlText = result ;
  724.  
  725.         return result;
  726. }
  727.  
  728. ODULong ODGetModificationDate(Environment* ev,
  729.                                 ODStorageUnit* su)
  730. {       return ODGetDateProperty(ev, su, kODPropModDate);}
  731.  
  732. void    ODSetModificationDate(Environment* ev,
  733.                                 ODStorageUnit* su,
  734.                                 ODTime dateTime)
  735. {       ODSetDateProperty(ev, su, kODPropModDate, dateTime);}
  736.  
  737. ODIText*        ODGetPOName(Environment* ev, ODPersistentObject* pstobj,ODIText* name)
  738. {
  739. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_OS2_)
  740.         return ODGetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, 
  741.                               kODPlatformIText,name);
  742. #elif (defined _PLATFORM_MACINTOSH_)
  743.         return ODGetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, 
  744.                               kODMacIText,name);
  745. #endif
  746. }
  747.  
  748.  
  749. void            ODSetPONameUsingSU(Environment* ev, ODStorageUnit* su, ODIText* name)
  750. {
  751. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_OS2_)
  752.         ODSetITextProp(ev, su, kODPropName, kODPlatformIText, name);
  753. #elif (defined _PLATFORM_MACINTOSH_)
  754.         ODSetITextProp(ev, su, kODPropName, kODMacIText, name);
  755. #endif
  756. }
  757.  
  758. ODIText*        ODGetModifiedBy(Environment* ev,
  759.                                 ODStorageUnit* su, ODIText* userName)
  760. {
  761. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_OS2_)
  762.         return ODGetITextProp(ev, su, kODPropModUser, kODPlatformIText, 
  763.                               userName);
  764. #elif (defined _PLATFORM_MACINTOSH_)
  765.         return ODGetITextProp(ev, su, kODPropModUser, kODMacIText, userName);
  766. #endif
  767. }
  768.  
  769. void            ODSetModifiedBy(Environment* ev,
  770.                                 ODStorageUnit* su, ODIText* userName)
  771. {
  772. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_OS2_)
  773.         ODSetITextProp(ev, su, kODPropModUser, kODPlatformIText, userName);
  774. #elif (defined _PLATFORM_MACINTOSH_)
  775.         ODSetITextProp(ev, su, kODPropModUser, kODMacIText, userName);
  776. #endif
  777. }
  778.  
  779. ODIText*
  780. ODGetPOComments(Environment* ev, ODPart *part, ODIText* comments)
  781. {
  782.         ODStorageUnit*  su = ODGetSUFromPstObj(ev, part);
  783.         ODIText*                propComments;
  784.  
  785. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_OS2_)
  786.         propComments = ODGetITextProp(ev, su, kODPropComments, kODPlatformIText,
  787.                                       comments);
  788. #elif (defined _PLATFORM_MACINTOSH_)
  789.         propComments = ODGetITextProp(ev, su, kODPropComments, kODMacIText,
  790.                                       comments);
  791. #endif
  792.         return propComments;
  793. }
  794.  
  795. void    ODSetPOComments(Environment* ev, ODPart *part, ODIText* comments)
  796. {
  797.         ODStorageUnit*  su = ODGetSUFromPstObj(ev, part);
  798.  
  799. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_OS2_)
  800.         ODSetITextProp(ev, su, kODPropComments, kODPlatformIText, comments);
  801. #elif (defined _PLATFORM_MACINTOSH_)
  802.         ODSetITextProp(ev, su, kODPropComments, kODMacIText, comments);
  803. #endif
  804. }
  805.  
  806. //--------------------------------------------------------------------
  807. // ODGetIsStationery
  808. //--------------------------------------------------------------------
  809.  
  810. ODBoolean       ODGetIsStationery(Environment* ev,
  811.                                 ODFrame* frame)
  812. {
  813. //  ODBoolean    isStationery;
  814. //  TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  815. //  if (usersFile)
  816. //          isStationery = usersFile->IsStationery();
  817.  
  818.     TempODPart              part = frame->AcquirePart(ev);
  819.     TempODFrame  containingFrame = frame->AcquireContainingFrame(ev);
  820.     ODBoolean         isRootPart = ( containingFrame == kODNULL );
  821.     TempODStorageUnit         su = part->GetStorageUnit(ev);
  822.     ODBoolean stationeryExist = kODFalse;
  823.  
  824.     // Need to acquire storage unit before using it
  825.     su->Acquire(ev);
  826.  
  827.     if (isRootPart)
  828.     {
  829.  
  830.        // kODPropIsStationery is a property to tell whether
  831.        // this is a stationery or not.
  832.        // Check whether this property exists or not. If this
  833.        // property exists, get the value.
  834.        stationeryExist = (ODSUExistsThenFocus(ev, su,
  835.                                            kODPropIsStationery,
  836.                                            kODBoolean));
  837.  
  838.        if (stationeryExist)
  839.            StorageUnitGetValue(su, ev, sizeof(ODBoolean),
  840.                                            (ODValue)&stationeryExist);
  841.  
  842.  
  843.     }
  844.  
  845.     return stationeryExist;
  846.  
  847. }
  848.  
  849. //--------------------------------------------------------------------
  850. // ODSetIsStationery
  851. //--------------------------------------------------------------------
  852.  
  853. void            ODSetIsStationery(Environment* ev,
  854.                                   ODFrame* frame,
  855.                                   ODBoolean isStationery)
  856. {
  857. //      { TempODPart part = frame->AcquirePart(ev);
  858. //        ODSetBooleanProp( ev, ODGetSUFromPstObj(ev, part),
  859. //                          kODPropIsStationery, kODBoolean, isStationery);
  860. //      }
  861. //      TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  862. //      if (usersFile)
  863. //              usersFile->SetStationery(isStationery);
  864.     TempODPart              part = frame->AcquirePart(ev);
  865.     TempODFrame  containingFrame = frame->AcquireContainingFrame(ev);
  866.     ODBoolean         isRootPart = ( containingFrame == kODNULL );
  867.  
  868.  
  869.     if (isRootPart)
  870.     {
  871.  
  872.     // Set kODPropIsStationery property to signal that this file
  873.     // is a stationery
  874.         TempODStorageUnit    su = part->GetStorageUnit(ev);
  875.         su->Acquire(ev);
  876.         ODSetBooleanProp(ev, su, kODPropIsStationery, kODBoolean, isStationery);
  877.     }
  878.  
  879. }
  880.  
  881. ODType  ODGetKind(Environment* ev, ODPart* part)
  882. {
  883.         return ODGetKindFromPartSU(ev, ODGetSUFromPstObj(ev, part));
  884. }
  885.  
  886. ODULong ODGetPOSize(Environment* ev, ODPersistentObject* pstobj)
  887. {
  888.         ODStorageUnit* su = ODGetSUFromPstObj(ev, pstobj);
  889.         su->Focus(ev, kODNULL, kODPosAll, kODNULL,0, kODPosAll);
  890.         return su->GetSize(ev);
  891. }
  892.  
  893.