Handle Quit event more gracefully

This commit is contained in:
elasota
2020-04-18 05:51:39 -04:00
parent 94f26d0be1
commit 69e3fb3023
9 changed files with 87 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -251,6 +251,7 @@ namespace GpVOSEventTypes
kMouseInput,
kGamepadInput,
kVideoResolutionChanged,
kQuit
};
}

View File

@@ -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)
{

View File

@@ -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;
}
}

View File

@@ -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;
};
}

View File

@@ -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;
}
}

View File

@@ -146,6 +146,7 @@
<ClInclude Include="AEHandlerDesc.h" />
<ClInclude Include="AEManager.h" />
<ClInclude Include="AntiAliasTable.h" />
<ClInclude Include="AppEventHandler.h" />
<ClInclude Include="ArrayTools.h" />
<ClInclude Include="BinarySearch.h" />
<ClInclude Include="BinHex4.h" />
@@ -303,6 +304,7 @@
<ClCompile Include="..\stb\stb_image_write.c" />
<ClCompile Include="AEManager.cpp" />
<ClCompile Include="AntiAliasTable.cpp" />
<ClCompile Include="AppEventHandler.cpp" />
<ClCompile Include="BinHex4.cpp" />
<ClCompile Include="BitmapImage.cpp" />
<ClCompile Include="ByteSwap.cpp" />

View File

@@ -483,6 +483,9 @@
<ClInclude Include="ArrayTools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AppEventHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CFileStream.cpp">
@@ -758,5 +761,8 @@
<ClCompile Include="TextPlacer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AppEventHandler.cpp">
<Filter>Header Files</Filter>
</ClCompile>
</ItemGroup>
</Project>