home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / set_prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  3.9 KB  |  173 lines

  1. /*
  2.  * Set_Prefs.c
  3.  *
  4.  * This example changes the printer device's COPY of preferences (as obtained
  5.  * when the printer device was opened by a task via OpenDevice()).  Note that
  6.  * it only changes the printer device's copy of preferences, not the preferences
  7.  * as set by the user via the preference editor(s).
  8.  *
  9.  * Compile with SAS C 5.10: LC -b1 -cfistq -v -y -L
  10.  *
  11.  * Run from CLI only
  12.  */
  13.  
  14. #include <exec/types.h>
  15. #include <devices/printer.h>
  16. #include <devices/prtbase.h>
  17. #include <intuition/intuition.h>
  18. #include <intuition/screens.h>
  19. #include <intuition/preferences.h>
  20.  
  21. #include <clib/exec_protos.h>
  22. #include <clib/alib_protos.h>
  23. #include <clib/alib_stdio_protos.h>
  24. #include <clib/graphics_protos.h>
  25. #include <clib/intuition_protos.h>
  26.  
  27. struct Library *IntuitionBase;
  28. struct Library *GfxBase;
  29.  
  30. union printerIO
  31. {
  32.     struct IOStdReq    ios;
  33.     struct IODRPReq    iodrp;
  34.     struct IOPrtCmdReq iopc;
  35. };
  36.  
  37. struct MsgPort *PrintMP;
  38. union printerIO *pio;
  39.  
  40. char message[] = "\
  41. This is a test message to see how this looks when printed\n\
  42. using various printer settings.\n\n";
  43.  
  44. VOID main(VOID);
  45. VOID DoPrinter(VOID);
  46. int DoTest(VOID);
  47.  
  48. VOID main(VOID)
  49. {
  50.  
  51. if (IntuitionBase = OpenLibrary("intuition.library",0L))
  52.     {
  53.     if (GfxBase = OpenLibrary("graphics.library",0L))
  54.         {
  55.         DoPrinter();
  56.         CloseLibrary(GfxBase);
  57.         }
  58.  
  59.     CloseLibrary(IntuitionBase);
  60.     }
  61. }
  62.  
  63. VOID DoPrinter(VOID)
  64. {
  65.  
  66. if (PrintMP = CreatePort(0L,0L))
  67.     {
  68.     if (pio = (union printerIO *)CreateExtIO(PrintMP,sizeof(union printerIO)))
  69.         {
  70.         if (!(OpenDevice("printer.device",0L,(struct IORequest *)pio,0L)))
  71.             {
  72.             DoTest();
  73.             CloseDevice((struct IORequest *)pio);
  74.             }
  75.         DeleteExtIO((struct IORequest *)pio);
  76.         }
  77.     DeletePort(PrintMP);
  78.     }
  79. }
  80.  
  81. DoTest(VOID)
  82. {
  83. struct PrinterData *PD;
  84. struct Preferences *prefs;
  85. UWORD newpitch;
  86. UWORD newspacing;
  87.  
  88. /* Send INIT sequence - make sure printer is inited - some      */
  89. /* printers may eject the current page if necessary when inited */
  90.  
  91. pio->ios.io_Command = CMD_WRITE;
  92. pio->ios.io_Data = "\033#1";
  93. pio->ios.io_Length = -1L;
  94.  
  95. if (DoIO((struct IORequest *)pio))
  96.     return(FALSE);
  97.  
  98. /* Print some text using the default settings from Preferences */
  99.  
  100. pio->ios.io_Command = CMD_WRITE;
  101. pio->ios.io_Data = message;
  102. pio->ios.io_Length = -1L;
  103.  
  104. if(DoIO((struct IORequest *)pio))
  105.    return(FALSE);
  106.  
  107. /* Now try changing some settings
  108.  * Note that we could just as well send the printer.device escape
  109.  * sequences to change these settings, but this is an example program.
  110.  */
  111.  
  112. /* Get pointer to printer data  */
  113. PD = (struct PrinterData *) pio->ios.io_Device;
  114.  
  115. /* Get pointer to printer's copy of preferences
  116.  * Note that the printer.device makes a copy of preferences when
  117.  * the printer.device is successfully opened via OpenDevice(),
  118.  * so we are only going to change the COPY of preferences
  119.  */
  120.  
  121. prefs = &PD->pd_Preferences;
  122.  
  123.  
  124. /* Change a couple of settings                          */
  125.  
  126. if (prefs->PrintSpacing == SIX_LPI)
  127.     newspacing = EIGHT_LPI;
  128. if (prefs->PrintSpacing == EIGHT_LPI)
  129.     newspacing = SIX_LPI;
  130.  
  131. if (prefs->PrintPitch == PICA)
  132.     newpitch = ELITE;
  133. if (prefs->PrintPitch == ELITE)
  134.     newpitch = FINE;
  135. if (prefs->PrintPitch == FINE)
  136.     newpitch = PICA;
  137.  
  138. /* And let's change the margins too for this example */
  139.  
  140. prefs->PrintLeftMargin = 20;
  141. prefs->PrintRightMargin = 40;
  142.  
  143. prefs->PrintPitch = newpitch;
  144. prefs->PrintSpacing = newspacing;
  145.  
  146. /* Send INIT sequence so that these settings are used */
  147.  
  148. pio->ios.io_Command = CMD_WRITE;
  149. pio->ios.io_Data = "\033#1";
  150. pio->ios.io_Length = -1L;
  151.  
  152. if(DoIO((struct IORequest *)pio))
  153.    return(FALSE);
  154.  
  155. pio->ios.io_Command = CMD_WRITE;
  156. pio->ios.io_Data = message;
  157. pio->ios.io_Length = -1L;
  158.  
  159. if(DoIO((struct IORequest *)pio))
  160.    return(FALSE);
  161.  
  162. /* Send FormFeed so page is ejected  */
  163.  
  164. pio->ios.io_Command = CMD_WRITE;
  165. pio->ios.io_Data = "\014";
  166. pio->ios.io_Length = -1L;
  167.  
  168. if(DoIO((struct IORequest *)pio))
  169.    return(FALSE);
  170.  
  171. return(TRUE);
  172. }
  173.