-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcbits.m
122 lines (98 loc) · 2.26 KB
/
cbits.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
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
#import "AppKit/AppKit.h"
#import "AppKit/NSStatusBar.h"
#include <unistd.h>
void release(id o)
{
[o release];
}
void freeHaskellFunPtr(void (*ptr)(void));
@interface IOAction : NSObject
{
@public void (*ioaction)(void);
}
- (void) callIOAction;
- (void) dealloc;
@end
@implementation IOAction
- (void) callIOAction
{
self->ioaction();
}
- (void) dealloc
{
freeHaskellFunPtr(self->ioaction);
[super dealloc];
}
@end
/******************************************************/
void sendEvent(void)
{
NSEvent *e = [NSEvent otherEventWithType: NSEventTypeApplicationDefined location: NSZeroPoint modifierFlags: 0 timestamp: 0 windowNumber: 0 context: nil subtype: 12 data1: 0 data2: 0];
[NSApp postEvent: e atStart: NO];
[e release];
}
void initApp(void)
{
[NSApplication sharedApplication];
}
NSStatusItem *newStatusItem(void)
{
return [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
}
NSString *newNSString(char *volatile str)
{
return [[NSString alloc] initWithUTF8String: str];
}
void setTitle(NSStatusItem *si, char *title)
{
NSString *t = newNSString(title);
si.button.title = t;
[t release];
}
void runApp(void (*ptr)(void))
{
[NSEvent addLocalMonitorForEventsMatchingMask: NSEventMaskApplicationDefined handler: ^NSEvent * _Nullable (NSEvent *e){
ptr();
return nil;
}];
[NSApp run];
}
NSMenu *newMenu(char *title)
{
NSString *t = newNSString(title);
NSMenu *r = [[NSMenu alloc] initWithTitle: t];
[t release];
return r;
}
NSMenuItem *newMenuItem(char *title)
{
NSString *t = newNSString(title);
NSMenuItem *r = [[NSMenuItem alloc] initWithTitle: t action: NULL keyEquivalent: @""];
[t release];
return r;
}
void assignAction(NSMenuItem *mi, void (*ptr)(void))
{
IOAction *action = [IOAction alloc];
action->ioaction = ptr;
mi.target = action;
mi.action = @selector(callIOAction);
mi.representedObject = action;
[action release];
}
void assignSubMenu(NSMenuItem *mi, NSMenu *m)
{
mi.submenu = m;
}
NSMenuItem *newSeparator(void)
{
return [NSMenuItem separatorItem];
}
void addMenuItem(NSMenu *m, NSMenuItem *i)
{
[m addItem: i];
}
void setStatusItemMenu(NSStatusItem *si, NSMenu *m)
{
si.menu = m;
}