comparison src/nsterm.m @ 101490:cfaf6934d659

Changes to remove Feval calls from GUI under NS. * nsterm.h: Move KEY_NS_... definitions here from nsterm.m. Add NS_TOGGLE_TOOLBAR, NS_PUT_WORKING_TEXT, NS_UNPUT_WORKING_TEXT. Remove NS_INSERT_WORKING_TEXT, NS_DELETE_WORKING_TEXT. * nsterm.m: Move KEY_NS_... definitions to nsterm.h. (EmacsView-toggleToolbar:): Use KEY_NS_TOGGLE_TOOLBAR. (EmacsView-setMarkedText:,-deleteWorkingText:): Use NS_TEXT_EVENT instead of NON_ASCII_KEYSTROKE_EVENT. (EmacsApp-terminate:): Use KEY_NS_POWER_OFF instead of Feval. (EmacsApp-applicationShouldTerminate:): Query user. (EmacsPreferencesController-runHelp:): Use KEY_NS_INFO_PREFS instead of Feval. * termhooks.h (NS_TEXT_EVENT): New event type under HAVE_NS. * keyboard.c (kbd_buffer_get_event): Check for it. (keys_of_keyboard): Define lispy keys for ns-put/unput-working-text. * nsmenu.m (ns_popup_dialog): Resync window setting with X and W32 versions. (EmacsDialog-runDialogAt:): Use NSModalPanelRunLoopMode.
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Sun, 25 Jan 2009 19:43:31 +0000
parents fd15717d12c3
children c32306216562
comparison
equal deleted inserted replaced
101489:d98a233b0396 101490:cfaf6934d659
66 /* ========================================================================== 66 /* ==========================================================================
67 67
68 Local declarations 68 Local declarations
69 69
70 ========================================================================== */ 70 ========================================================================== */
71
72 /* Special keycodes that we pass down the event chain */
73 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
74 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
75 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
76 #define KEY_NS_DRAG_FILE ((1<<28)|(0<<16)|4)
77 #define KEY_NS_DRAG_COLOR ((1<<28)|(0<<16)|5)
78 #define KEY_NS_DRAG_TEXT ((1<<28)|(0<<16)|6)
79 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
80 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
81 #define KEY_NS_INSERT_WORKING_TEXT ((1<<28)|(0<<16)|9)
82 #define KEY_NS_DELETE_WORKING_TEXT ((1<<28)|(0<<16)|10)
83 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
84 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
85 71
86 /* Convert a symbol indexed with an NSxxx value to a value as defined 72 /* Convert a symbol indexed with an NSxxx value to a value as defined
87 in keyboard.c (lispy_function_key). I hope this is a correct way 73 in keyboard.c (lispy_function_key). I hope this is a correct way
88 of doing things... */ 74 of doing things... */
89 static unsigned convert_ns_to_X_keysym[] = 75 static unsigned convert_ns_to_X_keysym[] =
4046 -------------------------------------------------------------------------- */ 4032 -------------------------------------------------------------------------- */
4047 { 4033 {
4048 int type = [theEvent type]; 4034 int type = [theEvent type];
4049 NSWindow *window = [theEvent window]; 4035 NSWindow *window = [theEvent window];
4050 /* NSTRACE (sendEvent); */ 4036 /* NSTRACE (sendEvent); */
4051 /*fprintf (stderr, "received event of type %d\n", [theEvent type]); */ 4037 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4052 4038
4053 if (type == NSCursorUpdate && window == nil) 4039 if (type == NSCursorUpdate && window == nil)
4054 { 4040 {
4055 fprintf (stderr, "Dropping external cursor update event.\n"); 4041 fprintf (stderr, "Dropping external cursor update event.\n");
4056 return; 4042 return;
4151 [NSApp setServicesProvider: NSApp]; 4137 [NSApp setServicesProvider: NSApp];
4152 ns_send_appdefined (-2); 4138 ns_send_appdefined (-2);
4153 } 4139 }
4154 4140
4155 4141
4142 /* Termination sequences (ns_shutdown_properly):
4143 C-x C-c:
4144 Cmd-Q:
4145 MenuBar | File | Exit:
4146 ns_term_shutdown: 0
4147 received -terminate: 1
4148 received -appShouldTerminate: 1
4149
4150 Select Quit from App menubar:
4151 received -terminate: 0
4152 ns_term_shutdown: 0
4153 received -terminate: 1
4154 received -appShouldTerminate: 1
4155
4156 Select Quit from Dock menu:
4157 Logout attempt:
4158 received -appShouldTerminate: 0
4159 Cancel -> Nothing else
4160 Accept ->
4161 received -terminate: 0
4162 ns_term_shutdown: 0
4163 received -terminate: 1
4164 received -appShouldTerminate: 1
4165 */
4166
4156 - (void) terminate: (id)sender 4167 - (void) terminate: (id)sender
4157 { 4168 {
4158 BLOCK_INPUT;
4159 if (ns_shutdown_properly) 4169 if (ns_shutdown_properly)
4160 [super terminate: sender]; 4170 [super terminate: sender];
4161 else 4171 else
4162 { 4172 {
4163 /* Fkill_emacs (Qnil); */ 4173 struct frame *emacsframe = SELECTED_FRAME ();
4174
4175 if (!emacs_event)
4176 return;
4177
4164 ns_shutdown_properly = YES; 4178 ns_shutdown_properly = YES;
4165 Feval (Fcons (intern ("save-buffers-kill-emacs"), Qnil)); 4179 emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
4166 } 4180 emacs_event->code = KEY_NS_POWER_OFF;
4167 UNBLOCK_INPUT; 4181 EV_TRAILER ((id)nil);
4182 }
4168 } 4183 }
4169 4184
4170 4185
4171 - (NSApplicationTerminateReply)applicationShouldTerminate: (id)sender 4186 - (NSApplicationTerminateReply)applicationShouldTerminate: (id)sender
4172 { 4187 {
4188 int ret;
4189
4173 if (ns_shutdown_properly) 4190 if (ns_shutdown_properly)
4174 return NSTerminateNow; 4191 return NSTerminateNow;
4175 4192
4176 Lisp_Object contents = list3 (build_string ("Exit requested. Would you like to Save Buffers and Exit, or Cancel the request?"), 4193 /* XXX: This while() loop is needed because if the user switches to another
4177 Fcons (build_string ("Cancel"), Qnil), 4194 application while the panel is up, it is taken down w/a return value
4178 Fcons (build_string ("Save and Exit"), Qt)); 4195 of -1000, and the event queue gets messed up. In this case resend
4179 Lisp_Object res = ns_popup_dialog (Qt, contents, Qnil); 4196 the appdefined and put up the window again. */
4180 fprintf (stderr, "res = %d\n", EQ (res, Qt)); /* FIXME */ 4197 while (1) {
4181 if (EQ (res, Qt)) 4198 ret = NSRunAlertPanel([[NSProcessInfo processInfo] processName],
4182 { 4199 [NSString stringWithUTF8String:"Exit requested. Would you like to Save Buffers and Exit, or Cancel the request?"],
4183 Feval (Fcons (intern ("save-buffers-kill-emacs"), Qnil)); 4200 @"Save Buffers and Exit", @"Cancel", nil);
4184 return NSTerminateNow; 4201
4185 } 4202 if (ret == NSAlertDefaultReturn)
4186 return NSTerminateCancel; 4203 {
4204 send_appdefined = YES;
4205 ns_send_appdefined(-1);
4206 return NSTerminateNow;
4207 }
4208 else if (ret == NSAlertAlternateReturn)
4209 {
4210 send_appdefined = YES;
4211 ns_send_appdefined(-1);
4212 return NSTerminateCancel;
4213 }
4214 }
4187 } 4215 }
4188 4216
4189 4217
4190 /* Notification from the Workspace to open a file */ 4218 /* Notification from the Workspace to open a file */
4191 - (BOOL)application: sender openFile: (NSString *)file 4219 - (BOOL)application: sender openFile: (NSString *)file
4610 4638
4611 4639
4612 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */ 4640 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4613 4641
4614 4642
4615 /* <NSTextInput>: called through when done composing */ 4643 /* <NSTextInput>: called when done composing;
4644 NOTE: also called when we delete over working text, followed immed.
4645 by doCommandBySelector: deleteBackward: */
4616 - (void)insertText: (id)aString 4646 - (void)insertText: (id)aString
4617 { 4647 {
4618 int code; 4648 int code;
4619 int len = [(NSString *)aString length]; 4649 int len = [(NSString *)aString length];
4620 int i; 4650 int i;
4665 4695
4666 processingCompose = YES; 4696 processingCompose = YES;
4667 workingText = [str copy]; 4697 workingText = [str copy];
4668 ns_working_text = build_string ([workingText UTF8String]); 4698 ns_working_text = build_string ([workingText UTF8String]);
4669 4699
4670 /* if in "echo area", not true minibuffer, can't show chars in interactive 4700 emacs_event->kind = NS_TEXT_EVENT;
4671 mode, so call using eval; otherwise we send a key event, which was the 4701 emacs_event->code = KEY_NS_PUT_WORKING_TEXT;
4672 original way this was done */ 4702 EV_TRAILER ((id)nil);
4673 if (!EQ (Feval (Fcons (intern ("ns-in-echo-area"), Qnil)), Qnil))
4674 {
4675 Feval (Fcons (intern ("ns-echo-working-text"), Qnil));
4676 ns_send_appdefined (-1);
4677 }
4678 else
4679 {
4680 emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
4681 emacs_event->code = KEY_NS_INSERT_WORKING_TEXT;
4682 EV_TRAILER ((id)nil);
4683 }
4684 } 4703 }
4685 4704
4686 4705
4687 /* delete display of composing characters [not in <NSTextInput>] */ 4706 /* delete display of composing characters [not in <NSTextInput>] */
4688 - (void)deleteWorkingText 4707 - (void)deleteWorkingText
4689 { 4708 {
4690 if (workingText == nil) 4709 if (workingText == nil)
4691 return; 4710 return;
4692 if (NS_KEYLOG) 4711 if (NS_KEYLOG)
4693 fprintf (stderr, "deleteWorkingText len =%d\n", [workingText length]); 4712 NSLog(@"deleteWorkingText len =%d\n", [workingText length]);
4694 [workingText release]; 4713 [workingText release];
4695 workingText = nil; 4714 workingText = nil;
4696 processingCompose = NO; 4715 processingCompose = NO;
4697 4716
4698 if (!emacs_event) 4717 if (!emacs_event)
4699 return; 4718 return;
4700 4719
4701 if (!EQ (Feval (Fcons (intern ("ns-in-echo-area"), Qnil)), Qnil)) 4720 emacs_event->kind = NS_TEXT_EVENT;
4702 { 4721 emacs_event->code = KEY_NS_UNPUT_WORKING_TEXT;
4703 Feval (Fcons (intern ("ns-unecho-working-text"), Qnil)); 4722 EV_TRAILER ((id)nil);
4704 ns_send_appdefined (-1); 4723 }
4705 }
4706 else
4707 {
4708 emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
4709 emacs_event->code = KEY_NS_DELETE_WORKING_TEXT;
4710 EV_TRAILER ((id)nil);
4711 }
4712 }
4713 4724
4714 4725
4715 - (BOOL)hasMarkedText 4726 - (BOOL)hasMarkedText
4716 { 4727 {
4717 return workingText != nil; 4728 return workingText != nil;
4718 } 4729 }
4730
4719 4731
4720 - (NSRange)markedRange 4732 - (NSRange)markedRange
4721 { 4733 {
4722 NSRange rng = workingText != nil 4734 NSRange rng = workingText != nil
4723 ? NSMakeRange (0, [workingText length]) : NSMakeRange (NSNotFound, 0); 4735 ? NSMakeRange (0, [workingText length]) : NSMakeRange (NSNotFound, 0);
4724 if (NS_KEYLOG) 4736 if (NS_KEYLOG)
4725 NSLog (@"markedRange request"); 4737 NSLog (@"markedRange request");
4726 return rng; 4738 return rng;
4727 } 4739 }
4728 4740
4741
4729 - (void)unmarkText 4742 - (void)unmarkText
4730 { 4743 {
4731 if (NS_KEYLOG) 4744 if (NS_KEYLOG)
4732 NSLog (@"unmark (accept) text"); 4745 NSLog (@"unmark (accept) text");
4733 [self deleteWorkingText]; 4746 [self deleteWorkingText];
4734 processingCompose = NO; 4747 processingCompose = NO;
4735 } 4748 }
4749
4736 4750
4737 /* used to position char selection windows, etc. */ 4751 /* used to position char selection windows, etc. */
4738 - (NSRect)firstRectForCharacterRange: (NSRange)theRange 4752 - (NSRect)firstRectForCharacterRange: (NSRange)theRange
4739 { 4753 {
4740 NSRect rect; 4754 NSRect rect;
4753 pt = [[self window] convertBaseToScreen: pt]; 4767 pt = [[self window] convertBaseToScreen: pt];
4754 rect.origin = pt; 4768 rect.origin = pt;
4755 return rect; 4769 return rect;
4756 } 4770 }
4757 4771
4772
4758 - (NSInteger)conversationIdentifier 4773 - (NSInteger)conversationIdentifier
4759 { 4774 {
4760 return (NSInteger)self; 4775 return (NSInteger)self;
4761 } 4776 }
4762 4777
4763 /* TODO: below here not yet implemented correctly, but may not be needed */
4764 4778
4765 - (void)doCommandBySelector: (SEL)aSelector 4779 - (void)doCommandBySelector: (SEL)aSelector
4766 { 4780 {
4767 if (NS_KEYLOG) 4781 if (NS_KEYLOG)
4768 NSLog (@"doCommandBySelector: %@", NSStringFromSelector (aSelector)); 4782 NSLog (@"doCommandBySelector: %@", NSStringFromSelector (aSelector));
5396 5410
5397 if (!emacs_event) 5411 if (!emacs_event)
5398 return self; 5412 return self;
5399 5413
5400 /* send first event (for some reason two needed) */ 5414 /* send first event (for some reason two needed) */
5401 theEvent =[[self window] currentEvent]; 5415 theEvent = [[self window] currentEvent];
5402 emacs_event->kind = TOOL_BAR_EVENT; 5416 emacs_event->kind = TOOL_BAR_EVENT;
5403 XSETFRAME (emacs_event->arg, emacsframe); 5417 XSETFRAME (emacs_event->arg, emacsframe);
5404 EV_TRAILER (theEvent); 5418 EV_TRAILER (theEvent);
5405 5419
5406 emacs_event->kind = TOOL_BAR_EVENT; 5420 emacs_event->kind = TOOL_BAR_EVENT;
5413 } 5427 }
5414 5428
5415 5429
5416 - toggleToolbar: (id)sender 5430 - toggleToolbar: (id)sender
5417 { 5431 {
5418 Lisp_Object lispFrame; 5432 if (!emacs_event)
5419 XSETFRAME (lispFrame, emacsframe); 5433 return self;
5420 Feval (Fcons (intern ("ns-toggle-toolbar"), Fcons (lispFrame, Qnil))); 5434
5421 SET_FRAME_GARBAGED (emacsframe); 5435 emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
5422 ns_send_appdefined (-1); 5436 emacs_event->code = KEY_NS_TOGGLE_TOOLBAR;
5437 EV_TRAILER ((id)nil);
5438 return self;
5423 } 5439 }
5424 5440
5425 5441
5426 - (void)drawRect: (NSRect)rect 5442 - (void)drawRect: (NSRect)rect
5427 { 5443 {
6264 } 6280 }
6265 6281
6266 6282
6267 - (IBAction)runHelp: (id)sender 6283 - (IBAction)runHelp: (id)sender
6268 { 6284 {
6269 Feval (Fcons (intern ("info"), 6285 struct frame *emacsframe = frame;
6270 Fcons (build_string ("(emacs)Mac / GNUstep Customization"), 6286 if (!emacs_event)
6271 Qnil))); 6287 return;
6272 SET_FRAME_GARBAGED (frame); 6288 ns_raise_frame(frame);
6273 ns_send_appdefined (-1); 6289 emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
6290 emacs_event->code = KEY_NS_INFO_PREFS;
6291 EV_TRAILER ((id)nil);
6274 } 6292 }
6275 6293
6276 6294
6277 - (IBAction)setColors: (id)sender 6295 - (IBAction)setColors: (id)sender
6278 { 6296 {