2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_HorizontalScrollBar)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
@implementation CocoaHorizontalScrollBar : NSScroller
|
|
|
|
|
|
|
|
-(id) initWith:(hiro::mHorizontalScrollBar&)horizontalScrollBarReference {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 1, 0)]) {
|
2015-12-30 06:41:46 +00:00
|
|
|
horizontalScrollBar = &horizontalScrollBarReference;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
[self setTarget:self];
|
|
|
|
[self setAction:@selector(scroll:)];
|
|
|
|
|
|
|
|
[self setControlSize:NSRegularControlSize];
|
|
|
|
[self setScrollerStyle:NSScrollerStyleLegacy];
|
|
|
|
[self setEnabled:YES];
|
|
|
|
|
|
|
|
[self update];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) update {
|
2015-12-30 06:41:46 +00:00
|
|
|
double d = 1.0 / horizontalScrollBar->state.length;
|
|
|
|
double f = d * horizontalScrollBar->state.position;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
[self setDoubleValue:f];
|
|
|
|
[self setKnobProportion:d];
|
|
|
|
}
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(IBAction) scroll:(id)sender {
|
2015-12-30 06:41:46 +00:00
|
|
|
auto& state = horizontalScrollBar->state;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
switch([self hitPart]) {
|
|
|
|
case NSScrollerIncrementLine:
|
|
|
|
case NSScrollerIncrementPage:
|
|
|
|
if(state.position < state.length - 1) state.position++;
|
|
|
|
[self update];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerDecrementLine:
|
|
|
|
case NSScrollerDecrementPage:
|
|
|
|
if(state.position) state.position--;
|
|
|
|
[self update];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerKnob:
|
|
|
|
state.position = [self doubleValue] * state.length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
horizontalScrollBar->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 pHorizontalScrollBar::construct() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
cocoaView = cocoaHorizontalScrollBar = [[CocoaHorizontalScrollBar alloc] initWith:self()];
|
|
|
|
pWidget::construct();
|
|
|
|
|
|
|
|
setLength(state().length);
|
|
|
|
setPosition(state().position);
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pHorizontalScrollBar::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 pHorizontalScrollBar::minimumSize() const -> Size {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
return {32, (int)[NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy]};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pHorizontalScrollBar::setLength(uint length) -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView update];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pHorizontalScrollBar::setPosition(uint position) -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView update];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
|
|
|
|
#endif
|