comparison lisp/prim/gui.el @ 0:376386a54a3c r19-14

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