Fixed: #1156 Handle window close/application quit cleanly
parent
0daf18f0ec
commit
ad6bf52e20
@ -0,0 +1,33 @@
|
|||||||
|
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
namespace NL3D
|
||||||
|
{
|
||||||
|
class CDriverGL;
|
||||||
|
NSApplicationTerminateReply applicationShouldTerminate(CDriverGL*);
|
||||||
|
}
|
||||||
|
|
||||||
|
@interface CocoaApplicationDelegate : NSObject<NSApplicationDelegate>
|
||||||
|
{
|
||||||
|
NL3D::CDriverGL* _driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(id)initWithDriver:(NL3D::CDriverGL*)driver;
|
||||||
|
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,62 @@
|
|||||||
|
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../driver_opengl.h"
|
||||||
|
|
||||||
|
#include "cocoa_application_delegate.h"
|
||||||
|
#include "cocoa_event_emitter.h"
|
||||||
|
|
||||||
|
namespace NL3D
|
||||||
|
{
|
||||||
|
NSApplicationTerminateReply applicationShouldTerminate(CDriverGL* driver)
|
||||||
|
{
|
||||||
|
// cancel if there is a driver and a custom exit handler set up
|
||||||
|
if(driver && driver->ExitFunc)
|
||||||
|
{
|
||||||
|
driver->ExitFunc();
|
||||||
|
return NSTerminateCancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
NLMISC::CCocoaEventEmitter* eventEmitter =
|
||||||
|
NLMISC::safe_cast<NLMISC::CCocoaEventEmitter*>(&(driver->_EventEmitter));
|
||||||
|
|
||||||
|
// cancel if there is a driver and cocoa event emitter handles the quit
|
||||||
|
if(driver && eventEmitter && eventEmitter->handleQuitRequest())
|
||||||
|
return NSTerminateCancel;
|
||||||
|
|
||||||
|
// just let the app terminate if no custom quit handling worked
|
||||||
|
return NSTerminateNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@implementation CocoaApplicationDelegate
|
||||||
|
|
||||||
|
-(id)initWithDriver:(NL3D::CDriverGL*)driver
|
||||||
|
{
|
||||||
|
if((self = [super init]))
|
||||||
|
{
|
||||||
|
_driver = driver;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
|
||||||
|
{
|
||||||
|
return NL3D::applicationShouldTerminate(_driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
Loading…
Reference in New Issue