home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / psion / opp16f_zip / INCLUDE / lib / PRINTLIB.OPP < prev    next >
Encoding:
Text File  |  1996-02-05  |  4.3 KB  |  212 lines

  1. /*
  2.  * OPP library file
  3.  * Procs for handling printing using WDR
  4.  * See ptest: for example
  5.  * Note: requires util_lib.opp
  6.  */
  7.  
  8. #include <oo\printer>
  9. #ifndef PRINTER_OPH
  10. #include <sdk\printer>
  11. #endif
  12. #include <oo\gate>
  13. #include <sdk\errors>
  14. #include <opp\process>
  15. #include "a:\opp\printlib.oph"
  16.  
  17. LIBPROC ptest:
  18.     local i%,pb%,ppar%,<P_SETUP*>pmod%
  19.     while 1
  20.         psetup:
  21.         print "Header=";pgethd$:(P_HDR_TOP)
  22.         print "Footer=";pgethd$:(P_HDR_BOT)
  23.         pmod%=pgetset%:
  24.         pmod%=pset:(pmod%)
  25.         pmod%=pgetset%:
  26.         print "Model =";pmod%->model%
  27.         print "Driver=";pmod%->name$
  28.         print "Header=";pmod%->header$
  29.         print "Footer=";pmod%->footer$
  30.         get
  31.         pb%=pinit%:(100)
  32.         i%=0
  33.         while i%<16
  34.             pprintl:(pb%,i%,"line "+num$(i%,3))
  35.             i%++
  36.         endwh
  37.         pprint:(pb%,1)
  38.         pprint:(pb%,0)
  39.         pend:(pb%)
  40.     endwh
  41. ENDP
  42.  
  43. /* Display standard page setup dialog */
  44. LIBPROC psetup:
  45.     local r%
  46.     r%=send(peekw(DatDatGate),O_GT_WDR_PRINT_SETUP)
  47.     if r%<>0
  48.         raise r%
  49.     endif
  50. ENDP
  51.  
  52. /* Get print setup */
  53. LIBPROC pgetset%:
  54.     local printer%,<P_SETUP*>pm%,p%
  55.     printer%=pgetp%:
  56.     pm%=alloc(SIZEOF(P_SETUP))
  57.     if pm%=0
  58.         raise NoMemoryErr
  59.     endif
  60.     pm%->params%=send(printer%,O_PR_GET_PARAMS)
  61.     p%=uadd(pm%,OFFSETOF(P_SETUP,name$))
  62.     pm%->model%=send(printer%,O_PR_SENSE_MODEL,#uadd(p%,1))
  63.     pokeb p%,clen%:(uadd(p%,1))
  64.     pm%->header$=pgethd$:(P_HDR_TOP)
  65.     pm%->footer$=pgethd$:(P_HDR_BOT)
  66.     return pm%
  67. ENDP
  68.  
  69. /* Restore print setup */
  70. LIBPROC pset:(<P_SETUP*>ps%)
  71.     local printer%,p%
  72.     printer%=pgetp%:
  73.  
  74.     copy:(ps%->params%,send(printer%,O_PR_GET_PARAMS),SIZEOF(PRINTER_PARAMS))
  75.  
  76.     ps%->name$=ps%->name$+chr$(0)
  77.     p%=uadd(ps%,1+OFFSETOF(P_SETUP,name$))
  78.     send(printer%,O_PR_SET_MODEL,#0,#p%,#ps%->model%)
  79.  
  80.     ps%->header$=ps%->header$+chr$(0)
  81.     p%=uadd(ps%,1+OFFSETOF(P_SETUP,header$))
  82.     send(printer%,O_PR_SET_HD,#PRINTER_HDR_TOP,#p%)
  83.  
  84.     ps%->footer$=ps%->footer$+chr$(0)
  85.     p%=uadd(ps%,1+OFFSETOF(P_SETUP,footer$))
  86.     send(printer%,O_PR_SET_HD,#PRINTER_HDR_BOT,#p%)
  87. ENDP
  88.  
  89. /* Get print header or footer for given page */
  90. LIBPROC pgetfhd$:(where%,file$,page%)
  91.     local s$(255),t$(128),p%,c%,i%
  92.     s$=pgethd$:(where%)
  93.     p%=addr(s$)
  94.     while i%<len(s$)-1
  95.         p%=uadd(p%,1)
  96.         i%++
  97.         if peekb(p%)=%%
  98.             c%=peekb(uadd(p%,1))
  99.             if c%=%D
  100.                 t$=pdate$:(day,month,year)
  101.             elseif c%=%T
  102.                 t$=ptim$:(hour,minute)
  103.             elseif c%=%F
  104.                 t$=file$
  105.             elseif c%=%P
  106.                 if page%>0
  107.                     t$=num$(page%,3)
  108.                 else
  109.                     t$=""
  110.                 endif
  111.             elseif c%=%%
  112.                 t$="%"
  113.             else
  114.                 t$=""
  115.             endif
  116.             if i%+len(t$)>256
  117.                 s$=left$(s$,i%-1)+left$(t$,256-i%)
  118.                 break
  119.             elseif len(s$)+len(t$)-2>255
  120.                 s$=left$(s$,i%-1)+t$+mid$(s$,i%+2,256-i%-len(t$))
  121.                 break
  122.             else
  123.                 s$=left$(s$,i%-1)+t$+mid$(s$,i%+2,255)
  124.             endif
  125.         endif
  126.     endwh
  127.     return s$
  128. ENDP
  129.  
  130. /* Get print setup header or footer */
  131. LIBPROC pgethd$:(where%)
  132.     return ctoo$:(send(pgetp%:,O_PR_GET_HD,#where%))
  133. ENDP
  134.  
  135. /* Get printer handle */
  136. LIBPROC pgetp%:
  137.     send(peekw(DatP18),31)    /* make sure printer active */
  138.     return peekw(uadd(peekw(DatP18),68))
  139. ENDP
  140.  
  141. /*
  142.  * Intialise printing, lines%=no lines to print
  143.  * Returns pointer to storage buffer which should
  144.  * be passed to other print routines.
  145.  */
  146. LIBPROC pinit%:(lines%)
  147.     local pbuf%
  148.     pbuf%=alloc(2+6*lines%)
  149.     if pbuf%=0
  150.         raise NoMemoryErr
  151.     endif
  152.     pokew pbuf%,0
  153.     return pbuf%
  154. ENDP
  155.  
  156. /*
  157.  * End printing
  158.  * pbuf%=pointer returned by pinit%:
  159.  */
  160. LIBPROC pend:(pbuf%)
  161.     local i%,lc%,p1%,p2%
  162.     lc%=peekw(pbuf%)
  163.     p1%=uadd(pbuf%,6)
  164.     i%=0
  165.     while i%<lc%
  166.         i%++
  167.         freealloc usub(peekw(p1%),1)
  168.         p1%=uadd(p1%,6)
  169.     endwh
  170.     freealloc pbuf%
  171.     p1%=peekw(DatP18)
  172.     p2%=peekw(uadd(p1%,28))
  173.     if p2%
  174.         send(p2%,0)
  175.         pokew uadd(p1%,28),0
  176.     endif
  177. ENDP
  178.  
  179. /*
  180.  * Page preview or print
  181.  * pbuf%=pointer returned by pinit%:
  182.  * dest%=destination, 0=print, 1=review
  183.  */
  184. LIBPROC pprint:(pbuf%,dest%)
  185.     local lc%,r%
  186.     lc%=peekw(pbuf%)
  187.     r%=send(peekw(DatDatGate),O_GT_WDR_PRINT,#dest%,#lc%,#uadd(pbuf%,2))
  188.     if r%<>0
  189.         raise r%
  190.     endif
  191. ENDP
  192.  
  193. /*
  194.  * Print line
  195.  * pbuf%=pointer returned by pinit%:
  196.  * s%=style info (see P_STYLE_... defines)
  197.  * s$=string to print
  198.  */
  199. LIBPROC pprintl:(pbuf%,s%,s$)
  200.     local lc%,p%
  201.     lc%=peekw(pbuf%)
  202.     p%=alloc(len(s$)+1)
  203.     if p%=0
  204.         raise NoMemoryErr
  205.     endif
  206.     poke$ p%,s$
  207.     pokew uadd(pbuf%,2+lc%*6),s%
  208.     pokew uadd(pbuf%,4+lc%*6),len(s$)
  209.     pokew uadd(pbuf%,6+lc%*6),uadd(p%,1)
  210.     pokew pbuf%,lc%+1
  211. ENDP
  212.