
#import <appkit/appkit.h>

#import "XQ_InterchangeCell.h"
#import "XQ_UserFunction.h"

#import "Questor_API_Demo2Speaker.h"
#import "Questor_API_Demo2Listener.h"
#import "Questor_API_Demo2.h"

@implementation Questor_API_Demo2

- appWillInit:sender;
{
	id l = [[Questor_API_Demo2Listener alloc] init];
	id s = [[Questor_API_Demo2Speaker alloc] init];
	
	[NXApp setAppListener: l];
	[NXApp setAppSpeaker: s];

	return self;
}

//
// Write some fancy comments here
//


- (int)questorData: (char *)buf 
	len:(int)len
	fromRow: (int)fromRow
	fromCol: (int)fromCol
	toRow: (int)toRow
	toCol: (int)toCol
	sheet: (char *)aPath
	ok: (int *)ok;
{
	id valueList = NXReadObjectFromBuffer(buf, len);
	NXStream *stream = NULL;
	int i, j, k = 0;
	
	[[row findCellWithTag: 0] setIntValue: fromRow];
	[[row findCellWithTag: 1] setIntValue: toRow];
	[[col findCellWithTag: 0] setIntValue: fromCol];
	[[col findCellWithTag: 1] setIntValue: toCol];
	
	[path setStringValue: (const char *)aPath];
	
	stream = NXOpenMemory(NULL,0, NX_READWRITE);
	for(i=fromRow; i<=toRow; i++) {
		for(j=fromCol; j<=toCol; j++) {
			id cell = [valueList objectAt: k++];
			[cell princ:stream];
			NXPrintf(stream, "\t");
		}
		NXPrintf(stream, "\n");
	}
	NXSeek(stream, 0, NX_FROMSTART);
	[[scrollView docView] readText: stream];
	
	if(stream != NULL)NXCloseMemory(stream, NX_FREEBUFFER);
	[[valueList freeObjects] free];
	*ok = 1;
	return 0;
}
@end
