mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 19:35:32 +08:00
Fluid: modernize Function Node class
This commit is contained in:
@@ -1513,7 +1513,6 @@ Class_Node Class_Node::prototype;
|
|||||||
*/
|
*/
|
||||||
Class_Node::Class_Node() :
|
Class_Node::Class_Node() :
|
||||||
Node(),
|
Node(),
|
||||||
subclass_of(nullptr),
|
|
||||||
public_(1)
|
public_(1)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -1521,8 +1520,6 @@ Class_Node::Class_Node() :
|
|||||||
Destructor.
|
Destructor.
|
||||||
*/
|
*/
|
||||||
Class_Node::~Class_Node() {
|
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();
|
Class_Node *o = new Class_Node();
|
||||||
o->name("UserInterface");
|
o->name("UserInterface");
|
||||||
o->prefix("");
|
o->prefix("");
|
||||||
o->subclass_of = nullptr;
|
o->base_class("");
|
||||||
o->public_ = 1;
|
o->public_ = 1;
|
||||||
o->add(anchor, strategy);
|
o->add(anchor, strategy);
|
||||||
o->factory = this;
|
o->factory = this;
|
||||||
@@ -1563,9 +1560,9 @@ Node *Class_Node::make(Strategy strategy) {
|
|||||||
*/
|
*/
|
||||||
void Class_Node::write_properties(fld::io::Project_Writer &f) {
|
void Class_Node::write_properties(fld::io::Project_Writer &f) {
|
||||||
Node::write_properties(f);
|
Node::write_properties(f);
|
||||||
if (subclass_of) {
|
if (!base_class().empty()) {
|
||||||
f.write_string(":");
|
f.write_string(":");
|
||||||
f.write_word(subclass_of);
|
f.write_word(base_class().c_str());
|
||||||
}
|
}
|
||||||
switch (public_) {
|
switch (public_) {
|
||||||
case 0: f.write_string("private"); break;
|
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")) {
|
} else if (!strcmp(c,"protected")) {
|
||||||
public_ = 2;
|
public_ = 2;
|
||||||
} else if (!strcmp(c,":")) {
|
} else if (!strcmp(c,":")) {
|
||||||
storestring(f.read_word(), subclass_of);
|
base_class(f.read_word());
|
||||||
} else {
|
} else {
|
||||||
Node::read_property(f, c);
|
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());
|
f.write_h("class %s %s ", prefix().c_str(), name());
|
||||||
else
|
else
|
||||||
f.write_h("class %s ", name());
|
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");
|
f.write_h("{\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -271,9 +271,9 @@ public:
|
|||||||
typedef Node super;
|
typedef Node super;
|
||||||
static Class_Node prototype;
|
static Class_Node prototype;
|
||||||
private:
|
private:
|
||||||
const char* subclass_of;
|
std::string base_class_;
|
||||||
char public_;
|
|
||||||
std::string prefix_;
|
std::string prefix_;
|
||||||
|
char public_;
|
||||||
public:
|
public:
|
||||||
Class_Node();
|
Class_Node();
|
||||||
~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); }
|
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 write_properties(fld::io::Project_Writer &f) override;
|
||||||
void read_property(fld::io::Project_Reader &f, const char *) 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_; }
|
char visibility() { return public_; }
|
||||||
void visibility(char v) { public_ = v; }
|
void visibility(char v) { public_ = v; }
|
||||||
|
|
||||||
// class prefix attribute access
|
// 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 */
|
/** Get the text between `class` and the class name */
|
||||||
std::string prefix() const { return prefix_; }
|
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
|
#endif // FLUID_NODES_FUNCTION_NODE_H
|
||||||
|
|||||||
@@ -455,6 +455,19 @@ int storestring(const char *n, const char * & p, int nostrip) {
|
|||||||
return 1;
|
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.
|
/** Update the `visible` flag for `p` and all its descendants.
|
||||||
\param[in] p start here and update all descendants
|
\param[in] p start here and update all descendants
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include <FL/Fl_Widget.H>
|
#include <FL/Fl_Widget.H>
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class Node;
|
class Node;
|
||||||
class Group_Node;
|
class Group_Node;
|
||||||
class Window_Node;
|
class Window_Node;
|
||||||
@@ -113,6 +115,7 @@ enum class Type {
|
|||||||
void update_visibility_flag(Node *p);
|
void update_visibility_flag(Node *p);
|
||||||
void delete_all(int selected_only=0);
|
void delete_all(int selected_only=0);
|
||||||
int storestring(const char *n, const char * & p, int nostrip=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_all_cb(Fl_Widget *,void *);
|
||||||
void select_none_cb(Fl_Widget *,void *);
|
void select_none_cb(Fl_Widget *,void *);
|
||||||
|
|||||||
@@ -2696,13 +2696,11 @@ static void cb_Base(Fl_Input* o, void* v) {
|
|||||||
Class_Node* nd = (Class_Node*)current_node;
|
Class_Node* nd = (Class_Node*)current_node;
|
||||||
|
|
||||||
if (v == LOAD) {
|
if (v == LOAD) {
|
||||||
o->value( nd->base_class_name() );
|
o->value( nd->base_class().c_str() );
|
||||||
} else {
|
} else {
|
||||||
const char *nn = nd->base_class_name();
|
auto nn = nd->base_class();
|
||||||
if ( ( nn && (strcmp(nn, o->value()) != 0))
|
if (nn != o->value()) {
|
||||||
|| (!nn && (strcmp("", o->value()) != 0)) )
|
nd->base_class( o->value() );
|
||||||
{
|
|
||||||
nd->base_class_name( o->value() );
|
|
||||||
Fluid.proj.set_modflag(1);
|
Fluid.proj.set_modflag(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3263,7 +3261,6 @@ Fl_Double_Window* make_widget_panel() {
|
|||||||
widget_tabs->labelcolor(FL_BACKGROUND2_COLOR);
|
widget_tabs->labelcolor(FL_BACKGROUND2_COLOR);
|
||||||
widget_tabs->callback((Fl_Callback*)cb_widget_tabs);
|
widget_tabs->callback((Fl_Callback*)cb_widget_tabs);
|
||||||
widget_tabs->when(FL_WHEN_NEVER);
|
widget_tabs->when(FL_WHEN_NEVER);
|
||||||
widget_tabs->hide();
|
|
||||||
{ wp_gui_tab = new Fl_Group(10, 30, 400, 330, "GUI");
|
{ wp_gui_tab = new Fl_Group(10, 30, 400, 330, "GUI");
|
||||||
wp_gui_tab->labelsize(11);
|
wp_gui_tab->labelsize(11);
|
||||||
wp_gui_tab->callback((Fl_Callback*)propagate_load);
|
wp_gui_tab->callback((Fl_Callback*)propagate_load);
|
||||||
@@ -4351,6 +4348,7 @@ Fl_Double_Window* make_widget_panel() {
|
|||||||
class_tabs->labelsize(11);
|
class_tabs->labelsize(11);
|
||||||
class_tabs->labelcolor(FL_WHITE);
|
class_tabs->labelcolor(FL_WHITE);
|
||||||
class_tabs->callback((Fl_Callback*)cb_class_tabs);
|
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 = new Fl_Group(10, 30, 400, 330, "Class");
|
||||||
class_tabs_main->labelsize(11);
|
class_tabs_main->labelsize(11);
|
||||||
class_tabs_main->callback((Fl_Callback*)propagate_load);
|
class_tabs_main->callback((Fl_Callback*)propagate_load);
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ decl {\#include <FL/Fl_Menu_Item.H>} {private global
|
|||||||
decl {\#include <FL/Fl_File_Chooser.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
|
decl {\#define ZERO_ENTRY 1000} {private global
|
||||||
@@ -489,8 +489,8 @@ Function {make_widget_panel()} {
|
|||||||
} {
|
} {
|
||||||
Fl_Tabs widget_tabs {
|
Fl_Tabs widget_tabs {
|
||||||
callback {if (current_widget)
|
callback {if (current_widget)
|
||||||
propagate_load((Fl_Group *)o,v);}
|
propagate_load((Fl_Group *)o,v);} selected
|
||||||
xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 7 when 0 hide
|
xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 7 when 0
|
||||||
code0 {o->show();}
|
code0 {o->show();}
|
||||||
} {
|
} {
|
||||||
Fl_Group wp_gui_tab {
|
Fl_Group wp_gui_tab {
|
||||||
@@ -2975,8 +2975,8 @@ if (v == LOAD) {
|
|||||||
}
|
}
|
||||||
Fl_Tabs class_tabs {
|
Fl_Tabs class_tabs {
|
||||||
callback {if (current_node && current_node->is_a(Type::Class))
|
callback {if (current_node && current_node->is_a(Type::Class))
|
||||||
propagate_load((Fl_Group *)o,v);} open
|
propagate_load((Fl_Group *)o,v);}
|
||||||
xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 255
|
xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 255 hide
|
||||||
} {
|
} {
|
||||||
Fl_Group class_tabs_main {
|
Fl_Group class_tabs_main {
|
||||||
label Class
|
label Class
|
||||||
@@ -3096,13 +3096,11 @@ if (v == LOAD) {
|
|||||||
Class_Node* nd = (Class_Node*)current_node;
|
Class_Node* nd = (Class_Node*)current_node;
|
||||||
|
|
||||||
if (v == LOAD) {
|
if (v == LOAD) {
|
||||||
o->value( nd->base_class_name() );
|
o->value( nd->base_class().c_str() );
|
||||||
} else {
|
} else {
|
||||||
const char *nn = nd->base_class_name();
|
auto nn = nd->base_class();
|
||||||
if ( ( nn && (strcmp(nn, o->value()) != 0))
|
if (nn != o->value()) {
|
||||||
|| (!nn && (strcmp("", o->value()) != 0)) )
|
nd->base_class( o->value() );
|
||||||
{
|
|
||||||
nd->base_class_name( o->value() );
|
|
||||||
Fluid.proj.set_modflag(1);
|
Fluid.proj.set_modflag(1);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user