2010-06-03 22:59:07 -06:00
|
|
|
#import "cocoaApp.h"
|
|
|
|
|
|
|
|
@implementation NSApplication(i)
|
|
|
|
- (void)appRunning
|
|
|
|
{
|
2010-07-09 16:31:04 -06:00
|
|
|
_running = 1;
|
2010-06-03 22:59:07 -06:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface cocoaAppDelegate : NSObject
|
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation cocoaAppDelegate : NSObject
|
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
|
|
|
{
|
2010-07-09 16:31:04 -06:00
|
|
|
return NSTerminateCancel;
|
2010-06-03 22:59:07 -06:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
void cocoaCreateApp()
|
|
|
|
{
|
|
|
|
ProcessSerialNumber psn;
|
|
|
|
|
|
|
|
if (!GetCurrentProcess(&psn)) {
|
2010-07-09 16:31:04 -06:00
|
|
|
TransformProcessType(&psn,
|
|
|
|
kProcessTransformToForegroundApplication);
|
2010-06-03 22:59:07 -06:00
|
|
|
SetFrontProcess(&psn);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NSApp == nil) {
|
|
|
|
[NSApplication sharedApplication];
|
|
|
|
//TODO : Create menu
|
|
|
|
[NSApp finishLaunching];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([NSApp delegate] == nil) {
|
|
|
|
[NSApp setDelegate:[[cocoaAppDelegate alloc] init]];
|
|
|
|
}
|
|
|
|
|
|
|
|
[NSApp appRunning];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cocoaKeyCode(NSEvent *event)
|
|
|
|
{
|
|
|
|
static bool CMDDown = false, QDown = false;
|
|
|
|
bool Return = false;
|
|
|
|
|
|
|
|
NSConnection *connec = [[NSConnection new] autorelease];
|
|
|
|
|
|
|
|
[connec setRootObject: event];
|
|
|
|
if ([connec registerName: @"DolphinCocoaEvent"] == NO)
|
|
|
|
{
|
|
|
|
//printf("error creating nsconnection\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if( [event type] != NSFlagsChanged )
|
|
|
|
{
|
|
|
|
const char *Keys = [[event characters] UTF8String];
|
|
|
|
|
|
|
|
if( Keys[0] == 'q' && [event type] == NSKeyDown )
|
|
|
|
QDown = true;
|
|
|
|
if( Keys[0] == 'q' && [event type] == NSKeyUp )
|
|
|
|
QDown = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( [event modifierFlags] & NSCommandKeyMask )
|
|
|
|
CMDDown = true;
|
|
|
|
else
|
|
|
|
CMDDown = false;
|
|
|
|
|
|
|
|
if( QDown && CMDDown )
|
|
|
|
Return = true;
|
|
|
|
|
|
|
|
return Return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cocoaSendEvent(NSEvent *event)
|
|
|
|
{
|
|
|
|
if ( event != nil ) {
|
|
|
|
switch ([event type]) {
|
|
|
|
case NSKeyDown:
|
|
|
|
case NSKeyUp:
|
|
|
|
case NSFlagsChanged: // For Command
|
|
|
|
return cocoaKeyCode(event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|