From b214cef3a8d2d9ecf0df7bef7d10dcdfbca4d9d3 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 14 Apr 2009 08:18:52 +0000 Subject: Implemented the full OS X navigation support for Fl_Input minus scrolling. Improved navigation on other systems (word fwd, backwd). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6764 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 2 +- src/Fl_Input.cxx | 140 +++++++++++++++++++++++++++++++++++++++++------------- src/Fl_Input_.cxx | 2 + 3 files changed, 110 insertions(+), 34 deletions(-) diff --git a/CHANGES b/CHANGES index ae920645e..932027936 100644 --- a/CHANGES +++ b/CHANGES @@ -1,10 +1,10 @@ CHANGES IN FLTK 1.3.0 + - Added improved OS X cursor control to Fl_Input (STR #2169) - Fix for multiple popups, when dragging and calling fl_alert() and friends from the callback (STR #2159) - Avoiding crashes for recursive common dialogs (this does not fix the issue at hand yet) (STR #1986, 2150) - - Added OS X cursor control to Fl_Input (STR #2169) - Fixed control key keycodes with modifiers on OS X - Added menu shortcut alignment for OS X - Fixed bad system menu hadling in OS X (STR #2153) diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index 71434a25e..1ebda7d85 100644 --- a/src/Fl_Input.cxx +++ b/src/Fl_Input.cxx @@ -140,83 +140,157 @@ int Fl_Input::handle_key() { return 1; } + unsigned int mods = Fl::event_state() & (FL_META|FL_CTRL|FL_ALT); switch (Fl::event_key()) { case FL_Insert: if (Fl::event_state() & FL_CTRL) ascii = ctrl('C'); else if (Fl::event_state() & FL_SHIFT) ascii = ctrl('V'); break; - case FL_Delete: + case FL_Delete: // FIXME if (Fl::event_state() & FL_SHIFT) ascii = ctrl('X'); else ascii = ctrl('D'); break; case FL_Left: - ascii = ctrl('B'); #ifdef __APPLE__ - if (Fl::event_state() & (FL_META|FL_CTRL) ) ascii = ctrl('A'); - // FIXME backward one word is missing (Alt-Left) -#endif // __APPLE__ + if (mods==0) { // char left + ascii = ctrl('B'); + } else if (mods==FL_ALT) { // word left + shift_position(word_start(position())); + return 1; + } else if (mods==FL_CTRL || mods==FL_META) { // start of line + shift_position(line_start(position())); + return 1; + } else return 1; +#else + if (mods==0) { // char left + ascii = ctrl('B'); + } else if (mods==FL_CTRL) { // word left + shift_position(word_start(position())); + return 1; + } else return 1; +#endif break; case FL_Right: - ascii = ctrl('F'); #ifdef __APPLE__ - if (Fl::event_state() & (FL_META|FL_CTRL) ) ascii = ctrl('E'); - // FIXME advance one word is missing (Alt-Right) + if (mods==0) { // char right + ascii = ctrl('F'); + } else if (mods==FL_ALT) { // word right + shift_position(word_end(position())); + return 1; + } else if (mods==FL_CTRL || mods==FL_META) { // end of line + shift_position(line_end(position())); + return 1; + } else return 1; +#else + if (mods==0) { // char right + ascii = ctrl('F'); + } else if (mods==FL_CTRL) { // word right + shift_position(word_end(position())); + return 1; + } else return 1; #endif // __APPLE__ break; - case FL_Page_Up: + case FL_Page_Up: // FIXME fl_font(textfont(),textsize()); //ensure current font is set to ours repeat_num=h()/fl_height(); // number of lines to scroll if (!repeat_num) repeat_num=1; case FL_Up: - ascii = ctrl('P'); #ifdef __APPLE__ - if (Fl::event_state() & (FL_META) ) { - shift_position(0); - return 1; - } - if (Fl::event_state() & (FL_ALT) ) { + if (mods==0) { // line up + ascii = ctrl('P'); + } else if (mods==FL_CTRL) { + return 1; // FIXME scroll text down one page + // FIXME Fl_Inut_ does not support an independent scroll value + // (heck, it doesn't even support a scrollbar - what do you expect ;-) + } else if (mods==FL_ALT) { // line start and up if (line_start(position())==position() && position()>0) return shift_position(line_start(position()-1)) + NORMAL_INPUT_MOVE; else return shift_position(line_start(position())) + NORMAL_INPUT_MOVE; - } -#endif // __APPLE__ + } else if (mods==FL_META) { // start of document + shift_position(0); + return 1; + } else return 1; +#else + if (mods==0) { // line up + ascii = ctrl('P'); + } else if (mods==FL_CTRL) { + return 1; // FIXME scroll text down one line + } else return 1; +#endif break; - case FL_Page_Down: + case FL_Page_Down: // FIXME fl_font(textfont(),textsize()); repeat_num=h()/fl_height(); if (!repeat_num) repeat_num=1; case FL_Down: - ascii = ctrl('N'); #ifdef __APPLE__ - if (Fl::event_state() & (FL_META) ) { - shift_position(size()); - return 1; - } - if (Fl::event_state() & (FL_ALT) ) { + if (mods==0) { // line down + ascii = ctrl('N'); + } else if (mods==FL_CTRL) { + return 1; // FIXME scroll text up one page + } else if (mods==FL_ALT) { // line end and down if (line_end(position())==position() && position()= size() || !isword(index(i))) // while (i > 0 && !isword(index(i-1))) i--; + while (i > 0 && !isword(index(i-1))) i--; while (i > 0 && isword(index(i-1))) i--; return i; } -- cgit v1.2.3