diff options
| -rw-r--r-- | FL/Fl_Table.H | 37 | ||||
| -rw-r--r-- | src/Fl_Table.cxx | 20 |
2 files changed, 52 insertions, 5 deletions
diff --git a/FL/Fl_Table.H b/FL/Fl_Table.H index 28836c9a0..cf6519fcc 100644 --- a/FL/Fl_Table.H +++ b/FL/Fl_Table.H @@ -210,6 +210,12 @@ private: #if FLTK_ABI_VERSION >= 10301 int _scrollbar_size; #endif +#if FLTK_ABI_VERSION >= 10303 + enum { + TABCELLNAV = 1<<0, ///> tab cell navigation flag + }; + unsigned int flags_; +#endif // An STL-ish vector without templates class FL_EXPORT IntVector { @@ -823,6 +829,7 @@ public: int is_selected(int r, int c); // selected cell void get_selection(int &row_top, int &col_left, int &row_bot, int &col_right); void set_selection(int row_top, int col_left, int row_bot, int col_right); + int move_cursor(int R, int C, int shiftselect); int move_cursor(int R, int C); /** @@ -1107,6 +1114,36 @@ public: _scrollbar_size = newSize; } #endif +#if FLTK_ABI_VERSION >= 10303 + /** + Flag to control if Tab navigates table cells or not. + + If on, Tab key navigates table cells. + If off, Tab key navigates fltk widget focus. (default) + + As of fltk 1.3, the default behavior of the Tab key is to navigate focus off + the current widget, and on to the next one. But in some applications, + it's useful for Tab to be used to navigate cells in the Fl_Table. + + \param [in] val If \p val is 1, Tab key navigates cells in table, not fltk widgets.<BR> + If \p val is 0, Tab key will advance focus to the next fltk widget (default), and does not navigate cells in table. + */ + void tab_cell_nav(int val) { + if ( val ) flags_ |= TABCELLNAV; + else flags_ &= ~TABCELLNAV; + } + + /** + Get state of fltk widget tab navigation flag. + + \returns 1 if Tab configured to navigate widget focus (default) or 0 for Tab to navigate table cells. + + \see tab_cell_nav(int) + */ + int tab_cell_nav() const { + return(flags_ & TABCELLNAV ? 1 : 0); + } +#endif }; #endif /*_FL_TABLE_H*/ diff --git a/src/Fl_Table.cxx b/src/Fl_Table.cxx index d608aa189..a351d5ef3 100644 --- a/src/Fl_Table.cxx +++ b/src/Fl_Table.cxx @@ -131,6 +131,9 @@ Fl_Table::Fl_Table(int X, int Y, int W, int H, const char *l) : Fl_Group(X,Y,W,H #if FLTK_ABI_VERSION >= 10301 _scrollbar_size = 0; #endif +#if FLTK_ABI_VERSION >= 10303 + flags_ = 0; // TABCELLNAV off +#endif box(FL_THIN_DOWN_FRAME); vscrollbar = new Fl_Scrollbar(x()+w()-Fl::scrollbar_size(), y(), @@ -674,7 +677,7 @@ void Fl_Table::damage_zone(int r1, int c1, int r2, int c2, int r3, int c3) { redraw_range(R1, R2, C1, C2); } -int Fl_Table::move_cursor(int R, int C) { +int Fl_Table::move_cursor(int R, int C, int shiftselect) { if (select_row == -1) R++; if (select_col == -1) C++; R += select_row; @@ -687,7 +690,7 @@ int Fl_Table::move_cursor(int R, int C) { damage_zone(current_row, current_col, select_row, select_col, R, C); select_row = R; select_col = C; - if (!Fl::event_state(FL_SHIFT)) { + if (!shiftselect || !Fl::event_state(FL_SHIFT)) { current_row = R; current_col = C; } @@ -696,7 +699,11 @@ int Fl_Table::move_cursor(int R, int C) { return 1; } -// #define DEBUG 1 +int Fl_Table::move_cursor(int R, int C) { + return move_cursor(R,C,1); +} + +//#define DEBUG 1 #ifdef DEBUG #include <FL/names.h> #define PRINTEVENT \ @@ -1020,10 +1027,13 @@ int Fl_Table::handle(int event) { ret = move_cursor(1, 0); break; case FL_Tab: +#if FLTK_ABI_VERSION >= 10303 + if ( !tab_cell_nav() ) break; // not navigating cells? let fltk handle it (STR#2862) +#endif if ( _event_state & FL_SHIFT ) { - ret = move_cursor(0, -1); // shift-tab -> left + ret = move_cursor(0, -1, 0); // shift-tab -> left } else { - ret = move_cursor(0, 1); // tab -> right + ret = move_cursor(0, 1, 0); // tab -> right } break; } |
