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 / Button / Sources / Content.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.9 KB  |  223 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Content.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef CONTENT_H
  13. #include "Content.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef BINDING_K
  21. #include "Binding.k"
  22. #endif
  23.  
  24. #ifndef DEFINES_K
  25. #include "Defines.k"
  26. #endif
  27.  
  28. #ifndef ACTIONS_H
  29. #include "Actions.h"
  30. #endif
  31.  
  32. #ifndef FWKIND_H
  33. #include "FWKind.h"
  34. #endif
  35.  
  36. #ifndef FWSUSINK_H
  37. #include "FWSUSink.h"
  38. #endif
  39.  
  40. #ifndef FWSUUTIL_H
  41. #include "FWSUUtil.h"
  42. #endif
  43.  
  44. #ifndef FWAROPER_H
  45. #include "FWArOper.h"
  46. #endif
  47.  
  48. #ifndef FWNOTIFI_H
  49. #include "FWNotifi.h"
  50. #endif
  51.  
  52. #ifndef SOM_ODStorageUnit_xh
  53. #include <StorageU.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. //    Runtime information
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment odfbutton
  62. #endif
  63.  
  64. //========================================================================================
  65. //    Class CButtonContent
  66. //========================================================================================
  67.  
  68. FW_DEFINE_AUTO(CButtonContent)
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // CButtonContent constructor
  72. //----------------------------------------------------------------------------------------
  73.  
  74. CButtonContent::CButtonContent(Environment* ev, CButtonPart* part) :
  75.     FW_CContent(ev, part),
  76.     fAction(NULL),
  77.     fPart(part),
  78.     fActionType(0)
  79. {
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. // CButtonContent destructor
  84. //----------------------------------------------------------------------------------------
  85.  
  86. CButtonContent::~CButtonContent()
  87. {
  88.     delete fAction;
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. // CButtonContent::ExternalizeKind
  93. //----------------------------------------------------------------------------------------
  94.  
  95. void CButtonContent::ExternalizeKind(Environment* ev,
  96.                                  ODStorageUnit* destinationSU,
  97.                                  FW_CKind* kind,
  98.                                  FW_StorageKinds storageKind,
  99.                                  FW_CPromise* promise,
  100.                                  FW_CCloneInfo* cloneInfo)
  101. {
  102. FW_UNUSED(promise);
  103. FW_UNUSED(storageKind);
  104. FW_UNUSED(cloneInfo);
  105.     if (kind->IsPartKind(ev))
  106.     {
  107.         FW_PStorageUnitSink sink(ev, destinationSU, kODPropContents, kind->GetType(ev));
  108.         FW_CWritableStream stream(sink);
  109.         stream << fActionType;
  110.         FW_SUDeleteEndOfFocusedValue(ev, destinationSU);
  111.     }
  112.     else if (kind->IsEqual(ev, fPart->fDataSoundKind))
  113.     {
  114.         FW_ASSERT(fAction != NULL);
  115.         FW_ASSERT(fAction->GetActionType() == kSound);
  116.         fAction->Externalize(ev, destinationSU, kind);
  117.     }
  118.     else if (kind->IsEqual(ev, fPart->fDataScriptKind))
  119.     {
  120.         FW_ASSERT(fAction != NULL);
  121.         FW_ASSERT(fAction->GetActionType() == kScript);
  122.         fAction->Externalize(ev, destinationSU, kind);
  123.     }
  124.         
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. // CButtonContent::InternalizeKind
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_Boolean CButtonContent::InternalizeKind(Environment* ev,
  132.                                     ODStorageUnit* storage, 
  133.                                      FW_CKind* kind,
  134.                                     FW_StorageKinds storageKind,
  135.                                     FW_CCloneInfo* cloneInfo)
  136. {
  137. FW_UNUSED(storageKind);
  138. FW_UNUSED(cloneInfo);
  139.     
  140.     CAction* action = NULL;
  141.     short actionType = kNothing;
  142.     
  143.     if (kind->IsPartKind(ev))
  144.     {
  145.         FW_PStorageUnitSink sink(ev, storage, kODPropContents, kind->GetType(ev));
  146.         FW_CReadableStream stream(sink);
  147.         stream >> actionType;
  148.         
  149.         if (actionType == kSound)
  150.         {
  151.             if (storage->Exists(ev, kODPropContents, fPart->fDataSoundKind->GetType(ev), 0))
  152.                 action = new CSoundAction(ev, storage, fPart->fDataSoundKind);
  153.         }
  154.         else if (actionType == kScript)
  155.         {
  156.             if (storage->Exists(ev, kODPropContents, fPart->fDataScriptKind->GetType(ev), 0))
  157.                 action = new CScriptAction(ev, storage, fPart->fDataScriptKind);
  158.         }
  159.     }
  160.     else if (kind->IsEqual(ev, 'snd ', kODPlatformDataType) || kind->IsEqual(ev, 'sfil', kODPlatformFileType))
  161.     {
  162.         action = new CSoundAction(ev, storage, kind);
  163.         actionType = kSound;
  164.     }
  165.     else if (kind->IsEqual(ev, 'scpt', kODPlatformDataType) || kind->IsEqual(ev, 'osas', kODPlatformFileType))
  166.     {
  167.         action = new CScriptAction(ev, storage, kind);
  168.         actionType = kScript;
  169.     }
  170.     else
  171.         FW_DEBUG_MESSAGE("CButtonContent::InternalizeKind - Unknown type");
  172.     
  173.     ChangeAction(ev, action, actionType);
  174.  
  175.     return true;
  176. }
  177.  
  178.         
  179. //----------------------------------------------------------------------------------------
  180. //    CButtonContent::ChangeAction
  181. //----------------------------------------------------------------------------------------
  182.  
  183. void CButtonContent::ChangeAction(Environment* ev, CAction* action, short actionType)
  184. {
  185.     if (action != fAction)
  186.     {
  187.         if (actionType != fActionType)
  188.         {
  189.             if (fActionType == kSound)
  190.                 fPart->fDataSoundKind->ChangeImportExport(ev, FW_kImport);
  191.             else if (fActionType == kScript)
  192.                 fPart->fDataScriptKind->ChangeImportExport(ev, FW_kImport);
  193.             
  194.             fActionType = actionType;
  195.             
  196.             if (fActionType == kSound)
  197.                 fPart->fDataSoundKind->ChangeImportExport(ev, FW_kImportExportEnabled);
  198.             else if (fActionType == kScript)
  199.                 fPart->fDataScriptKind->ChangeImportExport(ev, FW_kImportExportEnabled);
  200.         }
  201.         
  202.         delete fAction;
  203.         fAction = action;
  204.     }
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    CButtonContent::HandleNotification
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void CButtonContent::HandleNotification(Environment* ev, const FW_CNotification& notification)
  212. {
  213. FW_UNUSED(ev);
  214.  
  215.     if (notification.GetMessage() == FW_kButtonPressedMsg && fAction != NULL)
  216.     {
  217.         // no need to check for the button ID, there is only 1 button in this frame
  218.         fAction->DoIt();        
  219.     }
  220. }
  221.  
  222.  
  223.