/* !FormText.import.h */
/* Handles Data Transfer Protocol for import */

#ifndef __import_h
#define __import_h

#ifndef __wimp_h
#include "wimp.h"
#endif

/* Supplied importing functions should report errors if they can not
   load a file or claim enough memory
   You supply a handle to import_start() which is passed back to your functions
   Any Scrap file deletion is handled by import code
*/



/* Type of function to load data from file; return file size or <= 0 */
typedef int (*ImportLoader)(const char *filename, void *handle);




/* Type of function to empty/extend RAM transfer buffer
   At entry:
   bufptr  =>  buffer to be emptied, contains 0 for first call
   size    =   number of bytes in buffer to be emptied
               or estimated size for first call.
               If less than what you last allocated this is last call,
               you needn't extend buffer
   At exit:
   bufptr  =>  buffer to be filled
   Return size of buffer to be filled or <= 0
*/
typedef int (*ImportBufferHandler)(void **bufptr, int size, void *handle);




/* Type of function to be called when transfer is complete:
   filename is 0 or NULL for transfer between applications
   size is <= 0 for failure; note that in RAM transfer, size
   (bytes transferred) will probably be less than what you allocated in total
*/
typedef void (*ImportComplete)(const char *filename, int size, void *handle);





/* Main function to initiate transfer in response to:
   Wimp_MDataLoad / Wimp_MDataSave / Wimp_MDataOpen
   WimpMessage * => the complete message we are responding to
   BufferHandler can be 0 if you don't support RAM transfer
*/
void import_start(const WimpMessage *,
	ImportLoader, ImportBufferHandler, ImportComplete, void *handle);
/* Scrap transfer acts as if the original Message_DataSave was never received,
   the app will later receive a Message_DataLoad for "<Wimp$Scrap>" 'instead'
*/

/* Arbitrary size for RAM buffer extensions */
#define ArbitrarySize 4096

#endif
