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