|
Documentation |
Brief Documentation (ver 0.0.1)For now I only wrote brief text about this new callback system. This document is very brief description of FLTKCallback++ and my English is far from perfect so it could be confusing. You must be familiar with C++ templates, function pointers and member function pointers. I will soon write short user manual which will be more useful. Table of contexst
UsageExample:First here is one example: full test1.h:
#ifndef test1_h
#define test1_h
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Output.H>
#include <FL/fl_message.H>
#include <iostream>
void fl_func_stdG(Fl_Widget *w, void *d);
void fl_func_0G(void);
int fl_funcR_0G(void);
void fl_func_1G(int i);
float fl_funcR_1G(int i);
void fl_func_2G(char p, int i);
int fl_funcR_2G(int i, float ff);
class TestUI {
public:
TestUI();
private:
Fl_Window *main_window;
Fl_Button *FStd;
Fl_Button *F0;
Fl_Button *F1;
Fl_Button *FR1;
Fl_Button *F2;
Fl_Button *FR2;
Fl_Button *FStdG;
Fl_Button *F0G;
Fl_Button *F1G;
Fl_Button *FR1G;
Fl_Button *F2G;
Fl_Button *FR2G;
Fl_Output *output;
Fl_Button *FR0;
Fl_Button *FR0G;
public:
void fl_func_std(Fl_Widget *w, void *d);
void fl_func_0(void);
int fl_funcR_0(void);
void fl_func_1(int i);
float fl_funcR_1(int i);
void fl_func_2(char p, int i);
int fl_funcR_2(int i, float ff);
void show(void);
};
#endif
part (constructor definition of TestUI) of test1.cxx:
Fl_Window* w;
{Fl_Window* o = main_window = new Fl_Window(317, 284, "FLTKCallback++ test1");
w = o;
o->user_data((void*)(this));
FStd = new Fl_Button(10, 15, 145, 25, "Fl_Func_Std");
FStd->callback(Fl_Callback_C(this, &TestUI::fl_func_std));
F0 = new Fl_Button(10, 45, 145, 25, "Fl_Func_0");
F0->callback(Fl_Callback_C(this, &TestUI::fl_func_0));
F1 = new Fl_Button(10, 105, 145, 25, "Fl_Func_1");
F1->callback(Fl_Callback_C(this, &TestUI::fl_func_1, 10));
FR1 = new Fl_Button(10, 135, 145, 25, "Fl_FuncR_1");
FR1->callback(Fl_Callback_C(this, &TestUI::fl_funcR_1, 10));
F2 = new Fl_Button(10, 165, 145, 25, "Fl_func_2");
F2->callback(Fl_Callback_C(this, &TestUI::fl_func_2, 'c', 5));
FR2 = new Fl_Button(10, 195, 145, 25, "Fl_FuncR_2");
FR2->callback(Fl_Callback_C(this, &TestUI::fl_funcR_2, 5, (float)1.1));
FStdG = new Fl_Button(165, 15, 140, 25, "Fl_Func_StdG");
FStdG->callback(Fl_Callback_C(fl_func_stdG));
F0G = new Fl_Button(165, 45, 140, 25, "Fl_Func_0G");
F0G->callback(Fl_Callback_C(fl_func_0G));
F1G = new Fl_Button(165, 105, 140, 25, "Fl_Func_1G");
F1G->callback(Fl_Callback_C(fl_func_1G, 10));
FR1G = new Fl_Button(165, 135, 140, 25, "Fl_FuncR_1G");
FR1G->callback(Fl_Callback_C(fl_funcR_1G, 5));
F2G = new Fl_Button(165, 165, 140, 25, "Fl_Func_2G");
F2G->callback(Fl_Callback_C(fl_func_2G, 'c', 3));
FR2G = new Fl_Button(165, 195, 140, 25, "Fl_FuncR_2G");
FR2G->callback(Fl_Callback_C(fl_funcR_2G, 3, (float)1.2345));
{ Fl_Output* o = output = new Fl_Output(10, 250, 290, 25, "Button outputs");
o->align(FL_ALIGN_TOP);
}
FR0 = new Fl_Button(10, 75, 145, 25, "Fl_FuncR_0");
FR0->callback(Fl_Callback_C(this, &TestUI::fl_funcR_0));
FR0G = new Fl_Button(165, 75, 140, 25, "Fl_funcR_0G");
FR0G->callback(Fl_Callback_C(fl_funcR_0G));
o->end();
Note: you can find complete test1.h and test1.cxx in nctest directory of this package.
Classic callbacksFltk classic callback system is changed in way that Now let as take global function FStdG->callback(fl_func_stdG);or FStdG->callback(fl_func_stdG, data);This is still possible because of compatibility and it is done with Fl_Callback_C::operator=(...)which is taking void (*fp)(Fl_Widget *, void *) function pointer.If we want to write the same thing but with FLTKCallback++ in mind the code would look like: FStdG->callback(Fl_Callback_C(fl_func_stdG));or FStdG->callback(Fl_Callback_C(fl_func_stdG), data); Once again I have to point out that the classic (old) way will work just fine. Full back compatibility is supported. FLTKCalback++ approachFLTKCallback++ let you to create callback which is member function or global function with arguments of any kind (maximum 2 arguments). FunctionsTo create callback from some function you must write something like:float fl_funcR_1G(int i); ... FR1G->callback(Fl_Callback_C(fl_funcR_1G, 5)); Fl_Callback_C(fl_funcR_1G, 5) is taking function pointer and value which will be passed as argument.You can write: float fl_funcR_1G(int i); ... FR1G->callback(Fl_Callback_C(fl_funcR_1G, 5), data);but data will not be used so there is no sense to write it.
Member functionsTo create callback from some member function you must write something like:F2->callback(Fl_Callback_C(this, &TestUI::fl_func_2, 'c', 5));Here Fl_Callback_C(this, &TestUI::fl_func_2, 'c', 5) is taking pointer to object which method will be used, pointer to its member function and values which will be passed as arguments.
List of all Fl_Callback_C constructors:Here is list of all
template <typename t, typename ret, typename first>
Fl_Callback_C(t *obj, ret (t::*fl_ptr)(first), first data);
template <typename t, typename first>
Fl_Callback_C(t *obj, void (t::*fl_ptr)(first), first data);
template <typename t>
Fl_Callback_C(t *obj, void (t::*fl_ptr)(void));
template <typename t, typename ret>
Fl_Callback_C(t *obj, ret (t::*fl_ptr)(void));
template <typename t , typename ret, typename first, typename second>
Fl_Callback_C(t *obj, ret (t::*fl_ptr)(first, second), first data_f, second data_s);
template <typename t>
Fl_Callback_C(t *obj, void (t::*fl_ptr)(Fl_Widget *, void *));
template <typename t ,typename first, typename second>
Fl_Callback_C(t *obj, void (t::*fl_ptr)(first, second), first data_f, second data_s);
template <typename ret, typename first>
Fl_Callback_C(ret (*fl_ptr)(first), first data);
template <typename first>
Fl_Callback_C(void (*fl_ptr)(first), first data);
template <typename ret, typename first, typename second>
Fl_Callback_C(ret (*fl_ptr)(first, second), first data_f, second data_s);
template <typename first, typename second>
Fl_Callback_C(void (*fl_ptr)(first, second), first data_f, second data_s);
template <typename ret>
Fl_Callback_C(ret (*fl_ptr)(void));
Fl_Callback_C(void (*fl_ptr)(void));
Fl_Callback_C(void (*fl_ptr)(Fl_Widget *, void *));
Fl_Callback_C(const sp::s_ptr<Fl_Function_> &function_obj);
SummaryTo use FLTKCallback++ calbacks you must use If you want to use member function you must use following If you want to use global function you must use following I think that this new callback system is much easier to use and code looks more natural and understandable. What about fluid and FLTKCalback++?Well you can use fluid to define your application look but to add FLTKCallback++ callbacks you must use code editor after fluid generates code. You can in fluid define functions which will later be in your code editor assigned as callbacks. Maybe one day I or somebody else will add FLTKCallback++ support in fluid. This will be more easier than writing classical (current) callback support in fluid. |