* Modified: Jun & Jul 1989 for 1.0. Added NX_HANDLER for error detection.
* Modified: Aug 90 for 2.0. Added use of second context for robustness.
* Modified: Jan 92 for 3.0. Localized.
*
* This class is a subclass of view that manages the output in Yap. It
* provides a method (executeCodeFrom:) to execute PS from a text object.
* The PostScript output will be displayed in the view. The output is
* also cached in a bitmap for fast redraw response.
*
* You may freely copy, distribute and reuse the code in this example.
* NeXT disclaims any warranty of any kind, expressed or implied,
* as to its fitness for any particular use.
*/
#import <appkit/appkit.h>
#import <objc/NXBundle.h>
#import <objc/error.h>
#import <libc.h>
#import <string.h>
#import <sys/file.h>
#import "YapOutput.h"
#import "YapApp.h"
#import "YapWrap.h"
#define BUSY_STRING NXLocalString ("BUSY", NULL, "String shown when PostScript is being executed")
#define EXECUTION_COMPLETE_STRING NXLocalString("Yap Postscript Output (Execution Time %d ms)", NULL, "Shown when PostScript has executed successfully")
#define NONPOSTSCRIPT_ERROR_STRING NXLocalString("A non-PostScript error while running program.", NULL, "Shown if a non-PostScript error occurs during execution")
#define NOCONTEXT_STRING NXLocalString("Could not connect to window server.", NULL, "Shown if a connection cannot be created with the window server")
@implementation YapOutput
/*
* initFrame: initializes the instance and creates a cache.
*/
- initFrame:(const NXRect *)viewFrame
{
[super initFrame:viewFrame];
[self setCacheCleared:YES];
[self setCacheShown:NO];
cache = [[Window allocFromZone:[self zone]]
initContent:&bounds
style:NX_PLAINSTYLE
backing:NX_RETAINED
buttonMask:0
defer:NO];
return self;
}
/*
* Set/get parameters that determine behaviour.
*/
- (BOOL)isCacheCleared
{
return clearCache;
}
- (BOOL)isCacheShown
{
return showCache;
}
- setCacheCleared:(BOOL)flag
{
clearCache = flag;
return self;
}
- setCacheShown:(BOOL)flag
{
showCache = flag;
return self;
}
/*
* sizeTo:: is called whenever the view is resized. It resizes the bitmap cache
* along with the view. It doesn't do anything if the new size is equal to the
* old one.
*/
- sizeTo:(NXCoord)width :(NXCoord)height
{
if (width == frame.size.width && height == frame.size.height) return self;
[super sizeTo:width :height];
[cache sizeWindow:width :height];
return self;
}
/*
* drawSelf: simply shows the cache.
*/
- drawSelf:(NXRect *)rects :(int)rectCount
{
if (rectCount == 3) { /* Scrolling diagonally; use last two rectangles */