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 Development Framework / ODFDev / ODF / OS / FWGraphx / FWIcon.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.7 KB  |  205 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWIcon.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef SLICON_H
  13. #include "SLIcon.h"
  14. #endif
  15.  
  16. #ifndef FWICON_H
  17. #include "FWIcon.h"
  18. #endif
  19.  
  20. #ifndef FWSTRMRW_H
  21. #include "FWStrmRW.h"
  22. #endif
  23.  
  24. #ifndef SLGC_H
  25. #include "SLGC.h"
  26. #endif
  27.  
  28. #ifdef FW_BUILD_MAC
  29. #pragma segment FWGraphics_Icon
  30. #endif
  31.  
  32. //========================================================================================
  33. //    Template instantiation
  34. //========================================================================================
  35.  
  36. #include "FWGrRef.tpp"
  37.  
  38. FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HIcon)
  39.  
  40. #ifdef FW_USE_TEMPLATE_PRAGMAS
  41.  
  42. #pragma template_access public
  43. #pragma template FW_TGrRefPtr<FW_HIcon>
  44.  
  45. #else
  46.  
  47. template class FW_TGrRefPtr<FW_HIcon>;
  48.  
  49. #endif
  50.  
  51. //========================================================================================
  52. // class FW_CIcon
  53. //========================================================================================
  54.  
  55. FW_DEFINE_AUTO(FW_CIcon)
  56.  
  57. //----------------------------------------------------------------------------------------
  58. //    FW_PrivAcquireGrRep
  59. //----------------------------------------------------------------------------------------
  60.  
  61. void FW_PrivAcquireGrRep(FW_HIcon rep)
  62. {
  63.     if (rep != 0)
  64.         FW_PrivIcon_Acquire(rep);
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //    FW_PrivReleaseGrRep
  69. //----------------------------------------------------------------------------------------
  70.  
  71. void FW_PrivReleaseGrRep(FW_HIcon rep)
  72. {
  73.     if (rep != 0)
  74.         FW_PrivIcon_Release(rep);
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // FW_CIcon::FW_CIcon
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_CIcon::FW_CIcon()
  82. {
  83.     FW_END_CONSTRUCTOR
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. // FW_CIcon::FW_CIcon
  88. //----------------------------------------------------------------------------------------
  89.  
  90. FW_CIcon::FW_CIcon(FW_CReadableStream& stream)
  91. {
  92.     FW_PlatformError error;
  93.     FW_HIcon rep = FW_PrivIcon_Read(stream, &error);
  94.     FW_FailOnError(error);
  95.     SetRep(rep);
  96.     FW_END_CONSTRUCTOR
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. // FW_CIcon::FW_CIcon
  101. //----------------------------------------------------------------------------------------
  102.  
  103. FW_CIcon::FW_CIcon(FW_PlatformIcon platformIcon)
  104. {
  105.     FW_PlatformError error;
  106.     FW_HIcon rep = FW_PrivIcon_CreateFromPlatformIcon(platformIcon, &error);
  107.     FW_FailOnError(error);
  108.     SetRep(rep);
  109.     FW_END_CONSTRUCTOR
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // FW_CIcon::FW_CIcon
  114. //----------------------------------------------------------------------------------------
  115.  
  116. FW_CIcon::FW_CIcon(FW_PResourceFile& resourceFile,
  117.                    FW_ResourceID resID,
  118.                    short size)
  119. {
  120.     FW_PlatformError error;
  121.     FW_HIcon rep = FW_PrivIcon_CreateFromResource(resourceFile, resID, size, &error);
  122.     FW_FailOnError(error);
  123.     SetRep(rep);
  124.     FW_END_CONSTRUCTOR
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. // FW_CIcon::FW_CIcon
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_CIcon::FW_CIcon(const FW_CIcon& other) :
  132.     FW_TGrRefPtr<FW_HIcon>(other)
  133. {
  134.     FW_END_CONSTRUCTOR
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. // FW_CIcon::~FW_CIcon
  139. //----------------------------------------------------------------------------------------
  140.  
  141. FW_CIcon::~FW_CIcon()
  142. {
  143.     FW_START_DESTRUCTOR
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. // FW_CIcon::operator=
  148. //----------------------------------------------------------------------------------------
  149.  
  150. FW_CIcon& FW_CIcon::operator=(const FW_CIcon& other)
  151. {
  152.     FW_TGrRefPtr<FW_HIcon>::operator=(other);
  153.     return *this;
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // FW_CIcon::Copy
  158. //----------------------------------------------------------------------------------------
  159.  
  160. FW_CIcon FW_CIcon::Copy() const
  161. {
  162.     FW_PlatformError error;
  163.     FW_HIcon rep = FW_PrivIcon_Copy(fRep, &error);
  164.     FW_FailOnError(error);
  165.     
  166.     FW_CIcon icon;
  167.     icon.SetRep(rep);
  168.     return icon;
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // FW_CIcon::GetIconSize
  173. //----------------------------------------------------------------------------------------
  174.  
  175. void FW_CIcon::GetIconSize(FW_SGraphicContext& gc, FW_SPoint& size) const
  176.     FW_PrivIcon_GetIconSizeGC(gc.fEnvironment, fRep, gc, size); 
  177.     FW_FailOnEvError(gc.fEnvironment);
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //    operator <<
  182. //----------------------------------------------------------------------------------------
  183.  
  184. FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CIcon& icon)
  185. {
  186.     FW_PlatformError error;
  187.     FW_PrivIcon_Write(icon.fRep, stream, &error);
  188.     FW_FailOnError(error);
  189.     return stream;
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    operator >>
  194. //----------------------------------------------------------------------------------------
  195.  
  196. FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CIcon& icon)
  197. {
  198.     FW_PlatformError error;
  199.     FW_HIcon rep = FW_PrivIcon_Read(stream, &error);
  200.     FW_FailOnError(error);
  201.     icon.SetRep(rep);
  202.     return stream;
  203. }
  204.