diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-02 22:53:03 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-02 22:53:03 -0400 |
| commit | 8a81650b3da7ce00725336df9e03b38e935c5a65 (patch) | |
| tree | 08af843f0460e7226f305cf7162021ef54e8c3f7 /dialog_darwin.m | |
| parent | 4dd5ceb11d62bd6b9af4847936314a9d8c45707f (diff) | |
Moved it all back; the preemptive multitaksing during an event handler kills us on all platforms. Going to have to restrict ALL GUI accss to happening from one t hread, so going to need to drop uitask entirely and have just a start() callback for startup code and a post() function for posting requests to windows (like channel sends but into a perpetual buffer).
Diffstat (limited to 'dialog_darwin.m')
| -rw-r--r-- | dialog_darwin.m | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/dialog_darwin.m b/dialog_darwin.m new file mode 100644 index 0000000..226ad4b --- /dev/null +++ b/dialog_darwin.m @@ -0,0 +1,45 @@ +// 15 may 2014 + +#include "objc_darwin.h" +#include "_cgo_export.h" +#import <AppKit/NSAlert.h> +#import <AppKit/NSWindow.h> +#import <AppKit/NSApplication.h> + +#define to(T, x) ((T *) (x)) +#define toNSWindow(x) to(NSWindow, (x)) + +static intptr_t alert(id parent, NSString *primary, NSString *secondary, NSAlertStyle style) +{ + NSAlert *box; + + box = [NSAlert new]; + [box setMessageText:primary]; + if (secondary != nil) + [box setInformativeText:secondary]; + [box setAlertStyle:style]; + // TODO is there a named constant? will also need to be changed when we add different dialog types + [box addButtonWithTitle:@"OK"]; + if (parent == nil) + return (intptr_t) [box runModal]; + else { + NSInteger ret; + + [box beginSheetModalForWindow:toNSWindow(parent) + modalDelegate:[NSApp delegate] + didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) + contextInfo:&ret]; + // TODO + return (intptr_t) ret; + } +} + +void msgBox(id parent, id primary, id secondary) +{ + alert(parent, (NSString *) primary, (NSString *) secondary, NSInformationalAlertStyle); +} + +void msgBoxError(id parent, id primary, id secondary) +{ + alert(parent, (NSString *) primary, (NSString *) secondary, NSCriticalAlertStyle); +} |
