I need to put an image from NSProgressIndicator in an NSOutlineView cell. I wrote code that does this for a specific indicator, and it works great:
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:NO];
[progressIndicator setMaxValue:100.0];
[progressIndicator setDoubleValue:somePercentage];
NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];
return [updateImage autorelease];
I tried to change the code to also give me vague indicator images. However, for an uncertain case, I always get a blank 16x16 image. (I confirmed this by writing the image to a file in each case, a certain case gives me an image of a progress indicator, an undefined case is always 16x16 white square).
Modified Code:
if(self.lengthUnknown)
{
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:YES];
NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];
return [updateImage autorelease];
}
else
{
}
Undefined progress indicators use some type of drawing that calls -dataWithPDFInsideRect: can't capture their image?
: , , NSImage lockFocus, , .
, (AMIndeterminateProgressIndicatorCell) - , , , .