home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 12.5 KB | 400 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSemPrp.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSCPPRP_H
- #include "FWScpPrp.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWAPLEVT_H
- #include "FWAplEvt.h"
- #endif
-
- #ifndef FWSCPTBL_H
- #include "FWScptbl.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWPSTR_H
- #include "FWPStr.h"
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwsemevt
- #endif
-
- FW_DEFINE_AUTO(FW_CPropertyDesignator)
- FW_DEFINE_AUTO(FW_CSetPropertyCommand)
-
- //========================================================================================
- // class FW_CPropertyDesignator
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CPropertyDesignator, FW_MScriptable)
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::FW_CPropertyDesignator
- //---------------------------------------------------------------------------------------
-
- FW_CPropertyDesignator::FW_CPropertyDesignator(FW_CPart* part,
- FW_MScriptable* whichObject,
- ODDescType whichProperty) :
- FW_MScriptable(),
- fObject(whichObject),
- fPart(part),
- fWhichProperty(whichProperty),
- fRefCount(1)
- {
- FW_ASSERT(fPart);
-
- if (fObject)
- {
- fObject->AcquireScriptable();
- whichObject->AddDependent(this);
- }
-
- FW_END_CONSTRUCTOR
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::~FW_CPropertyDesignator
- //---------------------------------------------------------------------------------------
-
- FW_CPropertyDesignator::~FW_CPropertyDesignator()
- {
- FW_START_DESTRUCTOR
-
- FW_ASSERT(fRefCount == 0);
-
- if (fObject)
- {
- fObject->RemoveDependent(this);
- fObject->ReleaseScriptable();
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::AcquireScriptable
- //---------------------------------------------------------------------------------------
-
- long FW_CPropertyDesignator::AcquireScriptable()
- {
- return ++fRefCount;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::ReleaseScriptable
- //---------------------------------------------------------------------------------------
-
- long FW_CPropertyDesignator::ReleaseScriptable()
- {
- FW_ASSERT(fRefCount > 0);
-
- long result = --fRefCount;
-
- if (result == 0)
- delete this;
-
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::GetObjectClass
- //---------------------------------------------------------------------------------------
-
- ODDescType FW_CPropertyDesignator::GetObjectClass() const
- {
- return cProperty;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::GetSpecifierForm
- //---------------------------------------------------------------------------------------
-
- ODDescType FW_CPropertyDesignator::GetSpecifierForm() const
- {
- return formPropertyID;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::BuildObjectSpecifier
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::BuildObjectSpecifier(Environment* ev,
- FW_CPart* part,
- const FW_CFrame* frame,
- FW_CDesc& specifier,
- ODDescType preferredForm) const
- {
- if (preferredForm != formPropertyID)
- {
- FW_MScriptable::BuildObjectSpecifier(ev, part, frame, specifier, preferredForm);
- }
- else
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
-
- fObject->GetPropertySpecifier(ev, part, fWhichProperty, specifier);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::GetDesignateValue
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPropertyDesignator::GetDesignateValue(Environment* ev,
- FW_CDesc& propertyValue,
- ODDescType desiredType) const
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
-
- return (fObject->GetProperty(ev, fPart, propertyValue, fWhichProperty, desiredType));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::SaveDesignateValue
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::SaveDesignateValue(Environment* ev,
- FW_CDesc& propertyValue,
- ODDescType desiredType) const
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
-
- fObject->SaveProperty(ev, fPart, propertyValue, fWhichProperty, desiredType);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::SetDesignateValue
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::SetDesignateValue(Environment* ev, FW_CDesc& propertyValue)
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
-
- fObject->SetProperty(ev, fPart, propertyValue, fWhichProperty);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::RestoreDesignateValue
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::RestoreDesignateValue(Environment* ev, FW_CDesc& propertyValue)
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
- fObject->RestoreProperty(ev, fPart, propertyValue, fWhichProperty);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::GetDesignateFrame
- //---------------------------------------------------------------------------------------
-
- FW_CFrame* FW_CPropertyDesignator::GetDesignateFrame(Environment* ev, FW_CPart* part)
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
- return (fObject->GetFrame(ev, part));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::GetDesignateInfo
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::GetDesignateInfo(Environment* ev,
- FW_Boolean& canUndo,
- FW_Boolean& causesChange)
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
- fObject->GetPropertyInfo(ev, fPart, canUndo, causesChange);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::GetDesignateUndoStrings
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::GetDesignateUndoStrings(Environment* ev,
- FW_CPart* part,
- FW_CString& undoString,
- FW_CString& redoString)
- {
- if (!fObject)
- FW_Failure(errAEEventNotHandled);
- fObject->GetUndoStrings(ev, part, fWhichProperty, undoString, redoString);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::HandlePrimaryDeleted
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::HandlePrimaryDeleted(FW_MScriptable* primary)
- {
- FW_UNUSED(primary);
-
- FW_ASSERT(primary == fObject);
- fObject = NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::Compare
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPropertyDesignator::CompareScriptableObjects(Environment* ev,
- FW_CPart* part,
- ODDescType operation,
- const FW_CDesc& other) const
- {
- FW_UNUSED(part);
- FW_CDesc value;
-
- // Try to get the designated value as the same type as the descriptor
- // to be compared against. If that doesn't work, get it as whatever
- // type is available, and give FW_CDesc::Compare a chance to coerce
- // the values into a common type.
-
- if (!GetDesignateValue(ev, value, other.DescriptorType()))
- GetDesignateValue(ev, value, typeWildCard);
-
- return value.Compare(operation, other);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::DoAEGetData
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::DoAEGetData(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(part);
- FW_CDesc propertyValue;
- ODDescType desiredType = typeWildCard;
-
- if (event.HasDataKey(keyAERequestedType))
- event.GetDataByPtr(typeWildCard, &desiredType, NULL, sizeof(ODDescType), keyAERequestedType);
-
- if (!GetDesignateValue(ev, propertyValue, desiredType))
- FW_Failure(errAEEventNotHandled);
-
- reply.PutDataByDesc(propertyValue, keyAEResult);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPropertyDesignator::DoAESetData
- //---------------------------------------------------------------------------------------
-
- void FW_CPropertyDesignator::DoAESetData(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(reply);
- FW_CDesc propertyValue;
-
- FW_Boolean canUndo;
- FW_Boolean causesChange;
-
- event.GetDataByDesc(propertyValue, keyAEData);
- GetDesignateInfo(ev, canUndo, causesChange);
-
- FW_CSetPropertyCommand* cmd = FW_NEW(FW_CSetPropertyCommand, (ev, GetDesignateFrame(ev, part), canUndo, this, propertyValue));
- cmd->SetCausesChange(ev, causesChange);
- cmd->Execute(ev);
- }
-
- //========================================================================================
- // class FW_SetPropertyCommand
- //========================================================================================
-
- //---------------------------------------------------------------------------------------
- // FW_CSetPropertyCommand::SetPropertyCommand
- //---------------------------------------------------------------------------------------
-
- FW_CSetPropertyCommand::FW_CSetPropertyCommand(Environment* ev,
- FW_CFrame* frame,
- FW_Boolean canUndo,
- FW_CPropertyDesignator* propDesignator,
- FW_CDesc& newValue) :
- FW_CCommand(ev, -1, frame, TRUE),
- fPropDesignator(propDesignator),
- fOldValue(),
- fNewValue(newValue)
- {
- FW_UNUSED(canUndo);
- if (propDesignator)
- propDesignator->AcquireScriptable();
-
- FW_END_CONSTRUCTOR
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CSetPropertyCommand::~SetPropertyCommand
- //---------------------------------------------------------------------------------------
-
- FW_CSetPropertyCommand::~FW_CSetPropertyCommand()
- {
- FW_START_DESTRUCTOR
-
- if (fPropDesignator)
- fPropDesignator->ReleaseScriptable();
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CSetPropertyCommand::DoIt
- //---------------------------------------------------------------------------------------
-
- void FW_CSetPropertyCommand::DoIt(Environment* ev)
- {
- if (GetCanUndo(ev))
- {
- FW_CString undoString;
- FW_CString redoString;
-
- fPropDesignator->GetDesignateUndoStrings(ev, GetPart(ev), undoString, redoString);
- SetMenuStrings(ev, undoString, redoString);
- }
-
- fPropDesignator->SaveDesignateValue(ev, fOldValue, typeWildCard);
- fPropDesignator->SetDesignateValue(ev, fNewValue);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CSetPropertyCommand::UndoIt
- //---------------------------------------------------------------------------------------
-
- void FW_CSetPropertyCommand::UndoIt(Environment* ev)
- {
- fPropDesignator->RestoreDesignateValue(ev, fOldValue);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CSetPropertyCommand::RedoIt
- //---------------------------------------------------------------------------------------
-
- void FW_CSetPropertyCommand::RedoIt(Environment* ev)
- {
- fPropDesignator->SetDesignateValue(ev, fNewValue);
- }
-