2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_CheckLabel)
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
@implementation CocoaCheckLabel : NSButton
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
-(id) initWith:(hiro::mCheckLabel&)checkLabelReference {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
|
|
|
|
checkLabel = &checkLabelReference;
|
|
|
|
|
|
|
|
[self setTarget:self];
|
|
|
|
[self setAction:@selector(activate:)];
|
|
|
|
[self setButtonType:NSSwitchButton];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(IBAction) activate:(id)sender {
|
|
|
|
checkLabel->state.checked = [self state] != NSOffState;
|
2015-12-30 06:41:46 +00:00
|
|
|
checkLabel->doToggle();
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
auto pCheckLabel::construct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaCheckLabel = [[CocoaCheckLabel alloc] initWith:self()];
|
|
|
|
pWidget::construct();
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
setChecked(state().checked);
|
|
|
|
setText(state().text);
|
|
|
|
}
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pCheckLabel::destruct() -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
2016-01-07 08:14:33 +00:00
|
|
|
[cocoaView removeFromSuperview];
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView release];
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pCheckLabel::minimumSize() const -> Size {
|
|
|
|
Size size = pFont::size(self().font(true), state().text);
|
|
|
|
return {size.width() + 20, size.height()};
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pCheckLabel::setChecked(bool checked) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView setState:checked ? NSOnState : NSOffState];
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pCheckLabel::setGeometry(Geometry geometry) -> void {
|
|
|
|
pWidget::setGeometry({
|
|
|
|
geometry.x() - 2, geometry.y(),
|
|
|
|
geometry.width() + 4, geometry.height()
|
|
|
|
});
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pCheckLabel::setText(const string& text) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView setTitle:[NSString stringWithUTF8String:text]];
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
|
|
|
|
#endif
|