0
|
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
|
16
|
17 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
18 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 ;; Boston, MA 02111-1307, USA.
|
0
|
20
|
|
21 (defvar dialog-frame-plist '(width 60 height 20)
|
|
22 "Plist of frame properties for initially creating a dialog frame.
|
|
23 Properties specified here supersede the values given in
|
|
24 `default-frame-plist'.")
|
|
25
|
|
26 (defun make-dialog-frame (&optional props parent)
|
|
27 "Create a frame suitable for use as a dialog box.
|
|
28 The frame is made a child of PARENT (defaults to the selected frame),
|
|
29 and has additional properties PROPS, as well as `dialog-frame-plist'.
|
|
30 Normally it also has no modelines, menubars, or toolbars."
|
|
31 (or parent (setq parent (selected-frame)))
|
|
32 (let* ((ftop (frame-property parent 'top))
|
|
33 (fleft (frame-property parent 'left))
|
|
34 (fwidth (frame-pixel-width parent))
|
|
35 (fheight (frame-pixel-height parent))
|
|
36 (fonth (font-height (face-font 'default)))
|
|
37 (fontw (font-width (face-font 'default)))
|
|
38 (props (append props dialog-frame-plist))
|
|
39 (dfheight (plist-get props 'height))
|
|
40 (dfwidth (plist-get props 'width))
|
|
41 ;; under FVWM at least, if I don't specify the initial position,
|
|
42 ;; it ends up always at (0, 0). xwininfo doesn't tell me
|
|
43 ;; that there are any program-specified position hints, so
|
|
44 ;; it must be an FVWM bug. So just be smashing and position
|
|
45 ;; in the center of the selected frame.
|
|
46 (frame (make-frame
|
|
47 (append props
|
|
48 `(popup ,parent initially-unmapped t
|
|
49 menubar-visible-p nil
|
|
50 has-modeline-p nil
|
|
51 default-toolbar-visible-p nil
|
|
52 modeline-shadow-thickness 0
|
|
53 left ,(+ fleft (- (/ fwidth 2)
|
|
54 (/ (* dfwidth fontw)
|
|
55 2)))
|
|
56 top ,(+ ftop (- (/ fheight 2)
|
|
57 (/ (* dfheight fonth)
|
|
58 2))))))))
|
|
59 (set-face-foreground 'modeline [default foreground] frame)
|
|
60 (set-face-background 'modeline [default background] frame)
|
|
61 (make-frame-visible frame)
|
|
62 frame))
|
|
63
|
|
64 (defvar gui-button-shadow-thickness 2)
|
|
65
|
|
66 (defun gui-button-p (object)
|
|
67 "True if OBJECT is a GUI button."
|
|
68 (and (vectorp object)
|
|
69 (> (length object) 0)
|
|
70 (eq 'gui-button (aref object 0))))
|
|
71
|
|
72 (make-face 'gui-button-face "Face used for gui buttons")
|
|
73 (if (not (face-differs-from-default-p 'gui-button-face))
|
|
74 (progn
|
|
75 (set-face-background 'gui-button-face "grey75")
|
|
76 (set-face-foreground 'gui-button-face "black")))
|
|
77
|
|
78 (defun make-gui-button (string &optional action user-data)
|
|
79 "Make a GUI button whose label is STRING and whose action is ACTION.
|
|
80 If the button is inserted in a buffer and then clicked on, and ACTION
|
|
81 is non-nil, ACTION will be called with one argument, USER-DATA."
|
|
82 (vector 'gui-button
|
|
83 (if (featurep 'xpm)
|
|
84 (xpm-button-create
|
|
85 string gui-button-shadow-thickness
|
|
86 (color-instance-name (face-foreground-instance 'gui-button-face))
|
|
87 (color-instance-name (face-background-instance 'gui-button-face)))
|
|
88 (xbm-button-create string gui-button-shadow-thickness))
|
|
89 action user-data))
|
|
90
|
|
91 (defun insert-gui-button (button &optional pos buffer)
|
|
92 "Insert GUI button BUTTON at POS in BUFFER."
|
|
93 (check-argument-type 'gui-button-p button)
|
|
94 (let ((annotation
|
|
95 (make-annotation (make-glyph (car (aref button 1)))
|
|
96 pos 'text buffer nil
|
|
97 (make-glyph (cadr (aref button 1)))))
|
|
98 (action (aref button 2)))
|
|
99 (and action
|
|
100 (progn
|
|
101 (set-annotation-action annotation action)
|
|
102 (set-annotation-data annotation (aref button 3))))))
|