FLUID now knows if a static callback is already declared in a class and won't declare it 'extern' (STR #776)

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4534 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2005-08-23 11:28:13 +00:00
parent 7e02be0309
commit cd1de720b7
6 changed files with 60 additions and 6 deletions

View File

@ -3,6 +3,8 @@ CHANGES IN FLTK 1.1.7
- Documentation fixes (STR #571, STR #648, STR #692, STR
#730, STR #744, STR #745, STR #931, STR #942, STR #960,
STR #969)
- FLUID now knows if a static callback is already declared
in a class and won't declare it 'extern' (STR #776)
- Some actions in FLUID would not set the
"changed" flag (STR #984)
- fl_filename_list now always appends a forward slash to

View File

@ -348,6 +348,16 @@ void Fl_Function_Type::write_code2() {
indentation = 0;
}
int Fl_Function_Type::has_signature(const char *rtype, const char *sig) const {
if (!return_type) return 0;
if (!name()) return 0;
if ( strcmp(return_type, rtype)==0
&& fl_filename_match(name(), sig)) {
return 1;
}
return 0;
}
////////////////////////////////////////////////////////////////
Fl_Type *Fl_Code_Type::make() {
@ -895,6 +905,20 @@ const char* Fl_Type::class_name(const int need_nest) const {
return 0;
}
/**
* If this Type resides inside a class, this function returns the class type, or null.
*/
const Fl_Class_Type *Fl_Type::is_in_class() const {
Fl_Type* p = parent;
while (p) {
if (p->is_class()) {
return (Fl_Class_Type*)p;
}
p = p->parent;
}
return 0;
}
int Fl_Class_Type::is_public() const {return public_;}
void Fl_Class_Type::prefix(const char*p) {
@ -1024,6 +1048,21 @@ void Fl_Class_Type::write_code2() {
current_class = parent_class;
}
/**
* Return 1 if this class contains a function with the given signature.
*/
int Fl_Class_Type::has_function(const char *rtype, const char *sig) const {
Fl_Type *child;
for (child = next; child && child->level > level; child = child->next) {
if (child->level == level+1 && strcmp(child->type_name(), "Function")==0) {
const Fl_Function_Type *fn = (const Fl_Function_Type*)child;
if (fn->has_signature(rtype, sig))
return 1;
}
}
return 0;
}
//
// End of "$Id$".
//

View File

@ -141,6 +141,7 @@ public:
virtual int pixmapID() { return 0; }
const char* class_name(const int need_nest) const;
const class Fl_Class_Type* is_in_class() const;
};
class Fl_Function_Type : public Fl_Type {
@ -162,6 +163,7 @@ public:
int pixmapID() { return 7; }
void write_properties();
void read_property(const char *);
int has_signature(const char *, const char*) const;
};
class Fl_Code_Type : public Fl_Type {
@ -262,6 +264,7 @@ public:
// class prefix attribute access
void prefix(const char* p);
const char* prefix() const {return class_prefix;}
int has_function(const char*, const char*) const;
private:
const char* class_prefix;
};

View File

@ -1763,11 +1763,20 @@ void Fl_Widget_Type::write_static() {
if (extra_code(n) && isdeclare(extra_code(n)))
write_declare("%s", extra_code(n));
}
if (callback() && is_name(callback()))
write_declare("extern void %s(%s*, %s);", callback(), t,
user_data_type() ? user_data_type() : "void*");
const char* c = array_name(this);
if (callback() && is_name(callback())) {
int write_extern_declaration = 1;
const Fl_Class_Type *cc = is_in_class();
if (cc) {
char buf[1024]; snprintf(buf, 1023, "%s(*)", callback());
if (cc->has_function("static void", buf))
write_extern_declaration = 0;
}
if (write_extern_declaration)
write_declare("extern void %s(%s*, %s);", callback(), t,
user_data_type() ? user_data_type() : "void*");
}
const char* k = class_name(1);
const char* c = array_name(this);
if (c && !k && !is_class()) {
write_c("\n");
if (!public_) write_c("static ");

View File

@ -643,7 +643,8 @@ Fl_Double_Window* make_widget_panel() {
o->callback((Fl_Callback*)v_input_cb, (void*)(3));
}
{ CodeEditor* o = new CodeEditor(90, 170, 300, 90, "Callback:");
o->tooltip("The callback function or code for the widget.");
o->tooltip("The callback function or code for the widget. Use the variable name \'o\' to \
access the Widget pointer and \'v\' to access the user value.");
o->box(FL_DOWN_BOX);
o->color(FL_BACKGROUND2_COLOR);
o->selection_color(FL_SELECTION_COLOR);

View File

@ -464,7 +464,7 @@ Function {make_widget_panel()} {open
Fl_Text_Editor {} {
label {Callback:}
callback callback_cb
tooltip {The callback function or code for the widget.} xywh {90 170 300 90} box DOWN_BOX labelfont 1 labelsize 11 align 4 textfont 4 textsize 11 resizable
tooltip {The callback function or code for the widget. Use the variable name 'o' to access the Widget pointer and 'v' to access the user value.} xywh {90 170 300 90} box DOWN_BOX labelfont 1 labelsize 11 align 4 textfont 4 textsize 11 resizable
code0 {\#include "CodeEditor.h"}
class CodeEditor
}