Hello,
I am trying to create a menu-like window which pops up when the user 
interacts with a search field in a modal window. I have created an 
example which you should be able to compile after copy & paste (if the 
mail client doesn't break the lines). What I need help with is how to 
get the green window behave like a modal one (as far as not letting the 
main window with the "Click me" button work), but let the button in the 
search popup work.

Thank you in advance,
/Daniel

#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 
make 
this button work\n(And the the input field in the\ngreen window at the 
same time)?");
                aButton->align(FL_ALIGN_TOP);
                end();
        }       
};

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_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();
        }

        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

Reply via email to