summaryrefslogtreecommitdiff
path: root/dialog_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-02 18:37:25 -0500
committerPietro Gagliardi <[email protected]>2014-03-02 18:37:25 -0500
commite20b4684729f6278bfb7fe60c68f2b80626fe062 (patch)
tree78e4a0b5a85ee42ba656c565e884cf80065c8e6e /dialog_darwin.go
parent234b724403bb93171a0eac72a8c24db3879c5900 (diff)
Added the Mac OS X implementation of messageboxes.
Diffstat (limited to 'dialog_darwin.go')
-rw-r--r--dialog_darwin.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/dialog_darwin.go b/dialog_darwin.go
new file mode 100644
index 0000000..ff7e166
--- /dev/null
+++ b/dialog_darwin.go
@@ -0,0 +1,52 @@
+// 2 march 2014
+package ui
+
+import (
+ // ...
+)
+
+// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
+// #include "objc_darwin.h"
+import "C"
+
+// NSAlert styles.
+const (
+ _NSWarningAlertStyle = 0 // default
+ _NSInformationalAlertStyle = 1
+ _NSCriticalAlertStyle = 2
+)
+
+var (
+ _NSAlert = objc_getClass("NSAlert")
+
+ _setMessageText = sel_getUid("setMessageText:")
+ _setInformativeText = sel_getUid("setInformativeText:")
+ _setAlertStyle = sel_getUid("setAlertStyle:")
+ _addButtonWithTitle = sel_getUid("addButtonWithTitle:")
+ _runModal = sel_getUid("runModal")
+)
+
+func _msgBox(title string, text string, style uintptr, button0 string) {
+ ret := make(chan struct{})
+ defer close(ret)
+ uitask <- func() {
+ box := objc_new(_NSAlert)
+ // TODO is this appropriate for title?
+ C.objc_msgSend_id(box, _setMessageText, toNSString(title))
+ C.objc_msgSend_id(box, _setInformativeText, toNSString(text))
+ objc_msgSend_uint(box, _setAlertStyle, style)
+ C.objc_msgSend_id(box, _addButtonWithTitle, toNSString(button0))
+ C.objc_msgSend_noargs(box, _runModal)
+ ret <- struct{}{}
+ }
+ <-ret
+}
+
+func msgBox(title string, text string) {
+ // TODO _NSInformationalAlertStyle?
+ _msgBox(title, text, _NSWarningAlertStyle, "OK")
+}
+
+func msgBoxError(title string, text string) {
+ _msgBox(title, text, _NSCriticalAlertStyle, "OK")
+}