2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_TabFrame)
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
@implementation CocoaTabFrame : NSTabView
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
-(id) initWith:(hiro::mTabFrame&)tabFrameReference {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
|
|
|
|
tabFrame = &tabFrameReference;
|
|
|
|
|
|
|
|
[self setDelegate:self];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem {
|
2015-12-30 06:41:46 +00:00
|
|
|
tabFrame->self()->_updateSelected([tabView indexOfTabViewItem:tabViewItem]);
|
|
|
|
tabFrame->self()->_synchronizeLayout();
|
|
|
|
tabFrame->doChange();
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CocoaTabFrameItem : NSTabViewItem
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
-(id) initWith:(hiro::mTabFrame&)tabFrameReference {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(self = [super initWithIdentifier:nil]) {
|
|
|
|
tabFrame = &tabFrameReference;
|
2015-12-30 06:41:46 +00:00
|
|
|
cocoaTabFrame = tabFrame->self()->cocoaTabFrame;
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(NSSize) sizeOfLabel:(BOOL)shouldTruncateLabel {
|
|
|
|
NSSize sizeOfLabel = [super sizeOfLabel:shouldTruncateLabel];
|
2015-12-30 06:41:46 +00:00
|
|
|
int selection = [cocoaTabFrame indexOfTabViewItem:self];
|
2013-11-28 10:29:01 +00:00
|
|
|
if(selection < 0) return sizeOfLabel; //should never happen
|
2015-12-30 06:41:46 +00:00
|
|
|
// if(!tabFrame->state.image[selection].empty()) {
|
|
|
|
// uint iconSize = hiro::pFont::size(tabFrame->font(true), " ").height();
|
|
|
|
// sizeOfLabel.width += iconSize + 2;
|
|
|
|
// }
|
2013-11-28 10:29:01 +00:00
|
|
|
return sizeOfLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect {
|
2015-12-30 06:41:46 +00:00
|
|
|
int selection = [cocoaTabFrame indexOfTabViewItem:self];
|
|
|
|
/*if(selection >= 0 && !tabFrame->state.image[selection].empty()) {
|
|
|
|
uint iconSize = phoenix::Font::size(tabFrame->font(), " ").height;
|
2013-11-28 10:29:01 +00:00
|
|
|
NSImage* image = NSMakeImage(tabFrame->state.image[selection]);
|
|
|
|
|
|
|
|
[[NSGraphicsContext currentContext] saveGraphicsState];
|
|
|
|
NSRect targetRect = NSMakeRect(tabRect.origin.x, tabRect.origin.y + 2, iconSize, iconSize);
|
|
|
|
[image drawInRect:targetRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
|
|
|
|
[[NSGraphicsContext currentContext] restoreGraphicsState];
|
|
|
|
|
|
|
|
tabRect.origin.x += iconSize + 2;
|
|
|
|
tabRect.size.width -= iconSize + 2;
|
2015-12-30 06:41:46 +00:00
|
|
|
}*/
|
2013-11-28 10:29:01 +00:00
|
|
|
[super drawLabel:shouldTruncateLabel inRect:tabRect];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
auto pTabFrame::construct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaTabFrame = [[CocoaTabFrame alloc] initWith:self()];
|
|
|
|
pWidget::construct();
|
|
|
|
|
|
|
|
setNavigation(state().navigation);
|
|
|
|
}
|
|
|
|
}
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::destruct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pTabFrame::append(sTabFrameItem item) -> void {
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pTabFrame::remove(sTabFrameItem item) -> void {
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
auto pTabFrame::append(string text, const image& image) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
CocoaTabFrameItem* item = [[CocoaTabFrameItem alloc] initWith:tabFrame];
|
|
|
|
[item setLabel:[NSString stringWithUTF8String:text]];
|
|
|
|
[cocoaView addTabViewItem:item];
|
|
|
|
tabs.append(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::remove(unsigned selection) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
CocoaTabFrameItem* item = tabs[selection];
|
|
|
|
[cocoaView removeTabViewItem:item];
|
|
|
|
tabs.remove(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::setEnabled(bool enabled) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
for(auto& layout : tabFrame.state.layout) {
|
|
|
|
if(layout) layout->setEnabled(layout->enabled());
|
|
|
|
}
|
|
|
|
pWidget::setEnabled(enabled);
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
*/
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::setGeometry(Geometry geometry) -> void {
|
|
|
|
/*
|
2013-11-28 10:29:01 +00:00
|
|
|
pWidget::setGeometry({
|
|
|
|
geometry.x - 7, geometry.y - 5,
|
|
|
|
geometry.width + 14, geometry.height + 6
|
|
|
|
});
|
|
|
|
geometry.x += 1, geometry.width -= 2;
|
|
|
|
geometry.y += 22, geometry.height -= 32;
|
|
|
|
for(auto& layout : tabFrame.state.layout) {
|
|
|
|
if(layout == nullptr) continue;
|
|
|
|
layout->setGeometry(geometry);
|
|
|
|
}
|
|
|
|
synchronizeLayout();
|
2015-12-30 06:41:46 +00:00
|
|
|
*/
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::setNavigation(Navigation navigation) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
/*
|
|
|
|
auto pTabFrame::setSelection(unsigned selection) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
CocoaTabFrameItem* item = tabs[selection];
|
|
|
|
[cocoaView selectTabViewItem:item];
|
|
|
|
}
|
|
|
|
synchronizeLayout();
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::setText(unsigned selection, string text) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
CocoaTabFrameItem* item = tabs[selection];
|
|
|
|
[item setLabel:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::setVisible(bool visible) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
for(auto& layout : tabFrame.state.layout) {
|
|
|
|
if(layout) layout->setVisible(layout->visible());
|
|
|
|
}
|
|
|
|
pWidget::setVisible(visible);
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
*/
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::_synchronizeLayout() -> void {
|
|
|
|
/*
|
|
|
|
uint selection = 0;
|
2013-11-28 10:29:01 +00:00
|
|
|
for(auto& layout : tabFrame.state.layout) {
|
|
|
|
if(layout) layout->setVisible(selection == tabFrame.state.selection);
|
|
|
|
selection++;
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
*/
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pTabFrame::_updateSelected(int selected) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|