-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathObjectiveCBridge.m
71 lines (60 loc) · 1.76 KB
/
ObjectiveCBridge.m
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
// qmake does not compile Objective-C++ sources with C++ flags. This is a
// critical failing, because the C++ flags can alter the library ABI. In
// particular, -stdlib=libc++ enables an incompatible standard library.
//
// I do not see an obvious non-hacky fix for this issue, and without one,
// Objective-C++ is unusable with qmake, at least on OS X with the version of
// Qt I'm using (Qt 4.8.6 installed via Homebrew).
//
// As a workaround, put Objective-C code here and call it from C++.
#import "ObjectiveCBridge.h"
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
id cursor_currentSystemCursor()
{
return [NSCursor currentSystemCursor];
}
BridgePoint cursor_hotSpot(id cursor)
{
NSPoint ret = [(NSCursor*)cursor hotSpot];
BridgePoint ret2 = { ret.x, ret.y };
return ret2;
}
BridgePoint event_mouseLocation()
{
NSPoint ret = [NSEvent mouseLocation];
BridgePoint ret2 = { ret.x, ret.y };
return ret2;
}
id cursor_image(id cursor)
{
return [(NSCursor*)cursor image];
}
id image_TIFFRepresentation(id image)
{
return [(NSImage*)image TIFFRepresentation];
}
const void *data_bytes(id data)
{
return [(NSData*)data bytes];
}
size_t data_length(id data)
{
return [(NSData*)data length];
}
void bridgeWriteCursorFile(id tiffData, uint32_t imageID)
{
NSBitmapImageRep *imageRep =
[[[NSBitmapImageRep alloc]
initWithData:(NSData*)tiffData] autorelease];
assert(imageRep != nil);
NSData *pngData =
[imageRep representationUsingType:NSPNGFileType properties:nil];
NSString *path =
[NSString stringWithFormat:@"cursor_%u.png", imageID];
[pngData writeToFile:path atomically:NO];
}
bool bridgeCapsLockEnabled()
{
return ([NSEvent modifierFlags] & NSAlphaShiftKeyMask) != 0;
}