2015-08-14 22:50:38 -05:00
|
|
|
// 14 august 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2016-05-28 21:49:27 -05:00
|
|
|
// NSProgressIndicator has no intrinsic width by default; use the default width in Interface Builder
|
|
|
|
#define progressIndicatorWidth 100
|
|
|
|
|
|
|
|
@interface intrinsicWidthNSProgressIndicator : NSProgressIndicator
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation intrinsicWidthNSProgressIndicator
|
|
|
|
|
|
|
|
- (NSSize)intrinsicContentSize
|
|
|
|
{
|
|
|
|
NSSize s;
|
|
|
|
|
|
|
|
s = [super intrinsicContentSize];
|
|
|
|
s.width = progressIndicatorWidth;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-08-14 22:50:38 -05:00
|
|
|
struct uiProgressBar {
|
|
|
|
uiDarwinControl c;
|
|
|
|
NSProgressIndicator *pi;
|
|
|
|
};
|
|
|
|
|
2016-04-25 10:54:09 -05:00
|
|
|
uiDarwinControlAllDefaults(uiProgressBar, pi)
|
2015-08-14 22:50:38 -05:00
|
|
|
|
2016-06-16 02:45:08 -05:00
|
|
|
int uiProgressBarValue(uiProgressBar *p)
|
|
|
|
{
|
2016-06-16 16:43:04 -05:00
|
|
|
if ([p->pi isIndeterminate])
|
2016-06-16 02:45:08 -05:00
|
|
|
return -1;
|
2016-06-16 16:43:04 -05:00
|
|
|
return [p->pi doubleValue];
|
2016-06-16 02:45:08 -05:00
|
|
|
}
|
|
|
|
|
2015-08-16 22:44:23 -05:00
|
|
|
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
2015-08-14 22:50:38 -05:00
|
|
|
{
|
2016-06-16 02:45:08 -05:00
|
|
|
if (value == -1) {
|
|
|
|
[p->pi setIndeterminate:YES];
|
|
|
|
[p->pi startAnimation:p->pi];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:43:04 -05:00
|
|
|
if ([p->pi isIndeterminate]) {
|
2016-06-16 02:45:08 -05:00
|
|
|
[p->pi setIndeterminate:NO];
|
|
|
|
[p->pi stopAnimation:p->pi];
|
|
|
|
}
|
|
|
|
|
2015-08-14 22:50:38 -05:00
|
|
|
if (value < 0 || value > 100)
|
2016-05-13 19:14:46 -05:00
|
|
|
userbug("Value %d out of range for a uiProgressBar.", value);
|
2016-06-16 02:45:08 -05:00
|
|
|
|
2015-08-23 22:10:17 -05:00
|
|
|
// on 10.8 there's an animation when the progress bar increases, just like with Aero
|
|
|
|
if (value == 100) {
|
|
|
|
[p->pi setMaxValue:101];
|
|
|
|
[p->pi setDoubleValue:101];
|
|
|
|
[p->pi setDoubleValue:100];
|
|
|
|
[p->pi setMaxValue:100];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[p->pi setDoubleValue:((double) (value + 1))];
|
2015-08-17 14:16:54 -05:00
|
|
|
[p->pi setDoubleValue:((double) value)];
|
2015-08-14 22:50:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiProgressBar *uiNewProgressBar(void)
|
|
|
|
{
|
|
|
|
uiProgressBar *p;
|
|
|
|
|
2016-04-25 10:54:09 -05:00
|
|
|
uiDarwinNewControl(uiProgressBar, p);
|
2015-08-14 22:50:38 -05:00
|
|
|
|
2016-05-28 21:49:27 -05:00
|
|
|
p->pi = [[intrinsicWidthNSProgressIndicator alloc] initWithFrame:NSZeroRect];
|
2015-08-14 22:50:38 -05:00
|
|
|
[p->pi setControlSize:NSRegularControlSize];
|
|
|
|
[p->pi setBezeled:YES];
|
|
|
|
[p->pi setStyle:NSProgressIndicatorBarStyle];
|
|
|
|
[p->pi setIndeterminate:NO];
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|