2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_VerticalScrollBar)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
@implementation CocoaVerticalScrollBar : NSScroller
|
|
|
|
|
|
|
|
-(id) initWith:(hiro::mVerticalScrollBar&)verticalScrollBarReference {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 1)]) {
|
2015-12-30 06:41:46 +00:00
|
|
|
verticalScrollBar = &verticalScrollBarReference;
|
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 / verticalScrollBar->state.length;
|
|
|
|
double f = d * verticalScrollBar->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 = verticalScrollBar->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
|
|
|
verticalScrollBar->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 pVerticalScrollBar::construct() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
cocoaView = cocoaVerticalScrollBar = [[CocoaVerticalScrollBar 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 pVerticalScrollBar::destruct() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
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 pVerticalScrollBar::minimumSize() const -> Size {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2015-12-30 06:41:46 +00:00
|
|
|
return {(int)[NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy], 32};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pVerticalScrollBar::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 pVerticalScrollBar::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
|