summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-05 00:53:26 -0400
committerPietro Gagliardi <[email protected]>2014-06-05 00:53:26 -0400
commit60de6d05c5c870bbde6ac82e07db0dd83a7bfc1a (patch)
tree300df1b8356ebc092a2456faf1b02ffe952bc319
parent8e0a38dc470ee8ba7c209e5e33fa46c27469eabb (diff)
Implemented message box transience on Mac OS X.
-rw-r--r--delegateuitask_darwin.m6
-rw-r--r--dialog_darwin.go19
-rw-r--r--dialog_darwin.m38
-rw-r--r--objc_darwin.h4
4 files changed, 52 insertions, 15 deletions
diff --git a/delegateuitask_darwin.m b/delegateuitask_darwin.m
index a49fda3..023cb49 100644
--- a/delegateuitask_darwin.m
+++ b/delegateuitask_darwin.m
@@ -9,6 +9,7 @@
// see the hack below; we'll include everything first just in case some other headers get included below; if the hack ever gets resolved, we can use the ones below instead
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSEvent.h>
+#import <AppKit/NSAlert.h>
// HACK.
// Apple's header files are bugged: there's an enum that was introduced in 10.7 with new values added in 10.8, but instead of wrapping the whole enum in a version check, they wrap just the fields. This means that on 10.6 that enum will be empty, which is illegal.
@@ -33,6 +34,7 @@
#import <AppKit/NSWindow.h>
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSEvent.h>
+#import <AppKit/NSAlert.h>
extern NSRect dummyRect;
@@ -68,6 +70,10 @@ extern NSRect dummyRect;
return NSTerminateCancel;
}
+- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
+}
+
@end
id makeAppDelegate(void)
diff --git a/dialog_darwin.go b/dialog_darwin.go
index 81819ba..ef1cd6c 100644
--- a/dialog_darwin.go
+++ b/dialog_darwin.go
@@ -9,10 +9,15 @@ import (
// #include "objc_darwin.h"
import "C"
-func _msgBox(primarytext string, secondarytext string, style uintptr) {
+func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) {
ret := make(chan struct{})
defer close(ret)
uitask <- func() {
+ var pwin C.id = nil
+
+ if parent != nil {
+ pwin = parent.sysData.id
+ }
primary := toNSString(primarytext)
secondary := C.id(nil)
if secondarytext != "" {
@@ -20,19 +25,19 @@ func _msgBox(primarytext string, secondarytext string, style uintptr) {
}
switch style {
case 0: // normal
- C.msgBox(primary, secondary)
+ C.msgBox(pwin, primary, secondary)
case 1: // error
- C.msgBoxError(primary, secondary)
+ C.msgBoxError(pwin, primary, secondary)
}
ret <- struct{}{}
}
<-ret
}
-func msgBox(primarytext string, secondarytext string) {
- _msgBox(primarytext, secondarytext, 0)
+func msgBox(parent *Window, primarytext string, secondarytext string) {
+ _msgBox(parent, primarytext, secondarytext, 0)
}
-func msgBoxError(primarytext string, secondarytext string) {
- _msgBox(primarytext, secondarytext, 1)
+func msgBoxError(parent *Window, primarytext string, secondarytext string) {
+ _msgBox(parent, primarytext, secondarytext, 1)
}
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);
}
diff --git a/objc_darwin.h b/objc_darwin.h
index e26db6f..fd2058a 100644
--- a/objc_darwin.h
+++ b/objc_darwin.h
@@ -61,8 +61,8 @@ extern void breakMainLoop(void);
extern void cocoaMainLoop(void);
/* dialog_darwin.m */
-extern void msgBox(id, id);
-extern void msgBoxError(id, id);
+extern void msgBox(id, id, id);
+extern void msgBoxError(id, id, id);
/* listbox_darwin.m */
extern id toListboxItem(id, id);