home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / OpenDocSetup / SIZERC.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  2.8 KB  |  141 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        SIZERC.cpp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <1>     6/21/96    NP        first checked in
  13.  
  14.     To Do:
  15. */
  16.  
  17. #ifndef SIZERC_H
  18. #include "SIZERC.h"
  19. #endif
  20.  
  21. #ifndef ST_MACCLASSES_H
  22. #include "ST_MacClasses.h"
  23. #endif
  24.  
  25. SIZEResourceHandle    GetSIZEResource (short resFile, short id)
  26. {
  27.     ST_ResFileSaver        saver = CurResFile ();
  28.     UseResFile (resFile);
  29.     
  30.     SIZEResourceHandle    handle = (SIZEResourceHandle) Get1Resource ('SIZE', id);
  31.     return handle;
  32. }
  33.  
  34. OSErr GetOriginalSize (short resFile, Size& minimum, Size& maximum)
  35. {
  36.     SIZEResourceHandle        s = GetSIZEResource (resFile, kOriginalSIZEResourceID);
  37.     if (s) {
  38.         minimum = (**s).minimumMemorySize;
  39.         maximum = (**s).preferredMemorySize;
  40.         ReleaseResource ((Handle)s);
  41.         return noErr;
  42.     } else {
  43.         minimum = maximum = 0;
  44.         return resNotFound;    
  45.     }
  46. }
  47.  
  48. OSErr GetCustomSize (short resFile, Size& minimum, Size& maximum)
  49. {
  50.     SIZEResourceHandle        s;
  51.     
  52.     s = GetSIZEResource (resFile, kMaximumSIZEResourceID);
  53.     if (s) {
  54.         maximum = (**s).preferredMemorySize;
  55.         ReleaseResource ((Handle)s);
  56.     } else {
  57.         minimum = maximum = 0;
  58.         return resNotFound;    
  59.     }
  60.     
  61.     s = GetSIZEResource (resFile, kMinimumSIZEResourceID);
  62.     if (s) {
  63.         minimum = (**s).minimumMemorySize;
  64.         ReleaseResource ((Handle)s);
  65.     } else {
  66.         minimum = maximum = 0;
  67.         return resNotFound;    
  68.     }
  69.     
  70.     return noErr;
  71. }
  72.  
  73. OSErr SetCustomSize (short resFile, Size minimum, Size maximum)
  74. {
  75.     OSErr                        error;
  76.     ST_ResourceHandle            original = (Handle) GetSIZEResource (resFile, kOriginalSIZEResourceID);
  77.     if (!(Handle) original)
  78.         return resNotFound;
  79.         
  80.     /* set the minimum size, creating a resource if necessary */
  81.  
  82.     SIZEResourceHandle            minCustom = GetSIZEResource (resFile, kMinimumSIZEResourceID);
  83.     if (!minCustom) {
  84.         minCustom = (SIZEResourceHandle)(Handle) original;
  85.         error = HandToHand ((Handle*) &minCustom);
  86.         if (error)
  87.             return resNotFound;
  88.         else {
  89.             AddResource ((Handle) minCustom, 'SIZE', kMinimumSIZEResourceID, "\p");
  90.             error = ResError ();
  91.             if (error)
  92.                 return error;
  93.         }
  94.     }
  95.         
  96.     (**minCustom).minimumMemorySize = minimum;
  97.     ST_ResourceHandle            minimumHandle ((Handle) minCustom);
  98.  
  99.     /* set the maximum size, creating a resource if necessary */
  100.  
  101.     SIZEResourceHandle            maxCustom = GetSIZEResource (resFile, kMaximumSIZEResourceID);
  102.     if (!maxCustom) {
  103.         maxCustom = (SIZEResourceHandle)(Handle) original;
  104.         error = HandToHand ((Handle*) &maxCustom);
  105.         if (error)
  106.             return resNotFound;
  107.         else {
  108.             AddResource ((Handle) maxCustom, 'SIZE', kMaximumSIZEResourceID, "\p");
  109.             error = ResError ();
  110.             if (error)
  111.                 return error;
  112.         }
  113.     }
  114.     
  115.     (**maxCustom).preferredMemorySize = maximum;
  116.     ST_ResourceHandle            maximumHandle ((Handle) maxCustom);
  117.  
  118.     WriteResource ((Handle) minimumHandle);
  119.     WriteResource ((Handle) maximumHandle);    
  120.     
  121.     return noErr;
  122. }
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.