o Modified example to take advantage of new Fl_Table::tab_cell_nav() method
o Changed behavior of example to be more predictable o Enter key can be used to toggle edit mode o User can navigate table cells with arrow keys or tab/shift-tab without slipping into cell edit mode o Fixed other issues with Alt, Shift, multicell selection.. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9842 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
81c20e30a4
commit
0ed7405c49
@ -58,8 +58,7 @@ public:
|
||||
values[r][c] = c + (r*MAX_COLS); // initialize cells
|
||||
end();
|
||||
row_edit = col_edit = 0;
|
||||
select_row = current_row = 0;
|
||||
select_col = current_col = 0;
|
||||
set_selection(0,0,0,0);
|
||||
}
|
||||
~Spreadsheet() { }
|
||||
|
||||
@ -76,6 +75,7 @@ public:
|
||||
void start_editing(int R, int C) {
|
||||
row_edit = R; // Now editing this row/col
|
||||
col_edit = C;
|
||||
set_selection(R,C,R,C); // Clear any previous multicell selection
|
||||
int X,Y,W,H;
|
||||
find_cell(CONTEXT_CELL, R,C, X,Y,W,H); // Find X/Y/W/H of cell
|
||||
input->resize(X,Y,W,H); // Move Fl_Input widget there
|
||||
@ -160,7 +160,7 @@ void Spreadsheet::draw_cell(TableContext context, int R,int C, int X,int Y,int W
|
||||
}
|
||||
// Background
|
||||
if ( C < cols()-1 && R < rows()-1 ) {
|
||||
fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, (R==row_edit && C==col_edit) ? FL_YELLOW : FL_WHITE);
|
||||
fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, is_selected(R,C) ? FL_YELLOW : FL_WHITE);
|
||||
} else {
|
||||
fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, 0xbbddbb00); // money green
|
||||
}
|
||||
@ -209,16 +209,19 @@ void Spreadsheet::event_callback2() {
|
||||
return;
|
||||
|
||||
case FL_KEYBOARD: // key press in table?
|
||||
switch (Fl::event_key()) {
|
||||
case FL_Escape: exit(0); // ESC closes app
|
||||
case FL_Shift_L: return; // ignore shift
|
||||
case FL_Shift_R: return;
|
||||
}
|
||||
if (C == cols()-1 || R == rows()-1) return; // no editing of totals column
|
||||
if ( Fl::event_key() == FL_Escape ) exit(0); // ESC closes app
|
||||
done_editing(); // finish any previous editing
|
||||
start_editing(R,C); // start new edit
|
||||
if (Fl::event() == FL_KEYBOARD && Fl::e_text[0] != '\r') {
|
||||
input->handle(Fl::event()); // pass keypress to input widget
|
||||
if (C==cols()-1 || R==rows()-1) return; // no editing of totals column
|
||||
switch ( Fl::e_text[0] ) {
|
||||
case '0': case '1': case '2': case '3': // any of these should start editing new cell
|
||||
case '4': case '5': case '6': case '7':
|
||||
case '8': case '9': case '+': case '-':
|
||||
start_editing(R,C); // start new edit
|
||||
input->handle(Fl::event()); // pass typed char to input
|
||||
break;
|
||||
case '\r': case '\n': // let enter key edit the cell
|
||||
start_editing(R,C); // start new edit
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -237,9 +240,13 @@ void Spreadsheet::event_callback2() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
Fl::option(Fl::OPTION_ARROW_FOCUS, 1); // we want arrow keys to navigate table's widgets
|
||||
Fl_Double_Window *win = new Fl_Double_Window(862, 322, "Fl_Table Spreadsheet");
|
||||
Spreadsheet *table = new Spreadsheet(10, 10, win->w()-20, win->h()-20);
|
||||
#if FLTK_ABI_VERSION >= 10303
|
||||
table->tab_cell_nav(1); // enable tab navigation of table cells (instead of fltk widgets)
|
||||
#endif
|
||||
table->tooltip("Use keyboard to navigate cells:\n"
|
||||
"Arrow keys or Tab/Shift-Tab");
|
||||
// Table rows
|
||||
table->row_header(1);
|
||||
table->row_header_width(70);
|
||||
|
Loading…
x
Reference in New Issue
Block a user