home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / printer / set_prefs.c < prev   
C/C++ Source or Header  |  1992-09-03  |  5KB  |  202 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  *****************************************************************************
  27.  *
  28.  * Set_Prefs.c
  29.  *
  30.  * This example changes the printer device's COPY of preferences (as obtained
  31.  * when the printer device was opened by a task via OpenDevice()).  Note that
  32.  * it only changes the printer device's copy of preferences, not the preferences
  33.  * as set by the user via the preference editor(s).
  34.  *
  35.  *
  36.  * Compile with SAS C 5.10: LC -b1 -cfistq -v -y -L
  37.  *
  38.  * Run from CLI only
  39.  */
  40.  
  41. #include <exec/types.h>
  42. #include <devices/printer.h>
  43. #include <devices/prtbase.h>
  44. #include <intuition/intuition.h>
  45. #include <intuition/screens.h>
  46. #include <intuition/preferences.h>
  47.  
  48. #include <clib/exec_protos.h>
  49. #include <clib/alib_protos.h>
  50. #include <clib/alib_stdio_protos.h>
  51. #include <clib/graphics_protos.h>
  52. #include <clib/intuition_protos.h>
  53.  
  54. struct Library *IntuitionBase;
  55. struct Library *GfxBase;
  56.  
  57. union printerIO
  58. {
  59.     struct IOStdReq    ios;
  60.     struct IODRPReq    iodrp;
  61.     struct IOPrtCmdReq iopc;
  62. };
  63.  
  64. struct MsgPort *PrintMP;
  65. union printerIO *pio;
  66.  
  67. char message[] = "\
  68. This is a test message to see how this looks when printed\n\
  69. using various printer settings.\n\n";
  70.  
  71. VOID main(VOID);
  72. VOID DoPrinter(VOID);
  73. int DoTest(VOID);
  74.  
  75. VOID main(VOID)
  76. {
  77.  
  78. if (IntuitionBase = OpenLibrary("intuition.library",0L))
  79.     {
  80.     if (GfxBase = OpenLibrary("graphics.library",0L))
  81.         {
  82.         DoPrinter();
  83.         CloseLibrary(GfxBase);
  84.         }
  85.  
  86.     CloseLibrary(IntuitionBase);
  87.     }
  88. }
  89.  
  90. VOID DoPrinter(VOID)
  91. {
  92.  
  93. if (PrintMP = CreatePort(0L,0L))
  94.     {
  95.     if (pio = (union printerIO *)CreateExtIO(PrintMP,sizeof(union printerIO)))
  96.         {
  97.         if (!(OpenDevice("printer.device",0L,(struct IORequest *)pio,0L)))
  98.             {
  99.             DoTest();
  100.             CloseDevice((struct IORequest *)pio);
  101.             }
  102.         DeleteExtIO((struct IORequest *)pio);
  103.         }
  104.     DeletePort(PrintMP);
  105.     }
  106.  
  107. }
  108.  
  109. DoTest(VOID)
  110. {
  111. struct PrinterData *PD;
  112. struct Preferences *prefs;
  113. UWORD newpitch;
  114. UWORD newspacing;
  115.  
  116. /* Send INIT sequence - make sure printer is inited - some      */
  117. /* printers may eject the current page if necessary when inited */
  118.  
  119. pio->ios.io_Command = CMD_WRITE;
  120. pio->ios.io_Data = "\033#1";
  121. pio->ios.io_Length = -1L;
  122.  
  123. if (DoIO((struct IORequest *)pio))
  124.     return(FALSE);
  125.  
  126. /* Print some text using the default settings from Preferences */
  127.  
  128. pio->ios.io_Command = CMD_WRITE;
  129. pio->ios.io_Data = message;
  130. pio->ios.io_Length = -1L;
  131.  
  132. if(DoIO((struct IORequest *)pio))
  133.    return(FALSE);
  134.  
  135. /* Now try changing some settings
  136.  * Note that we could just as well send the printer.device escape
  137.  * sequences to change these settings, but this is an example program.
  138.  */
  139.  
  140. /* Get pointer to printer data  */
  141. PD = (struct PrinterData *) pio->ios.io_Device;
  142.  
  143. /* Get pointer to printer's copy of preferences
  144.  * Note that the printer.device makes a copy of preferences when
  145.  * the printer.device is successfully opened via OpenDevice(),
  146.  * so we are only going to change the COPY of preferences
  147.  */
  148.  
  149. prefs = &PD->pd_Preferences;
  150.  
  151.  
  152. /* Change a couple of settings                          */
  153.  
  154. if (prefs->PrintSpacing == SIX_LPI)
  155.     newspacing = EIGHT_LPI;
  156. if (prefs->PrintSpacing == EIGHT_LPI)
  157.     newspacing = SIX_LPI;
  158.  
  159. if (prefs->PrintPitch == PICA)
  160.     newpitch = ELITE;
  161. if (prefs->PrintPitch == ELITE)
  162.     newpitch = FINE;
  163. if (prefs->PrintPitch == FINE)
  164.     newpitch = PICA;
  165.  
  166. /* And let's change the margins too for this example */
  167.  
  168. prefs->PrintLeftMargin = 20;
  169. prefs->PrintRightMargin = 40;
  170.  
  171. prefs->PrintPitch = newpitch;
  172. prefs->PrintSpacing = newspacing;
  173.  
  174. /* Send INIT sequence so that these settings are used */
  175.  
  176. pio->ios.io_Command = CMD_WRITE;
  177. pio->ios.io_Data = "\033#1";
  178. pio->ios.io_Length = -1L;
  179.  
  180. if(DoIO((struct IORequest *)pio))
  181.    return(FALSE);
  182.  
  183. pio->ios.io_Command = CMD_WRITE;
  184. pio->ios.io_Data = message;
  185. pio->ios.io_Length = -1L;
  186.  
  187. if(DoIO((struct IORequest *)pio))
  188.    return(FALSE);
  189.  
  190. /* Send FormFeed so page is ejected  */
  191.  
  192. pio->ios.io_Command = CMD_WRITE;
  193. pio->ios.io_Data = "\014";
  194. pio->ios.io_Length = -1L;
  195.  
  196. if(DoIO((struct IORequest *)pio))
  197.    return(FALSE);
  198.  
  199. return(TRUE);
  200.  
  201. }
  202.