annotate lisp/prim/gui.el @ 171:929b76928fce r20-3b12

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