Fluid: Rename Stratgy constants to comply with CMP.
Build and Test / build-linux (push) Waiting to run
Build and Test / build-wayland (push) Waiting to run
Build and Test / build-macos (push) Waiting to run
Build and Test / build-windows (push) Waiting to run

Capitalized constants.
Added flag to indicate creation by user or file.
Removed global variable 'reading_file'.
This commit is contained in:
Matthias Melcher
2024-12-27 20:56:02 -05:00
parent 2100655a1b
commit 050cbabdfe
16 changed files with 114 additions and 90 deletions
+24 -17
View File
@@ -202,15 +202,16 @@ Fl_Function_Type::~Fl_Function_Type() {
/** /**
Create a new function for the widget tree. Create a new function for the widget tree.
\param[in] strategy new function add after current or as last child \param[in] strategy add new function after current or as last child
\return the new node \return the new node
*/ */
Fl_Type *Fl_Function_Type::make(Strategy strategy) { Fl_Type *Fl_Function_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !p->is_decl_block()) { while (p && !p->is_decl_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
Fl_Function_Type *o = new Fl_Function_Type(); Fl_Function_Type *o = new Fl_Function_Type();
@@ -596,10 +597,11 @@ Fl_Code_Type::Fl_Code_Type() :
*/ */
Fl_Type *Fl_Code_Type::make(Strategy strategy) { Fl_Type *Fl_Code_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !p->is_code_block()) { while (p && !p->is_code_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
if (!p) { if (!p) {
@@ -763,10 +765,11 @@ Fl_CodeBlock_Type::~Fl_CodeBlock_Type() {
*/ */
Fl_Type *Fl_CodeBlock_Type::make(Strategy strategy) { Fl_Type *Fl_CodeBlock_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !p->is_code_block()) { while (p && !p->is_code_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
if (!p) { if (!p) {
@@ -904,10 +907,11 @@ int Fl_Decl_Type::is_public() const
*/ */
Fl_Type *Fl_Decl_Type::make(Strategy strategy) { Fl_Type *Fl_Decl_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !p->is_decl_block()) { while (p && !p->is_decl_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
Fl_Decl_Type *o = new Fl_Decl_Type(); Fl_Decl_Type *o = new Fl_Decl_Type();
@@ -1131,10 +1135,11 @@ Fl_Data_Type::~Fl_Data_Type() {
*/ */
Fl_Type *Fl_Data_Type::make(Strategy strategy) { Fl_Type *Fl_Data_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !p->is_decl_block()) { while (p && !p->is_decl_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
Fl_Data_Type *o = new Fl_Data_Type(); Fl_Data_Type *o = new Fl_Data_Type();
@@ -1474,10 +1479,10 @@ int Fl_DeclBlock_Type::is_public() const {
*/ */
Fl_Type *Fl_DeclBlock_Type::make(Strategy strategy) { Fl_Type *Fl_DeclBlock_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT)) p = p->parent;
while (p && !p->is_decl_block()) { while (p && !p->is_decl_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
Fl_DeclBlock_Type *o = new Fl_DeclBlock_Type(); Fl_DeclBlock_Type *o = new Fl_DeclBlock_Type();
@@ -1706,10 +1711,11 @@ Fl_Comment_Type::Fl_Comment_Type() :
*/ */
Fl_Type *Fl_Comment_Type::make(Strategy strategy) { Fl_Type *Fl_Comment_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !p->is_code_block()) { while (p && !p->is_code_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
Fl_Comment_Type *o = new Fl_Comment_Type(); Fl_Comment_Type *o = new Fl_Comment_Type();
@@ -1985,10 +1991,11 @@ void Fl_Class_Type::prefix(const char*p) {
*/ */
Fl_Type *Fl_Class_Type::make(Strategy strategy) { Fl_Type *Fl_Class_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !p->is_decl_block()) { while (p && !p->is_decl_block()) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
Fl_Class_Type *o = new Fl_Class_Type(); Fl_Class_Type *o = new Fl_Class_Type();
+2 -2
View File
@@ -117,7 +117,7 @@ void group_cb(Fl_Widget *, void *) {
undo_checkpoint(); undo_checkpoint();
undo_suspend(); undo_suspend();
Fl_Type::current = qq; Fl_Type::current = qq;
Fl_Group_Type *n = (Fl_Group_Type*)(Fl_Group_type.make(kAddAsLastChild)); Fl_Group_Type *n = (Fl_Group_Type*)(Fl_Group_type.make(Strategy::AS_LAST_CHILD));
n->move_before(q); n->move_before(q);
n->o->resize(q->o->x(),q->o->y(),q->o->w(),q->o->h()); n->o->resize(q->o->x(),q->o->y(),q->o->w(),q->o->h());
for (Fl_Type *t = qq->next; t && (t->level > qq->level);) { for (Fl_Type *t = qq->next; t && (t->level > qq->level);) {
@@ -126,7 +126,7 @@ void group_cb(Fl_Widget *, void *) {
continue; continue;
} }
Fl_Type *nxt = t->remove(); Fl_Type *nxt = t->remove();
t->add(n, kAddAsLastChild); t->add(n, Strategy::AS_LAST_CHILD);
t = nxt; t = nxt;
} }
fix_group_size(n); fix_group_size(n);
+6 -5
View File
@@ -162,10 +162,11 @@ Fl_Type *Fl_Menu_Item_Type::make(Strategy strategy) {
Fl_Type* Fl_Menu_Item_Type::make(int flags, Strategy strategy) { Fl_Type* Fl_Menu_Item_Type::make(int flags, Strategy strategy) {
// Find a good insert position based on the current marked node // Find a good insert position based on the current marked node
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT))
p = p->parent;
while (p && !(p->is_a(ID_Menu_Manager_) || p->is_a(ID_Submenu))) { while (p && !(p->is_a(ID_Menu_Manager_) || p->is_a(ID_Submenu))) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
if (!p) { if (!p) {
@@ -186,7 +187,7 @@ Fl_Type* Fl_Menu_Item_Type::make(int flags, Strategy strategy) {
t->o->type(flags); t->o->type(flags);
t->factory = this; t->factory = this;
t->add(anchor, strategy); t->add(anchor, strategy);
if (!reading_file) { if (strategy.source() == Strategy::FROM_USER) {
if (flags==FL_SUBMENU) { if (flags==FL_SUBMENU) {
t->label("submenu"); t->label("submenu");
} else { } else {
@@ -209,14 +210,14 @@ void group_selected_menuitems() {
} }
undo_checkpoint(); undo_checkpoint();
undo_suspend(); undo_suspend();
Fl_Widget_Type *n = (Fl_Widget_Type*)(q->make(FL_SUBMENU, kAddAfterCurrent)); Fl_Widget_Type *n = (Fl_Widget_Type*)(q->make(FL_SUBMENU, Strategy::AFTER_CURRENT));
for (Fl_Type *t = qq->next; t && (t->level > qq->level);) { for (Fl_Type *t = qq->next; t && (t->level > qq->level);) {
if (t->level != n->level || t == n || !t->selected) { if (t->level != n->level || t == n || !t->selected) {
t = t->next; t = t->next;
continue; continue;
} }
Fl_Type *nxt = t->remove(); Fl_Type *nxt = t->remove();
t->add(n, kAddAsLastChild); t->add(n, Strategy::AS_LAST_CHILD);
t = nxt; t = nxt;
} }
widget_browser->rebuild(); widget_browser->rebuild();
+6 -5
View File
@@ -619,7 +619,7 @@ Fl_Group_Type *Fl_Type::group() {
This methods updates the widget_browser. This methods updates the widget_browser.
\param[in] p insert \c this tree as a child of \c p \param[in] p insert \c this tree as a child of \c p
\param[in] strategy is kAddAsLastChild or kAddAfterCurrent \param[in] strategy is Strategy::AS_LAST_CHILD or Strategy::AFTER_CURRENT
*/ */
void Fl_Type::add(Fl_Type *anchor, Strategy strategy) { void Fl_Type::add(Fl_Type *anchor, Strategy strategy) {
#if 0 #if 0
@@ -637,8 +637,9 @@ void Fl_Type::add(Fl_Type *anchor, Strategy strategy) {
int target_level = 0; // adjust self to this new level int target_level = 0; // adjust self to this new level
// Find the node after our insertion position // Find the node after our insertion position
switch (strategy) { switch (strategy.placement()) {
case kAddAsFirstChild: case Strategy::AS_FIRST_CHILD:
default:
if (anchor == NULL) { if (anchor == NULL) {
target = Fl_Type::first; target = Fl_Type::first;
} else { } else {
@@ -647,7 +648,7 @@ void Fl_Type::add(Fl_Type *anchor, Strategy strategy) {
target_parent = anchor; target_parent = anchor;
} }
break; break;
case kAddAsLastChild: case Strategy::AS_LAST_CHILD:
if (anchor == NULL) { if (anchor == NULL) {
/* empty */ /* empty */
} else { } else {
@@ -656,7 +657,7 @@ void Fl_Type::add(Fl_Type *anchor, Strategy strategy) {
target_parent = anchor; target_parent = anchor;
} }
break; break;
case kAddAfterCurrent: case Strategy::AFTER_CURRENT:
if (anchor == NULL) { if (anchor == NULL) {
target = Fl_Type::first; target = Fl_Type::first;
} else { } else {
+26 -6
View File
@@ -30,9 +30,14 @@ class Fd_Project_Reader;
class Fd_Project_Writer; class Fd_Project_Writer;
/** /**
Declare where a new type is placed in the hierarchy. Declare where a new type is placed and how to create it.
Note that a type can also be the start of a hierarchy of types. In that case, Placement can be as the first or last child of the anchor, or right after the
anchor. In most cases, the anchor is the last selected type node.
If the source is FROM_USER, widgets may be created with default titles and
labels. Type created FROM_FILE will start with no label, so the label is set
correctly later.
\see Fl_Type *Fl_..._Type::make(Strategy strategy) calls `add()` \see Fl_Type *Fl_..._Type::make(Strategy strategy) calls `add()`
Add single Type: Add single Type:
@@ -45,10 +50,25 @@ class Fd_Project_Writer;
Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options) Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options)
int Fd_Project_Reader::read_project(const char *filename, int merge, Strategy strategy) int Fd_Project_Reader::read_project(const char *filename, int merge, Strategy strategy)
*/ */
typedef enum { typedef struct Strategy {
kAddAsFirstChild = 0, enum Flags {
kAddAsLastChild, AS_FIRST_CHILD = 0x0000,
kAddAfterCurrent AS_LAST_CHILD = 0x0001,
AFTER_CURRENT = 0x0002,
PLACEMENT_MASK = 0x000f,
FROM_USER = 0x0000,
FROM_FILE = 0x0010,
SOURCE_MASK = 0x00f0,
FROM_FILE_AS_FIRST_CHILD = 0x0010,
FROM_FILE_AS_LAST_CHILD = 0x0011,
FROM_FILE_AFTER_CURRENT = 0x0012,
};
Flags flags;
Strategy(Flags f) { flags = f; }
void placement(Flags f) { flags = (Flags)((flags & ~PLACEMENT_MASK) | (f & PLACEMENT_MASK)); }
Flags placement() { return (Flags)(flags & PLACEMENT_MASK); }
void source(Flags f) { flags = (Flags)((flags & ~SOURCE_MASK) | (f & SOURCE_MASK)); }
Flags source() { return (Flags)(flags & SOURCE_MASK); }
} Strategy; } Strategy;
enum ID { enum ID {
+6 -4
View File
@@ -83,15 +83,16 @@ Fl_Widget_Type::ideal_size(int &w, int &h) {
/** /**
Make a new Widget node. Make a new Widget node.
\param[in] strategy is kAddAsLastChild or kAddAfterCurrent \param[in] strategy is Strategy::AS_LAST_CHILD or Strategy::AFTER_CURRENT
\return new node \return new node
*/ */
Fl_Type *Fl_Widget_Type::make(Strategy strategy) { Fl_Type *Fl_Widget_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *pp = anchor; Fl_Type *anchor = Fl_Type::current, *pp = anchor;
if (pp && (strategy == kAddAfterCurrent)) pp = pp->parent; if (pp && (strategy.placement() == Strategy::AFTER_CURRENT))
pp = pp->parent;
while (pp && !pp->is_a(ID_Group)) { while (pp && !pp->is_a(ID_Group)) {
anchor = pp; anchor = pp;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
pp = pp->parent; pp = pp->parent;
} }
if (!pp || !pp->is_true_widget() || !anchor->is_true_widget()) { if (!pp || !pp->is_true_widget() || !anchor->is_true_widget()) {
@@ -141,7 +142,8 @@ Fl_Type *Fl_Widget_Type::make(Strategy strategy) {
t->factory = this; t->factory = this;
// Construct the Fl_Widget: // Construct the Fl_Widget:
t->o = widget(X,Y,W,H); t->o = widget(X,Y,W,H);
if (reading_file) t->o->label(0); if (strategy.source() == Strategy::FROM_FILE)
t->o->label(0);
else if (t->o->label()) t->label(t->o->label()); // allow editing else if (t->o->label()) t->label(t->o->label()); // allow editing
t->o->user_data((void*)t); t->o->user_data((void*)t);
// Put it in the parent: // Put it in the parent:
+7 -7
View File
@@ -223,15 +223,15 @@ int Overlay_Window::handle(int e) {
/** /**
Make and add a new Window node. Make and add a new Window node.
\param[in] strategy is kAddAsLastChild or kAddAfterCurrent \param[in] strategy is Strategy::AS_LAST_CHILD or Strategy::AFTER_CURRENT
\return new node \return new node
*/ */
Fl_Type *Fl_Window_Type::make(Strategy strategy) { Fl_Type *Fl_Window_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT)) p = p->parent;
while (p && (!p->is_code_block() || p->is_a(ID_Widget_Class))) { while (p && (!p->is_code_block() || p->is_a(ID_Widget_Class))) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
if (!p) { if (!p) {
@@ -1073,10 +1073,10 @@ int Fl_Window_Type::handle(int event) {
{ {
Fl_Type *cc = Fl_Type::current; Fl_Type *cc = Fl_Type::current;
Fl_Type::current = Fl_Type::current_dnd; Fl_Type::current = Fl_Type::current_dnd;
add_new_widget_from_user(prototype, kAddAsLastChild); add_new_widget_from_user(prototype, Strategy::AS_LAST_CHILD);
Fl_Type::current = cc; Fl_Type::current = cc;
} else { } else {
add_new_widget_from_user(prototype, kAddAsLastChild); add_new_widget_from_user(prototype, Strategy::AS_LAST_CHILD);
} }
popupx = 0x7FFFFFFF; popupx = 0x7FFFFFFF;
popupy = 0x7FFFFFFF; // mark as invalid (MAXINT) popupy = 0x7FFFFFFF; // mark as invalid (MAXINT)
@@ -1376,10 +1376,10 @@ Fl_Widget_Class_Type *current_widget_class = 0;
*/ */
Fl_Type *Fl_Widget_Class_Type::make(Strategy strategy) { Fl_Type *Fl_Widget_Class_Type::make(Strategy strategy) {
Fl_Type *anchor = Fl_Type::current, *p = anchor; Fl_Type *anchor = Fl_Type::current, *p = anchor;
if (p && (strategy == kAddAfterCurrent)) p = p->parent; if (p && (strategy.placement() == Strategy::AFTER_CURRENT)) p = p->parent;
while (p && (!p->is_decl_block() || (p->is_widget() && p->is_class()))) { while (p && (!p->is_decl_block() || (p->is_widget() && p->is_class()))) {
anchor = p; anchor = p;
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
p = p->parent; p = p->parent;
} }
Fl_Widget_Class_Type *myo = new Fl_Widget_Class_Type(); Fl_Widget_Class_Type *myo = new Fl_Widget_Class_Type();
+10 -10
View File
@@ -383,22 +383,22 @@ void run_autodoc(const Fl_String &target_dir) {
// Create a silly project that contains all widgets that we want to document // Create a silly project that contains all widgets that we want to document
new_project(false); new_project(false);
/*Fl_Type *t_func = */ add_new_widget_from_user("Function", kAddAsLastChild, false); /*Fl_Type *t_func = */ add_new_widget_from_user("Function", Strategy::AS_LAST_CHILD, false);
Fl_Window_Type *t_win = (Fl_Window_Type*)add_new_widget_from_user("Fl_Window", kAddAsLastChild, false); Fl_Window_Type *t_win = (Fl_Window_Type*)add_new_widget_from_user("Fl_Window", Strategy::AS_LAST_CHILD, false);
t_win->label("My Main Window"); t_win->label("My Main Window");
Fl_Widget_Type *t_grp = (Fl_Widget_Type*)add_new_widget_from_user("Fl_Group", kAddAsLastChild, false); Fl_Widget_Type *t_grp = (Fl_Widget_Type*)add_new_widget_from_user("Fl_Group", Strategy::AS_LAST_CHILD, false);
t_grp->public_ = 0; t_grp->public_ = 0;
Fl_Widget_Type *t_btn = (Fl_Widget_Type*)add_new_widget_from_user("Fl_Button", kAddAsLastChild, false); Fl_Widget_Type *t_btn = (Fl_Widget_Type*)add_new_widget_from_user("Fl_Button", Strategy::AS_LAST_CHILD, false);
t_btn->comment("Don't press this button!"); t_btn->comment("Don't press this button!");
t_btn->name("emergency_btn"); t_btn->name("emergency_btn");
((Fl_Button*)t_btn->o)->shortcut(FL_COMMAND|'g'); ((Fl_Button*)t_btn->o)->shortcut(FL_COMMAND|'g');
Fl_Type *t_sldr = add_new_widget_from_user("Fl_Slider", kAddAsLastChild, false); Fl_Type *t_sldr = add_new_widget_from_user("Fl_Slider", Strategy::AS_LAST_CHILD, false);
Fl_Type *t_inp = add_new_widget_from_user("Fl_Input", kAddAsLastChild, false); Fl_Type *t_inp = add_new_widget_from_user("Fl_Input", Strategy::AS_LAST_CHILD, false);
Fl_Type *t_flx = add_new_widget_from_user("Fl_Flex", kAddAsLastChild, false); Fl_Type *t_flx = add_new_widget_from_user("Fl_Flex", Strategy::AS_LAST_CHILD, false);
Fl_Type *t_flxc = add_new_widget_from_user("Fl_Button", kAddAsLastChild, false); Fl_Type *t_flxc = add_new_widget_from_user("Fl_Button", Strategy::AS_LAST_CHILD, false);
select_only(t_grp); select_only(t_grp);
Fl_Type *t_grd = add_new_widget_from_user("Fl_Grid", kAddAsLastChild, false); Fl_Type *t_grd = add_new_widget_from_user("Fl_Grid", Strategy::AS_LAST_CHILD, false);
Fl_Type *t_grdc = add_new_widget_from_user("Fl_Button", kAddAsLastChild, false); Fl_Type *t_grdc = add_new_widget_from_user("Fl_Button", Strategy::AS_LAST_CHILD, false);
widget_browser->rebuild(); widget_browser->rebuild();
g_project.update_settings_dialog(); g_project.update_settings_dialog();
+1 -1
View File
@@ -110,7 +110,7 @@ int Widget_Bin_Window_Button::handle(int inEvent)
// create a new window here // create a new window here
Fl_Type *prototype = typename_to_prototype((char*)user_data()); Fl_Type *prototype = typename_to_prototype((char*)user_data());
if (prototype) { if (prototype) {
Fl_Type *new_type = add_new_widget_from_user(prototype, kAddAfterCurrent); Fl_Type *new_type = add_new_widget_from_user(prototype, Strategy::AFTER_CURRENT);
if (new_type && new_type->is_a(ID_Window)) { if (new_type && new_type->is_a(ID_Window)) {
Fl_Window_Type *new_window = (Fl_Window_Type*)new_type; Fl_Window_Type *new_window = (Fl_Window_Type*)new_type;
Fl_Window *w = (Fl_Window *)new_window->o; Fl_Window *w = (Fl_Window *)new_window->o;
+4 -6
View File
@@ -1355,9 +1355,9 @@ Fl_Type *add_new_widget_from_user(const char *inName, Strategy strategy, bool an
static void cbf(Fl_Widget *, void *v) { static void cbf(Fl_Widget *, void *v) {
Fl_Type *t = NULL; Fl_Type *t = NULL;
if (Fl_Type::current && Fl_Type::current->can_have_children()) if (Fl_Type::current && Fl_Type::current->can_have_children())
t = ((Fl_Type*)v)->make(kAddAsLastChild); t = ((Fl_Type*)v)->make(Strategy::AS_LAST_CHILD);
else else
t = ((Fl_Type*)v)->make(kAddAfterCurrent); t = ((Fl_Type*)v)->make(Strategy::AFTER_CURRENT);
select_only(t); select_only(t);
} }
@@ -1370,9 +1370,9 @@ static void cbf(Fl_Widget *, void *v) {
static void cb(Fl_Widget *, void *v) { static void cb(Fl_Widget *, void *v) {
Fl_Type *t = NULL; Fl_Type *t = NULL;
if (Fl_Type::current && Fl_Type::current->can_have_children()) if (Fl_Type::current && Fl_Type::current->can_have_children())
t = add_new_widget_from_user((Fl_Type*)v, kAddAsLastChild); t = add_new_widget_from_user((Fl_Type*)v, Strategy::AS_LAST_CHILD);
else else
t = add_new_widget_from_user((Fl_Type*)v, kAddAfterCurrent); t = add_new_widget_from_user((Fl_Type*)v, Strategy::AFTER_CURRENT);
select_only(t); select_only(t);
} }
@@ -1546,9 +1546,7 @@ Fl_Type *add_new_widget_from_file(const char *inName, Strategy strategy) {
Fl_Type *prototype = typename_to_prototype(inName); Fl_Type *prototype = typename_to_prototype(inName);
if (!prototype) if (!prototype)
return NULL; return NULL;
reading_file = 1; // makes labels be null
Fl_Type *new_node = prototype->make(strategy); Fl_Type *new_node = prototype->make(strategy);
reading_file = 0;
return new_node; return new_node;
} }
+11 -10
View File
@@ -63,6 +63,7 @@ int fdesign_flip = 0;
*/ */
int read_file(const char *filename, int merge, Strategy strategy) { int read_file(const char *filename, int merge, Strategy strategy) {
Fd_Project_Reader f; Fd_Project_Reader f;
strategy.source(Strategy::FROM_FILE);
return f.read_project(filename, merge, strategy); return f.read_project(filename, merge, strategy);
} }
@@ -260,7 +261,7 @@ Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strate
// back compatibility with Vincent Penne's original class code: // back compatibility with Vincent Penne's original class code:
if (!p && !strcmp(c,"define_in_struct")) { if (!p && !strcmp(c,"define_in_struct")) {
Fl_Type *t = add_new_widget_from_file("class", kAddAsLastChild); Fl_Type *t = add_new_widget_from_file("class", Strategy::FROM_FILE_AS_LAST_CHILD);
t->name(read_word()); t->name(read_word());
Fl_Type::current = p = t; Fl_Type::current = p = t;
merge = 1; // stops "missing }" error merge = 1; // stops "missing }" error
@@ -390,7 +391,7 @@ Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strate
read_error("Missing child list for %s\n",t->title()); read_error("Missing child list for %s\n",t->title());
goto REUSE_C; goto REUSE_C;
} }
read_children(t, 0, kAddAsLastChild, skip_options); read_children(t, 0, Strategy::FROM_FILE_AS_LAST_CHILD, skip_options);
t->postprocess_read(); t->postprocess_read();
// FIXME: this has no business in the file reader! // FIXME: this has no business in the file reader!
// TODO: this is called whenever something is pasted from the top level into a grid // TODO: this is called whenever something is pasted from the top level into a grid
@@ -406,10 +407,10 @@ Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strate
t->layout_widget(); t->layout_widget();
} }
if (strategy == kAddAsFirstChild) { if (strategy.placement() == Strategy::AS_FIRST_CHILD) {
strategy = kAddAfterCurrent; strategy.placement(Strategy::AFTER_CURRENT);
} }
if (strategy == kAddAfterCurrent) { if (strategy.placement() == Strategy::AFTER_CURRENT) {
Fl_Type::current = t; Fl_Type::current = t;
} else { } else {
Fl_Type::current = p; Fl_Type::current = p;
@@ -733,7 +734,7 @@ void Fd_Project_Reader::read_fdesign() {
Fl_Widget_Type *group = 0; Fl_Widget_Type *group = 0;
Fl_Widget_Type *widget = 0; Fl_Widget_Type *widget = 0;
if (!Fl_Type::current) { if (!Fl_Type::current) {
Fl_Type *t = add_new_widget_from_file("Function", kAddAsLastChild); Fl_Type *t = add_new_widget_from_file("Function", Strategy::FROM_FILE_AS_LAST_CHILD);
t->name("create_the_forms()"); t->name("create_the_forms()");
Fl_Type::current = t; Fl_Type::current = t;
} }
@@ -744,7 +745,7 @@ void Fd_Project_Reader::read_fdesign() {
if (!strcmp(name,"Name")) { if (!strcmp(name,"Name")) {
window = (Fl_Widget_Type*)add_new_widget_from_file("Fl_Window", kAddAsLastChild); window = (Fl_Widget_Type*)add_new_widget_from_file("Fl_Window", Strategy::FROM_FILE_AS_LAST_CHILD);
window->name(value); window->name(value);
window->label(value); window->label(value);
Fl_Type::current = widget = window; Fl_Type::current = widget = window;
@@ -752,7 +753,7 @@ void Fd_Project_Reader::read_fdesign() {
} else if (!strcmp(name,"class")) { } else if (!strcmp(name,"class")) {
if (!strcmp(value,"FL_BEGIN_GROUP")) { if (!strcmp(value,"FL_BEGIN_GROUP")) {
group = widget = (Fl_Widget_Type*)add_new_widget_from_file("Fl_Group", kAddAsLastChild); group = widget = (Fl_Widget_Type*)add_new_widget_from_file("Fl_Group", Strategy::FROM_FILE_AS_LAST_CHILD);
Fl_Type::current = group; Fl_Type::current = group;
} else if (!strcmp(value,"FL_END_GROUP")) { } else if (!strcmp(value,"FL_END_GROUP")) {
if (group) { if (group) {
@@ -767,10 +768,10 @@ void Fd_Project_Reader::read_fdesign() {
for (int i = 0; class_matcher[i]; i += 2) for (int i = 0; class_matcher[i]; i += 2)
if (!strcmp(value,class_matcher[i])) { if (!strcmp(value,class_matcher[i])) {
value = class_matcher[i+1]; break;} value = class_matcher[i+1]; break;}
widget = (Fl_Widget_Type*)add_new_widget_from_file(value, kAddAsLastChild); widget = (Fl_Widget_Type*)add_new_widget_from_file(value, Strategy::FROM_FILE_AS_LAST_CHILD);
if (!widget) { if (!widget) {
printf("class %s not found, using Fl_Button\n", value); printf("class %s not found, using Fl_Button\n", value);
widget = (Fl_Widget_Type*)add_new_widget_from_file("Fl_Button", kAddAsLastChild); widget = (Fl_Widget_Type*)add_new_widget_from_file("Fl_Button", Strategy::FROM_FILE_AS_LAST_CHILD);
} }
} }
+2 -2
View File
@@ -25,7 +25,7 @@ class Fl_Type;
extern int fdesign_flip; extern int fdesign_flip;
int read_file(const char *, int merge, Strategy strategy=kAddAsLastChild); int read_file(const char *, int merge, Strategy strategy=Strategy::FROM_FILE_AS_LAST_CHILD);
int write_file(const char *, int selected_only = 0, bool to_codeview = false); int write_file(const char *, int selected_only = 0, bool to_codeview = false);
class Fd_Project_Reader class Fd_Project_Reader
@@ -58,7 +58,7 @@ public:
const char *filename_name(); const char *filename_name();
int read_quoted(); int read_quoted();
Fl_Type *read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options=0); Fl_Type *read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options=0);
int read_project(const char *, int merge, Strategy strategy=kAddAsLastChild); int read_project(const char *, int merge, Strategy strategy=Strategy::FROM_FILE_AS_LAST_CHILD);
void read_error(const char *format, ...); void read_error(const char *format, ...);
const char *read_word(int wantbrace = 0); const char *read_word(int wantbrace = 0);
int read_int(); int read_int();
+4 -9
View File
@@ -106,11 +106,6 @@ int G_debug = 0;
char G_external_editor_command[512]; char G_external_editor_command[512];
/// This is set to create different labels when creating new widgets.
/// \todo Details unclear.
int reading_file = 0;
// File history info... // File history info...
/// Stores the absolute filename of the last 10 design files, saved in app preferences. /// Stores the absolute filename of the last 10 design files, saved in app preferences.
@@ -1418,14 +1413,14 @@ void paste_cb(Fl_Widget*, void*) {
pasteoffset = ipasteoffset; pasteoffset = ipasteoffset;
undo_checkpoint(); undo_checkpoint();
undo_suspend(); undo_suspend();
Strategy strategy = kAddAfterCurrent; Strategy strategy = Strategy::FROM_FILE_AFTER_CURRENT;
if (Fl_Type::current && Fl_Type::current->can_have_children()) { if (Fl_Type::current && Fl_Type::current->can_have_children()) {
if (Fl_Type::current->folded_ == 0) { if (Fl_Type::current->folded_ == 0) {
// If the current widget is a group widget and it is not folded, // If the current widget is a group widget and it is not folded,
// add the new widgets inside the group. // add the new widgets inside the group.
strategy = kAddAsLastChild; strategy = Strategy::FROM_FILE_AS_LAST_CHILD;
// The following alternative also works quite nicely // The following alternative also works quite nicely
//strategy = kAddAsFirstChild; //strategy = Strategy::FROM_FILE_AS_FIRST_CHILD;
} }
} }
if (!read_file(cutfname(), 1, strategy)) { if (!read_file(cutfname(), 1, strategy)) {
@@ -1479,7 +1474,7 @@ void duplicate_cb(Fl_Widget*, void*) {
pasteoffset = 0; pasteoffset = 0;
undo_checkpoint(); undo_checkpoint();
undo_suspend(); undo_suspend();
if (!read_file(cutfname(1), 1, kAddAfterCurrent)) { if (!read_file(cutfname(1), 1, Strategy::FROM_FILE_AFTER_CURRENT)) {
fl_message("Can't read %s: %s", cutfname(1), strerror(errno)); fl_message("Can't read %s: %s", cutfname(1), strerror(errno));
} }
fl_unlink(cutfname(1)); fl_unlink(cutfname(1));
-2
View File
@@ -65,8 +65,6 @@ extern int G_use_external_editor;
extern int G_debug; extern int G_debug;
extern char G_external_editor_command[512]; extern char G_external_editor_command[512];
extern int reading_file;
// File history info... // File history info...
extern char absolute_history[10][FL_PATH_MAX]; extern char absolute_history[10][FL_PATH_MAX];
extern char relative_history[10][FL_PATH_MAX]; extern char relative_history[10][FL_PATH_MAX];
+2 -2
View File
@@ -766,9 +766,9 @@ Fl_Double_Window* make_comment_panel() {
void type_make_cb(Fl_Widget*,void*d) { void type_make_cb(Fl_Widget*,void*d) {
const char *type_name = (const char*)d; const char *type_name = (const char*)d;
if (Fl_Type::current && Fl_Type::current->can_have_children()) if (Fl_Type::current && Fl_Type::current->can_have_children())
add_new_widget_from_user(type_name, kAddAsLastChild); add_new_widget_from_user(type_name, Strategy::AS_LAST_CHILD);
else else
add_new_widget_from_user(type_name, kAddAfterCurrent); add_new_widget_from_user(type_name, Strategy::AFTER_CURRENT);
} }
Fl_Window *widgetbin_panel=(Fl_Window *)0; Fl_Window *widgetbin_panel=(Fl_Window *)0;
+3 -2
View File
@@ -589,9 +589,10 @@ Function {type_make_cb(Fl_Widget*,void*d)} {open return_type void
} { } {
code {const char *type_name = (const char*)d; code {const char *type_name = (const char*)d;
if (Fl_Type::current && Fl_Type::current->can_have_children()) if (Fl_Type::current && Fl_Type::current->can_have_children())
add_new_widget_from_user(type_name, kAddAsLastChild); add_new_widget_from_user(type_name, Strategy::AS_LAST_CHILD);
else else
add_new_widget_from_user(type_name, kAddAfterCurrent);} {} add_new_widget_from_user(type_name, Strategy::AFTER_CURRENT);} {selected
}
} }
Function {make_widgetbin()} {open Function {make_widgetbin()} {open