This method works except for 1 UI flaw and 1 obvious inefficiency, both of which are described under switch(e) I know can't be doing it quite right. I have tried test_shortcut; no idea whether it's appropriate or what is the correct usage.
All the shortcuts keys are created here
class Appmenu : public Fl_Menu_Bar {
public:
Appmenu(App *app) : Fl_Menu_Bar(... dims ...) {
add("menu/save", FL_CTRL + 's', save_cb, app); // app is the main and only application window
.
.
.
}
};
App *app also contains an Fl_Group which contains > 200 subclassed Fl_Boxes. I have written no explicit event handling in the Fl_Group.
If I do, the Group is going to get all the events before the Boxes do, and that will open a whole 'nother can of worms.
class Cell : public Fl_Box {
public:
BrdCell(...) : Fl_Box(...) {
...
}
int handle(int e) { return brd_handle(this, e); }
static int brd_handle(Cell *cell, int e);
};
int Cell::brd_handle(Cell *cell, int e) {
#define S_NORM 0x100000 // raw bits of event states. to do: also detect capslock
// The inefficiency is here in FL_SHORTCUT: every sibling cell is checked to see if it will handle the shortcut.
// Eventually the menu widget is checked and the shortcut happens.
// And i suppose this is also the source of the UI problem, wherein after all the searching about, if a shortcut function involves another
// cell taking focus, the old cell will not receive FL_UNFOCUS (leaving it highlighted). // ***************************************************************************************************************************************
case FL_SHORTCUT: return EVNOTHANDLED; // also need ctrl+key to return nothandled for shortcuts to work
case FL_KEYBOARD:
switch(s) {
case S_NORM:
{ block-specific vars defined here
if k is alpha {
do stuff;
cell->redraw();
}
else {
if k == delete, tab, arrows {
box label gets deleted or one of various sibling cells ->take_focus()
or if the cell that is graphically last has focus, then text editor ->take_focus() (an uncle to the box widgets)
}
}
}
break;
case S_SHFT: cout << "brd state=shift" << endl; break;
case S_CTRL: cout << "brd state=ctrl" << endl; return EVNOTHANDLED; // seems to be necessary for shortcuts
case S_ALT: cout << "brd state=alt" << endl; break;
// default: not currently coded
} // end switch (state)
break;
case FL_FOCUS:
cell->color(hilite); cell->redraw(); break; // hilite colorapplies to all cells andisassigned per user option, elsewhere.
case FL_UNFOCUS:
cell->color(cell->lolite); cell->redraw(); break;// lolite color applies per cell
case FL_PUSH:
cell->take_focus(); break;
case FL_RELEASE: case FL_MOVE: case FL_ENTER:// remainder of events are ignored
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.