2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_ComboButton)
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
@implementation CocoaComboButton : NSPopUpButton
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
-(id) initWith:(hiro::mComboButton&)comboButtonReference {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0) pullsDown:NO]) {
|
|
|
|
comboButton = &comboButtonReference;
|
|
|
|
|
|
|
|
[self setTarget:self];
|
|
|
|
[self setAction:@selector(activate:)];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(IBAction) activate:(id)sender {
|
2015-12-30 06:41:46 +00:00
|
|
|
if(auto p = comboButton->self()) p->_updateSelected([self indexOfSelectedItem]);
|
|
|
|
comboButton->doChange();
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::construct() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
cocoaView = cocoaComboButton = [[CocoaComboButton alloc] initWith:self()];
|
|
|
|
pWidget::construct();
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::destruct() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2016-01-07 08:14:33 +00:00
|
|
|
[cocoaView removeFromSuperview];
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView release];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::append(sComboButtonItem item) -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView addItemWithTitle:[NSString stringWithUTF8String:item->text()]];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::minimumSize() const -> Size {
|
|
|
|
auto font = self().font(true);
|
|
|
|
int maximumWidth = 0;
|
|
|
|
for(auto& item : state().items) {
|
|
|
|
maximumWidth = max(maximumWidth, pFont::size(font, item->state.text).width());
|
|
|
|
}
|
|
|
|
Size size = pFont::size(font, " ");
|
|
|
|
return {maximumWidth + 36, size.height() + 6};
|
2013-04-09 13:31:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::remove(sComboButtonItem item) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView removeItemAtIndex:item->offset()];
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::reset() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView removeAllItems];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::setGeometry(Geometry geometry) -> void {
|
|
|
|
pWidget::setGeometry({
|
|
|
|
geometry.x() - 2, geometry.y(),
|
|
|
|
geometry.width() + 4, geometry.height()
|
|
|
|
});
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pComboButton::_updateSelected(signed selected) -> void {
|
|
|
|
for(auto& item : state().items) {
|
|
|
|
item->state.selected = item->offset() == selected;
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
|
|
|
|
#endif
|