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>
|
|
|
|
#import <AppKit/NSScrollView.h>
|
|
|
|
#import <AppKit/NSTableView.h>
|
|
|
|
#import <AppKit/NSProgressIndicator.h>
|
2014-06-26 09:06:58 -05:00
|
|
|
#import <AppKit/NSView.h>
|
|
|
|
// needed for the methods called by alignmentInfo()
|
|
|
|
#import <AppKit/NSLayoutConstraint.h>
|
2014-05-15 18:21:54 -05:00
|
|
|
|
|
|
|
#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))
|
2014-06-26 09:06:58 -05:00
|
|
|
#define toNSView(x) to(NSView, (x))
|
2014-05-15 18:21:54 -05:00
|
|
|
|
|
|
|
#define inScrollView(x) ([toNSScrollView((x)) documentView])
|
|
|
|
#define listboxInScrollView(x) toNSTableView(inScrollView((x)))
|
|
|
|
#define areaInScrollView(x) inScrollView((x))
|
|
|
|
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize controlPrefSize(id control)
|
2014-05-15 18:21:54 -05:00
|
|
|
{
|
|
|
|
NSControl *c;
|
|
|
|
NSRect r;
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize 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;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize listboxPrefSize(id scrollview)
|
2014-05-15 18:21:54 -05:00
|
|
|
{
|
|
|
|
NSTableView *c;
|
|
|
|
NSRect r;
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize 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;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize pbarPrefSize(id control)
|
2014-05-15 18:21:54 -05:00
|
|
|
{
|
|
|
|
NSProgressIndicator *c;
|
|
|
|
NSRect r;
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize 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;
|
|
|
|
return s;
|
2014-06-06 22:03:29 -05:00
|
|
|
}
|
|
|
|
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize areaPrefSize(id scrollview)
|
2014-06-06 22:03:29 -05:00
|
|
|
{
|
|
|
|
NSView *c;
|
|
|
|
NSRect r;
|
2014-06-25 23:23:29 -05:00
|
|
|
struct xsize 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;
|
|
|
|
return s;
|
2014-06-25 15:32:07 -05:00
|
|
|
}
|
2014-06-26 09:06:58 -05:00
|
|
|
|
|
|
|
struct xalignment alignmentInfo(id c, struct xrect newrect)
|
|
|
|
{
|
|
|
|
NSView *v;
|
|
|
|
struct xalignment a;
|
|
|
|
NSRect r;
|
|
|
|
|
|
|
|
v = toNSView(c);
|
|
|
|
r = NSMakeRect((CGFloat) newrect.x,
|
|
|
|
(CGFloat) newrect.y,
|
|
|
|
(CGFloat) newrect.width,
|
|
|
|
(CGFloat) newrect.height);
|
|
|
|
r = [v alignmentRectForFrame:r];
|
|
|
|
a.alignmentRect.x = (intptr_t) r.origin.x;
|
|
|
|
a.alignmentRect.y = (intptr_t) r.origin.y;
|
|
|
|
a.alignmentRect.width = (intptr_t) r.size.width;
|
|
|
|
a.alignmentRect.height = (intptr_t) r.size.height;
|
|
|
|
a.baseline = (intptr_t) [v baselineOffsetFromBottom];
|
|
|
|
return a;
|
|
|
|
}
|