comparison lisp/w3/w3-display.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents 4103f0995bd7
children ec9a17fef872
comparison
equal deleted inserted replaced
25:383a494979f8 26:441bb1e64a06
1 ;;; w3-display.el --- display engine v99999 1 ;;; w3-display.el --- display engine v99999
2 ;; Author: wmperry 2 ;; Author: wmperry
3 ;; Created: 1997/02/15 23:38:28 3 ;; Created: 1997/02/20 21:48:44
4 ;; Version: 1.128 4 ;; Version: 1.135
5 ;; Keywords: faces, help, hypermedia 5 ;; Keywords: faces, help, hypermedia
6 6
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu) 8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu)
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc. 9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
365 (skip-chars-forward " \t\r\n") 365 (skip-chars-forward " \t\r\n")
366 (point))))) 366 (point)))))
367 (goto-char (point-max)) 367 (goto-char (point-max))
368 (add-text-properties w3-scratch-start-point 368 (add-text-properties w3-scratch-start-point
369 (point) (list 'face w3-active-faces 369 (point) (list 'face w3-active-faces
370 'html-stack w3-display-open-element-stack
370 'start-open t 371 'start-open t
371 'end-open t 372 'end-open t
372 'rear-nonsticky t 373 'rear-nonsticky t
373 'duplicable t)) 374 'duplicable t))
374 (if (car w3-active-voices) 375 (if (car w3-active-voices)
412 (stringp (symbol-value (car check))) 413 (stringp (symbol-value (car check)))
413 (throw 'exit (symbol-value (car check)))) 414 (throw 'exit (symbol-value (car check))))
414 (pop check))))) 415 (pop check)))))
415 416
416 (defun w3-follow-hyperlink (widget &rest ignore) 417 (defun w3-follow-hyperlink (widget &rest ignore)
417 (let* ((target (widget-get widget 'target)) 418 (let* ((target (or (widget-get widget 'target)
419 w3-base-target))
418 (href (widget-get widget 'href))) 420 (href (widget-get widget 'href)))
419 (if target (setq target (intern (downcase target)))) 421 (if target (setq target (intern (downcase target))))
420 (case target 422 (case target
421 ((_blank external) 423 ((_blank external)
422 (w3-fetch-other-frame href)) 424 (w3-fetch-other-frame href))
423 (_top 425 (_top
424 (delete-other-windows) 426 (delete-other-windows)
425 (w3-fetch href)) 427 (w3-fetch href))
426 (otherwise 428 (otherwise
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))))
427 (w3-fetch href))))) 434 (w3-fetch href)))))
428 435
429 (defun w3-balloon-help-callback (object &optional event) 436 (defun w3-balloon-help-callback (object &optional event)
430 (let* ((widget (widget-at (extent-start-position object))) 437 (let* ((widget (widget-at (extent-start-position object)))
431 (href (and widget (widget-get widget 'href)))) 438 (href (and widget (widget-get widget 'href))))
1495 (let ( 1502 (let (
1496 (content-stack (list (list node))) 1503 (content-stack (list (list node)))
1497 (right-margin-stack (list fill-column)) 1504 (right-margin-stack (list fill-column))
1498 (left-margin-stack (list 0)) 1505 (left-margin-stack (list 0))
1499 (inhibit-read-only t) 1506 (inhibit-read-only t)
1507 (widget-push-button-gui nil)
1500 node 1508 node
1501 insert-before 1509 insert-before
1502 insert-after 1510 insert-after
1503 tag 1511 tag
1504 args 1512 args
1646 (img ; inlined image 1654 (img ; inlined image
1647 (w3-handle-image) 1655 (w3-handle-image)
1648 (w3-handle-empty-tag)) 1656 (w3-handle-empty-tag))
1649 (frameset 1657 (frameset
1650 (if w3-display-frames 1658 (if w3-display-frames
1651 (w3-handle-content node) 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))
1652 (w3-handle-empty-tag))) 1668 (w3-handle-empty-tag)))
1653 (frame 1669 (frame
1654 (let* ((href (or (w3-get-attribute 'src) 1670 (if w3-display-frames
1655 (w3-get-attribute 'href))) 1671 (let* ((href (or (w3-get-attribute 'src)
1656 (name (or (w3-get-attribute 'name) 1672 (w3-get-attribute 'href)))
1657 (w3-get-attribute 'title) 1673 (name (or (w3-get-attribute 'name)
1658 (w3-get-attribute 'alt) 1674 (w3-get-attribute 'title)
1659 "Unknown frame name"))) 1675 (w3-get-attribute 'alt)
1660 (w3-handle-content 1676 "Unknown frame name")))
1661 (list tag args 1677 (push 'frame w3-frameset-structure)
1662 (list 1678 (w3-handle-content
1663 (list 'p nil 1679 (list tag args
1664 (list 1680 (list
1665 (list 'a 1681 (list 'p nil
1666 (cons (cons 'href href) 1682 (list
1667 args) 1683 (list 'a
1668 (list 1684 (cons (cons 'href href)
1669 "Fetch frame: " 1685 args)
1670 name))))))))) 1686 (list
1687 (car w3-frame-labels)
1688 name
1689 (cdr w3-frame-labels)))))))))))
1671 (noframes 1690 (noframes
1672 (if w3-display-frames 1691 (if w3-display-frames
1673 (w3-handle-empty-tag) 1692 (w3-handle-empty-tag)
1674 (w3-handle-content node))) 1693 (w3-handle-content node)))
1675 (script ; Scripts 1694 (script ; Scripts
1773 w3-persistent-variables))) 1792 w3-persistent-variables)))
1774 (if (not w3-display-same-buffer) 1793 (if (not w3-display-same-buffer)
1775 (set-buffer (generate-new-buffer "Untitled"))) 1794 (set-buffer (generate-new-buffer "Untitled")))
1776 (setq w3-current-form-number 0 1795 (setq w3-current-form-number 0
1777 w3-display-open-element-stack nil 1796 w3-display-open-element-stack nil
1778 w3-last-fill-pos (point-min) 1797 w3-last-fill-pos (point-min))
1779 fill-column (min (- (or w3-strict-width (window-width)) 1798 (setcar right-margin-stack
1780 w3-right-margin) 1799 (min (- (or w3-strict-width (window-width))
1781 (or w3-maximum-line-length 1800 w3-right-margin)
1782 (window-width)))) 1801 (or w3-maximum-line-length
1802 (window-width))))
1783 (switch-to-buffer (current-buffer)) 1803 (switch-to-buffer (current-buffer))
1784 (buffer-disable-undo (current-buffer)) 1804 (buffer-disable-undo (current-buffer))
1785 (mapcar (function (lambda (x) (set (car x) (cdr x)))) info) 1805 (mapcar (function (lambda (x) (set (car x) (cdr x)))) info)
1786 ;; ACK! We don't like filladapt mode! 1806 ;; ACK! We don't like filladapt mode!
1787 (set (make-local-variable 'filladapt-mode) nil) 1807 (set (make-local-variable 'filladapt-mode) nil)
1788 (set (make-local-variable 'adaptive-fill-mode) nil) 1808 (set (make-local-variable 'adaptive-fill-mode) nil)
1789 (set (make-local-variable 'voice-lock-mode) t) 1809 (set (make-local-variable 'voice-lock-mode) t)
1790 (setq w3-current-stylesheet (css-copy-stylesheet 1810 (setq w3-current-stylesheet (css-copy-stylesheet
1791 w3-user-stylesheet) 1811 w3-user-stylesheet)
1792 w3-last-fill-pos (point) 1812 w3-last-fill-pos (point)
1793 fill-column (min (- (or w3-strict-width (window-width))
1794 w3-right-margin)
1795 (or w3-maximum-line-length
1796 (window-width)))
1797 fill-prefix "") 1813 fill-prefix "")
1798 (set (make-local-variable 'inhibit-read-only) t)) 1814 (set (make-local-variable 'inhibit-read-only) t))
1799 (w3-handle-content node) 1815 (w3-handle-content node)
1800 ) 1816 )
1801 (*invisible 1817 (*invisible
1838 (string-match "^[ \t]*$" potential-title)) 1854 (string-match "^[ \t]*$" potential-title))
1839 nil 1855 nil
1840 (rename-buffer (generate-new-buffer-name 1856 (rename-buffer (generate-new-buffer-name
1841 (w3-fix-spaces potential-title))))) 1857 (w3-fix-spaces potential-title)))))
1842 (w3-handle-empty-tag)) 1858 (w3-handle-empty-tag))
1859 (base
1860 (setq w3-base-target (cdr-safe (assq 'target args)))
1861 (w3-handle-content node))
1843 (form 1862 (form
1844 (setq w3-current-form-number (1+ w3-current-form-number)) 1863 (setq w3-current-form-number (1+ w3-current-form-number))
1845 (let* ( 1864 (let* (
1846 (action (w3-get-attribute 'action)) 1865 (action (w3-get-attribute 'action))
1847 (url nil)) 1866 (url nil))
2014 url (widget-get widget 'src) 2033 url (widget-get widget 'src)
2015 glyph (cdr-safe (assoc url w3-graphics-list))) 2034 glyph (cdr-safe (assoc url w3-graphics-list)))
2016 (condition-case nil 2035 (condition-case nil
2017 (widget-value-set widget glyph) 2036 (widget-value-set widget glyph)
2018 (error nil)))) 2037 (error nil))))
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)))
2019 (and (not w3-running-xemacs) 2043 (and (not w3-running-xemacs)
2020 (not (eq (device-type) 'tty)) 2044 (not (eq (device-type) 'tty))
2021 (w3-fixup-eol-faces)) 2045 (w3-fixup-eol-faces))
2046 (message "Drawing... done")
2022 ;;(w3-handle-headers) 2047 ;;(w3-handle-headers)
2023 ) 2048 )
2024 2049
2025 (defun w3-region (st nd) 2050 (defun w3-region (st nd)
2026 (if (not w3-setup-done) (w3-do-setup)) 2051 (if (not w3-setup-done) (w3-do-setup))
2065 (setq w3-current-source source 2090 (setq w3-current-source source
2066 w3-current-parse parse) 2091 w3-current-parse parse)
2067 (w3-finish-drawing) 2092 (w3-finish-drawing)
2068 (w3-mode) 2093 (w3-mode)
2069 (set-buffer-modified-p nil) 2094 (set-buffer-modified-p nil)
2070 (goto-char (point-min))
2071 (if url-keep-history 2095 (if url-keep-history
2072 (let ((url (url-view-url t))) 2096 (let ((url (url-view-url t)))
2073 (if (not url-history-list) 2097 (if (not url-history-list)
2074 (setq url-history-list (make-hash-table :size 131 :test 'equal))) 2098 (setq url-history-list (make-hash-table :size 131 :test 'equal)))
2075 (cl-puthash url (buffer-name) url-history-list) 2099 (cl-puthash url (buffer-name) url-history-list)
2076 (if (fboundp 'w3-shuffle-history-menu) 2100 (if (fboundp 'w3-shuffle-history-menu)
2077 (w3-shuffle-history-menu))))) 2101 (w3-shuffle-history-menu)))))
2078 ) 2102 )
2079 2103
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
2080 (provide 'w3-display) 2232 (provide 'w3-display)