diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-05 00:53:26 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-05 00:53:26 -0400 |
| commit | 60de6d05c5c870bbde6ac82e07db0dd83a7bfc1a (patch) | |
| tree | 300df1b8356ebc092a2456faf1b02ffe952bc319 /dialog_darwin.m | |
| parent | 8e0a38dc470ee8ba7c209e5e33fa46c27469eabb (diff) | |
Implemented message box transience on Mac OS X.
Diffstat (limited to 'dialog_darwin.m')
| -rw-r--r-- | dialog_darwin.m | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/dialog_darwin.m b/dialog_darwin.m index b147c5a..6bbad61 100644 --- a/dialog_darwin.m +++ b/dialog_darwin.m @@ -3,7 +3,27 @@ #include "objc_darwin.h" #import <AppKit/NSAlert.h> -static void alert(NSString *primary, NSString *secondary, NSAlertStyle style) +// see delegateuitask_darwin.m +// in this case, NSWindow.h includes NSApplication.h + +#ifdef MAC_OS_X_VERSION_10_7 +#undef MAC_OS_X_VERSION_MIN_REQUIRED +#undef MAC_OS_X_VERSION_MAX_ALLOWED +#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_7 +#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_7 +#endif +#import <AppKit/NSApplication.h> +#undef MAC_OS_X_VERSION_MIN_REQUIRED +#undef MAC_OS_X_VERSION_MAX_ALLOWED +#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_6 +#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_6 + +#import <AppKit/NSWindow.h> + +#define to(T, x) ((T *) (x)) +#define toNSWindow(x) to(NSWindow, (x)) + +static void alert(id parent, NSString *primary, NSString *secondary, NSAlertStyle style) { NSAlert *box; @@ -14,15 +34,21 @@ static void alert(NSString *primary, NSString *secondary, NSAlertStyle style) [box setAlertStyle:style]; // TODO is there a named constant? will also need to be changed when we add different dialog types [box addButtonWithTitle:@"OK"]; - [box runModal]; + if (parent == nil) + [box runModal]; + else + [box beginSheetModalForWindow:toNSWindow(parent) + modalDelegate:[NSApp delegate] + didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) + contextInfo:NULL]; } -void msgBox(id primary, id secondary) +void msgBox(id parent, id primary, id secondary) { - alert((NSString *) primary, (NSString *) secondary, NSInformationalAlertStyle); + alert(parent, (NSString *) primary, (NSString *) secondary, NSInformationalAlertStyle); } -void msgBoxError(id primary, id secondary) +void msgBoxError(id parent, id primary, id secondary) { - alert((NSString *) primary, (NSString *) secondary, NSCriticalAlertStyle); + alert(parent, (NSString *) primary, (NSString *) secondary, NSCriticalAlertStyle); } |
