home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / desklib / examples / DeskLib / Examples / OtherSrc / c / Print < prev    next >
Encoding:
Text File  |  1995-05-17  |  4.1 KB  |  186 lines

  1. /*
  2.  
  3. This is some code from my Shell library which uses DeskLib's Print
  4. library to print bits of windows.
  5.  
  6. It *won't* compile because it uses things from Shell.
  7.  
  8. However, you should be able to get an idea for how to use the Print_
  9. library from this.
  10.  
  11. Hopefully, a working example of using the Print library will be included
  12. sometime.
  13.  
  14. - Julian Smith 17 May 1995
  15.  
  16. */
  17.  
  18.  
  19. #include <string.h>
  20.  
  21. #include "DeskLib:Event.h"
  22. #include "DeskLib:WimpSWIs.h"
  23. #include "DeskLib:Hourglass.h"
  24. #include "DeskLib:PDriver.h"
  25. #include "DeskLib:Error.h"
  26. #include "DeskLib:Kbd.h"
  27.  
  28. #include "Shell.Shell.h"
  29. #include "Shell.FindWind.h"
  30. #include "Shell.Redraw2.h"
  31.  
  32. #include "DeskLib:Print.h"
  33.  
  34.  
  35.  
  36. static void    ErrorCheck( print_block *print, os_error *error)
  37.     /* Errors occuring during printing have to be dealt with    */
  38.     /* rather carefully - PDriver_AbortJob *must* be called before    */
  39.     /* any error is reported, as otherwise the error text will be    */
  40.     /* intercepted by the printer driver.                */
  41. {
  42. if ( !error)    return;
  43. PDriver_AbortJob( print->job);
  44. /*Error_Report( 0, Error_PLACE);*/
  45. Error_ReportFatal( error->errnum, error->errmess);
  46. }
  47.  
  48.  
  49.  
  50.  
  51. static BOOL    Shell__RectPrintFn( print_block *print)
  52. {
  53. print_transformation    matrix;
  54. wimp_point        position;
  55. wimp_rect        rect;
  56. int            more = 0, n;
  57.  
  58. Shell_convertpoint    convert;
  59. Shell_rectblock        *shellrect = (Shell_rectblock *) print->reference;
  60. Shell_windblock        *shellwind = Shell_FindWindBlock( shellrect->window);
  61.  
  62. matrix.xx    = 1<<16;    /* This is an identity matrix.    */
  63. matrix.xy    = 0;
  64. matrix.yy    = 1<<16;
  65. matrix.yx    = 0;
  66.  
  67. position.x    = 72000*1;    /* This is where bottom-left corner of our rect will appear on    */
  68. position.y    = 72000*1;    /* the page, relative to bottom-left of page, in millipoints.    */
  69.                 /* Should really find size of page and borders etc.        */
  70. rect = shellrect->rect;
  71.  
  72. convert.x = 0;    /* Make all Shell redrawing be relative to window origin        */
  73. convert.y = 0;    /* because we will specify our rectangle (in PDriver_GiveRectangle)    */
  74.         /* in coors rel to window origin.                    */
  75.  
  76. Hourglass_On();
  77.  
  78. ErrorCheck( print, PDriver_GiveRectangle( 0, &rect, &matrix, &position, 0xffffff00/*backgnd*/));
  79.  
  80. ErrorCheck( print, PDriver_DrawPage( 1, &rect, 0, NULL, &more, &n));
  81.  
  82. while( more)    {
  83.     Shell_WindRedraw2( &rect, convert, shellwind);
  84.  
  85.     ErrorCheck( print, PDriver_GetRectangle( &rect, &more, &n));
  86.     }
  87.  
  88. Hourglass_Off();
  89.  
  90. return NOERROR;
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. static void    Shell__PrintResultFn( print_block *print, print_result result)
  98. {
  99. UNUSED( print);
  100.  
  101. if ( result>256)    {
  102.     os_error    *error = (os_error *) result;
  103.     Error_Report( error->errnum, error->errmess);
  104.     }
  105.  
  106. else if ( result==print_result_QUEUED)    {
  107.     Error_Report( 0, "Shell rectangle data has been saved to print queue.");
  108.     }
  109.  
  110. else if ( result!=print_result_OK)
  111.     Error_Report( 0, "Shell rectangle printing error number %i", result);
  112.  
  113. else Error_Report( 0, "Shell rectangle print finished.");
  114. }
  115.  
  116.  
  117.  
  118. static BOOL    Shell__PrintSaveFn( print_block *print, message_datasaveack *datasaveack)
  119. {
  120. Shell_rectblock *rect = (Shell_rectblock *) print->reference;
  121. if ( rect->saver)    return rect->saver( datasaveack->filename, rect);
  122. return ERROR;
  123. }
  124.  
  125.  
  126.  
  127.  
  128. void    Shell_PrintRect( Shell_rectblock *rect)
  129. {
  130. BOOL    e;
  131.  
  132. e = Print_StartPrint(
  133.     Shell__RectPrintFn,
  134.     (rect->saver) ? Shell__PrintSaveFn : NULL,
  135.     Shell__PrintResultFn,
  136.     rect,            /* reference        */
  137.     rect->filetype,
  138.     rect->size,        /* estimated filesize    */
  139.     "ShellPrint",        /* leafname        */
  140.     "Shell-rectangle"    /* Job title.        */
  141.     );
  142.  
  143. if (e==ERROR)    Error_Report( 0, "Print_StartPrint failed");
  144. }
  145.  
  146.  
  147.  
  148. static BOOL Shell_PrintRectClickHandler( event_pollblock *event, void *reference)
  149.     /* This fn is called whenever there is a click on any window    */
  150. {
  151. Shell_rectblock    *r;
  152. mouse_block    ptrinfo;
  153. os_error    error;
  154. int        ret;
  155.  
  156. UNUSED( reference);
  157. UNUSED( event);
  158.  
  159. if ( !Kbd_KeyDown( inkey_CTRL)) return FALSE;
  160.  
  161. Wimp_GetPointerInfo( &ptrinfo);
  162. r = Shell_FindRectBlockFromPtr( &ptrinfo);
  163.  
  164. if ( !r) return FALSE;        /* Click wasn't on a rect        */
  165.  
  166. error.errnum    = 0;
  167. strcpy( error.errmess, "Print this Shell rectangle?");
  168. ret = Wimp_ReportErrorR( &error, 3 /*OK,Cancel*/, event_taskname);
  169.     
  170. if (ret==1)    Shell_PrintRect( r);    /* OK pressed.    */
  171.  
  172. return TRUE;
  173. }
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180. void Shell_InitPrintRectClick( void)
  181. {
  182. Event_Claim( event_CLICK, event_ANY, event_ANY, Shell_PrintRectClickHandler, NULL);
  183. return;
  184. }
  185.  
  186.