summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-05-15 19:21:54 -0400
committerPietro Gagliardi <[email protected]>2014-05-15 19:21:54 -0400
commitb73d4e9010a273fd4e3e0b809959387a3b020cb0 (patch)
tree054edebfe408a2c20dbe60aac3e240133a7139d9
parent5b5c76021eda98783f1611da66f4b2f10f09f590 (diff)
Migrated prefsize_darwin.go to plain Objective-C. Not much left...!
-rw-r--r--prefsize_darwin.go15
-rw-r--r--prefsize_darwin.h5
-rw-r--r--prefsize_darwin.m60
3 files changed, 76 insertions, 4 deletions
diff --git a/prefsize_darwin.go b/prefsize_darwin.go
index 8b56ef7..8cea526 100644
--- a/prefsize_darwin.go
+++ b/prefsize_darwin.go
@@ -4,6 +4,7 @@ package ui
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
// #include "objc_darwin.h"
+// #include "prefsize_darwin.h"
import "C"
/*
@@ -17,14 +18,20 @@ var (
// standard case: control immediately passed in
func controlPrefSize(control C.id) (width int, height int) {
- C.objc_msgSend_noargs(control, _sizeToFit)
- r := C.objc_msgSend_stret_rect_noargs(control, _frame)
+ r := C.controlPrefSize(control)
return int(r.width), int(r.height)
}
// NSTableView is actually in a NSScrollView so we have to get it out first
func listboxPrefSize(control C.id) (width int, height int) {
- return controlPrefSize(listboxInScrollView(control))
+ r := C.listboxPrefSize(control)
+ return int(r.width), int(r.height)
+}
+
+// and for type checking reasons, progress bars are separate despite responding to -[sizeToFit]
+func pbarPrefSize(control C.id) (width int, height int) {
+ r := C.pbarPrefSize(control)
+ return int(r.width), int(r.height)
}
var prefsizefuncs = [nctypes]func(C.id) (int, int){
@@ -34,7 +41,7 @@ var prefsizefuncs = [nctypes]func(C.id) (int, int){
c_lineedit: controlPrefSize,
c_label: controlPrefSize,
c_listbox: listboxPrefSize,
- c_progressbar: controlPrefSize,
+ c_progressbar: pbarPrefSize,
}
func (s *sysData) preferredSize() (width int, height int) {
diff --git a/prefsize_darwin.h b/prefsize_darwin.h
new file mode 100644
index 0000000..afe1573
--- /dev/null
+++ b/prefsize_darwin.h
@@ -0,0 +1,5 @@
+/* 15 may 2014 */
+
+extern struct xsize controlPrefSize(id);
+extern struct xsize listboxPrefSize(id);
+extern struct xsize pbarPrefSize(id);
diff --git a/prefsize_darwin.m b/prefsize_darwin.m
new file mode 100644
index 0000000..40f6b11
--- /dev/null
+++ b/prefsize_darwin.m
@@ -0,0 +1,60 @@
+// 15 may 2014
+
+#include "objc_darwin.h"
+#include "prefsize_darwin.h"
+#include <AppKit/NSControl.h>
+#include <AppKit/NSScrollView.h>
+#include <AppKit/NSTableView.h>
+#include <AppKit/NSProgressIndicator.h>
+
+#define to(T, x) ((T *) (x))
+#define toNSControl(x) to(NSControl, (x))
+#define toNSScrollView(x) to(NSScrollView, (x))
+#define toNSTableView(x) to(NSTableView, (x))
+#define toNSProgressIndicator(x) to(NSProgressIndicator, (x))
+
+#define inScrollView(x) ([toNSScrollView((x)) documentView])
+#define listboxInScrollView(x) toNSTableView(inScrollView((x)))
+#define areaInScrollView(x) inScrollView((x))
+
+struct xsize controlPrefSize(id control)
+{
+ NSControl *c;
+ NSRect r;
+ struct xsize s;
+
+ c = toNSControl(control);
+ [c sizeToFit];
+ r = [c frame];
+ s.width = (intptr_t) r.size.width;
+ s.height = (intptr_t) r.size.height;
+ return s;
+}
+
+struct xsize listboxPrefSize(id scrollview)
+{
+ NSTableView *c;
+ NSRect r;
+ struct xsize s;
+
+ c = listboxInScrollView(toNSScrollView(scrollview));
+ [c sizeToFit];
+ r = [c frame];
+ s.width = (intptr_t) r.size.width;
+ s.height = (intptr_t) r.size.height;
+ return s;
+}
+
+struct xsize pbarPrefSize(id control)
+{
+ NSProgressIndicator *c;
+ NSRect r;
+ struct xsize s;
+
+ c = toNSProgressIndicator(control);
+ [c sizeToFit];
+ r = [c frame];
+ s.width = (intptr_t) r.size.width;
+ s.height = (intptr_t) r.size.height;
+ return s;
+} \ No newline at end of file