1 ;;; semi-def.el --- definition module for SEMI
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: definition, MIME, multimedia, mail, news
8 ;; This file is part of SEMI (Sample of Emacs MIME Implementation).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'static))
31 (defconst mime-user-interface-product ["EMY" (1 13 9) "Art is long, life is short"]
32 "Product name, version number and code name of MIME-kernel package.")
34 (autoload 'mule-caesar-region "mule-caesar"
35 "Caesar rotation of current region." t)
37 (autoload 'widget-convert-button "wid-edit")
43 (defconst mime-echo-buffer-name "*MIME-echo*"
44 "Name of buffer to display MIME-playing information.")
46 (defconst mime-temp-buffer-name " *MIME-temp*")
52 ;; #### This definition should be removed. Instead, defface should be
54 (defcustom mime-button-face 'bold
55 "Face used for content-button or URL-button of MIME-Preview buffer.
56 Variable `widget-button-face' is equivalent for it if widget is used."
60 (defcustom mime-button-mouse-face 'highlight
61 "Face used for MIME-preview buffer mouse highlighting.
62 Variable `widget-mouse-face' is equivalent for it if widget is used."
66 (defcustom mime-use-widget nil
67 "If t, use widget to display buttons."
71 (defun mime-create-widget-button (string function)
72 "Display STRING as a widget button with the callback FUNCTION.
73 Under XEmacs, the function `mime-create-xpm-button' might be identical
74 to the function `mime-create-widget-button' if the feature `xpm' is not
75 provided or the TTY frame is used."
76 (let ((start (point)))
79 :action `(lambda (widget &optional event) (,function))
80 :mouse-down-action `(lambda (widget event)
82 (save-window-excursion
83 (mouse-set-point event)
84 (setq buf (current-buffer)
91 ;; There may be only one string "*" behind the widget button. We
92 ;; should replace it with the string as it can be seen because it
93 ;; will be yanked into the reply messages.
94 (static-when (featurep 'xemacs)
97 (insert "[" string "]")
98 (while (setq extent (extent-at start nil nil extent))
99 ;; Avoid removing extents of next part.
100 (if (eq (extent-end-position extent) end)
101 (set-extent-endpoints extent end (point))))
102 (delete-region start end)))
103 (add-text-properties start (point)
108 (static-when (featurep 'xemacs)
109 (defcustom mime-xpm-button-shadow-thickness 3
110 "A number of pixels should be used for the shadows on the edges of
115 (defcustom mime-xpm-button-foreground "Yellow"
116 "A color used to display the text."
120 (defcustom mime-xpm-button-background "#a0a0d0"
121 "A background color the text will be displayed upon."
125 (defvar mime-xpm-button-glyph-cache nil)
128 (defun mime-create-xpm-button (string function)
129 "Display STRING as a XPM button with the callback FUNCTION.
130 It might be identical to the function `mime-create-widget-button'
131 if the TTY frame is used."
132 ;; `device-on-widow-system-p' must be checked at run-time.
133 (if (device-on-window-system-p)
135 (let ((old-point (point)))
136 (set-extent-properties (make-extent (point)
138 (insert "[" string "]")
140 '(invisible t intangible t
142 (add-text-properties old-point (point)
143 '(mime-button t start-open t)))
144 (let* ((spec (list string
145 mime-xpm-button-shadow-thickness
146 mime-xpm-button-foreground
147 mime-xpm-button-background))
148 (button (cdr (assoc spec mime-xpm-button-glyph-cache))))
150 (set-alist 'mime-xpm-button-glyph-cache spec
151 (setq button (apply (function xpm-button-create)
153 (let* ((extent (make-extent (point) (point)))
154 (down-glyph (make-glyph (car (cdr button))))
155 (up-glyph (make-glyph (car button)))
156 (down-func `(lambda (event)
158 (set-extent-begin-glyph ,extent
160 (up-func `(lambda (event)
162 (mouse-set-point event)
163 (set-extent-begin-glyph ,extent ,up-glyph)
165 (keymap (make-sparse-keymap)))
166 (define-key keymap 'button1 down-func)
167 (define-key keymap 'button2 down-func)
168 (define-key keymap 'button1up up-func)
169 (define-key keymap 'button2up up-func)
170 (set-extent-begin-glyph extent up-glyph)
171 (set-extent-property extent 'keymap keymap))
173 (mime-create-widget-button string function)))
174 (fset 'mime-create-xpm-button 'mime-create-widget-button)))
176 (defcustom mime-create-button-function 'mime-create-widget-button
177 "A function called to create the content button."
188 '((const :tag "Widget button" mime-create-widget-button))
189 (static-when (featurep 'xemacs)
190 '((const :tag "Xpm button" mime-create-xpm-button)))
191 '((function :tag "Other"))))))))
193 (defsubst mime-add-button (from to function &optional data)
194 "Create a button between FROM and TO with callback FUNCTION and DATA."
195 (and mime-button-face
196 (put-text-property from to 'face mime-button-face))
197 (and mime-button-mouse-face
198 (put-text-property from to 'mouse-face mime-button-mouse-face))
199 (add-text-properties from to (list 'mime-button-callback function
203 (add-text-properties from to (list 'mime-button-data data))))
205 (defsubst mime-insert-button (string function &optional data)
206 "Insert STRING as button with callback FUNCTION and DATA."
210 (narrow-to-region (point) (point))
214 (funcall mime-create-button-function line function)))
215 (split-string string "\n"))
217 ;; One more newline to avoid concatenation of face property.
218 (insert (concat "[" string "]\n\n"))
219 (mime-add-button (point-min) (1- (point-max)) function data)
222 (defvar mime-button-mother-dispatcher nil)
224 (defun mime-button-dispatcher (event)
225 "Select the button under point."
227 (let (buf point func data)
228 (save-window-excursion
229 (mouse-set-point event)
230 (setq buf (current-buffer)
232 func (get-text-property (point) 'mime-button-callback)
233 data (get-text-property (point) 'mime-button-data)))
239 (if (fboundp mime-button-mother-dispatcher)
240 (funcall mime-button-mother-dispatcher event))))))
246 (defcustom mime-browse-url-regexp
247 (concat "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):"
248 "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
249 "[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
250 "*Regexp to match URL in text body."
254 (defcustom mime-browse-url-function (function browse-url)
255 "*Function to browse URL."
259 (defsubst mime-add-url-buttons ()
260 "Add URL-buttons for text body."
261 (goto-char (point-min))
262 (while (re-search-forward mime-browse-url-regexp nil t)
263 (let ((beg (match-beginning 0))
267 (widget-convert-button 'mime-url-link beg end
268 (buffer-substring beg end))
269 (static-unless (featurep 'xemacs)
270 (overlay-put (make-overlay beg end) 'local-map widget-keymap)))
271 (mime-add-button beg end mime-browse-url-function
272 (list (buffer-substring beg end)))))))
274 (define-widget 'mime-url-link 'link
275 "A link to an www page."
276 :help-echo 'widget-url-link-help-echo
277 :action 'widget-mime-url-link-action)
279 (defun widget-mime-url-link-action (widget &optional event)
280 "Open the url specified by WIDGET."
281 (funcall mime-browse-url-function (widget-value widget)))
287 (static-if (featurep 'xemacs)
288 (defun select-menu-alist (title menu-alist)
289 ;; XEmacs can have both X and tty frames at the same time with
291 (if (device-on-window-system-p)
294 ;; list* is CL function, but CL is a part of XEmacs.
301 (setq ret ',(cdr cell))
308 (assoc (completing-read (concat title " : ") menu-alist)
311 (defun select-menu-alist (title menu-alist)
313 (list '(1 1) (selected-window))
314 (list title (cons title menu-alist))))
315 (defun select-menu-alist (title menu-alist)
317 (assoc (completing-read (concat title " : ") menu-alist)
324 (defvar mime-condition-type-alist
325 '((preview . mime-preview-condition)
326 (action . mime-acting-condition)))
328 (defvar mime-condition-mode-alist
329 '((with-default . ctree-set-calist-with-default)
330 (t . ctree-set-calist-strictly)))
332 (defun mime-add-condition (target-type condition &optional mode file)
333 "Add CONDITION to database specified by TARGET-TYPE.
334 TARGET-TYPE must be 'preview or 'action.
335 If optional argument MODE is 'strict or nil (omitted), CONDITION is
337 If optional argument MODE is 'with-default, CONDITION is added with
339 If optional argument FILE is specified, it is loaded when CONDITION is
341 (let ((sym (cdr (assq target-type mime-condition-type-alist))))
343 (let ((func (cdr (or (assq mode mime-condition-mode-alist)
344 (assq t mime-condition-mode-alist)))))
347 (funcall func sym condition)
349 (let ((method (cdr (assq 'method condition))))
350 (autoload method file))))
351 (error "Function for mode `%s' is not found." mode)))
352 (error "Variable for target-type `%s' is not found." target-type))))
360 ;;; semi-def.el ends here