// FILE:      BrailleConverter.m
// AUTHOR:    Daniel Lee
// PURPOSE:   
// REFERENCE: None. 
// COMMENTS:  
// REQUIRES: BrailleConverter.h 
// Last Mod:  07-04-2006




#import "BrailleConverter.h"

@implementation BrailleConverter


// NAME: awakefromNIB
// PURPOSE: To initilise the view for use
// IMPORTS: nil
// EXPORTS: nil
// AUTHOR: Daniel Lee
// REMARKS: 
// LAST MODIFIED: 06-04-2006

- (void) awakefromNIB
{
    // Set the boxes to set the delegate to this object
    [inputTextView setDelegate: self];
	[asciiTextView setDelegate: self];

	// asciiTextView does not needs a delegate since only braille is being sent there
	// There is no input that is allowed to be placed in that box

	// Set the font of the asciiTextView and brailleTextView to braille, size 16
	NSFont* braille = [NSFont fontWithName: @"Braille" size: 16];
	[asciiTextView setFont: braille];
    [brailleTextView setFont: braille];

    // Also need to set the mask so that the range is given in words
}


// NAME: textDidChange
// PURPOSE: A delegate function to do the translation when the text is edited
// IMPORTS: NSNotification
// EXPORTS: nil
// AUTHOR: Daniel Lee
// REMARKS: 
// LAST MODIFIED: 07-04-2006

- (void) textDidChange: (NSNotification *) aNotification
{

    char *tempOutput, *tempInput;
	NSTextView *input, *output;
	BOOL tempTranslateToBraille = [configObject translateToBraile];
    NSRange range;
	NSTextStorage *text;

    // Set the input and output variables to the respective ones which are to be used
	// This is done because the code is very similar on a lot of places and that the
	// program should be a s compact as possible.
	
    if( tempTranslateToBraille )
	{
        input = brailleTextView;
        output = inputTextView;
	}
	else
	{
        input = inputTextView;
        output = brailleTextView;
	}
	
    // Obtaining the range of the text. First the textStorage is fetched and then
	// the range is obtained.

    text = [input textStorage];
	range = [text editedRange];

	// Essentially both should grab the text that was changed from the input
    // - (NSData *)RTFFromRange:(NSRange)aRange

    if( tempTranslateToBraille )
	{
        // translateLineToBraille
	}
	else
	{
        // translateLineFromBraille
    }

	// Find the same range from the output box as the changed box and overwrite
	// the text
	// ie. replaceCharactersInRange: range withString: (NSString *)aString

	// make sure text is pasted to the ascii view
	// Most likely better the replace the entire text from the inputTextView, set a braille
	// font on it and then paste it to the asciiTextView
}


// NAME: 
// PURPOSE: 
// IMPORTS: 
// EXPORTS: 
// AUTHOR: 
// REMARKS: 
// LAST MODIFIED: 


@end
