aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2013-03-30 20:37:57 +0300
committerEli Zaretskii2013-03-30 20:37:57 +0300
commitf1aa11971a74b7b2fa0f5baaaaf21dfbd388de6b (patch)
tree48e20bfab4262d7171593d4ef98309ae717c1cb6 /src
parent7c4026b6ad03974a55a175af17c8e76c61931b69 (diff)
parent119b2d43cc40759394cae256c0a38624cacbf776 (diff)
downloademacs-f1aa11971a74b7b2fa0f5baaaaf21dfbd388de6b.tar.gz
emacs-f1aa11971a74b7b2fa0f5baaaaf21dfbd388de6b.zip
Merge from trunk.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog22
-rw-r--r--src/nsmenu.m49
-rw-r--r--src/nsterm.h3
-rw-r--r--src/nsterm.m90
4 files changed, 154 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 14e21e402d6..b9e9cce5cb7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,25 @@
12013-03-30 Darren Ho <darren.hoo@gmail.com> (tiny change)
2
3 * nsmenu.m (showAtX:Y:for:): setLevel to
4 NSPopUpMenuWindowLevel (Bug#13998).
5
62013-03-30 Jan Djärv <jan.h.d@swipnet.se>
7
8 * nsterm.h (ns_get_pending_menu_title, ns_check_menu_open)
9 (ns_check_pending_open_menu): Declare.
10
11 * nsmenu.m (ns_update_menubar): Correct NSTRACE.
12 (x_activate_menubar): Update the menu with title that matches
13 ns_get_pending_menu_title, and call
14 ns_check_pending_openmenu (Bug#12698).
15 (menuWillOpen:): New method.
16 (menuNeedsUpdate:): Add check for ! COCOA || OSX < 10.5 (Bug#12698).
17
18 * nsterm.m (menu_will_open_state, menu_mouse_point)
19 (menu_pending_title): New varaibles.
20 (ns_get_pending_menu_title, ns_check_menu_open)
21 (ns_check_pending_open_menu): New functions.
22
12013-03-29 Dmitry Antipov <dmantipov@yandex.ru> 232013-03-29 Dmitry Antipov <dmantipov@yandex.ru>
2 24
3 * indent.c (current_column_bol_cache): Remove leftover which is not 25 * indent.c (current_column_bol_cache): Remove leftover which is not
diff --git a/src/nsmenu.m b/src/nsmenu.m
index b764d3f5951..4e26a994b59 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -88,14 +88,6 @@ static int trackingMenu;
88 ========================================================================== */ 88 ========================================================================== */
89 89
90 90
91/* FIXME: not currently used, but should normalize with other terms. */
92void
93x_activate_menubar (struct frame *f)
94{
95 fprintf (stderr, "XXX: Received x_activate_menubar event.\n");
96}
97
98
99/* Supposed to discard menubar and free storage. Since we share the 91/* Supposed to discard menubar and free storage. Since we share the
100 menubar among frames and update its context for the focused window, 92 menubar among frames and update its context for the focused window,
101 there is nothing to do here. */ 93 there is nothing to do here. */
@@ -138,7 +130,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
138 long t; 130 long t;
139#endif 131#endif
140 132
141 NSTRACE (set_frame_menubar); 133 NSTRACE (ns_update_menubar);
142 134
143 if (f != SELECTED_FRAME ()) 135 if (f != SELECTED_FRAME ())
144 return; 136 return;
@@ -512,6 +504,29 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
512 ns_update_menubar (f, deep_p, nil); 504 ns_update_menubar (f, deep_p, nil);
513} 505}
514 506
507void
508x_activate_menubar (struct frame *f)
509{
510 NSArray *a = [[NSApp mainMenu] itemArray];
511 /* Update each submenu separatly so ns_update_menubar don't reset
512 the delegate. */
513 int i = 0;
514 while (i < [a count])
515 {
516 EmacsMenu *menu = (EmacsMenu *)[[a objectAtIndex:i] submenu];
517 const char *title = [[menu title] UTF8String];
518 if (strcmp (title, ns_get_pending_menu_title ()) == 0)
519 {
520 ns_update_menubar (f, true, menu);
521 break;
522 }
523 ++i;
524 }
525 ns_check_pending_open_menu ();
526}
527
528
529
515 530
516/* ========================================================================== 531/* ==========================================================================
517 532
@@ -564,6 +579,14 @@ extern NSString *NSMenuDidBeginTrackingNotification;
564 trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification 579 trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification
565 ? 1 : 0); 580 ? 1 : 0);
566} 581}
582
583#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
584- (void)menuWillOpen:(NSMenu *)menu
585{
586 ns_check_menu_open (menu);
587}
588#endif
589
567#endif 590#endif
568 591
569/* delegate method called when a submenu is being opened: run a 'deep' call 592/* delegate method called when a submenu is being opened: run a 'deep' call
@@ -591,7 +614,12 @@ extern NSString *NSMenuDidBeginTrackingNotification;
591 if (trackingMenu == 0) 614 if (trackingMenu == 0)
592 return; 615 return;
593/*fprintf (stderr, "Updating menu '%s'\n", [[self title] UTF8String]); NSLog (@"%@\n", event); */ 616/*fprintf (stderr, "Updating menu '%s'\n", [[self title] UTF8String]); NSLog (@"%@\n", event); */
594 ns_update_menubar (frame, 1, self); 617#if ! defined(NS_IMPL_COCOA) || \
618 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
619 /* Don't know how to do this for anything other than OSX >= 10.5
620 This is wrong, as it might run Lisp code in the event loop. */
621 ns_update_menubar (frame, true, self);
622#endif
595} 623}
596 624
597 625
@@ -1300,6 +1328,7 @@ update_frame_tool_bar (FRAME_PTR f)
1300 wr.size = [textField frame].size; 1328 wr.size = [textField frame].size;
1301 1329
1302 [win setFrame: wr display: YES]; 1330 [win setFrame: wr display: YES];
1331 [win setLevel: NSPopUpMenuWindowLevel];
1303 [win orderFront: self]; 1332 [win orderFront: self];
1304 [win display]; 1333 [win display];
1305 timer = [NSTimer scheduledTimerWithTimeInterval: (float)seconds target: self 1334 timer = [NSTimer scheduledTimerWithTimeInterval: (float)seconds target: self
diff --git a/src/nsterm.h b/src/nsterm.h
index 6bd04b96684..a43a90428d0 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -792,6 +792,9 @@ extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
792extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f); 792extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
793extern unsigned long ns_index_color (NSColor *color, struct frame *f); 793extern unsigned long ns_index_color (NSColor *color, struct frame *f);
794extern void ns_free_indexed_color (unsigned long idx, struct frame *f); 794extern void ns_free_indexed_color (unsigned long idx, struct frame *f);
795extern const char *ns_get_pending_menu_title ();
796extern void ns_check_menu_open (NSMenu *menu);
797extern void ns_check_pending_open_menu ();
795#endif 798#endif
796 799
797/* C access to ObjC functionality */ 800/* C access to ObjC functionality */
diff --git a/src/nsterm.m b/src/nsterm.m
index c75167d7531..9baa95a506b 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -228,6 +228,25 @@ static struct {
228 NULL, 0, 0 228 NULL, 0, 0
229}; 229};
230 230
231/*
232 * State for pending menu activation:
233 * MENU_NONE Normal state
234 * MENU_PENDING A menu has been clicked on, but has been canceled so we can
235 * run lisp to update the menu.
236 * MENU_OPENING Menu is up to date, and the click event is redone so the menu
237 * will open.
238 */
239#define MENU_NONE 0
240#define MENU_PENDING 1
241#define MENU_OPENING 2
242static int menu_will_open_state = MENU_NONE;
243
244/* Saved position for menu click. */
245static CGPoint menu_mouse_point;
246
247/* Title for the menu to open. */
248static char *menu_pending_title = 0;
249
231/* Convert modifiers in a NeXTstep event to emacs style modifiers. */ 250/* Convert modifiers in a NeXTstep event to emacs style modifiers. */
232#define NS_FUNCTION_KEY_MASK 0x800000 251#define NS_FUNCTION_KEY_MASK 0x800000
233#define NSLeftControlKeyMask (0x000001 | NSControlKeyMask) 252#define NSLeftControlKeyMask (0x000001 | NSControlKeyMask)
@@ -3388,6 +3407,77 @@ check_native_fs ()
3388} 3407}
3389#endif 3408#endif
3390 3409
3410const char *
3411ns_get_pending_menu_title ()
3412{
3413 return menu_pending_title;
3414}
3415
3416/* Check if menu open should be cancelled or continued as normal. */
3417void
3418ns_check_menu_open (NSMenu *menu)
3419{
3420 /* GNUStep and OSX <= 10.4 does not have cancelTracking. */
3421#if defined(NS_IMPL_COCOA) && \
3422 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3423
3424 /* Click in menu bar? */
3425 NSArray *a = [[NSApp mainMenu] itemArray];
3426 int i;
3427 BOOL found = NO;
3428 for (i = 0; ! found && i < [a count]; i++)
3429 found = menu == [[a objectAtIndex:i] submenu];
3430 if (found)
3431 {
3432 if (menu_will_open_state == MENU_NONE && emacs_event)
3433 {
3434 NSEvent *theEvent = [NSApp currentEvent];
3435 struct frame *emacsframe = SELECTED_FRAME ();
3436
3437 [menu cancelTracking];
3438 menu_will_open_state = MENU_PENDING;
3439 emacs_event->kind = MENU_BAR_ACTIVATE_EVENT;
3440 EV_TRAILER (theEvent);
3441
3442 CGEventRef ourEvent = CGEventCreate (NULL);
3443 menu_mouse_point = CGEventGetLocation (ourEvent);
3444 CFRelease (ourEvent);
3445 xfree (menu_pending_title);
3446 menu_pending_title = xstrdup ([[menu title] UTF8String]);
3447 }
3448 else if (menu_will_open_state == MENU_OPENING)
3449 {
3450 menu_will_open_state = MENU_NONE;
3451 }
3452 }
3453#endif
3454}
3455
3456/* Redo saved menu click if state is MENU_PENDING. */
3457void
3458ns_check_pending_open_menu ()
3459{
3460#ifdef NS_IMPL_COCOA
3461 if (menu_will_open_state == MENU_PENDING)
3462 {
3463 CGEventSourceRef source
3464 = CGEventSourceCreate (kCGEventSourceStateHIDSystemState);
3465
3466 CGEventRef event = CGEventCreateMouseEvent (source,
3467 kCGEventLeftMouseDown,
3468 menu_mouse_point,
3469 kCGMouseButtonLeft);
3470 CGEventSetType (event, kCGEventLeftMouseDown);
3471 CGEventPost (kCGHIDEventTap, event);
3472 CFRelease (event);
3473 CFRelease (source);
3474
3475 menu_will_open_state = MENU_OPENING;
3476 }
3477#endif
3478}
3479
3480
3391static int 3481static int
3392ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) 3482ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
3393/* -------------------------------------------------------------------------- 3483/* --------------------------------------------------------------------------