mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-06 07:31:13 -08:00
Implement `follow-tooltip' on NS as well
* lisp/term/ns-win.el (x-begin-drag): Pass `follow-tooltip'. * src/nsfns.m (Fx_show_tip): Record last dx and dy. (syms_of_nsfns): New staticpros. * src/nsmenu.m ([EmacsTooltip moveTo:]): New method. * src/nsselect.m (Fns_begin_drag): New parameter `follow-tooltip'. * src/nsterm.h (@interface EmacsWindow): (EmacsTooltip): Update prototypes. * src/nsterm.m ([EmacsWindow draggedImage:movedTo:]): Move any tooltip to the right location. ([EmacsWindow beginDrag:forPasteboard...]): New parameter `followTooltip'.
This commit is contained in:
parent
0ba43e15d9
commit
e7ac2ac4e0
6 changed files with 124 additions and 38 deletions
|
|
@ -896,7 +896,7 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
|
|||
(ns-get-selection selection-symbol target-type))
|
||||
|
||||
(defun x-begin-drag (targets &optional action frame return-frame
|
||||
allow-current-frame _follow-tooltip)
|
||||
allow-current-frame follow-tooltip)
|
||||
"SKIP: real doc in xfns.c."
|
||||
(unless ns-dnd-selection-value
|
||||
(error "No local value for XdndSelection"))
|
||||
|
|
@ -921,7 +921,8 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
|
|||
(expand-file-name
|
||||
ns-dnd-selection-value))))
|
||||
pasteboard))))
|
||||
(ns-begin-drag frame pasteboard action return-frame allow-current-frame)))
|
||||
(ns-begin-drag frame pasteboard action return-frame
|
||||
allow-current-frame follow-tooltip)))
|
||||
|
||||
(defun ns-handle-drag-motion (frame x y)
|
||||
"Handle mouse movement on FRAME at X and Y during drag-and-drop.
|
||||
|
|
|
|||
49
src/nsfns.m
49
src/nsfns.m
|
|
@ -63,6 +63,9 @@ static EmacsTooltip *ns_tooltip = nil;
|
|||
/* The frame of the currently visible tooltip, or nil if none. */
|
||||
static Lisp_Object tip_frame;
|
||||
|
||||
/* The X and Y deltas of the last call to `x-show-tip'. */
|
||||
static Lisp_Object tip_dx, tip_dy;
|
||||
|
||||
/* The window-system window corresponding to the frame of the
|
||||
currently visible tooltip. */
|
||||
static NSWindow *tip_window;
|
||||
|
|
@ -3243,6 +3246,9 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
|
|||
else
|
||||
CHECK_FIXNUM (dy);
|
||||
|
||||
tip_dx = dx;
|
||||
tip_dy = dy;
|
||||
|
||||
if (use_system_tooltips)
|
||||
{
|
||||
NSSize size;
|
||||
|
|
@ -3794,6 +3800,45 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
|
|||
}
|
||||
@end
|
||||
|
||||
void
|
||||
ns_move_tooltip_to_mouse_location (NSPoint screen_point)
|
||||
{
|
||||
int root_x, root_y;
|
||||
NSSize size;
|
||||
NSWindow *window;
|
||||
struct frame *tip_f;
|
||||
|
||||
if (!FIXNUMP (tip_dx) || !FIXNUMP (tip_dy))
|
||||
return;
|
||||
|
||||
if (ns_tooltip)
|
||||
size = [ns_tooltip frame].size;
|
||||
else if (!FRAMEP (tip_frame)
|
||||
|| !FRAME_LIVE_P (XFRAME (tip_frame)))
|
||||
return;
|
||||
else
|
||||
{
|
||||
tip_f = XFRAME (tip_frame);
|
||||
window = [FRAME_NS_VIEW (tip_f) window];
|
||||
size = [window frame].size;
|
||||
}
|
||||
|
||||
root_x = screen_point.x;
|
||||
root_y = screen_point.y;
|
||||
|
||||
/* We can directly use `compute_tip_xy' here, since it doesn't cons
|
||||
nearly as much as it does on X. */
|
||||
compute_tip_xy (NULL, Qnil, tip_dx, tip_dy, (int) size.width,
|
||||
(int) size.height, &root_x, &root_y);
|
||||
|
||||
if (ns_tooltip)
|
||||
[ns_tooltip moveTo: NSMakePoint (root_x, root_y)];
|
||||
else
|
||||
[window setFrame: NSMakeRect (root_x, root_y,
|
||||
size.width, size.height)
|
||||
display: YES];
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
|
||||
Lisp interface declaration
|
||||
|
|
@ -3902,6 +3947,10 @@ Default is t. */);
|
|||
staticpro (&tip_last_string);
|
||||
tip_last_parms = Qnil;
|
||||
staticpro (&tip_last_parms);
|
||||
tip_dx = Qnil;
|
||||
staticpro (&tip_dx);
|
||||
tip_dy = Qnil;
|
||||
staticpro (&tip_dy);
|
||||
|
||||
#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
|
||||
defsubr (&Ssystem_move_file_to_trash);
|
||||
|
|
|
|||
|
|
@ -1497,6 +1497,15 @@ update_frame_tool_bar (struct frame *f)
|
|||
[timer retain];
|
||||
}
|
||||
|
||||
- (void) moveTo: (NSPoint) screen_point
|
||||
{
|
||||
[win setFrame: NSMakeRect (screen_point.x,
|
||||
screen_point.y,
|
||||
[self frame].size.width,
|
||||
[self frame].size.height)
|
||||
display: YES];
|
||||
}
|
||||
|
||||
- (void) hide
|
||||
{
|
||||
[win close];
|
||||
|
|
|
|||
|
|
@ -703,7 +703,7 @@ ns_dnd_action_from_operation (NSDragOperation operation)
|
|||
}
|
||||
}
|
||||
|
||||
DEFUN ("ns-begin-drag", Fns_begin_drag, Sns_begin_drag, 3, 5, 0,
|
||||
DEFUN ("ns-begin-drag", Fns_begin_drag, Sns_begin_drag, 3, 6, 0,
|
||||
doc: /* Begin a drag-and-drop operation on FRAME.
|
||||
|
||||
FRAME must be a window system frame. PBOARD is an alist of (TYPE
|
||||
|
|
@ -729,9 +729,12 @@ other non-nil value means to do the same, but to wait for the mouse to
|
|||
leave FRAME first.
|
||||
|
||||
If ALLOW-SAME-FRAME is nil, dropping on FRAME will result in the drop
|
||||
being ignored. */)
|
||||
being ignored.
|
||||
|
||||
FOLLOW-TOOLTIP means the same thing it does in `x-begin-drag'. */)
|
||||
(Lisp_Object frame, Lisp_Object pboard, Lisp_Object action,
|
||||
Lisp_Object return_frame, Lisp_Object allow_same_frame)
|
||||
Lisp_Object return_frame, Lisp_Object allow_same_frame,
|
||||
Lisp_Object follow_tooltip)
|
||||
{
|
||||
struct frame *f, *return_to;
|
||||
NSPasteboard *pasteboard;
|
||||
|
|
@ -761,7 +764,8 @@ being ignored. */)
|
|||
forPasteboard: pasteboard
|
||||
withMode: mode
|
||||
returnFrameTo: &return_to
|
||||
prohibitSame: (BOOL) NILP (allow_same_frame)];
|
||||
prohibitSame: (BOOL) NILP (allow_same_frame)
|
||||
followTooltip: (BOOL) !NILP (follow_tooltip)];
|
||||
|
||||
if (return_to)
|
||||
{
|
||||
|
|
|
|||
27
src/nsterm.h
27
src/nsterm.h
|
|
@ -426,6 +426,7 @@ enum ns_return_frame_mode
|
|||
struct frame *dnd_return_frame;
|
||||
enum ns_return_frame_mode dnd_mode;
|
||||
BOOL dnd_allow_same_frame;
|
||||
BOOL dnd_move_tooltip_with_frame;
|
||||
}
|
||||
|
||||
#ifdef NS_IMPL_GNUSTEP
|
||||
|
|
@ -446,7 +447,8 @@ enum ns_return_frame_mode
|
|||
forPasteboard: (NSPasteboard *) pasteboard
|
||||
withMode: (enum ns_return_frame_mode) mode
|
||||
returnFrameTo: (struct frame **) frame_return
|
||||
prohibitSame: (BOOL) prohibit_same_frame;
|
||||
prohibitSame: (BOOL) prohibit_same_frame
|
||||
followTooltip: (BOOL) follow_tooltip;
|
||||
- (BOOL) mustNotDropOn: (NSView *) receiver;
|
||||
@end
|
||||
|
||||
|
|
@ -630,19 +632,21 @@ enum ns_return_frame_mode
|
|||
#else
|
||||
@interface EmacsTooltip : NSObject
|
||||
#endif
|
||||
{
|
||||
NSWindow *win;
|
||||
NSTextField *textField;
|
||||
NSTimer *timer;
|
||||
}
|
||||
{
|
||||
NSWindow *win;
|
||||
NSTextField *textField;
|
||||
NSTimer *timer;
|
||||
}
|
||||
|
||||
- (instancetype) init;
|
||||
- (void) setText: (char *)text;
|
||||
- (void) setBackgroundColor: (NSColor *)col;
|
||||
- (void) setForegroundColor: (NSColor *)col;
|
||||
- (void) showAtX: (int)x Y: (int)y for: (int)seconds;
|
||||
- (void) setText: (char *) text;
|
||||
- (void) setBackgroundColor: (NSColor *) col;
|
||||
- (void) setForegroundColor: (NSColor *) col;
|
||||
- (void) showAtX: (int) x Y: (int) y for: (int) seconds;
|
||||
- (void) hide;
|
||||
- (BOOL) isActive;
|
||||
- (NSRect) frame;
|
||||
- (void) moveTo: (NSPoint) screen_point;
|
||||
@end
|
||||
|
||||
|
||||
|
|
@ -1140,6 +1144,9 @@ extern const char *ns_get_pending_menu_title (void);
|
|||
#endif
|
||||
|
||||
/* Implemented in nsfns, published in nsterm. */
|
||||
#ifdef __OBJC__
|
||||
extern void ns_move_tooltip_to_mouse_location (NSPoint);
|
||||
#endif
|
||||
extern void ns_implicitly_set_name (struct frame *f, Lisp_Object arg,
|
||||
Lisp_Object oldval);
|
||||
extern void ns_set_scroll_bar_default_width (struct frame *f);
|
||||
|
|
|
|||
60
src/nsterm.m
60
src/nsterm.m
|
|
@ -9629,35 +9629,45 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
|
|||
selected_op = operation;
|
||||
}
|
||||
|
||||
#ifdef NS_IMPL_COCOA
|
||||
- (void) draggedImage: (NSImage *) dragged_image
|
||||
movedTo: (NSPoint) screen_point
|
||||
{
|
||||
NSPoint mouse_loc;
|
||||
#ifdef NS_IMPL_COCOA
|
||||
NSInteger window_number;
|
||||
NSWindow *w;
|
||||
|
||||
if (dnd_mode == RETURN_FRAME_NEVER)
|
||||
return;
|
||||
|
||||
window_number = [NSWindow windowNumberAtPoint: [NSEvent mouseLocation]
|
||||
belowWindowWithWindowNumber: 0];
|
||||
w = [NSApp windowWithWindowNumber: window_number];
|
||||
|
||||
if (!w || w != self)
|
||||
dnd_mode = RETURN_FRAME_NOW;
|
||||
|
||||
if (dnd_mode != RETURN_FRAME_NOW
|
||||
|| ![[w delegate] isKindOfClass: [EmacsView class]])
|
||||
return;
|
||||
|
||||
dnd_return_frame = ((EmacsView *) [w delegate])->emacsframe;
|
||||
|
||||
/* FIXME: there must be a better way to leave the event loop. */
|
||||
[NSException raise: @""
|
||||
format: @"Must return DND frame"];
|
||||
}
|
||||
#endif
|
||||
|
||||
mouse_loc = [NSEvent mouseLocation];
|
||||
|
||||
#ifdef NS_IMPL_COCOA
|
||||
if (dnd_mode != RETURN_FRAME_NEVER)
|
||||
{
|
||||
window_number = [NSWindow windowNumberAtPoint: mouse_loc
|
||||
belowWindowWithWindowNumber: 0];
|
||||
w = [NSApp windowWithWindowNumber: window_number];
|
||||
|
||||
if (!w || w != self)
|
||||
dnd_mode = RETURN_FRAME_NOW;
|
||||
|
||||
if (dnd_mode != RETURN_FRAME_NOW
|
||||
|| ![[w delegate] isKindOfClass: [EmacsView class]])
|
||||
goto out;
|
||||
|
||||
dnd_return_frame = ((EmacsView *) [w delegate])->emacsframe;
|
||||
|
||||
/* FIXME: there must be a better way to leave the event loop. */
|
||||
[NSException raise: @""
|
||||
format: @"Must return DND frame"];
|
||||
}
|
||||
#endif
|
||||
|
||||
out:
|
||||
|
||||
if (dnd_move_tooltip_with_frame)
|
||||
ns_move_tooltip_to_mouse_location (mouse_loc);
|
||||
}
|
||||
|
||||
- (BOOL) mustNotDropOn: (NSView *) receiver
|
||||
{
|
||||
return ([receiver window] == self
|
||||
|
|
@ -9669,6 +9679,7 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
|
|||
withMode: (enum ns_return_frame_mode) mode
|
||||
returnFrameTo: (struct frame **) frame_return
|
||||
prohibitSame: (BOOL) prohibit_same_frame
|
||||
followTooltip: (BOOL) follow_tooltip
|
||||
{
|
||||
NSImage *image;
|
||||
#ifdef NS_IMPL_COCOA
|
||||
|
|
@ -9681,6 +9692,7 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
|
|||
dnd_mode = mode;
|
||||
dnd_return_frame = NULL;
|
||||
dnd_allow_same_frame = !prohibit_same_frame;
|
||||
dnd_move_tooltip_with_frame = follow_tooltip;
|
||||
|
||||
/* Now draw transparency onto the image. */
|
||||
[image lockFocus];
|
||||
|
|
@ -9728,6 +9740,10 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
|
|||
#endif
|
||||
unblock_input ();
|
||||
|
||||
/* The drop happened, so delete the tooltip. */
|
||||
if (follow_tooltip)
|
||||
Fx_hide_tip ();
|
||||
|
||||
/* Assume all buttons have been released since the drag-and-drop
|
||||
operation is now over. */
|
||||
if (!dnd_return_frame)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue