Migrated prefsize_darwin.go to plain Objective-C. Not much left...!
This commit is contained in:
parent
5b5c76021e
commit
b73d4e9010
|
@ -4,6 +4,7 @@ package ui
|
||||||
|
|
||||||
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
|
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
|
||||||
// #include "objc_darwin.h"
|
// #include "objc_darwin.h"
|
||||||
|
// #include "prefsize_darwin.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -17,14 +18,20 @@ var (
|
||||||
|
|
||||||
// standard case: control immediately passed in
|
// standard case: control immediately passed in
|
||||||
func controlPrefSize(control C.id) (width int, height int) {
|
func controlPrefSize(control C.id) (width int, height int) {
|
||||||
C.objc_msgSend_noargs(control, _sizeToFit)
|
r := C.controlPrefSize(control)
|
||||||
r := C.objc_msgSend_stret_rect_noargs(control, _frame)
|
|
||||||
return int(r.width), int(r.height)
|
return int(r.width), int(r.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSTableView is actually in a NSScrollView so we have to get it out first
|
// NSTableView is actually in a NSScrollView so we have to get it out first
|
||||||
func listboxPrefSize(control C.id) (width int, height int) {
|
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){
|
var prefsizefuncs = [nctypes]func(C.id) (int, int){
|
||||||
|
@ -34,7 +41,7 @@ var prefsizefuncs = [nctypes]func(C.id) (int, int){
|
||||||
c_lineedit: controlPrefSize,
|
c_lineedit: controlPrefSize,
|
||||||
c_label: controlPrefSize,
|
c_label: controlPrefSize,
|
||||||
c_listbox: listboxPrefSize,
|
c_listbox: listboxPrefSize,
|
||||||
c_progressbar: controlPrefSize,
|
c_progressbar: pbarPrefSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysData) preferredSize() (width int, height int) {
|
func (s *sysData) preferredSize() (width int, height int) {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
/* 15 may 2014 */
|
||||||
|
|
||||||
|
extern struct xsize controlPrefSize(id);
|
||||||
|
extern struct xsize listboxPrefSize(id);
|
||||||
|
extern struct xsize pbarPrefSize(id);
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue