2013-03-15 13:11:33 +00:00
|
|
|
@implementation CocoaCheckButton : NSButton
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(id) initWith:(phoenix::CheckButton&)checkButtonReference {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
|
|
|
|
checkButton = &checkButtonReference;
|
|
|
|
|
|
|
|
[self setTarget:self];
|
|
|
|
[self setAction:@selector(activate:)];
|
2013-11-28 10:29:01 +00:00
|
|
|
[self setBezelStyle:NSRegularSquareBezelStyle];
|
|
|
|
[self setButtonType:NSOnOffButton];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(IBAction) activate:(id)sender {
|
2013-03-15 13:11:33 +00:00
|
|
|
checkButton->state.checked = [self state] != NSOffState;
|
|
|
|
if(checkButton->onToggle) checkButton->onToggle();
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
namespace phoenix {
|
|
|
|
|
|
|
|
Size pCheckButton::minimumSize() {
|
|
|
|
Size size = Font::size(checkButton.font(), checkButton.state.text);
|
2013-11-28 10:29:01 +00:00
|
|
|
|
|
|
|
if(checkButton.state.orientation == Orientation::Horizontal) {
|
|
|
|
size.width += checkButton.state.image.width;
|
|
|
|
size.height = max(checkButton.state.image.height, size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(checkButton.state.orientation == Orientation::Vertical) {
|
|
|
|
size.width = max(checkButton.state.image.width, size.width);
|
|
|
|
size.height += checkButton.state.image.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {size.width + 20, size.height + 4};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::setChecked(bool checked) {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setState:checked ? NSOnState : NSOffState];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
void pCheckButton::setGeometry(Geometry geometry) {
|
2013-04-09 13:31:46 +00:00
|
|
|
pWidget::setGeometry({
|
2013-11-28 10:29:01 +00:00
|
|
|
geometry.x - 2, geometry.y - 2,
|
|
|
|
geometry.width + 4, geometry.height + 4
|
2013-04-09 13:31:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCheckButton::setImage(const image& image, Orientation orientation) {
|
|
|
|
@autoreleasepool {
|
|
|
|
if(image.empty()) {
|
|
|
|
[cocoaView setImage:nil];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[cocoaView setImage:NSMakeImage(image)];
|
|
|
|
|
|
|
|
if(orientation == Orientation::Horizontal) [cocoaView setImagePosition:NSImageLeft];
|
|
|
|
if(orientation == Orientation::Vertical ) [cocoaView setImagePosition:NSImageAbove];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
void pCheckButton::setText(string text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::constructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaCheckButton = [[CocoaCheckButton alloc] initWith:checkButton];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::destructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|