diff -up fltk-1.3.x-r8501/src/Fl_cocoa.mm.dead-mac fltk-1.3.x-r8501/src/Fl_cocoa.mm
--- fltk-1.3.x-r8501/src/Fl_cocoa.mm.dead-mac	2011-03-01 13:37:34.000000000 +0100
+++ fltk-1.3.x-r8501/src/Fl_cocoa.mm	2011-03-31 12:57:53.439955142 +0200
@@ -837,34 +837,26 @@ static void cocoaMouseHandler(NSEvent *t
   return;
 }
 
-
-static void calc_e_text(CFStringRef s, char *buffer, size_t len, unsigned sym)
+static const char* cocoaDead2FLTK(const char *in)
 {
-  int i, no_text_key = false;
-  static unsigned notext[] = { // keys that don't emit text
-    FL_BackSpace, FL_Print, FL_Scroll_Lock, FL_Pause,
-    FL_Insert, FL_Home, FL_Page_Up, FL_Delete, FL_End, FL_Page_Down,
-    FL_Left, FL_Up, FL_Right, FL_Down, 
-    FL_Menu, FL_Num_Lock, FL_Help 
-  };
-  int count = sizeof(notext)/sizeof(int);
-   
-  if (sym > FL_F && sym <= FL_F_Last) no_text_key = true;
-  else for (i=0; i < count; i++) {
-    if (notext[i] == sym) {
-      no_text_key = true;
-      break;
-      }
-  }
-  
-  if (no_text_key) {
-    buffer[0] = 0;
-  } else {
-    CFStringGetCString(s, buffer, len, kCFStringEncodingUTF8);
-  }
+  if (strcmp(in, "\140") == 0)      // GRAVE ACCENT
+    return "\314\200";              // COMBINING GRAVE ACCENT
+  if (strcmp(in, "\302\264") == 0)  // ACUTE ACCENT
+    return "\314\201";              // COMBINING ACUTE ACCENT
+  if (strcmp(in, "\136") == 0)      // CIRCUMFLEX ACCENT
+    return "\314\202";              // COMBINING CIRCUMFLEX ACCENT
+  if (strcmp(in, "\176") == 0)      // TILDE
+    return "\314\203";              // COMBINING TILDE
+  if (strcmp(in, "\302\250") == 0)  // DIAERESIS
+    return "\314\210";              // COMBINING DIAERESIS
+  // FIXME: OS X dead key behaviour isn't documented and I don't have
+  //        any more keyboards to test with...
+
+  // hope that OS X gave us something proper to begin with
+  return in;
 }
 
-static int cocoaKeyboardHandler(NSEvent *theEvent);
+static void cocoaKeyboardHandler(NSEvent *theEvent);
 
 @interface FLTextView : NSTextView 
 // this subclass is needed under OS X <= 10.4 but not under >= 10.5 where the base class is enough
