diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-12-06 02:50:28 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-12-06 02:50:28 +0100 |
| commit | b1d3ee13bd1be3fefda2be490ce773afab2ade04 (patch) | |
| tree | 84e182175cc6403dadce8c28604afd3edbe4304f | |
| parent | 5e7ed2f6534bf8d99688e375c56f44f792bdf7bb (diff) | |
Fluid: modernize Function Node class
| -rw-r--r-- | fluid/nodes/Function_Node.cxx | 15 | ||||
| -rw-r--r-- | fluid/nodes/Function_Node.h | 16 | ||||
| -rw-r--r-- | fluid/nodes/Node.cxx | 13 | ||||
| -rw-r--r-- | fluid/nodes/Node.h | 3 | ||||
| -rw-r--r-- | fluid/panels/widget_panel.cxx | 12 | ||||
| -rw-r--r-- | fluid/panels/widget_panel.fl | 20 |
6 files changed, 47 insertions, 32 deletions
diff --git a/fluid/nodes/Function_Node.cxx b/fluid/nodes/Function_Node.cxx index 3e98a898f..42c3f3996 100644 --- a/fluid/nodes/Function_Node.cxx +++ b/fluid/nodes/Function_Node.cxx @@ -1513,7 +1513,6 @@ Class_Node Class_Node::prototype; */ Class_Node::Class_Node() : Node(), - subclass_of(nullptr), public_(1) { } @@ -1521,8 +1520,6 @@ Class_Node::Class_Node() : Destructor. */ Class_Node::~Class_Node() { - if (subclass_of) - free((void*)subclass_of); } /** @@ -1549,7 +1546,7 @@ Node *Class_Node::make(Strategy strategy) { Class_Node *o = new Class_Node(); o->name("UserInterface"); o->prefix(""); - o->subclass_of = nullptr; + o->base_class(""); o->public_ = 1; o->add(anchor, strategy); o->factory = this; @@ -1563,9 +1560,9 @@ Node *Class_Node::make(Strategy strategy) { */ void Class_Node::write_properties(fld::io::Project_Writer &f) { Node::write_properties(f); - if (subclass_of) { + if (!base_class().empty()) { f.write_string(":"); - f.write_word(subclass_of); + f.write_word(base_class().c_str()); } switch (public_) { case 0: f.write_string("private"); break; @@ -1582,7 +1579,7 @@ void Class_Node::read_property(fld::io::Project_Reader &f, const char *c) { } else if (!strcmp(c,"protected")) { public_ = 2; } else if (!strcmp(c,":")) { - storestring(f.read_word(), subclass_of); + base_class(f.read_word()); } else { Node::read_property(f, c); } @@ -1608,7 +1605,9 @@ void Class_Node::write_code1(fld::io::Code_Writer& f) { f.write_h("class %s %s ", prefix().c_str(), name()); else f.write_h("class %s ", name()); - if (subclass_of) f.write_h(": %s ", subclass_of); + if (!base_class().empty()) { + f.write_h(": %s ", base_class().c_str()); + } f.write_h("{\n"); } diff --git a/fluid/nodes/Function_Node.h b/fluid/nodes/Function_Node.h index 282f33312..33bcc1849 100644 --- a/fluid/nodes/Function_Node.h +++ b/fluid/nodes/Function_Node.h @@ -271,9 +271,9 @@ public: typedef Node super; static Class_Node prototype; private: - const char* subclass_of; - char public_; + std::string base_class_; std::string prefix_; + char public_; public: Class_Node(); ~Class_Node(); @@ -294,16 +294,20 @@ public: bool is_a(Type inType) const override { return (inType==Type::Class) ? 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; - const char* base_class_name() { return subclass_of; } - void base_class_name(const char* name) { storestring(name, subclass_of); } + + /** Get base class access and name. */ + std::string base_class() { return base_class_; } + /** Set base class access and name, i.e. `public Fl_Widget`. */ + void base_class(const std::string& name) { storestring(name, base_class_); } + char visibility() { return public_; } void visibility(char v) { public_ = v; } // class prefix attribute access - /** Set the text between `class` and the class name */ - void prefix(const std::string& p) { prefix_ = p; } /** Get the text between `class` and the class name */ std::string prefix() const { return prefix_; } + /** Set the text between `class` and the class name */ + void prefix(const std::string& p) { prefix_ = p; } }; #endif // FLUID_NODES_FUNCTION_NODE_H diff --git a/fluid/nodes/Node.cxx b/fluid/nodes/Node.cxx index 7557e61f4..a84528b59 100644 --- a/fluid/nodes/Node.cxx +++ b/fluid/nodes/Node.cxx @@ -455,6 +455,19 @@ 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 { nullptr }; + 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 */ diff --git a/fluid/nodes/Node.h b/fluid/nodes/Node.h index f6fce09b4..900addc6b 100644 --- a/fluid/nodes/Node.h +++ b/fluid/nodes/Node.h @@ -22,6 +22,8 @@ #include <FL/Fl_Widget.H> #include <FL/fl_draw.H> +#include <string> + class Node; class Group_Node; class Window_Node; @@ -113,6 +115,7 @@ enum class 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/panels/widget_panel.cxx b/fluid/panels/widget_panel.cxx index 5556a19fa..5f84c911f 100644 --- a/fluid/panels/widget_panel.cxx +++ b/fluid/panels/widget_panel.cxx @@ -2696,13 +2696,11 @@ static void cb_Base(Fl_Input* o, void* v) { Class_Node* nd = (Class_Node*)current_node; if (v == LOAD) { - o->value( nd->base_class_name() ); + o->value( nd->base_class().c_str() ); } else { - const char *nn = nd->base_class_name(); - if ( ( nn && (strcmp(nn, o->value()) != 0)) - || (!nn && (strcmp("", o->value()) != 0)) ) - { - nd->base_class_name( o->value() ); + auto nn = nd->base_class(); + if (nn != o->value()) { + nd->base_class( o->value() ); Fluid.proj.set_modflag(1); } } @@ -3263,7 +3261,6 @@ Fl_Double_Window* make_widget_panel() { widget_tabs->labelcolor(FL_BACKGROUND2_COLOR); widget_tabs->callback((Fl_Callback*)cb_widget_tabs); widget_tabs->when(FL_WHEN_NEVER); - widget_tabs->hide(); { wp_gui_tab = new Fl_Group(10, 30, 400, 330, "GUI"); wp_gui_tab->labelsize(11); wp_gui_tab->callback((Fl_Callback*)propagate_load); @@ -4351,6 +4348,7 @@ Fl_Double_Window* make_widget_panel() { class_tabs->labelsize(11); class_tabs->labelcolor(FL_WHITE); class_tabs->callback((Fl_Callback*)cb_class_tabs); + class_tabs->hide(); { class_tabs_main = new Fl_Group(10, 30, 400, 330, "Class"); class_tabs_main->labelsize(11); class_tabs_main->callback((Fl_Callback*)propagate_load); diff --git a/fluid/panels/widget_panel.fl b/fluid/panels/widget_panel.fl index 17c545d15..f2b2cbfbf 100644 --- a/fluid/panels/widget_panel.fl +++ b/fluid/panels/widget_panel.fl @@ -80,7 +80,7 @@ decl {\#include <FL/Fl_Menu_Item.H>} {private global decl {\#include <FL/Fl_File_Chooser.H>} {private global } -decl {\#include <ctype.h>} {selected private global +decl {\#include <ctype.h>} {private global } decl {\#define ZERO_ENTRY 1000} {private global @@ -489,8 +489,8 @@ Function {make_widget_panel()} { } { Fl_Tabs widget_tabs { callback {if (current_widget) - propagate_load((Fl_Group *)o,v);} - xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 7 when 0 hide + propagate_load((Fl_Group *)o,v);} selected + xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 7 when 0 code0 {o->show();} } { Fl_Group wp_gui_tab { @@ -2975,8 +2975,8 @@ if (v == LOAD) { } Fl_Tabs class_tabs { callback {if (current_node && current_node->is_a(Type::Class)) - propagate_load((Fl_Group *)o,v);} open - xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 255 + propagate_load((Fl_Group *)o,v);} + xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 255 hide } { Fl_Group class_tabs_main { label Class @@ -3096,13 +3096,11 @@ if (v == LOAD) { Class_Node* nd = (Class_Node*)current_node; if (v == LOAD) { - o->value( nd->base_class_name() ); + o->value( nd->base_class().c_str() ); } else { - const char *nn = nd->base_class_name(); - if ( ( nn && (strcmp(nn, o->value()) != 0)) - || (!nn && (strcmp("", o->value()) != 0)) ) - { - nd->base_class_name( o->value() ); + auto nn = nd->base_class(); + if (nn != o->value()) { + nd->base_class( o->value() ); Fluid.proj.set_modflag(1); } }} |
