diff options
| author | maxim nikonov <maxim.nikonov@hqo.co> | 2026-02-06 03:20:53 +0500 |
|---|---|---|
| committer | maxim nikonov <maxim.nikonov@hqo.co> | 2026-02-06 03:20:53 +0500 |
| commit | ddba971ebb304512ba9e0a01b77ec71b59b977b6 (patch) | |
| tree | 7e681b80b442ec86f19a3e19aa42770198946d35 /fluid/nodes | |
| parent | c19f34db2f4a64326d03cee7edae095051660f65 (diff) | |
wip
Diffstat (limited to 'fluid/nodes')
| -rw-r--r-- | fluid/nodes/Button_Node.cxx | 10 | ||||
| -rw-r--r-- | fluid/nodes/Function_Node.cxx | 206 | ||||
| -rw-r--r-- | fluid/nodes/Function_Node.h | 72 | ||||
| -rw-r--r-- | fluid/nodes/Node.cxx | 16 | ||||
| -rw-r--r-- | fluid/nodes/Node.h | 3 | ||||
| -rw-r--r-- | fluid/nodes/Tree.cxx | 4 | ||||
| -rw-r--r-- | fluid/nodes/Window_Node.cxx | 20 | ||||
| -rw-r--r-- | fluid/nodes/factory.cxx | 26 |
8 files changed, 197 insertions, 160 deletions
diff --git a/fluid/nodes/Button_Node.cxx b/fluid/nodes/Button_Node.cxx index d989c527c..877c5588d 100644 --- a/fluid/nodes/Button_Node.cxx +++ b/fluid/nodes/Button_Node.cxx @@ -57,7 +57,7 @@ Fl_Menu_Item *Button_Node::subtypes() { } void Button_Node::ideal_size(int &w, int &h) { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->labelsize + 8; w = layout->labelsize * 4 + 8; fld::app::Snap_Action::better_size(w, h); @@ -95,7 +95,7 @@ void Button_Node::copy_properties() { // ---- Return Button ---- void Return_Button_Node::ideal_size(int &w, int &h) { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->labelsize + 8; w = layout->labelsize * 4 + 8 + h; // make room for the symbol fld::app::Snap_Action::better_size(w, h); @@ -120,7 +120,7 @@ Repeat_Button_Node Repeat_Button_Node::prototype; // ---- Light Button ---- void Light_Button_Node::ideal_size(int &w, int &h) { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->labelsize + 8; w = layout->labelsize * 4 + 8 + layout->labelsize; // make room for the light fld::app::Snap_Action::better_size(w, h); @@ -136,7 +136,7 @@ Light_Button_Node Light_Button_Node::prototype; // ---- Check Button ---- void Check_Button_Node::ideal_size(int &w, int &h) { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->labelsize + 8; w = layout->labelsize * 4 + 8 + layout->labelsize; // make room for the symbol fld::app::Snap_Action::better_size(w, h); @@ -152,7 +152,7 @@ Check_Button_Node Check_Button_Node::prototype; // ---- Round Button ---- void Round_Button_Node::ideal_size(int &w, int &h) { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->labelsize + 8; w = layout->labelsize * 4 + 8 + layout->labelsize; // make room for the symbol fld::app::Snap_Action::better_size(w, h); diff --git a/fluid/nodes/Function_Node.cxx b/fluid/nodes/Function_Node.cxx index 27e8c83de..de3706eb3 100644 --- a/fluid/nodes/Function_Node.cxx +++ b/fluid/nodes/Function_Node.cxx @@ -185,6 +185,18 @@ const char *c_check(const char *c, int type) { or C++ function. */ +Function_Node::Function_Node() { + return_type_ = 0; + public_ = 0; + declare_c_ = 0; + constructor = 0; + havewidgets = 0; +} + +Function_Node::~Function_Node() { + if (return_type_) free((void*)return_type_); +} + /// Prototype for a function to be used by the factory. Function_Node Function_Node::prototype; @@ -204,7 +216,7 @@ Node *Function_Node::make(Strategy strategy) { } Function_Node *o = new Function_Node(); o->name("make_window()"); - o->return_type_.clear(); + if (o->return_type_) { free((void*)o->return_type_); o->return_type_ = 0; } o->add(anchor, strategy); o->factory = this; o->public_ = 1; @@ -225,7 +237,7 @@ void Function_Node::write_properties(fld::io::Project_Writer &f) { case 2: f.write_string("protected"); break; } if (declare_c_) f.write_string("C"); - if (!return_type().empty()) { + if (return_type()[0]) { f.write_string("return_type"); f.write_word(return_type()); } @@ -335,36 +347,41 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) { if (havechildren) f.write_c("int main(int argc, char **argv) {\n"); } else { - std::string rtype = return_type(); - std::string star = ""; + char rtype[256]; + const char *star = ""; + const char *rt = return_type(); + strncpy(rtype, rt ? rt : "", sizeof(rtype)-1); + rtype[sizeof(rtype)-1] = '\0'; // from matt: let the user type "static " at the start of type // in order to declare a static method; int is_static = 0; int is_virtual = 0; - if (!rtype.empty()) { - if (rtype == "static") { + if (rtype[0]) { + if (strcmp(rtype, "static") == 0) { is_static = 1; - rtype.clear(); - } else if (rtype.compare(0, 7, "static ")==0) { + rtype[0] = '\0'; + } else if (strncmp(rtype, "static ", 7)==0) { is_static = 1; - rtype.erase(0, 7); + memmove(rtype, rtype+7, strlen(rtype)-6); } } - if (!rtype.empty()) { - if (rtype == "virtual") { + if (rtype[0]) { + if (strcmp(rtype, "virtual") == 0) { is_virtual = 1; - rtype.clear(); - } else if (rtype.compare(0, 8, "virtual ")==0) { + rtype[0] = '\0'; + } else if (strncmp(rtype, "virtual ", 8)==0) { is_virtual = 1; - rtype.erase(0, 8); + memmove(rtype, rtype+8, strlen(rtype)-7); } } - if (rtype.empty()) { + if (!rtype[0]) { if (havewidgets) { - rtype = subclassname(child); + const char *scn = subclassname(child); + strncpy(rtype, scn ? scn : "", sizeof(rtype)-1); + rtype[sizeof(rtype)-1] = '\0'; star = "*"; } else { - rtype = "void"; + strcpy(rtype, "void"); } } @@ -383,9 +400,9 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) { if (is_static) f.write_h("static "); if (is_virtual) f.write_h("virtual "); if (!constructor) { - f.write_h("%s%s ", rtype.c_str(), star.c_str()); + f.write_h("%s%s ", rtype, star); if (havechildren) - f.write_c("%s%s ", rtype.c_str(), star.c_str()); + f.write_c("%s%s ", rtype, star); } // if this is a subclass, only f.write_h() the part before the ':' @@ -416,9 +433,9 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) { write_comment_c(f); if (public_==1) { if (declare_c_) - f.write_h("extern \"C\" { %s%s %s; }\n", rtype.c_str(), star.c_str(), name()); + f.write_h("extern \"C\" { %s%s %s; }\n", rtype, star, name()); else - f.write_h("%s%s %s;\n", rtype.c_str(), star.c_str(), name()); + f.write_h("%s%s %s;\n", rtype, star, name()); } else if (public_==2) { // write neither the prototype nor static, the function may be declared elsewhere } else { @@ -430,7 +447,7 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) { char s[1024]; if (havechildren) { clean_function_for_implementation(s, name()); - f.write_c("%s%s %s {\n", rtype.c_str(), star.c_str(), s); + f.write_c("%s%s %s {\n", rtype, star, s); } } } @@ -459,7 +476,7 @@ void Function_Node::write_code2(fld::io::Code_Writer& f) { f.write_c("%s%s->show(argc, argv);\n", f.indent(1), var); if (havechildren) f.write_c("%sreturn Fl::run();\n", f.indent(1)); - } else if (havewidgets && !constructor && return_type().empty()) { + } else if (havewidgets && !constructor && !return_type()[0]) { f.write_c("%sreturn %s;\n", f.indent(1), var); } if (havechildren) @@ -474,11 +491,11 @@ void Function_Node::write_code2(fld::io::Code_Writer& f) { \return 1 if they match, 0 if not */ int Function_Node::has_signature(const char *rtype, const char *sig) const { - if (rtype && return_type().empty()) + if (rtype && !return_type()[0]) return 0; if (!name()) return 0; - if ( (rtype==0 || (return_type() == rtype)) && fl_filename_match(name(), sig)) { + if ( (rtype==0 || strcmp(return_type(), rtype)==0) && fl_filename_match(name(), sig)) { return 1; } return 0; @@ -615,6 +632,14 @@ int Code_Node::handle_editor_changes() { \todo this node could support multiple lines of code for each block. */ +CodeBlock_Node::CodeBlock_Node() { + end_code_ = 0; +} + +CodeBlock_Node::~CodeBlock_Node() { + if (end_code_) free((void*)end_code_); +} + /// Prototype for a block of code to be used by the factory. CodeBlock_Node CodeBlock_Node::prototype; @@ -640,7 +665,7 @@ Node *CodeBlock_Node::make(Strategy strategy) { } CodeBlock_Node *o = new CodeBlock_Node(); o->name("if (test())"); - o->end_code_.clear(); + if (o->end_code_) { free((void*)o->end_code_); o->end_code_ = 0; } o->add(anchor, strategy); o->factory = this; return o; @@ -653,7 +678,7 @@ Node *CodeBlock_Node::make(Strategy strategy) { */ void CodeBlock_Node::write_properties(fld::io::Project_Writer &f) { Node::write_properties(f); - if (!end_code().empty()) { + if (end_code()[0]) { f.write_string("after"); f.write_word(end_code()); } @@ -691,8 +716,8 @@ void CodeBlock_Node::write_code1(fld::io::Code_Writer& f) { */ void CodeBlock_Node::write_code2(fld::io::Code_Writer& f) { f.indentation--; - if (!end_code().empty()) - f.write_c("%s} %s\n", f.indent(), end_code().c_str()); + if (end_code()[0]) + f.write_c("%s} %s\n", f.indent(), end_code()); else f.write_c("%s}\n", f.indent()); } @@ -870,6 +895,15 @@ void Decl_Node::write_code1(fld::io::Code_Writer& f) { code. This can be used to store images inline in the source code, */ +Data_Node::Data_Node() { + filename_ = 0; + output_format_ = 0; +} + +Data_Node::~Data_Node() { + if (filename_) free((void*)filename_); +} + /// Prototype for a data node to be used by the factory. Data_Node Data_Node::prototype; @@ -890,7 +924,7 @@ Node *Data_Node::make(Strategy strategy) { Data_Node *o = new Data_Node(); o->public_ = 1; o->static_ = 1; - o->filename_.clear(); + if (o->filename_) { free((void*)o->filename_); o->filename_ = 0; } o->output_format_ = 0; o->name("myInlineData"); o->add(anchor, strategy); @@ -905,7 +939,7 @@ Node *Data_Node::make(Strategy strategy) { */ void Data_Node::write_properties(fld::io::Project_Writer &f) { Decl_Node::write_properties(f); - if (!filename().empty()) { + if (filename()[0]) { f.write_string("filename"); f.write_word(filename()); } @@ -953,14 +987,14 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { const char *message = 0; const char *c = name(); if (!c) return; - std::string fn = filename(); + const char *fn = filename(); char *data = 0; int nData = -1; int uncompressedDataSize = 0; // path should be set correctly already - if (!filename().empty() && !f.write_codeview) { + if (fn && fn[0] && !f.write_codeview) { Fluid.proj.enter_project_dir(); - FILE *f = fl_fopen(filename().c_str(), "rb"); + FILE *f = fl_fopen(fn, "rb"); Fluid.proj.leave_project_dir(); if (!f) { message = "Can't include data from file. Can't open"; @@ -984,7 +1018,7 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { fclose(f); } } else { - if (filename().empty()) + if (!fn || !fn[0]) fn = "<no filename>"; } if (is_in_class()) { @@ -994,13 +1028,13 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { write_comment_c(f); if (output_format_ == 1) { f.write_h("%sstatic const char *%s;\n", f.indent(1), c); - f.write_c("const char *%s::%s = /* text inlined from %s */\n", class_name(1), c, fn.c_str()); + f.write_c("const char *%s::%s = /* text inlined from %s */\n", class_name(1), c, fn); } else { f.write_h_once("#include <string>"); f.write_h("%sstatic const std::string %s;\n", f.indent(1), c); - f.write_c("const std::string %s::%s = /* text inlined from %s */\n", class_name(1), c, fn.c_str()); + f.write_c("const std::string %s::%s = /* text inlined from %s */\n", class_name(1), c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cstring(data, nData); } else if ((output_format_ == 2) || (output_format_ == 5)) { f.write_h("%sstatic int %s_size;\n", f.indent(1), c); @@ -1009,28 +1043,28 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { f.write_c("int %s::%s_size = %d;\n", class_name(1), c, uncompressedDataSize); if (output_format_ == 2) { f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData); - f.write_c("unsigned char %s::%s[%d] = /* data compressed and inlined from %s */\n", class_name(1), c, nData, fn.c_str()); + f.write_c("unsigned char %s::%s[%d] = /* data compressed and inlined from %s */\n", class_name(1), c, nData, fn); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("%sstatic std::vector<uint8_t> %s;\n", f.indent(1), c); - f.write_c("std::vector<uint8_t> %s::%s = /* data compressed and inlined from %s */\n", class_name(1), c, fn.c_str()); + f.write_c("std::vector<uint8_t> %s::%s = /* data compressed and inlined from %s */\n", class_name(1), c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cdata(data, nData); } else { f.write_c("\n"); write_comment_c(f); if (output_format_ == 0) { f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData); - f.write_c("unsigned char %s::%s[%d] = /* data inlined from %s */\n", class_name(1), c, nData, fn.c_str()); + f.write_c("unsigned char %s::%s[%d] = /* data inlined from %s */\n", class_name(1), c, nData, fn); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("%sstatic std::vector<uint8_t> %s;\n", f.indent(1), c); - f.write_c("std::vector<uint8_t> %s::%s = /* data inlined from %s */\n", class_name(1), c, fn.c_str()); + f.write_c("std::vector<uint8_t> %s::%s = /* data inlined from %s */\n", class_name(1), c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cdata(data, nData); } f.write_c(";\n"); @@ -1043,13 +1077,13 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { write_comment_c(f); if (output_format_ == 1) { f.write_h("extern const char *%s;\n", c); - f.write_c("const char *%s = /* text inlined from %s */\n", c, fn.c_str()); + f.write_c("const char *%s = /* text inlined from %s */\n", c, fn); } else { f.write_h_once("#include <string>"); f.write_h("extern const std::string %s;\n", c); - f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn.c_str()); + f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cstring(data, nData); } else if ((output_format_ == 2) || (output_format_ == 5)) { f.write_h("extern int %s_size;\n", c); @@ -1058,34 +1092,34 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { f.write_c("int %s_size = %d;\n", c, uncompressedDataSize); if (output_format_ == 2) { f.write_h("extern unsigned char %s[%d];\n", c, nData); - f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn.c_str()); + f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("extern std::vector<uint8_t> %s;\n", c); - f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn.c_str()); + f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cdata(data, nData); } else { f.write_c("\n"); write_comment_c(f); if (output_format_ == 0) { f.write_h("extern unsigned char %s[%d];\n", c, nData); - f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn.c_str()); + f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("extern std::vector<uint8_t> %s;\n", c); - f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn.c_str()); + f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cdata(data, nData); } f.write_c(";\n"); } else { write_comment_h(f); - f.write_h("#error Unsupported declaration loading inline data %s\n", fn.c_str()); + f.write_h("#error Unsupported declaration loading inline data %s\n", fn); if (output_format_ == 1) f.write_h("const char *%s = \"abc...\";\n", c); else @@ -1097,39 +1131,39 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { if ((output_format_ == 1) || (output_format_ == 4)) { if (output_format_ == 1) { if (static_) f.write_c("static "); - f.write_c("const char *%s = /* text inlined from %s */\n", c, fn.c_str()); + f.write_c("const char *%s = /* text inlined from %s */\n", c, fn); } else { f.write_c_once("#include <string>"); if (static_) f.write_c("static "); - f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn.c_str()); + f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cstring(data, nData); } else if ((output_format_ == 2) || (output_format_ == 5)) { if (static_) f.write_c("static "); f.write_c("int %s_size = %d;\n", c, uncompressedDataSize); if (output_format_ == 2) { if (static_) f.write_c("static "); - f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn.c_str()); + f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn); } else { f.write_c_once("#include <stdint.h>"); f.write_c_once("#include <vector>"); if (static_) f.write_c("static "); - f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn.c_str()); + f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cdata(data, nData); } else { if (output_format_ == 0) { if (static_) f.write_c("static "); - f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn.c_str()); + f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn); } else { f.write_c_once("#include <stdint.h>"); f.write_c_once("#include <vector>"); if (static_) f.write_c("static "); - f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn.c_str()); + f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn); } - if (message) f.write_c("#error %s %s\n", message, fn.c_str()); + if (message) f.write_c("#error %s %s\n", message, fn); f.write_cdata(data, nData); } f.write_c(";\n"); @@ -1139,9 +1173,9 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { // giving the error: (Fluid.batch_mode && !write_codeview) ??? if (message && !f.write_codeview) { if (Fluid.batch_mode) - fprintf(stderr, "FLUID ERROR: %s %s\n", message, fn.c_str()); + fprintf(stderr, "FLUID ERROR: %s %s\n", message, fn); else - fl_alert("%s\n%s\n", message, fn.c_str()); + fl_alert("%s\n%s\n", message, fn); } if (data) free(data); } @@ -1157,6 +1191,15 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { is written to the source file, and to the header file, if declared public. */ +DeclBlock_Node::DeclBlock_Node() { + end_code_ = 0; + write_map_ = CODE_IN_SOURCE; +} + +DeclBlock_Node::~DeclBlock_Node() { + if (end_code_) free((void*)end_code_); +} + /// Prototype for a declaration block to be used by the factory. DeclBlock_Node DeclBlock_Node::prototype; @@ -1247,11 +1290,11 @@ void DeclBlock_Node::write_static(fld::io::Code_Writer& f) { Write the \b after static code to the source file, and to the header file if declared public. */ void DeclBlock_Node::write_static_after(fld::io::Code_Writer& f) { - if (!end_code().empty()) { + if (end_code()[0]) { if (write_map_ & STATIC_IN_HEADER) - f.write_h("%s\n", end_code().c_str()); + f.write_h("%s\n", end_code()); if (write_map_ & STATIC_IN_SOURCE) - f.write_c("%s\n", end_code().c_str()); + f.write_c("%s\n", end_code()); } } @@ -1273,11 +1316,11 @@ void DeclBlock_Node::write_code1(fld::io::Code_Writer& f) { Write the \b after code to the source file, and to the header file if declared public. */ void DeclBlock_Node::write_code2(fld::io::Code_Writer& f) { - if (!end_code().empty()) { + if (end_code()[0]) { if (write_map_ & CODE_IN_HEADER) - f.write_h("%s\n", end_code().c_str()); + f.write_h("%s\n", end_code()); if (write_map_ & CODE_IN_SOURCE) - f.write_c("%s\n", end_code().c_str()); + f.write_c("%s\n", end_code()); } } @@ -1424,6 +1467,17 @@ void Comment_Node::write_code1(fld::io::Code_Writer& f) { Manage a class declaration and implementation. */ +Class_Node::Class_Node() { + base_class_ = 0; + prefix_ = 0; + public_ = 1; +} + +Class_Node::~Class_Node() { + if (base_class_) free((void*)base_class_); + if (prefix_) free((void*)prefix_); +} + /// Prototype for a class node to be used by the factory. Class_Node Class_Node::prototype; @@ -1465,7 +1519,7 @@ Node *Class_Node::make(Strategy strategy) { */ void Class_Node::write_properties(fld::io::Project_Writer &f) { Node::write_properties(f); - if (!base_class().empty()) { + if (base_class()[0]) { f.write_string(":"); f.write_word(base_class()); } @@ -1506,12 +1560,12 @@ void Class_Node::write_code1(fld::io::Code_Writer& f) { write_public_state = 0; f.write_h("\n"); write_comment_h(f); - if (!prefix().empty()) - f.write_h("class %s %s ", prefix().c_str(), name()); + if (prefix()[0]) + f.write_h("class %s %s ", prefix(), name()); else f.write_h("class %s ", name()); - if (!base_class().empty()) { - f.write_h(": %s ", base_class().c_str()); + if (base_class()[0]) { + f.write_h(": %s ", base_class()); } f.write_h("{\n"); } diff --git a/fluid/nodes/Function_Node.h b/fluid/nodes/Function_Node.h index 0ad4494f3..87664e317 100644 --- a/fluid/nodes/Function_Node.h +++ b/fluid/nodes/Function_Node.h @@ -34,8 +34,6 @@ #include <stdarg.h> #include <stdlib.h> -#include <string> - extern class Class_Node *current_class; int has_toplevel_function(const char *rtype, const char *sig); @@ -51,15 +49,15 @@ public: static Function_Node prototype; private: - std::string return_type_; - char public_ = 0; - char declare_c_ = 0; - char constructor = 0; - char havewidgets = 0; + const char *return_type_; + char public_; + char declare_c_; + char constructor; + char havewidgets; public: - Function_Node() = default; - ~Function_Node() override = default; + Function_Node(); + ~Function_Node(); Node *make(Strategy strategy) override; void write_code1(fld::io::Code_Writer& f) override; @@ -76,8 +74,8 @@ public: void write_properties(fld::io::Project_Writer &f) override; void read_property(fld::io::Project_Reader &f, const char *) override; int has_signature(const char *, const char*) const; - std::string return_type() const { return return_type_; } - void return_type(const std::string& t) { storestring(t, return_type_); } + const char *return_type() const { return return_type_ ? return_type_ : ""; } + void return_type(const char *t) { storestring(t, return_type_); } char visibility() { return public_; } void visibility(char v) { public_ = v; } char declare_c() { return declare_c_; } @@ -132,11 +130,11 @@ public: static CodeBlock_Node prototype; private: - std::string end_code_; + const char *end_code_; public: - CodeBlock_Node() = default; - ~CodeBlock_Node() override = default; + CodeBlock_Node(); + ~CodeBlock_Node(); Node *make(Strategy strategy) override; void write_code1(fld::io::Code_Writer& f) override; @@ -150,8 +148,8 @@ public: bool is_a(Type inType) const override { return (inType==FLD_NODE_TYPE_CodeBlock) ? true : super::is_a(inType); } void write_properties(fld::io::Project_Writer &f) override; void read_property(fld::io::Project_Reader &f, const char *) override; - std::string end_code() const { return end_code_; } - void end_code(const std::string& c) { storestring(c, end_code_); } + const char *end_code() const { return end_code_ ? end_code_ : ""; } + void end_code(const char *c) { storestring(c, end_code_); } }; // ---- Decl_Node declaration @@ -195,12 +193,12 @@ public: static Data_Node prototype; private: - std::string filename_; - int output_format_ = 0; + const char *filename_; + int output_format_; public: - Data_Node() = default; - ~Data_Node() override = default; + Data_Node(); + ~Data_Node(); Node *make(Strategy strategy) override; void write_code1(fld::io::Code_Writer& f) override; @@ -211,8 +209,8 @@ public: void read_property(fld::io::Project_Reader &f, const char *) override; Type type() const override { return FLD_NODE_TYPE_Data; } bool is_a(Type inType) const override { return (inType==FLD_NODE_TYPE_Data) ? true : super::is_a(inType); } - void filename(const std::string& fn) { storestring(fn, filename_); } - std::string filename() const { return filename_; } + void filename(const char *fn) { storestring(fn, filename_); } + const char *filename() const { return filename_ ? filename_ : ""; } int output_format() { return output_format_; } void output_format(int fmt) { output_format_ = fmt; } }; @@ -232,12 +230,12 @@ public: }; private: - std::string end_code_; ///< code after all children of this block - int write_map_ = CODE_IN_SOURCE; ///< see enum above + const char *end_code_; ///< code after all children of this block + int write_map_; ///< see enum above public: - DeclBlock_Node() = default; - ~DeclBlock_Node() override = default; + DeclBlock_Node(); + ~DeclBlock_Node(); Node *make(Strategy strategy) override; void write_static(fld::io::Code_Writer& f) override; @@ -253,8 +251,8 @@ public: int is_public() const override; Type type() const override { return FLD_NODE_TYPE_DeclBlock; } bool is_a(Type inType) const override { return (inType==FLD_NODE_TYPE_DeclBlock) ? true : super::is_a(inType); } - std::string end_code() const { return end_code_; } - void end_code(const std::string& p) { storestring(p, end_code_); } + const char *end_code() const { return end_code_ ? end_code_ : ""; } + void end_code(const char *p) { storestring(p, end_code_); } int write_map() { return write_map_; } void write_map(int v) { write_map_ = v; } }; @@ -301,13 +299,13 @@ public: static Class_Node prototype; private: - std::string base_class_; - std::string prefix_; - char public_ = 1; + const char *base_class_; + const char *prefix_; + char public_; public: - Class_Node() = default; - ~Class_Node() override = default; + Class_Node(); + ~Class_Node(); // State variables used when writing code to file char write_public_state; // true when public: has been printed @@ -328,17 +326,17 @@ public: void read_property(fld::io::Project_Reader &f, const char *) override; /** Get base class access and name. */ - std::string base_class() const { return base_class_; } + const char *base_class() const { return base_class_ ? base_class_ : ""; } /** Set base class access and name, i.e. `public Fl_Widget`. */ - void base_class(const std::string& name) { storestring(name, base_class_); } + void base_class(const char *name) { storestring(name, base_class_); } char visibility() { return public_; } void visibility(char v) { public_ = v; } /** Get the text between `class` and the class name */ - std::string prefix() const { return prefix_; } + const char *prefix() const { return prefix_ ? prefix_ : ""; } /** Set the text between `class` and the class name */ - void prefix(const std::string& p) { prefix_ = p; } + void prefix(const char *p) { storestring(p, prefix_); } }; #endif // FLUID_NODES_FUNCTION_NODE_H diff --git a/fluid/nodes/Node.cxx b/fluid/nodes/Node.cxx index 2971bad2d..8e0041f3c 100644 --- a/fluid/nodes/Node.cxx +++ b/fluid/nodes/Node.cxx @@ -455,18 +455,6 @@ int storestring(const char *n, const char * & p, int nostrip) { return 1; } -// C++11 version, still using the original to copy all the side effects. -int storestring(const std::string& n, std::string& p, int nostrip) { - const char *buffer { 0 }; - int ret = storestring(n.c_str(), buffer); - if (buffer) { - p = buffer; - free((void*)buffer); - } else { - p.clear(); - } - return ret; -} /** Update the `visible` flag for `p` and all its descendants. \param[in] p start here and update all descendants @@ -902,8 +890,8 @@ void Node::write(fld::io::Project_Writer &f) { f.write_word(type_name()); if (is_class()) { - auto p = ((Class_Node*)this)->prefix(); - if (!p.empty()) + const char *p = ((Class_Node*)this)->prefix(); + if (p[0]) f.write_word(p); } diff --git a/fluid/nodes/Node.h b/fluid/nodes/Node.h index 02338903f..a20dd7258 100644 --- a/fluid/nodes/Node.h +++ b/fluid/nodes/Node.h @@ -22,8 +22,6 @@ #include <FL/Fl_Widget.H> #include <FL/fl_draw.H> -#include <string> - class Node; class Group_Node; class Window_Node; @@ -117,7 +115,6 @@ typedef NodeType Type; void update_visibility_flag(Node *p); void delete_all(int selected_only=0); int storestring(const char *n, const char * & p, int nostrip=0); -int storestring(const std::string& n, std::string& p, int nostrip=0); void select_all_cb(Fl_Widget *,void *); void select_none_cb(Fl_Widget *,void *); diff --git a/fluid/nodes/Tree.cxx b/fluid/nodes/Tree.cxx index a163c4181..d437b5bd3 100644 --- a/fluid/nodes/Tree.cxx +++ b/fluid/nodes/Tree.cxx @@ -92,7 +92,7 @@ Tree::Tree(Project &proj) \return the node with this uid, or 0 if not found */ Node *Tree::find_by_uid(unsigned short uid) { - for (auto tp: all_nodes()) { + for (Node *tp: all_nodes()) { if (tp->get_uid() == uid) return tp; } return 0; @@ -106,7 +106,7 @@ Node *Tree::find_by_uid(unsigned short uid) { \return the node we found or 0 */ Node *Tree::find_in_text(int text_type, int crsr) { - for (auto node: all_nodes()) { + for (Node *node: all_nodes()) { switch (text_type) { case 0: if (crsr >= node->code1_start && crsr < node->code1_end) return node; diff --git a/fluid/nodes/Window_Node.cxx b/fluid/nodes/Window_Node.cxx index 0c3b0f01c..2bcd9f1b1 100644 --- a/fluid/nodes/Window_Node.cxx +++ b/fluid/nodes/Window_Node.cxx @@ -1386,13 +1386,13 @@ void Widget_Class_Node::write_code1(fld::io::Code_Writer& f) { current_widget_class = this; write_public_state = 1; - std::string c = subclass(); - if (c.empty()) c = "Fl_Group"; + const char *c = subclass(); + if (!c || !c[0]) c = "Fl_Group"; f.write_c("\n"); write_comment_h(f); - f.write_h("\nclass %s : public %s {\n", name(), c.c_str()); - if (c.find("Window")!=c.npos) { + f.write_h("\nclass %s : public %s {\n", name(), c); + if (strstr(c, "Window") != 0) { f.write_h("%svoid _%s();\n", f.indent(1), trimclassname(name())); f.write_h("public:\n"); f.write_h("%s%s(int X, int Y, int W, int H, const char *L = 0);\n", f.indent(1), trimclassname(name())); @@ -1401,20 +1401,20 @@ void Widget_Class_Node::write_code1(fld::io::Code_Writer& f) { // a constructor with all four dimensions plus label f.write_c("%s::%s(int X, int Y, int W, int H, const char *L) :\n", name(), trimclassname(name())); - f.write_c("%s%s(X, Y, W, H, L)\n{\n", f.indent(1), c.c_str()); + f.write_c("%s%s(X, Y, W, H, L)\n{\n", f.indent(1), c); f.write_c("%s_%s();\n", f.indent(1), trimclassname(name())); f.write_c("}\n\n"); // a constructor with just the size and label. The window manager will position the window f.write_c("%s::%s(int W, int H, const char *L) :\n", name(), trimclassname(name())); - f.write_c("%s%s(0, 0, W, H, L)\n{\n", f.indent(1), c.c_str()); + f.write_c("%s%s(0, 0, W, H, L)\n{\n", f.indent(1), c); f.write_c("%sclear_flag(16);\n", f.indent(1)); f.write_c("%s_%s();\n", f.indent(1), trimclassname(name())); f.write_c("}\n\n"); // a constructor that takes size and label from the Fluid database f.write_c("%s::%s() :\n", name(), trimclassname(name())); - f.write_c("%s%s(0, 0, %d, %d, ", f.indent(1), c.c_str(), o->w(), o->h()); + f.write_c("%s%s(0, 0, %d, %d, ", f.indent(1), c, o->w(), o->h()); const char *cstr = label(); if (cstr) f.write_cstring(cstr); else f.write_c("0"); @@ -1431,11 +1431,11 @@ void Widget_Class_Node::write_code1(fld::io::Code_Writer& f) { f.indent(1), trimclassname(name())); f.write_c("%s::%s(int X, int Y, int W, int H, const char *L) :\n", name(), trimclassname(name())); if (wc_relative==1) - f.write_c("%s%s(0, 0, W, H, L)\n{\n", f.indent(1), c.c_str()); + f.write_c("%s%s(0, 0, W, H, L)\n{\n", f.indent(1), c); else if (wc_relative==2) - f.write_c("%s%s(0, 0, %d, %d, L)\n{\n", f.indent(1), c.c_str(), o->w(), o->h()); + f.write_c("%s%s(0, 0, %d, %d, L)\n{\n", f.indent(1), c, o->w(), o->h()); else - f.write_c("%s%s(X, Y, W, H, L)\n{\n", f.indent(1), c.c_str()); + f.write_c("%s%s(X, Y, W, H, L)\n{\n", f.indent(1), c); } // f.write_c("%s%s *o = this;\n", f.indent(1), name()); diff --git a/fluid/nodes/factory.cxx b/fluid/nodes/factory.cxx index 792a9ff72..70e960edd 100644 --- a/fluid/nodes/factory.cxx +++ b/fluid/nodes/factory.cxx @@ -390,7 +390,7 @@ private: } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->textsize_not_null() + 8; w = layout->textsize_not_null() * 4 + 4 * h; // make room for the arrows fld::app::Snap_Action::better_size(w, h); @@ -420,7 +420,7 @@ public: static Adjuster_Node prototype; public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->labelsize + 8; w = 3 * h; fld::app::Snap_Action::better_size(w, h); @@ -495,7 +495,7 @@ private: Fl_Menu_Item *subtypes() override { return roller_type_menu; } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; w = layout->labelsize + 8; h = 4 * w; fld::app::Snap_Action::better_size(w, h); @@ -539,7 +539,7 @@ private: Fl_Menu_Item *subtypes() override { return slider_type_menu; } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; w = layout->labelsize + 8; h = 4 * w; fld::app::Snap_Action::better_size(w, h); @@ -649,7 +649,7 @@ private: } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->textsize_not_null() + 8; w = layout->textsize_not_null() * 4 + 8; fld::app::Snap_Action::better_size(w, h); @@ -692,7 +692,7 @@ private: } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->textsize_not_null() + 8; w = layout->textsize_not_null() * 4 + 8; fld::app::Snap_Action::better_size(w, h); @@ -751,7 +751,7 @@ private: } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->textsize_not_null() + 8; w = layout->textsize_not_null() * 6 + 8; fld::app::Snap_Action::better_size(w, h); @@ -793,7 +793,7 @@ private: Fl_Menu_Item *subtypes() override { return 0; } // Don't inherit. public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->textsize_not_null() + 8 + 10; // Directoy bar is additional 10 pixels high w = layout->textsize_not_null() * 10 + 8; fld::app::Snap_Action::better_size(w, h); @@ -877,7 +877,7 @@ private: } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->textsize_not_null() * 4 + 8; w = layout->textsize_not_null() * 10 + 8; fld::app::Snap_Action::better_size(w, h); @@ -1101,7 +1101,7 @@ public: static Progress_Node prototype; public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->labelsize + 8; w = layout->labelsize * 12; fld::app::Snap_Action::better_size(w, h); @@ -1153,7 +1153,7 @@ private: } public: void ideal_size(int &w, int &h) override { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; h = layout->textsize_not_null() + 8; w = layout->textsize_not_null() * 4 + 8; fld::app::Snap_Action::better_size(w, h); @@ -1282,11 +1282,11 @@ static Node *known_types[] = { Node *add_new_widget_from_user(Node *inPrototype, Strategy strategy, bool and_open) { Fluid.proj.undo.checkpoint(); Fluid.proj.undo.suspend(); - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; Node *t = ((Node*)inPrototype)->make(strategy); if (t) { if (t->is_widget() && !t->is_a(FLD_NODE_TYPE_Window)) { - auto layout = Fluid.proj.layout; + fld::app::Layout_Preset *layout = Fluid.proj.layout; Widget_Node *wt = (Widget_Node *)t; bool changed = false; |
