home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xprint.CPP < prev    next >
C/C++ Source or Header  |  1998-04-06  |  18KB  |  683 lines

  1. /* Printer code. Code based on the Maverik class library by Fabrizio Aversa */
  2. /* ported by Stefan von Brauk */
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "XCheckBx.h"
  9. #include "XListBox.h"
  10. #include "XEntry.h"
  11. #include "XCntrevn.h"
  12. #include "xfont.h"
  13. #include "XFrmwnd.h"
  14. #include "xmsgbox.h"
  15. #include "XReslib.h"
  16. #include "XRes.h"
  17. #include "XExcept.h"
  18. #include "xcountry.h"
  19. #include "xprint.h"
  20. #include "xgraphob.h"
  21. #include "xmodal.h"
  22. #include "oolres.rh"
  23.  
  24. /*@
  25. @class XPrinterDevice
  26. @parent XGraphicDevice
  27. @type overview
  28. @remarks
  29. XPrinterDevice gives you the capability to print. It is derived from XGraphicDevice,
  30. you can draw text or graphic objects like on XGraphicDevice.<P>
  31. For printing a dialog is displayed, this dialog is displayed with local language support
  32. (currently only italic, francais, english and german). For applications which use XPrinterDevice it
  33. is nessacary that the OOL-resourcelibrary OOLRES.DLL is in the libpath.<P>
  34. To print follow these sample:
  35. <PRE>
  36.     XPrinterDevice printer(this); //this is a pointer to the owner-window
  37.     XString queue, fileName;
  38.  
  39.     //setup the printer
  40.     if( printer.SetupPrinter("Print", this, &queue, &fileName) == FALSE)
  41.         return FALSE;
  42.  
  43.     //open a printer-job
  44.     if( printer.OpenPrinterJob( "Test Job") == FALSE)
  45.     {
  46.         XMessageBox( "error, cannot create printer-job" );
  47.         return FALSE;
  48.     }
  49.  
  50.     XSize size;
  51.     //query the size of the used sheet
  52.     printer.GetPageSize( &size );
  53.  
  54.     //create a bitmap to draw
  55.     XPoint rp( 300, 1500);
  56.     XBitmap * bmp = new XBitmap( &rp);
  57.     bmp->Load( "sample.bmp" );
  58.     bmp->Draw(&printer);
  59.  
  60.     //close the job
  61.     printer.ClosePrinterJob( );
  62. </PRE>
  63. If you need to draw multiple pages you need to follow this example:
  64. <PRE>
  65.    if( newPage)
  66.    {
  67.       priner.NewPage(); //add a new page
  68.    }
  69.    //continue here with drawing objects
  70. </PRE>
  71. @symbol _
  72. */
  73. class PrinterDialog:public XModalDialog
  74. {
  75.    friend XPrinterDevice;
  76.    public:
  77.        PrinterDialog(const XFrameWindow *, PRINTERSETUP *, const XResource *);
  78.       ~PrinterDialog();
  79.    private:
  80.       PRINTERSETUP backup;
  81.       PPRINTERSETUP pSetup, pTarget;
  82.       void FillFields();
  83.       BOOL DoCommand(LONG com);
  84.       void DoControl(XControlEvent *);
  85.       XCheckBox *check;
  86.       XEntryField *entry;
  87.       XListBox *list;
  88. };
  89.  
  90.  
  91. PrinterDialog :: PrinterDialog(const XFrameWindow * owner, PRINTERSETUP * p1, const XResource * r): XModalDialog( r, owner)
  92. {
  93.    memcpy(&backup, p1, sizeof(PRINTERSETUP));
  94.    pSetup = &backup;
  95.    pTarget = p1;
  96.  
  97.    check = (XCheckBox *) GetWindow(IDC_TOFILE);
  98.    entry = (XEntryField *) GetWindow(IDC_ENTRY);
  99.    list = (XListBox *) GetWindow(IDC_LISTBOX);
  100.  
  101.    FillFields();
  102. }
  103.  
  104.  
  105. PrinterDialog :: ~PrinterDialog()
  106. {
  107.    delete check;
  108.    delete entry;
  109.    delete list;
  110. }
  111.  
  112.  
  113. void PrinterDialog::FillFields()
  114. {
  115.    LONG j, i, selected = 0;
  116.    char * psz;
  117.  
  118.    for (i = 0; i < pSetup->cQueues; i++)
  119.    {
  120.       psz = (char*) (*pSetup->pQueueInfo[i].pszComment ?
  121.          pSetup->pQueueInfo[i].pszComment : pSetup->pQueueInfo[i].pszName);
  122.  
  123.       for (j = 0; j < strlen(psz); j++)
  124.          if (psz[j] == 13 || psz[j] == 10)
  125.             psz[j] = ' ';
  126.  
  127.       list->InsertItem(psz);
  128.  
  129.       if (0 == strcmp( (char*)pSetup->pQueueInfo[i].pszName, pSetup->szPreferredQueue))
  130.          selected = i;
  131.    }
  132.  
  133.    if (list->GetCount())
  134.       list->SelectItem(selected);
  135.  
  136.    if (!pSetup->fToFile)
  137.    {
  138.       check->Select(FALSE);
  139.       entry->Enable(FALSE);
  140.    }
  141.    else
  142.       check->Select();
  143.  
  144.    if (0 == strlen(pSetup->szFileName))
  145.       strcpy(pSetup->szFileName, "PRINTER.OUT");
  146.  
  147.    entry->SetText(pSetup->szFileName);
  148. }
  149.  
  150.  
  151. BOOL PrinterDialog::DoCommand(LONG command)
  152. {
  153.    CHAR szDeviceName[48];
  154.    CHAR szDriverName[64];
  155.    PPRQINFO3 pqi;
  156.  
  157.    pqi = &pSetup->pQueueInfo[list->GetSelection()];
  158.    char *pch;
  159.  
  160.    switch (command)
  161.    {
  162.    case DID_OK:
  163.       strcpy(pSetup->szPreferredQueue, (char*)pqi->pszName);
  164.       if (check->IsSelected())
  165.       {
  166.          pSetup->fToFile = TRUE;
  167.          XString buffer;
  168.  
  169.          entry->GetText(&buffer);
  170.          strcpy(pSetup->szFileName, (char *) buffer);
  171.       }
  172.       else
  173.       {
  174.          pSetup->fToFile = FALSE;
  175.          *pSetup->szFileName = 0;
  176.       }
  177.       memcpy(pTarget, pSetup, sizeof(PRINTERSETUP));
  178.       break;
  179.    case DID_CANCEL:
  180.       break;
  181.    case IDC_JOBPROP:
  182.       strcpy(szDriverName, (char*)pqi->pszDriverName);
  183.       pch = strchr(szDriverName, '.');
  184.       if (pch)
  185.       {
  186.          strcpy(szDeviceName, pch + 1);
  187.          *pch = 0;
  188.       }
  189.       else
  190.          *szDeviceName = 0;
  191.  
  192.       pch = strchr( (char*) pqi->pszPrinters, ',');
  193.       if (pch)
  194.          *pch = 0;
  195.  
  196.       if (DevPostDeviceModes(pSetup->hab, pqi->pDriverData, (PSZ) szDriverName, (PSZ) szDeviceName, pqi->pszPrinters, DPDM_POSTJOBPROP) == DPDM_ERROR)
  197.       {
  198.          XMessageBox msgbox("Impostazione stampante", "DevPostDeviceModes", MB_OK | MB_ERROR | MB_MOVEABLE, this);
  199.       }
  200.       return FALSE;
  201.    }
  202.    return TRUE;
  203. }
  204.  
  205.  
  206. void PrinterDialog::DoControl(XControlEvent * event)
  207. {
  208.    switch (event->GetWindowID())
  209.    {
  210.       case IDC_TOFILE:
  211.       if (check->IsSelected())
  212.          entry->Enable();
  213.       else
  214.          entry->Enable(FALSE);
  215.       break;
  216.    }
  217. }
  218.  
  219.  
  220. /*@ XPrinterDevice::SetupPrinter(char *title, XFrameWindow * owner, XString * queueName, XString * fileName)
  221. @remarks Let the user select the printer-queue in a dialog. The dialog is loaded from OOLRES.DLL which must be installed.
  222. @parameters
  223. <t '°' c=2>
  224. °char *title            °the title of the dialog
  225. °XFrameWindow * owner   °owner window. If NULL, the dialog for the printer-setup is not opened
  226.                          and the  queue given in parameter 3 is initialized directly
  227. °XString * queueName      °default queue-name (can be null)
  228. °XString * fileName      °buffer for a fileName if the user wants to print to a file (if NULL no fiflename is stored)
  229. </t>
  230. @returns BOOL success
  231. */
  232. BOOL XPrinterDevice::SetupPrinter(const char *title, const XFrameWindow * owner, XString * queueName, XString * fileName)
  233. {
  234.    BOOL fOK;
  235.    CHAR szDefaultQueue[196];
  236.    CHAR szSavedQueue[196];
  237.    CHAR szWork[196];
  238.    PCHAR pch;
  239.    PPRQINFO3 pqi;
  240.    SIZEL sizel;
  241.    ULONG cReturned;
  242.    ULONG cTotal;
  243.    ULONG cbNeeded;
  244.    ULONG ul;
  245.    ULONG ulrc;
  246.  
  247.    // Caller must set these items before calling.
  248.    if (!pSetup->hab || !pSetup->lWorldCoordinates)
  249.       return FALSE;
  250.  
  251.    // no good unless I can open a PS
  252.    pSetup->pDevOpenData = NULL;
  253.  
  254.    // Close the info DC's and PS's from any previous call.
  255.    if (pSetup->hpsPrinterInfo)
  256.    {
  257.       GpiAssociate(pSetup->hpsPrinterInfo, (HDC) 0);
  258.       GpiDestroyPS(pSetup->hpsPrinterInfo);
  259.       pSetup->hpsPrinterInfo = (HPS) 0;
  260.    }
  261.  
  262.    if (pSetup->hdcPrinterInfo)
  263.    {
  264.       DevCloseDC(pSetup->hdcPrinterInfo);
  265.       pSetup->hdcPrinterInfo = (HDC) 0;
  266.    }
  267.  
  268.    if (pSetup->pQueueInfo)
  269.    {
  270.       // Free the array of PRQINFO3 from previous call.
  271.       free(pSetup->pQueueInfo);
  272.       pSetup->pQueueInfo = NULL;
  273.    }
  274.  
  275.    // Query how many queues exist on this computer and the
  276.    // number of bytes needed to hold the array.
  277.    ul = SplEnumQueue(NULL, 3, NULL, 0, &cReturned, &cTotal, &cbNeeded, NULL);
  278.    if (cTotal == 0)
  279.    {
  280.       // There are no queues on this computer!
  281.       pSetup->cQueues = 0;
  282.       return FALSE;
  283.    }
  284.  
  285.    // Allocate memory to store the newly enumerated queue information.
  286.    pSetup->pQueueInfo = (PRQINFO3 *) malloc(cbNeeded);
  287.    if (!pSetup->pQueueInfo)
  288.       return FALSE;
  289.  
  290.    // Call system again to get the array of PRQINFO3 structures.
  291.    ul = SplEnumQueue(NULL, 3, pSetup->pQueueInfo, cbNeeded, &cReturned, &cTotal, &cbNeeded, NULL);
  292.    if (ul != 0 ||
  293.       cReturned != cTotal)
  294.       return FALSE;
  295.    pSetup->cQueues = cReturned;
  296.  
  297.    // Establish a default queue -- might need it.
  298.    // Profiled queue name ends with a semicolon.
  299.    ul = PrfQueryProfileString(HINI_PROFILE, (PSZ) "PM_SPOOLER", (PSZ) "QUEUE", NULL, szDefaultQueue, 196);
  300.    if (ul > 1)
  301.    {
  302.       // Trim off semicolon.
  303.       pch = strchr(szDefaultQueue, ';');
  304.       *pch = 0;
  305.    }
  306.    else
  307.    {
  308.       // Hmmmm. Use the first one queue from the enumeration.
  309.       strcpy(szDefaultQueue, (char*) pSetup->pQueueInfo->pszName);
  310.    }
  311.    if (!strlen(szDefaultQueue))
  312.       return FALSE;
  313.  
  314.    if (0 == strlen(pSetup->szPreferredQueue))
  315.    {
  316.       // No queue preference; use default.
  317.       strcpy(pSetup->szPreferredQueue, szDefaultQueue);
  318.  
  319.       // Don't expect to see DRIVDATA without queue name.
  320.       // if(! pSetup->pDriverData ) return FALSE;
  321.    }
  322.  
  323.    if (queueName)
  324.    {
  325.       if (!queueName->IsEmpty())
  326.       {
  327.          pSetup->fToFile = FALSE;
  328.          strcpy(pSetup->szPreferredQueue, (char *) *queueName);
  329.       }
  330.       if (fileName)
  331.       {
  332.          if (!fileName->IsEmpty())
  333.          {
  334.             pSetup->fToFile = TRUE;
  335.             strcpy(pSetup->szFileName, (char *) *fileName);
  336.          }
  337.       }
  338.    }
  339.  
  340.    pqi = FindQueue(pSetup);
  341.    if (!pqi)
  342.    {
  343.       strcpy(pSetup->szPreferredQueue, szDefaultQueue);
  344.       if (pSetup->pDriverData)
  345.       {
  346.          free(pSetup->pDriverData);
  347.          pSetup->pDriverData = NULL;
  348.       }
  349.    }
  350.    else
  351.    {
  352.       fOK = TRUE;
  353.  
  354.       if (pSetup->pDriverData)
  355.       {
  356.          fOK = fOK && (pqi->pDriverData->cb == pSetup->pDriverData->cb);
  357.          fOK = fOK && (0 == strcmp(pqi->pDriverData->szDeviceName, pSetup->pDriverData->szDeviceName));
  358.       }
  359.  
  360.       if (!fOK)
  361.       {
  362.          free(pSetup->pDriverData);
  363.          pSetup->pDriverData = NULL;
  364.       }
  365.    }
  366.  
  367.    pqi = FindQueue(pSetup);
  368.  
  369.    if (!pSetup->pDriverData)
  370.    {
  371.       pSetup->pDriverData = (DRIVDATA *) malloc(pqi->pDriverData->cb);
  372.       if (!pSetup->pDriverData)
  373.       {
  374.          ulrc = FALSE;
  375.          return ulrc;
  376.       }
  377.       memcpy(pSetup->pDriverData, pqi->pDriverData, pqi->pDriverData->cb);
  378.    }
  379.  
  380.    if (!pSetup->pDriverData || pSetup->pDriverData->cb <= 0 || pSetup->pDriverData->cb != pqi->pDriverData->cb || strcmp(pqi->pDriverData->szDeviceName, pSetup->pDriverData->szDeviceName))
  381.       return FALSE;
  382.  
  383.    memcpy(pqi->pDriverData, pSetup->pDriverData, pSetup->pDriverData->cb);
  384.  
  385.    strcpy(szSavedQueue, pSetup->szPreferredQueue);
  386.  
  387.    if (owner)
  388.    {
  389.       XCountryInfo info;
  390.       XResourceLibrary lib( "oolres");
  391.       LONG dlgID;
  392.  
  393.       switch (info.GetCountry())
  394.       {
  395.       case 39:            // italy
  396.          dlgID = IDD_SELPRINT_ITA;
  397.          break;
  398.       case 2:             // can francais
  399.       case 33:            // france
  400.       case 32:            // belgien
  401.          dlgID = IDD_SELPRINT_FRA;
  402.          break;
  403.       case 49:            // german
  404.          dlgID = IDD_SELPRINT_GER;
  405.          break;
  406.       default:            // english
  407.          dlgID = IDD_SELPRINT_ENG;
  408.       }
  409.       XResource res(dlgID, &lib);
  410.  
  411.       PrinterDialog *printerDialog = new PrinterDialog(owner, pSetup, &res);
  412. //      printerDialog->SetText((char*) title);
  413.       LONG result = printerDialog->Start();
  414.       if (result == DID_CANCEL)
  415.          return FALSE;
  416.    }
  417.    else
  418.    {
  419.       if (queueName)
  420.       {
  421.          pSetup->fToFile = FALSE;
  422.          strcpy(pSetup->szPreferredQueue, (char *) *queueName);
  423.  
  424.          if (fileName)
  425.          {
  426.             pSetup->fToFile = TRUE;
  427.             strcpy(pSetup->szFileName, (char *) *fileName);
  428.          }
  429.       }
  430.    }
  431.  
  432.    *queueName = "";
  433.    *fileName = "";
  434.  
  435.    pqi = FindQueue(pSetup);
  436.    if (!pqi)
  437.       return FALSE;
  438.  
  439.    if (0 != strcmp(szSavedQueue, pSetup->szPreferredQueue))
  440.    {
  441.       if (!pSetup->pDriverData)
  442.          return FALSE;
  443.       free(pSetup->pDriverData);
  444.  
  445.       pSetup->pDriverData = (DRIVDATA *) malloc(pqi->pDriverData->cb);
  446.       if (!pSetup->pDriverData)
  447.       {
  448.          ulrc = FALSE;
  449.          return ulrc;
  450.       }
  451.       pSetup->pDriverData->cb = pqi->pDriverData->cb;
  452.    }
  453.  
  454.    if (!pSetup->pDriverData || !pSetup->pDriverData->cb == pqi->pDriverData->cb)
  455.       return FALSE;
  456.    memcpy(pSetup->pDriverData, pqi->pDriverData, pqi->pDriverData->cb);
  457.  
  458.    if (pSetup->fToFile)
  459.    {
  460.       pSetup->lDCType = OD_DIRECT;
  461.       pSetup->devopenstruc.pszLogAddress = (PSZ) pSetup->szFileName;
  462.    }
  463.    else
  464.    {
  465.       pSetup->lDCType = OD_QUEUED;
  466.       pSetup->devopenstruc.pszLogAddress = (PSZ) pSetup->szPreferredQueue;
  467.    }
  468.  
  469.    strcpy(szWork, (char*) pqi->pszDriverName);
  470.    pch = strchr(szWork, '.');
  471.    if (pch)
  472.       *pch = 0;
  473.  
  474.    if (pSetup->devopenstruc.pszDriverName)
  475.       free(pSetup->devopenstruc.pszDriverName);
  476.  
  477.    pSetup->devopenstruc.pszDriverName = (PSZ) malloc(1 + strlen(szWork));
  478.    if (!pSetup->devopenstruc.pszDriverName)
  479.       return FALSE;
  480.  
  481.    strcpy( (char*) pSetup->devopenstruc.pszDriverName, szWork);
  482.  
  483.    pSetup->devopenstruc.pdriv = pSetup->pDriverData;
  484.    pSetup->devopenstruc.pszDataType = (PSZ) "PM_Q_STD";
  485.  
  486.    pSetup->hdcPrinterInfo = DevOpenDC(pSetup->hab, OD_INFO, (PSZ) "*", 4, (PDEVOPENDATA) & pSetup->devopenstruc, (HDC) 0);
  487.    if (!pSetup->hdcPrinterInfo)
  488.       return FALSE;
  489.  
  490.    sizel.cx = 0;
  491.    sizel.cy = 0;
  492.    pSetup->hpsPrinterInfo = GpiCreatePS(pSetup->hab, pSetup->hdcPrinterInfo, &sizel, pSetup->lWorldCoordinates | GPIA_ASSOC);
  493.  
  494.    if (GPI_ERROR == pSetup->hpsPrinterInfo)
  495.    {
  496.       DevCloseDC(pSetup->hdcPrinterInfo);
  497.       pSetup->hdcPrinterInfo = (HDC) 0;
  498.       pSetup->hpsPrinterInfo = (HPS) 0;
  499.       return FALSE;
  500.    }
  501.  
  502.    pSetup->pDevOpenData = (PDEVOPENDATA) & pSetup->devopenstruc;
  503.  
  504.    *queueName = pSetup->szPreferredQueue;
  505.    if (pSetup->fToFile)
  506.       *fileName = pSetup->szFileName;
  507.    return TRUE;
  508. }
  509.  
  510.  
  511. PPRQINFO3 XPrinterDevice::FindQueue(PPRINTERSETUP pSetup)
  512. {
  513.    for (LONG i = 0; i < pSetup->cQueues; i++)
  514.    {
  515.       if (0 == strcmp(pSetup->szPreferredQueue, (char*) pSetup->pQueueInfo[i].pszName))
  516.          return &pSetup->pQueueInfo[i];
  517.    }
  518.    return NULL;
  519. }
  520.  
  521.  
  522. void XPrinterDevice::CleanupPrinter()
  523. {
  524.    if (pSetup->hpsPrinterInfo)
  525.    {
  526.       GpiAssociate(pSetup->hpsPrinterInfo, (HDC) 0);
  527.       GpiDestroyPS(pSetup->hpsPrinterInfo);
  528.       pSetup->hpsPrinterInfo = (HPS) 0;
  529.    }
  530.  
  531.    if (pSetup->hdcPrinterInfo)
  532.    {
  533.       DevCloseDC(pSetup->hdcPrinterInfo);
  534.       pSetup->hdcPrinterInfo = (HDC) 0;
  535.    }
  536.  
  537.    if (pSetup->pQueueInfo)
  538.    {
  539.       free(pSetup->pQueueInfo);
  540.       pSetup->pQueueInfo = NULL;
  541.    }
  542.  
  543.    if (pSetup->pDriverData)
  544.    {
  545.       free(pSetup->pDriverData);
  546.       pSetup->pDriverData = NULL;
  547.    }
  548.  
  549.    if (pSetup->devopenstruc.pszDriverName)
  550.    {
  551.       free(pSetup->devopenstruc.pszDriverName);
  552.       pSetup->devopenstruc.pszDriverName = NULL;
  553.    }
  554. }
  555.  
  556.  
  557. /*@ XPrinterDevice :: XPrinterDevice(XFrameWindow * w, LONG m)
  558. @remarks Create a printer-device
  559. @parameters XFrameWindow * owner-window
  560. <BR>
  561.             LONG resolution   see XGraphicDevice::XGraphicDevice() for details
  562. @returns TRUE
  563. */
  564. XPrinterDevice :: XPrinterDevice(const XFrameWindow * w, const LONG m):XGraphicDevice(m)
  565. {
  566.    pSetup = (PRINTERSETUP *) calloc(sizeof(PRINTERSETUP), 1);
  567.  
  568.    pSetup->lWorldCoordinates = m;
  569.    pSetup->hab = XApplication::GetApplication()->GetAnchorBlock();
  570.  
  571.    width = 0;
  572.    height = 0;
  573. }
  574.  
  575.  
  576. XPrinterDevice :: ~XPrinterDevice()
  577. {
  578.    free(pSetup);
  579. }
  580.  
  581.  
  582. /*@ XPrinterDevice::OpenPrinterJob(char *pszJobTitle)
  583. @remarks Open a printer job
  584. @parameters char * title      title of the printer job
  585. @returns TRUE
  586. */
  587. BOOL XPrinterDevice::OpenPrinterJob(const char *pszJobTitle)
  588. {
  589.    hdc = DevOpenDC(pSetup->hab, pSetup->lDCType, (PSZ) "*", 9, pSetup->pDevOpenData, (HDC) 0);
  590.  
  591.    if (hdc == NULLHANDLE)
  592.       return FALSE;
  593.  
  594.    SIZEL sizel;
  595.  
  596.    sizel.cx = 0;
  597.    sizel.cy = 0;
  598.    hps = GpiCreatePS(pSetup->hab, hdc, &sizel, pSetup->lWorldCoordinates | GPIF_DEFAULT | GPIT_NORMAL | GPIA_ASSOC);
  599.  
  600.    if (GPI_ERROR == hps)
  601.    {
  602.       DevCloseDC(hdc);
  603.       hdc = (HDC) 0;
  604.       hps = (HPS) 0;
  605.       return FALSE;
  606.    }
  607.    DevEscape(hdc, DEVESC_STARTDOC, strlen(pszJobTitle), (PSZ) pszJobTitle, NULL, NULL);
  608.    if (!GpiSetCharMode(hps, CM_MODE2))
  609.       return FALSE;
  610.    if (!GpiSetTextAlignment(hps, TA_NORMAL_HORIZ, TA_NORMAL_VERT))
  611.       return FALSE;
  612.  
  613.    SIZEL sizPage;
  614.  
  615.    if (!GpiQueryPS(hps, &sizPage))
  616.       return FALSE;
  617.    width = sizPage.cx;
  618.    height = sizPage.cy;
  619.  
  620.    return TRUE;
  621. }
  622.  
  623.  
  624. /*@ XPrinterDevice::ClosePrinterJob()
  625. @remarks Close the job so it can be printed.
  626. */
  627. void XPrinterDevice::ClosePrinterJob()
  628. {
  629.    DevEscape(hdc, DEVESC_ENDDOC, 0, NULL, NULL, NULL);
  630.  
  631.    if (hps)
  632.    {
  633.       GpiSetCharSet(hps, 0);
  634.       GpiAssociate(hps, (HDC) 0);
  635.       GpiDestroyPS(hps);
  636.       hps = (HPS) 0;
  637.    }
  638.  
  639.    if (hdc)
  640.    {
  641.       DevCloseDC(hdc);
  642.       hdc = (HDC) 0;
  643.    }
  644. }
  645.  
  646.  
  647. /*@ XPrinterDevice::KillPrinterJob()
  648. @remarks Remove the printer job from the printer queue.
  649. */
  650. void XPrinterDevice::KillPrinterJob()
  651. {
  652.    DevEscape(hdc, DEVESC_ABORTDOC, 0, NULL, NULL, NULL);
  653.  
  654.    if (hps)
  655.    {
  656.       GpiSetCharSet(hps, 0);
  657.       GpiAssociate(hps, (HDC) 0);
  658.       GpiDestroyPS(hps);
  659.       hps = (HPS) 0;
  660.    }
  661.  
  662.    if (hdc)
  663.    {
  664.       DevCloseDC(hdc);
  665.       hdc = (HDC) 0;
  666.    }
  667. }
  668.  
  669.  
  670. /*@ XPrinterDevice::NewPage()
  671. @remarks Add a new page to the printer-job.
  672. @returns BOOL success
  673. */
  674. BOOL XPrinterDevice::NewPage() const
  675. {
  676.    if (hdc)
  677.    {
  678.       if (DevEscape(hdc, DEVESC_NEWFRAME, 0, NULL, NULL, NULL) == DEV_OK)
  679.          return TRUE;
  680.    }
  681.    return FALSE;
  682. }
  683.