diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2005-08-23 11:28:13 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2005-08-23 11:28:13 +0000 |
| commit | cd1de720b716d77810a923bc7aa7242e99db891c (patch) | |
| tree | 12970e246988c9f35564177f4396c559f33f3314 | |
| parent | 7e02be0309fbe276358efeedf01b2609b07d5988 (diff) | |
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
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | fluid/Fl_Function_Type.cxx | 39 | ||||
| -rw-r--r-- | fluid/Fl_Type.h | 3 | ||||
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 17 | ||||
| -rw-r--r-- | fluid/widget_panel.cxx | 3 | ||||
| -rw-r--r-- | fluid/widget_panel.fl | 2 |
6 files changed, 60 insertions, 6 deletions
@@ -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 diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index 379b147bd..d5627b2a8 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -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$". // diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h index eaacb3a29..d50ccaf02 100644 --- a/fluid/Fl_Type.h +++ b/fluid/Fl_Type.h @@ -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; }; diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index 820b4184a..47d64fa65 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -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 "); diff --git a/fluid/widget_panel.cxx b/fluid/widget_panel.cxx index 6b8904ba7..d93de79d1 100644 --- a/fluid/widget_panel.cxx +++ b/fluid/widget_panel.cxx @@ -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); diff --git a/fluid/widget_panel.fl b/fluid/widget_panel.fl index 53a50d2e9..90fdbeb11 100644 --- a/fluid/widget_panel.fl +++ b/fluid/widget_panel.fl @@ -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 } |
