diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_get_key_mac.cxx | 4 | ||||
| -rw-r--r-- | src/Fl_mac.cxx | 97 | ||||
| -rw-r--r-- | src/fl_dnd_mac.cxx | 2 | ||||
| -rw-r--r-- | src/fl_rect.cxx | 4 | ||||
| -rw-r--r-- | src/fl_shortcut.cxx | 42 |
5 files changed, 131 insertions, 18 deletions
diff --git a/src/Fl_get_key_mac.cxx b/src/Fl_get_key_mac.cxx index 63d660251..afdeddb7b 100644 --- a/src/Fl_get_key_mac.cxx +++ b/src/Fl_get_key_mac.cxx @@ -54,7 +54,7 @@ static const struct {unsigned short vk, fltk;} vktab[] = { { 107, FL_Scroll_Lock }, { 53, FL_Escape }, { 0x73, FL_Home }, { 123, FL_Left }, { 126, FL_Up }, { 124, FL_Right }, { 125, FL_Down }, { 0x74, FL_Page_Up }, { 0x79, FL_Page_Down }, { 119, FL_End }, { 0x71, FL_Print }, { 127, FL_Insert }, - { 0x6e, FL_Menu }, { 114, FL_Help }, { 0x47, FL_Num_Lock }, + { 0x6e, FL_Menu }, { 114, FL_Help }, /*{ 0x47, FL_Num_Lock },*/ { 76, FL_KP_Enter }, { 67, FL_KP+'*' }, { 69, FL_KP+'+'}, { 78, FL_KP+'-' }, { 65, FL_KP+'.' }, { 75, FL_KP+'/' }, { 82, FL_KP+'0' }, { 83, FL_KP+'1' }, { 84, FL_KP+'2' }, { 85, FL_KP+'3' }, { 86, FL_KP+'4' }, { 87, FL_KP+'5' }, { 88, FL_KP+'6' }, { 89, FL_KP+'7' }, @@ -64,7 +64,7 @@ static const struct {unsigned short vk, fltk;} vktab[] = { { 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 }, + { 58, FL_Alt_L }, { 58, FL_Alt_R }, /*{ 0x75, FL_Delete },*/ { 0x47, FL_Delete }, }; static int fltk2mac(int fltk) { diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx index f17e79cb7..a7835881a 100644 --- a/src/Fl_mac.cxx +++ b/src/Fl_mac.cxx @@ -156,7 +156,7 @@ static unsigned short macKeyLookUp[128] = 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, - 0, FL_KP+'.', FL_Right, FL_KP+'*', 0, FL_KP+'+', FL_Left, FL_Num_Lock, + 0, FL_KP+'.', FL_Right, FL_KP+'*', 0, FL_KP+'+', FL_Left, FL_Delete, FL_Down, 0, 0, FL_KP+'/', FL_KP_Enter, FL_Up, FL_KP+'-', 0, 0, FL_KP+'=', FL_KP+'0', FL_KP+'1', FL_KP+'2', FL_KP+'3', FL_KP+'4', FL_KP+'5', @@ -1234,6 +1234,34 @@ static int keycode_wrap_old( static int (*keycode_function)(char*, int, EventKind, UInt32, UInt32, UInt32*, unsigned char, unsigned short) = keycode_wrap_old; +// EXPERIMENTAL! +pascal OSStatus carbonTextHandler( + EventHandlerCallRef nextHandler, EventRef event, void *userData ) +{ + Fl_Window *window = (Fl_Window*)userData; + Fl::first_window(window); + fl_lock_function(); + int kind = GetEventKind(event); + unsigned short buf[200]; + ByteCount size; + GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, + NULL, 100, &size, &buf ); +// printf("TextEvent: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]); + // FIXME: oversimplified! + unsigned ucs = buf[0]; + char utf8buf[20]; + int len = fl_utf8encode(ucs, utf8buf); + Fl::e_length = len; + Fl::e_text = utf8buf; + while (window->parent()) window = window->window(); + Fl::handle(FL_KEYBOARD, window); + fl_unlock_function(); + fl_lock_function(); + Fl::handle(FL_KEYUP, window); + fl_unlock_function(); + return noErr; +} + /** * handle carbon keyboard events */ @@ -1256,7 +1284,7 @@ pascal OSStatus carbonKeyboardHandler( NULL, sizeof(UInt32), NULL, &mods ); // get the key code only for key events - UInt32 keyCode = 0; + UInt32 keyCode = 0, maskedKeyCode = 0; unsigned char key = 0; unsigned short sym = 0; if (kind!=kEventRawKeyModifiersChanged) { @@ -1265,7 +1293,12 @@ pascal OSStatus carbonKeyboardHandler( GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key ); } - /* output a human readable event identifier for debugging + // extended keyboards can also send sequences on key-up to generate Kanji etc. codes. + // Some observed prefixes are 0x81 to 0x83, followed by an 8 bit keycode. + // In this mode, there seem to be no key-down codes +// printf("%08x %08x %08x\n", keyCode, mods, key); + maskedKeyCode = keyCode & 0x7f; + /* output a human readable event identifier for debugging */ const char *ev = ""; switch (kind) { case kEventRawKeyDown: ev = "kEventRawKeyDown"; break; @@ -1274,8 +1307,8 @@ pascal OSStatus carbonKeyboardHandler( case kEventRawKeyModifiersChanged: ev = "kEventRawKeyModifiersChanged"; break; default: ev = "unknown"; } - printf("%08x %08x %08x '%c' %s \n", mods, keyCode, key, key, ev); - */ +// printf("%08x %08x %08x '%c' %s \n", mods, keyCode, key, key, ev); +// */ switch (kind) { case kEventRawKeyDown: @@ -1311,12 +1344,13 @@ pascal OSStatus carbonKeyboardHandler( else if ( Fl::e_state&FL_CTRL && key<32 ) sym = key+96; else if ( Fl::e_state&FL_ALT ) // find the keycap of this key - sym = keycode_to_sym( keyCode & 0x7f, 0, macKeyLookUp[ keyCode & 0x7f ] ); + sym = keycode_to_sym( maskedKeyCode, 0, macKeyLookUp[ maskedKeyCode ] ); else - sym = macKeyLookUp[ keyCode & 0x7f ]; + sym = macKeyLookUp[ maskedKeyCode ]; Fl::e_keysym = Fl::e_original_keysym = sym; // Handle FL_KP_Enter on regular keyboards and on Powerbooks - if ( keyCode==0x4c || keyCode==0x34) key=0x0d; + if ( maskedKeyCode==0x4c || maskedKeyCode==0x34) key=0x0d; + // Handle the Delete key on the keypad // Matt: the Mac has no concept of a NumLock key, or at least not visible // Matt: to Carbon. The kEventKeyModifierNumLockMask is only set when // Matt: a numeric keypad key is pressed and does not correspond with @@ -1850,19 +1884,36 @@ static OSErr fillCurrentDragData(DragReference dragRef) FlavorFlags flags; Size itemSize, size = 0; CountDragItems( dragRef, &nItem ); + for ( i = 1; i <= nItem; i++ ) { GetDragItemReferenceNumber( dragRef, i, &itemRef ); + ret = GetFlavorFlags( dragRef, itemRef, 'utf8', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utf8', &itemSize ); + size += itemSize; + continue; + } + ret = GetFlavorFlags( dragRef, itemRef, 'utxt', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utxt', &itemSize ); + size += itemSize; + continue; + } ret = GetFlavorFlags( dragRef, itemRef, 'TEXT', &flags ); if ( ret == noErr ) { GetFlavorDataSize( dragRef, itemRef, 'TEXT', &itemSize ); size += itemSize; + continue; } ret = GetFlavorFlags( dragRef, itemRef, 'hfs ', &flags ); if ( ret == noErr ) { size += 1024; //++ ouch! We should create the full pathname and figure out its length + continue; } } @@ -1878,6 +1929,25 @@ static OSErr fillCurrentDragData(DragReference dragRef) for ( i = 1; i <= nItem; i++ ) { GetDragItemReferenceNumber( dragRef, i, &itemRef ); + ret = GetFlavorFlags( dragRef, itemRef, 'utf8', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utf8', &itemSize ); + GetFlavorData( dragRef, itemRef, 'utf8', dst, &itemSize, 0L ); + dst += itemSize; + *dst++ = '\n'; // add our element separator + continue; + } + GetDragItemReferenceNumber( dragRef, i, &itemRef ); + ret = GetFlavorFlags( dragRef, itemRef, 'utxt', &flags ); + if ( ret == noErr ) + { + GetFlavorDataSize( dragRef, itemRef, 'utxt', &itemSize ); + GetFlavorData( dragRef, itemRef, 'utxt', dst, &itemSize, 0L ); + dst += itemSize; + *dst++ = '\n'; // add our element separator + continue; + } ret = GetFlavorFlags( dragRef, itemRef, 'TEXT', &flags ); if ( ret == noErr ) { @@ -1885,17 +1955,19 @@ static OSErr fillCurrentDragData(DragReference dragRef) GetFlavorData( dragRef, itemRef, 'TEXT', dst, &itemSize, 0L ); dst += itemSize; *dst++ = '\n'; // add our element separator + continue; } ret = GetFlavorFlags( dragRef, itemRef, 'hfs ', &flags ); if ( ret == noErr ) { HFSFlavor hfs; itemSize = sizeof( hfs ); GetFlavorData( dragRef, itemRef, 'hfs ', &hfs, &itemSize, 0L ); - itemSize = FSSpec2UnixPath( &hfs.fileSpec, dst ); + itemSize = FSSpec2UnixPath( &hfs.fileSpec, dst ); // return the path name in UTF8 dst += itemSize; if ( itemSize>1 && ( hfs.fileType=='fold' || hfs.fileType=='disk' ) ) *dst++ = '/'; *dst++ = '\n'; // add our element separator + continue; } } @@ -2185,6 +2257,7 @@ void Fl_X::make(Fl_Window* w) { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDragged } }; ret = InstallWindowEventHandler( x->xid, mouseHandler, 4, mouseEvents, w, 0L ); + EventHandlerUPP keyboardHandler = NewEventHandlerUPP( carbonKeyboardHandler ); // will not be disposed by Carbon... static EventTypeSpec keyboardEvents[] = { { kEventClassKeyboard, kEventRawKeyDown }, @@ -2192,6 +2265,12 @@ void Fl_X::make(Fl_Window* w) { kEventClassKeyboard, kEventRawKeyUp }, { kEventClassKeyboard, kEventRawKeyModifiersChanged } }; ret = InstallWindowEventHandler( x->xid, keyboardHandler, 4, keyboardEvents, w, 0L ); + + EventHandlerUPP textHandler = NewEventHandlerUPP( carbonTextHandler ); // will not be disposed by Carbon... + static EventTypeSpec textEvents[] = { + { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } }; + ret = InstallWindowEventHandler( x->xid, textHandler, 1, textEvents, w, 0L ); + EventHandlerUPP windowHandler = NewEventHandlerUPP( carbonWindowHandler ); // will not be disposed by Carbon... static EventTypeSpec windowEvents[] = { { kEventClassWindow, kEventWindowDrawContent }, diff --git a/src/fl_dnd_mac.cxx b/src/fl_dnd_mac.cxx index eaae1d149..af8cf1c58 100644 --- a/src/fl_dnd_mac.cxx +++ b/src/fl_dnd_mac.cxx @@ -51,7 +51,7 @@ int Fl::dnd() result = NewDrag( &dragRef ); if ( result != noErr ) return false; - result = AddDragItemFlavor( dragRef, 1, 'TEXT', fl_selection_buffer, fl_selection_length, 0 ); + result = AddDragItemFlavor( dragRef, 1, 'utf8', fl_selection_buffer, fl_selection_length, 0 ); if ( result != noErr ) { DisposeDrag( dragRef ); return false; } Point mp; diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx index ec0ed5832..fb7fe0f05 100644 --- a/src/fl_rect.cxx +++ b/src/fl_rect.cxx @@ -419,8 +419,8 @@ void fl_point(int x, int y) { SetPixel(fl_gc, x, y, fl_RGB()); #elif defined(__APPLE_QUARTZ__) if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); - CGContextMoveToPoint(fl_gc, x, y); - CGContextAddLineToPoint(fl_gc, x, y); + CGContextMoveToPoint(fl_gc, x-.5, y); // Quartz needs a line that is one pixel long, or it will not draw anything + CGContextAddLineToPoint(fl_gc, x+.5, y); CGContextStrokePath(fl_gc); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); #else diff --git a/src/fl_shortcut.cxx b/src/fl_shortcut.cxx index b0519d14f..050d454b2 100644 --- a/src/fl_shortcut.cxx +++ b/src/fl_shortcut.cxx @@ -95,9 +95,9 @@ int Fl::test_shortcut(int shortcut) { return 0; } -#if defined(WIN32) || defined(__APPLE__) // if not X // This table must be in numeric order by fltk (X) keysym number: struct Keyname {int key; const char* name;}; +#if defined(WIN32) static Keyname table[] = { {' ', "Space"}, {FL_BackSpace, "Backspace"}, @@ -131,6 +131,40 @@ static Keyname table[] = { {FL_Alt_R, "Alt_R"}, {FL_Delete, "Delete"} }; +#elif defined(__APPLE__) +static Keyname table[] = { + {' ', "Space"}, + {FL_BackSpace,"\xe2\x8c\xab"}, + {FL_Tab, "\xe2\x87\xa5"}, + {0xff0b/*XK_Clear*/, "Clear"}, + {FL_Enter, "\xe2\x86\xa9"}, + {FL_Pause, "Pause"}, + {FL_Scroll_Lock, "Scroll_Lock"}, + {FL_Escape, "\xe2\x90\x9b"}, + {FL_Home, "\xe2\x86\x96"}, + {FL_Left, "\xe2\x86\x90"}, + {FL_Up, "\xe2\x86\x91"}, + {FL_Right, "\xe2\x86\x92"}, + {FL_Down, "\xe2\x86\x93"}, + {FL_Page_Up, "\xe2\x87\x9e"}, // utf8 arrow up with two strokes + {FL_Page_Down,"\xe2\x87\x9f"}, // utf8 arrow down with two strokes + {FL_End, "\xe2\x86\x98"}, + {FL_Print, "Print"}, + {FL_Insert, "Insert"}, + {FL_Menu, "Menu"}, + {FL_Num_Lock, "Num_Lock"}, + {FL_KP_Enter, "\xe2\x86\xb5"}, + {FL_Shift_L, "Shift_L"}, + {FL_Shift_R, "Shift_R"}, + {FL_Control_L,"Control_L"}, + {FL_Control_R,"Control_R"}, + {FL_Caps_Lock,"\xe2\x87\xaa"}, // utf8 Caps Lock symbol + {FL_Meta_L, "Meta_L"}, + {FL_Meta_R, "Meta_R"}, + {FL_Alt_L, "Alt_L"}, + {FL_Alt_R, "Alt_R"}, + {FL_Delete, "\xe2\x8c\xa7"} +}; #endif /** @@ -158,9 +192,9 @@ const char* fl_shortcut_label(int shortcut) { } #ifdef __APPLE__ // \todo Mac : we might want to change the symbols for Mac users - consider drawing Apple Symbols... . - if (shortcut & FL_SHIFT) {strcpy(p,"\xe2\x87\xa7"); p += 3;} //: Mac hollow up arrow - if (shortcut & FL_CTRL) {strcpy(p,"^"); p += 1;} //: Mac ctrl key - if (shortcut & FL_ALT) {strcpy(p,"\xe2\x8e\x87"); p += 3;} //: Mac 'Alt/Option' or fancy switch symbol + if (shortcut & FL_SHIFT) {strcpy(p,"\xe2\x87\xa7"); p += 3;} //: Mac hollow up arrow + if (shortcut & FL_CTRL) {strcpy(p,"\xe2\x8c\x83"); p += 3;} //: Mac ctrl key + if (shortcut & FL_ALT) {strcpy(p,"\xe2\x8e\x87"); p += 3;} //: Mac 'Alt/Option' or fancy switch symbol if (shortcut & FL_META) {strcpy(p,"\xe2\x8c\x98"); p += 3;} //: Mac 'Apple' key #else if (shortcut & FL_META) {strcpy(p,"Meta+"); p += 5;} |
