diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-02 17:13:40 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-02 17:13:40 -0400 |
| commit | 5d339e656b66d00356960ae057969532d34245b4 (patch) | |
| tree | 01f00932aba2a4b996603beeda788995e0f0a382 /prevlib/dialog_darwin.m | |
| parent | 2d7e168e6a350a0cfb52970fbf74c9e37834eaec (diff) | |
Moved everything out of the way pending rewrite.
Diffstat (limited to 'prevlib/dialog_darwin.m')
| -rw-r--r-- | prevlib/dialog_darwin.m | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/prevlib/dialog_darwin.m b/prevlib/dialog_darwin.m new file mode 100644 index 0000000..226ad4b --- /dev/null +++ b/prevlib/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); +} |
