2014-05-15 18:21:54 -05:00
|
|
|
// 15 may 2014
|
|
|
|
|
|
|
|
#include "objc_darwin.h"
|
2014-05-20 07:08:55 -05:00
|
|
|
#import <AppKit/NSControl.h>
|
2014-06-25 15:32:07 -05:00
|
|
|
#import <AppKit/NSView.h>
|
|
|
|
#import <AppKit/NSTextField.h>
|
2014-05-20 07:08:55 -05:00
|
|
|
#import <AppKit/NSScrollView.h>
|
|
|
|
#import <AppKit/NSTableView.h>
|
|
|
|
#import <AppKit/NSProgressIndicator.h>
|
2014-05-15 18:21:54 -05:00
|
|
|
|
|
|
|
#define to(T, x) ((T *) (x))
|
|
|
|
#define toNSControl(x) to(NSControl, (x))
|
2014-06-25 15:32:07 -05:00
|
|
|
#define toNSTextField(x) to(NSTextField, (x))
|
2014-05-15 18:21:54 -05:00
|
|
|
#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))
|
|
|
|
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize controlPrefSize(id control, BOOL alternate)
|
2014-05-15 18:21:54 -05:00
|
|
|
{
|
|
|
|
NSControl *c;
|
|
|
|
NSRect r;
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize s;
|
2014-05-15 18:21:54 -05:00
|
|
|
|
|
|
|
c = toNSControl(control);
|
|
|
|
[c sizeToFit];
|
|
|
|
r = [c frame];
|
|
|
|
s.width = (intptr_t) r.size.width;
|
|
|
|
s.height = (intptr_t) r.size.height;
|
2014-06-25 15:32:07 -05:00
|
|
|
s.yoff = 0; // no yoff for most controls
|
2014-05-15 18:21:54 -05:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize labelPrefSize(id control, BOOL alternate)
|
|
|
|
{
|
|
|
|
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)
|
2014-05-15 18:21:54 -05:00
|
|
|
{
|
|
|
|
NSTableView *c;
|
|
|
|
NSRect r;
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize s;
|
2014-05-15 18:21:54 -05:00
|
|
|
|
|
|
|
c = listboxInScrollView(toNSScrollView(scrollview));
|
|
|
|
[c sizeToFit];
|
|
|
|
r = [c frame];
|
|
|
|
s.width = (intptr_t) r.size.width;
|
|
|
|
s.height = (intptr_t) r.size.height;
|
2014-06-25 15:32:07 -05:00
|
|
|
s.yoff = 0; // no yoff for listboxes
|
2014-05-15 18:21:54 -05:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize pbarPrefSize(id control, BOOL alternate)
|
2014-05-15 18:21:54 -05:00
|
|
|
{
|
|
|
|
NSProgressIndicator *c;
|
|
|
|
NSRect r;
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize s;
|
2014-05-15 18:21:54 -05:00
|
|
|
|
|
|
|
c = toNSProgressIndicator(control);
|
|
|
|
[c sizeToFit];
|
|
|
|
r = [c frame];
|
|
|
|
s.width = (intptr_t) r.size.width;
|
|
|
|
s.height = (intptr_t) r.size.height;
|
2014-06-25 15:32:07 -05:00
|
|
|
s.yoff = 0; // no yoff for progress bars
|
2014-05-15 18:21:54 -05:00
|
|
|
return s;
|
2014-06-06 22:03:29 -05:00
|
|
|
}
|
|
|
|
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize areaPrefSize(id scrollview, BOOL alternate)
|
2014-06-06 22:03:29 -05:00
|
|
|
{
|
|
|
|
NSView *c;
|
|
|
|
NSRect r;
|
2014-06-25 15:32:07 -05:00
|
|
|
struct xprefsize s;
|
2014-06-06 22:03:29 -05:00
|
|
|
|
|
|
|
c = areaInScrollView(toNSScrollView(scrollview));
|
|
|
|
// don't size to fit; the frame size is already the size we want
|
|
|
|
r = [c frame];
|
|
|
|
s.width = (intptr_t) r.size.width;
|
|
|
|
s.height = (intptr_t) r.size.height;
|
2014-06-25 15:32:07 -05:00
|
|
|
s.yoff = 0; // no yoff for areas
|
2014-06-06 22:03:29 -05:00
|
|
|
return s;
|
2014-06-25 15:32:07 -05:00
|
|
|
}
|