annotate lisp/prim/gui.el @ 173:8eaf7971accc r20-3b13

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