1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#if defined(Hiro_Widget)
namespace hiro {
auto pWidget::construct() -> void {
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());
setDroppable(self().droppable());
setEnabled(self().enabled(true));
setFocusable(self().focusable());
setFont(self().font(true));
setMouseCursor(self().mouseCursor());
setToolTip(self().toolTip());
setVisible(self().visible(true));
}
}
auto pWidget::destruct() -> void {
[cocoaView removeFromSuperview];
}
auto pWidget::focused() const -> bool {
return cocoaView == [[cocoaView window] firstResponder];
}
auto pWidget::setDroppable(bool droppable) -> void {
//virtual
}
auto pWidget::setEnabled(bool enabled) -> void {
if(abstract) enabled = false;
if([cocoaView respondsToSelector:@selector(setEnabled:)]) {
[(id)cocoaView setEnabled:enabled];
}
}
auto pWidget::setFocusable(bool focusable) -> void {
//virtual
}
auto pWidget::setFocused() -> void {
[[cocoaView window] makeFirstResponder:cocoaView];
}
auto pWidget::setFont(const Font& font) -> void {
if([cocoaView respondsToSelector:@selector(setFont:)]) {
[(id)cocoaView setFont:pFont::create(font)];
}
}
auto pWidget::setGeometry(Geometry geometry) -> void {
CGFloat windowHeight = [[cocoaView superview] frame].size.height;
//round coordinates
u32 x = geometry.x();
u32 y = windowHeight - geometry.y() - geometry.height();
u32 width = geometry.width();
u32 height = geometry.height();
[cocoaView setFrame:NSMakeRect(x, y, width, height)];
[[cocoaView superview] setNeedsDisplay:YES];
pSizable::setGeometry(geometry);
}
auto pWidget::setMouseCursor(const MouseCursor& mouseCursor) -> void {
//TODO
}
auto pWidget::setToolTip(const string& toolTip) -> void {
//TODO
}
auto pWidget::setVisible(bool visible) -> void {
if(abstract) visible = false;
[cocoaView setHidden:!visible];
}
}
#endif
|