-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOSXHelper.mm
executable file
·126 lines (94 loc) · 3.15 KB
/
OSXHelper.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <objc/NSObject.h>
#import <include/cef_application_mac.h>
#include "Handler.hpp"
//#import "OSXHelper.h"
struct Platform {
NSObject *delegate;
NSAutoreleasePool *autopool;
};
@interface AppDelegate : NSObject<NSApplicationDelegate>
- (void)createApplication:(id)object;
- (void)tryToTerminateApplication:(NSApplication*)app;
@end
@implementation AppDelegate
- (void)createApplication:(id)object {
[NSApplication sharedApplication] ;
[[NSBundle mainBundle] loadNibNamed:@"MainMa"
owner:NSApp
topLevelObjects:nil];
}
- (void)tryToTerminateApplication:(NSApplication *)app {
printf("qwdweiof");
}
- (NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication*)sender {
return NSTerminateNow;
}
@end
@interface Application : NSApplication <CefAppProtocol> {
@private
BOOL handlingEvents_;
}
@end
@implementation Application
- (BOOL)isHandlingSendEvent {
return self->handlingEvents_;
}
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
self->handlingEvents_ = handlingSendEvent;
}
- (void)sendEvent:(NSEvent *)event {
CefScopedSendingEvent sendingEvent;
[super sendEvent:event];
}
- (void)terminate:(nullable id)sender {
auto delegate = static_cast<AppDelegate *>([NSApp delegate]);
[delegate tryToTerminateApplication:self];
[super terminate:sender];
}
@end
@interface WindowDelegate : NSObject<NSWindowDelegate> {
}
@end
@implementation WindowDelegate
- (void)windowWillClose:(NSNotification *)notification {
Handler *handler = Handler::GetHandler();
printf("%p\n", handler);
handler->CloseAll();
}
@end
extern "C" NSWindow* CreateView() {
Application *app = [Application sharedApplication];
// NSApplication *app = [NSApplication sharedApplication];
[app activateIgnoringOtherApps: YES];
auto rect = NSRect {100, 100, 1280, 800};
NSWindow *window = [[NSWindow alloc] initWithContentRect:rect
styleMask:NSWindowStyleMaskClosable | NSWindowStyleMaskResizable | NSWindowStyleMaskTitled
backing:NSBackingStoreBuffered
defer:NO];
window.delegate = [[WindowDelegate alloc] init];
[window setOpaque: NO];
[window makeKeyAndOrderFront: nil];
return window;
}
extern "C" NSView* GetContentView(NSWindow *window) {
return [window contentView];
}
extern "C" void ReleaseView(NSWindow *window) {
[window release];
}
extern "C" void InitPlatform(Platform *platform) {
platform->autopool = [[NSAutoreleasePool alloc] init];
[Application sharedApplication];
AppDelegate *delegate = [[AppDelegate alloc] init];
[delegate performSelectorOnMainThread: @selector(createApplication:)
withObject: nil
waitUntilDone: NO];
platform->delegate = delegate;
}
extern "C" void ReleasePlatform(Platform *platform) {
[platform->delegate release];
[platform->autopool release];
}