comparison lisp/wid-edit.el @ 25686:c1a7a52bbfea

Remove some compatibility code and checks. (widget-specify-field, widget-specify-button): Don't use XEmacs properties. (widget-overlay-inactive): Change error message. (widget-button-pressed-face): New variable. (widget-button-click): Use it. (widget-documentation-link-add): Specify mouse and button faces. (widget-echo-help-mouse, widget-stop-mouse-tracking): Functions removed now the functionality is built in.
author Dave Love <fx@gnu.org>
date Mon, 13 Sep 1999 13:54:33 +0000
parents ba243531aa37
children c147359a515b
comparison
equal deleted inserted replaced
25685:fc2bfab28ed7 25686:c1a7a52bbfea
1 ;;; wid-edit.el --- Functions for creating and using widgets. 1 ;;; wid-edit.el --- Functions for creating and using widgets.
2 ;; 2 ;;
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> 5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Maintainer: FSF
6 ;; Keywords: extensions 7 ;; Keywords: extensions
7 ;; Version: 1.9951 8 ;; Version: 1.9951
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ 9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ (probably obsolete)
9 10
10 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
11 12
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by 14 ;; it under the terms of the GNU General Public License as published by
43 44
44 (eval-and-compile 45 (eval-and-compile
45 (autoload 'pp-to-string "pp") 46 (autoload 'pp-to-string "pp")
46 (autoload 'Info-goto-node "info") 47 (autoload 'Info-goto-node "info")
47 (autoload 'finder-commentary "finder" nil t) 48 (autoload 'finder-commentary "finder" nil t)
48
49 (unless (and (featurep 'custom) (fboundp 'custom-declare-variable))
50 ;; We have the old custom-library, hack around it!
51 (defmacro defgroup (&rest args) nil)
52 (defmacro defcustom (var value doc &rest args)
53 (` (defvar (, var) (, value) (, doc))))
54 (defmacro defface (&rest args) nil)
55 (define-widget-keywords :prefix :tag :load :link :options :type :group)
56 (when (fboundp 'copy-face)
57 (copy-face 'default 'widget-documentation-face)
58 (copy-face 'bold 'widget-button-face)
59 (copy-face 'italic 'widget-field-face)))
60 49
61 (unless (fboundp 'button-release-event-p) 50 (unless (fboundp 'button-release-event-p)
62 ;; XEmacs function missing from Emacs. 51 ;; XEmacs function missing from Emacs.
63 (defun button-release-event-p (event) 52 (defun button-release-event-p (event)
64 "Non-nil if EVENT is a mouse-button-release event object." 53 "Non-nil if EVENT is a mouse-button-release event object."
87 "Faces used by the widget library." 76 "Faces used by the widget library."
88 :group 'widgets 77 :group 'widgets
89 :group 'faces) 78 :group 'faces)
90 79
91 (defvar widget-documentation-face 'widget-documentation-face 80 (defvar widget-documentation-face 'widget-documentation-face
92 "Face used for documentation strings in widges. 81 "Face used for documentation strings in widgets.
93 This exists as a variable so it can be set locally in certain buffers.") 82 This exists as a variable so it can be set locally in certain buffers.")
94 83
95 (defface widget-documentation-face '((((class color) 84 (defface widget-documentation-face '((((class color)
96 (background dark)) 85 (background dark))
97 (:foreground "lime green")) 86 (:foreground "lime green"))
102 "Face used for documentation text." 91 "Face used for documentation text."
103 :group 'widget-documentation 92 :group 'widget-documentation
104 :group 'widget-faces) 93 :group 'widget-faces)
105 94
106 (defvar widget-button-face 'widget-button-face 95 (defvar widget-button-face 'widget-button-face
107 "Face used for buttons in widges. 96 "Face used for buttons in widgets.
108 This exists as a variable so it can be set locally in certain buffers.") 97 This exists as a variable so it can be set locally in certain buffers.")
109 98
110 (defface widget-button-face '((t (:bold t))) 99 (defface widget-button-face '((t (:bold t)))
111 "Face used for widget buttons." 100 "Face used for widget buttons."
112 :group 'widget-faces) 101 :group 'widget-faces)
338 nil (or (not widget-field-add-space) 327 nil (or (not widget-field-add-space)
339 (widget-get widget :size))))) 328 (widget-get widget :size)))))
340 (unless (or (stringp help-echo) (null help-echo)) 329 (unless (or (stringp help-echo) (null help-echo))
341 (setq help-echo 'widget-mouse-help)) 330 (setq help-echo 'widget-mouse-help))
342 (widget-put widget :field-overlay overlay) 331 (widget-put widget :field-overlay overlay)
343 (overlay-put overlay 'detachable nil) 332 ;;(overlay-put overlay 'detachable nil)
344 (overlay-put overlay 'field widget) 333 (overlay-put overlay 'field widget)
345 (overlay-put overlay 'local-map map) 334 (overlay-put overlay 'local-map map)
346 (overlay-put overlay 'keymap map) 335 ;;(overlay-put overlay 'keymap map)
347 (overlay-put overlay 'face face) 336 (overlay-put overlay 'face face)
348 (overlay-put overlay 'balloon-help help-echo) 337 ;;(overlay-put overlay 'balloon-help help-echo)
349 (overlay-put overlay 'help-echo help-echo)) 338 (overlay-put overlay 'help-echo help-echo))
350 (widget-specify-secret widget)) 339 (widget-specify-secret widget))
351 340
352 (defun widget-specify-secret (field) 341 (defun widget-specify-secret (field)
353 "Replace text in FIELD with value of `:secret', if non-nil." 342 "Replace text in FIELD with value of `:secret', if non-nil."
375 (widget-put widget :button-overlay overlay) 364 (widget-put widget :button-overlay overlay)
376 (unless (or (null help-echo) (stringp help-echo)) 365 (unless (or (null help-echo) (stringp help-echo))
377 (setq help-echo 'widget-mouse-help)) 366 (setq help-echo 'widget-mouse-help))
378 (overlay-put overlay 'button widget) 367 (overlay-put overlay 'button widget)
379 (overlay-put overlay 'mouse-face widget-mouse-face) 368 (overlay-put overlay 'mouse-face widget-mouse-face)
380 (overlay-put overlay 'balloon-help help-echo) 369 ;;(overlay-put overlay 'balloon-help help-echo)
381 (overlay-put overlay 'help-echo help-echo) 370 (overlay-put overlay 'help-echo help-echo)
382 (overlay-put overlay 'face face))) 371 (overlay-put overlay 'face face)))
383 372
384 (defun widget-mouse-help (extent) 373 (defun widget-mouse-help (extent)
385 "Find mouse help string for button in extent." 374 "Find mouse help string for button in extent."
442 (overlay-put overlay 'face 'widget-inactive-face) 431 (overlay-put overlay 'face 'widget-inactive-face)
443 ;; This is disabled, as it makes the mouse cursor change shape. 432 ;; This is disabled, as it makes the mouse cursor change shape.
444 ;; (overlay-put overlay 'mouse-face 'widget-inactive-face) 433 ;; (overlay-put overlay 'mouse-face 'widget-inactive-face)
445 (overlay-put overlay 'evaporate t) 434 (overlay-put overlay 'evaporate t)
446 (overlay-put overlay 'priority 100) 435 (overlay-put overlay 'priority 100)
447 (overlay-put overlay (if (string-match "XEmacs" emacs-version) 436 (overlay-put overlay 'modification-hooks '(widget-overlay-inactive))
448 'read-only
449 'modification-hooks) '(widget-overlay-inactive))
450 (widget-put widget :inactive overlay)))) 437 (widget-put widget :inactive overlay))))
451 438
452 (defun widget-overlay-inactive (&rest junk) 439 (defun widget-overlay-inactive (&rest junk)
453 "Ignoring the arguments, signal an error." 440 "Ignoring the arguments, signal an error."
454 (unless inhibit-read-only 441 (unless inhibit-read-only
455 (error "Attempt to modify inactive widget"))) 442 (error "The widget here is not active")))
456 443
457 444
458 (defun widget-specify-active (widget) 445 (defun widget-specify-active (widget)
459 "Make WIDGET active for user modifications." 446 "Make WIDGET active for user modifications."
460 (let ((inactive (widget-get widget :inactive))) 447 (let ((inactive (widget-get widget :inactive)))
500 "Extract the default value of WIDGET." 487 "Extract the default value of WIDGET."
501 (or (widget-get widget :value) 488 (or (widget-get widget :value)
502 (widget-apply widget :default-get))) 489 (widget-apply widget :default-get)))
503 490
504 (defun widget-match-inline (widget vals) 491 (defun widget-match-inline (widget vals)
505 ;; In WIDGET, match the start of VALS. 492 "In WIDGET, match the start of VALS."
506 (cond ((widget-get widget :inline) 493 (cond ((widget-get widget :inline)
507 (widget-apply widget :match-inline vals)) 494 (widget-apply widget :match-inline vals))
508 ((and vals 495 ((and vals
509 (widget-apply widget :match (car vals))) 496 (widget-apply widget :match (car vals)))
510 (cons (list (car vals)) (cdr vals))) 497 (cons (list (car vals)) (cdr vals)))
884 (defvar widget-field-keymap nil 871 (defvar widget-field-keymap nil
885 "Keymap used inside an editable field.") 872 "Keymap used inside an editable field.")
886 873
887 (unless widget-field-keymap 874 (unless widget-field-keymap
888 (setq widget-field-keymap (copy-keymap widget-keymap)) 875 (setq widget-field-keymap (copy-keymap widget-keymap))
889 (unless (string-match "XEmacs" (emacs-version)) 876 (define-key widget-field-keymap [menu-bar] 'nil)
890 (define-key widget-field-keymap [menu-bar] 'nil))
891 (define-key widget-field-keymap "\C-k" 'widget-kill-line) 877 (define-key widget-field-keymap "\C-k" 'widget-kill-line)
892 (define-key widget-field-keymap "\M-\t" 'widget-complete) 878 (define-key widget-field-keymap "\M-\t" 'widget-complete)
893 (define-key widget-field-keymap "\C-m" 'widget-field-activate) 879 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
894 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line) 880 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
895 (define-key widget-field-keymap "\C-e" 'widget-end-of-line) 881 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
898 (defvar widget-text-keymap nil 884 (defvar widget-text-keymap nil
899 "Keymap used inside a text field.") 885 "Keymap used inside a text field.")
900 886
901 (unless widget-text-keymap 887 (unless widget-text-keymap
902 (setq widget-text-keymap (copy-keymap widget-keymap)) 888 (setq widget-text-keymap (copy-keymap widget-keymap))
903 (unless (string-match "XEmacs" (emacs-version)) 889 (define-key widget-text-keymap [menu-bar] 'nil)
904 (define-key widget-text-keymap [menu-bar] 'nil))
905 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line) 890 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
906 (define-key widget-text-keymap "\C-e" 'widget-end-of-line) 891 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
907 (set-keymap-parent widget-text-keymap global-map)) 892 (set-keymap-parent widget-text-keymap global-map))
908 893
909 (defun widget-field-activate (pos &optional event) 894 (defun widget-field-activate (pos &optional event)
912 (let ((field (get-char-property pos 'field))) 897 (let ((field (get-char-property pos 'field)))
913 (if field 898 (if field
914 (widget-apply-action field event) 899 (widget-apply-action field event)
915 (call-interactively 900 (call-interactively
916 (lookup-key widget-global-map (this-command-keys)))))) 901 (lookup-key widget-global-map (this-command-keys))))))
902
903 (defvar widget-button-pressed-face 'widget-button-pressed-face
904 "Face used for pressed buttons in widgets.
905 This exists as a variable so it can be set locally in certain buffers.")
917 906
918 (defface widget-button-pressed-face 907 (defface widget-button-pressed-face
919 '((((class color)) 908 '((((class color))
920 (:foreground "red")) 909 (:foreground "red"))
921 (t 910 (t
938 (face (overlay-get overlay 'face)) 927 (face (overlay-get overlay 'face))
939 (mouse-face (overlay-get overlay 'mouse-face))) 928 (mouse-face (overlay-get overlay 'mouse-face)))
940 (unwind-protect 929 (unwind-protect
941 (let ((track-mouse t)) 930 (let ((track-mouse t))
942 (overlay-put overlay 931 (overlay-put overlay
943 'face 'widget-button-pressed-face) 932 'face widget-button-pressed-face)
944 (overlay-put overlay 933 (overlay-put overlay
945 'mouse-face 'widget-button-pressed-face) 934 'mouse-face widget-button-pressed-face)
946 (unless (widget-apply button :mouse-down-action event) 935 (unless (widget-apply button :mouse-down-action event)
947 (while (not (button-release-event-p event)) 936 (while (not (button-release-event-p event))
948 (setq event (widget-read-event) 937 (setq event (widget-read-event)
949 pos (widget-event-point event)) 938 pos (widget-event-point event))
950 (if (and pos 939 (if (and pos
951 (eq (get-char-property pos 'button) 940 (eq (get-char-property pos 'button)
952 button)) 941 button))
953 (progn 942 (progn
954 (overlay-put overlay 943 (overlay-put overlay
955 'face 944 'face
956 'widget-button-pressed-face) 945 widget-button-pressed-face)
957 (overlay-put overlay 946 (overlay-put overlay
958 'mouse-face 947 'mouse-face
959 'widget-button-pressed-face)) 948 widget-button-pressed-face))
960 (overlay-put overlay 'face face) 949 (overlay-put overlay 'face face)
961 (overlay-put overlay 'mouse-face mouse-face)))) 950 (overlay-put overlay 'mouse-face mouse-face))))
962 (when (and pos 951 (when (and pos
963 (eq (get-char-property pos 'button) button)) 952 (eq (get-char-property pos 'button) button))
964 (widget-apply-action button event))) 953 (widget-apply-action button event)))
2690 child)) 2679 child))
2691 2680
2692 ;;; The `group' Widget. 2681 ;;; The `group' Widget.
2693 2682
2694 (define-widget 'group 'default 2683 (define-widget 'group 'default
2695 "A widget which group other widgets inside." 2684 "A widget which groups other widgets inside."
2696 :convert-widget 'widget-types-convert-widget 2685 :convert-widget 'widget-types-convert-widget
2697 :format "%v" 2686 :format "%v"
2698 :value-create 'widget-group-value-create 2687 :value-create 'widget-group-value-create
2699 :value-delete 'widget-children-value-delete 2688 :value-delete 'widget-children-value-delete
2700 :value-get 'widget-editable-list-value-get 2689 :value-get 'widget-editable-list-value-get
2837 (widget-specify-doc widget from to) 2826 (widget-specify-doc widget from to)
2838 (when widget-documentation-links 2827 (when widget-documentation-links
2839 (let ((regexp widget-documentation-link-regexp) 2828 (let ((regexp widget-documentation-link-regexp)
2840 (predicate widget-documentation-link-p) 2829 (predicate widget-documentation-link-p)
2841 (type widget-documentation-link-type) 2830 (type widget-documentation-link-type)
2842 (buttons (widget-get widget :buttons))) 2831 (buttons (widget-get widget :buttons))
2832 (widget-mouse-face (default-value 'widget-mouse-face))
2833 (widget-button-face widget-documentation-face)
2834 (widget-button-pressed-face widget-documentation-face))
2843 (save-excursion 2835 (save-excursion
2844 (goto-char from) 2836 (goto-char from)
2845 (while (re-search-forward regexp to t) 2837 (while (re-search-forward regexp to t)
2846 (let ((name (match-string 1)) 2838 (let ((name (match-string 1))
2847 (begin (match-beginning 1)) 2839 (begin (match-beginning 1))
3540 'face (widget-apply widget :sample-face-get)) 3532 'face (widget-apply widget :sample-face-get))
3541 (widget-default-notify widget child event)) 3533 (widget-default-notify widget child event))
3542 3534
3543 ;;; The Help Echo 3535 ;;; The Help Echo
3544 3536
3545 (defun widget-echo-help-mouse ()
3546 "Display the help message for the widget under the mouse.
3547 Enable with (run-with-idle-timer 1 t 'widget-echo-help-mouse)"
3548 (let* ((pos (mouse-position))
3549 (frame (car pos))
3550 (x (car (cdr pos)))
3551 (y (cdr (cdr pos)))
3552 (win (window-at x y frame))
3553 (where (coordinates-in-window-p (cons x y) win)))
3554 (when (consp where)
3555 (save-window-excursion
3556 (progn ; save-excursion
3557 (select-window win)
3558 (let* ((result (compute-motion (window-start win)
3559 '(0 . 0)
3560 (point-max)
3561 where
3562 (window-width win)
3563 (cons (window-hscroll) 0)
3564 win)))
3565 (when (and (eq (nth 1 result) x)
3566 (eq (nth 2 result) y))
3567 (widget-echo-help (nth 0 result))))))))
3568 (unless track-mouse
3569 (setq track-mouse t)
3570 (add-hook 'post-command-hook 'widget-stop-mouse-tracking)))
3571
3572 (defun widget-stop-mouse-tracking (&rest args)
3573 "Stop the mouse tracking done while idle."
3574 (remove-hook 'post-command-hook 'widget-stop-mouse-tracking)
3575 (setq track-mouse nil))
3576
3577 (defun widget-at (pos) 3537 (defun widget-at (pos)
3578 "The button or field at POS." 3538 "The button or field at POS."
3579 (or (get-char-property pos 'button) 3539 (or (get-char-property pos 'button)
3580 (get-char-property pos 'field))) 3540 (get-char-property pos 'field)))
3581 3541