This is MyView.m in view mode; [Download] [Up]
/* Generated by Interface Builder */
#import "MyView.h"
#import <appkit/NXImage.h>
#import <appkit/OpenPanel.h>
#ifdef NeXT
#import <appkit/nextstd.h>
#else
#import <appkit/stdmacros.h>
#import <appkit/graphics.h>
#endif
#import <dpsclient/wraps.h>
@implementation MyView
- readFile:sender
{
id openPanel;
const char *filename;
const char *const types[] = {"tiff", "tif", "eps", NULL};
openPanel = [OpenPanel new];
[openPanel allowMultipleFiles:NO];
if ([openPanel runModalForTypes:types] &&
(filename = [openPanel filename])) {
NX_FREE(theFile);
theFile = NXCopyStringBuffer(filename);
[self display];
}
return self;
}
- drawSelf:(const NXRect *)rects :(int)rectCount
{
NXSize scaledSize;
NXSize imageSize;
NXPoint factor;
NXImage *image;
PSsetgray(NX_WHITE);
NXRectFill(&bounds);
if (!theFile)
return self;
image = [[NXImage alloc] initFromFile:theFile];
if (!image) {
NXRunAlertPanel("Alert", "Error: Cannot load image file.",
"OK", NULL, NULL);
return nil;
}
[[self window] setTitleAsFilename:theFile];
[image setScalable:YES];
[image getSize:&imageSize];
// Size to current view's size
if (!imageSize.width || !imageSize.height) {
NXRunAlertPanel("Alert",
"Error: zero size image- LIB_TIFF is not selected?",
"OK", NULL, NULL);
return nil;
}
factor.x = bounds.size.width / imageSize.width;
factor.y = bounds.size.height / imageSize.height;
factor.x = factor.y = (factor.x < factor.y) ? factor.x : factor.y;
scaledSize = bounds.size;
scaledSize.width = imageSize.width * factor.x;
scaledSize.height = imageSize.height * factor.y;
[image setSize:&scaledSize];
[image composite:NX_SOVER toPoint:&bounds.origin];
[image free];
return self;
}
- free
{
NX_FREE(theFile);
return [super free];
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.