Hi, Here is a similar demo program for fltk 1.1x. You type in an input in one
window, and as soon as you type it pops up another window with an input, and it
retains the focus, and as you continue typing, it updates the text in the
second window.
#include <FL/Fl.h>
#include <FL/Fl_Window.h>
#include <FL/Fl_Input.h>
#include <Fl/Fl_Button.h>
#include <iostream>
Fl_Window *win;
Fl_Input *in;
Fl_Window *ext_win;
Fl_Input *ext_in;
Fl_Button *hide_button;
void hide_cb(Fl_Widget *w,void *d){
if(ext_win->visible())
ext_win->hide();
}
void in_cb(Fl_Widget *w,void *d){
if(!ext_win->visible())
ext_win->show();
ext_in->value(in->value());
in->take_focus();
}//in_cb
int main(void){
win=new Fl_Window(0,100,100,30,"window");
in=new Fl_Input(0,0,100,30);
in->callback(in_cb,0);
in->when(FL_WHEN_CHANGED);
win->end();
win->show();
ext_win=new Fl_Window(0,0,300,50,"extended window");
ext_in=new Fl_Input(0,0,300,30);
hide_button=new Fl_Button(5,35,45,15,"Hide");
hide_button->callback(hide_cb);
ext_win->end();
ext_win->hide();//see comment below
return Fl::run();
}
BTW I noticed that if I don't explicitly hide this window ext_win->visible()
returns 1, even though the window is not shown.. is this a feature or a bug?
> Hi. I have main window which has input in it, and it should as soon as
> something is typed in the input box, popup new borderless window (child of
> main) with browser in it, with that what is typed in input box added in
> browsers.
>
> When I type the first character in input box, child window with browser in it,
> which added that character, pops up but focus is not on input anymore, so I
> have to click on input and continue typing after which focus stays on input.
>
> But how can I prevent losing focus even that first time (after first typed
> character), because it is expected that user should continuously type the
> whole word in input box, not first one character and then switch manually to
> input again and continue typing?
>
> I'm using FLTK 2.x and piece of code in question is bellow:
> --- Begin ---
> void MainWindow::cb_wordInput_i() { // callback, called "WHEN_CHANGED"
> // wordInput is fltk::Input
> if (wordInput->size()) {
> browser->add(wordInput->value());
> browserWindow->show();
> wordInput->take_focus(); // I've tried and focus(wordInput)
> // also, from <fltk/events.h>
> } else {
> browser->clear();
> browserWindow->hide();
> }
> }
> --- End ---
>
> Thanks in advance.
>
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk