]> code.delx.au - gnu-emacs/blobdiff - lisp/wid-edit.el
(Info-goto-index): One register one step in the history.
[gnu-emacs] / lisp / wid-edit.el
index fe58e1acf393f5c198092f2ad11786ff84a80144..a5cd1dba5231647af1a57597a0711cd6ef52812e 100644 (file)
@@ -1,6 +1,6 @@
 ;;; wid-edit.el --- Functions for creating and using widgets -*-byte-compile-dynamic: t;-*-
 ;;
-;; Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
 ;;
 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
 ;; Maintainer: FSF
@@ -120,7 +120,12 @@ This exists as a variable so it can be set locally in certain buffers.")
   :type 'face
   :group 'widget-faces)
 
-(defface widget-field-face '((((class grayscale color)
+;; TTY gets special definitions here and in the next defface, because
+;; the gray colors defined for other displays cause black text on a black
+;; background, at least on light-background TTYs.
+(defface widget-field-face '((((type tty))
+                             (:background "yellow3"))
+                            (((class grayscale color)
                               (background light))
                              (:background "gray85"))
                             (((class grayscale color)
@@ -131,7 +136,9 @@ This exists as a variable so it can be set locally in certain buffers.")
   "Face used for editable fields."
   :group 'widget-faces)
 
-(defface widget-single-line-field-face '((((class grayscale color)
+(defface widget-single-line-field-face '((((type tty))
+                                         (:background "green3"))
+                                        (((class grayscale color)
                                           (background light))
                                          (:background "gray85"))
                                         (((class grayscale color)
@@ -851,47 +858,65 @@ Recommended as a parent keymap for modes using widgets.")
   "Invoke the button that the mouse is pointing at."
   (interactive "@e")
   (if (widget-event-point event)
-      (save-excursion
-       (mouse-set-point event)
-       (let* ((pos (widget-event-point event))
-              (button (get-char-property pos 'button)))
-         (if button
-             (let* ((overlay (widget-get button :button-overlay))
-                    (face (overlay-get overlay 'face))
-                    (mouse-face (overlay-get overlay 'mouse-face)))
-               (unwind-protect
-                   (let ((track-mouse t))
-                     (save-excursion
-                       (when face      ; avoid changing around image
-                         (overlay-put overlay
-                                      'face widget-button-pressed-face)
-                         (overlay-put overlay
-                                      'mouse-face widget-button-pressed-face))
-                       (unless (widget-apply button :mouse-down-action event)
-                         (while (not (widget-button-release-event-p event))
-                           (setq event (read-event)
-                                 pos (widget-event-point event))
-                           (if (and pos
-                                    (eq (get-char-property pos 'button)
-                                        button))
-                               (when face
-                                 (overlay-put overlay
-                                              'face
-                                              widget-button-pressed-face)
-                                 (overlay-put overlay
-                                              'mouse-face
-                                              widget-button-pressed-face))
-                             (overlay-put overlay 'face face)
-                             (overlay-put overlay 'mouse-face mouse-face))))
-                       (when (and pos
-                                  (eq (get-char-property pos 'button) button))
-                         (widget-apply-action button event))))
-                 (overlay-put overlay 'face face)
-                 (overlay-put overlay 'mouse-face mouse-face)))
-           (let ((up t)
-                 command)
-             ;; Find the global command to run, and check whether it
-             ;; is bound to an up event.
+      (let* ((pos (widget-event-point event))
+            (button (get-char-property pos 'button)))
+       (if button
+           ;; Mouse click on a widget button.  Do the following
+           ;; in a save-excursion so that the click on the button
+           ;; doesn't change point.
+           (save-selected-window
+             (save-excursion
+               (mouse-set-point event)
+               (let* ((overlay (widget-get button :button-overlay))
+                      (face (overlay-get overlay 'face))
+                      (mouse-face (overlay-get overlay 'mouse-face)))
+                 (unwind-protect
+                     ;; Read events, including mouse-movement events
+                     ;; until we receive a release event.  Highlight/
+                     ;; unhighlight the button the mouse was initially
+                     ;; on when we move over it.
+                     (let ((track-mouse t))
+                       (save-excursion
+                         (when face    ; avoid changing around image
+                           (overlay-put overlay
+                                        'face widget-button-pressed-face)
+                           (overlay-put overlay
+                                        'mouse-face widget-button-pressed-face))
+                         (unless (widget-apply button :mouse-down-action event)
+                           (while (not (widget-button-release-event-p event))
+                             (setq event (read-event)
+                                   pos (widget-event-point event))
+                             (if (and pos
+                                      (eq (get-char-property pos 'button)
+                                          button))
+                                 (when face
+                                   (overlay-put overlay
+                                                'face
+                                                widget-button-pressed-face)
+                                   (overlay-put overlay
+                                                'mouse-face
+                                                widget-button-pressed-face))
+                               (overlay-put overlay 'face face)
+                               (overlay-put overlay 'mouse-face mouse-face))))
+
+                         ;; When mouse is released over the button, run
+                         ;; its action function.
+                         (when (and pos
+                                    (eq (get-char-property pos 'button) button))
+                           (widget-apply-action button event))))
+                   (overlay-put overlay 'face face)
+                   (overlay-put overlay 'mouse-face mouse-face))))
+
+               (unless (pos-visible-in-window-p (widget-event-point event))
+                 (mouse-set-point event)
+                 (beginning-of-line)
+                 (recenter)))
+
+           (let ((up t) command)
+             ;; Mouse click not on a widget button.  Find the global
+             ;; command to run, and check whether it is bound to an
+             ;; up event.
+             (mouse-set-point event)
              (if (memq (event-basic-type event) '(mouse-1 down-mouse-1))
                  (cond ((setq command  ;down event
                               (lookup-key widget-global-map [down-mouse-1]))
@@ -909,10 +934,6 @@ Recommended as a parent keymap for modes using widgets.")
                  (setq event (read-event))))
              (when command
                (call-interactively command)))))
-         (unless (pos-visible-in-window-p (widget-event-point event))
-           (mouse-set-point event)
-           (beginning-of-line)
-           (recenter)))
     (message "You clicked somewhere weird.")))
 
 (defun widget-button-press (pos &optional event)
@@ -1791,8 +1812,8 @@ the earlier input."
 ;;; The `text' Widget.
 
 (define-widget 'text 'editable-field
-  :keymap widget-text-keymap
-  "A multiline text area.")
+  "A multiline text area."
+  :keymap widget-text-keymap)
 
 ;;; The `menu-choice' Widget.
 
@@ -1975,9 +1996,18 @@ when he invoked the menu."
 (defun widget-toggle-value-create (widget)
   "Insert text representing the `on' and `off' states."
   (if (widget-value widget)
-      (widget-image-insert widget
-                          (widget-get widget :on)
-                          (widget-get widget :on-glyph))
+      (progn
+       (and (display-graphic-p)
+            (listp (widget-get widget :on-glyph))
+            (widget-put widget :on-glyph
+                        (eval (widget-get widget :on-glyph))))
+       (widget-image-insert widget
+                            (widget-get widget :on)
+                            (widget-get widget :on-glyph)))
+    (and (display-graphic-p)
+        (listp (widget-get widget :off-glyph))
+        (widget-put widget :off-glyph
+                    (eval (widget-get widget :off-glyph))))
     (widget-image-insert widget
                         (widget-get widget :off)
                         (widget-get widget :off-glyph))))
@@ -1999,18 +2029,19 @@ when he invoked the menu."
   ;; We could probably do the same job as the images using single
   ;; space characters in a boxed face with a stretch specification to
   ;; make them square.
-  :on-glyph (create-image "\377\311\301\343\301\311\377"  ; this is an `X'
-                         'xbm t :width 7 :height 7
-                         :foreground "grey75" ; like default mode line
-                         :background "black"
-                         :relief -3
-                         :ascent 'center)
-  :off "[ ]"
-  :off-glyph (create-image (make-bool-vector 49 1)
+  :on-glyph '(create-image "\000\066\076\034\076\066\000"
                           'xbm t :width 7 :height 7
-                          :foreground "grey75"
-                          :relief 3
+                          :background "grey75" ; like default mode line
+                          :foreground "black"
+                          :relief -3
                           :ascent 'center)
+  :off "[ ]"
+  :off-glyph '(create-image (make-string 7 0)
+                           'xbm t :width 7 :height 7
+                           :background "grey75"
+                           :foreground "black"
+                           :relief 3
+                           :ascent 'center)
   :help-echo "Toggle this item."
   :action 'widget-checkbox-action)
 
@@ -2031,7 +2062,6 @@ when he invoked the menu."
   :format "%v"
   :offset 4
   :entry-format "%b %v"
-  :menu-tag "checklist"
   :greedy nil
   :value-create 'widget-checklist-value-create
   :value-delete 'widget-children-value-delete
@@ -2209,7 +2239,6 @@ Return an alist of (TYPE MATCH)."
   :offset 4
   :format "%v"
   :entry-format "%b %v"
-  :menu-tag "radio"
   :value-create 'widget-radio-value-create
   :value-delete 'widget-children-value-delete
   :value-get 'widget-radio-value-get
@@ -2399,7 +2428,6 @@ Return an alist of (TYPE MATCH)."
   :format "%v%i\n"
   :format-handler 'widget-editable-list-format-handler
   :entry-format "%i %d %v"
-  :menu-tag "editable-list"
   :value-create 'widget-editable-list-value-create
   :value-delete 'widget-children-value-delete
   :value-get 'widget-editable-list-value-get
@@ -3194,10 +3222,11 @@ To use this type, you must define :match or :match-alternatives."
 (defun widget-plist-convert-widget (widget)
   ;; Handle `:options'.
   (let* ((options (widget-get widget :options))
+        (widget-plist-value-type (widget-get widget :value-type))
         (other `(editable-list :inline t
                                (group :inline t
                                       ,(widget-get widget :key-type)
-                                      ,(widget-get widget :value-type))))
+                                      ,widget-plist-value-type)))
         (args (if options
                   (list `(checklist :inline t
                                     :greedy t
@@ -3238,10 +3267,11 @@ To use this type, you must define :match or :match-alternatives."
 (defun widget-alist-convert-widget (widget)
   ;; Handle `:options'.
   (let* ((options (widget-get widget :options))
+        (widget-alist-value-type (widget-get widget :value-type))
         (other `(editable-list :inline t
                                (cons :format "%v"
                                      ,(widget-get widget :key-type)
-                                     ,(widget-get widget :value-type))))
+                                     ,widget-alist-value-type)))
         (args (if options
                   (list `(checklist :inline t
                                     :greedy t
@@ -3382,11 +3412,10 @@ To use this type, you must define :match or :match-alternatives."
 (defun widget-color-sample-face-get (widget)
   (let* ((value (condition-case nil
                    (widget-value widget)
-                 (error (widget-get widget :value))))
-        (symbol (intern (concat "fg:" value))))
-    (condition-case nil
-       (facemenu-get-face symbol)
-      (error 'default))))
+                 (error (widget-get widget :value)))))
+    (if (color-defined-p value)
+       (list (cons 'foreground-color value))
+      'default)))
 
 (defun widget-color-action (widget &optional event)
   "Prompt for a color."