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