FLUID: Imporving method name `can_have_children()`

This commit is contained in:
Matthias Melcher 2024-09-11 15:00:48 +02:00
parent 9b777cc011
commit a7328d940b
11 changed files with 29 additions and 29 deletions

View File

@ -60,7 +60,7 @@ public:
const char *title() FL_OVERRIDE { const char *title() FL_OVERRIDE {
return name() ? name() : "main()"; return name() ? name() : "main()";
} }
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
int is_code_block() const FL_OVERRIDE {return 1;} int is_code_block() const FL_OVERRIDE {return 1;}
int is_public() const FL_OVERRIDE; int is_public() const FL_OVERRIDE;
ID id() const FL_OVERRIDE { return ID_Function; } ID id() const FL_OVERRIDE { return ID_Function; }
@ -113,7 +113,7 @@ public:
void open() FL_OVERRIDE; void open() FL_OVERRIDE;
const char *type_name() FL_OVERRIDE {return "codeblock";} const char *type_name() FL_OVERRIDE {return "codeblock";}
int is_code_block() const FL_OVERRIDE {return 1;} int is_code_block() const FL_OVERRIDE {return 1;}
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
int is_public() const FL_OVERRIDE { return -1; } int is_public() const FL_OVERRIDE { return -1; }
ID id() const FL_OVERRIDE { return ID_CodeBlock; } ID id() const FL_OVERRIDE { return ID_CodeBlock; }
bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_CodeBlock) ? true : super::is_a(inID); } bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_CodeBlock) ? true : super::is_a(inID); }
@ -193,7 +193,7 @@ public:
const char *type_name() FL_OVERRIDE {return "declblock";} const char *type_name() FL_OVERRIDE {return "declblock";}
void write_properties(Fd_Project_Writer &f) FL_OVERRIDE; void write_properties(Fd_Project_Writer &f) FL_OVERRIDE;
void read_property(Fd_Project_Reader &f, const char *) FL_OVERRIDE; void read_property(Fd_Project_Reader &f, const char *) FL_OVERRIDE;
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
int is_decl_block() const FL_OVERRIDE {return 1;} int is_decl_block() const FL_OVERRIDE {return 1;}
int is_public() const FL_OVERRIDE; int is_public() const FL_OVERRIDE;
ID id() const FL_OVERRIDE { return ID_DeclBlock; } ID id() const FL_OVERRIDE { return ID_DeclBlock; }
@ -242,7 +242,7 @@ public:
void write_code2(Fd_Code_Writer& f) FL_OVERRIDE; void write_code2(Fd_Code_Writer& f) FL_OVERRIDE;
void open() FL_OVERRIDE; void open() FL_OVERRIDE;
const char *type_name() FL_OVERRIDE {return "class";} const char *type_name() FL_OVERRIDE {return "class";}
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
int is_decl_block() const FL_OVERRIDE {return 1;} int is_decl_block() const FL_OVERRIDE {return 1;}
int is_class() const FL_OVERRIDE {return 1;} int is_class() const FL_OVERRIDE {return 1;}
int is_public() const FL_OVERRIDE; int is_public() const FL_OVERRIDE;

View File

@ -59,7 +59,7 @@ public:
void add_child(Fl_Type*, Fl_Type*) FL_OVERRIDE; void add_child(Fl_Type*, Fl_Type*) FL_OVERRIDE;
void move_child(Fl_Type*, Fl_Type*) FL_OVERRIDE; void move_child(Fl_Type*, Fl_Type*) FL_OVERRIDE;
void remove_child(Fl_Type*) FL_OVERRIDE; void remove_child(Fl_Type*) FL_OVERRIDE;
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
ID id() const FL_OVERRIDE { return ID_Group; } ID id() const FL_OVERRIDE { return ID_Group; }
bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_Group) ? true : super::is_a(inID); } bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_Group) ? true : super::is_a(inID); }
Fl_Widget *enter_live_mode(int top=0) FL_OVERRIDE; Fl_Widget *enter_live_mode(int top=0) FL_OVERRIDE;

