c++ - FLTK: Event when a window gets focus on MacOS -
using fltk, i'm writing desktop application uses multiple windows. application manages list of open windows , shows them in menu these lines:
for( int = 0; < windows.size(); ++i ) { menu->add(("&windows/"+windows[i].name).c_str(), 0, mymenucallback); }
now want set checkmark in front of name of top-most window:
flags = fl_menu_toggle|fl_menu_value; menu->add(("&windows/"+windows[i].name).c_str(), 0, mymenucallback, 0, flags);
i'm stuck @ installing event handler gets called whenever top-most window changes. hoping fl::add_handler( &genericeventhandler );
called whenever focus changes, not case. so, question is: how notified, when focus of windows changes?
you should subclass fl_window override handle method monitor fl_focus , fl_unfocus events. here sample:
class mywindow : public fl_window { public: mywindow(int x,int y,int w,int h, const char* title) : fl_window (x, y, w, h, title) {} int handle(int e) { switch(e) { case fl_focus: std::cout << "window " << label() << " focused" << std::endl; break; case fl_unfocus: std::cout << "window " << label() << " has lost focus" << std::endl; break; } return(fl_window::handle(e)); } }; int main() { mywindow win1(100, 100, 200,200, "window 1"); win1.show(); mywindow win2(350, 100, 200,200, "window 2"); win2.show(); return fl::run(); }
Comments
Post a Comment