/*
 *	HelpPanelControl.m
 *
 *		by  Takeshi Ogihara (ogihara@seg.kobe-u.ac.jp)
 */

#import "HelpPanelControl.h"
#import "strfunc.h"
#import <objc/NXBundle.h>

@implementation HelpPanelControl

static char *helpindex[] = {
	"HelpAbst", "HelpDoc", "HelpInfo", "HelpCustom", "Copyright"
};

- makeKeyAndOrderFront:sender
{
	if (helpPanel == nil) {
		[NXApp loadNibSection:"HelpPanel.nib" owner:self];
		curtag = -1;
		[self readHelp: 0];
	}
	[helpPanel makeKeyAndOrderFront:sender];
	return self;
}

- selectHelp:sender
{
	int tag = [sender selectedTag];
	if (tag != curtag)    
		[self readHelp: tag];
	return self;
}

- readHelp: (int) helpid
{
	char	buf[256];
	NXStream *s;
	NXPoint	point;

	if (bundle == nil)
		bundle = [NXBundle mainBundle];
	if (![bundle getPath:buf forResource:helpindex[helpid] ofType:"rtf"]
		|| (s = NXMapFile(buf, NX_READONLY)) == NULL) {
		curtag = 0;
		return self;
	}
	point.x = point.y = 0;
	[helpText scrollPoint:&point];
	[helpText readRichText:s];
	NXCloseMemory(s, NX_FREEBUFFER);
	curtag = helpid;
	return self;
}

@end
