Undid the whole yoff spiel on Mac OS X. NOW I'll merge the new sizing system into that backend.
This commit is contained in:
parent
4a68c3cb7a
commit
5e17d64b09
|
@ -33,12 +33,6 @@ struct xpoint {
|
||||||
intptr_t y;
|
intptr_t y;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xprefsize {
|
|
||||||
intptr_t width;
|
|
||||||
intptr_t height;
|
|
||||||
intptr_t yoff;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* objc_darwin.m */
|
/* objc_darwin.m */
|
||||||
extern id toNSString(char *);
|
extern id toNSString(char *);
|
||||||
extern char *fromNSString(id);
|
extern char *fromNSString(id);
|
||||||
|
@ -92,11 +86,10 @@ extern uintptr_t listboxIndexesNext(id, uintptr_t);
|
||||||
extern intptr_t listboxLen(id);
|
extern intptr_t listboxLen(id);
|
||||||
|
|
||||||
/* prefsize_darwin.m */
|
/* prefsize_darwin.m */
|
||||||
extern struct xprefsize controlPrefSize(id, BOOL);
|
extern struct xsize controlPrefSize(id);
|
||||||
extern struct xprefsize labelPrefSize(id, BOOL);
|
extern struct xsize listboxPrefSize(id);
|
||||||
extern struct xprefsize listboxPrefSize(id, BOOL);
|
extern struct xsize pbarPrefSize(id);
|
||||||
extern struct xprefsize pbarPrefSize(id, BOOL);
|
extern struct xsize areaPrefSize(id);
|
||||||
extern struct xprefsize areaPrefSize(id, BOOL);
|
|
||||||
|
|
||||||
/* sysdata_darwin.m */
|
/* sysdata_darwin.m */
|
||||||
extern void addControl(id, id);
|
extern void addControl(id, id);
|
||||||
|
|
|
@ -10,46 +10,40 @@ Cocoa doesn't provide a reliable way to get the preferred size of a control (you
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// standard case: control immediately passed in
|
// standard case: control immediately passed in
|
||||||
func controlPrefSize(control C.id, alternate C.BOOL) (width int, height int, yoff int) {
|
func controlPrefSize(control C.id) (width int, height int) {
|
||||||
r := C.controlPrefSize(control, alternate)
|
r := C.controlPrefSize(control)
|
||||||
return int(r.width), int(r.height), int(r.yoff)
|
return int(r.width), int(r.height)
|
||||||
}
|
|
||||||
|
|
||||||
// Labels have special yoff calculation
|
|
||||||
func labelPrefSize(control C.id, alternate C.BOOL) (width int, height int, yoff int) {
|
|
||||||
r := C.labelPrefSize(control, alternate)
|
|
||||||
return int(r.width), int(r.height), int(r.yoff)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, alternate C.BOOL) (width int, height int, yoff int) {
|
func listboxPrefSize(control C.id) (width int, height int) {
|
||||||
r := C.listboxPrefSize(control, alternate)
|
r := C.listboxPrefSize(control, alternate)
|
||||||
return int(r.width), int(r.height), int(r.yoff)
|
return int(r.width), int(r.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// and for type checking reasons, progress bars are separate despite responding to -[sizeToFit]
|
// and for type checking reasons, progress bars are separate despite responding to -[sizeToFit]
|
||||||
func pbarPrefSize(control C.id, alternate C.BOOL) (width int, height int, yoff int) {
|
func pbarPrefSize(control C.id) (width int, height int) {
|
||||||
r := C.pbarPrefSize(control, alternate)
|
r := C.pbarPrefSize(control)
|
||||||
return int(r.width), int(r.height), int(r.yoff)
|
return int(r.width), int(r.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Areas know their own preferred size
|
// Areas know their own preferred size
|
||||||
func areaPrefSize(control C.id, alternate C.BOOL) (width int, height int, yoff int) {
|
func areaPrefSize(control C.id) (width int, height int) {
|
||||||
r := C.areaPrefSize(control, alternate)
|
r := C.areaPrefSize(control)
|
||||||
return int(r.width), int(r.height), int(r.yoff)
|
return int(r.width), int(r.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
var prefsizefuncs = [nctypes]func(C.id, C.BOOL) (int, int, int){
|
var prefsizefuncs = [nctypes]func(C.id) (int, int){
|
||||||
c_button: controlPrefSize,
|
c_button: controlPrefSize,
|
||||||
c_checkbox: controlPrefSize,
|
c_checkbox: controlPrefSize,
|
||||||
c_combobox: controlPrefSize,
|
c_combobox: controlPrefSize,
|
||||||
c_lineedit: controlPrefSize,
|
c_lineedit: controlPrefSize,
|
||||||
c_label: labelPrefSize,
|
c_label: controlPrefSize,
|
||||||
c_listbox: listboxPrefSize,
|
c_listbox: listboxPrefSize,
|
||||||
c_progressbar: pbarPrefSize,
|
c_progressbar: pbarPrefSize,
|
||||||
c_area: areaPrefSize,
|
c_area: areaPrefSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysData) preferredSize() (width int, height int, yoff int) {
|
func (s *sysData) preferredSize() (width int, height int) {
|
||||||
return prefsizefuncs[s.ctype](s.id, toBOOL(s.alternate))
|
return prefsizefuncs[s.ctype](s.id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
#include "objc_darwin.h"
|
#include "objc_darwin.h"
|
||||||
#import <AppKit/NSControl.h>
|
#import <AppKit/NSControl.h>
|
||||||
#import <AppKit/NSView.h>
|
#import <AppKit/NSView.h>
|
||||||
#import <AppKit/NSTextField.h>
|
|
||||||
#import <AppKit/NSScrollView.h>
|
#import <AppKit/NSScrollView.h>
|
||||||
#import <AppKit/NSTableView.h>
|
#import <AppKit/NSTableView.h>
|
||||||
#import <AppKit/NSProgressIndicator.h>
|
#import <AppKit/NSProgressIndicator.h>
|
||||||
|
|
||||||
#define to(T, x) ((T *) (x))
|
#define to(T, x) ((T *) (x))
|
||||||
#define toNSControl(x) to(NSControl, (x))
|
#define toNSControl(x) to(NSControl, (x))
|
||||||
#define toNSTextField(x) to(NSTextField, (x))
|
|
||||||
#define toNSScrollView(x) to(NSScrollView, (x))
|
#define toNSScrollView(x) to(NSScrollView, (x))
|
||||||
#define toNSTableView(x) to(NSTableView, (x))
|
#define toNSTableView(x) to(NSTableView, (x))
|
||||||
#define toNSProgressIndicator(x) to(NSProgressIndicator, (x))
|
#define toNSProgressIndicator(x) to(NSProgressIndicator, (x))
|
||||||
|
@ -19,87 +17,58 @@
|
||||||
#define listboxInScrollView(x) toNSTableView(inScrollView((x)))
|
#define listboxInScrollView(x) toNSTableView(inScrollView((x)))
|
||||||
#define areaInScrollView(x) inScrollView((x))
|
#define areaInScrollView(x) inScrollView((x))
|
||||||
|
|
||||||
struct xprefsize controlPrefSize(id control, BOOL alternate)
|
struct xsize controlPrefSize(id control)
|
||||||
{
|
{
|
||||||
NSControl *c;
|
NSControl *c;
|
||||||
NSRect r;
|
NSRect r;
|
||||||
struct xprefsize s;
|
struct xsize s;
|
||||||
|
|
||||||
c = toNSControl(control);
|
c = toNSControl(control);
|
||||||
[c sizeToFit];
|
[c sizeToFit];
|
||||||
r = [c frame];
|
r = [c frame];
|
||||||
s.width = (intptr_t) r.size.width;
|
s.width = (intptr_t) r.size.width;
|
||||||
s.height = (intptr_t) r.size.height;
|
s.height = (intptr_t) r.size.height;
|
||||||
s.yoff = 0; // no yoff for most controls
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xprefsize labelPrefSize(id control, BOOL alternate)
|
struct xsize listboxPrefSize(id scrollview)
|
||||||
{
|
|
||||||
NSControl *c;
|
|
||||||
NSRect r;
|
|
||||||
struct xprefsize s;
|
|
||||||
|
|
||||||
c = toNSControl(control);
|
|
||||||
[c sizeToFit];
|
|
||||||
r = [c frame];
|
|
||||||
s.width = (intptr_t) r.size.width;
|
|
||||||
s.height = (intptr_t) r.size.height;
|
|
||||||
s.yoff = 0; // no yoff for standalone labels
|
|
||||||
if (!alternate) {
|
|
||||||
// TODO this seems really hacky
|
|
||||||
// temporarily enable the border, compute its height, and take the height difference
|
|
||||||
[toNSTextField(c) setBordered:YES];
|
|
||||||
[c sizeToFit];
|
|
||||||
r = [c frame];
|
|
||||||
[toNSTextField(c) setBordered:NO];
|
|
||||||
// - 1 since the sizes are exclusive (????? TODO)
|
|
||||||
s.yoff = ((intptr_t) r.size.height) - s.height - 1;
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct xprefsize listboxPrefSize(id scrollview, BOOL altenrate)
|
|
||||||
{
|
{
|
||||||
NSTableView *c;
|
NSTableView *c;
|
||||||
NSRect r;
|
NSRect r;
|
||||||
struct xprefsize s;
|
struct xsize s;
|
||||||
|
|
||||||
c = listboxInScrollView(toNSScrollView(scrollview));
|
c = listboxInScrollView(toNSScrollView(scrollview));
|
||||||
[c sizeToFit];
|
[c sizeToFit];
|
||||||
r = [c frame];
|
r = [c frame];
|
||||||
s.width = (intptr_t) r.size.width;
|
s.width = (intptr_t) r.size.width;
|
||||||
s.height = (intptr_t) r.size.height;
|
s.height = (intptr_t) r.size.height;
|
||||||
s.yoff = 0; // no yoff for listboxes
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xprefsize pbarPrefSize(id control, BOOL alternate)
|
struct xsize pbarPrefSize(id control)
|
||||||
{
|
{
|
||||||
NSProgressIndicator *c;
|
NSProgressIndicator *c;
|
||||||
NSRect r;
|
NSRect r;
|
||||||
struct xprefsize s;
|
struct xsize s;
|
||||||
|
|
||||||
c = toNSProgressIndicator(control);
|
c = toNSProgressIndicator(control);
|
||||||
[c sizeToFit];
|
[c sizeToFit];
|
||||||
r = [c frame];
|
r = [c frame];
|
||||||
s.width = (intptr_t) r.size.width;
|
s.width = (intptr_t) r.size.width;
|
||||||
s.height = (intptr_t) r.size.height;
|
s.height = (intptr_t) r.size.height;
|
||||||
s.yoff = 0; // no yoff for progress bars
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xprefsize areaPrefSize(id scrollview, BOOL alternate)
|
struct xsize areaPrefSize(id scrollview)
|
||||||
{
|
{
|
||||||
NSView *c;
|
NSView *c;
|
||||||
NSRect r;
|
NSRect r;
|
||||||
struct xprefsize s;
|
struct xsize s;
|
||||||
|
|
||||||
c = areaInScrollView(toNSScrollView(scrollview));
|
c = areaInScrollView(toNSScrollView(scrollview));
|
||||||
// don't size to fit; the frame size is already the size we want
|
// don't size to fit; the frame size is already the size we want
|
||||||
r = [c frame];
|
r = [c frame];
|
||||||
s.width = (intptr_t) r.size.width;
|
s.width = (intptr_t) r.size.width;
|
||||||
s.height = (intptr_t) r.size.height;
|
s.height = (intptr_t) r.size.height;
|
||||||
s.yoff = 0; // no yoff for areas
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue