Mercurial > emacs
annotate lisp/x-menu.el @ 1717:aa7d6d57504b
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Thu, 24 Dec 1992 06:17:18 +0000 |
| parents | 2cdce064065f |
| children | 83fea4c633e8 |
| rev | line source |
|---|---|
|
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
1 ;;; x-menu.el --- menu support for X |
|
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
2 |
| 35 | 3 ;; Copyright (C) 1986 Free Software Foundation, Inc. |
| 4 | |
| 5 ;; This file is part of GNU Emacs. | |
| 6 | |
| 7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 8 ;; it under the terms of the GNU General Public License as published by | |
| 806 | 9 ;; the Free Software Foundation; either version 2, or (at your option) |
| 35 | 10 ;; any later version. |
| 11 | |
| 12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 ;; GNU General Public License for more details. | |
| 16 | |
| 17 ;; You should have received a copy of the GNU General Public License | |
| 18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 20 | |
|
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
656
diff
changeset
|
21 ;;; Code: |
| 35 | 22 |
| 23 (defmacro caar (conscell) | |
| 24 (list 'car (list 'car conscell))) | |
| 25 | |
| 26 (defmacro cdar (conscell) | |
| 27 (list 'cdr (list 'car conscell))) | |
| 28 | |
| 29 (defun x-menu-mode () | |
| 30 "Major mode for creating permanent menus for use with X. | |
| 31 These menus are implemented entirely in Lisp; popup menus, implemented | |
| 32 with x-popup-menu, are implemented using XMenu primitives." | |
| 33 (make-local-variable 'x-menu-items-per-line) | |
| 34 (make-local-variable 'x-menu-item-width) | |
| 35 (make-local-variable 'x-menu-items-alist) | |
| 36 (make-local-variable 'x-process-mouse-hook) | |
| 37 (make-local-variable 'x-menu-assoc-buffer) | |
| 38 (setq buffer-read-only t) | |
| 39 (setq truncate-lines t) | |
| 40 (setq x-process-mouse-hook 'x-menu-pick-entry) | |
| 41 (setq mode-line-buffer-identification '("MENU: %32b"))) | |
| 42 | |
| 43 (defvar x-menu-max-width 0) | |
| 44 (defvar x-menu-items-per-line 0) | |
| 45 (defvar x-menu-item-width 0) | |
| 46 (defvar x-menu-items-alist nil) | |
| 47 (defvar x-menu-assoc-buffer nil) | |
| 48 | |
| 49 (defvar x-menu-item-spacing 1 | |
| 50 "*Minimum horizontal spacing between objects in a permanent X menu.") | |
| 51 | |
| 52 (defun x-menu-create-menu (name) | |
| 53 "Create a permanent X menu. Returns an item which should be used as a | |
| 54 menu object whenever referring to the menu." | |
| 55 (let ((old (current-buffer)) | |
| 56 (buf (get-buffer-create name))) | |
| 57 (set-buffer buf) | |
| 58 (x-menu-mode) | |
| 59 (setq x-menu-assoc-buffer old) | |
| 60 (set-buffer old) | |
| 61 buf)) | |
| 62 | |
| 63 (defun x-menu-change-associated-buffer (menu buffer) | |
| 64 "Change associated buffer of MENU to BUFFER. BUFFER should be a buffer | |
| 65 object." | |
| 66 (let ((old (current-buffer))) | |
| 67 (set-buffer menu) | |
| 68 (setq x-menu-assoc-buffer buffer) | |
| 69 (set-buffer old))) | |
| 70 | |
| 71 (defun x-menu-add-item (menu item binding) | |
| 72 "Adds to MENU an item with name ITEM, associated with BINDING. | |
| 73 Following a sequence of calls to x-menu-add-item, a call to x-menu-compute | |
| 74 should be performed before the menu will be made available to the user. | |
| 75 | |
| 76 BINDING should be a function of one argument, which is the numerical | |
| 77 button/key code as defined in x-menu.el." | |
| 78 (let ((old (current-buffer)) | |
| 79 elt) | |
| 80 (set-buffer menu) | |
| 81 (if (setq elt (assoc item x-menu-items-alist)) | |
| 82 (rplacd elt binding) | |
| 83 (setq x-menu-items-alist (append x-menu-items-alist | |
| 84 (list (cons item binding))))) | |
| 85 (set-buffer old) | |
| 86 item)) | |
| 87 | |
| 88 (defun x-menu-delete-item (menu item) | |
| 89 "Deletes from MENU the item named ITEM. x-menu-compute should be called | |
| 90 before the menu is made available to the user." | |
| 91 (let ((old (current-buffer)) | |
| 92 elt) | |
| 93 (set-buffer menu) | |
| 94 (if (setq elt (assoc item x-menu-items-alist)) | |
| 95 (rplaca elt nil)) | |
| 96 (set-buffer old) | |
| 97 item)) | |
| 98 | |
| 99 (defun x-menu-activate (menu) | |
| 100 "Computes all necessary parameters for MENU. This must be called whenever | |
| 101 a menu is modified before it is made available to the user. | |
| 102 | |
| 103 This also creates the menu itself." | |
| 104 (let ((buf (current-buffer))) | |
| 105 (pop-to-buffer menu) | |
| 106 (let (buffer-read-only) | |
| 806 | 107 (setq x-menu-max-width (1- (frame-width))) |
| 35 | 108 (setq x-menu-item-width 0) |
| 109 (let (items-head | |
| 110 (items-tail x-menu-items-alist)) | |
| 111 (while items-tail | |
| 112 (if (caar items-tail) | |
| 113 (progn (setq items-head (cons (car items-tail) items-head)) | |
| 114 (setq x-menu-item-width | |
| 115 (max x-menu-item-width | |
| 116 (length (caar items-tail)))))) | |
| 117 (setq items-tail (cdr items-tail))) | |
| 118 (setq x-menu-items-alist (reverse items-head))) | |
| 119 (setq x-menu-item-width (+ x-menu-item-spacing x-menu-item-width)) | |
| 120 (setq x-menu-items-per-line | |
| 121 (max 1 (/ x-menu-max-width x-menu-item-width))) | |
| 122 (erase-buffer) | |
| 123 (let ((items-head x-menu-items-alist)) | |
| 124 (while items-head | |
| 125 (let ((items 0)) | |
| 126 (while (and items-head | |
| 127 (<= (setq items (1+ items)) x-menu-items-per-line)) | |
| 128 (insert (format (concat "%" | |
| 129 (int-to-string x-menu-item-width) "s") | |
| 130 (caar items-head))) | |
| 131 (setq items-head (cdr items-head)))) | |
| 132 (insert ?\n))) | |
| 133 (shrink-window (max 0 | |
| 134 (- (window-height) | |
| 135 (1+ (count-lines (point-min) (point-max)))))) | |
| 136 (goto-char (point-min))) | |
| 137 (pop-to-buffer buf))) | |
| 138 | |
| 139 (defun x-menu-pick-entry (position event) | |
| 140 "Internal function for dispatching on mouse/menu events" | |
| 141 (let* ((x (min (1- x-menu-items-per-line) | |
| 142 (/ (current-column) x-menu-item-width))) | |
| 143 (y (- (count-lines (point-min) (point)) | |
| 144 (if (zerop (current-column)) 0 1))) | |
| 145 (item (+ x (* y x-menu-items-per-line))) | |
| 146 (litem (cdr (nth item x-menu-items-alist)))) | |
| 147 (and litem (funcall litem event))) | |
| 148 (pop-to-buffer x-menu-assoc-buffer)) | |
|
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
149 |
|
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
150 ;;; x-menu.el ends here |
