aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2013-12-19 11:25:48 +0100
committerJan Djärv2013-12-19 11:25:48 +0100
commit1269a680862a9bc6cd65e3d26ef05f68c7521632 (patch)
tree1160cb3afcd5b77d2240c276029289ce38feffc1 /src
parent680e6b8c5a28489733df544edb074fd29d0522a0 (diff)
downloademacs-1269a680862a9bc6cd65e3d26ef05f68c7521632.tar.gz
emacs-1269a680862a9bc6cd65e3d26ef05f68c7521632.zip
Make NS port use the normal dnd functions.
* lisp/term/ns-win.el: Require dnd. (global-map): Remove drag items. (ns-insert-text, ns-set-foreground-at-mouse) (ns-set-background-at-mouse): Remove (ns-drag-n-drop, ns-drag-n-drop-other-frame) (ns-drag-n-drop-as-text, ns-drag-n-drop-as-text-other-frame): New functions. * src/nsterm.h (KEY_NS_DRAG_FILE, KEY_NS_DRAG_COLOR, KEY_NS_DRAG_TEXT): Remove. * src/nsterm.m (Qfile, Qurl): New. (EV_MODIFIERS2): New macro. (EV_MODIFIERS): Use EV_MODIFIERS2. (ns_term_init): Remove font and color from DND, does not work on newer OSX, and other ports don't have them. (performDragOperation:): Handle modifiers used during drag. Use DRAG_N_DROP_EVENT instead of NS specific events. Remove global Lisp variables used to communicate with ns-win.el. Remove font and color handling. (syms_of_nsterm): Defsym Qfile and Qurl. Fixes: debbugs:8051
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/nsterm.h3
-rw-r--r--src/nsterm.m127
3 files changed, 69 insertions, 77 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e7f30f25800..283777cbcdf 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12013-12-19 Jan Djärv <jan.h.d@swipnet.se>
2
3 * nsterm.h (KEY_NS_DRAG_FILE, KEY_NS_DRAG_COLOR, KEY_NS_DRAG_TEXT):
4 Remove.
5
6 * nsterm.m (Qfile, Qurl): New.
7 (EV_MODIFIERS2): New macro.
8 (EV_MODIFIERS): Use EV_MODIFIERS2.
9 (ns_term_init): Remove font and color from DND, does not work on
10 newer OSX, and other ports don't have them.
11 (performDragOperation:): Handle modifiers used during drag.
12 Use DRAG_N_DROP_EVENT instead of NS specific events (Bug#8051).
13 Remove global Lisp variables used to communicate with ns-win.el.
14 Remove font and color handling.
15 (syms_of_nsterm): Defsym Qfile and Qurl.
16
12013-12-19 Anders Lindgren <andlind@gmail.com> 172013-12-19 Anders Lindgren <andlind@gmail.com>
2 18
3 * nsterm.m (NSTRACE_SIZE, NSTRACE_RECT): New macros. 19 * nsterm.m (NSTRACE_SIZE, NSTRACE_RECT): New macros.
diff --git a/src/nsterm.h b/src/nsterm.h
index faf8271bcc7..b86122417e5 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -458,9 +458,6 @@ extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
458#define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1) 458#define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
459#define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2) 459#define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
460#define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3) 460#define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
461#define KEY_NS_DRAG_FILE ((1<<28)|(0<<16)|4)
462#define KEY_NS_DRAG_COLOR ((1<<28)|(0<<16)|5)
463#define KEY_NS_DRAG_TEXT ((1<<28)|(0<<16)|6)
464#define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7) 461#define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
465#define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8) 462#define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
466#define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9) 463#define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
diff --git a/src/nsterm.m b/src/nsterm.m
index d7c2f38135a..8047bca1f60 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -80,7 +80,7 @@ int term_trace_num = 0;
80#endif 80#endif
81 81
82/* Detailed tracing. "S" means "size" and "LL" stands for "lower left". */ 82/* Detailed tracing. "S" means "size" and "LL" stands for "lower left". */
83#if 1 83#if 0
84int term_trace_num = 0; 84int term_trace_num = 0;
85#define NSTRACE_SIZE(str,size) fprintf (stderr, \ 85#define NSTRACE_SIZE(str,size) fprintf (stderr, \
86 "%s:%d: [%d] " str \ 86 "%s:%d: [%d] " str \
@@ -196,6 +196,7 @@ extern Lisp_Object Qcursor_color, Qcursor_type, Qns, Qleft;
196 196
197static Lisp_Object QUTF8_STRING; 197static Lisp_Object QUTF8_STRING;
198static Lisp_Object Qcocoa, Qgnustep; 198static Lisp_Object Qcocoa, Qgnustep;
199static Lisp_Object Qfile, Qurl;
199 200
200/* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold, 201/* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
201 the maximum font size to NOT antialias. On GNUstep there is currently 202 the maximum font size to NOT antialias. On GNUstep there is currently
@@ -278,31 +279,32 @@ static CGPoint menu_mouse_point;
278#define NSRightCommandKeyMask (0x000010 | NSCommandKeyMask) 279#define NSRightCommandKeyMask (0x000010 | NSCommandKeyMask)
279#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) 280#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
280#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) 281#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
281#define EV_MODIFIERS(e) \ 282#define EV_MODIFIERS2(flags) \
282 ((([e modifierFlags] & NSHelpKeyMask) ? \ 283 (((flags & NSHelpKeyMask) ? \
283 hyper_modifier : 0) \ 284 hyper_modifier : 0) \
284 | (!EQ (ns_right_alternate_modifier, Qleft) && \ 285 | (!EQ (ns_right_alternate_modifier, Qleft) && \
285 (([e modifierFlags] & NSRightAlternateKeyMask) \ 286 ((flags & NSRightAlternateKeyMask) \
286 == NSRightAlternateKeyMask) ? \ 287 == NSRightAlternateKeyMask) ? \
287 parse_solitary_modifier (ns_right_alternate_modifier) : 0) \ 288 parse_solitary_modifier (ns_right_alternate_modifier) : 0) \
288 | (([e modifierFlags] & NSAlternateKeyMask) ? \ 289 | ((flags & NSAlternateKeyMask) ? \
289 parse_solitary_modifier (ns_alternate_modifier) : 0) \ 290 parse_solitary_modifier (ns_alternate_modifier) : 0) \
290 | (([e modifierFlags] & NSShiftKeyMask) ? \ 291 | ((flags & NSShiftKeyMask) ? \
291 shift_modifier : 0) \ 292 shift_modifier : 0) \
292 | (!EQ (ns_right_control_modifier, Qleft) && \ 293 | (!EQ (ns_right_control_modifier, Qleft) && \
293 (([e modifierFlags] & NSRightControlKeyMask) \ 294 ((flags & NSRightControlKeyMask) \
294 == NSRightControlKeyMask) ? \ 295 == NSRightControlKeyMask) ? \
295 parse_solitary_modifier (ns_right_control_modifier) : 0) \ 296 parse_solitary_modifier (ns_right_control_modifier) : 0) \
296 | (([e modifierFlags] & NSControlKeyMask) ? \ 297 | ((flags & NSControlKeyMask) ? \
297 parse_solitary_modifier (ns_control_modifier) : 0) \ 298 parse_solitary_modifier (ns_control_modifier) : 0) \
298 | (([e modifierFlags] & NS_FUNCTION_KEY_MASK) ? \ 299 | ((flags & NS_FUNCTION_KEY_MASK) ? \
299 parse_solitary_modifier (ns_function_modifier) : 0) \ 300 parse_solitary_modifier (ns_function_modifier) : 0) \
300 | (!EQ (ns_right_command_modifier, Qleft) && \ 301 | (!EQ (ns_right_command_modifier, Qleft) && \
301 (([e modifierFlags] & NSRightCommandKeyMask) \ 302 ((flags & NSRightCommandKeyMask) \
302 == NSRightCommandKeyMask) ? \ 303 == NSRightCommandKeyMask) ? \
303 parse_solitary_modifier (ns_right_command_modifier) : 0) \ 304 parse_solitary_modifier (ns_right_command_modifier) : 0) \
304 | (([e modifierFlags] & NSCommandKeyMask) ? \ 305 | ((flags & NSCommandKeyMask) ? \
305 parse_solitary_modifier (ns_command_modifier):0)) 306 parse_solitary_modifier (ns_command_modifier):0))
307#define EV_MODIFIERS(e) EV_MODIFIERS2 ([e modifierFlags])
306 308
307#define EV_UDMODIFIERS(e) \ 309#define EV_UDMODIFIERS(e) \
308 ((([e type] == NSLeftMouseDown) ? down_modifier : 0) \ 310 ((([e type] == NSLeftMouseDown) ? down_modifier : 0) \
@@ -4377,9 +4379,7 @@ ns_term_init (Lisp_Object display_name)
4377 NSStringPboardType, 4379 NSStringPboardType,
4378 NSTabularTextPboardType, 4380 NSTabularTextPboardType,
4379 NSFilenamesPboardType, 4381 NSFilenamesPboardType,
4380 NSURLPboardType, 4382 NSURLPboardType, nil] retain];
4381 NSColorPboardType,
4382 NSFontPboardType, nil] retain];
4383 4383
4384 /* If fullscreen is in init/default-frame-alist, focus isn't set 4384 /* If fullscreen is in init/default-frame-alist, focus isn't set
4385 right for fullscreen windows, so set this. */ 4385 right for fullscreen windows, so set this. */
@@ -6647,6 +6647,8 @@ if (cols > 0 && rows > 0)
6647 NSString *type; 6647 NSString *type;
6648 NSEvent *theEvent = [[self window] currentEvent]; 6648 NSEvent *theEvent = [[self window] currentEvent];
6649 NSPoint position; 6649 NSPoint position;
6650 NSDragOperation op = [sender draggingSourceOperationMask];
6651 int modifiers = 0;
6650 6652
6651 NSTRACE (performDragOperation); 6653 NSTRACE (performDragOperation);
6652 6654
@@ -6658,6 +6660,20 @@ if (cols > 0 && rows > 0)
6658 6660
6659 pb = [sender draggingPasteboard]; 6661 pb = [sender draggingPasteboard];
6660 type = [pb availableTypeFromArray: ns_drag_types]; 6662 type = [pb availableTypeFromArray: ns_drag_types];
6663
6664 if (! (op & (NSDragOperationMove|NSDragOperationDelete)) &&
6665 // URL drags contain all operations (0xf), don't allow all to be set.
6666 (op & 0xf) != 0xf)
6667 {
6668 if (op & NSDragOperationLink)
6669 modifiers |= NSControlKeyMask;
6670 if (op & NSDragOperationCopy)
6671 modifiers |= NSAlternateKeyMask;
6672 if (op & NSDragOperationGeneric)
6673 modifiers |= NSCommandKeyMask;
6674 }
6675
6676 modifiers = EV_MODIFIERS2 (modifiers);
6661 if (type == 0) 6677 if (type == 0)
6662 { 6678 {
6663 return NO; 6679 return NO;
@@ -6674,34 +6690,37 @@ if (cols > 0 && rows > 0)
6674 fenum = [files objectEnumerator]; 6690 fenum = [files objectEnumerator];
6675 while ( (file = [fenum nextObject]) ) 6691 while ( (file = [fenum nextObject]) )
6676 { 6692 {
6677 emacs_event->kind = NS_NONKEY_EVENT; 6693 emacs_event->kind = DRAG_N_DROP_EVENT;
6678 emacs_event->code = KEY_NS_DRAG_FILE;
6679 XSETINT (emacs_event->x, x); 6694 XSETINT (emacs_event->x, x);
6680 XSETINT (emacs_event->y, y); 6695 XSETINT (emacs_event->y, y);
6681 ns_input_file = append2 (ns_input_file, 6696 ns_input_file = append2 (ns_input_file,
6682 build_string ([file UTF8String])); 6697 build_string ([file UTF8String]));
6683 emacs_event->modifiers = EV_MODIFIERS (theEvent); 6698 emacs_event->modifiers = modifiers;
6699 emacs_event->arg = list2 (Qfile, build_string ([file UTF8String]));
6684 EV_TRAILER (theEvent); 6700 EV_TRAILER (theEvent);
6685 } 6701 }
6686 return YES; 6702 return YES;
6687 } 6703 }
6688 else if ([type isEqualToString: NSURLPboardType]) 6704 else if ([type isEqualToString: NSURLPboardType])
6689 { 6705 {
6690 NSString *file; 6706 NSURL *url = [NSURL URLFromPasteboard: pb];
6691 NSURL *fileURL; 6707 if (url == nil) return NO;
6692
6693 if (!(fileURL = [NSURL URLFromPasteboard: pb]) ||
6694 [fileURL isFileURL] == NO)
6695 return NO;
6696 6708
6697 file = [fileURL path]; 6709 emacs_event->kind = DRAG_N_DROP_EVENT;
6698 emacs_event->kind = NS_NONKEY_EVENT;
6699 emacs_event->code = KEY_NS_DRAG_FILE;
6700 XSETINT (emacs_event->x, x); 6710 XSETINT (emacs_event->x, x);
6701 XSETINT (emacs_event->y, y); 6711 XSETINT (emacs_event->y, y);
6702 ns_input_file = append2 (ns_input_file, build_string ([file UTF8String])); 6712 emacs_event->modifiers = modifiers;
6703 emacs_event->modifiers = EV_MODIFIERS (theEvent); 6713 emacs_event->arg = list2 (Qurl,
6714 build_string ([[url absoluteString]
6715 UTF8String]));
6704 EV_TRAILER (theEvent); 6716 EV_TRAILER (theEvent);
6717
6718 if ([url isFileURL] != NO)
6719 {
6720 NSString *file = [url path];
6721 ns_input_file = append2 (ns_input_file,
6722 build_string ([file UTF8String]));
6723 }
6705 return YES; 6724 return YES;
6706 } 6725 }
6707 else if ([type isEqualToString: NSStringPboardType] 6726 else if ([type isEqualToString: NSStringPboardType]
@@ -6712,46 +6731,11 @@ if (cols > 0 && rows > 0)
6712 if (! (data = [pb stringForType: type])) 6731 if (! (data = [pb stringForType: type]))
6713 return NO; 6732 return NO;
6714 6733
6715 emacs_event->kind = NS_NONKEY_EVENT; 6734 emacs_event->kind = DRAG_N_DROP_EVENT;
6716 emacs_event->code = KEY_NS_DRAG_TEXT;
6717 XSETINT (emacs_event->x, x);
6718 XSETINT (emacs_event->y, y);
6719 ns_input_text = build_string ([data UTF8String]);
6720 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6721 EV_TRAILER (theEvent);
6722 return YES;
6723 }
6724 else if ([type isEqualToString: NSColorPboardType])
6725 {
6726 NSColor *c = [NSColor colorFromPasteboard: pb];
6727 emacs_event->kind = NS_NONKEY_EVENT;
6728 emacs_event->code = KEY_NS_DRAG_COLOR;
6729 XSETINT (emacs_event->x, x);
6730 XSETINT (emacs_event->y, y);
6731 ns_input_color = ns_color_to_lisp (c);
6732 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6733 EV_TRAILER (theEvent);
6734 return YES;
6735 }
6736 else if ([type isEqualToString: NSFontPboardType])
6737 {
6738 /* impl based on GNUstep NSTextView.m */
6739 NSData *data = [pb dataForType: NSFontPboardType];
6740 NSDictionary *dict = [NSUnarchiver unarchiveObjectWithData: data];
6741 NSFont *font = [dict objectForKey: NSFontAttributeName];
6742 char fontSize[10];
6743
6744 if (font == nil)
6745 return NO;
6746
6747 emacs_event->kind = NS_NONKEY_EVENT;
6748 emacs_event->code = KEY_NS_CHANGE_FONT;
6749 XSETINT (emacs_event->x, x); 6735 XSETINT (emacs_event->x, x);
6750 XSETINT (emacs_event->y, y); 6736 XSETINT (emacs_event->y, y);
6751 ns_input_font = build_string ([[font fontName] UTF8String]); 6737 emacs_event->modifiers = modifiers;
6752 snprintf (fontSize, 10, "%f", [font pointSize]); 6738 emacs_event->arg = list2 (Qnil, build_string ([data UTF8String]));
6753 ns_input_fontsize = build_string (fontSize);
6754 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6755 EV_TRAILER (theEvent); 6739 EV_TRAILER (theEvent);
6756 return YES; 6740 return YES;
6757 } 6741 }
@@ -7514,6 +7498,9 @@ syms_of_nsterm (void)
7514 DEFSYM (Qcontrol, "control"); 7498 DEFSYM (Qcontrol, "control");
7515 DEFSYM (QUTF8_STRING, "UTF8_STRING"); 7499 DEFSYM (QUTF8_STRING, "UTF8_STRING");
7516 7500
7501 DEFSYM (Qfile, "file");
7502 DEFSYM (Qurl, "url");
7503
7517 Fput (Qalt, Qmodifier_value, make_number (alt_modifier)); 7504 Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
7518 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier)); 7505 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
7519 Fput (Qmeta, Qmodifier_value, make_number (meta_modifier)); 7506 Fput (Qmeta, Qmodifier_value, make_number (meta_modifier));
@@ -7524,10 +7511,6 @@ syms_of_nsterm (void)
7524 "The file specified in the last NS event."); 7511 "The file specified in the last NS event.");
7525 ns_input_file =Qnil; 7512 ns_input_file =Qnil;
7526 7513
7527 DEFVAR_LISP ("ns-input-text", ns_input_text,
7528 "The data received in the last NS text drag event.");
7529 ns_input_text =Qnil;
7530
7531 DEFVAR_LISP ("ns-working-text", ns_working_text, 7514 DEFVAR_LISP ("ns-working-text", ns_working_text,
7532 "String for visualizing working composition sequence."); 7515 "String for visualizing working composition sequence.");
7533 ns_working_text =Qnil; 7516 ns_working_text =Qnil;
@@ -7544,10 +7527,6 @@ syms_of_nsterm (void)
7544 "The line specified in the last NS event."); 7527 "The line specified in the last NS event.");
7545 ns_input_line =Qnil; 7528 ns_input_line =Qnil;
7546 7529
7547 DEFVAR_LISP ("ns-input-color", ns_input_color,
7548 "The color specified in the last NS event.");
7549 ns_input_color =Qnil;
7550
7551 DEFVAR_LISP ("ns-input-spi-name", ns_input_spi_name, 7530 DEFVAR_LISP ("ns-input-spi-name", ns_input_spi_name,
7552 "The service name specified in the last NS event."); 7531 "The service name specified in the last NS event.");
7553 ns_input_spi_name =Qnil; 7532 ns_input_spi_name =Qnil;