diff options
| author | Kim F. Storm | 2005-10-11 22:35:40 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2005-10-11 22:35:40 +0000 |
| commit | e2570d37b26c728ac4b5d90c7f6e362b880ba243 (patch) | |
| tree | 15504ed813ff11b4ab3f88c8899b5bc314995435 /src | |
| parent | d7f18f68ff720399e4a8a48ba27b218f93992203 (diff) | |
| download | emacs-e2570d37b26c728ac4b5d90c7f6e362b880ba243.tar.gz emacs-e2570d37b26c728ac4b5d90c7f6e362b880ba243.zip | |
(note_mouse_movement): Add call to remember_mouse_glyph.
(glyph_rect, remember_mouse_glyph): Remove mac specific versions.
(XTmouse_position): Adapt to use generic remember_mouse_glyph
instead of pixel_to_glyph_coords.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macterm.c | 173 |
1 files changed, 41 insertions, 132 deletions
diff --git a/src/macterm.c b/src/macterm.c index 2142698bbf4..e18f3ee48a0 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -4190,6 +4190,8 @@ note_mouse_movement (frame, pos) | |||
| 4190 | frame->mouse_moved = 1; | 4190 | frame->mouse_moved = 1; |
| 4191 | last_mouse_scroll_bar = Qnil; | 4191 | last_mouse_scroll_bar = Qnil; |
| 4192 | note_mouse_highlight (frame, pos->h, pos->v); | 4192 | note_mouse_highlight (frame, pos->h, pos->v); |
| 4193 | /* Remember which glyph we're now on. */ | ||
| 4194 | remember_mouse_glyph (frame, pos->h, pos->v, &last_mouse_glyph); | ||
| 4193 | } | 4195 | } |
| 4194 | } | 4196 | } |
| 4195 | 4197 | ||
| @@ -4198,9 +4200,6 @@ note_mouse_movement (frame, pos) | |||
| 4198 | Mouse Face | 4200 | Mouse Face |
| 4199 | ************************************************************************/ | 4201 | ************************************************************************/ |
| 4200 | 4202 | ||
| 4201 | static int glyph_rect P_ ((struct frame *f, int, int, Rect *)); | ||
| 4202 | |||
| 4203 | |||
| 4204 | /* MAC TODO: This should be called from somewhere (or removed) ++KFS */ | 4203 | /* MAC TODO: This should be called from somewhere (or removed) ++KFS */ |
| 4205 | 4204 | ||
| 4206 | static void | 4205 | static void |
| @@ -4214,110 +4213,6 @@ redo_mouse_highlight () | |||
| 4214 | } | 4213 | } |
| 4215 | 4214 | ||
| 4216 | 4215 | ||
| 4217 | /* Try to determine frame pixel position and size of the glyph under | ||
| 4218 | frame pixel coordinates X/Y on frame F . Return the position and | ||
| 4219 | size in *RECT. Value is non-zero if we could compute these | ||
| 4220 | values. */ | ||
| 4221 | |||
| 4222 | static int | ||
| 4223 | glyph_rect (f, x, y, rect) | ||
| 4224 | struct frame *f; | ||
| 4225 | int x, y; | ||
| 4226 | Rect *rect; | ||
| 4227 | { | ||
| 4228 | Lisp_Object window; | ||
| 4229 | |||
| 4230 | window = window_from_coordinates (f, x, y, 0, &x, &y, 0); | ||
| 4231 | |||
| 4232 | if (!NILP (window)) | ||
| 4233 | { | ||
| 4234 | struct window *w = XWINDOW (window); | ||
| 4235 | struct glyph_row *r = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | ||
| 4236 | struct glyph_row *end = r + w->current_matrix->nrows - 1; | ||
| 4237 | |||
| 4238 | for (; r < end && r->enabled_p; ++r) | ||
| 4239 | if (r->y <= y && r->y + r->height > y) | ||
| 4240 | { | ||
| 4241 | /* Found the row at y. */ | ||
| 4242 | struct glyph *g = r->glyphs[TEXT_AREA]; | ||
| 4243 | struct glyph *end = g + r->used[TEXT_AREA]; | ||
| 4244 | int gx; | ||
| 4245 | |||
| 4246 | rect->top = WINDOW_TO_FRAME_PIXEL_Y (w, r->y); | ||
| 4247 | rect->bottom = rect->top + r->height; | ||
| 4248 | |||
| 4249 | if (x < r->x) | ||
| 4250 | { | ||
| 4251 | /* x is to the left of the first glyph in the row. */ | ||
| 4252 | /* Shouldn't this be a pixel value? | ||
| 4253 | WINDOW_LEFT_EDGE_X (w) seems to be the right value. | ||
| 4254 | ++KFS */ | ||
| 4255 | rect->left = WINDOW_LEFT_EDGE_COL (w); | ||
| 4256 | rect->right = WINDOW_TO_FRAME_PIXEL_X (w, r->x); | ||
| 4257 | return 1; | ||
| 4258 | } | ||
| 4259 | |||
| 4260 | for (gx = r->x; g < end; gx += g->pixel_width, ++g) | ||
| 4261 | if (gx <= x && gx + g->pixel_width > x) | ||
| 4262 | { | ||
| 4263 | /* x is on a glyph. */ | ||
| 4264 | rect->left = WINDOW_TO_FRAME_PIXEL_X (w, gx); | ||
| 4265 | rect->right = rect->left + g->pixel_width; | ||
| 4266 | return 1; | ||
| 4267 | } | ||
| 4268 | |||
| 4269 | /* x is to the right of the last glyph in the row. */ | ||
| 4270 | rect->left = WINDOW_TO_FRAME_PIXEL_X (w, gx); | ||
| 4271 | /* Shouldn't this be a pixel value? | ||
| 4272 | WINDOW_RIGHT_EDGE_X (w) seems to be the right value. | ||
| 4273 | ++KFS */ | ||
| 4274 | rect->right = WINDOW_RIGHT_EDGE_COL (w); | ||
| 4275 | return 1; | ||
| 4276 | } | ||
| 4277 | } | ||
| 4278 | |||
| 4279 | /* The y is not on any row. */ | ||
| 4280 | return 0; | ||
| 4281 | } | ||
| 4282 | |||
| 4283 | /* MAC TODO: This should be called from somewhere (or removed) ++KFS */ | ||
| 4284 | |||
| 4285 | /* Record the position of the mouse in last_mouse_glyph. */ | ||
| 4286 | static void | ||
| 4287 | remember_mouse_glyph (f1, gx, gy) | ||
| 4288 | struct frame * f1; | ||
| 4289 | int gx, gy; | ||
| 4290 | { | ||
| 4291 | if (!glyph_rect (f1, gx, gy, &last_mouse_glyph)) | ||
| 4292 | { | ||
| 4293 | int width = FRAME_SMALLEST_CHAR_WIDTH (f1); | ||
| 4294 | int height = FRAME_SMALLEST_FONT_HEIGHT (f1); | ||
| 4295 | |||
| 4296 | /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to | ||
| 4297 | round down even for negative values. */ | ||
| 4298 | if (gx < 0) | ||
| 4299 | gx -= width - 1; | ||
| 4300 | if (gy < 0) | ||
| 4301 | gy -= height - 1; | ||
| 4302 | #if 0 | ||
| 4303 | /* This was the original code from XTmouse_position, but it seems | ||
| 4304 | to give the position of the glyph diagonally next to the one | ||
| 4305 | the mouse is over. */ | ||
| 4306 | gx = (gx + width - 1) / width * width; | ||
| 4307 | gy = (gy + height - 1) / height * height; | ||
| 4308 | #else | ||
| 4309 | gx = gx / width * width; | ||
| 4310 | gy = gy / height * height; | ||
| 4311 | #endif | ||
| 4312 | |||
| 4313 | last_mouse_glyph.left = gx; | ||
| 4314 | last_mouse_glyph.top = gy; | ||
| 4315 | last_mouse_glyph.right = gx + width; | ||
| 4316 | last_mouse_glyph.bottom = gy + height; | ||
| 4317 | } | ||
| 4318 | } | ||
| 4319 | |||
| 4320 | |||
| 4321 | static struct frame * | 4216 | static struct frame * |
| 4322 | mac_focus_frame (dpyinfo) | 4217 | mac_focus_frame (dpyinfo) |
| 4323 | struct mac_display_info *dpyinfo; | 4218 | struct mac_display_info *dpyinfo; |
| @@ -4333,18 +4228,18 @@ mac_focus_frame (dpyinfo) | |||
| 4333 | 4228 | ||
| 4334 | 4229 | ||
| 4335 | /* Return the current position of the mouse. | 4230 | /* Return the current position of the mouse. |
| 4336 | *fp should be a frame which indicates which display to ask about. | 4231 | *FP should be a frame which indicates which display to ask about. |
| 4337 | 4232 | ||
| 4338 | If the mouse movement started in a scroll bar, set *fp, *bar_window, | 4233 | If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW, |
| 4339 | and *part to the frame, window, and scroll bar part that the mouse | 4234 | and *PART to the frame, window, and scroll bar part that the mouse |
| 4340 | is over. Set *x and *y to the portion and whole of the mouse's | 4235 | is over. Set *X and *Y to the portion and whole of the mouse's |
| 4341 | position on the scroll bar. | 4236 | position on the scroll bar. |
| 4342 | 4237 | ||
| 4343 | If the mouse movement started elsewhere, set *fp to the frame the | 4238 | If the mouse movement started elsewhere, set *FP to the frame the |
| 4344 | mouse is on, *bar_window to nil, and *x and *y to the character cell | 4239 | mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell |
| 4345 | the mouse is over. | 4240 | the mouse is over. |
| 4346 | 4241 | ||
| 4347 | Set *time to the server time-stamp for the time at which the mouse | 4242 | Set *TIME to the server time-stamp for the time at which the mouse |
| 4348 | was at this position. | 4243 | was at this position. |
| 4349 | 4244 | ||
| 4350 | Don't store anything if we don't have a valid set of values to report. | 4245 | Don't store anything if we don't have a valid set of values to report. |
| @@ -4361,11 +4256,7 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time) | |||
| 4361 | Lisp_Object *x, *y; | 4256 | Lisp_Object *x, *y; |
| 4362 | unsigned long *time; | 4257 | unsigned long *time; |
| 4363 | { | 4258 | { |
| 4364 | Point mouse_pos; | 4259 | FRAME_PTR f1; |
| 4365 | int ignore1, ignore2; | ||
| 4366 | struct frame *f = mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp)); | ||
| 4367 | WindowPtr wp = FRAME_MAC_WINDOW (f); | ||
| 4368 | Lisp_Object frame, tail; | ||
| 4369 | 4260 | ||
| 4370 | BLOCK_INPUT; | 4261 | BLOCK_INPUT; |
| 4371 | 4262 | ||
| @@ -4373,25 +4264,43 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time) | |||
| 4373 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); | 4264 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); |
| 4374 | else | 4265 | else |
| 4375 | { | 4266 | { |
| 4267 | Lisp_Object frame, tail; | ||
| 4268 | |||
| 4376 | /* Clear the mouse-moved flag for every frame on this display. */ | 4269 | /* Clear the mouse-moved flag for every frame on this display. */ |
| 4377 | FOR_EACH_FRAME (tail, frame) | 4270 | FOR_EACH_FRAME (tail, frame) |
| 4378 | XFRAME (frame)->mouse_moved = 0; | 4271 | XFRAME (frame)->mouse_moved = 0; |
| 4379 | 4272 | ||
| 4380 | last_mouse_scroll_bar = Qnil; | 4273 | last_mouse_scroll_bar = Qnil; |
| 4381 | 4274 | ||
| 4382 | SetPortWindowPort (wp); | 4275 | if (FRAME_MAC_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame |
| 4383 | 4276 | && FRAME_LIVE_P (last_mouse_frame)) | |
| 4384 | GetMouse (&mouse_pos); | 4277 | f1 = last_mouse_frame; |
| 4385 | 4278 | else | |
| 4386 | pixel_to_glyph_coords (f, mouse_pos.h, mouse_pos.v, &ignore1, &ignore2, | 4279 | f1 = mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp)); |
| 4387 | &last_mouse_glyph, insist); | ||
| 4388 | 4280 | ||
| 4389 | *bar_window = Qnil; | 4281 | if (f1) |
| 4390 | *part = scroll_bar_handle; | 4282 | { |
| 4391 | *fp = f; | 4283 | /* Ok, we found a frame. Store all the values. |
| 4392 | XSETINT (*x, mouse_pos.h); | 4284 | last_mouse_glyph is a rectangle used to reduce the |
| 4393 | XSETINT (*y, mouse_pos.v); | 4285 | generation of mouse events. To not miss any motion |
| 4394 | *time = last_mouse_movement_time; | 4286 | events, we must divide the frame into rectangles of the |
| 4287 | size of the smallest character that could be displayed | ||
| 4288 | on it, i.e. into the same rectangles that matrices on | ||
| 4289 | the frame are divided into. */ | ||
| 4290 | Point mouse_pos; | ||
| 4291 | |||
| 4292 | SetPortWindowPort (FRAME_MAC_WINDOW (f1)); | ||
| 4293 | GetMouse (&mouse_pos); | ||
| 4294 | remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, | ||
| 4295 | &last_mouse_glyph); | ||
| 4296 | |||
| 4297 | *bar_window = Qnil; | ||
| 4298 | *part = 0; | ||
| 4299 | *fp = f1; | ||
| 4300 | XSETINT (*x, mouse_pos.h); | ||
| 4301 | XSETINT (*y, mouse_pos.v); | ||
| 4302 | *time = last_mouse_movement_time; | ||
| 4303 | } | ||
| 4395 | } | 4304 | } |
| 4396 | 4305 | ||
| 4397 | UNBLOCK_INPUT; | 4306 | UNBLOCK_INPUT; |