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