Hmm, to answer the question in the subject, which is how to call
one callback from another, you can call the second widget's callback
directly via thewidget->do_callback(), since all FLTK widgets inherit
from Fl_Widget.
http://fltk.org/documentation.php/doc-1.1/Fl_Widget.html#Fl_Widget.do_callback
But based on the below, I'm not sure you want one callback to call
another..
steve wrote:
> I am very new to FLTK and c++ programming in general.
>
> I have designed a program that uses a file chooser.
> I would like the contents of the selected file to appear in a multiline input
> widget I created.
>
> I have figured out how to access the contents of the chosen file using the
> text() method of the Text Buffer.
>
Sounds like your 'multiline input widget' is the usual combo of an
Fl_Text_Editor + Fl_Text_Buffer.
So you would want to use the Fl_Text_Buffer's text()/append() methods
to set/append the chosen filename to the widget.
Typically an Fl_Text_Editor widget is tied to the Fl_Text_Buffer class
once during construction of the classes:
Fl_Text_Buffer *buff = new Fl_Text_Buffer();
Fl_Text_Editor *edit = new Fl_Text_Editor(20, 20, 640-40, 480-40);
edit->buffer(buff); // tie the two together
..so whenever you call e.g. buff->append(), the editor will reflect
the change (since the buffer and editor are tied together).
Presumably you are getting the filename back from the file chooser
via the file chooser's callback.
So in that callback, you would call buff->append() to add the filename
from the chooser.
This would mean the 'buff' pointer variable would need to be
accessible to the callback, either via the callback's user_data()
or by it being visible to the callback by means of the callback and
'buff' pointer sharing the same class. eg:
class YourApplication ..
{
Fl_Text_Buffer *buff;
Fl_Text_Editor *edit;
Fl_File_Chooser *choo;
..
void Chooser_CB() {
buff->append(choo->value());
}
..it is assumed you've set up the callback to be non-static in the
'usual way', so that it has access to both the buffer and chooser
widgets.
The 'usual way; being:
class YourApplication {
Fl_Text_Buffer *buff;
Fl_Text_Editor *edit;
Fl_File_Chooser *choo;
void Chooser_CB() { // non static callback
buff->append(choo->value()); // both buff and choo are visible
}
static void Chooser_Static_CB(Widget *w, void *userdata) { // static
callback
YourApplication *o = (YourApplication*)userdata; // userdata to
resolve 'this'
o->Chooser_CB(); // call
non-static callback
}
public:
YourApplication() { // CTOR
..
choo->callback(Chooser_Static_CB, (void*)this);
}
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk