/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    Print.h
    Author:  Copyright  1995 Julian Smith
    Version: 1.00 (20 Jan 1995)
    Purpose: Automatic handling of RO 3 wimp printing protocol messages, 
             and some of the PDriver calls involved in printing.

*/

#ifndef __dl_print_h
#define __dl_print_h

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __dl_wimp_h
#include "Wimp.h"
#endif


#ifndef __dl_pdriver_h
#include "PDriver.h"
#endif




typedef struct print_block	{
	void		*reference;	/* As passed to Print_StartPrint.	*/
	char		*jobtitle;	/* As passed to Print_StartPrint.	*/
	printer_info	printerinfo;	/* This info may be useful to printfn.	*/
	print_job	job;		/* The current job handle.		*/
	print_job	oldjob;		/* The previous job (if any).		*/
	}
	print_block;


enum	{
	print_result_OK		= 0,	/* Printing is finished.			*/
	print_result_QUEUED,		/* Data has been saved into printer queue.	*/
	print_result_NEEDPRINTERMANAGER,/* printfn==NULL, but !Printers not running.	*/
	print_result_PRINTERROR,	/* message_PRINTERROR received.			*/
	print_result_SAVEFAILED,	/* savefn failed.				*/
	print_result_CANTSAVE,		/* savefn==NULL, !Printers busy			*/
	print_result_CANTOPENPRINTER,	/* File_Open( "Printer:") failed.		*/
	print_result_FAILED		/* Something else has gone wrong.		*/
	};

typedef int	print_result;
	/* If result>255, it is an (os_error *), otherwise it is a print_result_*	*/



typedef BOOL (*print_printfn)( print_block *print);
typedef BOOL (*print_savefn)( print_block *print, message_datasaveack *datasaveack);
typedef void (*print_resultfn)( print_block *print, print_result result);



BOOL	Print_StartPrint( 
		print_printfn	printfn,	/* Called to do the actual printing after	*/
						/* the wimp messageing has finished.		*/
		print_savefn	savefn,		/* Called if print job is queued.		*/
		print_resultfn	resulfn,	/* Always called.				*/
		void		*reference,	/* Always passed to the above functions.	*/
		int		filetype, 	/* Used if print data is saved in queue.	*/
		int		estsize,	/* Used if print data is saved in queue.	*/
		char		*leafname,	/* Used if print data is saved in queue.	*/
		char		*jobtitle
		);
/*

Call this function to start a printout. Print_StartPrint does all the
wimp message handling needed to start a print job, sets up the printer
driver and then calls 'printfn'.

Returns NOERROR if the print protocol was started ok. Otherwise returns
ERROR.

Note that 'jobtitle' is *not* strcpy-ed, so the string must be present
until printing has finished.

'printfn' should print the data. 'savefn' should save the data to a file
in a form that can be printed later - this is done if the print job
needs to be queued.

Both 'printfn' and 'savefn' should return ERROR or NOERROR (see
DeskLib:Core.h).

'resultfn' will always be called with the result of the print.

Pass NULL for printfn or savefn if you can't print directly or can't
save the data to a file. Obviously, if both printfn and savefn are NULL,
the print will fail.

'savefn' will be called if !Printers already has a queue, or if
'printfn'==NULL. In this case, !Printers prints the file itself when it
comes to top of printer queue if it can (eg a text file), else it
broadcasts message_PRINTTYPEODD. You should register an event handler
for message_PRINTTYPEODD if resultfn is told that the job has been
queued *and* savefn has saved the data in a non-standard format that
!Printers won't be able to print itself.

'printfn' will be called if !Printers is not running but there is a
printer driver loaded, or if !Printers has no queue of print jobs.

'resultfn' is always called, with a print_result. If greater than
256, it is an (os_error *) from a PDriver SWi.

*/

#ifdef __cplusplus
}
#endif


#endif
