Migrated prefsize_darwin.go to plain Objective-C. Not much left...!

This commit is contained in:
Pietro Gagliardi 2014-05-15 19:21:54 -04:00
parent 5b5c76021e
commit b73d4e9010
3 changed files with 76 additions and 4 deletions

View File

@ -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) {

5
prefsize_darwin.h Normal file
View File

@ -0,0 +1,5 @@
/* 15 may 2014 */
extern struct xsize controlPrefSize(id);
extern struct xsize listboxPrefSize(id);
extern struct xsize pbarPrefSize(id);

60
prefsize_darwin.m Normal file
View File

@ -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;
}