| 1 |
@implementation CocoaFrame : NSBox |
| 2 |
|
| 3 |
-(id) initWith:(phoenix::Frame&)frameReference { |
| 4 |
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) { |
| 5 |
frame = &frameReference; |
| 6 |
|
| 7 |
[self setTitle:@""]; |
| 8 |
} |
| 9 |
return self; |
| 10 |
} |
| 11 |
|
| 12 |
@end |
| 13 |
|
| 14 |
namespace phoenix { |
| 15 |
|
| 16 |
void pFrame::setEnabled(bool enabled) { |
| 17 |
if(frame.state.layout) frame.state.layout->setEnabled(frame.state.layout->enabled()); |
| 18 |
pWidget::setEnabled(enabled); |
| 19 |
} |
| 20 |
|
| 21 |
void pFrame::setFont(string font) { |
| 22 |
@autoreleasepool { |
| 23 |
[cocoaView setTitleFont:pFont::cocoaFont(font)]; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
void pFrame::setGeometry(Geometry geometry) { |
| 28 |
bool empty = frame.state.text.empty(); |
| 29 |
Size size = Font::size(frame.font(), frame.state.text); |
| 30 |
pWidget::setGeometry({ |
| 31 |
geometry.x - 3, geometry.y - (empty ? size.height - 2 : 1), |
| 32 |
geometry.width + 6, geometry.height + (empty ? size.height + 2 : 5) |
| 33 |
}); |
| 34 |
if(frame.state.layout == nullptr) return; |
| 35 |
geometry.x += 1, geometry.y += (empty ? 1 : size.height - 2); |
| 36 |
geometry.width -= 2, geometry.height -= (empty ? 1 : size.height - 1); |
| 37 |
frame.state.layout->setGeometry(geometry); |
| 38 |
} |
| 39 |
|
| 40 |
void pFrame::setText(string text) { |
| 41 |
@autoreleasepool { |
| 42 |
[cocoaView setTitle:[NSString stringWithUTF8String:text]]; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void pFrame::setVisible(bool visible) { |
| 47 |
if(frame.state.layout) frame.state.layout->setVisible(frame.state.layout->visible()); |
| 48 |
pWidget::setVisible(visible); |
| 49 |
} |
| 50 |
|
| 51 |
void pFrame::constructor() { |
| 52 |
@autoreleasepool { |
| 53 |
cocoaView = cocoaFrame = [[CocoaFrame alloc] initWith:frame]; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
void pFrame::destructor() { |
| 58 |
@autoreleasepool { |
| 59 |
[cocoaView release]; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
void pFrame::orphan() { |
| 64 |
destructor(); |
| 65 |
constructor(); |
| 66 |
} |
| 67 |
|
| 68 |
} |