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