@@ -874,11 +866,13 @@ static int cocoaKeyboardHandler(NSEvent 
 @implementation FLTextView
 - (void)insertText:(id)aString
 {
-  cocoaKeyboardHandler([NSApp currentEvent]);
+  //NSLog(@"FLTextView:insertText:");
+  [[[NSApp keyWindow] contentView] insertText:aString];
 }
 - (void)doCommandBySelector:(SEL)aSelector
 {
-  cocoaKeyboardHandler([NSApp currentEvent]);
+  //NSLog(@"FLTextView:doCommandBySelector:");
+  [[[NSApp keyWindow] contentView] doCommandBySelector:aSelector];
 }
 @end
 
@@ -891,15 +885,10 @@ Events during a character composition se
     replace the temporary character by this one
  - keyup -> [theEvent characters] contains the standard character
  */
-static int cocoaKeyboardHandler(NSEvent *theEvent)
+static void cocoaKeyboardHandler(NSEvent *theEvent)
 {
-  static char buffer[32];
-  int sendEvent = 0, retval = 0;
-  Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
-  Fl::first_window(window);
   NSUInteger mods;
   
-  fl_lock_function();
   // get the modifiers
   mods = [theEvent modifierFlags];
   // get the key code
@@ -915,40 +904,32 @@ static int cocoaKeyboardHandler(NSEvent 
   // In this mode, there seem to be no key-down codes
   // printf("%08x %08x %08x\n", keyCode, mods, key);
   maskedKeyCode = keyCode & 0x7f;
-  switch([theEvent type]) {
-    case NSKeyDown:
-      sendEvent = FL_KEYBOARD;
-      // fall through
-    case NSKeyUp:
-      if ( !sendEvent ) {
-        sendEvent = FL_KEYUP;
-        Fl::e_state &= 0xbfffffff; // clear the deadkey flag
-      }
-      mods_to_e_state( mods ); // process modifier keys
-      sym = macKeyLookUp[maskedKeyCode];
-      if (sym < 0xff00) { // a "simple" key
-	// find the result of this key without modifier
-	NSString *sim = [theEvent charactersIgnoringModifiers];
-	UniChar one;
-	CFStringGetCharacters((CFStringRef)sim, CFRangeMake(0, 1), &one);
-	// charactersIgnoringModifiers doesn't ignore shift, remove it when it's on
-	if(one >= 'A' && one <= 'Z') one += 32;
-	if (one > 0 && one <= 0x7f && (sym<'0' || sym>'9') ) sym = one;
-      }
-      Fl::e_keysym = Fl::e_original_keysym = sym;
-      // Handle FL_KP_Enter on regular keyboards and on Powerbooks
-      if ( maskedKeyCode==0x4c || maskedKeyCode==0x34) s = @"\r";    
-      calc_e_text((CFStringRef)s, buffer, sizeof(buffer), sym);
-      Fl::e_length = strlen(buffer);
-      Fl::e_text = buffer;
-    default:			// prevent 'not handled in switch' warnings
-      break;
+
+  if ([theEvent type] == NSKeyUp) {
+    Fl::e_state &= 0xbfffffff; // clear the deadkey flag
   }
-  if (sendEvent) {
-    retval = Fl::handle(sendEvent,window);
+
+  mods_to_e_state( mods ); // process modifier keys
+  sym = macKeyLookUp[maskedKeyCode];
+  if (sym < 0xff00) { // a "simple" key
+    // find the result of this key without modifier
+    NSString *sim = [theEvent charactersIgnoringModifiers];
+    UniChar one;
+    CFStringGetCharacters((CFStringRef)sim, CFRangeMake(0, 1), &one);
+    // charactersIgnoringModifiers doesn't ignore shift, remove it when it's on
+    if(one >= 'A' && one <= 'Z') one += 32;
+    if (one > 0 && one <= 0x7f && (sym<'0' || sym>'9') ) sym = one;
   }
-  fl_unlock_function();  
-  return retval;
+  Fl::e_keysym = Fl::e_original_keysym = sym;
+
+  //NSLog(@"cocoaKeyboardHandler: keycode=%08x keysym=%08x mods=%08x symbol=%@ (%@)",
+  //  keyCode, sym, mods, [theEvent characters], [theEvent charactersIgnoringModifiers]);
+
+  // If there is text associated with this key, it will be filled
+  // in later.
+  Fl::e_length = 0;
+  Fl::e_text = "";
+  Fl::e_compose_symbol = (char*)[[theEvent charactersIgnoringModifiers] UTF8String];
 }
 
 
@@ -1563,6 +1544,7 @@ static void  q_set_window_title(NSWindow
 
 
 @interface FLView : NSView <NSTextInput> {
+  int next_compose_length;
 }
 - (void)drawRect:(NSRect)rect;
 - (BOOL)acceptsFirstResponder;
@@ -1579,6 +1561,7 @@ static void  q_set_window_title(NSWindow
 - (void)rightMouseDragged:(NSEvent *)theEvent;
 - (void)otherMouseDragged:(NSEvent *)theEvent;
 - (void)scrollWheel:(NSEvent *)theEvent;
+- (BOOL)handleKeyDown:(NSEvent *)theEvent;
 - (void)keyDown:(NSEvent *)theEvent;
 - (void)keyUp:(NSEvent *)theEvent;
 - (void)flagsChanged:(NSEvent *)theEvent;
@@ -1603,8 +1586,8 @@ static void  q_set_window_title(NSWindow
 }
 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent
 {   
-  int err = cocoaKeyboardHandler(theEvent);
-  return (err ? YES : NO);
+  //NSLog(@"performKeyEquivalent:");
+  return [self handleKeyDown:theEvent];
 }
 - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent
 {   
@@ -1645,14 +1628,48 @@ static void  q_set_window_title(NSWindow
 - (void)scrollWheel:(NSEvent *)theEvent {
   cocoaMouseWheelHandler(theEvent);
 }
-- (void)keyDown:(NSEvent *)theEvent {
+- (BOOL)handleKeyDown:(NSEvent *)theEvent {
+  fl_lock_function();
+
+  Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
+
+  next_compose_length = -1;
+
+  // First let's process the raw key press
+  cocoaKeyboardHandler(theEvent);
+
+  // Then we can let the OS have a stab at it and see if it thinks it
+  // should result in some text
   FLTextView *edit = (FLTextView*)[[theEvent window]  fieldEditor:YES forObject:nil];
   [edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
+
+  Fl::first_window(window);
+  int handled = Fl::handle(FL_KEYDOWN,window);
+
+  // We have to update this after Fl::handle as it says what to do on the
+  // _next_ input
+  if (next_compose_length != -1)
+    Fl::compose_state = next_compose_length;
+
+  fl_unlock_function();
+
+  return (handled ? YES : NO);
+}
+- (void)keyDown:(NSEvent *)theEvent {
+  //NSLog(@"keyDown: ");
+  [self handleKeyDown:theEvent];
 }
 - (void)keyUp:(NSEvent *)theEvent {
+  //NSLog(@"keyUp: ");
+  fl_lock_function();
+  Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
   cocoaKeyboardHandler(theEvent);
+  Fl::first_window(window);
+  Fl::handle(FL_KEYUP,window);
+  fl_unlock_function();
 }
 - (void)flagsChanged:(NSEvent *)theEvent {
+  //NSLog(@"flagsChanged: ");
   fl_lock_function();
   static UInt32 prevMods = 0;
   NSUInteger mods = [theEvent modifierFlags];
@@ -1756,44 +1773,56 @@ static void  q_set_window_title(NSWindow
 }
 
 - (void)insertText:(id)aString {
-  NSEvent *event = [NSApp currentEvent];
-  NSEventType type = [event type];
-  NSString *str = @"";
   NSString *received;
   if ([aString isKindOfClass:[NSAttributedString class]]) {
     received = [(NSAttributedString*)aString string];
   } else {
     received = (NSString*)aString;
   }
-//NSLog(@"insertText: received=%@ event type=%d",received, type);
-  if (type == NSKeyDown ) {
-    str = [event characters];
-    }
-  if ([received isEqualToString:@"\b"] || [str isEqualToString:received]) {
-    if (type == NSKeyDown ) cocoaKeyboardHandler(event);
+  //NSLog(@"insertText: received=%@",received);
+  fl_lock_function();
+  Fl::e_text = (char*)[received UTF8String];
+  Fl::e_length = strlen(Fl::e_text);
+  if (Fl::e_compose_state == FL_COMPOSE_INTERMEDIATE) {
+    Fl::e_compose_state = FL_COMPOSE_FINAL;
   } else {
-    fl_lock_function();
-    Fl_Window *window = [(FLWindow*)[NSApp keyWindow] getFl_Window];
-    Fl::e_text = (char*)[received UTF8String];
-    Fl::e_length = strlen(Fl::e_text);
-    Fl::handle(FL_KEYBOARD, window);
-    Fl::handle(FL_KEYUP, window);
-    fl_unlock_function();
-    // for some reason, the window does not redraw until the next mouse move or button push
-    // sending a 'redraw()' or 'awake()' does not solve the issue!
-    Fl::flush();
+    Fl::e_compose_state = FL_COMPOSE_NONE;
   }
+  fl_unlock_function();
 }
 
 - (void)setMarkedText:(id)aString selectedRange:(NSRange)newSelection  {
-  // NSLog(@"setMarkedText: %@ %d %d Fl::compose_state=%d",
-  //  aString,newSelection.location,newSelection.length,newSelection.location);
-  [self insertText:aString];
-  Fl::compose_state = newSelection.location;
+  NSString *received;
+
+  if (newSelection.location == 0) {
+    [self unmarkText];
+    return;
+  }
+
+  if ([aString isKindOfClass:[NSAttributedString class]]) {
+    received = [(NSAttributedString*)aString string];
+  } else {
+    received = (NSString*)aString;
+  }
+
+  //NSLog(@"setMarkedText: %@ %d %d",
+  //  received,newSelection.location,newSelection.length);
+
+  Fl::e_compose_symbol = cocoaDead2FLTK((char*)[received UTF8String]);
+  Fl::e_compose_state = FL_COMPOSE_INTERMEDIATE;
+
+  // This code creates the OS X behaviour of seeing dead keys as things
+  // are being composed. Comment out to get Windows/Unix behaviour.
+  next_compose_length = newSelection.location;
+  NSString *current = [NSString stringWithUTF8String:Fl::e_text];
+  NSString *aggregate = [current stringByAppendingString:received];
+  Fl::e_text = (char*)[aggregate UTF8String];
+  Fl::e_length = strlen(Fl::e_text);
 }
 
 - (void)unmarkText {
   Fl::compose_state = 0;
+  Fl::e_compose_state = FL_COMPOSE_NONE;
   //NSLog(@"unmarkText");
 }
 
diff -up fltk-1.3.x-r8501/src/Fl_compose.cxx.dead-mac fltk-1.3.x-r8501/src/Fl_compose.cxx
--- fltk-1.3.x-r8501/src/Fl_compose.cxx.dead-mac	2011-03-31 13:15:24.682673566 +0200
+++ fltk-1.3.x-r8501/src/Fl_compose.cxx	2011-03-31 13:17:17.047979577 +0200
@@ -55,6 +55,7 @@ const char* Fl::e_compose_symbol = "";
  */
 int Fl::compose(int& del) {
   // character composition is now handled by the OS
+  unsigned char ascii = (unsigned)e_text[0];
   del = 0;
 #if defined(__APPLE__)
   // this stuff is to be treated as a function key
@@ -63,17 +64,14 @@ int Fl::compose(int& del) {
     return 0;
   }
 #else
-  unsigned char ascii = (unsigned)e_text[0];
   if ((e_state & (FL_ALT | FL_META)) && !(ascii & 128)) return 0;
 #endif
   if(Fl::compose_state) {
     del = Fl::compose_state;
     Fl::compose_state = 0;
   } else {
-#ifndef __APPLE__
     // Only insert non-control characters:
     if (! (ascii & ~31 && ascii!=127)) { return 0; }
-#endif
   }
   return 1;
 }
