14
|
1 ;;; w3-display.el --- display engine v99999
|
|
2 ;; Author: wmperry
|
88
|
3 ;; Created: 1997/01/31 04:26:17
|
|
4 ;; Version: 1.115
|
14
|
5 ;; Keywords: faces, help, hypermedia
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu)
|
82
|
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
|
14
|
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
11 ;;;
|
|
12 ;;; This file is part of GNU Emacs.
|
|
13 ;;;
|
|
14 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
15 ;;; it under the terms of the GNU General Public License as published by
|
|
16 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;;; any later version.
|
|
18 ;;;
|
|
19 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;;; GNU General Public License for more details.
|
|
23 ;;;
|
|
24 ;;; You should have received a copy of the GNU General Public License
|
|
25 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;;; Boston, MA 02111-1307, USA.
|
|
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
29 (require 'cl)
|
|
30 (require 'css)
|
|
31 (require 'font)
|
|
32 (require 'w3-widget)
|
|
33 (require 'w3-imap)
|
|
34
|
88
|
35 (autoload 'sentence-ify "flame")
|
|
36 (autoload 'string-ify "flame")
|
|
37 (autoload '*flame "flame")
|
|
38 (if (not (fboundp 'flatten)) (autoload 'flatten "flame"))
|
|
39 (defvar w3-cookie-cache nil)
|
|
40
|
14
|
41 (defmacro w3-d-s-var-def (var)
|
|
42 (` (make-variable-buffer-local (defvar (, var) nil))))
|
|
43
|
|
44 (w3-d-s-var-def w3-display-open-element-stack)
|
|
45 (w3-d-s-var-def w3-display-alignment-stack)
|
|
46 (w3-d-s-var-def w3-display-list-stack)
|
82
|
47 (w3-d-s-var-def w3-display-form-id)
|
14
|
48 (w3-d-s-var-def w3-display-whitespace-stack)
|
|
49 (w3-d-s-var-def w3-display-font-family-stack)
|
|
50 (w3-d-s-var-def w3-display-font-weight-stack)
|
|
51 (w3-d-s-var-def w3-display-font-variant-stack)
|
|
52 (w3-d-s-var-def w3-display-font-size-stack)
|
|
53 (w3-d-s-var-def w3-face-color)
|
82
|
54 (w3-d-s-var-def w3-face-background-color)
|
14
|
55 (w3-d-s-var-def w3-active-faces)
|
|
56 (w3-d-s-var-def w3-active-voices)
|
|
57 (w3-d-s-var-def w3-current-form-number)
|
|
58 (w3-d-s-var-def w3-face-font-family)
|
|
59 (w3-d-s-var-def w3-face-font-weight)
|
|
60 (w3-d-s-var-def w3-face-font-variant)
|
|
61 (w3-d-s-var-def w3-face-font-size)
|
|
62 (w3-d-s-var-def w3-face-font-family)
|
|
63 (w3-d-s-var-def w3-face-font-size)
|
88
|
64 (w3-d-s-var-def w3-face-font-style)
|
14
|
65 (w3-d-s-var-def w3-face-font-spec)
|
|
66 (w3-d-s-var-def w3-face-text-decoration)
|
|
67 (w3-d-s-var-def w3-face-face)
|
|
68 (w3-d-s-var-def w3-face-descr)
|
|
69 (w3-d-s-var-def w3-face-pixmap)
|
|
70 (w3-d-s-var-def w3-display-css-properties)
|
|
71
|
|
72 (eval-when-compile
|
|
73 (defmacro w3-get-attribute (attr)
|
|
74 (` (cdr-safe (assq (, attr) args))))
|
|
75
|
|
76 (defmacro w3-get-face-info (info)
|
|
77 (let ((var (intern (format "w3-face-%s" info))))
|
|
78 (` (push (w3-get-style-info (quote (, info)) node (car (, var)))
|
|
79 (, var)))))
|
|
80
|
|
81 (defmacro w3-pop-face-info (info)
|
|
82 (let ((var (intern (format "w3-face-%s" info))))
|
|
83 (` (pop (, var)))))
|
|
84
|
|
85 (defmacro w3-get-all-face-info ()
|
|
86 (`
|
|
87 (progn
|
|
88 (w3-get-face-info font-family)
|
88
|
89 (w3-get-face-info font-style)
|
14
|
90 (w3-get-face-info font-weight)
|
|
91 (w3-get-face-info font-variant)
|
|
92 (w3-get-face-info font-size)
|
|
93 (w3-get-face-info text-decoration)
|
|
94 ;;(w3-get-face-info pixmap)
|
|
95 (w3-get-face-info color)
|
82
|
96 (w3-get-face-info background-color)
|
14
|
97 (setq w3-face-font-spec (make-font
|
|
98 :weight (car w3-face-font-weight)
|
|
99 :family (car w3-face-font-family)
|
|
100 :size (car w3-face-font-size))))))
|
|
101
|
|
102 (defmacro w3-pop-all-face-info ()
|
|
103 (`
|
|
104 (progn
|
|
105 (w3-pop-face-info font-family)
|
|
106 (w3-pop-face-info font-weight)
|
|
107 (w3-pop-face-info font-variant)
|
|
108 (w3-pop-face-info font-size)
|
88
|
109 (w3-pop-face-info font-style)
|
14
|
110 (w3-pop-face-info text-decoration)
|
|
111 ;;(w3-pop-face-info pixmap)
|
|
112 (w3-pop-face-info color)
|
82
|
113 (w3-pop-face-info background-color))))
|
14
|
114
|
|
115 )
|
|
116
|
82
|
117 (defvar w3-display-same-buffer nil)
|
14
|
118 (defvar w3-face-cache nil "Cache for w3-face-for-element")
|
|
119 (defvar w3-face-index 0)
|
|
120 (defvar w3-image-widgets-waiting nil)
|
|
121
|
|
122 (make-variable-buffer-local 'w3-last-fill-pos)
|
|
123
|
|
124 (defconst w3-fill-prefixes-vector
|
|
125 (let ((len 0)
|
|
126 (prefix-vector (make-vector 80 nil)))
|
|
127 (while (< len 80)
|
|
128 (aset prefix-vector len (make-string len ? ))
|
|
129 (setq len (1+ len)))
|
|
130 prefix-vector))
|
|
131
|
|
132 (defconst w3-line-breaks-vector
|
|
133 (let ((len 0)
|
|
134 (breaks-vector (make-vector 10 nil)))
|
|
135 (while (< len 10)
|
|
136 (aset breaks-vector len (make-string len ?\n))
|
|
137 (setq len (1+ len)))
|
|
138 breaks-vector))
|
|
139
|
|
140 (defun w3-pause ()
|
|
141 (cond
|
|
142 (w3-running-FSF19 (sit-for 0))
|
|
143 (w3-running-xemacs
|
|
144 (sit-for 0))
|
|
145 ;; (if (and (not (sit-for 0)) (input-pending-p))
|
|
146 ;; (condition-case ()
|
|
147 ;; (dispatch-event (next-command-event))
|
|
148 ;; (error nil)))
|
|
149 (t (sit-for 0))))
|
|
150
|
|
151 (defmacro w3-get-pad-string (len)
|
|
152 (` (cond
|
|
153 ((< (, len) 0)
|
|
154 "")
|
|
155 ((< (, len) 80)
|
|
156 (aref w3-fill-prefixes-vector (, len)))
|
|
157 (t (make-string (, len) ? )))))
|
|
158
|
|
159 (defsubst w3-set-fill-prefix-length (len)
|
|
160 (setq fill-prefix (if (< len (- (or w3-strict-width (window-width)) 4))
|
|
161 (w3-get-pad-string len)
|
|
162 (url-warn
|
|
163 'html
|
|
164 "Runaway indentation! Too deep for window width!")
|
|
165 fill-prefix)))
|
|
166
|
|
167 (defsubst w3-get-style-info (info node &optional default)
|
|
168 (or (cdr-safe (assq info w3-display-css-properties)) default))
|
|
169
|
|
170 (defun w3-decode-area-coords (str)
|
|
171 (let (retval)
|
|
172 (while (string-match "\\([ \t0-9]+\\),\\([ \t0-9]+\\)" str)
|
|
173 (setq retval (cons (vector (string-to-int (match-string 1 str))
|
|
174 (string-to-int (match-string 2 str))) retval)
|
|
175 str (substring str (match-end 0) nil)))
|
|
176 (if (string-match "\\([0-9]+\\)" str)
|
|
177 (setq retval (cons (vector (+ (aref (car retval) 0)
|
|
178 (string-to-int (match-string 1 str)))
|
|
179 (aref (car retval) 1)) retval)))
|
|
180 (nreverse retval)))
|
|
181
|
|
182 (defun w3-normalize-color (color)
|
|
183 (cond
|
|
184 ((valid-color-name-p color)
|
|
185 color)
|
|
186 ((valid-color-name-p (concat "#" color))
|
|
187 (concat "#" color))
|
|
188 ((string-match "[ \t\r\n]" color)
|
|
189 (w3-normalize-color
|
|
190 (mapconcat (function (lambda (x) (if (memq x '(?\t ?\r ?\n ? )) ""
|
|
191 (char-to-string x)))) color "")))
|
|
192 ((valid-color-name-p (font-normalize-color color))
|
|
193 (font-normalize-color color))
|
|
194 (t
|
|
195 (w3-warn 'html (format "Bad color specification: %s" color))
|
|
196 nil)))
|
|
197
|
|
198 (defsubst w3-voice-for-element (node)
|
|
199 (if (featurep 'emacspeak)
|
|
200 (let (family gain left right pitch pitch-range stress richness voice)
|
|
201 (setq family (w3-get-style-info 'voice-family node)
|
|
202 gain (w3-get-style-info 'gain node)
|
|
203 left (w3-get-style-info 'left-volume node)
|
|
204 right (w3-get-style-info 'right-volume node)
|
|
205 pitch (w3-get-style-info 'pitch node)
|
|
206 pitch-range (w3-get-style-info 'pitch-range node)
|
|
207 stress (w3-get-style-info 'stress node)
|
|
208 richness (w3-get-style-info 'richness node))
|
|
209 (if (or family gain left right pitch pitch-range stress richness)
|
|
210 (setq voice (dtk-personality-from-speech-style
|
|
211 (make-dtk-speech-style :family (or family 'paul)
|
|
212 :gain (or gain 5)
|
|
213 :left-volume (or left 5)
|
|
214 :right-volume (or right 5)
|
|
215 :average-pitch (or pitch 5)
|
|
216 :pitch-range (or pitch-range 5)
|
|
217 :stress (or stress 5)
|
|
218 :richness (or richness 5))))
|
|
219 (setq voice nil))
|
|
220 (or voice (car w3-active-voices)))))
|
|
221
|
|
222 (defun w3-make-face-emacs19 (name &optional doc-string temporary)
|
|
223 "Defines and returns a new FACE described by DOC-STRING.
|
|
224 If the face already exists, it is unmodified.
|
|
225 If TEMPORARY is non-nil, this face will cease to exist if not in use."
|
|
226 (make-face name))
|
|
227
|
|
228 (cond
|
|
229 ((not (fboundp 'make-face))
|
|
230 (fset 'w3-make-face 'ignore))
|
|
231 (w3-running-xemacs
|
|
232 (fset 'w3-make-face 'make-face))
|
|
233 (t
|
|
234 (fset 'w3-make-face 'w3-make-face-emacs19)))
|
|
235
|
|
236 (defsubst w3-face-for-element (node)
|
|
237 (w3-get-all-face-info)
|
|
238 (if (car w3-face-text-decoration)
|
|
239 (set-font-style-by-keywords w3-face-font-spec
|
|
240 (car w3-face-text-decoration)))
|
|
241 (if w3-face-font-variant
|
|
242 (set-font-style-by-keywords w3-face-font-spec
|
|
243 (car w3-face-font-variant)))
|
88
|
244 (if w3-face-font-style
|
|
245 (set-font-style-by-keywords w3-face-font-spec
|
|
246 (car w3-face-font-style)))
|
14
|
247 (setq w3-face-descr (list w3-face-font-spec
|
|
248 (car w3-face-color)
|
82
|
249 (car w3-face-background-color))
|
14
|
250 w3-face-face (cdr-safe (assoc w3-face-descr w3-face-cache)))
|
|
251 (if (or w3-face-face (not (or (car w3-face-color)
|
82
|
252 (car w3-face-background-color)
|
14
|
253 w3-face-font-spec)))
|
|
254 nil ; Do nothing, we got it already
|
|
255 (setq w3-face-face
|
|
256 (w3-make-face (intern (format "w3-style-face-%05d" w3-face-index))
|
|
257 "An Emacs-W3 face... don't edit by hand." t)
|
|
258 w3-face-index (1+ w3-face-index))
|
|
259 (if w3-face-font-spec
|
|
260 (set-face-font w3-face-face w3-face-font-spec))
|
|
261 (if (car w3-face-color)
|
|
262 (set-face-foreground w3-face-face (car w3-face-color)))
|
82
|
263 (if (car w3-face-background-color)
|
|
264 (set-face-background w3-face-face (car w3-face-background-color)))
|
14
|
265 ;;(set-face-background-pixmap w3-face-face w3-face-pixmap)
|
|
266 (setq w3-face-cache (cons
|
|
267 (cons w3-face-descr w3-face-face)
|
|
268 w3-face-cache)))
|
|
269 w3-face-face)
|
|
270
|
|
271 (defun w3-normalize-spaces (string)
|
|
272 ;; nuke spaces in the middle
|
|
273 (while (string-match "[ \t\r\n][ \r\t\n]+" string)
|
|
274 (setq string (concat (substring string 0 (1+ (match-beginning 0)))
|
|
275 (substring string (match-end 0)))))
|
|
276
|
|
277 ;; nuke spaces at the beginning
|
|
278 (if (string-match "^[ \t\r\n]+" string)
|
|
279 (setq string (substring string (match-end 0))))
|
|
280
|
|
281 ;; nuke spaces at the end
|
|
282 (if (string-match "[ \t\n\r]+$" string)
|
|
283 (setq string (substring string 0 (match-beginning 0))))
|
|
284 string)
|
|
285
|
|
286 (defvar w3-bullets
|
|
287 '((disc . ?*)
|
|
288 (circle . ?o)
|
|
289 (square . ?#)
|
82
|
290 (none . ? )
|
14
|
291 )
|
|
292 "*An assoc list of unordered list types mapping to characters to use
|
|
293 as the bullet character.")
|
|
294
|
|
295
|
|
296 (defsubst w3-display-line-break (n)
|
|
297 (if (or
|
|
298 (memq (car w3-display-whitespace-stack) '(pre nowrap)) ; Been told
|
|
299 (= w3-last-fill-pos (point))
|
|
300 (> w3-last-fill-pos (point-max)))
|
|
301 (if (/= (preceding-char) ?\n) (setq n (1+ n))) ; at least put one line in
|
|
302 (let ((fill-column (max (1+ (length fill-prefix)) fill-column))
|
|
303 width)
|
|
304 (case (car w3-display-alignment-stack)
|
|
305 (center
|
|
306 (fill-region-as-paragraph w3-last-fill-pos (point))
|
|
307 (center-region w3-last-fill-pos (point-max)))
|
|
308 ((justify full)
|
|
309 (fill-region-as-paragraph w3-last-fill-pos (point) t))
|
|
310 (right
|
|
311 (fill-region-as-paragraph w3-last-fill-pos (point))
|
|
312 (goto-char w3-last-fill-pos)
|
|
313 (catch 'fill-exit
|
|
314 (while (re-search-forward ".$" nil t)
|
|
315 (if (>= (setq width (current-column)) fill-column)
|
|
316 nil ; already justified, or error
|
|
317 (beginning-of-line)
|
|
318 (insert-char ? (- fill-column width))
|
|
319 (end-of-line)
|
|
320 (if (eobp)
|
|
321 (throw 'fill-exit t))
|
|
322 (condition-case ()
|
|
323 (forward-char 1)
|
|
324 (error (throw 'fill-exit t))))))
|
|
325 )
|
|
326 (otherwise ; Default is left justification
|
|
327 (fill-region-as-paragraph w3-last-fill-pos (point)))
|
|
328 ))
|
|
329 (setq n (1- n)))
|
|
330 (setq w3-last-fill-pos (point-max))
|
|
331 (insert (cond
|
|
332 ((<= n 0) "")
|
|
333 ((< n 10)
|
|
334 (aref w3-line-breaks-vector n))
|
|
335 (t
|
|
336 (make-string n ?\n)))))
|
|
337
|
|
338 (defsubst w3-munge-line-breaks-p ()
|
|
339 (eq (car w3-display-whitespace-stack) 'pre))
|
|
340
|
|
341 (defvar w3-display-nil-face (w3-make-face nil "Stub face... don't ask." t))
|
|
342
|
|
343 (defvar w3-scratch-start-point nil)
|
|
344
|
|
345 (defsubst w3-handle-string-content (string)
|
|
346 (setq w3-scratch-start-point (point))
|
|
347 (insert string)
|
|
348 (if (w3-munge-line-breaks-p)
|
|
349 (progn
|
|
350 (goto-char w3-scratch-start-point)
|
|
351 (if (not (search-forward "\n" nil t))
|
|
352 (subst-char-in-region w3-scratch-start-point (point-max) ?\r ?\n)
|
|
353 (subst-char-in-region w3-scratch-start-point (point-max) ?\r ? )))
|
|
354 (goto-char w3-scratch-start-point)
|
|
355 (while (re-search-forward
|
|
356 " [ \t\n\r]+\\|[\t\n\r][ \t\n\r]*"
|
|
357 nil 'move)
|
|
358 (replace-match " "))
|
|
359 (goto-char w3-scratch-start-point)
|
|
360 (if (and (memq (preceding-char) '(? ?\t ?\r ?\n))
|
|
361 (looking-at "[ \t\r\n]"))
|
|
362 (delete-region (point)
|
|
363 (progn
|
|
364 (skip-chars-forward " \t\r\n")
|
|
365 (point)))))
|
|
366 (goto-char (point-max))
|
|
367 (add-text-properties w3-scratch-start-point
|
|
368 (point) (list 'face w3-active-faces 'duplicable t))
|
|
369 (if (car w3-active-voices)
|
|
370 (add-text-properties w3-scratch-start-point (point)
|
|
371 (list 'personality (car w3-active-voices))))
|
|
372 )
|
|
373
|
88
|
374 (defun w3-display-get-cookie (args)
|
|
375 (if (not (fboundp 'cookie))
|
|
376 "Sorry, no cookies today."
|
|
377 (let* ((href (or (w3-get-attribute 'href) (w3-get-attribute 'src)))
|
|
378 (fname (or (cdr-safe (assoc href w3-cookie-cache))
|
|
379 (url-generate-unique-filename "%s.cki")))
|
|
380 (st (or (cdr-safe (assq 'start args)) "Loading cookies..."))
|
|
381 (nd (or (cdr-safe (assq 'end args)) "Loading cookies... done.")))
|
|
382 (if (not (file-exists-p fname))
|
|
383 (save-excursion
|
|
384 (set-buffer (generate-new-buffer " *cookie*"))
|
|
385 (url-insert-file-contents href)
|
|
386 (write-region (point-min) (point-max) fname 5)
|
|
387 (setq w3-cookie-cache (cons (cons href fname) w3-cookie-cache))))
|
|
388 (cookie fname st nd))))
|
|
389
|
14
|
390 (defun w3-widget-echo (widget &rest ignore)
|
82
|
391 (let ((url (widget-get widget 'href))
|
14
|
392 (name (widget-get widget 'name))
|
|
393 (text (buffer-substring (widget-get widget :from)
|
|
394 (widget-get widget :to)))
|
|
395 (title (widget-get widget 'title))
|
82
|
396 (check w3-echo-link)
|
14
|
397 (msg nil))
|
82
|
398 (if url
|
|
399 (setq url (url-truncate-url-for-viewing url)))
|
14
|
400 (if name
|
|
401 (setq name (concat "anchor:" name)))
|
82
|
402 (if (not (listp check))
|
|
403 (setq check (cons check '(title url text name))))
|
|
404 (catch 'exit
|
|
405 (while check
|
|
406 (and (boundp (car check))
|
|
407 (stringp (symbol-value (car check)))
|
|
408 (throw 'exit (symbol-value (car check))))
|
|
409 (pop check)))))
|
14
|
410
|
|
411 (defun w3-follow-hyperlink (widget &rest ignore)
|
|
412 (let* ((target (widget-get widget 'target))
|
|
413 (href (widget-get widget 'href)))
|
|
414 (if target (setq target (intern (downcase target))))
|
|
415 (case target
|
|
416 ((_blank external)
|
|
417 (w3-fetch-other-frame href))
|
|
418 (_top
|
|
419 (delete-other-windows)
|
|
420 (w3-fetch href))
|
|
421 (otherwise
|
|
422 (w3-fetch href)))))
|
|
423
|
|
424 (defun w3-balloon-help-callback (object &optional event)
|
|
425 (let* ((widget (widget-at (extent-start-position object)))
|
|
426 (href (and widget (widget-get widget 'href))))
|
|
427 (if href
|
|
428 (url-truncate-url-for-viewing href)
|
|
429 nil)))
|
|
430
|
|
431
|
|
432 ;; Various macros
|
|
433 (eval-when-compile
|
|
434 (defmacro w3-expand-url (url)
|
|
435 (`
|
|
436 (url-expand-file-name (, url)
|
|
437 (cdr-safe
|
|
438 (assoc
|
|
439 (cdr-safe
|
|
440 (assq 'base args)) w3-base-alist)))))
|
|
441
|
|
442 (defmacro w3-handle-empty-tag ()
|
|
443 (`
|
|
444 (progn
|
|
445 (push (cons tag args) w3-display-open-element-stack)
|
|
446 (push content content-stack)
|
|
447 (setq content nil))))
|
|
448
|
|
449 (defmacro w3-handle-content (node)
|
|
450 (`
|
|
451 (progn
|
|
452 (push (cons tag args) w3-display-open-element-stack)
|
|
453 (push content content-stack)
|
|
454 (setq content (nth 2 node)))))
|
|
455
|
|
456 (defmacro w3-display-handle-list-type ()
|
|
457 (`
|
|
458 (case (car break-style)
|
|
459 (list-item
|
82
|
460 (let ((list-style (w3-get-style-info 'list-style-type node))
|
14
|
461 (list-num (if (car w3-display-list-stack)
|
|
462 (incf (car w3-display-list-stack))
|
|
463 1))
|
|
464 (margin (1- (car left-margin-stack)))
|
|
465 (indent (w3-get-style-info 'text-indent node 0)))
|
|
466 (if (> indent 0)
|
|
467 (setq margin (+ margin indent))
|
|
468 (setq margin (max 0 (- margin indent))))
|
|
469 (beginning-of-line)
|
|
470 (case list-style
|
|
471 ((disc circle square)
|
|
472 (insert (format (format "%%%dc" margin)
|
|
473 (or (cdr-safe (assq list-style w3-bullets))
|
|
474 ?o))))
|
|
475 ((decimal lower-roman upper-roman lower-alpha upper-alpha)
|
|
476 (let ((x (case list-style
|
|
477 (lower-roman
|
|
478 (w3-decimal-to-roman list-num))
|
|
479 (upper-roman
|
|
480 (upcase
|
|
481 (w3-decimal-to-roman list-num)))
|
|
482 (lower-alpha
|
|
483 (w3-decimal-to-alpha list-num))
|
|
484 (upper-alpha
|
|
485 (upcase
|
|
486 (w3-decimal-to-alpha list-num)))
|
|
487 (otherwise
|
|
488 (int-to-string list-num)))))
|
|
489 (insert (format (format "%%%ds." margin) x))
|
|
490 )
|
|
491 )
|
|
492 (otherwise
|
|
493 (insert (w3-get-pad-string margin)))
|
|
494 )
|
|
495 )
|
|
496 )
|
|
497 (otherwise
|
|
498 (insert (w3-get-pad-string (+ (car left-margin-stack)
|
|
499 (w3-get-style-info 'text-indent node 0)))))
|
|
500 )
|
|
501 )
|
|
502 )
|
|
503
|
|
504 (defmacro w3-display-set-margins ()
|
|
505 (`
|
|
506 (progn
|
|
507 (push (+ (w3-get-style-info 'margin-left node 0)
|
|
508 (car left-margin-stack)) left-margin-stack)
|
|
509 (push (-
|
|
510 (car right-margin-stack)
|
|
511 (w3-get-style-info 'margin-right node 0)) right-margin-stack)
|
|
512 (setq fill-column (car right-margin-stack))
|
|
513 (w3-set-fill-prefix-length (car left-margin-stack))
|
|
514 (w3-display-handle-list-type))))
|
|
515
|
|
516 (defmacro w3-display-restore-margins ()
|
|
517 (`
|
|
518 (progn
|
|
519 (pop right-margin-stack)
|
|
520 (pop left-margin-stack))))
|
|
521
|
|
522 (defmacro w3-display-handle-break ()
|
|
523 (`
|
|
524 (case (car break-style)
|
|
525 (block ; Full paragraph break
|
|
526 (if (eq (cadr break-style) 'list-item)
|
|
527 (setf (cadr break-style) 'line)
|
|
528 (w3-display-line-break 1))
|
|
529 (w3-display-set-margins)
|
|
530 (push
|
|
531 (w3-get-style-info 'white-space node
|
|
532 (car w3-display-whitespace-stack))
|
|
533 w3-display-whitespace-stack)
|
|
534 (push
|
|
535 (or (w3-get-attribute 'align)
|
|
536 (w3-get-style-info 'text-align node
|
|
537 (car w3-display-alignment-stack)))
|
|
538 w3-display-alignment-stack)
|
|
539 (and w3-do-incremental-display (w3-pause)))
|
|
540 ((line list-item) ; Single line break
|
|
541 (w3-display-line-break 0)
|
|
542 (w3-display-set-margins)
|
|
543 (push
|
|
544 (w3-get-style-info 'white-space node
|
|
545 (car w3-display-whitespace-stack))
|
|
546 w3-display-whitespace-stack)
|
|
547 (push
|
|
548 (w3-get-style-info 'text-align node
|
|
549 (or (w3-get-attribute 'align)
|
|
550 (car w3-display-alignment-stack)))
|
|
551 w3-display-alignment-stack))
|
|
552 (otherwise ; Assume 'inline' rendering as default
|
|
553 nil))
|
|
554 )
|
|
555 )
|
|
556
|
|
557 (defmacro w3-display-handle-end-break ()
|
|
558 (`
|
|
559 (case (pop break-style)
|
|
560 (block ; Full paragraph break
|
|
561 (w3-display-line-break 1)
|
|
562 (w3-display-restore-margins)
|
|
563 (pop w3-display-whitespace-stack)
|
|
564 (pop w3-display-alignment-stack)
|
|
565 (and w3-do-incremental-display (w3-pause)))
|
|
566 ((line list-item) ; Single line break
|
|
567 (w3-display-restore-margins)
|
|
568 (w3-display-line-break 0)
|
|
569 (pop w3-display-whitespace-stack)
|
|
570 (pop w3-display-alignment-stack))
|
|
571 (otherwise ; Assume 'inline' rendering as default
|
|
572 nil))
|
|
573 )
|
|
574 )
|
|
575 )
|
|
576
|
|
577 ;; <link> handling
|
|
578 (defun w3-parse-link (args)
|
|
579 (let* ((type (if (w3-get-attribute 'rel) 'rel 'rev))
|
|
580 (desc (w3-get-attribute type))
|
|
581 (dc-desc (and desc (downcase desc))) ; canonical case
|
|
582 (dest (w3-get-attribute 'href))
|
|
583 (plist (alist-to-plist args))
|
|
584 (node-1 (assq type w3-current-links))
|
|
585 (node-2 (and node-1 desc (or (assoc desc
|
|
586 (cdr node-1))
|
|
587 (assoc dc-desc
|
|
588 (cdr node-1)))))
|
|
589 )
|
|
590 ;; Canonicalize the case of link types we may look for
|
|
591 ;; specifically (toolbar etc.) since that's done with
|
|
592 ;; assoc. See `w3-mail-document-author' and
|
|
593 ;; `w3-link-toolbar', at least.
|
|
594 (if (member dc-desc w3-defined-link-types)
|
|
595 (setq desc dc-desc))
|
|
596 (if dest ; ignore if HREF missing
|
|
597 (cond
|
|
598 (node-2 ; Add to old value
|
|
599 (setcdr node-2 (cons plist (cdr node-2))))
|
|
600 (node-1 ; first rel/rev
|
|
601 (setcdr node-1 (cons (cons desc (list plist))
|
|
602 (cdr node-1))))
|
|
603 (t (setq w3-current-links
|
|
604 (cons (cons type (list (cons desc (list plist))))
|
|
605 w3-current-links)))))
|
|
606 (setq desc (and desc (intern dc-desc)))
|
|
607 (case desc
|
|
608 ((style stylesheet)
|
82
|
609 (w3-handle-style plist))
|
14
|
610 (otherwise
|
|
611 )
|
|
612 )
|
|
613 )
|
|
614 )
|
|
615
|
|
616
|
|
617 ;; Image handling
|
|
618 (defun w3-maybe-start-image-download (widget)
|
|
619 (let* ((src (widget-get widget 'src))
|
|
620 (cached-glyph (w3-image-cached-p src)))
|
|
621 (if (and cached-glyph (widget-glyphp cached-glyph))
|
|
622 (setq w3-image-widgets-waiting (cons widget w3-image-widgets-waiting))
|
|
623 (cond
|
|
624 ((or w3-delay-image-loads ; Delaying images
|
|
625 (not (fboundp 'valid-specifier-domain-p)) ; Can't do images
|
|
626 (eq (device-type) 'tty)) ; Why bother?
|
|
627 (w3-add-delayed-graphic widget))
|
|
628 ((not (w3-image-loadable-p src nil)) ; Hey, we can't load it!
|
|
629 (w3-warn 'images (format "Skipping image %s" (url-basepath src t)))
|
|
630 (w3-add-delayed-graphic widget))
|
|
631 (t ; Grab the images
|
|
632 (let (
|
|
633 (url-request-method "GET")
|
|
634 (old-asynch url-be-asynchronous)
|
|
635 (url-request-data nil)
|
|
636 (url-request-extra-headers nil)
|
|
637 (url-source t)
|
|
638 (url-mime-accept-string (substring
|
|
639 (mapconcat
|
|
640 (function
|
|
641 (lambda (x)
|
|
642 (if x
|
|
643 (concat (car x) ",")
|
|
644 "")))
|
|
645 w3-allowed-image-types "")
|
|
646 0 -1))
|
|
647 (url-working-buffer (generate-new-buffer-name " *W3GRAPH*")))
|
|
648 (setq-default url-be-asynchronous t)
|
|
649 (setq w3-graphics-list (cons (cons src (make-glyph))
|
|
650 w3-graphics-list))
|
|
651 (save-excursion
|
|
652 (set-buffer (get-buffer-create url-working-buffer))
|
|
653 (setq url-current-callback-data (list widget)
|
|
654 url-be-asynchronous t
|
|
655 url-current-callback-func 'w3-finalize-image-download)
|
|
656 (url-retrieve src))
|
|
657 (setq-default url-be-asynchronous old-asynch)))))))
|
|
658
|
|
659 (defun w3-finalize-image-download (widget)
|
|
660 (let ((glyph nil)
|
|
661 (url (widget-get widget 'src))
|
|
662 (node nil)
|
|
663 (buffer (widget-get widget 'buffer)))
|
|
664 (message "Enhancing image...")
|
|
665 (setq glyph (image-normalize (cdr-safe (assoc url-current-mime-type
|
|
666 w3-image-mappings))
|
|
667 (buffer-string)))
|
|
668 (message "Enhancing image... done")
|
|
669 (kill-buffer (current-buffer))
|
|
670 (cond
|
|
671 ((w3-image-invalid-glyph-p glyph)
|
|
672 (setq glyph nil)
|
|
673 (w3-warn 'image (format "Reading of %s failed." url)))
|
|
674 ((eq (aref glyph 0) 'xbm)
|
|
675 (let ((temp-fname (url-generate-unique-filename "%s.xbm")))
|
|
676 (save-excursion
|
|
677 (set-buffer (generate-new-buffer " *xbm-garbage*"))
|
|
678 (erase-buffer)
|
|
679 (insert (aref glyph 2))
|
|
680 (setq glyph temp-fname)
|
|
681 (write-region (point-min) (point-max) temp-fname)
|
|
682 (kill-buffer (current-buffer)))
|
|
683 (setq glyph (make-glyph (list (cons 'x glyph))))
|
|
684 (condition-case ()
|
|
685 (delete-file temp-fname)
|
|
686 (error nil))))
|
|
687 (t
|
|
688 (setq glyph (make-glyph glyph))))
|
|
689 (setq node (assoc url w3-graphics-list))
|
|
690 (cond
|
|
691 ((and node glyph)
|
|
692 (set-glyph-image (cdr node) (glyph-image glyph)))
|
|
693 (glyph
|
|
694 (setq w3-graphics-list (cons (cons url glyph) w3-graphics-list)))
|
|
695 (t nil))
|
|
696
|
|
697 (if (and (buffer-name buffer) ; Dest. buffer exists
|
|
698 (widget-glyphp glyph)) ; got a valid glyph
|
|
699 (save-excursion
|
|
700 (set-buffer buffer)
|
|
701 (if (eq major-mode 'w3-mode)
|
|
702 (widget-value-set widget glyph)
|
|
703 (setq w3-image-widgets-waiting
|
|
704 (cons widget w3-image-widgets-waiting)))))))
|
|
705
|
|
706 (defmacro w3-node-visible-p ()
|
|
707 (` (not (eq (car break-style) 'none))))
|
|
708
|
|
709 (defmacro w3-handle-image ()
|
|
710 (`
|
|
711 (let* ((height (w3-get-attribute 'height))
|
|
712 (width (w3-get-attribute 'width))
|
|
713 (src (or (w3-get-attribute 'src) "Error Image"))
|
|
714 (our-alt (cond
|
|
715 ((null w3-auto-image-alt) "")
|
|
716 ((eq t w3-auto-image-alt)
|
|
717 (concat "[IMAGE(" (url-basepath src t) ")] "))
|
|
718 ((stringp w3-auto-image-alt)
|
|
719 (format w3-auto-image-alt (url-basepath src t)))))
|
|
720 (alt (or (w3-get-attribute 'alt) our-alt))
|
|
721 (ismap (and (assq 'ismap args) 'ismap))
|
|
722 (usemap (w3-get-attribute 'usemap))
|
|
723 (base (w3-get-attribute 'base))
|
|
724 (href (and hyperlink-info (widget-get (cadr hyperlink-info) 'href)))
|
|
725 (widget nil)
|
|
726 (align (or (w3-get-attribute 'align)
|
|
727 (w3-get-style-info 'vertical-align node))))
|
88
|
728 (if (assq '*table-autolayout w3-display-open-element-stack)
|
|
729 (insert alt)
|
|
730 (setq widget (widget-create 'image
|
|
731 :value-face w3-active-faces
|
|
732 'src src ; Where to load the image from
|
|
733 'alt alt ; Textual replacement
|
|
734 'ismap ismap ; Is it a server-side map?
|
|
735 'usemap usemap ; Is it a client-side map?
|
|
736 'href href ; Hyperlink destination
|
|
737 ))
|
|
738 (widget-put widget 'buffer (current-buffer))
|
|
739 (w3-maybe-start-image-download widget)
|
|
740 (goto-char (point-max))))))
|
14
|
741
|
|
742 ;; The table handling
|
|
743
|
|
744 (defvar w3-display-table-cut-words-p nil
|
|
745 "*Whether to cut words that are oversized in table cells")
|
|
746
|
|
747 (defvar w3-display-table-force-borders nil
|
|
748 "*Whether to always draw table borders")
|
|
749
|
|
750 (defun w3-display-table-cut ()
|
|
751 (save-excursion
|
|
752 (goto-char (point-min))
|
|
753 (let ((offset -1))
|
|
754 (while (< offset 0)
|
|
755 (end-of-line)
|
|
756 (setq offset (- fill-column (current-column)))
|
|
757 (cond ((< offset 0)
|
|
758 (condition-case nil
|
|
759 (progn (forward-char offset)
|
|
760 (insert ?\n))
|
|
761 (error (setq offset 0))))
|
|
762 ((not (eobp))
|
|
763 (forward-line 1)
|
|
764 (setq offset -1)))))))
|
|
765
|
|
766
|
|
767 (defun w3-display-fix-widgets ()
|
|
768 ;; Make markers belong to the right buffer
|
|
769 (save-excursion
|
|
770 (let ((st (point-min))
|
|
771 (nd nil)
|
|
772 (widget nil) parent
|
|
773 (to-marker nil)
|
|
774 (from-marker nil))
|
|
775 (while (setq st (next-single-property-change st 'button))
|
|
776 (setq nd (or (next-single-property-change st 'button) (point-max))
|
|
777 widget (widget-at st)
|
|
778 to-marker (and widget (widget-get widget :to))
|
|
779 from-marker (and widget (widget-get widget :from))
|
|
780 parent (and widget (widget-get widget :parent))
|
|
781 )
|
|
782 (if (not widget)
|
|
783 nil
|
|
784 (widget-put widget :from (set-marker (make-marker) st))
|
|
785 (widget-put widget :to (set-marker (make-marker) nd))
|
|
786 (if (not parent)
|
|
787 nil
|
|
788 (widget-put parent :from (set-marker (make-marker) st))
|
|
789 (widget-put parent :to (set-marker (make-marker) nd))))
|
|
790 (if (condition-case ()
|
|
791 (get-text-property (1+ nd) 'button)
|
|
792 (error nil))
|
|
793 (setq st nd)
|
|
794 (setq st (min (point-max) (1+ nd))))))))
|
|
795
|
|
796 (defun w3-size-of-tree (tree minmax)
|
|
797 (save-excursion
|
|
798 (save-restriction
|
|
799 (narrow-to-region (point) (point))
|
|
800 ;; XXX fill-column set to 1 fails when fill-prefix is set
|
|
801 ;; XXX setting fill-column at all isn't really right
|
|
802 ;; for example <hr>s shouldn't be especially wide
|
|
803 ;; we should set a flag that makes w3 never wrap a line
|
|
804 (let ((fill-column (cond ((eq minmax 'min)
|
|
805 3)
|
|
806 ((eq minmax 'max)
|
|
807 400)))
|
|
808 (fill-prefix "")
|
|
809 (w3-last-fill-pos (point-min))
|
|
810 a retval
|
|
811 (w3-do-incremental-display nil)
|
|
812 (hr-regexp (concat "^"
|
|
813 (regexp-quote
|
|
814 (make-string 5 w3-horizontal-rule-char))
|
|
815 "*$"))
|
|
816 )
|
|
817 ;;(push 'left w3-display-alignment-stack)
|
|
818 (push (if (eq minmax 'max) 'nowrap) w3-display-whitespace-stack)
|
|
819 (while tree
|
|
820 (push (cons '*td args) w3-display-open-element-stack)
|
|
821 (w3-display-node (pop tree)))
|
|
822 (pop w3-display-whitespace-stack)
|
|
823 (goto-char (point-min))
|
|
824 (while (re-search-forward hr-regexp nil t)
|
|
825 (replace-match "" t t))
|
|
826 (goto-char (point-min))
|
|
827 (while (not (eobp))
|
|
828 ;; loop invariant: at beginning of uncounted line
|
|
829 (end-of-line)
|
|
830 (skip-chars-backward " ")
|
|
831 (setq retval (cons (current-column)
|
|
832 retval))
|
|
833 (beginning-of-line 2))
|
|
834 (if (= (point-min) (point-max))
|
|
835 (setq retval 0)
|
|
836 (setq retval (apply 'max (cons 0 retval))))
|
|
837 (delete-region (point-min) (point-max))
|
|
838 retval))))
|
|
839
|
|
840 (defun w3-display-table-dimensions (node)
|
|
841 ;; fill-column sets maximum width
|
|
842 (let (min-vector
|
|
843 max-vector
|
|
844 rows cols
|
|
845 ;;(w3-form-elements (and (boundp 'w3-form-elements) w3-form-elements))
|
|
846 (table-info (assq 'w3-table-info (cadr node))))
|
|
847
|
|
848 (if table-info
|
|
849 (setq min-vector (nth 1 table-info)
|
|
850 max-vector (nth 2 table-info)
|
|
851 rows (nth 3 table-info)
|
|
852 cols (nth 4 table-info))
|
|
853
|
|
854 (push (cons '*table-autolayout args) w3-display-open-element-stack)
|
|
855 (let (content
|
|
856 cur
|
|
857 (table-spans (list nil)) ; don't make this '(nil)
|
|
858 ptr
|
|
859 col
|
|
860 constraints
|
|
861
|
|
862 colspan rowspan min max)
|
|
863 (setq content (nth 2 node))
|
|
864 (setq rows 0 cols 0)
|
|
865 (while content
|
|
866 (setq cur (pop content))
|
|
867 (if (stringp cur)
|
|
868 nil
|
|
869 (case (car cur)
|
|
870 (tr
|
|
871 (setq col 0)
|
|
872 (setq rows (1+ rows))
|
|
873 (setq ptr table-spans)
|
|
874 (mapcar
|
|
875 (function
|
|
876 (lambda (td)
|
|
877 (setq colspan (string-to-int (or (cdr-safe (assq 'colspan (nth 1 td))) "1"))
|
|
878 rowspan (string-to-int (or (cdr-safe (assq 'rowspan (nth 1 td))) "1"))
|
|
879 min (w3-size-of-tree (nth 2 td) 'min)
|
|
880 max (w3-size-of-tree (nth 2 td) 'max)
|
|
881 )
|
|
882 (while (eq (car-safe (car-safe (cdr ptr))) col)
|
|
883 (setq col (+ col (cdr (cdr (car (cdr ptr))))))
|
|
884 (if (= 0 (decf (car (cdr (car (cdr ptr))))))
|
|
885 (pop (cdr ptr))
|
|
886 (setq ptr (cdr ptr))))
|
|
887 (push (list col colspan min max)
|
|
888 constraints)
|
|
889 (if (= rowspan 1) nil
|
|
890 (push (cons col (cons (1- rowspan) colspan)) (cdr ptr))
|
|
891 (setq ptr (cdr ptr)))
|
|
892 (setq col (+ col colspan))
|
|
893 ))
|
|
894 (nth 2 cur))
|
|
895 (while (cdr ptr)
|
|
896 (if (= 0 (decf (car (cdr (car (cdr ptr))))))
|
|
897 (pop (cdr ptr))
|
|
898 (setq ptr (cdr ptr))))
|
|
899 (setq cols (max cols col))
|
|
900 )
|
|
901 (caption
|
|
902 nil)
|
|
903 (otherwise
|
|
904 (setq content (nth 2 cur)))
|
|
905 )
|
|
906 )
|
|
907 )
|
|
908 (setq constraints (sort constraints
|
|
909 (function
|
|
910 (lambda (a b)
|
|
911 (< (cadr a) (cadr b)))))
|
|
912 min-vector (make-vector cols 0)
|
|
913 max-vector (make-vector cols 0))
|
|
914 (let (start end i mincellwidth maxcellwidth)
|
|
915 (mapcar (function (lambda (c)
|
|
916 (cond ((= (cadr c) 1)
|
|
917 (aset min-vector (car c)
|
|
918 (max (aref min-vector (car c))
|
|
919 (nth 2 c)))
|
|
920 (aset max-vector (car c)
|
|
921 (max (aref max-vector (car c))
|
|
922 (nth 3 c))))
|
|
923 (t
|
|
924 (setq start (car c)
|
|
925 end (+ (car c) (cadr c))
|
|
926 mincellwidth 0
|
|
927 maxcellwidth 0
|
|
928 i start)
|
|
929 (while (< i end)
|
|
930 (setq mincellwidth (+ mincellwidth
|
|
931 (aref min-vector i))
|
|
932 maxcellwidth (+
|
|
933 maxcellwidth
|
|
934 (aref max-vector i))
|
|
935 i (1+ i)))
|
|
936 (setq i start)
|
|
937 (if (= mincellwidth 0)
|
|
938 ;; if existing width is 0 divide evenly
|
|
939 (while (< i end)
|
|
940 (aset min-vector i
|
|
941 (/ (nth 2 c) (cadr c)))
|
|
942 (aset max-vector i
|
|
943 (/ (nth 3 c) (cadr c)))
|
|
944 (setq i (1+ i)))
|
|
945 ;; otherwise weight it by existing widths
|
|
946 (while (< i end)
|
|
947 (aset min-vector i
|
|
948 (max (aref min-vector i)
|
|
949 (/ (* (nth 2 c)
|
|
950 (aref min-vector i))
|
|
951 mincellwidth)))
|
|
952 (aset max-vector i
|
|
953 (max (aref max-vector i)
|
|
954 (/ (* (nth 3 c)
|
|
955 (aref max-vector i))
|
|
956 maxcellwidth)))
|
|
957 (setq i (1+ i))))
|
|
958 ))))
|
|
959 constraints)))
|
|
960 (push (cons 'w3-table-info
|
|
961 (list min-vector max-vector rows cols))
|
|
962 (cadr node))
|
|
963 (pop w3-display-open-element-stack))
|
|
964
|
|
965 (let (max-width
|
|
966 min-width
|
|
967 ret-vector
|
|
968 col
|
|
969 )
|
|
970
|
|
971
|
|
972 (setq max-width (apply '+ (append max-vector (list cols 1))))
|
|
973 (setq min-width (apply '+ (append min-vector (list cols 1))))
|
|
974
|
|
975 ;; the comments in the cond are excerpts from rfc1942 itself
|
|
976 (cond
|
|
977 ;; 1. The minimum table width is equal to or wider than the available
|
|
978 ;; space. In this case, assign the minimum widths and allow the
|
|
979 ;; user to scroll horizontally. For conversion to braille, it will
|
|
980 ;; be necessary to replace the cells by references to notes
|
|
981 ;; containing their full content. By convention these appear
|
|
982 ;; before the table.
|
|
983 ((>= min-width fill-column)
|
|
984 (setq ret-vector min-vector))
|
|
985
|
|
986 ;; 2. The maximum table width fits within the available space. In
|
|
987 ;; this case, set the columns to their maximum widths.
|
|
988 ((<= max-width fill-column)
|
|
989 (setq ret-vector max-vector))
|
|
990
|
|
991 ;; 3. The maximum width of the table is greater than the available
|
|
992 ;; space, but the minimum table width is smaller. In this case,
|
|
993 ;; find the difference between the available space and the minimum
|
|
994 ;; table width, lets call it W. Lets also call D the difference
|
|
995 ;; between maximum and minimum width of the table.
|
|
996
|
|
997 ;; For each column, let d be the difference between maximum and
|
|
998 ;; minimum width of that column. Now set the column's width to the
|
|
999 ;; minimum width plus d times W over D. This makes columns with
|
|
1000 ;; large differences between minimum and maximum widths wider than
|
|
1001 ;; columns with smaller differences.
|
|
1002 (t
|
|
1003 (setq ret-vector (make-vector cols 0))
|
|
1004 (let ((W (- fill-column min-width))
|
|
1005 (D (- max-width min-width))
|
|
1006 d extra)
|
|
1007 (setq col 0)
|
|
1008 (while (< col (length ret-vector))
|
|
1009 (setq d (- (aref max-vector col)
|
|
1010 (aref min-vector col)))
|
|
1011 (aset ret-vector col
|
|
1012 (+ (aref min-vector col)
|
|
1013 (/ (* d W) D)))
|
|
1014 (setq col (1+ col)))
|
|
1015 (setq extra (- fill-column
|
|
1016 (apply '+ (append ret-vector
|
|
1017 (list (length ret-vector) 1))))
|
|
1018 col 0)
|
|
1019 (while (and (< col (length ret-vector)) (> extra 0))
|
|
1020 (if (= 1 (- (aref max-vector col) (aref ret-vector col) ))
|
|
1021 (aset ret-vector col (1+ (aref ret-vector col))))
|
|
1022 (setq extra (1- extra)
|
|
1023 col (1+ col)))
|
|
1024 )))
|
|
1025 (list rows cols ret-vector))))
|
|
1026
|
|
1027 (defvar w3-table-ascii-border-chars
|
|
1028 [? ? ? ?/ ? ?- ?\\ ?- ? ?\\ ?| ?| ?/ ?- ?| ?-]
|
|
1029 "Vector of ascii characters to use to draw table borders.
|
|
1030 w3-table-unhack-border-chars uses this to restore w3-table-border-chars.")
|
|
1031
|
|
1032 (defvar w3-table-border-chars w3-table-ascii-border-chars
|
|
1033 "Vector of characters to use to draw table borders.
|
|
1034 If you set this you should set w3-table-ascii-border-chars to the same value
|
|
1035 so that w3-table-unhack-borders can restore the value if necessary.
|
|
1036
|
|
1037 A reasonable value is [? ? ? ?/ ? ?- ?\\\\ ?^ ? ?\\\\ ?| ?< ?/ ?- ?> ?-]
|
|
1038 Though i recommend replacing the ^ with - and the < and > with |")
|
|
1039
|
|
1040 (defsubst w3-table-lookup-char (l u r b)
|
|
1041 (aref w3-table-border-chars (logior (if l 1 0)
|
|
1042 (if u 2 0)
|
|
1043 (if r 4 0)
|
|
1044 (if b 8 0))))
|
|
1045
|
|
1046 (defun w3-table-hack-borders nil
|
|
1047 "Try to find the best set of characters to draw table borders with.
|
|
1048 I definitely recommend trying this on X.
|
|
1049 On a console, this can trigger some Emacs display bugs.
|
|
1050
|
|
1051 I haven't tried this on XEmacs or any window-system other than X."
|
|
1052 (interactive)
|
|
1053 (case (device-type)
|
|
1054 (x
|
|
1055 (let ((id (or (and (find-face 'w3-table-hack-x-face)
|
|
1056 (face-id 'w3-table-hack-x-face))
|
|
1057 (progn
|
|
1058 (make-face 'w3-table-hack-x-face)
|
|
1059 (set-face-font 'w3-table-hack-x-face
|
|
1060 (make-font :family "terminal"))
|
|
1061 (face-id 'w3-table-hack-x-face)))))
|
|
1062 (if (not (face-differs-from-default-p 'w3-table-hack-x-face))
|
|
1063 nil
|
|
1064 (aset standard-display-table 1 (vector (+ (* 256 id) ?l)))
|
|
1065 (aset standard-display-table 2 (vector (+ (* 256 id) ?q)))
|
|
1066 (aset standard-display-table 3 (vector (+ (* 256 id) ?k)))
|
|
1067 (aset standard-display-table 4 (vector (+ (* 256 id) ?t)))
|
|
1068 (aset standard-display-table 5 (vector (+ (* 256 id) ?n)))
|
|
1069 (aset standard-display-table 6 (vector (+ (* 256 id) ?u)))
|
|
1070 (aset standard-display-table 7 (vector (+ (* 256 id) ?m)))
|
|
1071 (aset standard-display-table 8 (vector (+ (* 256 id) ?x)))
|
|
1072 (aset standard-display-table 11 (vector (+ (* 256 id) ?j)))
|
|
1073 (aset standard-display-table 14 (vector (+ (* 256 id) ?v)))
|
|
1074 (aset standard-display-table 15 (vector (+ (* 256 id) ?w)))
|
|
1075 (setq w3-table-border-chars [? ? ? 11 ? 2 7 14 ? 3 8 6 1 15 4 5])
|
|
1076 (setq w3-horizontal-rule-char 2))))
|
|
1077 (tty
|
|
1078 (standard-display-g1 1 108) ; ulcorner
|
|
1079 (standard-display-g1 2 113) ; hline
|
|
1080 (standard-display-g1 3 107) ; urcorner
|
|
1081 (standard-display-g1 4 116) ; leftt
|
|
1082 (standard-display-g1 5 110) ; intersection
|
|
1083 (standard-display-g1 6 117) ; rightt
|
|
1084 (standard-display-g1 7 109) ; llcorner
|
|
1085 (standard-display-g1 8 120) ; vline
|
|
1086 (standard-display-g1 11 106) ; lrcorner
|
|
1087 (standard-display-g1 14 118) ; upt
|
|
1088 (standard-display-g1 15 119) ; downt
|
|
1089 (setq w3-table-border-chars [? ? ? 11 ? 2 7 14 ? 3 8 6 1 15 4 5])
|
|
1090 (setq w3-horizontal-rule-char 2))
|
|
1091 (otherwise
|
|
1092 (error "Unknown window-system, can't do any better than ascii borders")))
|
|
1093 )
|
|
1094
|
|
1095 (defun w3-table-unhack-borders nil
|
|
1096 (interactive)
|
|
1097 (w3-table-excise-hack (buffer-list))
|
|
1098 (standard-display-default 1 15)
|
|
1099 (setq w3-table-border-chars w3-table-ascii-border-chars)
|
|
1100 (setq w3-horizontal-rule-char ?-))
|
|
1101
|
|
1102 (defun w3-table-excise-hack (buffs)
|
|
1103 "Replace hacked characters with ascii characters in buffers BUFFS.
|
|
1104 Should be run before restoring w3-table-border-chars to ascii characters."
|
|
1105 (interactive (list (list (current-buffer))))
|
|
1106 (let ((inhibit-read-only t)
|
|
1107 (tr (make-string 16 ? ))
|
|
1108 (i 0))
|
|
1109 (while (< i (length tr))
|
|
1110 (aset tr i i)
|
|
1111 (setq i (1+ i)))
|
|
1112 (setq i 0)
|
|
1113 (while (< i (length w3-table-border-chars))
|
|
1114 (if (< (aref w3-table-border-chars i) 16)
|
|
1115 (aset tr
|
|
1116 (aref w3-table-border-chars i)
|
|
1117 (aref w3-table-ascii-border-chars i)))
|
|
1118 (setq i (1+ i)))
|
|
1119 (mapcar (function (lambda (buf)
|
|
1120 (save-excursion
|
|
1121 (set-buffer buf)
|
|
1122 (if (eq major-mode 'w3-mode)
|
|
1123 (translate-region (point-min)
|
|
1124 (point-max)
|
|
1125 tr)))))
|
|
1126 buffs)))
|
|
1127
|
|
1128 (defun w3-display-table (node)
|
|
1129 (let* ((dimensions (w3-display-table-dimensions node))
|
|
1130 (num-cols (max (cadr dimensions) 1))
|
|
1131 (num-rows (max (car dimensions) 1))
|
|
1132 (column-dimensions (caddr dimensions))
|
|
1133 (table-width (apply '+ (append column-dimensions (list num-cols 1)))))
|
|
1134 (cond
|
|
1135 ((or (<= (cadr dimensions) 0) (<= (car dimensions) 0))
|
|
1136 ;; We have an invalid table
|
|
1137 nil)
|
|
1138 ((assq '*table-autolayout w3-display-open-element-stack)
|
|
1139 ;; don't bother displaying the table if all we really need is the size
|
|
1140 (progn (insert-char ?T table-width) (insert "\n")))
|
|
1141 (t
|
|
1142 (let* ((tag (nth 0 node))
|
|
1143 (args (nth 1 node))
|
|
1144 (border-node (cdr-safe (assq 'border args)))
|
|
1145 (border (or w3-display-table-force-borders
|
|
1146 (and border-node
|
|
1147 (or (/= 0 (string-to-int border-node))
|
|
1148 (string= "border" border-node)))))
|
|
1149 (w3-table-border-chars
|
|
1150 (if border
|
|
1151 w3-table-border-chars
|
|
1152 (make-vector (length w3-table-border-chars) ? )))
|
|
1153 valign align
|
|
1154 (content (nth 2 node))
|
|
1155 (avgwidth (/ (- fill-column num-cols num-cols) num-cols))
|
|
1156 (formatted-cols (make-vector num-cols nil))
|
|
1157 (table-rowspans (make-vector num-cols 0))
|
|
1158 (table-colspans (make-vector num-cols 1))
|
|
1159 (prev-colspans (make-vector num-cols 0))
|
|
1160 (prev-rowspans (make-vector num-cols 0))
|
|
1161 (table-colwidth (make-vector num-cols 0))
|
|
1162 (fill-prefix "")
|
|
1163 (height nil)
|
|
1164 (cur-height nil)
|
|
1165 (cols nil)
|
|
1166 (rows nil)
|
|
1167 (row 0)
|
|
1168 (this-rectangle nil)
|
|
1169 (i 0)
|
|
1170 )
|
|
1171
|
|
1172 (push (cons tag args) w3-display-open-element-stack)
|
|
1173
|
|
1174 (if (memq 'nowrap w3-display-whitespace-stack)
|
|
1175 (setq fill-prefix "")
|
|
1176 (case (car w3-display-alignment-stack)
|
|
1177 (center
|
|
1178 (w3-set-fill-prefix-length
|
|
1179 (max 0 (/ (- fill-column table-width) 2))))
|
|
1180 (right
|
|
1181 (w3-set-fill-prefix-length
|
|
1182 (max 0 (- fill-column table-width))))
|
|
1183 (t
|
|
1184 (setq fill-prefix ""))))
|
|
1185 (while content
|
|
1186 (case (caar content)
|
|
1187 (tr
|
|
1188 (setq w3-display-css-properties (css-get
|
|
1189 (nth 0 (car content))
|
|
1190 (nth 1 (car content))
|
|
1191 w3-current-stylesheet
|
|
1192 w3-display-open-element-stack))
|
|
1193 (setq cols (nth 2 (car content))
|
|
1194 valign (or (cdr-safe (assq 'valign (nth 1 (car content))))
|
|
1195 (w3-get-style-info 'vertical-align node))
|
|
1196 align (or (cdr-safe (assq 'align (nth 1 (car content))))
|
|
1197 (w3-get-style-info 'text-align node))
|
|
1198 content (cdr content)
|
|
1199 row (1+ row))
|
|
1200 (if (and valign (stringp valign))
|
|
1201 (setq valign (intern (downcase valign))))
|
|
1202 ;; this is iffy
|
|
1203 ;;(if align (push (intern (downcase align)) w3-display-alignment-stack))
|
|
1204 (save-excursion
|
|
1205 (save-restriction
|
|
1206 (narrow-to-region (point) (point))
|
|
1207 (setq fill-column avgwidth
|
|
1208 inhibit-read-only t
|
|
1209 w3-last-fill-pos (point-min)
|
|
1210 i 0)
|
|
1211 ;; skip over columns that have leftover content
|
|
1212 (while (and (< i num-cols)
|
|
1213 (/= 0 (aref table-rowspans i)))
|
|
1214 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1215 (while cols
|
|
1216 (let* ((node (car cols))
|
|
1217 (attributes (nth 1 node))
|
|
1218 (colspan (string-to-int
|
|
1219 (or (cdr-safe (assq 'colspan attributes))
|
|
1220 "1")))
|
|
1221 (rowspan (string-to-int
|
|
1222 (or (cdr-safe (assq 'rowspan attributes))
|
|
1223 "1")))
|
|
1224 fill-column column-width
|
|
1225 (fill-prefix "")
|
|
1226 (w3-do-incremental-display nil)
|
|
1227 (indent-tabs-mode nil)
|
|
1228 c e
|
|
1229 )
|
|
1230
|
|
1231 (aset table-colspans i colspan)
|
|
1232 (aset table-rowspans i rowspan)
|
|
1233
|
|
1234 (setq fill-column 0)
|
|
1235 (setq c i
|
|
1236 e (+ i colspan))
|
|
1237 (while (< c e)
|
|
1238 (setq fill-column (+ fill-column
|
|
1239 (aref column-dimensions c)
|
|
1240 1)
|
|
1241 c (1+ c)))
|
|
1242 (setq fill-column (1- fill-column))
|
|
1243 (aset table-colwidth i fill-column)
|
|
1244
|
|
1245 (setq w3-last-fill-pos (point-min))
|
|
1246 (push (cons (nth 0 node) (nth 1 node))
|
|
1247 w3-display-open-element-stack)
|
|
1248 (w3-display-node node)
|
|
1249 (setq fill-column (aref table-colwidth i))
|
|
1250 (if w3-display-table-cut-words-p
|
|
1251 (w3-display-table-cut))
|
|
1252 (setq cols (cdr cols))
|
|
1253 (goto-char (point-min))
|
|
1254 (skip-chars-forward "\t\n\r")
|
|
1255 (beginning-of-line)
|
|
1256 (delete-region (point-min) (point))
|
|
1257 (goto-char (point-max))
|
|
1258 (skip-chars-backward " \t\n\r")
|
|
1259 (delete-region (point) (point-max))
|
|
1260 (if (>= fill-column (current-column))
|
|
1261 (insert-char ? (- fill-column (current-column))))
|
|
1262 (aset formatted-cols i (extract-rectangle (point-min) (point-max)))
|
|
1263 (delete-region (point-min) (point-max))
|
|
1264 (let ((j (1- colspan)))
|
|
1265 (while (> j 0)
|
|
1266 (aset table-colspans (+ i j) 0)
|
|
1267 (setq j (1- j))))
|
|
1268 (setq i (+ i colspan))
|
|
1269 ;; skip over columns that have leftover content
|
|
1270 (while (and (< i num-cols)
|
|
1271 (/= 0 (aref table-rowspans i)))
|
|
1272 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1273 ))
|
|
1274
|
|
1275 ;; finish off the columns
|
|
1276 (while (< i num-cols)
|
|
1277 (aset table-colwidth i (aref column-dimensions i))
|
|
1278 (aset table-colspans i 1)
|
|
1279 (setq i (1+ i))
|
|
1280 (while (and (< i num-cols)
|
|
1281 (/= 0 (aref table-rowspans i)))
|
|
1282 (setq i (+ i (max 1 (aref table-colspans i))))))
|
|
1283
|
|
1284 ;; on the last row empty any pending rowspans per the rfc
|
|
1285 (if content nil
|
|
1286 (fillarray table-rowspans 1))
|
|
1287
|
|
1288 ;; Find the tallest rectangle that isn't a rowspanning cell
|
|
1289 (setq height 0
|
|
1290 i 0)
|
|
1291 (while (< i num-cols)
|
|
1292 (if (= 1 (aref table-rowspans i))
|
|
1293 (setq height (max height (length (aref formatted-cols i)))))
|
|
1294 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1295
|
|
1296 ;; Make all rectangles the same height
|
|
1297 (setq i 0)
|
|
1298 (while (< i num-cols)
|
|
1299 (setq this-rectangle (aref formatted-cols i))
|
|
1300 (if (> height (length this-rectangle))
|
|
1301 (let ((colspan-fill-line
|
|
1302 (make-string (aref table-colwidth i) ? )))
|
|
1303 (case valign
|
|
1304 ((center middle)
|
|
1305 (aset formatted-cols i
|
|
1306 (append (make-list (/ (- height (length this-rectangle)) 2)
|
|
1307 colspan-fill-line)
|
|
1308 this-rectangle)))
|
|
1309 (bottom
|
|
1310 (aset formatted-cols i
|
|
1311 (append (make-list (- height (length this-rectangle))
|
|
1312 colspan-fill-line)
|
|
1313 this-rectangle))))))
|
|
1314 (setq i (+ i (max 1 (aref table-colspans i)))))))
|
|
1315
|
|
1316
|
|
1317 ;; fix broken colspans (this should only matter on illegal tables)
|
|
1318 (setq i 0)
|
|
1319 (while (< i num-cols)
|
|
1320 (if (= (aref table-colspans i) 0)
|
|
1321 (aset table-colspans i 1))
|
|
1322 (setq i (+ i (aref table-colspans i))))
|
|
1323
|
|
1324 ;; Insert a separator
|
|
1325 (insert fill-prefix)
|
|
1326 (setq i 0)
|
|
1327 (let (rflag bflag tflag lflag)
|
|
1328 (while (< i num-cols)
|
|
1329
|
|
1330 (setq rflag (= (aref prev-rowspans i) 0))
|
|
1331 (setq bflag (/= (aref table-colspans i) 0))
|
|
1332 (setq tflag (/= (aref prev-colspans i) 0))
|
|
1333
|
|
1334 (insert (w3-table-lookup-char lflag tflag rflag bflag))
|
|
1335 (setq lflag t)
|
|
1336 (cond ((= (aref prev-rowspans i) 0)
|
|
1337 (insert-char (w3-table-lookup-char t nil t nil)
|
|
1338 (aref column-dimensions i))
|
|
1339 (setq i (1+ i)))
|
|
1340 ((car (aref formatted-cols i))
|
|
1341 (insert (pop (aref formatted-cols i)))
|
|
1342 (setq lflag nil)
|
|
1343 (setq i (+ i (max (aref table-colspans i)
|
|
1344 (aref prev-colspans i) 1))))
|
|
1345 (t
|
|
1346 (insert-char ? (aref table-colwidth i))
|
|
1347 (setq lflag nil)
|
|
1348 (setq i (+ i (max (aref table-colspans i)
|
|
1349 (aref prev-colspans i) 1))))))
|
|
1350 (insert (w3-table-lookup-char lflag (/= row 1) nil t) "\n"))
|
|
1351
|
|
1352 ;; recalculate height (in case we've shortened a rowspanning cell
|
|
1353 (setq height 0
|
|
1354 i 0)
|
|
1355 (while (< i num-cols)
|
|
1356 (if (= 1 (aref table-rowspans i))
|
|
1357 (setq height (max height (length (aref formatted-cols i)))))
|
|
1358 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1359
|
|
1360 ;; Insert a row back in original buffer
|
|
1361 (while (> height 0)
|
|
1362 (insert fill-prefix (w3-table-lookup-char nil t nil t))
|
|
1363 (setq i 0)
|
|
1364 (while (< i num-cols)
|
|
1365 (if (car (aref formatted-cols i))
|
|
1366 (insert (pop (aref formatted-cols i)))
|
|
1367 (insert-char ? (aref table-colwidth i)))
|
|
1368 (insert (w3-table-lookup-char nil t nil t))
|
|
1369 (setq i (+ i (max (aref table-colspans i) 1))))
|
|
1370 (insert "\n")
|
|
1371 ;;(and w3-do-incremental-display (w3-pause))
|
|
1372 (setq height (1- height)))
|
|
1373
|
|
1374 (setq i 0)
|
|
1375 (while (< i num-cols)
|
|
1376 (if (> (aref table-rowspans i) 0)
|
|
1377 (decf (aref table-rowspans i)))
|
|
1378 (incf i))
|
|
1379
|
|
1380 (setq prev-rowspans (copy-seq table-rowspans))
|
|
1381 (setq prev-colspans (copy-seq table-colspans))
|
|
1382
|
|
1383 (and w3-do-incremental-display (w3-pause))
|
|
1384
|
|
1385 )
|
|
1386 (caption
|
|
1387 (let ((left (length fill-prefix))
|
|
1388 (fill-prefix "")
|
|
1389 (fill-column table-width)
|
|
1390 (start (point)))
|
|
1391 (w3-display-node (pop content))
|
|
1392 (indent-rigidly start (point) left)))
|
|
1393 (otherwise
|
|
1394 (delete-horizontal-space)
|
|
1395 (setq content (nth 2 (car content))))
|
|
1396 ))
|
|
1397 (if (= (length column-dimensions) 0) nil
|
|
1398 (insert fill-prefix)
|
|
1399 (setq i 0)
|
|
1400 (let (tflag lflag)
|
|
1401 (while (< i num-cols)
|
|
1402 (setq tflag (/= (aref prev-colspans i) 0))
|
|
1403 (insert (w3-table-lookup-char lflag tflag t nil))
|
|
1404 (setq lflag t)
|
|
1405 (insert-char (w3-table-lookup-char t nil t nil)
|
|
1406 (aref column-dimensions i))
|
|
1407 (setq i (1+ i)))
|
|
1408 (insert (w3-table-lookup-char t t nil nil) "\n")))
|
|
1409 )
|
|
1410 (pop w3-display-open-element-stack)))))
|
|
1411
|
|
1412
|
|
1413
|
|
1414 (defun w3-display-create-unique-id ()
|
|
1415 (let* ((date (current-time-string))
|
|
1416 (dateinfo (and date (timezone-parse-date date)))
|
|
1417 (timeinfo (and date (timezone-parse-time (aref dateinfo 3)))))
|
|
1418 (if (and dateinfo timeinfo)
|
|
1419 (concat (aref dateinfo 0) ; Year
|
|
1420 (aref dateinfo 1) ; Month
|
|
1421 (aref dateinfo 2) ; Day
|
|
1422 (aref timeinfo 0) ; Hour
|
|
1423 (aref timeinfo 1) ; Minute
|
|
1424 (aref timeinfo 2) ; Second
|
|
1425 )
|
|
1426 "HoplesSLYCoNfUSED")))
|
|
1427
|
82
|
1428 (defun w3-display-chop-into-table (node cols)
|
|
1429 ;; Chop the content of 'node' up into 'cols' columns suitable for inclusion
|
|
1430 ;; as the content of a table
|
|
1431 (let ((content (nth 2 node))
|
|
1432 (items nil)
|
|
1433 (rows nil))
|
|
1434 (setq cols (max cols 1))
|
|
1435 (while content
|
|
1436 (push (list 'td nil (list (pop content))) items)
|
|
1437 (if (= (length items) cols)
|
|
1438 (setq rows (cons (nreverse items) rows)
|
|
1439 items nil)))
|
|
1440 (if items ; Store any leftovers
|
|
1441 (setq rows (cons (nreverse items) rows)
|
|
1442 items nil))
|
|
1443 (while rows
|
|
1444 (push (list 'tr nil (pop rows)) items))
|
|
1445 items))
|
|
1446
|
86
|
1447 (defun w3-display-normalize-form-info (args)
|
|
1448 (let* ((plist (alist-to-plist args))
|
|
1449 (type (intern (downcase
|
|
1450 (or (plist-get plist 'type) "text"))))
|
|
1451 (name (plist-get plist 'name))
|
|
1452 (value (or (plist-get plist 'value) ""))
|
|
1453 (size (if (plist-get plist 'size)
|
|
1454 (string-to-int (plist-get plist 'size))))
|
|
1455 (maxlength (if (plist-get plist 'maxlength)
|
|
1456 (string-to-int
|
|
1457 (plist-get plist 'maxlength))))
|
|
1458 (default value)
|
|
1459 (checked (assq 'checked args)))
|
|
1460 (if (memq type '(checkbox radio)) (setq default checked))
|
|
1461 (if (and (eq type 'checkbox) (string= value ""))
|
|
1462 (setq value "on"))
|
|
1463 (if (and (not (memq type '(submit reset button)))
|
|
1464 (not name))
|
|
1465 (setq name (symbol-name type)))
|
|
1466 (while (and name (string-match "[\r\n]+" name))
|
|
1467 (setq name (concat (substring name 0 (match-beginning 0))
|
|
1468 (substring name (match-end 0) nil))))
|
|
1469 (setq plist (plist-put plist 'type type)
|
|
1470 plist (plist-put plist 'name name)
|
|
1471 plist (plist-put plist 'value value)
|
|
1472 plist (plist-put plist 'size size)
|
|
1473 plist (plist-put plist 'default default)
|
|
1474 plist (plist-put plist 'internal-form-number w3-current-form-number)
|
|
1475 plist (plist-put plist 'action w3-display-form-id)
|
|
1476 plist (plist-put plist 'maxlength maxlength))
|
|
1477 plist))
|
|
1478
|
14
|
1479 (defun w3-display-node (node &optional nofaces)
|
|
1480 (let (
|
|
1481 (content-stack (list (list node)))
|
|
1482 (right-margin-stack (list fill-column))
|
|
1483 (left-margin-stack (list 0))
|
|
1484 node
|
|
1485 insert-before
|
|
1486 insert-after
|
|
1487 tag
|
|
1488 args
|
|
1489 content
|
|
1490 hyperlink-info
|
|
1491 break-style
|
|
1492 cur
|
|
1493 id
|
|
1494 class
|
|
1495 )
|
|
1496 (while content-stack
|
|
1497 (setq content (pop content-stack))
|
|
1498 (pop w3-active-faces)
|
|
1499 (pop w3-active-voices)
|
|
1500 (case (car (pop w3-display-open-element-stack))
|
|
1501 ;; Any weird, post-display-of-content stuff for specific tags
|
|
1502 ;; goes here. Couldn't think of any better way to do this when we
|
|
1503 ;; are iterative. *sigh*
|
|
1504 (a
|
|
1505 (if (not hyperlink-info)
|
|
1506 nil
|
|
1507 (add-text-properties (car hyperlink-info) (point)
|
|
1508 (list
|
|
1509 'mouse-face 'highlight
|
|
1510 'duplicable t
|
82
|
1511 'start-open t
|
|
1512 'end-open t
|
|
1513 'rear-nonsticky t
|
14
|
1514 'help-echo 'w3-balloon-help-callback
|
|
1515 'balloon-help 'w3-balloon-help-callback))
|
|
1516 (fillin-text-property (car hyperlink-info) (point)
|
|
1517 'button 'button (cadr hyperlink-info))
|
|
1518 (widget-put (cadr hyperlink-info) :to (set-marker
|
|
1519 (make-marker) (point))))
|
|
1520 (setq hyperlink-info nil))
|
|
1521 ((ol ul dl dir menu)
|
|
1522 (pop w3-display-list-stack))
|
|
1523 (otherwise
|
|
1524 nil))
|
|
1525 (if (car insert-after)
|
|
1526 (w3-handle-string-content (car insert-after)))
|
|
1527 (pop insert-after)
|
|
1528 (w3-display-handle-end-break)
|
|
1529 (w3-pop-all-face-info)
|
|
1530 ;; Handle the element's content
|
|
1531 (while content
|
|
1532 (if (stringp (car content))
|
|
1533 (w3-handle-string-content (pop content))
|
|
1534 (setq node (pop content)
|
|
1535 tag (nth 0 node)
|
|
1536 args (nth 1 node)
|
|
1537 id (or (w3-get-attribute 'name)
|
|
1538 (w3-get-attribute 'id))
|
|
1539 )
|
|
1540 ;; This little bit of magic takes care of inline styles.
|
|
1541 ;; Evil Evil Evil, but it appears to work.
|
|
1542 (if (w3-get-attribute 'style)
|
|
1543 (let ((unique-id (or (w3-get-attribute 'id)
|
|
1544 (w3-display-create-unique-id)))
|
82
|
1545 (sheet "")
|
|
1546 (class (assq 'class args)))
|
14
|
1547 (setq sheet (format "%s.%s { %s }\n" tag unique-id
|
|
1548 (w3-get-attribute 'style)))
|
82
|
1549 (if class
|
|
1550 (setcdr class (cons unique-id (cdr class)))
|
|
1551 (setf (nth 1 node) (cons (cons 'class (list unique-id))
|
|
1552 (nth 1 node))))
|
|
1553 (setf (nth 1 node) (cons (cons 'id unique-id) (nth 1 node)))
|
|
1554 (w3-handle-style (list 'data sheet
|
|
1555 'notation "css"))))
|
14
|
1556 (setq w3-display-css-properties (css-get
|
82
|
1557 (nth 0 node)
|
|
1558 (nth 1 node)
|
14
|
1559 w3-current-stylesheet
|
|
1560 w3-display-open-element-stack))
|
|
1561 (if nofaces
|
|
1562 nil
|
|
1563 (push (w3-face-for-element node) w3-active-faces)
|
|
1564 (push (w3-voice-for-element node) w3-active-voices))
|
|
1565 (push (w3-get-style-info 'display node) break-style)
|
|
1566 (push (w3-get-style-info 'insert-after node) insert-after)
|
|
1567 (setq insert-before (w3-get-style-info 'insert-before node))
|
|
1568 (w3-display-handle-break)
|
|
1569 (if (w3-node-visible-p)
|
|
1570 nil
|
|
1571 (setq insert-before nil
|
|
1572 tag '*invisible)
|
|
1573 (setcar insert-after nil))
|
|
1574 (if insert-before
|
|
1575 (w3-handle-string-content insert-before))
|
|
1576 (setq insert-before nil)
|
|
1577 (if id
|
|
1578 (setq w3-id-positions (cons
|
|
1579 (cons (intern id)
|
|
1580 (set-marker (make-marker)
|
|
1581 (point-max)))
|
|
1582 w3-id-positions)))
|
|
1583 (case tag
|
|
1584 (a ; Hyperlinks
|
|
1585 (let* (
|
|
1586 (title (w3-get-attribute 'title))
|
|
1587 (name (or (w3-get-attribute 'id)
|
|
1588 (w3-get-attribute 'name)))
|
|
1589 (btdt nil)
|
|
1590 class
|
|
1591 (before nil)
|
|
1592 (after nil)
|
|
1593 (face nil)
|
|
1594 (voice nil)
|
|
1595 (st nil))
|
|
1596 (setq st (point)
|
|
1597 hyperlink-info (list
|
|
1598 st
|
|
1599 (append
|
|
1600 (list 'link :args nil
|
|
1601 :value "" :tag ""
|
|
1602 :action 'w3-follow-hyperlink
|
|
1603 :from
|
|
1604 (set-marker (make-marker) st)
|
|
1605 :help-echo 'w3-widget-echo
|
|
1606 )
|
|
1607 (alist-to-plist args))))
|
|
1608 (w3-handle-content node)
|
|
1609 )
|
|
1610 )
|
82
|
1611 ((ol ul dl menu)
|
|
1612 (push 0 w3-display-list-stack)
|
|
1613 (w3-handle-content node))
|
|
1614 (dir
|
14
|
1615 (push 0 w3-display-list-stack)
|
82
|
1616 (setq node
|
|
1617 (list tag args
|
|
1618 (list
|
|
1619 (list 'table nil
|
|
1620 (w3-display-chop-into-table node 3)))))
|
|
1621 (w3-handle-content node))
|
|
1622 (multicol
|
|
1623 (setq node (list tag args
|
|
1624 (list
|
|
1625 (list 'table nil
|
|
1626 (w3-display-chop-into-table node 2)))))
|
14
|
1627 (w3-handle-content node))
|
|
1628 (img ; inlined image
|
|
1629 (w3-handle-image)
|
|
1630 (w3-handle-empty-tag))
|
|
1631 (script ; Scripts
|
|
1632 (w3-handle-empty-tag))
|
|
1633 ((embed object) ; Embedded images/content
|
|
1634 (w3-handle-content node)
|
|
1635 )
|
|
1636 (hr ; Cause line break & insert rule
|
|
1637 (let* ((perc (or (w3-get-attribute 'width)
|
|
1638 (w3-get-style-info 'width node)
|
|
1639 "100%"))
|
|
1640 (rule nil)
|
|
1641 (width nil))
|
|
1642 (setq perc (/ (min (string-to-int perc) 100) 100.0)
|
|
1643 width (* fill-column perc)
|
|
1644 rule (make-string (max (truncate width) 0)
|
|
1645 w3-horizontal-rule-char)
|
|
1646 node (list 'hr nil (list rule)))
|
|
1647 (w3-handle-content node)))
|
|
1648 (map ; Client side imagemaps
|
|
1649 (let ((name (or (w3-get-attribute 'name)
|
|
1650 (w3-get-attribute 'id)
|
|
1651 "unnamed"))
|
|
1652 (areas
|
|
1653 (mapcar
|
|
1654 (function
|
|
1655 (lambda (node)
|
|
1656 (let* ((args (nth 1 node))
|
|
1657 (type (downcase (or
|
|
1658 (w3-get-attribute 'shape)
|
|
1659 "rect")))
|
|
1660 (coords (w3-decode-area-coords
|
|
1661 (or (cdr-safe
|
|
1662 (assq 'coords args)) "")))
|
|
1663 (alt (w3-get-attribute 'alt))
|
|
1664 (href (if (assq 'nohref args)
|
|
1665 t
|
|
1666 (or (w3-get-attribute 'src)
|
|
1667 (w3-get-attribute 'href))))
|
|
1668 )
|
|
1669 (vector type coords href alt))
|
|
1670 )
|
|
1671 )
|
|
1672 (nth 2 node))))
|
|
1673 (setq w3-imagemaps (cons (cons name areas) w3-imagemaps)))
|
|
1674 (w3-handle-empty-tag)
|
|
1675 )
|
82
|
1676 (note
|
|
1677 ;; Ewwwwhhh. Looks gross, but it works. This converts a
|
|
1678 ;; <note> into a two-cell table, so that things look all
|
|
1679 ;; pretty.
|
|
1680 (setq node
|
|
1681 (list 'note nil
|
|
1682 (list
|
|
1683 (list 'table nil
|
|
1684 (list
|
|
1685 (list 'tr nil
|
|
1686 (list
|
|
1687 (list 'td (list 'align 'right)
|
|
1688 (list
|
|
1689 (concat
|
|
1690 (or (w3-get-attribute 'role)
|
|
1691 "CAUTION") ":")))
|
|
1692 (list 'td nil
|
|
1693 (nth 2 node)))))))))
|
|
1694 (w3-handle-content node)
|
|
1695 )
|
|
1696 (table
|
14
|
1697 (w3-display-table node)
|
|
1698 (setq w3-last-fill-pos (point))
|
|
1699 (w3-handle-empty-tag)
|
|
1700 )
|
|
1701 (isindex
|
|
1702 (let ((prompt (or (w3-get-attribute 'prompt)
|
|
1703 "Search on (+ separates keywords): "))
|
|
1704 action node)
|
|
1705 (setq action (or (w3-get-attribute 'src)
|
|
1706 (w3-get-attribute 'href)
|
|
1707 (url-view-url t)))
|
|
1708 (if (and prompt (string-match "[^: \t-]+$" prompt))
|
|
1709 (setq prompt (concat prompt ": ")))
|
|
1710 (setq node
|
|
1711 (list 'isindex nil
|
|
1712 (list
|
|
1713 (list 'hr nil nil)
|
|
1714 (list 'form
|
|
1715 (list (cons 'action action)
|
|
1716 (cons 'enctype
|
|
1717 "application/x-w3-isindex")
|
|
1718 (cons 'method "get"))
|
|
1719 (list
|
|
1720 prompt
|
|
1721 (list 'input
|
|
1722 (list (cons 'type "text")
|
|
1723 (cons 'name "isindex"))))))))
|
|
1724 (w3-handle-content node)
|
|
1725 (setq w3-current-isindex (cons action prompt)))
|
|
1726 )
|
|
1727 (*document
|
|
1728 (let ((info (mapcar (lambda (x) (cons x (symbol-value x)))
|
|
1729 w3-persistent-variables)))
|
82
|
1730 (if (not w3-display-same-buffer)
|
|
1731 (set-buffer (generate-new-buffer "Untitled")))
|
14
|
1732 (setq w3-current-form-number 0
|
|
1733 w3-display-open-element-stack nil
|
|
1734 w3-last-fill-pos (point-min)
|
|
1735 fill-column (min (- (or w3-strict-width (window-width))
|
|
1736 w3-right-margin)
|
|
1737 (or w3-maximum-line-length
|
|
1738 (window-width))))
|
|
1739 (switch-to-buffer (current-buffer))
|
|
1740 (buffer-disable-undo (current-buffer))
|
|
1741 (mapcar (function (lambda (x) (set (car x) (cdr x)))) info)
|
|
1742 ;; ACK! We don't like filladapt mode!
|
|
1743 (set (make-local-variable 'filladapt-mode) nil)
|
|
1744 (set (make-local-variable 'adaptive-fill-mode) nil)
|
82
|
1745 (set (make-local-variable 'voice-lock-mode) t)
|
14
|
1746 (setq w3-current-stylesheet (css-copy-stylesheet
|
|
1747 w3-user-stylesheet)
|
|
1748 w3-last-fill-pos (point)
|
|
1749 fill-column (min (- (or w3-strict-width (window-width))
|
|
1750 w3-right-margin)
|
|
1751 (or w3-maximum-line-length
|
|
1752 (window-width)))
|
|
1753 fill-prefix "")
|
|
1754 (set (make-local-variable 'inhibit-read-only) t))
|
|
1755 (w3-handle-content node)
|
|
1756 )
|
|
1757 (*invisible
|
|
1758 (w3-handle-empty-tag))
|
|
1759 (meta
|
|
1760 (let* ((equiv (cdr-safe (assq 'http-equiv args)))
|
|
1761 (value (w3-get-attribute 'content))
|
|
1762 (name (w3-get-attribute 'name))
|
|
1763 (node (and equiv (assoc (setq equiv (downcase equiv))
|
|
1764 url-current-mime-headers))))
|
|
1765 (if equiv
|
|
1766 (setq url-current-mime-headers (cons
|
|
1767 (cons equiv value)
|
|
1768 url-current-mime-headers)))
|
|
1769 (if name
|
|
1770 (setq w3-current-metainfo (cons
|
|
1771 (cons name value)
|
|
1772 w3-current-metainfo)))
|
|
1773
|
|
1774 ;; Special-case the Set-Cookie header
|
|
1775 (if (and equiv (string= (downcase equiv) "set-cookie"))
|
|
1776 (url-cookie-handle-set-cookie value))
|
|
1777 ;; Special-case the refresh header
|
|
1778 (if (and equiv (string= (downcase equiv) "refresh"))
|
|
1779 (url-handle-refresh-header value)))
|
|
1780 (w3-handle-empty-tag)
|
|
1781 )
|
|
1782 (link
|
|
1783 ;; This doesn't handle blank-separated values per the RFC.
|
|
1784 (w3-parse-link args)
|
|
1785 (w3-handle-empty-tag))
|
|
1786 (title
|
|
1787 (let ((potential-title "")
|
|
1788 (content (nth 2 node)))
|
|
1789 (while content
|
|
1790 (setq potential-title (concat potential-title (car content))
|
|
1791 content (cdr content)))
|
|
1792 (setq potential-title (w3-normalize-spaces potential-title))
|
82
|
1793 (if (or w3-display-same-buffer
|
|
1794 (string-match "^[ \t]*$" potential-title))
|
14
|
1795 nil
|
|
1796 (rename-buffer (generate-new-buffer-name
|
|
1797 (w3-fix-spaces potential-title)))))
|
|
1798 (w3-handle-empty-tag))
|
|
1799 (form
|
|
1800 (setq w3-current-form-number (1+ w3-current-form-number))
|
|
1801 (let* (
|
|
1802 (action (w3-get-attribute 'action))
|
|
1803 (url nil))
|
|
1804 (if (not action)
|
|
1805 (setq args (cons (cons 'action (url-view-url t)) args)))
|
82
|
1806 (setq w3-display-form-id (cons
|
|
1807 (cons 'form-number
|
|
1808 w3-current-form-number)
|
|
1809 args))
|
14
|
1810 (w3-handle-content node)))
|
82
|
1811 (keygen
|
|
1812 (w3-form-add-element 'keygen
|
|
1813 (or (w3-get-attribute 'name)
|
|
1814 (w3-get-attribute 'id)
|
|
1815 "keygen")
|
|
1816 nil ; value
|
|
1817 nil ; size
|
|
1818 nil ; maxlength
|
|
1819 nil ; default
|
|
1820 w3-display-form-id ; action
|
|
1821 nil ; options
|
|
1822 w3-current-form-number
|
|
1823 (w3-get-attribute 'id) ; id
|
|
1824 nil ; checked
|
|
1825 (car w3-active-faces)))
|
14
|
1826 (input
|
86
|
1827 (w3-form-add-element
|
|
1828 (w3-display-normalize-form-info args)
|
|
1829 (car w3-active-faces))
|
14
|
1830 (w3-handle-empty-tag)
|
|
1831 )
|
|
1832 (select
|
86
|
1833 (let* ((plist (w3-display-normalize-form-info args))
|
82
|
1834 (tmp nil)
|
|
1835 (multiple (assq 'multiple args))
|
86
|
1836 (value nil)
|
|
1837 (name (plist-get plist 'name))
|
|
1838 (options (mapcar
|
|
1839 (function
|
|
1840 (lambda (n)
|
|
1841 (setq tmp (w3-normalize-spaces
|
|
1842 (apply 'concat (nth 2 n)))
|
|
1843 tmp (cons tmp
|
|
1844 (or
|
|
1845 (cdr-safe
|
|
1846 (assq 'value (nth 1 n)))
|
|
1847 tmp)))
|
|
1848 (if (assq 'selected (nth 1 n))
|
|
1849 (setq value (car tmp)))
|
|
1850 tmp))
|
|
1851 (nth 2 node))))
|
82
|
1852 (if (not value)
|
|
1853 (setq value (caar options)))
|
86
|
1854 (setq plist (plist-put plist 'value value))
|
82
|
1855 (if multiple
|
|
1856 (progn
|
|
1857 (setq options
|
|
1858 (mapcar
|
|
1859 (function
|
|
1860 (lambda (opt)
|
|
1861 (list 'div nil
|
|
1862 (list
|
|
1863 (list 'input
|
|
1864 (list (cons 'name name)
|
|
1865 (cons 'type "checkbox")
|
|
1866 (cons 'value (car opt))))
|
|
1867 " " (car opt) (list 'br nil nil)))))
|
|
1868 options))
|
|
1869 (setq node (list 'p nil options))
|
|
1870 (w3-handle-content node))
|
86
|
1871 (setq plist (plist-put plist 'type 'option)
|
|
1872 plist (plist-put plist 'options options))
|
|
1873 (w3-form-add-element plist (car w3-active-faces))
|
14
|
1874 ;; This should really not be necessary, but some versions
|
|
1875 ;; of the widget library leave point _BEFORE_ the menu
|
|
1876 ;; widget instead of after.
|
|
1877 (goto-char (point-max))
|
82
|
1878 (w3-handle-empty-tag))))
|
14
|
1879 (textarea
|
86
|
1880 (let* ((plist (w3-display-normalize-form-info args))
|
82
|
1881 (value (w3-normalize-spaces
|
86
|
1882 (apply 'concat (nth 2 node)))))
|
|
1883 (setq plist (plist-put plist 'type 'multiline)
|
|
1884 plist (plist-put plist 'value value))
|
|
1885 (w3-form-add-element plist (car w3-active-faces)))
|
14
|
1886 (w3-handle-empty-tag)
|
|
1887 )
|
|
1888 (style
|
82
|
1889 (w3-handle-style (alist-to-plist
|
|
1890 (cons (cons 'data (apply 'concat (nth 2 node)))
|
|
1891 (nth 1 node))))
|
14
|
1892 (w3-handle-empty-tag))
|
88
|
1893 ;; Emacs-W3 stuff that cannot be expressed in a stylesheet
|
|
1894 (pinhead
|
|
1895 ;; This check is so that we don't screw up table auto-layout
|
|
1896 ;; by changing our text midway through the parse/layout/display
|
|
1897 ;; steps.
|
|
1898 (if (nth 2 node)
|
|
1899 nil
|
|
1900 (setcar (cddr node)
|
|
1901 (list
|
|
1902 (if (fboundp 'yow)
|
|
1903 (yow)
|
|
1904 "AIEEEEE! I am having an UNDULATING EXPERIENCE!"))))
|
|
1905 (w3-handle-content node))
|
|
1906 (flame
|
|
1907 (if (nth 2 node)
|
|
1908 nil
|
|
1909 (setcar
|
|
1910 (cddr node)
|
|
1911 (list
|
|
1912 (condition-case ()
|
|
1913 (concat
|
|
1914 (sentence-ify
|
|
1915 (string-ify
|
|
1916 (append-suffixes-hack (flatten (*flame))))))
|
|
1917 (error
|
|
1918 "You know, everything is really a graphics editor.")))))
|
|
1919 (w3-handle-content node))
|
|
1920 (cookie
|
|
1921 (if (nth 2 node)
|
|
1922 nil
|
|
1923 (setcar
|
|
1924 (cddr node)
|
|
1925 (list
|
|
1926 (w3-display-get-cookie args))))
|
|
1927 (w3-handle-content node))
|
|
1928 ;; Generic formatting - all things that can be fully specified
|
|
1929 ;; by a CSS stylesheet.
|
14
|
1930 (otherwise
|
|
1931 (w3-handle-content node))
|
|
1932 ) ; case tag
|
|
1933 ) ; stringp content
|
|
1934 ) ; while content
|
|
1935 ) ; while content-stack
|
|
1936 )
|
|
1937 )
|
|
1938
|
|
1939 (defun w3-draw-tree (tree)
|
|
1940 ;; The main entry point - wow complicated
|
|
1941 (setq w3-current-stylesheet w3-user-stylesheet)
|
|
1942 (while tree
|
|
1943 (w3-display-node (car tree))
|
|
1944 (setq tree (cdr tree)))
|
|
1945 (w3-display-fix-widgets)
|
|
1946 (w3-form-resurrect-widgets))
|
|
1947
|
|
1948 (defun time-display (&optional tree)
|
|
1949 ;; Return the # of seconds it took to draw 'tree'
|
|
1950 (let ((st (nth 1 (current-time)))
|
|
1951 (nd nil))
|
|
1952 (w3-draw-tree (or tree w3-last-parse-tree))
|
|
1953 (setq nd (nth 1 (current-time)))
|
|
1954 (- nd st)))
|
|
1955
|
|
1956
|
82
|
1957 (defsubst w3-finish-drawing ()
|
|
1958 (if (and (boundp 'w3-image-widgets-waiting) w3-image-widgets-waiting)
|
|
1959 (let (url glyph widget)
|
|
1960 (while w3-image-widgets-waiting
|
|
1961 (setq widget (car w3-image-widgets-waiting)
|
|
1962 w3-image-widgets-waiting (cdr w3-image-widgets-waiting)
|
|
1963 url (widget-get widget 'src)
|
|
1964 glyph (cdr-safe (assoc url w3-graphics-list)))
|
|
1965 (widget-value-set widget glyph)))
|
|
1966 ;;(w3-handle-annotations)
|
|
1967 ;;(w3-handle-headers)
|
|
1968 )
|
|
1969 )
|
|
1970
|
|
1971 (defun w3-region (st nd)
|
|
1972 (if (not w3-setup-done) (w3-do-setup))
|
|
1973 (let* ((source (buffer-substring st nd))
|
|
1974 (w3-display-same-buffer t)
|
|
1975 (parse nil))
|
|
1976 (save-excursion
|
|
1977 (set-buffer (get-buffer-create " *w3-region*"))
|
|
1978 (erase-buffer)
|
|
1979 (insert source)
|
|
1980 (setq parse (w3-parse-buffer (current-buffer))))
|
|
1981 (narrow-to-region st nd)
|
|
1982 (delete-region (point-min) (point-max))
|
|
1983 (w3-draw-tree parse)
|
|
1984 (w3-finish-drawing)))
|
|
1985
|
|
1986 (defun w3-refresh-buffer ()
|
|
1987 (interactive)
|
|
1988 (let ((parse w3-current-parse)
|
|
1989 (inhibit-read-only t)
|
|
1990 (w3-display-same-buffer t))
|
|
1991 (if (not parse)
|
|
1992 (error "Could not find the parse tree for this buffer. EEEEK!"))
|
|
1993 (erase-buffer)
|
|
1994 (w3-draw-tree parse)
|
|
1995 (w3-finish-drawing)
|
|
1996 (w3-mode)
|
|
1997 (set-buffer-modified-p nil)))
|
|
1998
|
14
|
1999 (defun w3-prepare-buffer (&rest args)
|
|
2000 ;; The text/html viewer - does all the drawing and displaying of the buffer
|
|
2001 ;; that is necessary to go from raw HTML to a good presentation.
|
|
2002 (let* ((source (buffer-string))
|
|
2003 (source-buf (current-buffer))
|
|
2004 (parse (w3-parse-buffer source-buf)))
|
|
2005 (set-buffer-modified-p nil)
|
|
2006 (w3-draw-tree parse)
|
|
2007 (kill-buffer source-buf)
|
|
2008 (set-buffer-modified-p nil)
|
|
2009 (setq w3-current-source source
|
|
2010 w3-current-parse parse)
|
82
|
2011 (w3-finish-drawing)
|
14
|
2012 (w3-mode)
|
|
2013 (set-buffer-modified-p nil)
|
|
2014 (goto-char (point-min))
|
|
2015 (if url-keep-history
|
|
2016 (let ((url (url-view-url t)))
|
|
2017 (if (not url-history-list)
|
|
2018 (setq url-history-list (make-hash-table :size 131 :test 'equal)))
|
|
2019 (cl-puthash url (buffer-name) url-history-list)
|
|
2020 (if (fboundp 'w3-shuffle-history-menu)
|
|
2021 (w3-shuffle-history-menu)))))
|
|
2022 )
|
|
2023
|
|
2024 (provide 'w3-display)
|