/*----------------------------------------------------------------------*
    special.c version 3.0 - © Copyright 1991 Jaba Development

    Author : Jan van den Baard
    Purpose: Some special routines.
 *----------------------------------------------------------------------*/
extern struct RastPort      *MainRP;
extern struct Window        *MainWindow;
extern struct Screen        *MainScreen;
extern struct GadgetList     Gadgets;
extern struct NewWindow      nw_main;

/*
 * Dumps all gadget id's to the printer
 * (I keep forgetting what labels I gave my gadgets....)
 */
void DumpID( void )
{
    struct MyGadget *gd;
    BPTR             prtfile;

    disable_window();
    buisy();
    sst("Printing...");
    if((prtfile = Open("PRT:",MODE_OLDFILE))) {
        for(gd = Gadgets.Head; gd->Succ; gd = gd->Succ)
            WriteFormat(prtfile,"%s_ID = %ld\n",&gd->GadgetLabel[0],gd->Gadget.GadgetID);
        Close(prtfile);
    } else {
        enable_window();
        ok();
        Error("Can't find the printer !");
        goto end;
    }
    enable_window();
    ok();
end:
    refresh();
}

#include <devices/printer.h>

/*
 * Print the current window. Most of you will
 * probably find this option bullshit but I
 * think there is someone out there who finds
 * it usefull.
 */
void HardCopy( void )
{
    struct  MsgPort         *PrtPort = NULL;
    union PrinterIO {
        struct IOStdReq      pio_StdReq;
        struct IODRPReq      pio_DRPReq;
        struct IOPrtCmdReq   pio_CmdReq;
    } *PrtReq = NULL;
    ULONG   Dev = 1L;

    sst("Printing...");

    while(read_msg(MainWindow));
    ModifyIDCMP(MainWindow,SIZEVERIFY);

    if(NOT (PrtPort = CreatePort("PowerSource.PRINT",0L))) {
        Error("Can't create message port !");
        goto error;
    }
    if(NOT (PrtReq = (union PrinterIO *)CreateExtIO(PrtPort,(ULONG)sizeof(union PrinterIO)))) {
        Error("Can't create printer request !");
        goto error;
    }
    if((Dev = OpenDevice("printer.device",0,(struct IORequest *)PrtReq,0))) {
        Error("Can't open the printer.device !");
        goto error;
    }
    disable_window();
    buisy();
    PrtReq->pio_DRPReq.io_Command  = PRD_DUMPRPORT;
    PrtReq->pio_DRPReq.io_RastPort = MainRP;
    PrtReq->pio_DRPReq.io_ColorMap = MainScreen->ViewPort.ColorMap;
    PrtReq->pio_DRPReq.io_Modes    = MainScreen->ViewPort.Modes;
    PrtReq->pio_DRPReq.io_SrcX     = 0;
    PrtReq->pio_DRPReq.io_SrcY     = 0;
    PrtReq->pio_DRPReq.io_SrcWidth = MainWindow->Width;
    PrtReq->pio_DRPReq.io_SrcHeight= MainWindow->Height;
    PrtReq->pio_DRPReq.io_DestCols = (LONG)(22*MainWindow->Width);
    PrtReq->pio_DRPReq.io_DestRows = (LONG)(22*MainWindow->Height);
    PrtReq->pio_DRPReq.io_Special  = SPECIAL_MILCOLS|SPECIAL_MILROWS|SPECIAL_ASPECT;

    DoIO((struct IORequest *)PrtReq);
    enable_window();
    ok();
error:
    if(NOT Dev)     CloseDevice((struct IORequest *)PrtReq);
    if(PrtReq)      DeleteExtIO((struct IORequest *)PrtReq);
    if(PrtPort)     DeletePort(PrtPort);
    while(read_msg(MainWindow));
    ModifyIDCMP(MainWindow,nw_main.IDCMPFlags);
    refresh();
}
