diff options
author | Po Lu <luangruo@yahoo.com> | 2022-05-27 16:33:12 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-05-27 16:33:12 +0800 |
commit | 27de58af8b3a7617868408886f94bb12f7785800 (patch) | |
tree | 84643a488ba979e4bb368edfcdf3e37a72d6f4ad /src/nsterm.m | |
parent | 34e4eba07ed491d3c01902023df6f15c968117cf (diff) | |
download | emacs-27de58af8b3a7617868408886f94bb12f7785800.tar.gz |
Implement some drag and drop functions on NS
* lisp/term/ns-win.el (ns-selection-exists-p):
(gui-backend-set-selection):
(x-begin-drag): New functions and selection types.
* src/nsfns.m (Fns_get_resource):
(Fns_set_resource):
(Fx_server_max_request_size): Fix coding style.
* src/nsselect.m (ns_decode_data_to_pasteboard):
(ns_lisp_to_pasteboard):
(ns_dnd_action_to_operation):
(ns_dnd_action_from_operation):
(Fns_begin_drag): New functions.
(syms_of_nsselect): New subrs.
* src/nsterm.h (EmacsWindow): New fields and messages.
(NSPasteboardNameGeneral): New define.
* src/nsterm.m ([EmacsView mouseDown:]): Store last mouse event.
([EmacsWindow initWithEmacsFrame:fullscreen:screen:]): Clear that event.
([EmacsWindow dealloc]): Free last mouse event.
Diffstat (limited to 'src/nsterm.m')
-rw-r--r-- | src/nsterm.m | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/nsterm.m b/src/nsterm.m index d7e62a70c49..79e30d6ff91 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -7059,6 +7059,7 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) { struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); NSPoint p = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + EmacsWindow *window; NSTRACE ("[EmacsView mouseDown:]"); @@ -7070,6 +7071,9 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) button clicks. */ emacsframe->mouse_moved = 0; + window = (EmacsWindow *) [self window]; + [window setLastDragEvent: theEvent]; + if ([theEvent type] == NSEventTypeScrollWheel) { #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 @@ -8859,6 +8863,8 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskClosable); + last_drag_event = nil; + width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, f->text_cols); height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, f->text_lines); @@ -8974,6 +8980,11 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) /* We need to release the toolbar ourselves. */ [[self toolbar] release]; + + /* Also the last button press event . */ + if (last_drag_event) + [last_drag_event release]; + [super dealloc]; } @@ -9498,6 +9509,55 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c) return YES; } +- (void) setLastDragEvent: (NSEvent *) event +{ + if (last_drag_event) + [last_drag_event release]; + last_drag_event = [event copy]; +} + +- (NSDragOperation) draggingSourceOperationMaskForLocal: (BOOL) is_local +{ + return drag_op; +} + +- (void) draggedImage: (NSImage *) image + endedAt: (NSPoint) screen_point + operation: (NSDragOperation) operation +{ + selected_op = operation; +} + +- (NSDragOperation) beginDrag: (NSDragOperation) op + forPasteboard: (NSPasteboard *) pasteboard +{ + NSImage *image; + + drag_op = op; + selected_op = NSDragOperationNone; + image = [[NSImage alloc] initWithSize: NSMakeSize (1.0, 1.0)]; + + /* Now draw transparency onto the image. */ + [image lockFocus]; + [[NSColor colorWithUnsignedLong: 0] set]; + NSRectFillUsingOperation (NSMakeRect (0, 0, 1, 1), + NSCompositingOperationCopy); + [image unlockFocus]; + + if (last_drag_event) + [self dragImage: image + at: NSMakePoint (0, 0) + offset: NSMakeSize (0, 0) + event: last_drag_event + pasteboard: pasteboard + source: self + slideBack: NO]; + + [image release]; + + return selected_op; +} + @end /* EmacsWindow */ |