| 1 |
#if defined(Hiro_CheckLabel) |
| 2 |
|
| 3 |
@implementation CocoaCheckLabel |
| 4 |
|
| 5 |
-(id) initWith:(hiro::mCheckLabel&)checkLabelReference { |
| 6 |
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) { |
| 7 |
checkLabel = &checkLabelReference; |
| 8 |
|
| 9 |
[self setTarget:self]; |
| 10 |
[self setAction:@selector(activate:)]; |
| 11 |
[self setButtonType:NSButtonTypeSwitch]; |
| 12 |
} |
| 13 |
return self; |
| 14 |
} |
| 15 |
|
| 16 |
-(IBAction) activate:(id)sender { |
| 17 |
checkLabel->state.checked = [self state] != NSControlStateValueOff; |
| 18 |
checkLabel->doToggle(); |
| 19 |
} |
| 20 |
|
| 21 |
@end |
| 22 |
|
| 23 |
namespace hiro { |
| 24 |
|
| 25 |
auto pCheckLabel::construct() -> void { |
| 26 |
cocoaView = cocoaCheckLabel = [[CocoaCheckLabel alloc] initWith:self()]; |
| 27 |
pWidget::construct(); |
| 28 |
|
| 29 |
setChecked(state().checked); |
| 30 |
setText(state().text); |
| 31 |
} |
| 32 |
|
| 33 |
auto pCheckLabel::destruct() -> void { |
| 34 |
[cocoaView removeFromSuperview]; |
| 35 |
} |
| 36 |
|
| 37 |
auto pCheckLabel::minimumSize() const -> Size { |
| 38 |
Size size = pFont::size(self().font(true), state().text); |
| 39 |
return {size.width() + 20, size.height()}; |
| 40 |
} |
| 41 |
|
| 42 |
auto pCheckLabel::setChecked(bool checked) -> void { |
| 43 |
[(CocoaCheckLabel*)cocoaView setState:checked ? NSControlStateValueOn : NSControlStateValueOff]; |
| 44 |
} |
| 45 |
|
| 46 |
auto pCheckLabel::setGeometry(Geometry geometry) -> void { |
| 47 |
pWidget::setGeometry({ |
| 48 |
geometry.x() - 2, geometry.y(), |
| 49 |
geometry.width() + 4, geometry.height() |
| 50 |
}); |
| 51 |
} |
| 52 |
|
| 53 |
auto pCheckLabel::setText(const string& text) -> void { |
| 54 |
[(CocoaCheckLabel*)cocoaView setTitle:[NSString stringWithUTF8String:text]]; |
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
#endif |