2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_Widget)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
auto pWidget::construct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
if(!cocoaView) {
|
|
|
|
abstract = true;
|
|
|
|
cocoaView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
|
|
|
|
[cocoaView setHidden:true];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(auto window = self().parentWindow(true)) {
|
|
|
|
if(auto p = window->self()) p->_append(self());
|
|
|
|
setEnabled(self().enabled(true));
|
|
|
|
setFont(self().font(true));
|
|
|
|
setVisible(self().visible(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pWidget::destruct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-03-15 13:11:33 +00:00
|
|
|
bool pWidget::enabled() {
|
|
|
|
@autoreleasepool {
|
|
|
|
return [cocoaView respondsToSelector:@selector(enabled)] && [cocoaView enabled];
|
|
|
|
}
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
*/
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pWidget::focused() const -> bool {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
return cocoaView == [[cocoaView window] firstResponder];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pWidget::setEnabled(bool enabled) -> void {
|
|
|
|
if(abstract) enabled = false;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
@autoreleasepool {
|
|
|
|
if([cocoaView respondsToSelector:@selector(setEnabled:)]) {
|
|
|
|
[cocoaView setEnabled:enabled];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pWidget::setFocused() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[[cocoaView window] makeFirstResponder:cocoaView];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pWidget::setFont(const Font& font) -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
if([cocoaView respondsToSelector:@selector(setFont:)]) {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView setFont:pFont::create(font)];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pWidget::setGeometry(Geometry geometry) -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
CGFloat windowHeight = [[cocoaView superview] frame].size.height;
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView setFrame:NSMakeRect(geometry.x(), windowHeight - geometry.y() - geometry.height(), geometry.width(), geometry.height())];
|
2013-03-15 13:11:33 +00:00
|
|
|
[[cocoaView superview] setNeedsDisplay:YES];
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
self().doSize();
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pWidget::setVisible(bool visible) -> void {
|
|
|
|
if(abstract) visible = false;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setHidden:!visible];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
#endif
|