View File

@ -89,7 +89,7 @@ void Fl_Input_Choice_Type::build_menu() {
int n = 0; int n = 0;
Fl_Type* q; Fl_Type* q;
for (q = next; q && q->level > level; q = q->next) { for (q = next; q && q->level > level; q = q->next) {
if (q->is_parent()) n++; // space for null at end of submenu if (q->can_have_children()) n++; // space for null at end of submenu
n++; n++;
} }
if (!n) { if (!n) {
@ -136,7 +136,7 @@ void Fl_Input_Choice_Type::build_menu() {
m->labelfont(i->o->labelfont()); m->labelfont(i->o->labelfont());
m->labelsize(i->o->labelsize()); m->labelsize(i->o->labelsize());
m->labelcolor(i->o->labelcolor()); m->labelcolor(i->o->labelcolor());
if (q->is_parent()) {lvl++; m->flags |= FL_SUBMENU;} if (q->can_have_children()) {lvl++; m->flags |= FL_SUBMENU;}
m++; m++;
int l1 = int l1 =
(q->next && q->next->is_a(ID_Menu_Item)) ? q->next->level : level; (q->next && q->next->is_a(ID_Menu_Item)) ? q->next->level : level;
@ -157,7 +157,7 @@ Fl_Type *Fl_Menu_Item_Type::make(Strategy strategy) {
Fl_Type* q = Fl_Type::current; Fl_Type* q = Fl_Type::current;
Fl_Type* p = q; Fl_Type* p = q;
if (p) { if (p) {
if ( (force_parent && q->is_a(ID_Menu_Item)) || !q->is_parent()) p = p->parent; if ( (force_parent && q->is_a(ID_Menu_Item)) || !q->can_have_children()) p = p->parent;
} }
force_parent = 0; force_parent = 0;
if (!p || !(p->is_a(ID_Menu_Manager_) || p->is_a(ID_Submenu))) { if (!p || !(p->is_a(ID_Menu_Manager_) || p->is_a(ID_Submenu))) {
@ -295,7 +295,7 @@ const char* Fl_Menu_Item_Type::menu_name(Fd_Code_Writer& f, int& i) {
// be sure to count the {0} that ends a submenu: // be sure to count the {0} that ends a submenu:
if (t->level > t->next->level) i += (t->level - t->next->level); if (t->level > t->next->level) i += (t->level - t->next->level);
// detect empty submenu: // detect empty submenu:
else if (t->level == t->next->level && t->is_parent()) i++; else if (t->level == t->next->level && t->can_have_children()) i++;
t = t->prev; t = t->prev;
i++; i++;
} }
@ -414,7 +414,7 @@ void Fl_Menu_Item_Type::write_static(Fd_Code_Writer& f) {
Fl_Type* t = prev; while (t && t->is_a(ID_Menu_Item)) t = t->prev; Fl_Type* t = prev; while (t && t->is_a(ID_Menu_Item)) t = t->prev;
for (Fl_Type* q = t->next; q && q->is_a(ID_Menu_Item); q = q->next) { for (Fl_Type* q = t->next; q && q->is_a(ID_Menu_Item); q = q->next) {
((Fl_Menu_Item_Type*)q)->write_item(f); ((Fl_Menu_Item_Type*)q)->write_item(f);
int thislevel = q->level; if (q->is_parent()) thislevel++; int thislevel = q->level; if (q->can_have_children()) thislevel++;
int nextlevel = int nextlevel =
(q->next && q->next->is_a(ID_Menu_Item)) ? q->next->level : t->level+1; (q->next && q->next->is_a(ID_Menu_Item)) ? q->next->level : t->level+1;
while (thislevel > nextlevel) {f.write_c(" {0,0,0,0,0,0,0,0,0},\n"); thislevel--;} while (thislevel > nextlevel) {f.write_c(" {0,0,0,0,0,0,0,0,0},\n"); thislevel--;}
@ -448,7 +448,7 @@ int Fl_Menu_Item_Type::flags() {
if (((Fl_Button*)o)->value()) i |= FL_MENU_VALUE; if (((Fl_Button*)o)->value()) i |= FL_MENU_VALUE;
if (!o->active()) i |= FL_MENU_INACTIVE; if (!o->active()) i |= FL_MENU_INACTIVE;
if (!o->visible()) i |= FL_MENU_INVISIBLE; if (!o->visible()) i |= FL_MENU_INVISIBLE;
if (is_parent()) { if (can_have_children()) {
if (user_data() == NULL) i |= FL_SUBMENU; if (user_data() == NULL) i |= FL_SUBMENU;
else i |= FL_SUBMENU_POINTER; else i |= FL_SUBMENU_POINTER;
} }
@ -640,7 +640,7 @@ void Fl_Menu_Base_Type::build_menu() {
int n = 0; int n = 0;
Fl_Type* q; Fl_Type* q;
for (q = next; q && q->level > level; q = q->next) { for (q = next; q && q->level > level; q = q->next) {
if (q->is_parent()) n++; // space for null at end of submenu if (q->can_have_children()) n++; // space for null at end of submenu
n++; n++;
} }
if (!n) { if (!n) {
@ -687,7 +687,7 @@ void Fl_Menu_Base_Type::build_menu() {
m->labelfont(i->o->labelfont()); m->labelfont(i->o->labelfont());
m->labelsize(i->o->labelsize()); m->labelsize(i->o->labelsize());
m->labelcolor(i->o->labelcolor()); m->labelcolor(i->o->labelcolor());
if (q->is_parent()) {lvl++; m->flags |= FL_SUBMENU;} if (q->can_have_children()) {lvl++; m->flags |= FL_SUBMENU;}
m++; m++;
int l1 = int l1 =
(q->next && q->next->is_a(ID_Menu_Item)) ? q->next->level : level; (q->next && q->next->is_a(ID_Menu_Item)) ? q->next->level : level;

View File

@ -105,7 +105,7 @@ public:
Fl_Menu_Item* subtypes() FL_OVERRIDE {return 0;} Fl_Menu_Item* subtypes() FL_OVERRIDE {return 0;}
const char* type_name() FL_OVERRIDE {return "Submenu";} const char* type_name() FL_OVERRIDE {return "Submenu";}
const char* alt_type_name() FL_OVERRIDE {return "fltk::ItemGroup";} const char* alt_type_name() FL_OVERRIDE {return "fltk::ItemGroup";}
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
int is_button() const FL_OVERRIDE {return 0;} // disable shortcut int is_button() const FL_OVERRIDE {return 0;} // disable shortcut
Fl_Type* make(Strategy strategy) FL_OVERRIDE; Fl_Type* make(Strategy strategy) FL_OVERRIDE;
// changes to submenu must propagate up so build_menu is called // changes to submenu must propagate up so build_menu is called
@ -133,7 +133,7 @@ public:
w = layout->textsize_not_null() * 6 + 8; w = layout->textsize_not_null() * 6 + 8;
Fd_Snap_Action::better_size(w, h); Fd_Snap_Action::better_size(w, h);
} }
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
int menusize; int menusize;
virtual void build_menu() = 0; virtual void build_menu() = 0;
Fl_Menu_Manager_Type() : Fl_Widget_Type() {menusize = 0;} Fl_Menu_Manager_Type() : Fl_Widget_Type() {menusize = 0;}
@ -205,7 +205,7 @@ class Fl_Menu_Base_Type : public Fl_Menu_Manager_Type
return 1; return 1;
} }
public: public:
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
void build_menu() FL_OVERRIDE; void build_menu() FL_OVERRIDE;
~Fl_Menu_Base_Type() { ~Fl_Menu_Base_Type() {
if (menusize) delete[] (Fl_Menu_Item*)(((Fl_Menu_*)o)->menu()); if (menusize) delete[] (Fl_Menu_Item*)(((Fl_Menu_*)o)->menu());

View File

@ -713,7 +713,7 @@ void Fl_Type::write(Fd_Project_Writer &f) {
if (parent) parent->write_parent_properties(f, this, true); if (parent) parent->write_parent_properties(f, this, true);
f.write_close(level); f.write_close(level);
if (f.write_codeview()) proj1_end = (int)ftell(f.file()); if (f.write_codeview()) proj1_end = (int)ftell(f.file());
if (!is_parent()) { if (!can_have_children()) {
if (f.write_codeview()) proj2_end = (int)ftell(f.file()); if (f.write_codeview()) proj2_end = (int)ftell(f.file());
return; return;
} }
@ -757,7 +757,7 @@ void Fl_Type::write_properties(Fd_Project_Writer &f) {
f.write_word("comment"); f.write_word("comment");
f.write_word(comment()); f.write_word(comment());
} }
if (is_parent() && open_) f.write_word("open"); if (can_have_children() && open_) f.write_word("open");
if (selected) f.write_word("selected"); if (selected) f.write_word("selected");
} }

View File

@ -234,7 +234,7 @@ public:
int msgnum(); int msgnum();
/** Return 1 if the Type can have children. */ /** Return 1 if the Type can have children. */
virtual int is_parent() const {return 0;} virtual int can_have_children() const {return 0;}
/** Return 1 if the type is a widget or menu item. */ /** Return 1 if the type is a widget or menu item. */
virtual int is_widget() const {return 0;} virtual int is_widget() const {return 0;}
/** Return 1 if the type is a widget but not a menu item. */ /** Return 1 if the type is a widget but not a menu item. */

View File

@ -89,7 +89,7 @@ Fl_Widget_Type::ideal_size(int &w, int &h) {
Fl_Type *Fl_Widget_Type::make(Strategy strategy) { Fl_Type *Fl_Widget_Type::make(Strategy strategy) {
// Find the current widget, or widget to copy: // Find the current widget, or widget to copy:
Fl_Type *qq = Fl_Type::current; Fl_Type *qq = Fl_Type::current;
while (qq && (!qq->is_true_widget() || !qq->is_parent())) qq = qq->parent; while (qq && (!qq->is_true_widget() || !qq->can_have_children())) qq = qq->parent;
if (!qq) { if (!qq) {
fl_message("Please select a group widget or window"); fl_message("Please select a group widget or window");
return 0; return 0;
@ -3021,7 +3021,7 @@ void Fl_Widget_Type::write_code1(Fd_Code_Writer& f) {
f.varused = wused; f.varused = wused;
if (!name() && !f.varused) { if (!name() && !f.varused) {
f.varused |= is_parent(); f.varused |= can_have_children();
if (!f.varused) { if (!f.varused) {
f.varused_test = 1; f.varused_test = 1;

View File

@ -113,7 +113,7 @@ public:
void move_child(Fl_Type*, Fl_Type*) FL_OVERRIDE; void move_child(Fl_Type*, Fl_Type*) FL_OVERRIDE;
void remove_child(Fl_Type*) FL_OVERRIDE; void remove_child(Fl_Type*) FL_OVERRIDE;
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
Fl_Widget *enter_live_mode(int top=0) FL_OVERRIDE; Fl_Widget *enter_live_mode(int top=0) FL_OVERRIDE;
void leave_live_mode() FL_OVERRIDE; void leave_live_mode() FL_OVERRIDE;
@ -148,7 +148,7 @@ public:
const char *type_name() FL_OVERRIDE {return "widget_class";} const char *type_name() FL_OVERRIDE {return "widget_class";}
ID id() const FL_OVERRIDE { return ID_Widget_Class; } ID id() const FL_OVERRIDE { return ID_Widget_Class; }
bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_Widget_Class) ? true : super::is_a(inID); } bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_Widget_Class) ? true : super::is_a(inID); }
int is_parent() const FL_OVERRIDE {return 1;} int can_have_children() const FL_OVERRIDE {return 1;}
int is_code_block() const FL_OVERRIDE {return 1;} int is_code_block() const FL_OVERRIDE {return 1;}
int is_decl_block() const FL_OVERRIDE {return 1;} int is_decl_block() const FL_OVERRIDE {return 1;}
int is_class() const FL_OVERRIDE {return 1;} int is_class() const FL_OVERRIDE {return 1;}

View File

@ -384,7 +384,7 @@ Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strate
t->read_property(*this, cc); t->read_property(*this, cc);
} }
if (!t->is_parent()) continue; if (!t->can_have_children()) continue;
c = read_word(1); c = read_word(1);
if (strcmp(c,"{")) { if (strcmp(c,"{")) {
read_error("Missing child list for %s\n",t->title()); read_error("Missing child list for %s\n",t->title());

View File

@ -765,7 +765,7 @@ 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->is_parent()) 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, kAddAsLastChild);
else else
add_new_widget_from_user(type_name, kAddAfterCurrent); add_new_widget_from_user(type_name, kAddAfterCurrent);

View File

@ -337,7 +337,7 @@ void Widget_Browser::item_draw(void *v, int X, int Y, int, int) const {
else fl_color(FL_FOREGROUND_COLOR); else fl_color(FL_FOREGROUND_COLOR);
// Width=10: Draw the triangle that indicates possible children // Width=10: Draw the triangle that indicates possible children
if (l->is_parent()) { if (l->can_have_children()) {
X = X - 18 - 13; X = X - 18 - 13;
if (!l->next || l->next->level <= l->level) { if (!l->next || l->next->level <= l->level) {
if (l->open_!=(l==pushedtitle)) { if (l->open_!=(l==pushedtitle)) {
@ -507,7 +507,7 @@ int Widget_Browser::handle(int e) {
l = (Fl_Type*)find_item(Fl::event_y()); l = (Fl_Type*)find_item(Fl::event_y());
if (l) { if (l) {
X += 3 + 12*l->level - hposition(); X += 3 + 12*l->level - hposition();
if (l->is_parent() && Fl::event_x()>X && Fl::event_x()<X+13) { if (l->can_have_children() && Fl::event_x()>X && Fl::event_x()<X+13) {
title = pushedtitle = l; title = pushedtitle = l;
redraw_line(l); redraw_line(l);
return 1; return 1;
@ -519,7 +519,7 @@ int Widget_Browser::handle(int e) {
l = (Fl_Type*)find_item(Fl::event_y()); l = (Fl_Type*)find_item(Fl::event_y());
if (l) { if (l) {
X += 3 + 12*l->level - hposition(); X += 3 + 12*l->level - hposition();
if (l->is_parent() && Fl::event_x()>X && Fl::event_x()<X+13) ; if (l->can_have_children() && Fl::event_x()>X && Fl::event_x()<X+13) ;
else l = 0; else l = 0;
} }
if (l != pushedtitle) { if (l != pushedtitle) {
@ -546,7 +546,7 @@ int Widget_Browser::handle(int e) {
l->open_ = 1; l->open_ = 1;
for (Fl_Type*k=l->next; k&&k->level>l->level;) { for (Fl_Type*k=l->next; k&&k->level>l->level;) {
k->visible = 1; k->visible = 1;
if (k->is_parent() && !k->open_) { if (k->can_have_children() && !k->open_) {
Fl_Type *j; Fl_Type *j;
for (j = k->next; j && j->level>k->level; j = j->next) {/*empty*/} for (j = k->next; j && j->level>k->level; j = j->next) {/*empty*/}
k = j; k = j;