home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Utilities / StdIFmIO.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  5.2 KB  |  215 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StdIFmIO.cpp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>    .04.1996    NP        Change to allow ObjectMaster to parse. No
  13.                                     code changes.
  14.  
  15.     To Do:
  16. */
  17.  
  18. /*
  19.     File:        StdIFmIO.cpp
  20.  
  21.     Contains:    functions for read/writing standard IconFamily from/to storage units.
  22.                 This file is Macintosh-specific.
  23.  
  24.     Owned by:    Tantek Çelik, Jens Alfke
  25.  
  26.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  27.  
  28.     To Do:
  29.         1. Ensure that usage of functions to write substreams works (nil prop & val).
  30.     In Progress:
  31.         
  32. */
  33.  
  34.  
  35. #ifndef _EXCEPT_
  36. #include <Except.h>
  37. #endif
  38.  
  39. #ifndef _ODDEBUG_
  40. #include "ODDebug.h"
  41. #endif
  42.  
  43. #ifndef _ODMEMORY_
  44. #include <ODMemory.h>
  45. #endif
  46.  
  47. #ifndef SOM_ODStorageUnit_xh
  48. #include <StorageU.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODStorageUnitView_xh
  52. #include <SUView.xh>
  53. #endif
  54.  
  55. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  56. #include <StdTypes.xh>
  57. #endif
  58.  
  59. #ifndef _STDTYPIO_
  60. #include "StdTypIO.h"
  61. #endif
  62.  
  63. #ifndef _STORUTIL_
  64. #include <StorUtil.h>
  65. #endif
  66.  
  67. #ifndef _TEMPOBJ_
  68. #include "TempObj.h"
  69. #endif
  70.  
  71. #ifndef __ICONS__
  72. #include <Icons.h>
  73. #endif
  74.  
  75. //==============================================================================
  76. // Constants
  77. //==============================================================================
  78.  
  79. static const int kNIconTypes = 8;
  80. static const ResType    kIconType[kNIconTypes] 
  81.                     = {'ics#','ics4','ics8',     0,     0,'ICN#','icl4','icl8'};
  82. static const short        kIconSize[kNIconTypes]
  83.                     = {    64,   128,   256,   512,  1024,   256,   512,  1024};
  84.  
  85.  
  86. //==============================================================================
  87. // IconFamily
  88. //==============================================================================
  89.  
  90.  
  91. const ODULong kAllMacIconsMask = 0x00E7;        // 16x16 and 32x32 / 1,4,8 bits deep 
  92.  
  93. //    If there is no value at the passed in prop & val then kODNULL is returned.
  94. //    This is consistent with the other routines in StdTypIO which return pointers.
  95. //    Other StdTypIO routines which actually return the value gotten, WARN if no value
  96. //    is there.
  97. //    The reason is that there may be clients of ODIconFamily which more easily 
  98. //    handle the flow of control if it just returns kODNULL instead of THROWing. -Tantek
  99.  
  100. ODIconFamily
  101. ODGetIconFamilyProp(Environment* ev, ODStorageUnit* su, ODPropertyName prop, 
  102.                     ODValueType val, ODULong iconMask)
  103. {
  104.     if( val == kODIconFamily )
  105.         val = kODIconFamilyMac;        // If only kODIconFamily specified, use platform type
  106.         
  107.     if (ODSUExistsThenFocus(ev, su, prop, val))
  108.     {
  109.         iconMask &= kAllMacIconsMask;
  110.         
  111.         ODULong which;
  112.         ODSize pos = sizeof(which);
  113.         StorageUnitGetValue(su, ev, sizeof(which), &which);        
  114.             // Which icons have data?
  115.         
  116.         if( (which & iconMask) == 0 )
  117.             return kODNULL;
  118.         
  119.         ODIconFamily iconFamily;
  120.         THROW_IF_ERROR( NewIconSuite((Handle*)&iconFamily) );
  121.         
  122.         ODHandle h=kODNULL; ODVolatile(h);
  123.         TRY{
  124.             for( int i=0; i<kNIconTypes; i++ )
  125.                 if( which & (1<<i) ) {
  126.                     ODSize size = kIconSize[i];
  127.                     pos += size;
  128.                     if( iconMask & (1<<i) ) {            // Read icon:
  129.                         h = ODNewHandle(size);
  130.                         StorageUnitGetValue(su, ev,size, ODLockHandle(h));
  131.                         ODUnlockHandle(h);
  132.                         THROW_IF_ERROR( AddIconToSuite((Handle)h,(Handle)iconFamily,kIconType[i]) );
  133.                         h = kODNULL;
  134.                     } else
  135.                         su->SetOffset(ev,pos);            // Don't need this icon
  136.                 }
  137.         }CATCH_ALL{
  138.             ODDisposeHandle(h);
  139.             DisposeIconSuite((Handle)iconFamily,kODTrue);
  140.             RERAISE;
  141.         }ENDTRY
  142.         
  143.         return iconFamily;
  144.     }
  145.     else
  146.         return kODNULL;
  147. }
  148.  
  149.                         
  150. #define SKIPOMPARSE
  151. #ifdef SKIPOMPARSE
  152. static const char* const kODIconFamilyBaseString = kODIconFamily ":";
  153. #else
  154. static const char* const kODIconFamilyBaseString = "^^^^correct def.^^^^^";
  155. #endif
  156.  
  157. void
  158. ODSetIconFamilyProp(Environment* ev, ODStorageUnit* su, ODPropertyName prop, 
  159.                     ODValueType val, ODIconFamily iconFamily,
  160.                     ODBoolean removeOtherPlatformIcons)
  161. {
  162.     ODSUForceFocus(ev, su, prop, val);
  163.  
  164.     ODBoolean wholeValue = (prop!=kODNULL || val!=kODNULL);
  165.     
  166.     // See which icons exist in the family:
  167.     ODULong which = 0;
  168.     Handle icon;
  169.     if( iconFamily != kODNULL )
  170.         for( int i=0; i<kNIconTypes; i++ )
  171.             if( kIconType[i] && GetIconFromSuite(&icon,(Handle)iconFamily,kIconType[i])==noErr && icon )
  172.                 which |= (1<<i);
  173.             
  174.     if( which==0 && wholeValue) 
  175.     {
  176.         // If there are no icons, remove the value:
  177.         su->Remove(ev);
  178.     }
  179.     else 
  180.     {
  181.         su->SetOffset(ev,0);
  182.         ODSize size = su->GetSize(ev);
  183.         su->DeleteValue(ev,size);
  184.         
  185.         StorageUnitSetValue(su, ev, sizeof(which), &which);
  186.         for( int i=0; i<kNIconTypes; i++ )
  187.             if( kIconType[i] && GetIconFromSuite(&icon,(Handle)iconFamily,kIconType[i])==noErr && icon ) 
  188.             {
  189.                 TRY{
  190.                     ODLockHandle((ODHandle)icon);
  191.                     StorageUnitSetValue(su, ev, kIconSize[i], (ODValue)(*icon));
  192.                 }CATCH_ALL{
  193.                     ODUnlockHandle((ODHandle)icon);
  194.                     RERAISE;
  195.                 }ENDTRY
  196.                 ODUnlockHandle((ODHandle)icon);
  197.             }
  198.     }
  199.     
  200.     if( removeOtherPlatformIcons ) {
  201.         ODULong nValues = su->CountValues(ev);
  202.         ODULong index = 1;
  203.         while( nValues-- != 0 ) {
  204.             su->Focus(ev,kODNULL,kODPosSame, kODNULL,0,index);    // Focus to value by index
  205.             TempODValueType type = su->GetType(ev);
  206.             if( strncmp(type,kODIconFamilyBaseString,strlen(kODIconFamilyBaseString)) == 0
  207.                             && strcmp(type,val) != 0 )
  208.                 su->Remove(ev);
  209.             else
  210.                 index++;
  211.         }
  212.     }
  213. }
  214.                             
  215.