Hello,

After our discussion about Fl_Table focus problem (keyboard can move out 
the widget), i began to think about that.

I post here the notes i've taken.       

This covers only code and documentation found in 1.3 flavor of FLTK.
I used sources from Arch current package: fltk-1.3.0-source.tar.gz

As Greg said in http://www.fltk.org/str.php?L2862 :
« Fl_Table should honor the new Fl::option(OPTION_ARROW_FOCUS)
   flag for arrow key focus navigation as well »

This option can be set using two ways:

1) Text configuration (for every FLTK apps)
  see ~/.fltk/fltk.org/fltk.prefs for local configuration.
  I guess that for global configuration, you should look in /etc

  Those file configs can be edited by hand or with Fluid.
  They are loaded each time fltk app is launched, it's automatic.


2) Function (impact the running FLTK app only)
  in «Fl» class, you can read/set values of Fl_Option struct:
Fl_Option {
   OPTION_ARROW_FOCUS =
      0, OPTION_VISIBLE_FOCUS, OPTION_DND_TEXT, OPTION_SHOW_TOOLTIPS, 
OPTION_LAST
}

(extract from the documentation)
OPTION_ARROW_FOCUS      
When switched on, moving the text cursor beyond the start or end of a 
text in a text widget will change focus to the next text widget.
When switched off, the cursor will stop at the end of the text. Pressing 
Tab or Ctrl-Tab will advance the keyboard focus.

read with:  bool option (Fl_Option opt)
write with: void option (Fl_Option opt, bool val)

So we'd like that arrows keys in tables don't systematically focus to 
another widget, when we exceed the bounds of the table.
Fl_Table should test «OPTION_ARROW_FOCUS» for this.


The «old» FLTK 1.1 used a macro for deciding if the focus change at the 
end of a widget.
Since 1.3, this has changed.
At the beginning of Fl_Input.cxx, we have a new macro definition, using 
the API:

// NORMAL_INPUT_MOVE has been replaced by Fl::option(Fl::OPTION_ARROW_FOCUS)
// in FLTK 1.3.  This option has "inverted" values:
//   1 = Arrow keys move focus (previously 0)
//   0 = Arrow keys don't move focus (previously 1)
// Hence we define ...
//
#define NORMAL_INPUT_MOVE (Fl::option(Fl::OPTION_ARROW_FOCUS) ? 0 : 1)


It's used like this:

// Move cursor one character to the left
//    If OPTION_ARROW_FOCUS is disabled, return 1 to prevent focus 
navigation.
int Fl_Input::kf_move_char_left() {
   int i = shift_position(position()-1) + NORMAL_INPUT_MOVE;
   return Fl::option(Fl::OPTION_ARROW_FOCUS) ? i : 1;
}


Now, let's go to Fl_Table.H

This function seems interesting:

int Fl_Table::move_cursor(int R, int C)

It is called by the «FL_KEYBOARD» event in the Fl_Table event handler.
( int Fl_Table::handle(int event) )

Here is what i suggest:

#define CANNOT_CHANGE_FOCUS_WITH_KEYBOARD 
(Fl::option(Fl::OPTION_ARROW_FOCUS) ? 0 : 1)
int Fl_Table::move_cursor(int R, int C) {
   if (select_row == -1) R++;
   if (select_col == -1) C++;
   R += select_row;
   C += select_col;

  //JSeb : start of modifications
   if (CANNOT_CHANGE_FOCUS_WITH_KEYBOARD) {
     if (R==-1 || C==-1 || R >= rows() || C >= cols()) return 1; //JSEB
   }
   //JSeb : end of modifications

   if (R < 0) R = 0;
   if (R >= rows()) R = rows() - 1;
   if (C < 0) C = 0;
   if (C >= cols()) C = cols() - 1;
   if (R == select_row && C == select_col) return 0;
   damage_zone(current_row, current_col, select_row, select_col, R, C);
   select_row = R;
   select_col = C;
   if (!Fl::event_state(FL_SHIFT)) {
     current_row = R;
     current_col = C;
   }
   if (R < toprow + 1 || R > botrow - 1) row_position(R);
   if (C < leftcol + 1 || C > rightcol - 1) col_position(C);
   return 1;
}


It seems to work. I've compiled the «patched» fltk lib, and test it with 
Greg's «foo_v2.cxx» sample (see str #2862).
Focus don't change anymore with keyboard when «arrow keys move focus» is 
set to default with Fluid.
I tried and force «on» (still with Fluid user config writer) the «arrow 
keys move focus» : now, cursor keys and tab can move focus outside the 
widget.

Please, tell me if you think the changes are correct.


_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to