summaryrefslogtreecommitdiff
path: root/tizen/src/ns_event.m
blob: 3de382fde23f963abbceb93eab4753f777ef7fe4 (plain)
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
#import <Cocoa/Cocoa.h>
#import "ns_event.h"

// ns event loop for receive the events from cocoa framework
void ns_event_loop(int* keepRunning)
{
    NSDate* distantFuture;

    NSRunLoop* theRunLoop = [NSRunLoop currentRunLoop];
    do {
         distantFuture = [NSDate dateWithTimeIntervalSinceNow:0.5];
    }
    while (*keepRunning && [theRunLoop runMode:NSDefaultRunLoopMode beforeDate:distantFuture]);
    // return [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
}

@interface Runner : NSObject
{
    @public void (*func_void)();
    @public void (*func_bool)(bool bArg);
    @public bool isTrue;
}
- (void)run;
@end

@implementation Runner
- (void)run;
{
    if (self->func_void) {
        self->func_void();
    }
    if (self->func_bool) {
        self->func_bool(self->isTrue);
    }
}
@end

void ns_run_in_event_loop(void (*func)())
{
    Runner *runner = [[Runner alloc] init];
    runner->func_void = func;
    [runner performSelectorOnMainThread:@selector(run) withObject:nil waitUntilDone:YES];
    [runner release];
}

void ns_run_in_event_loop_with_bool(void (*func)(bool bArg), bool isTrue)
{
    Runner *runner = [[Runner alloc] init];
    runner->func_bool = func;
    runner->isTrue = isTrue;
    [runner performSelectorOnMainThread:@selector(run) withObject:nil waitUntilDone:YES];
    [runner release];
}

void set_application_icon(char *path)
{
    NSString *iconPath = [[NSString alloc] initWithUTF8String:path];
    NSImage *iconImage = [[NSImage alloc] initWithContentsOfFile:iconPath];
    [[NSApplication sharedApplication] setApplicationIconImage:iconImage];

    [iconImage release];
    [iconPath release];
}