annotate lisp/printer.el @ 4636:5c427ece884b r21-5-29

XEmacs 21.5.29 "garbanzo" is released.
author Stephen J. Turnbull <stephen@xemacs.org>
date Mon, 18 May 2009 23:04:47 +0900
parents 554b9d31e7a5
children 308d34e9f07d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1 ;;; printer.el --- support for hard-copy printing in XEmacs
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
2
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
3 ;; Copyright (C) 2000, 2002 Ben Wing.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
4 ;; Copyright (C) 2000 Kirill Katsnelson.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
5
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
7 ;; Keywords: printer, printing, internal, dumped
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
8
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
10
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
14 ;; any later version.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
15
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
19 ;; General Public License for more details.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
20
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
24 ;; 02111-1307, USA.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
25
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
26 ;;; Synched up with: Not in FSF.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
27
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
28 ;;; Authorship:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
29
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
30 ;; Created 2000 by Ben Wing, to provide the high-level interface onto the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
31 ;; print support implemented by Kirill Katsnelson.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
32
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
33 ;;; Commentary:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
34
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
35 ;; This file is dumped with XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
36
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
37
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
39 ;; generic printing code ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
41
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
42 ;; #### should be named print-buffer, but that's currently in
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
43 ;; lpr-buffer with some horrible definition: print-buffer == "print with
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
44 ;; headings", lpr-buffer == "print without headings", and the headings are
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
45 ;; generated by calling the external program "pr"! This is major stone-age
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
46 ;; here!
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
47 ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
48 ;; I propose junking that package entirely and creating a unified,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
49 ;; modern API here that will work well with modern GUI's on top of it,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
50 ;; and with various different actual implementations (e.g. lpr or the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
51 ;; pretty-print package on Unix, built-in msprinter support on
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
52 ;; Windows), where the workings of a particular implementation is
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
53 ;; hidden from the user and there is a consistent set of options to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
54 ;; control how to print, which works across all implementations.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
55 ;;
506
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
56 ;; The code here currently only really supports Windows.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
57
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
58 (defgroup printing nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
59 "Generic printing support."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
60 :group 'wp)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
61
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
62 (defcustom printer-name nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
63 "*Name of printer to print to.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
64 If nil, use default.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
65 Under Windows, use `mswindows-printer-list' to get names of installed
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
66 printers."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
67 :type 'string
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
68 :group 'printing)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
69
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
70 (defstruct Print-context pageno window start-time printer-name)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
71
506
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
72 (defvar printer-current-device nil)
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
73
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
74 (defun Printer-get-device ()
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
75 (or printer-current-device (setq printer-current-device
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
76 (make-device 'msprinter printer-name))))
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
77
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
78 (defun Printer-clear-device ()
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
79 ;; relying on GC to delete the device is too error-prone since there
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
80 ;; only can be one anyway.
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
81 (and printer-current-device (delete-device printer-current-device))
506
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
82 (setq printer-current-device nil))
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
83
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
84 (defcustom printer-page-header '((face bold date) nil (face bold buffer-name))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
85 "*Controls printed page header.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
86
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
87 This can be:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
88 - nil. Header is not printed.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
89 - An fbound symbol or lambda expression. The function is called with
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
90 one parameter, a print-context object, every time the headers need
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
91 to be set up. It can use the function `print-context-property' to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
92 query the properties of this object. The return value is treated as
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
93 if it was literally specified: i.e. it will be reprocessed.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
94 - A list of up to three elements, for left, center and right portions
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
95 of the header. Each of these can be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
96 - nil, not to print the portion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
97 - A string, which will be printed literally.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
98 - A predefined symbol, on of the following:
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
99 printer-name Name of printer being printed to
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
100 short-file-name File name only, no path
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
101 long-file-name File name with its path
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
102 buffer-name Buffer name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
103 date Date current when printing started
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
104 time Time current when printing started
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
105 page Current printout page number, 1-based
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
106 user-id User logon id
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
107 user-name User full name
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
108 - A list of three elements: (face FACE-NAME EXPR). EXPR is any of the
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
109 items given here. The item will be displayed in the given face.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
110 - A cons of an extent and any of the items given here. The item will
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
111 be displayed using the extent's face, begin-glyph and end-glyph
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
112 properties.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
113 - A list, each element of which is any of the items given here.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
114 Each element of the list is rendered in sequence. For example,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
115 '(\"Page \" page) is rendered as \"Page 5\" on the fifth page.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
116 - An fbound symbol or lambda expression, called with one parameter,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
117 a print-context object, as above. The return value is treated as
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
118 if it was literally specified: i.e. it will be reprocessed."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
119 :type 'sexp
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
120 :group 'printing)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
121
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
122 (defcustom printer-page-footer '(nil (face bold ("Page " page)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
123 "*Controls printed page footer.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
124
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
125 Format is the same as `printer-page-header'."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
126 :type 'sexp
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
127 :group 'printing)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
128
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
129 (defun generate-header-element (element context)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
130 (cond ((null element) nil)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
131 ((stringp element) (insert element))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
132 ((memq element '(printer-name
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
133 short-file-name long-file-name buffer-name
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
134 date time page user-id user-name))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
135 (insert (print-context-property context element)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
136 ((and (consp element) (eq 'face (car element)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
137 (let ((p (point)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
138 (generate-header-element (third element) context)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
139 (let ((x (make-extent p (point))))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
140 (set-extent-face x (second element)))))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
141 ((and (consp element) (extentp (car element)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
142 (let ((p (point)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
143 (generate-header-element (cdr element) context)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
144 (let ((x (make-extent p (point))))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
145 (set-extent-face x (extent-face (car element)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
146 (set-extent-begin-glyph x (extent-begin-glyph (car element)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
147 (set-extent-end-glyph x (extent-end-glyph (car element))))))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
148 ((listp element)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
149 (mapcar #'(lambda (el) (generate-header-element el context))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
150 element))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
151 ((functionp element)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
152 (generate-header-element (funcall element context) context))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
153 (t (error 'invalid-argument "Unknown header element" element))))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
154
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
155 (defun generate-header-line (spec context)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
156 (let* ((left (first spec))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
157 (middle (second spec))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
158 (right (third spec))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
159 (left-start (point))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
160 (middle-start (progn (generate-header-element left context)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
161 (point)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
162 (right-start (progn (generate-header-element middle context)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
163 (point)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
164 (right-end (progn (generate-header-element right context)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
165 (point)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
166 (left-width (- middle-start left-start))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
167 (middle-width (- right-start middle-start))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
168 (right-width (- right-end right-start))
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 903
diff changeset
169 (winwidth (- (window-width (Print-context-window context)) 2))
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
170 (spaces1 (max (- (/ (- winwidth middle-width) 2) left-width) 0))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
171 (spaces2 (max (- (- winwidth right-width)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
172 (+ left-width spaces1 middle-width))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
173 0)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
174 (goto-char right-start)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
175 (insert-char ?\ spaces2)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
176 (goto-char middle-start)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
177 (insert-char ?\ spaces1)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
178
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
179 (defun print-context-property (print-context prop)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
180 "Return property PROP of PRINT-CONTEXT.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
181
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
182 Valid properties are
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
183
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
184 print-buffer Buffer being printed
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
185 print-window Window on printer device containing print buffer
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
186 print-frame Frame on printer device corresponding to current page
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
187 print-device Device referring to printer
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
188 print-start-time Time current when printing started (`current-time' format)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
189 print-page Current printout page number, 1-based
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
190 printer-name Name of printer being printed to
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
191 short-file-name File name only, no path
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
192 long-file-name File name with its path
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
193 buffer-name Buffer name
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
194 date Date current when printing started (as a string)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
195 time Time current when printing started (as a string)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
196 page Current printout page number, 1-based (as a string)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
197 user-id User logon id (as a string)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
198 user-name User full name"
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
199 (let* ((window (Print-context-window print-context))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
200 (pageno (Print-context-pageno print-context))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
201 (start-time (Print-context-start-time print-context))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
202 (printer-name (Print-context-printer-name print-context))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
203 (buffer (window-buffer window)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
204 (case prop
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
205 (print-buffer buffer)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
206 (print-window window)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
207 (print-frame (window-frame window))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
208 (print-device (frame-device (window-frame window)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
209 (print-start-time start-time)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
210 (print-page pageno)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
211 (printer-name printer-name)
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
212 (short-file-name (let ((name (buffer-file-name buffer)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
213 (if name (file-name-nondirectory name) "")))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
214 (long-file-name (let ((name (buffer-file-name buffer)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
215 (or name "")))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
216 (buffer-name (buffer-name buffer))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
217 (date (format-time-string "%x" start-time))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
218 (time (format-time-string "%X" start-time))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
219 (page (format "%d" pageno))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
220 (user-id (format "%d" (user-uid)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
221 (user-name (format "%d" (user-login-name)))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
222 (t (error 'invalid-argument "Unrecognized print-context property"
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
223 prop)))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
224
506
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
225 (defun generic-page-setup ()
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
226 "Display the Page Setup dialog box.
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
227 Changes made are recorded internally."
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
228 (interactive)
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
229 (let* ((d (Printer-get-device))
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
230 (props
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
231 (condition-case err
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
232 (make-dialog-box 'page-setup :device d
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
233 :properties (declare-boundp
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
234 default-msprinter-frame-plist))
506
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
235 (error
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
236 (Printer-clear-device)
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
237 (signal (car err) (cdr err))))))
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
238 (while props
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
239 (with-boundp 'default-msprinter-frame-plist
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
240 (setq default-msprinter-frame-plist
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
241 (plist-put default-msprinter-frame-plist (car props)
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
242 (cadr props))))
506
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
243 (setq props (cddr props)))))
39ccc7dd8077 [xemacs-hg @ 2001-05-05 08:39:59 by ben]
ben
parents: 503
diff changeset
244
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
245 (defun generic-print-buffer (&optional buffer display-print-dialog)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
246 "Print buffer BUFFER using a printing method appropriate to the O.S. being run.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
247 Under Unix, `lpr' is normally used to spool out a no-frills version of the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
248 buffer, or the `ps-print' package is used to pretty-print the buffer to a
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
249 PostScript printer. Under MS Windows, the built-in printing support is used.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
250
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
251 If DISPLAY-PRINT-DIALOG is t, the print dialog will first be
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
252 displayed, allowing the user to select various printing settings
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
253 \(e.g. which printer to print to, the range of pages, number of copies,
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
254 modes such landscape/portrait/2-up/4-up [2 or 4 (small!) logical pages
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
255 per physical page], etc.). At this point the user can cancel the printing
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
256 operation using the dialog box, and `generic-print-buffer' will not print
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
257 anything. When called interactively, use a prefix arg to suppress the
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
258 display of the print dialog box.
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
259
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
260 If BUFFER is nil or omitted, the current buffer is used."
503
98fb34b6fbe9 [xemacs-hg @ 2001-05-04 23:31:31 by ben]
ben
parents: 491
diff changeset
261 (interactive (list nil (not current-prefix-arg)))
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
262 (condition-case err
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
263 (let* ((print-region (and (interactive-p) (region-active-p)))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
264 (start (if print-region (region-beginning) (point-min buffer)))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
265 (end (if print-region (region-end) (point-max buffer))))
4459
554b9d31e7a5 Handle printing correctly on non-mswindows.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1346
diff changeset
266 (if (or (not (valid-device-type-p 'msprinter))
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
267 (not display-print-dialog))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
268 (generic-print-region start end buffer)
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
269 (let* ((d (Printer-get-device))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
270 (props (make-dialog-box 'print :device d
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
271 :allow-selection print-region
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
272 :selected-page-button
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
273 (if print-region 'selection 'all))))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
274 (and props
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
275 (let ((really-print-region
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
276 (eq (plist-get props 'selected-page-button) 'selection)))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
277 (generic-print-region (if really-print-region start
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
278 (point-min buffer))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
279 (if really-print-region end
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
280 (point-max buffer))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
281 buffer d props))))))
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
282 (error
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
283 ;; Make sure we catch all errors thrown from the native code.
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
284 (Printer-clear-device)
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
285 (signal (car err) (cdr err)))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
286
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
287 (defun generic-print-region (start end &optional buffer print-device props)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
288 "Print region using a printing method appropriate to the O.S. being run.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
289 The region between START and END of BUFFER (defaults to the current
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
290 buffer) is printed.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
291
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
292 Under Unix, `lpr' is normally used to spool out a no-frills version of the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
293 buffer, or the `ps-print' package is used to pretty-print the buffer to a
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
294 PostScript printer. Under MS Windows, the built-in printing support is used.
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
295
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
296 Optional PRINT-DEVICE is a device, already created, to use to do the
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
297 printing. This is typically used when this function was invoked from
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
298 `generic-print-buffer' and it displayed a dialog box. That function created
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
299 the device, and then the dialog box stuffed it with the user's selections
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
300 of how the buffer should be printed.
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
301
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
302 PROPS, if given, is typically the plist returned from the call to
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
303 `make-dialog-box' that displayed the Print box. It contains properties
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
304 relevant to us when we print.
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
305
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
306 Recognized properties are the same as those in `make-dialog-box':
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
307
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
308 name Printer device name. If omitted, the current system-selected
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
309 printer will be used.
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
310 from-page First page to print, 1-based. If omitted, printing starts from
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
311 the beginning.
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
312 to-page Last page to print, inclusive, If omitted, printing ends at
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
313 the end.
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
314 copies Number of copies to print. If omitted, one copy is printed."
4459
554b9d31e7a5 Handle printing correctly on non-mswindows.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1346
diff changeset
315 (cond ((valid-device-type-p 'msprinter)
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
316 ;; loop, printing one copy of document per loop. kill and
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
317 ;; re-create the frame each time so that we eject the piece
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
318 ;; of paper at the end even if we're printing more than one
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
319 ;; page per sheet of paper.
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 546
diff changeset
320 (let ((copies (plist-get props 'copies 1))
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 546
diff changeset
321 ;; This is not relevant to printing and can mess up
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 546
diff changeset
322 ;; msprinter frame sizing
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 546
diff changeset
323 default-frame-plist)
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
324 (while (> copies 0)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
325 (let (d f header-buffer footer-buffer)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
326 (setq buffer (decode-buffer buffer))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
327 (unwind-protect
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
328 (with-current-buffer buffer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
329 (save-restriction
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
330 (narrow-to-region start end)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
331 (setq d (or print-device (Printer-get-device)))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
332 (setq f (make-frame
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
333 (list* 'name
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
334 (concat
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
335 (substitute ?_ ?. (buffer-name buffer))
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
336 " - XEmacs")
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
337 '(menubar-visible-p
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
338 nil
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
339 has-modeline-p nil
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
340 default-toolbar-visible-p nil
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
341 default-gutter-visible-p nil
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
342 minibuffer none
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
343 modeline-shadow-thickness 0
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
344 vertical-scrollbar-visible-p nil
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
345 horizontal-scrollbar-visible-p nil
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
346 [default foreground] "black"
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
347 [default background] "white"))
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
348 d))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
349 (let* ((w (frame-root-window f))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
350 (vertdpi
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
351 (cdr (device-system-metric d 'device-dpi)))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
352 (pixel-vertical-clip-threshold (/ vertdpi 2))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
353 (from-page (plist-get props 'from-page 1))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
354 (to-page (plist-get props 'to-page))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
355 (context (make-Print-context
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
356 :start-time (current-time)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
357 ;; #### bogus! we need accessors for
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
358 ;; print-settings objects.
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
359 :printer-name
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
360 (or (plist-get props 'name)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
361 printer-name
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
362 (declare-fboundp
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
363 (mswindows-get-default-printer)
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 776
diff changeset
364 ))))
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
365 header-window
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
366 footer-window)
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
367
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
368 (when printer-page-header
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
369 (let ((window-min-height 2))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
370 (setq header-window w)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
371 (setq w (split-window w 2)))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
372 (setq header-buffer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
373 (generate-new-buffer " *header*"))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
374 (set-window-buffer header-window header-buffer))
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
375
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
376 (when printer-page-footer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
377 (let ((window-min-height 2))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
378 (setq footer-window
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
379 (split-window w (- (window-height w) 2))))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
380 (setq footer-buffer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
381 (generate-new-buffer " *footer*"))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
382 (set-window-buffer footer-window footer-buffer))
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
383
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
384 (setf (Print-context-window context) w)
903
4a27df428c73 [xemacs-hg @ 2002-07-06 05:48:14 by andyp]
andyp
parents: 872
diff changeset
385
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
386 (let ((last-end 0) ; bufpos at end of previous page
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
387 reached-end ; t if we've reached the end of the
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
388 ; text we're printing
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
389 (pageno 1))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
390 (set-window-buffer w buffer)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
391 (set-window-start w start)
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
392
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
393 ;; loop, printing one page per loop
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
394 (while (and (not reached-end)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
395 ;; stop at end of region of text or
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
396 ;; outside of ranges of pages given
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
397 (or (not to-page) (<= pageno to-page)))
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
398
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
399 (setf (Print-context-pageno context) pageno)
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
400
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
401 ;; only actually print the page if it's in the
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
402 ;; range.
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
403 (when (>= pageno from-page)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
404 (when printer-page-header
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
405 (with-current-buffer header-buffer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
406 (erase-buffer)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
407 (generate-header-line printer-page-header
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
408 context)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
409 (goto-char (point-min))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
410 (set-window-start header-window
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
411 (point-min))))
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
412
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
413 (when printer-page-footer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
414 (with-current-buffer footer-buffer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
415 (erase-buffer)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
416 (insert "\n")
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
417 (generate-header-line printer-page-footer
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
418 context)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
419 (goto-char (point-min))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
420 (set-window-start footer-window
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
421 (point-min))))
491
b3bbdc4058d7 [xemacs-hg @ 2001-04-30 09:26:20 by ben]
ben
parents: 444
diff changeset
422
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
423 (redisplay-frame f t)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
424 (print-job-eject-page f)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
425 )
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
426 ;; but use the GUARANTEE argument to `window-end'
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
427 ;; so that we get the right value even if we
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
428 ;; didn't do a redisplay.
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
429 (let ((this-end (window-end w t))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
430 (pixvis
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
431 (window-last-line-visible-height w)))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
432 ;; in case we get stuck somewhere, bow out
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
433 ;; rather than printing an infinite number of
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
434 ;; pages. #### this will fail with an image
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
435 ;; bigger than an entire page. but we really
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
436 ;; need this check here. we should be more
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
437 ;; clever in our check, to deal with this case.
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
438 (if (or (= this-end last-end)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
439 ;; #### fuckme! window-end returns a
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
440 ;; value outside of the valid range of
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
441 ;; buffer positions!!!
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
442 (>= this-end end))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
443 (setq reached-end t)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
444 (setq last-end this-end)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
445 (set-window-start w this-end)
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
446 (if pixvis
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
447 (with-selected-window w
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
448 ;; #### scroll-down should take a
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
449 ;; window arg.
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
450 (let ((window-pixel-scroll-increment
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
451 pixvis))
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
452 (scroll-down 1))))))
546
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 510
diff changeset
453 (setq pageno (1+ pageno)))))))
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 510
diff changeset
454 (and f (delete-frame f))
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 510
diff changeset
455 (and header-buffer (kill-buffer header-buffer))
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 510
diff changeset
456 (and footer-buffer (kill-buffer footer-buffer))))
510
5bdbc721d46a [xemacs-hg @ 2001-05-06 08:33:35 by ben]
ben
parents: 506
diff changeset
457 (setq copies (1- copies)))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
458 ((and (not (eq system-type 'windows-nt))
503
98fb34b6fbe9 [xemacs-hg @ 2001-05-04 23:31:31 by ben]
ben
parents: 491
diff changeset
459 (fboundp 'lpr-region))
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 863
diff changeset
460 (declare-fboundp (lpr-region start end)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
461 (t (error "No print support available"))))