|
|
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 #define S_SHFT 0x110000 #define S_CTRL 0x140000 #define S_ALT 0x180000 #define EVNOTHANDLED 0 #define EVHANDLED 1
int s = Fl::event_state(); int k = Fl::event_key();
switch(e) {
// ***************************************************************************************************************************************
// 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 color applies to all cells and is assigned 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 case FL_LEAVE: case FL_SHOW: case FL_HIDE: case FL_KEYUP: case FL_DRAG: case FL_ACTIVATE: case FL_DEACTIVATE: case FL_NO_EVENT: break; default: cout << "wha???" << endl;
} // end switch(event)
return EVHANDLED;
}
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/CAPdW6bLLxYaZi6KxMT74GYWEPYogqp-8xeieCBkXohnD9u4Z1w%40mail.gmail.com.
[ Direct Link to Message ] | |
|
| |