diff --git a/Aerofoil/GpMain_Win32.cpp b/Aerofoil/GpMain_Win32.cpp
index c484d56..7fcb0a5 100644
--- a/Aerofoil/GpMain_Win32.cpp
+++ b/Aerofoil/GpMain_Win32.cpp
@@ -379,6 +379,12 @@ static void TranslateWindowsMessage(const MSG *msg, IGpVOSEventQueue *eventQueue
PostKeyboardEvent(eventQueue, keyEventType, subset, key, (lParam & 0xffff));
}
break;
+ case WM_QUIT:
+ {
+ if (GpVOSEvent *evt = eventQueue->QueueEvent())
+ evt->m_eventType = GpVOSEventTypes::kQuit;
+ }
+ break;
default:
break;
}
diff --git a/GpApp/AppleEvents.cpp b/GpApp/AppleEvents.cpp
index 1b50063..dbf85e1 100644
--- a/GpApp/AppleEvents.cpp
+++ b/GpApp/AppleEvents.cpp
@@ -7,6 +7,7 @@
#include "PLAppleEvents.h"
+#include "AppEventHandler.h"
#include "DialogManager.h"
#include "Externs.h"
#include "House.h"
@@ -168,12 +169,38 @@ PLError_t MyGotRequiredParams (const AppleEvent *theAE)
PLErrors::kInvalidParameter;
}
+class SystemEventHandlerImpl : public PortabilityLayer::IAppEventHandler
+{
+public:
+ void OnQuit() override;
+
+ static SystemEventHandlerImpl *GetInstance();
+
+private:
+ static SystemEventHandlerImpl ms_instance;
+};
+
+void SystemEventHandlerImpl::OnQuit()
+{
+ quitting = true;
+}
+
+
+SystemEventHandlerImpl *SystemEventHandlerImpl::GetInstance()
+{
+ return &ms_instance;
+}
+
+SystemEventHandlerImpl SystemEventHandlerImpl::ms_instance;
+
//-------------------------------------------------------------- SetUpAppleEvents
// Initializes all handlers, etc. for dealing with Apple Events.
void SetUpAppleEvents (void)
{
PLError_t theErr;
+
+ PortabilityLayer::AppEventHandler::SetInstance(SystemEventHandlerImpl::GetInstance());
openAppAEUPP = NewAEEventHandlerProc(DoOpenAppAE);
openDocAEUPP = NewAEEventHandlerProc(DoOpenDocAE);
diff --git a/GpCommon/GpVOSEvent.h b/GpCommon/GpVOSEvent.h
index eab1637..a337e4f 100644
--- a/GpCommon/GpVOSEvent.h
+++ b/GpCommon/GpVOSEvent.h
@@ -251,6 +251,7 @@ namespace GpVOSEventTypes
kMouseInput,
kGamepadInput,
kVideoResolutionChanged,
+ kQuit
};
}
diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
index 785e672..e1f3fe7 100644
--- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
+++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
@@ -56,6 +56,7 @@ LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message)
{
case WM_DESTROY:
+ case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
@@ -756,9 +757,6 @@ void GpDisplayDriverD3D11::Run()
{
DispatchMessage(&msg);
- if (msg.message == WM_QUIT)
- break;
- else
{
if (msg.message == WM_MOUSEMOVE)
{
diff --git a/PortabilityLayer/AppEventHandler.cpp b/PortabilityLayer/AppEventHandler.cpp
new file mode 100644
index 0000000..96fa9b3
--- /dev/null
+++ b/PortabilityLayer/AppEventHandler.cpp
@@ -0,0 +1,16 @@
+#include "AppEventHandler.h"
+
+namespace PortabilityLayer
+{
+ IAppEventHandler *AppEventHandler::ms_instance;
+
+ IAppEventHandler *AppEventHandler::GetInstance()
+ {
+ return ms_instance;
+ }
+
+ void AppEventHandler::SetInstance(IAppEventHandler *instance)
+ {
+ ms_instance = instance;
+ }
+}
diff --git a/PortabilityLayer/AppEventHandler.h b/PortabilityLayer/AppEventHandler.h
new file mode 100644
index 0000000..baacc9a
--- /dev/null
+++ b/PortabilityLayer/AppEventHandler.h
@@ -0,0 +1,19 @@
+#pragma once
+
+namespace PortabilityLayer
+{
+ struct IAppEventHandler
+ {
+ virtual void OnQuit() = 0;
+ };
+
+ class AppEventHandler
+ {
+ public:
+ static IAppEventHandler *GetInstance();
+ static void SetInstance(IAppEventHandler *instance);
+
+ private:
+ static IAppEventHandler *ms_instance;
+ };
+}
diff --git a/PortabilityLayer/PLSysCalls.cpp b/PortabilityLayer/PLSysCalls.cpp
index fc66abe..163c258 100644
--- a/PortabilityLayer/PLSysCalls.cpp
+++ b/PortabilityLayer/PLSysCalls.cpp
@@ -1,4 +1,5 @@
#include "PLCore.h"
+#include "AppEventHandler.h"
#include "PLEventQueue.h"
#include "PLKeyEncoding.h"
#include "PLMovies.h"
@@ -135,6 +136,14 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
case GpVOSEventTypes::kVideoResolutionChanged:
TranslateVideoResolutionChangedEvent(vosEvent->m_event.m_resolutionChangedEvent);
break;
+ case GpVOSEventTypes::kQuit:
+ if (TimeTaggedVOSEvent *evt = queue->Enqueue())
+ *evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp);
+
+ if (PortabilityLayer::IAppEventHandler *appHandler = PortabilityLayer::AppEventHandler::GetInstance())
+ appHandler->OnQuit();
+
+ break;
}
}
diff --git a/PortabilityLayer/PortabilityLayer.vcxproj b/PortabilityLayer/PortabilityLayer.vcxproj
index 795ca0b..37657c2 100644
--- a/PortabilityLayer/PortabilityLayer.vcxproj
+++ b/PortabilityLayer/PortabilityLayer.vcxproj
@@ -146,6 +146,7 @@
+
@@ -303,6 +304,7 @@
+
diff --git a/PortabilityLayer/PortabilityLayer.vcxproj.filters b/PortabilityLayer/PortabilityLayer.vcxproj.filters
index ac0b4c2..f3cb124 100644
--- a/PortabilityLayer/PortabilityLayer.vcxproj.filters
+++ b/PortabilityLayer/PortabilityLayer.vcxproj.filters
@@ -483,6 +483,9 @@
Header Files
+
+ Header Files
+
@@ -758,5 +761,8 @@
Source Files
+
+ Header Files
+
\ No newline at end of file