annotate lisp/gui.el @ 209:41ff10fd062f r20-4b3

Import from CVS: tag r20-4b3
author cvs
date Mon, 13 Aug 2007 10:04:58 +0200
parents
children 78478c60bfcd
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'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38 :type '(repeat (group :inline t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 (symbol :tag "Property")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 (sexp :tag "Value")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 :group 'frames)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 (defun make-dialog-frame (&optional props parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 "Create a frame suitable for use as a dialog box.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 The frame is made a child of PARENT (defaults to the selected frame),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 and has additional properties PROPS, as well as `dialog-frame-plist'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 Normally it also has no modelines, menubars, or toolbars."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 (or parent (setq parent (selected-frame)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 (let* ((ftop (frame-property parent 'top))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 (fleft (frame-property parent 'left))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 (fwidth (frame-pixel-width parent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 (fheight (frame-pixel-height parent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 (fonth (font-height (face-font 'default)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 (fontw (font-width (face-font 'default)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (props (append props dialog-frame-plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 (dfheight (plist-get props 'height))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 (dfwidth (plist-get props 'width))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 ;; under FVWM at least, if I don't specify the initial position,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 ;; it ends up always at (0, 0). xwininfo doesn't tell me
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 ;; that there are any program-specified position hints, so
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 ;; it must be an FVWM bug. So just be smashing and position
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 ;; in the center of the selected frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 (frame (make-frame
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 (append props
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 `(popup ,parent initially-unmapped t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 menubar-visible-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 has-modeline-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 default-toolbar-visible-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 modeline-shadow-thickness 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 left ,(+ fleft (- (/ fwidth 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 (/ (* dfwidth fontw)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 2)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 top ,(+ ftop (- (/ fheight 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 (/ (* dfheight fonth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 2))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 (set-face-foreground 'modeline [default foreground] frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 (set-face-background 'modeline [default background] frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (make-frame-visible frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 frame))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 (defvar gui-button-shadow-thickness 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (defun gui-button-p (object)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 "True if OBJECT is a GUI button."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 (and (vectorp object)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 (> (length object) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 (eq 'gui-button (aref object 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 (make-face 'gui-button-face "Face used for gui buttons")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 (if (not (face-differs-from-default-p 'gui-button-face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 (set-face-background 'gui-button-face "grey75")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (set-face-foreground 'gui-button-face "black")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (defun make-gui-button (string &optional action user-data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 "Make a GUI button whose label is STRING and whose action is ACTION.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 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
98 is non-nil, ACTION will be called with one argument, USER-DATA."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 (vector 'gui-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 (if (featurep 'xpm)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 (xpm-button-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 string gui-button-shadow-thickness
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 (color-instance-name (face-foreground-instance 'gui-button-face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 (color-instance-name (face-background-instance 'gui-button-face)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 (xbm-button-create string gui-button-shadow-thickness))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 action user-data))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 (defun insert-gui-button (button &optional pos buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 "Insert GUI button BUTTON at POS in BUFFER."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 (check-argument-type 'gui-button-p button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (let ((annotation
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (make-annotation (make-glyph (car (aref button 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 pos 'text buffer nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 (make-glyph (cadr (aref button 1)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 (action (aref button 2)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 (and action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 (set-annotation-action annotation action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (set-annotation-data annotation (aref button 3))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 ;;; gui.el ends here