Author: manolo
Date: 2011-03-30 15:15:17 -0700 (Wed, 30 Mar 2011)
New Revision: 8549
Log:
Mac OS: Make the Fl::event_key() function distinguish between left and right 
modifier keys.
Also, don't rebuild the application menu if one is already there.

Modified:
   branches/branch-1.3/src/Fl_cocoa.mm
   branches/branch-1.3/src/Fl_get_key_mac.cxx

Modified: branches/branch-1.3/src/Fl_cocoa.mm
===================================================================
--- branches/branch-1.3/src/Fl_cocoa.mm 2011-03-30 12:07:52 UTC (rev 8548)
+++ branches/branch-1.3/src/Fl_cocoa.mm 2011-03-30 22:15:17 UTC (rev 8549)
@@ -142,6 +142,7 @@
 
 /*
  * Mac keyboard lookup table
+ * See also the inverse converter vktab in Fl_get_get_mac.cxx
  */
 static unsigned short macKeyLookUp[128] =
 {
@@ -155,9 +156,9 @@
   'k', ';', '\\', ',', '/', 'n', 'm', '.',
   
   FL_Tab, ' ', '`', FL_BackSpace, 
-  FL_KP_Enter, FL_Escape, 0, 0/*FL_Meta_L*/,
-  0/*FL_Shift_L*/, 0/*FL_Caps_Lock*/, 0/*FL_Alt_L*/, 0/*FL_Control_L*/, 
-  0/*FL_Shift_R*/, 0/*FL_Alt_R*/, 0/*FL_Control_R*/, 0,
+  FL_KP_Enter, FL_Escape, FL_Meta_R, FL_Meta_L,
+  FL_Shift_L, FL_Caps_Lock, FL_Alt_L, FL_Control_L, 
+  FL_Shift_R, FL_Alt_R, FL_Control_R, 0/*FL_F*/,
   
   0, FL_KP+'.', FL_Right, FL_KP+'*', 0, FL_KP+'+', FL_Left, FL_Num_Lock,
   FL_Down, 0, 0, FL_KP+'/', FL_KP_Enter, FL_Up, FL_KP+'-', 0,
@@ -195,7 +196,7 @@
  * convert the current key chord into the FLTK keysym
  */
 
- static void mods_to_e_keysym( NSUInteger mods )
+ /*static void mods_to_e_keysym( NSUInteger mods )
  {
  if ( mods & NSCommandKeyMask ) Fl::e_keysym = FL_Meta_L;
  else if ( mods & NSNumericPadKeyMask ) Fl::e_keysym = FL_Num_Lock;
@@ -205,7 +206,7 @@
  else if ( mods & NSAlphaShiftKeyMask ) Fl::e_keysym = FL_Caps_Lock;
  else Fl::e_keysym = 0;
  //printf( "to sym 0x%08x (%04x)\n", Fl::e_keysym, mods );
- }
+ }*/
 
 // these pointers are set by the Fl::lock() function:
 static void nothing() {}
@@ -1369,7 +1370,8 @@
         }
       }
     }
-    createAppleMenu();
+    if (![NSApp servicesMenu]) createAppleMenu();
+    fl_system_menu = [NSApp mainMenu];
     
     [[NSNotificationCenter defaultCenter] addObserver:mydelegate 
               selector:@selector(anywindowwillclosenotif:) 
@@ -1694,7 +1696,9 @@
   int sendEvent = 0;
   if ( tMods )
   {
-    mods_to_e_keysym( tMods );
+    //mods_to_e_keysym( tMods );
+    unsigned short keycode = [theEvent keyCode];
+    Fl::e_keysym = macKeyLookUp[keycode & 0x7f];
     if ( Fl::e_keysym ) 
       sendEvent = ( prevMods<mods ) ? FL_KEYBOARD : FL_KEYUP;
     Fl::e_length = 0;
@@ -1809,6 +1813,7 @@
     Fl_Window *window = [(FLWindow*)[NSApp keyWindow] getFl_Window];
     Fl::e_text = (char*)[received UTF8String];
     Fl::e_length = strlen(Fl::e_text);
+    Fl::e_keysym = 0;
     Fl::handle(FL_KEYBOARD, window);
     Fl::handle(FL_KEYUP, window);
     fl_unlock_function();
@@ -2916,7 +2921,6 @@
   [mainmenu release];
   [appleMenu release];
   [menuItem release];
-  fl_system_menu = [NSApp mainMenu];
 }
 
 @interface FLMenuItem : NSMenuItem {
@@ -2971,7 +2975,7 @@
   aboutItem.callback(cb);
   aboutItem.user_data(user_data);
   aboutItem.shortcut(shortcut);
-  NSMenu *appleMenu = [[(NSMenu*)fl_system_menu itemAtIndex:0] submenu];
+  NSMenu *appleMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];
   CFStringRef cfname = CFStringCreateCopy(NULL, (CFStringRef)[[appleMenu 
itemAtIndex:0] title]);
   [appleMenu removeItemAtIndex:0];
   FLMenuItem *item = [[[FLMenuItem alloc] initWithTitle:(NSString*)cfname 
@@ -3119,11 +3123,11 @@
     // renames the system menu item numbered rank in fl_sys_menu_bar->menu()
     int rank = va_arg(ap, int);
     char *newname = remove_ampersand( va_arg(ap, const char *) );
-    int countmenus = [(NSMenu*)fl_system_menu numberOfItems];
+    int countmenus = [[NSApp mainMenu] numberOfItems];
     bool found = NO;
     NSMenuItem *macitem = 0;
     for(int i = 1; (!found) && i < countmenus; i++) {
-      NSMenuItem *item = [(NSMenu*)fl_system_menu itemAtIndex:i];
+      NSMenuItem *item = [[NSApp mainMenu] itemAtIndex:i];
       NSMenu *submenu = [item submenu];
       if (submenu == nil) continue;
       int countitems = [submenu numberOfItems];

Modified: branches/branch-1.3/src/Fl_get_key_mac.cxx
===================================================================
--- branches/branch-1.3/src/Fl_get_key_mac.cxx  2011-03-30 12:07:52 UTC (rev 
8548)
+++ branches/branch-1.3/src/Fl_get_key_mac.cxx  2011-03-30 22:15:17 UTC (rev 
8549)
@@ -64,9 +64,9 @@
   { 0x7a, FL_F+1 }, { 0x78, FL_F+2  }, { 0x63, FL_F+3  }, { 0x76, FL_F+4  }, 
   { 0x60, FL_F+5 }, { 0x61, FL_F+6  }, { 0x62, FL_F+7  }, { 0x64, FL_F+8  }, 
   { 0x65, FL_F+9 }, { 0x6D, FL_F+10 }, { 0x67, FL_F+11 }, { 0x6f, FL_F+12 }, 
-  { 56, FL_Shift_L }, { 56, FL_Shift_R }, { 59, FL_Control_L }, { 59, 
FL_Control_R }, 
-  { 57, FL_Caps_Lock }, { 55, FL_Meta_L }, { 55, FL_Meta_R },
-  { 58, FL_Alt_L }, { 58, FL_Alt_R }, { 0x75, FL_Delete },
+  { 0x38, FL_Shift_L }, { 0x3C, FL_Shift_R }, { 0x3B, FL_Control_L }, { 0x3E, 
FL_Control_R }, 
+  { 0x39, FL_Caps_Lock }, { 0x37, FL_Meta_L }, { 0x36, FL_Meta_R },
+  { 0x3A, FL_Alt_L }, { 0x3D, FL_Alt_R }, { 0x75, FL_Delete },
 };
 
 static int fltk2mac(int fltk) {

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to