1 ;;; efc-xemacs.el -- Emacs Foundation Classes using XEmacs gui features.
3 ;; Author: Andy Piper <andy@xemacs.org>
4 ;; Maintainer: Andy Piper
5 ;; Keywords: lisp, tools, classes gui
7 ;; Copyright (C) 2002, 2003, 2004 Andy Piper.
8 ;; Copyright (C) 2001, 2002 Paul Kinnucan.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU 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, US
26 ;; This package contains a set of eieio-based foundation classes
29 ;; Please send bug reports and enhancement suggestions
30 ;; to Andy Piper at <andy@xemacs.org>
37 ;; Install ourselves as the default option function,
38 ;; only if this version of XEmacs supports native widgets.
39 (when (and (fboundp 'make-dialog-box)
41 (setq efc-query-options-function 'efc-xemacs-query-options))
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 (defclass efc-xemacs-option-dialog (efc-dialog)
50 ((options :initarg :options
52 "Options from from which to choose.")
53 (radio-buttons :initarg :radio-buttons
55 "Buttons for selecting options.")
58 :initform "Select option."
60 "Text to be inserted at top of dialog.")
61 (selection :initarg :selection
64 "Option chosen by the user."))
65 "This dialog allows a user to choose one of a set of OPTIONS by clicking
66 a radio button next to the option. The dialog sets SELECTION to the option
67 chosen by the user when the user selects the OK button on the dialog. This
68 dialog uses recursive edit to emulate a modal dialog.")
70 (defmethod initialize-instance ((this efc-xemacs-option-dialog) &rest fields)
74 (defmethod efc-dialog-show ((this efc-xemacs-option-dialog))
75 "Shows the options dialog buffer. After showing the dialog buffer,
76 this method invokes recursive-edit to emulate the behavior of a modal
77 dialog. This suspends the current command until the user has selected
78 an option or canceled the dialog. See `efc-dialog-ok' and
79 `efc-dialog-cancel' for more information."
80 (efc-xemacs-option-dialog-show this))
82 ;; This is hack to get round a bug in XEmacs' treatment of :selected
83 (defvar efc-xemacs-option-dialog-selection nil)
85 (defun efc-xemacs-option-dialog-show (this)
86 (let ((parent (selected-frame)))
87 (unless (oref this selection)
88 (oset this selection (car (oref this options))))
89 (setq efc-xemacs-option-dialog-selection (oref this selection))
95 :title (oref this title)
99 `[layout :orientation vertical
101 :border [string :data ,(oref this text)]
102 :items ([layout :orientation vertical
103 :horizontally-justify left
104 :vertically-justify center
109 'button :descriptor x
112 (list 'efc-xemacs-option-dialog-action this x)
114 (list 'efc-xemacs-option-dialog-select this x)))
115 (oref this options))]
116 [layout :orientation horizontal
119 ([button :descriptor "Ok"
121 (lambda (image-instance event)
122 (efc-xemacs-dialog-ok ,this event))]
123 [button :descriptor "Cancel"
124 :callback-ex 'efc-xemacs-dialog-cancel
128 (defun efc-xemacs-option-dialog-select (this item)
129 (oset this selection item)
130 (setq efc-xemacs-option-dialog-selection item))
132 (defun efc-xemacs-option-dialog-action (this item)
133 ; This doesn't work for some reason I don't understand
134 ; (equal item (oref this selection))
135 (equal efc-xemacs-option-dialog-selection item))
137 (defun efc-xemacs-dialog-ok (image-instance event)
138 "Invoked when the user selects the OK button on the options
139 dialog. Sets the :selection field of THIS to the option chosen by the
140 user and kills the dialog window."
141 (delete-frame (event-channel event))
142 (dialog-box-finish efc-xemacs-option-dialog-selection))
144 (defun efc-xemacs-dialog-cancel (image-instance event)
145 "Invoked when the user clicks the dialog's Cancel button. Invokes
146 the default cancel method, sets the :selection field of THIS to nil,
147 and kills the dialog window."
148 (delete-frame (event-channel event))
151 (defun efc-xemacs-query-options (options &optional prompt title)
152 "Ask user to choose among a set of options."
154 (efc-xemacs-option-dialog
155 (or title "Option Dialog")
156 :title (or title "Option Dialog")
157 :text (if prompt prompt "Select option:")
159 (efc-dialog-show dialog)
160 (oref dialog selection)))
162 ;(defun efc-xemacs-test()
164 ; (message (efc-query-options (list "one" "two" "three")
165 ; "Select an option.")))
167 ;(defun efc-xemacs-test-ok()
172 ; :title "Ok cancel dialog")))
173 ; (efc-dialog-show dialog)))
175 (provide 'efc-xemacs)