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