home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-15 | 2.6 KB | 124 lines | [TEXT/CWIE] |
- #include "AppleEventManager.h"
- #include "ThreadManager.h"
- #include "ToolboxEvent.h"
- #include "Exceptions.h"
- #include "EventLoop.h"
- #include "Futures.h"
-
- //--------------------------------------------------------------------------------
-
- #if qDebug
-
- AppleEventManager& AppleEventManager::GetAppleEventManager()
- {
- if (!gAppleEventManager)
- {
- Debugger();
- }
-
- return *gAppleEventManager;
- }
-
- //--------------------------------------------------------------------------------
-
- AppleEventManager::AppleEventManager()
- {
- WarnIf(gAppleEventManager != nil, "Instantiating a second AppleEventManager");
-
- gAppleEventManager = this;
- }
-
- #endif
-
- //--------------------------------------------------------------------------------
-
- AppleEventManager::~AppleEventManager()
- {
- gAppleEventManager = nil;
- }
-
- //--------------------------------------------------------------------------------
-
- bool AppleEventManager::Validate()
- {
- if (TModule::Validate())
- {
- return true;
- }
-
- return false;
- }
-
- //--------------------------------------------------------------------------------
-
- void AppleEventManager::Initialize(void)
- {
- InitializeAfter(ThreadManager::GetThreadManager());
-
- TModule::Initialize();
- EventFilter::Initialize();
-
- #if qFeatureSupported(qFuturesSupport)
- FailOSErr(InitFutures(nil, kNoSpecialFutureFeatures));
- #endif
- }
-
- //--------------------------------------------------------------------------------
-
- void AppleEventManager::Finalize(void)
- {
- TModule::Finalize();
- EventFilter::Finalize();
- }
-
- //--------------------------------------------------------------------------------
-
- bool AppleEventManager::FilterEvent(ToolboxEvent& event)
- {
- #if qFeatureSupported(qFuturesSupport)
- IdleFutures();
- #endif
-
- if (event.IsHighLevelEvent())
- {
- FailOSErr(::AEProcessAppleEvent(event));
-
- return true;
- }
-
- return false;
- }
-
- //--------------------------------------------------------------------------------
-
- void AppleEventManager::SendAppleEvent(
- const AppleEvent& theAppleEvent,
- AppleEvent* reply,
- long timeOutInTicks,
- long maxWaitTime,
- AESendMode sendMode,
- AESendPriority sendPriority)
- {
- OSErr err;
-
- if (qFeatureSupported(qFuturesSupport)
- && ((sendMode & 0x03) == kAEFutureReply))
- {
- if (maxWaitTime == kNoTimeOut)
- {
- maxWaitTime = kNoMaximumWait;
- }
-
- err = AskForFuture(&theAppleEvent, reply, timeOutInTicks, maxWaitTime, sendMode, sendPriority);
- }
- else
- {
- err = AESend(&theAppleEvent, reply, sendMode, sendPriority, timeOutInTicks, EventLoop::GetAEIdleProc(), EventLoop::GetAEFilterProc());
- }
-
- FailOSErr(err);
- }
-
- //--------------------------------------------------------------------------------
-
-