OS X build fixes; configure: improved
[sdk] / ecere / src / gui / drivers / cocoa / CocoaEcereBridge.m
1 #import <Cocoa/Cocoa.h>
2
3 #import "CocoaEcereBridge.h"
4 #import "EcereView.h"
5
6 bool CocoaInitialize()
7 {
8     [[NSAutoreleasePool alloc] init];
9     [NSApplication sharedApplication];
10
11     [NSOpenGLContext clearCurrentContext];
12
13     return true;
14 }
15
16
17 void CocoaTerminate()
18 {
19     [NSApp release];
20 }
21
22 bool CocoaProcessInput(bool processAll)
23 {
24     NSEvent *event = NULL;
25     NSDate *date;
26     unsigned int eventMask;
27
28     eventMask = (NSAnyEventMask);
29
30     do {
31         event = [
32             NSApp nextEventMatchingMask:eventMask
33             untilDate:nil
34             inMode:NSDefaultRunLoopMode
35             dequeue:YES];
36
37         [NSApp sendEvent:event];
38         if ([event type])
39             printf("e%i\n", [event type]);
40     } while (event && processAll);
41
42     return true;
43 }
44
45 bool CocoaLock(WindowHandle handle)
46 {
47     EcereView *view = (EcereView*)handle;
48
49     [view lockFocus];
50
51     return true;
52 }
53
54 void CocoaUnlock(WindowHandle handle)
55 {
56     EcereView *view = (EcereView*)handle;
57
58     [view unlockFocus];
59 }
60
61 void CocoaGetCurrentMode(bool * fullScreen, int * resolution, int * colorDepth, int * refreshRate)
62 {
63     *fullScreen = false;
64     *resolution = -1;
65     *colorDepth = -1;
66     *refreshRate = -1;
67 }
68
69 WindowHandle CocoaCreateRootWindow(EcereWindowRef ecereWindow)
70 {
71     NSWindow *window = [[NSWindow alloc]
72         initWithContentRect:NSZeroRect
73         styleMask:( NSResizableWindowMask | NSClosableWindowMask | NSTitledWindowMask)
74         backing:NSBackingStoreBuffered
75         defer:NO
76         screen:nil];
77
78     EcereView *view = [[EcereView alloc] initWithEcereWindow:ecereWindow];
79         [window setContentView:view];
80
81     if (window) {
82         [window makeKeyAndOrderFront:window];
83     }
84
85     return view;
86 }
87
88 void CocoaDestroyRootWindow(WindowHandle handle)
89 {
90     EcereView *view = (EcereView*)handle;
91
92     [[view window] release];
93     [view release];
94 }
95
96 void CocoaSetRootWindowCaption(WindowHandle handle, const char *name)
97 {
98     EcereView *view = (EcereView*)handle;
99
100     NSString *title = [NSString stringWithCString:name];
101
102     [[view window] setTitle:title];
103
104     [title release];
105 }
106
107 void CocoaPositionRootWindow(WindowHandle handle, int x, int y, int w, int h, bool move, bool resize)
108 {
109     EcereView *view = (EcereView*)handle;
110
111     NSRect frame = [[view window] frame];
112
113     if (move) {
114         frame.origin.x = x;
115         frame.origin.y = y;
116     }
117
118     if (resize) {
119         frame.size.width = w;
120         frame.size.height = h;
121     }
122
123     [[view window] setFrame:frame display:YES];
124 }
125
126 void CocoaOffsetWindow(WindowHandle handle, int *x, int *y)
127 {
128 }
129
130 void CocoaGetMousePosition(int *x, int *y)
131 {
132     NSPoint location;
133     location = [NSEvent mouseLocation];
134
135     *x = location.x;
136     *y = location.y;
137 }
138
139 void CocoaOpenGLMakeCurrentContext(WindowHandle handle)
140 {
141     EcereView *view = (EcereView*)handle;
142
143     [view makeCurrentContext];
144 }
145
146 void CocoaOpenGLUpdate(WindowHandle handle)
147 {
148     EcereView *view = (EcereView*)handle;
149
150     [view flushOpenGLBuffer];
151 }
152
153
154