| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
bool pWidget::enabled() { |
| 4 |
@autoreleasepool { |
| 5 |
return [cocoaView respondsToSelector:@selector(enabled)] && [cocoaView enabled]; |
| 6 |
} |
| 7 |
} |
| 8 |
|
| 9 |
bool pWidget::focused() { |
| 10 |
@autoreleasepool { |
| 11 |
return cocoaView == [[cocoaView window] firstResponder]; |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
Size pWidget::minimumSize() { |
| 16 |
return {0, 0}; |
| 17 |
} |
| 18 |
|
| 19 |
void pWidget::setEnabled(bool enabled) { |
| 20 |
if(!widget.parent()) enabled = false; |
| 21 |
if(widget.state.abstract) enabled = false; |
| 22 |
if(!widget.enabledToAll()) enabled = false; |
| 23 |
|
| 24 |
@autoreleasepool { |
| 25 |
if([cocoaView respondsToSelector:@selector(setEnabled:)]) { |
| 26 |
[cocoaView setEnabled:enabled]; |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
void pWidget::setFocused() { |
| 32 |
@autoreleasepool { |
| 33 |
[[cocoaView window] makeFirstResponder:cocoaView]; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
void pWidget::setFont(string font) { |
| 38 |
@autoreleasepool { |
| 39 |
if([cocoaView respondsToSelector:@selector(setFont:)]) { |
| 40 |
[cocoaView setFont:pFont::cocoaFont(font)]; |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
void pWidget::setGeometry(Geometry geometry) { |
| 46 |
@autoreleasepool { |
| 47 |
CGFloat windowHeight = [[cocoaView superview] frame].size.height; |
| 48 |
[cocoaView setFrame:NSMakeRect(geometry.x, windowHeight - geometry.y - geometry.height, geometry.width, geometry.height)]; |
| 49 |
[[cocoaView superview] setNeedsDisplay:YES]; |
| 50 |
} |
| 51 |
if(widget.onSize) widget.onSize(); |
| 52 |
} |
| 53 |
|
| 54 |
void pWidget::setVisible(bool visible) { |
| 55 |
if(!widget.parent()) visible = false; |
| 56 |
if(widget.state.abstract) visible = false; |
| 57 |
if(!widget.visibleToAll()) visible = false; |
| 58 |
|
| 59 |
@autoreleasepool { |
| 60 |
[cocoaView setHidden:!visible]; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
void pWidget::constructor() { |
| 65 |
if(!widget.state.abstract) return; |
| 66 |
|
| 67 |
@autoreleasepool { |
| 68 |
cocoaView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]; |
| 69 |
[cocoaView setHidden:true]; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
void pWidget::destructor() { |
| 74 |
@autoreleasepool { |
| 75 |
[cocoaView release]; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
} |