Mercurial > hg > xemacs-beta
annotate lisp/dialog.el @ 5416:365bc8cb5894
Convert to GPLv3 misc files.
author | Mats Lidell <matsl@xemacs.org> |
---|---|
date | Wed, 27 Oct 2010 00:09:04 +0200 |
parents | 308d34e9f07d |
children | 89331fa1c819 |
rev | line source |
---|---|
209 | 1 ;;; dialog.el --- Dialog-box support for XEmacs |
2 | |
3 ;; Copyright (C) 1991-4, 1997 Free Software Foundation, Inc. | |
844 | 4 ;; Copyright (C) 2000, 2002 Ben Wing. |
209 | 5 |
6 ;; Maintainer: XEmacs Development Team | |
7 ;; Keywords: extensions, internal, dumped | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
11 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
12 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
13 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
14 ;; option) any later version. |
209 | 15 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
19 ;; for more details. |
209 | 20 |
21 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2730
diff
changeset
|
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
209 | 23 |
24 ;;; Synched up with: Not in FSF. | |
25 | |
844 | 26 ;;; Authorship: Mostly written or rewritten by Ben Wing; some old old stuff |
27 ;;; that underlies some current code was written by JWZ. | |
28 | |
209 | 29 ;;; Commentary: |
30 | |
31 ;; This file is dumped with XEmacs (when dialog boxes are compiled in). | |
32 | |
442 | 33 ;; Dialog boxes are non-modal at the C level, but made modal at the |
34 ;; Lisp level via hacks in functions such as yes-or-no-p-dialog-box | |
35 ;; below. Perhaps there should be truly modal dialog boxes | |
36 ;; implemented at the C level for safety. All code using dialog boxes | |
37 ;; should be careful to assume that the environment, for example the | |
38 ;; current buffer, might be completely different after returning from | |
39 ;; yes-or-no-p-dialog-box, but such code is difficult to write and test. | |
40 | |
209 | 41 ;;; Code: |
42 (defun yes-or-no-p-dialog-box (prompt) | |
442 | 43 "Ask user a yes-or-no question with a popup dialog box. |
44 Return t if the answer is \"yes\". | |
209 | 45 Takes one argument, which is the string to display to ask the question." |
442 | 46 (save-selected-frame |
47 (make-dialog-box 'question | |
48 :question prompt | |
49 :modal t | |
50 :buttons '(["Yes" (dialog-box-finish t)] | |
51 ["No" (dialog-box-finish nil)] | |
52 nil | |
53 ["Cancel" (dialog-box-cancel)])))) | |
209 | 54 |
442 | 55 ;; FSF has a similar function `x-popup-dialog'. |
209 | 56 (defun get-dialog-box-response (position contents) |
57 "Pop up a dialog box and return user's selection. | |
58 POSITION specifies which frame to use. | |
59 This is normally an event or a window or frame. | |
60 If POSITION is t or nil, it means to use the frame the mouse is on. | |
61 The dialog box appears in the middle of the specified frame. | |
62 | |
63 CONTENTS specifies the alternatives to display in the dialog box. | |
64 It is a list of the form (TITLE ITEM1 ITEM2...). | |
65 Each ITEM is a cons cell (STRING . VALUE). | |
66 The return value is VALUE from the chosen item. | |
67 | |
68 An ITEM may also be just a string--that makes a nonselectable item. | |
69 An ITEM may also be nil--that means to put all preceding items | |
70 on the left of the dialog box and all following items on the right." | |
71 (cond | |
72 ((eventp position) | |
73 (select-frame (event-frame position))) | |
74 ((framep position) | |
75 (select-frame position)) | |
76 ((windowp position) | |
77 (select-window position))) | |
442 | 78 (make-dialog-box 'question |
79 :question (car contents) | |
80 :modal t | |
81 :buttons | |
82 (mapcar #'(lambda (x) | |
83 (cond | |
84 ((null x) | |
85 nil) | |
86 ((stringp x) | |
87 ;;this will never get selected | |
88 `[,x 'ignore nil]) | |
89 (t | |
90 `[,(car x) (dialog-box-finish ',(cdr x)) t]))) | |
91 (cdr contents)))) | |
209 | 92 |
93 (defun message-box (fmt &rest args) | |
94 "Display a message, in a dialog box if possible. | |
95 If the selected device has no dialog-box support, use the echo area. | |
96 The arguments are the same as to `format'. | |
97 | |
98 If the only argument is nil, clear any existing message; let the | |
99 minibuffer contents show." | |
100 (if (and (null fmt) (null args)) | |
101 (progn | |
102 (clear-message nil) | |
103 nil) | |
104 (let ((str (apply 'format fmt args))) | |
105 (if (device-on-window-system-p) | |
442 | 106 (get-dialog-box-response nil (list str (cons "%_OK" t))) |
209 | 107 (display-message 'message str)) |
108 str))) | |
109 | |
110 (defun message-or-box (fmt &rest args) | |
442 | 111 "Display a message in a dialog box or in the echo area. |
112 If this command was invoked with the mouse, use a dialog box. | |
209 | 113 Otherwise, use the echo area. |
114 The arguments are the same as to `format'. | |
115 | |
116 If the only argument is nil, clear any existing message; let the | |
117 minibuffer contents show." | |
118 (if (should-use-dialog-box-p) | |
119 (apply 'message-box fmt args) | |
120 (apply 'message fmt args))) | |
121 | |
442 | 122 (defun make-dialog-box (type &rest cl-keys) |
123 "Pop up a dialog box. | |
124 TYPE is a symbol, the type of dialog box. Remaining arguments are | |
125 keyword-value pairs, specifying the particular characteristics of the | |
126 dialog box. The allowed keywords are particular to each type, but | |
127 some standard keywords are common to many types: | |
128 | |
129 :title | |
130 The title of the dialog box's window. | |
131 | |
132 :modal | |
133 If true, indicates that XEmacs will wait until the user is \"done\" | |
134 with the dialog box (usually, this means that a response has been | |
135 given). Typically, the response is returned. NOTE: Some dialog | |
136 boxes are always modal. If the dialog box is modal, `make-dialog-box' | |
137 returns immediately. The return value will be either nil or a | |
138 dialog box handle of some sort, e.g. a frame for type `general'. | |
139 | |
140 --------------------------------------------------------------------------- | |
141 | |
142 Recognized types are | |
143 | |
144 general | |
145 A dialog box consisting of an XEmacs glyph, typically a `layout' | |
146 widget specifying a dialog box arrangement. This is the most | |
147 general and powerful dialog box type, but requires more work than | |
148 the other types below. | |
149 | |
150 question | |
151 A simple dialog box that displays a question and contains one or | |
152 more user-defined buttons to specify possible responses. (This is | |
153 compatible with the old built-in dialog boxes formerly specified | |
154 using `popup-dialog-box'.) | |
155 | |
156 file | |
157 A file dialog box, of the type typically used in the window system | |
158 XEmacs is running on. | |
159 | |
160 color | |
161 A color picker. | |
162 | |
163 find | |
164 A find dialog box. | |
165 | |
166 font | |
167 A font chooser. | |
168 | |
169 print | |
170 A dialog box used when printing (e.g. number of pages, printer). | |
171 | |
172 page-setup | |
173 A dialog box for setting page options (e.g. margins) for printing. | |
174 | |
175 replace | |
176 A find/replace dialog box. | |
177 | |
178 mswindows-message | |
179 An MS Windows-specific standard dialog box type similar to `question'. | |
180 | |
181 --------------------------------------------------------------------------- | |
182 | |
183 For type `general': | |
184 | |
185 This type creates a frame and puts the specified widget layout in it. | |
186 \(Currently this is done by eliminating all areas but the gutter and placing | |
187 the layout there; but this is an implementation detail and may change.) | |
188 | |
189 The keywords allowed for `general' are | |
190 | |
191 :spec | |
192 The widget spec -- anything that can be passed to `make-glyph'. | |
193 :title | |
194 The title of the frame. | |
195 :parent | |
196 The frame is made a child of this frame (defaults to the selected frame). | |
197 :properties | |
198 Additional properties of the frame, as well as `dialog-frame-plist'. | |
863 | 199 :autosize |
200 If t the frame is sized to exactly fit the widgets given by :spec. | |
442 | 201 |
202 --------------------------------------------------------------------------- | |
203 | |
204 For type `question': | |
205 | |
206 The keywords allowed are | |
207 | |
208 :modal | |
209 t or nil. When t, the dialog box callback should exit the dialog box | |
210 using the functions `dialog-box-finish' or `dialog-box-cancel'. | |
211 :title | |
212 The title of the frame. | |
213 :question | |
214 A string, the question. | |
215 :buttons | |
216 A list, describing the buttons below the question. Each of these is a | |
217 vector, the syntax of which is essentially the same as that of popup menu | |
218 items. They may have any of the following forms: | |
219 | |
220 [ \"name\" callback <active-p> ] | |
221 [ \"name\" callback <active-p> \"suffix\" ] | |
222 [ \"name\" callback :<keyword> <value> :<keyword> <value> ... ] | |
223 | |
224 The name is the string to display on the button; it is filtered through the | |
225 resource database, so it is possible for resources to override what string | |
226 is actually displayed. | |
227 | |
228 Accelerators can be indicated in the string by putting the sequence | |
229 \"%_\" before the character corresponding to the key that will invoke | |
230 the button. Uppercase and lowercase accelerators are equivalent. The | |
231 sequence \"%%\" is also special, and is translated into a single %. | |
232 | |
233 If the `callback' of a button is a symbol, then it must name a command. | |
234 It will be invoked with `call-interactively'. If it is a list, then it is | |
235 evaluated with `eval'. | |
236 | |
237 One (and only one) of the buttons may be `nil'. This marker means that all | |
238 following buttons should be flushright instead of flushleft. | |
239 | |
240 Though the keyword/value syntax is supported for dialog boxes just as in | |
241 popup menus, the only keyword which is both meaningful and fully implemented | |
242 for dialog box buttons is `:active'. | |
243 | |
244 --------------------------------------------------------------------------- | |
245 | |
246 For type `file': | |
247 | |
248 The keywords allowed are | |
249 | |
250 :initial-filename | |
251 The initial filename to be placed in the dialog box (defaults to nothing). | |
252 :initial-directory | |
253 The initial directory to be selected in the dialog box (defaults to the | |
254 current buffer's `default-directory). | |
255 :filter-list | |
256 A list of (filter-desc filter ...) | |
257 :title | |
258 The title of the dialog box (defaults to \"Open\"). | |
259 :allow-multi-select t or nil | |
260 :create-prompt-on-nonexistent t or nil | |
261 :overwrite-prompt t or nil | |
262 :file-must-exist t or nil | |
263 :no-network-button t or nil | |
264 :no-read-only-return t or nil | |
265 | |
266 --------------------------------------------------------------------------- | |
267 | |
673 | 268 For type `directory': |
269 | |
270 The keywords allowed are | |
271 | |
272 :initial-directory | |
273 The initial directory to be selected in the dialog box (defaults to the | |
274 current buffer's `default-directory). | |
275 :title | |
276 The title of the dialog box (defaults to \"Open\"). | |
277 | |
278 --------------------------------------------------------------------------- | |
279 | |
442 | 280 For type `print': |
281 | |
282 This invokes the Windows standard Print dialog. | |
283 This dialog is usually invoked when the user selects the Print command. | |
284 After the user presses OK, the program should start actual printout. | |
285 | |
286 The keywords allowed are | |
287 | |
288 :device | |
289 An 'msprinter device. | |
290 :print-settings | |
291 A printer settings object. | |
510 | 292 :allow-selection |
293 t or nil -- whether the \"Selection\" button is enabled (defaults to nil). | |
294 :allow-pages | |
295 t or nil -- whether the \"Pages\" button and associated edit controls | |
296 are enabled (defaults to t). | |
297 :selected-page-button | |
298 `all', `selection', or `pages' -- which page button is initially | |
299 selected. | |
442 | 300 |
510 | 301 Exactly one of :device and :print-settings must be given. |
442 | 302 |
303 The function brings up the Print dialog, where the user can | |
506 | 304 select a different printer and/or change printer options. Connection |
442 | 305 name can change as a result of selecting a different printer device. If |
506 | 306 a device is specified, then changes are stored into the settings object |
442 | 307 currently selected into that printer. If a settings object is supplied, |
629 | 308 then changes are recorded into it, and, it is selected into a |
442 | 309 printer, then changes are propagated to that printer |
310 too. | |
311 | |
312 Return value is nil if the user has canceled the dialog. Otherwise, it | |
313 is a new plist, with the following properties: | |
510 | 314 name Printer device name, even if unchanged by the user. |
315 from-page First page to print, 1-based. Returned if | |
316 `selected-page-button' is `pages'. | |
317 user, then this value is not included in the plist. | |
318 to-page Last page to print, inclusive, 1-based. Returned if | |
319 `selected-page-button' is `pages'. | |
320 copies Number of copies to print. Always returned. | |
321 selected-page-button Which page button was selected (`all', `selection', | |
322 or `pages'). | |
442 | 323 |
324 The DEVICE is destroyed and an error is signaled in case of | |
325 initialization problem with the new printer. | |
326 | |
510 | 327 See also the `page-setup' dialog box type. |
442 | 328 |
329 --------------------------------------------------------------------------- | |
330 | |
331 For type `page-setup': | |
332 | |
333 This invokes the Windows standard Page Setup dialog. | |
506 | 334 This dialog is usually invoked in response to the Page Setup command, |
335 and used to choose such parameters as page orientation, print margins | |
336 etc. Note that this dialog contains the \"Printer\" button, which | |
337 invokes the Printer Setup dialog so that the user can update the | |
338 printer options or even select a different printer as well. | |
442 | 339 |
340 The keywords allowed are | |
341 | |
342 :device | |
343 An 'msprinter device. | |
344 :print-settings | |
345 A printer settings object. | |
346 :properties | |
347 A plist of job properties. | |
348 | |
349 Exactly one of these keywords must be given. | |
350 | |
351 The function brings up the Page Setup dialog, where the user | |
352 can select a different printer and/or change printer options. | |
353 Connection name can change as a result of selecting a different printer | |
506 | 354 device. If a device is specified, then changes are stored into the |
442 | 355 settings object currently selected into that printer. If a settings |
629 | 356 object is supplied, then changes are recorded into it, and, it is |
442 | 357 selected into a printer, then changes are propagated to that printer |
358 too. | |
359 | |
360 :properties specifies a plist of job properties; | |
361 see `default-msprinter-frame-plist' for the complete list. The plist | |
362 is used to initialize the dialog. | |
363 | |
364 Return value is nil if the user has canceled the dialog. Otherwise, | |
365 it is a new plist, containing the new list of properties. | |
366 | |
506 | 367 NOTE: The margin properties (returned by this function) are *NOT* stored |
368 into the print-settings or device object. | |
369 | |
442 | 370 The DEVICE is destroyed and an error is signaled in case of |
371 initialization problem with the new printer. | |
372 | |
510 | 373 See also the `print' dialog box type. |
442 | 374 |
375 --------------------------------------------------------------------------- | |
376 | |
377 For type `mswindows-message': | |
378 | |
379 The keywords allowed are | |
380 | |
381 :title | |
382 The title of the dialog box. | |
383 :message | |
384 The string to display. | |
385 :flags | |
386 A symbol or list of symbols: | |
387 | |
388 -- To specify the buttons in the message box: | |
389 | |
390 abortretryignore | |
391 The message box contains three push buttons: Abort, Retry, and Ignore. | |
392 ok | |
393 The message box contains one push button: OK. This is the default. | |
394 okcancel | |
395 The message box contains two push buttons: OK and Cancel. | |
396 retrycancel | |
397 The message box contains two push buttons: Retry and Cancel. | |
398 yesno | |
399 The message box contains two push buttons: Yes and No. | |
400 yesnocancel | |
401 The message box contains three push buttons: Yes, No, and Cancel. | |
402 | |
403 | |
404 -- To display an icon in the message box: | |
405 | |
406 iconexclamation, iconwarning | |
407 An exclamation-point icon appears in the message box. | |
408 iconinformation, iconasterisk | |
409 An icon consisting of a lowercase letter i in a circle appears in | |
410 the message box. | |
411 iconquestion | |
412 A question-mark icon appears in the message box. | |
413 iconstop, iconerror, iconhand | |
414 A stop-sign icon appears in the message box. | |
415 | |
416 | |
417 -- To indicate the default button: | |
418 | |
419 defbutton1 | |
420 The first button is the default button. This is the default. | |
421 defbutton2 | |
422 The second button is the default button. | |
423 defbutton3 | |
424 The third button is the default button. | |
425 defbutton4 | |
426 The fourth button is the default button. | |
427 | |
428 | |
429 -- To indicate the modality of the dialog box: | |
430 | |
431 applmodal | |
432 The user must respond to the message box before continuing work in | |
433 the window identified by the hWnd parameter. However, the user can | |
434 move to the windows of other applications and work in those windows. | |
435 Depending on the hierarchy of windows in the application, the user | |
436 may be able to move to other windows within the application. All | |
437 child windows of the parent of the message box are automatically | |
438 disabled, but popup windows are not. This is the default. | |
439 systemmodal | |
440 Same as applmodal except that the message box has the WS_EX_TOPMOST | |
441 style. Use system-modal message boxes to notify the user of serious, | |
442 potentially damaging errors that require immediate attention (for | |
443 example, running out of memory). This flag has no effect on the | |
444 user's ability to interact with windows other than those associated | |
445 with hWnd. | |
446 taskmodal | |
447 Same as applmodal except that all the top-level windows belonging to | |
448 the current task are disabled if the hWnd parameter is NULL. Use | |
449 this flag when the calling application or library does not have a | |
450 window handle available but still needs to prevent input to other | |
451 windows in the current application without suspending other | |
452 applications. | |
453 | |
454 | |
455 In addition, you can specify the following flags: | |
456 | |
457 default-desktop-only | |
458 The desktop currently receiving input must be a default desktop; | |
459 otherwise, the function fails. A default desktop is one an | |
460 application runs on after the user has logged on. | |
461 help | |
462 Adds a Help button to the message box. Choosing the Help button or | |
463 pressing F1 generates a Help event. | |
464 right | |
465 The text is right-justified. | |
466 rtlreading | |
467 Displays message and caption text using right-to-left reading order | |
468 on Hebrew and Arabic systems. | |
469 setforeground | |
470 The message box becomes the foreground window. Internally, Windows | |
471 calls the SetForegroundWindow function for the message box. | |
472 topmost | |
473 The message box is created with the WS_EX_TOPMOST window style. | |
474 service-notification | |
475 Windows NT only: The caller is a service notifying the user of an | |
476 event. The function displays a message box on the current active | |
477 desktop, even if there is no user logged on to the computer. If | |
478 this flag is set, the hWnd parameter must be NULL. This is so the | |
479 message box can appear on a desktop other than the desktop | |
480 corresponding to the hWnd. | |
481 | |
482 | |
483 The return value is one of the following menu-item values returned by | |
484 the dialog box: | |
485 | |
486 abort | |
487 Abort button was selected. | |
488 cancel | |
489 Cancel button was selected. | |
490 ignore | |
491 Ignore button was selected. | |
492 no | |
493 No button was selected. | |
494 ok | |
495 OK button was selected. | |
496 retry | |
497 Retry button was selected. | |
498 yes | |
499 Yes button was selected. | |
500 | |
501 If a message box has a Cancel button, the function returns the | |
502 `cancel' value if either the ESC key is pressed or the Cancel button | |
503 is selected. If the message box has no Cancel button, pressing ESC has | |
504 no effect." | |
505 (flet ((dialog-box-modal-loop (thunk) | |
506 (let* ((frames (frame-list)) | |
507 (result | |
508 ;; ok, this is extremely tricky. normally a modal | |
509 ;; dialog will pop itself down using (dialog-box-finish) | |
510 ;; or (dialog-box-cancel), which throws back to this | |
511 ;; catch. but question dialog boxes pop down themselves | |
512 ;; regardless, so a badly written question dialog box | |
513 ;; that does not use (dialog-box-finish) could seriously | |
514 ;; wedge us. furthermore, we disable all other frames | |
515 ;; in order to implement modality; we need to restore | |
516 ;; them before the dialog box is destroyed, because | |
517 ;; otherwise windows at least will notice that no top- | |
518 ;; level window can have the focus and will shift the | |
519 ;; focus to a different app, raising it and obscuring us. | |
520 ;; so we create `delete-dialog-box-hook', which is | |
521 ;; called right *before* the dialog box gets destroyed. | |
522 ;; here, we put a hook on it, and when it's our dialog | |
523 ;; box and not someone else's that's being destroyed, | |
524 ;; we reenable all the frames and remove the hook. | |
525 ;; BUT ... we still have to deal with exiting the | |
526 ;; modal loop in case it doesn't happen before us. | |
527 ;; we can't do this until after the callbacks for this | |
528 ;; dialog box get executed, and that doesn't happen until | |
529 ;; after the dialog box is destroyed. so to keep things | |
530 ;; synchronous, we enqueue an eval event, which goes into | |
531 ;; the same queue as the misc-user events encapsulating | |
532 ;; the dialog callbacks and will go after it (because | |
533 ;; destroying the dialog box happens after processing | |
534 ;; its selection). if the dialog boxes are written | |
535 ;; properly, we don't see this eval event, because we've | |
536 ;; already exited our modal loop. (Thus, we make sure the | |
537 ;; function given in this eval event is actually defined | |
538 ;; and does nothing.) If we do see it, though, we know | |
539 ;; that we encountered a badly written dialog box and | |
540 ;; need to exit now. Currently we just return nil, but | |
541 ;; maybe we should signal an error or issue a warning. | |
542 (catch 'internal-dialog-box-finish | |
543 (let ((id (eval thunk)) | |
544 (sym (gensym))) | |
545 (fset sym | |
546 `(lambda (did) | |
547 (when (eq ',id did) | |
548 (mapc 'enable-frame ',frames) | |
549 (enqueue-eval-event | |
550 'internal-make-dialog-box-exit did) | |
551 (remove-hook 'delete-dialog-box-hook | |
552 ',sym)))) | |
1066 | 553 (if (framep id) |
554 (add-hook 'delete-frame-hook sym) | |
555 (add-hook 'delete-dialog-box-hook sym)) | |
442 | 556 (mapc 'disable-frame frames) |
557 (block nil | |
558 (while t | |
559 (let ((event (next-event))) | |
560 (if (and (eval-event-p event) | |
561 (eq (event-function event) | |
562 'internal-make-dialog-box-exit) | |
563 (eq (event-object event) id)) | |
564 (return '(nil)) | |
565 (dispatch-event event))))))))) | |
566 (if (listp result) | |
567 (car result) | |
568 (signal 'quit nil))))) | |
569 (case type | |
570 (general | |
571 (cl-parsing-keywords | |
572 ((:title "XEmacs") | |
573 (:parent (selected-frame)) | |
574 :modal | |
575 :properties | |
863 | 576 :autosize |
442 | 577 :spec) |
578 () | |
579 (flet ((create-dialog-box-frame () | |
580 (let* ((ftop (frame-property cl-parent 'top)) | |
581 (fleft (frame-property cl-parent 'left)) | |
582 (fwidth (frame-pixel-width cl-parent)) | |
583 (fheight (frame-pixel-height cl-parent)) | |
584 (fonth (font-height (face-font 'default))) | |
585 (fontw (font-width (face-font 'default))) | |
586 (cl-properties (append cl-properties | |
587 dialog-frame-plist)) | |
588 (dfheight (plist-get cl-properties 'height)) | |
589 (dfwidth (plist-get cl-properties 'width)) | |
590 (unmapped (plist-get cl-properties | |
591 'initially-unmapped)) | |
592 (gutter-spec cl-spec) | |
593 (name (or (plist-get cl-properties 'name) "XEmacs")) | |
594 (frame nil)) | |
595 (plist-remprop cl-properties 'initially-unmapped) | |
596 ;; allow the user to just provide a glyph | |
597 (or (glyphp cl-spec) (setq cl-spec (make-glyph cl-spec))) | |
598 (setq gutter-spec (copy-sequence "\n")) | |
599 (set-extent-begin-glyph (make-extent 0 1 gutter-spec) | |
600 cl-spec) | |
601 ;; under FVWM at least, if I don't specify the | |
602 ;; initial position, it ends up always at (0, 0). | |
603 ;; xwininfo doesn't tell me that there are any | |
604 ;; program-specified position hints, so it must be | |
605 ;; an FVWM bug. So just be smashing and position in | |
606 ;; the center of the selected frame. | |
607 (setq frame | |
608 (make-frame | |
609 (append cl-properties | |
502 | 610 `(popup |
611 ,cl-parent initially-unmapped t | |
612 menubar-visible-p nil | |
613 has-modeline-p nil | |
614 default-toolbar-visible-p nil | |
615 top-gutter-visible-p t | |
616 top-gutter-height ,(* dfheight fonth) | |
617 top-gutter ,gutter-spec | |
618 minibuffer none | |
619 name ,name | |
620 modeline-shadow-thickness 0 | |
621 vertical-scrollbar-visible-p nil | |
622 horizontal-scrollbar-visible-p nil | |
623 unsplittable t | |
863 | 624 internal-border-width 8 |
502 | 625 left ,(+ fleft (- (/ fwidth 2) |
626 (/ (* dfwidth | |
627 fontw) | |
628 2))) | |
629 top ,(+ ftop (- (/ fheight 2) | |
630 (/ (* dfheight | |
631 fonth) | |
632 2))))))) | |
442 | 633 (set-face-foreground 'modeline [default foreground] frame) |
634 (set-face-background 'modeline [default background] frame) | |
863 | 635 ;; resize before mapping |
636 (when cl-autosize | |
1126 | 637 (set-frame-displayable-pixel-size |
863 | 638 frame |
639 (image-instance-width | |
640 (glyph-image-instance cl-spec | |
641 (frame-selected-window frame))) | |
642 (image-instance-height | |
643 (glyph-image-instance cl-spec | |
644 (frame-selected-window frame))))) | |
645 ;; somehow, even though the resizing is supposed | |
646 ;; to be while the frame is not visible, a | |
647 ;; visible resize is perceptible | |
442 | 648 (unless unmapped (make-frame-visible frame)) |
649 (let ((newbuf (generate-new-buffer " *dialog box*"))) | |
650 (set-buffer-dedicated-frame newbuf frame) | |
651 (set-frame-property frame 'dialog-box-buffer newbuf) | |
502 | 652 (set-window-buffer (frame-root-window frame) newbuf) |
442 | 653 (with-current-buffer newbuf |
502 | 654 (set (make-local-variable 'frame-title-format) |
655 cl-title) | |
656 (add-local-hook 'delete-frame-hook | |
657 #'(lambda (frame) | |
658 (kill-buffer | |
659 (frame-property | |
660 frame | |
661 'dialog-box-buffer)))))) | |
442 | 662 frame))) |
663 (if cl-modal | |
664 (dialog-box-modal-loop '(create-dialog-box-frame)) | |
665 (create-dialog-box-frame))))) | |
666 (question | |
667 (cl-parsing-keywords | |
668 ((:modal nil)) | |
669 t | |
670 (remf cl-keys :modal) | |
671 (if cl-modal | |
672 (dialog-box-modal-loop `(make-dialog-box-internal ',type | |
673 ',cl-keys)) | |
674 (make-dialog-box-internal type cl-keys)))) | |
675 (t | |
676 (make-dialog-box-internal type cl-keys))))) | |
677 | |
678 (defun dialog-box-finish (result) | |
679 "Exit a modal dialog box, returning RESULT. | |
680 This is meant to be executed from a dialog box callback function." | |
681 (throw 'internal-dialog-box-finish (list result))) | |
682 | |
683 (defun dialog-box-cancel () | |
684 "Cancel a modal dialog box. | |
685 This is meant to be executed from a dialog box callback function." | |
686 (throw 'internal-dialog-box-finish 'cancel)) | |
687 | |
688 ;; an eval event, used as a trigger inside of the dialog modal loop. | |
689 (defun internal-make-dialog-box-exit (did) | |
690 nil) | |
691 | |
692 (make-obsolete 'popup-dialog-box 'make-dialog-box) | |
693 (defun popup-dialog-box (desc) | |
694 "Obsolete equivalent of (make-dialog-box 'question ...). | |
695 | |
696 \(popup-dialog-box (QUESTION BUTTONS ...) | |
697 | |
698 is equivalent to | |
699 | |
700 \(make-dialog-box 'question :question QUESTION :buttons BUTTONS)" | |
701 (check-argument-type 'stringp (car desc)) | |
702 (or (consp (cdr desc)) | |
703 (error 'syntax-error | |
704 "Dialog descriptor must supply at least one button" | |
705 desc)) | |
706 (make-dialog-box 'question :question (car desc) :buttons (cdr desc))) | |
707 | |
209 | 708 ;;; dialog.el ends here |