When I though I had it all sorted out I ran into problems. Compiled and
tested it in linux and it seems that window focus is handled differently
in windows / linux. I modified the code from the original post to
describe the new problem.
The code works perfect in windows, but in linux the focus gets lost. I
have tried everything I could imagine, but can't keep the focus in the
green window after opening up the yellow one.
Can I force the cursor/focus to the input field some way?
Here is the updated code:
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
class SearchPopup : public Fl_Double_Window {
public:
SearchPopup(int X, int Y) : Fl_Double_Window(X, Y, 300, 180) {
color(FL_YELLOW);
border(0);
set_non_modal();
Fl_Button* aButton = new Fl_Button(100, 50, 50, 50, "How can I
retain
focus in the Fl_Input\nin the green window after opening\nthe yellow
window? (doesn't work\nin linux)");
aButton->align(FL_ALIGN_BOTTOM);
}
};
static void staticInputCB(Fl_Widget *w, void *data);
class SearchWindow : public Fl_Double_Window {
private:
Fl_Input* myInput;
SearchPopup* mySearchPopup;
int xoff, yoff;
public:
SearchWindow(int X, int Y) : Fl_Double_Window(X, Y, 300, 180) {
border(0);
color(FL_GREEN);
set_non_modal();
myInput = new Fl_Input(50, 50, 200, 30, "Enter text to open a
result
window");
myInput->callback(staticInputCB, (void*)this);
myInput->when(FL_WHEN_CHANGED);
myInput->align(FL_ALIGN_TOP_LEFT);
end();
mySearchPopup = new SearchPopup(300, 300);
mySearchPopup->end();
}
void dynamicInputCB(Fl_Widget *w){
mySearchPopup->position(myInput->x()+this->x(),
myInput->y()+myInput->h()+this->y());
mySearchPopup->show();
this->show(); //tried many things...
this->take_focus(); //...to get the focus..
myInput->take_focus(); //...back to the green window. Nothing
seems to
work..?
}
int handle(int event) {
int ret = Fl_Double_Window::handle(event);
switch ( event ){
case FL_PUSH:
xoff = x() - Fl::event_x_root();
yoff = y() - Fl::event_y_root();
ret = 1;
case FL_DRAG:
position(xoff + Fl::event_x_root(), yoff +
Fl::event_y_root());
mySearchPopup->position(myInput->x()+this->x(),
myInput->y()+myInput->h()+this->y());
ret = 1;
}
return(ret);
}
};
static void staticInputCB(Fl_Widget *w, void *data){
SearchWindow *o = (SearchWindow*)data;
o->dynamicInputCB(w);
}
SearchWindow* aSearchWindow;
void Button_CB(Fl_Widget*, void*) {
aSearchWindow->show();
}
int main() {
Fl_Double_Window win(300, 300);
Fl_Button* aButton = new Fl_Button(100, 120, 100, 50, "Click me");
aButton->callback(Button_CB);
win.end();
aSearchWindow = new SearchWindow(100, 100);
aSearchWindow->end();
win.show();
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk