2014-07-30 11:50:45 -05:00
|
|
|
// 30 july 2014
|
|
|
|
|
|
|
|
#import "objc_darwin.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#define toNSView(x) ((NSView *) (x))
|
2014-08-10 12:28:15 -05:00
|
|
|
#define toNSControl(x) ((NSControl *) (x))
|
|
|
|
|
|
|
|
void parent(id control, id parentid)
|
|
|
|
{
|
|
|
|
[toNSView(parentid) addSubview:toNSView(control)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void controlSetHidden(id control, BOOL hidden)
|
|
|
|
{
|
|
|
|
[toNSView(control) setHidden:hidden];
|
|
|
|
}
|
|
|
|
|
|
|
|
// also fine for NSCells
|
|
|
|
void setStandardControlFont(id control)
|
|
|
|
{
|
|
|
|
[toNSControl(control) setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// also fine for NSCells
|
|
|
|
void setSmallControlFont(id control)
|
|
|
|
{
|
|
|
|
[toNSControl(control) setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
|
|
|
|
}
|
2014-07-30 11:50:45 -05:00
|
|
|
|
2014-08-10 14:56:59 -05:00
|
|
|
// also good for NSProgressIndicator
|
2014-08-09 20:34:56 -05:00
|
|
|
struct xsize controlPreferredSize(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;
|
|
|
|
}
|
|
|
|
|
2014-08-10 13:37:34 -05:00
|
|
|
id newScrollView(id content, BOOL bordered)
|
2014-07-30 11:50:45 -05:00
|
|
|
{
|
|
|
|
NSScrollView *sv;
|
|
|
|
|
2014-08-05 21:02:57 -05:00
|
|
|
sv = [[NSScrollView alloc] initWithFrame:NSZeroRect];
|
2014-07-30 11:50:45 -05:00
|
|
|
[sv setDocumentView:toNSView(content)];
|
|
|
|
[sv setHasHorizontalScroller:YES];
|
|
|
|
[sv setHasVerticalScroller:YES];
|
|
|
|
[sv setAutohidesScrollers:YES];
|
2014-08-10 13:37:34 -05:00
|
|
|
if (bordered)
|
|
|
|
[sv setBorderType:NSBezelBorder];
|
|
|
|
else
|
|
|
|
[sv setBorderType:NSNoBorder];
|
2014-07-30 11:50:45 -05:00
|
|
|
return (id) sv;
|
|
|
|
}
|