annotate lisp/gui.el @ 327:03446687b7cc r21-0-61

Import from CVS: tag r21-0-61
author cvs
date Mon, 13 Aug 2007 10:48:16 +0200
parents c42ec1d1cded
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; gui.el --- Basic GUI functions for XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;; Copyright (C) 1996 Ben Wing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Keywords: internal, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;;; Synched up with: Not in FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs (when window system support is compiled in).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 (defcustom dialog-frame-plist '(width 60 height 20)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 "Plist of frame properties for initially creating a dialog frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 Properties specified here supersede the values given in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 `default-frame-plist'."
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 211
diff changeset
38 :type 'plist
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 :group 'frames)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 (defun make-dialog-frame (&optional props parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 "Create a frame suitable for use as a dialog box.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 The frame is made a child of PARENT (defaults to the selected frame),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 and has additional properties PROPS, as well as `dialog-frame-plist'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 Normally it also has no modelines, menubars, or toolbars."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 (or parent (setq parent (selected-frame)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 (let* ((ftop (frame-property parent 'top))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 (fleft (frame-property parent 'left))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 (fwidth (frame-pixel-width parent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 (fheight (frame-pixel-height parent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 (fonth (font-height (face-font 'default)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 (fontw (font-width (face-font 'default)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 (props (append props dialog-frame-plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 (dfheight (plist-get props 'height))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (dfwidth (plist-get props 'width))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 ;; under FVWM at least, if I don't specify the initial position,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 ;; it ends up always at (0, 0). xwininfo doesn't tell me
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 ;; that there are any program-specified position hints, so
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 ;; it must be an FVWM bug. So just be smashing and position
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 ;; in the center of the selected frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 (frame (make-frame
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 (append props
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 `(popup ,parent initially-unmapped t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 menubar-visible-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 has-modeline-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 default-toolbar-visible-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 modeline-shadow-thickness 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 left ,(+ fleft (- (/ fwidth 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 (/ (* dfwidth fontw)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 2)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 top ,(+ ftop (- (/ fheight 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (/ (* dfheight fonth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 2))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 (set-face-foreground 'modeline [default foreground] frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 (set-face-background 'modeline [default background] frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 (make-frame-visible frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 frame))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 (defvar gui-button-shadow-thickness 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 (defun gui-button-p (object)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 "True if OBJECT is a GUI button."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (and (vectorp object)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 (> (length object) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 (eq 'gui-button (aref object 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 (make-face 'gui-button-face "Face used for gui buttons")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 (if (not (face-differs-from-default-p 'gui-button-face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 (progn
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
90 (set-face-reverse-p 'gui-button-face t)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 219
diff changeset
91 (set-face-background 'gui-button-face '(((x color) . "grey75")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 219
diff changeset
92 ((mswindows color) . "grey75")))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 219
diff changeset
93 (set-face-foreground 'gui-button-face '(((x color) . "black")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 219
diff changeset
94 ((mswindows color) . "black")))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 (defun make-gui-button (string &optional action user-data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 "Make a GUI button whose label is STRING and whose action is ACTION.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 If the button is inserted in a buffer and then clicked on, and ACTION
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 is non-nil, ACTION will be called with one argument, USER-DATA."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 (vector 'gui-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 (if (featurep 'xpm)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 (xpm-button-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 string gui-button-shadow-thickness
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 (color-instance-name (face-foreground-instance 'gui-button-face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 (color-instance-name (face-background-instance 'gui-button-face)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 (xbm-button-create string gui-button-shadow-thickness))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 action user-data))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 (defun insert-gui-button (button &optional pos buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 "Insert GUI button BUTTON at POS in BUFFER."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (check-argument-type 'gui-button-p button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (let ((annotation
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (make-annotation (make-glyph (car (aref button 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 pos 'text buffer nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 (make-glyph (cadr (aref button 1)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 (action (aref button 2)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 (and action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (set-annotation-action annotation action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 (set-annotation-data annotation (aref button 3))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 ;;; gui.el ends here