Fix STR#2928: alt+e on US keyboard not processed correctly as shortcut on Mac OS.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9811 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2013-01-28 21:05:29 +00:00
parent e7c0c31661
commit 49f8a3cfc9
3 changed files with 16 additions and 0 deletions

View File

@ -133,6 +133,7 @@ public:
static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen
static int next_marked_length; // next length of marked text after current marked text will have been replaced static int next_marked_length; // next length of marked text after current marked text will have been replaced
static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point
static int shortcut_events_since_keyDown; // to limit to one FL_SHORTCUT event per keyDown event.
private: private:
static void relink(Fl_Window*, Fl_Window*); static void relink(Fl_Window*, Fl_Window*);
bool subwindow; bool subwindow;

View File

@ -1280,6 +1280,9 @@ int Fl::handle_(int e, Fl_Window* window)
e_number = e = FL_SHORTCUT; e_number = e = FL_SHORTCUT;
case FL_SHORTCUT: case FL_SHORTCUT:
#ifdef __APPLE__
if (Fl_X::shortcut_events_since_keyDown++ > 0) return 0;
#endif
if (grab()) {wi = grab(); break;} // send it to grab window if (grab()) {wi = grab(); break;} // send it to grab window
// Try it as shortcut, sending to mouse widget and all parents: // Try it as shortcut, sending to mouse widget and all parents:

View File

@ -52,6 +52,7 @@ extern "C" {
#include <unistd.h> #include <unistd.h>
#include <stdarg.h> #include <stdarg.h>
#include <math.h> #include <math.h>
#include <limits.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@ -106,6 +107,7 @@ Window fl_window;
Fl_Window *Fl_Window::current_; Fl_Window *Fl_Window::current_;
int fl_mac_os_version = calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4) int fl_mac_os_version = calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)
static SEL inputContextSEL = (fl_mac_os_version >= 100600 ? @selector(inputContext) : @selector(FLinputContext)); static SEL inputContextSEL = (fl_mac_os_version >= 100600 ? @selector(inputContext) : @selector(FLinputContext));
int Fl_X::shortcut_events_since_keyDown = INT_MIN;
// forward declarations of variables in this file // forward declarations of variables in this file
static int got_events = 0; static int got_events = 0;
@ -1657,6 +1659,14 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi
insertText: messages to the FLTextView object that are transmitted unchanged to myview to be processed as with OS >= 10.6. insertText: messages to the FLTextView object that are transmitted unchanged to myview to be processed as with OS >= 10.6.
The system also sends setMarkedText: messages directly to myview. The system also sends setMarkedText: messages directly to myview.
When 2 deadkeys are pressed in succession, the messages sent are [myview setMarkedText:] by the 1st keystroke and
[myview insertText:] [myview setMarkedText:] by the 2nd keystroke. Each of these messages creates an FL_KEYBOARD event,
so there are two FL_KEYBOARD events for the 2nd keystroke. If no widget in the window accepts keyboard input, FL_KEYBOARD
events are re-tried as FL_SHORTCUT events, which makes two FL_SHORTCUT events for a single keystroke. This is a problem
when these keystrokes are used as shortcuts. Such problem occurs, for example, with Alt+e on a US keyboard.
The Fl_X::shortcut_events_since_keyDown variable allows to transform only one FL_KEYBOARD event into an FL_SHORTCUT
event during processing of a keystroke, and thus fixes the double-shortcut problem.
There is furthermore an oddity of dead key processing with OS <= 10.5. It occurs when a dead key followed by a non-accented There is furthermore an oddity of dead key processing with OS <= 10.5. It occurs when a dead key followed by a non-accented
key are pressed. Say, for example, that keys '^' followed by 'p' are pressed on a French or German keyboard. Resulting key are pressed. Say, for example, that keys '^' followed by 'p' are pressed on a French or German keyboard. Resulting
messages are: [myview setMarkedText:@"^"], [myview insertText:@"^"], [myview insertText:@"p"], [FLTextView insertText:@"^p"]. messages are: [myview setMarkedText:@"^"], [myview insertText:@"^"], [myview insertText:@"p"], [FLTextView insertText:@"^p"].
@ -1859,7 +1869,9 @@ static void cocoaKeyboardHandler(NSEvent *theEvent)
Fl::first_window(window); Fl::first_window(window);
cocoaKeyboardHandler(theEvent); cocoaKeyboardHandler(theEvent);
in_key_event = YES; in_key_event = YES;
Fl_X::shortcut_events_since_keyDown = 0;
[[self performSelector:inputContextSEL] handleEvent:theEvent]; [[self performSelector:inputContextSEL] handleEvent:theEvent];
Fl_X::shortcut_events_since_keyDown = INT_MIN;
in_key_event = NO; in_key_event = NO;
fl_unlock_function(); fl_unlock_function();
} }