~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to src/Edit/Interface/edit_mouse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
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
******************************************************************************/
 
12
 
 
13
#include "edit_interface.hpp"
 
14
#include "tm_buffer.hpp"
 
15
#include "timer.hpp"
 
16
 
 
17
/******************************************************************************
 
18
* dispatching
 
19
******************************************************************************/
 
20
 
 
21
void
 
22
edit_interface_rep::mouse_any (string type, SI x, SI y, time_t t) {
 
23
  last_x= x; last_y= y;
 
24
  buf->mark_undo_block ();
 
25
 
 
26
  if ((type != "move") && (type != "enter") && (type != "leave"))
 
27
    set_input_normal ();
 
28
  if ((popup_win != NULL) && (type != "leave")) {
 
29
    popup_win->map ();
 
30
    delete popup_win;
 
31
    popup_win= NULL;
 
32
    this << emit_mouse_grab (false);
 
33
  }
 
34
 
 
35
  if (inside_graphics () && mouse_graphics (type, x, y, t)) return;
 
36
 
 
37
  if (type == "press-left") mouse_click (x, y);
 
38
  if (dragging && (type == "move")) {
 
39
    if (attached () && win->check_event (DRAG_EVENT)) return;
 
40
    mouse_drag (x, y);
 
41
  }
 
42
  if (type == "release-left") {
 
43
    dragging= false;
 
44
    this << emit_mouse_grab (false);
 
45
    if ((t >= last_click) && ((t - last_click) <= 250)) {
 
46
      last_click= t;
 
47
      if (mouse_extra_click (x, y))
 
48
        last_click= t- 1000;
 
49
    }
 
50
    else {
 
51
      last_click= t;
 
52
      mouse_select (x, y);
 
53
    }
 
54
  }
 
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);
 
59
 
 
60
  if ((type == "press-left") ||
 
61
      (type == "release-left") ||
 
62
      (type == "press-middle") ||
 
63
      (type == "press-right"))
 
64
    notify_change (THE_DECORATIONS);
 
65
}
 
66
 
 
67
/******************************************************************************
 
68
* Routines for the mouse
 
69
******************************************************************************/
 
70
 
 
71
void
 
72
edit_interface_rep::mouse_click (SI x, SI y) {
 
73
  if (eb->action ("click" , x, y, 0) != "") return;
 
74
  start_x   = x;
 
75
  start_y   = y;
 
76
  start_drag= true;
 
77
  dragging  = true;
 
78
  this << emit_mouse_grab (true);
 
79
}
 
80
 
 
81
bool
 
82
edit_interface_rep::mouse_extra_click (SI x, SI y) {
 
83
  go_to (x, y);
 
84
 
 
85
  // temporary hack for clickable footnotes
 
86
  path p= path_up (tp);
 
87
  if (!nil (p)) {
 
88
    if (is_compound (subtree (et, p), "footnote", 1)) {
 
89
      go_to (start (et, p * 0));
 
90
      return true;
 
91
    }
 
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));
 
97
          return true;
 
98
        }
 
99
    path q= search_upwards_compound ("footnote");
 
100
    if ((!nil (q)) && (tp == start (et, q * 0))) {
 
101
      go_to (end (et, q));
 
102
      return true;
 
103
    }
 
104
  }
 
105
  // end temporary hack
 
106
 
 
107
  if (eb->action ("double-click" , x, y, 0) != "") return true;
 
108
  go_to (x, y);
 
109
  path p1, p2;
 
110
  get_selection (p1, p2);
 
111
  if ((p1==p2) || path_less (tp, p1) || path_less (p2, tp)) select (tp, tp);
 
112
  select_enlarge ();
 
113
  return false;
 
114
}
 
115
 
 
116
void
 
117
edit_interface_rep::mouse_drag (SI x, SI y) {
 
118
  if (eb->action ("drag" , x, y, 0) != "") return;
 
119
  end_x  = x;
 
120
  end_y  = y;
 
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)) {
 
125
    path temp= p1;
 
126
    p1= p2;
 
127
    p2= temp;
 
128
  }
 
129
  set_selection (p1, p2);
 
130
  if ((p1 == p2) && start_drag) return;
 
131
  start_drag= false;
 
132
  notify_change (THE_SELECTION);
 
133
}
 
134
 
 
135
void
 
136
edit_interface_rep::mouse_select (SI x, SI y) {
 
137
  if (eb->action ("select" , x, y, 0) != "") return;
 
138
  go_to (x, y);
 
139
  if (selection_active_any ())
 
140
    selection_set ("primary", selection_get (), true);
 
141
}
 
142
 
 
143
void
 
144
edit_interface_rep::mouse_paste (SI x, SI y) { (void) x; (void) y;
 
145
  if (eb->action ("paste" , x, y, 0) != "") return;
 
146
  selection_copy ();
 
147
  selection_paste ();
 
148
}
 
149
 
 
150
void
 
151
edit_interface_rep::mouse_adjust (SI x, SI y) {
 
152
  if (eb->action ("adjust" , x, y, 0) != "") return;
 
153
  x /= sfactor; y /= sfactor;
 
154
  abs_round (x, y);
 
155
  if (popup_win == NULL) {
 
156
    SI wx, wy;
 
157
    win->get_position (wx, wy);
 
158
    widget wid;
 
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);
 
162
    popup_win->map ();
 
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);
 
167
  }
 
168
}
 
169
 
 
170
void
 
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;
 
174
  SI dy= 100*PIXEL;
 
175
  if (!up) dy= -dy;
 
176
  SERVER (scroll_where (x, y));
 
177
  y += dy;
 
178
  SERVER (scroll_to (x, y));
 
179
}
 
180
 
 
181
/******************************************************************************
 
182
* getting the cursor (both for text and graphics)
 
183
******************************************************************************/
 
184
 
 
185
cursor
 
186
edit_interface_rep::get_cursor () {
 
187
  if (inside_graphics ()) {
 
188
    frame f= find_frame ();
 
189
    if (!nil (f)) {
 
190
      point p= f [point (last_x, last_y)];
 
191
      p= f (adjust (p));
 
192
      SI x= (SI) p[0];
 
193
      SI y= (SI) p[1];
 
194
      return cursor (x, y, 0, -5*pixel, 5*pixel, 1.0);
 
195
    }
 
196
  }
 
197
  return copy (the_cursor ());
 
198
}
 
199
 
 
200
/******************************************************************************
 
201
* event handlers
 
202
******************************************************************************/
 
203
 
 
204
void
 
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);
 
210
}