2
/******************************************************************************
3
* MODULE : edit_mouse.cpp
4
* DESCRIPTION: Mouse handling
5
* COPYRIGHT : (C) 1999 Joris van der Hoeven
6
*******************************************************************************
7
* This software falls under the GNU general public license and comes WITHOUT
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11
******************************************************************************/
13
#include "edit_interface.hpp"
14
#include "tm_buffer.hpp"
17
/******************************************************************************
19
******************************************************************************/
22
edit_interface_rep::mouse_any (string type, SI x, SI y, time_t t) {
24
buf->mark_undo_block ();
26
if ((type != "move") && (type != "enter") && (type != "leave"))
28
if ((popup_win != NULL) && (type != "leave")) {
32
this << emit_mouse_grab (false);
35
if (inside_graphics () && mouse_graphics (type, x, y, t)) return;
37
if (type == "press-left") mouse_click (x, y);
38
if (dragging && (type == "move")) {
39
if (attached () && win->check_event (DRAG_EVENT)) return;
42
if (type == "release-left") {
44
this << emit_mouse_grab (false);
45
if ((t >= last_click) && ((t - last_click) <= 250)) {
47
if (mouse_extra_click (x, y))
55
if (type == "press-middle") mouse_paste (x, y);
56
if (type == "press-right") mouse_adjust (x, y);
57
if (type == "press-up") mouse_scroll (x, y, true);
58
if (type == "press-down") mouse_scroll (x, y, false);
60
if ((type == "press-left") ||
61
(type == "release-left") ||
62
(type == "press-middle") ||
63
(type == "press-right"))
64
notify_change (THE_DECORATIONS);
67
/******************************************************************************
68
* Routines for the mouse
69
******************************************************************************/
72
edit_interface_rep::mouse_click (SI x, SI y) {
73
if (eb->action ("click" , x, y, 0) != "") return;
78
this << emit_mouse_grab (true);
82
edit_interface_rep::mouse_extra_click (SI x, SI y) {
85
// temporary hack for clickable footnotes
88
if (is_compound (subtree (et, p), "footnote", 1)) {
89
go_to (start (et, p * 0));
92
tree st= subtree (et, path_up (p));
93
if (is_concat (st) && ((last_item (p) + 1) < N(st)))
94
if (last_item (tp) == right_index (st [last_item (p)]))
95
if (is_compound (subtree (et, path_inc (p)), "footnote", 1)) {
96
go_to (start (et, path_inc (p) * 0));
99
path q= search_upwards_compound ("footnote");
100
if ((!nil (q)) && (tp == start (et, q * 0))) {
105
// end temporary hack
107
if (eb->action ("double-click" , x, y, 0) != "") return true;
110
get_selection (p1, p2);
111
if ((p1==p2) || path_less (tp, p1) || path_less (p2, tp)) select (tp, tp);
117
edit_interface_rep::mouse_drag (SI x, SI y) {
118
if (eb->action ("drag" , x, y, 0) != "") return;
121
selection_visible ();
122
path p1= tree_path (start_x, start_y, 0);
123
path p2= tree_path (end_x , end_y , 0);
124
if (path_inf (p2, p1)) {
129
set_selection (p1, p2);
130
if ((p1 == p2) && start_drag) return;
132
notify_change (THE_SELECTION);
136
edit_interface_rep::mouse_select (SI x, SI y) {
137
if (eb->action ("select" , x, y, 0) != "") return;
139
if (selection_active_any ())
140
selection_set ("primary", selection_get (), true);
144
edit_interface_rep::mouse_paste (SI x, SI y) { (void) x; (void) y;
145
if (eb->action ("paste" , x, y, 0) != "") return;
151
edit_interface_rep::mouse_adjust (SI x, SI y) {
152
if (eb->action ("adjust" , x, y, 0) != "") return;
153
x /= sfactor; y /= sfactor;
155
if (popup_win == NULL) {
157
win->get_position (wx, wy);
159
SERVER (menu_widget ("(vertical (link texmacs-popup-menu))", wid));
160
widget popup_wid= popup_widget (wid, center);
161
popup_win= popup_window (popup_wid, wx+ ox+ x, wy+ oy+ y);
163
this << emit_mouse_grab (true);
164
popup_wid << set_integer ("grabbed", 1);
165
// popup_wid << set_integer ("freeze", 1);
166
popup_wid << emit_mouse_grab (true);
171
edit_interface_rep::mouse_scroll (SI x, SI y, bool up) {
172
string action= up? string ("scroll up"): string ("scroll down");
173
if (eb->action (action , x, y, 0) != "") return;
176
SERVER (scroll_where (x, y));
178
SERVER (scroll_to (x, y));
181
/******************************************************************************
182
* getting the cursor (both for text and graphics)
183
******************************************************************************/
186
edit_interface_rep::get_cursor () {
187
if (inside_graphics ()) {
188
frame f= find_frame ();
190
point p= f [point (last_x, last_y)];
194
return cursor (x, y, 0, -5*pixel, 5*pixel, 1.0);
197
return copy (the_cursor ());
200
/******************************************************************************
202
******************************************************************************/
205
edit_interface_rep::handle_mouse (mouse_event ev) {
206
string type= ev->type;
207
SI x = ev->x*sfactor;
208
SI y = ev->y*sfactor;
209
mouse_any (type, x, y, ev->t);