home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 7.0 KB | 231 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWAplEvt.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWAPLEVT_H
- #include "FWAplEvt.h"
- #endif
-
- #ifndef FWDSCOPR_H
- #include "FWDscOpr.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWSCPTBL_H
- #include "FWScptbl.h"
- #endif
-
- // ----- Macintosh Includes -----
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include <MssgIntf.xh>
- #endif
-
- #if defined(__MWERKS__) && GENERATING68K
- // A hack to work around a bug
- #pragma import list somNewObjectInstance
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwsemevt1
- #endif
-
- FW_DEFINE_AUTO(FW_CAppleEvent)
-
- //========================================================================================
- // CLASS FW_CAppleEvent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::FW_CAppleEvent
- //----------------------------------------------------------------------------------------
-
- FW_CAppleEvent::FW_CAppleEvent() :
- FW_CDesc()
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::FW_CAppleEvent
- //----------------------------------------------------------------------------------------
-
- FW_CAppleEvent::FW_CAppleEvent(ODAppleEvent* odAppleEvent) :
- FW_CDesc(odAppleEvent)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::~FW_CAppleEvent
- //----------------------------------------------------------------------------------------
-
- FW_CAppleEvent::~FW_CAppleEvent()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::HasAttributeKey
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CAppleEvent::HasAttributeKey(ODDescType key) const
- {
- FW_CDesc attribute;
- return (::AEGetAttributeDesc(*this, key, typeWildCard, attribute) == FW_xNoError);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::GetAttributeByKey
- //----------------------------------------------------------------------------------------
-
- void FW_CAppleEvent::GetAttributeByKey(AEKeyword key, FW_CDesc& desc, ODDescType desiredType) const
- {
- FW_FailOnError(::AEGetAttributeDesc(*this, key, desiredType, desc));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::HasSubject
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CAppleEvent::HasSubject() const
- {
- return HasAttributeKey(keySubjectAttr);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::GetSubject
- //----------------------------------------------------------------------------------------
-
- void FW_CAppleEvent::GetSubject(FW_CDesc& subjectDesc) const
- {
- GetAttributeByKey(keySubjectAttr, subjectDesc);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::GetEventClass
- //----------------------------------------------------------------------------------------
-
- AEKeyword FW_CAppleEvent::GetEventClass() const
- {
- AEKeyword eventClass = typeNull;
- FW_CDesc eventClassDesc;
-
- GetAttributeByKey(keyEventClassAttr, eventClassDesc);
- eventClassDesc >> eventClass;
-
- return eventClass;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::GetEventID
- //----------------------------------------------------------------------------------------
-
- AEKeyword FW_CAppleEvent::GetEventID() const
- {
- AEKeyword eventID = typeNull;
- FW_CDesc eventIDDesc;
-
- GetAttributeByKey(keyEventIDAttr, eventIDDesc);
- eventIDDesc >> eventID;
-
- return eventID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::operator ODAppleEvent*
- //----------------------------------------------------------------------------------------
-
- FW_CAppleEvent::operator ODAppleEvent*() const
- {
- PrivUpdateODDescIfStale();
- PrivODDescChanged();
- return (ODAppleEvent*)PrivGetODDescPtr();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::operator ODAppleEvent**
- //----------------------------------------------------------------------------------------
-
- FW_CAppleEvent::operator ODAppleEvent**()
- {
- PrivDispose();
- PrivODDescChanged();
- return (ODAppleEvent**)PrivGetODDescHandle();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAppleEvent::PrivCreateODDesc
- //----------------------------------------------------------------------------------------
-
- ODDesc* FW_CAppleEvent::PrivCreateODDesc(Environment* ev) const
- {
- ODAppleEvent* appleEvent = new ODAppleEvent;
- appleEvent->InitODAppleEvent(ev);
-
- return appleEvent;
- }
-
- //========================================================================================
- // Utility Functions
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_MakeSetLocalPropertyEvent : Given a local scriptable object, a property type,
- // and a new value for the property, create a recordable apple event that, when execute,
- // sets the specified property to the new value.
- //
- // This method is present for illustrative purposes only. ODF 1 does not implement
- // factored event handling or recordability.
- //----------------------------------------------------------------------------------------
-
- short FW_MakeSetLocalPropertyEvent(Environment* ev,
- FW_CPart* part,
- FW_MScriptable* theObject,
- ODDescType whichProperty,
- FW_CDesc& newValue,
- FW_CAppleEvent& setPropertyEvent)
- {
- FW_CDesc partAddress;
- ODMessageInterface* msgInt;
- short returnID;
-
- msgInt = part->GetSession(ev)->GetMessageInterface(ev);
-
- msgInt->CreatePartAddrDesc(ev, partAddress, part->GetODPart(ev));
- returnID = msgInt->CreateEvent(ev, kAECoreSuite, kAESetData, partAddress, 0, setPropertyEvent);
-
- FW_CDesc directObject;
- theObject->GetPropertySpecifier(ev, part, whichProperty, directObject);
-
- setPropertyEvent.PutDataByDesc(directObject, keyDirectObject);
- setPropertyEvent.PutDataByDesc(newValue, keyAEData);
-
- return returnID;
- }