From 42a93eb8dec6e3c637442e23e156b3f72c7f8ca7 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 8 Jan 2022 21:55:19 +0100 Subject: [PATCH] avoid early include of Fl.H option --- fluid/Fl_Menu_Type.cxx | 4 +++- fluid/Fl_Type.cxx | 1 + fluid/Fl_Widget_Type.cxx | 1 + fluid/Fl_Window_Type.cxx | 9 +++++++++ fluid/Fl_Window_Type.h | 1 + fluid/alignment_panel.cxx | 17 ++++++++++++----- fluid/alignment_panel.fl | 19 ++++++++++++------- fluid/alignment_panel.h | 2 ++ fluid/code.cxx | 4 +++- fluid/file.cxx | 6 ++++++ 10 files changed, 50 insertions(+), 14 deletions(-) diff --git a/fluid/Fl_Menu_Type.cxx b/fluid/Fl_Menu_Type.cxx index 48087e6c3..14f371d57 100644 --- a/fluid/Fl_Menu_Type.cxx +++ b/fluid/Fl_Menu_Type.cxx @@ -242,8 +242,10 @@ const char* Fl_Menu_Item_Type::menu_name(int& i) { } void Fl_Menu_Item_Type::write_static() { - if (image && label() && label()[0]) + if (image && label() && label()[0]) { + write_declare("#include "); write_declare("#include "); + } if (callback() && is_name(callback()) && !user_defined(callback())) write_declare("extern void %s(Fl_Menu_*, %s);", callback(), user_data_type() ? user_data_type() : "void*"); diff --git a/fluid/Fl_Type.cxx b/fluid/Fl_Type.cxx index 2669cb7b1..50a59869b 100644 --- a/fluid/Fl_Type.cxx +++ b/fluid/Fl_Type.cxx @@ -183,6 +183,7 @@ void delete_all(int selected_only) { include_H_from_C=1; use_FL_COMMAND=0; utf8_in_src = 0; + avoid_early_includes = 0; // reset the setting for the external shell command shell_prefs_get(); shell_settings_write(); diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index 6ad732fb8..80537bb0f 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -2015,6 +2015,7 @@ int isdeclare(const char *c) { void Fl_Widget_Type::write_static() { const char* t = subclassname(this); if (!subclass() || (is_class() && !strncmp(t, "Fl_", 3))) { + write_declare("#include "); write_declare("#include ", t); } for (int n=0; n < NUM_EXTRA_CODE; n++) { diff --git a/fluid/Fl_Window_Type.cxx b/fluid/Fl_Window_Type.cxx index ddc94fc9c..d5da99716 100644 --- a/fluid/Fl_Window_Type.cxx +++ b/fluid/Fl_Window_Type.cxx @@ -45,6 +45,7 @@ int include_H_from_C = 1; int use_FL_COMMAND = 0; int utf8_in_src = 0; +int avoid_early_includes = 0; extern Fl_Preferences fluid_prefs; @@ -194,6 +195,7 @@ void show_project_cb(Fl_Widget *, void *) { include_H_from_C_button->value(include_H_from_C); use_FL_COMMAND_button->value(use_FL_COMMAND); utf8_in_src_button->value(utf8_in_src); + avoid_early_includes_button->value(avoid_early_includes); header_file_input->value(header_file_name); code_file_input->value(code_file_name); i18n_type_chooser->value(i18n_type); @@ -292,6 +294,13 @@ void utf8_in_src_cb(Fl_Check_Button *b, void*) { } } +void avoid_early_includes_cb(Fl_Check_Button *b, void*) { + if (avoid_early_includes != b->value()) { + set_modflag(1); + avoid_early_includes = b->value(); + } +} + //////////////////////////////////////////////////////////////// Fl_Menu_Item window_type_menu[] = { diff --git a/fluid/Fl_Window_Type.h b/fluid/Fl_Window_Type.h index c1f54d6b8..e1ddcba9c 100644 --- a/fluid/Fl_Window_Type.h +++ b/fluid/Fl_Window_Type.h @@ -28,6 +28,7 @@ class Fl_Widget_Class_Type; extern int include_H_from_C; extern int use_FL_COMMAND; extern int utf8_in_src; +extern int avoid_early_includes; extern Fl_Menu_Item window_type_menu[]; extern Fl_Widget_Class_Type *current_widget_class; diff --git a/fluid/alignment_panel.cxx b/fluid/alignment_panel.cxx index 3a76c4012..26a45c700 100644 --- a/fluid/alignment_panel.cxx +++ b/fluid/alignment_panel.cxx @@ -38,6 +38,8 @@ Fl_Check_Button *use_FL_COMMAND_button=(Fl_Check_Button *)0; Fl_Check_Button *utf8_in_src_button=(Fl_Check_Button *)0; +Fl_Check_Button *avoid_early_includes_button=(Fl_Check_Button *)0; + Fl_Choice *i18n_type_chooser=(Fl_Choice *)0; Fl_Menu_Item menu_i18n_type_chooser[] = { @@ -60,15 +62,15 @@ Fl_Input *i18n_function_input=(Fl_Input *)0; Fl_Input *i18n_static_function_input=(Fl_Input *)0; Fl_Double_Window* make_project_window() { - { project_window = new Fl_Double_Window(399, 275, "Project Settings"); - { Fl_Button* o = new Fl_Button(328, 239, 60, 25, "Close"); + { project_window = new Fl_Double_Window(399, 298, "Project Settings"); + { Fl_Button* o = new Fl_Button(328, 267, 60, 25, "Close"); o->tooltip("Close this dialog."); o->callback((Fl_Callback*)cb_Close); } // Fl_Button* o - { Fl_Tabs* o = new Fl_Tabs(10, 10, 379, 218); + { Fl_Tabs* o = new Fl_Tabs(10, 10, 379, 246); o->selection_color((Fl_Color)12); o->labelcolor(FL_BACKGROUND2_COLOR); - { Fl_Group* o = new Fl_Group(10, 36, 379, 192, "Output"); + { Fl_Group* o = new Fl_Group(10, 36, 379, 220, "Output"); { Fl_Box* o = new Fl_Box(20, 49, 340, 49, "Use \"name.ext\" to set a file name or just \".ext\" to set extension."); o->align(Fl_Align(132|FL_ALIGN_INSIDE)); } // Fl_Box* o @@ -105,9 +107,14 @@ ped using octal notation `\\0123`. If this option is checked, Fluid will write\ utf8_in_src_button->down_box(FL_DOWN_BOX); utf8_in_src_button->callback((Fl_Callback*)utf8_in_src_cb); } // Fl_Check_Button* utf8_in_src_button + { avoid_early_includes_button = new Fl_Check_Button(117, 222, 272, 20, "avoid early include of Fl.H"); + avoid_early_includes_button->tooltip("Do not emit #include until it is needed by another include file."); + avoid_early_includes_button->down_box(FL_DOWN_BOX); + avoid_early_includes_button->callback((Fl_Callback*)avoid_early_includes_cb); + } // Fl_Check_Button* avoid_early_includes_button o->end(); } // Fl_Group* o - { Fl_Group* o = new Fl_Group(10, 36, 378, 192, "Internationalization"); + { Fl_Group* o = new Fl_Group(10, 36, 378, 220, "Internationalization"); o->hide(); { i18n_type_chooser = new Fl_Choice(128, 48, 136, 25, "Use:"); i18n_type_chooser->tooltip("Type of internationalization to use."); diff --git a/fluid/alignment_panel.fl b/fluid/alignment_panel.fl index ca8fb6cbb..8a4595e63 100644 --- a/fluid/alignment_panel.fl +++ b/fluid/alignment_panel.fl @@ -35,7 +35,7 @@ decl {\#include } {public local decl {\#include } {public local } -decl {\#include } {public local +decl {\#include } {selected public local } decl {\#include } {private global @@ -54,7 +54,7 @@ Function {make_project_window()} {open } { Fl_Window project_window { label {Project Settings} open - xywh {472 246 399 275} type Double + xywh {472 246 399 298} type Double code0 {\#include } code1 {\#include } modal visible } { @@ -62,14 +62,14 @@ Function {make_project_window()} {open label Close callback {project_window->hide(); set_modflag(-1, -1);} - tooltip {Close this dialog.} xywh {328 239 60 25} + tooltip {Close this dialog.} xywh {328 267 60 25} } Fl_Tabs {} {open - xywh {10 10 379 218} selection_color 12 labelcolor 7 + xywh {10 10 379 246} selection_color 12 labelcolor 7 } { Fl_Group {} { - label Output open selected - xywh {10 36 379 192} + label Output open + xywh {10 36 379 220} } { Fl_Box {} { label {Use "name.ext" to set a file name or just ".ext" to set extension.} @@ -102,10 +102,15 @@ set_modflag(-1, -1);} callback utf8_in_src_cb tooltip {For older compilers, characters outside of the printable ASCII range are escaped using octal notation `\\0123`. If this option is checked, Fluid will write UTF-8 characters unchanged.} xywh {117 199 272 20} down_box DOWN_BOX } + Fl_Check_Button avoid_early_includes_button { + label {avoid early include of Fl.H} + callback avoid_early_includes_cb + tooltip {Do not emit \#include until it is needed by another include file.} xywh {117 222 272 20} down_box DOWN_BOX + } } Fl_Group {} { label Internationalization open - xywh {10 36 378 192} hide + xywh {10 36 378 220} hide } { Fl_Choice i18n_type_chooser { label {Use:} diff --git a/fluid/alignment_panel.h b/fluid/alignment_panel.h index 9a6e6092a..cccadc337 100644 --- a/fluid/alignment_panel.h +++ b/fluid/alignment_panel.h @@ -46,6 +46,8 @@ extern void use_FL_COMMAND_button_cb(Fl_Check_Button*, void*); extern Fl_Check_Button *use_FL_COMMAND_button; extern void utf8_in_src_cb(Fl_Check_Button*, void*); extern Fl_Check_Button *utf8_in_src_button; +extern void avoid_early_includes_cb(Fl_Check_Button*, void*); +extern Fl_Check_Button *avoid_early_includes_button; #include extern void i18n_type_cb(Fl_Choice*, void*); extern Fl_Choice *i18n_type_chooser; diff --git a/fluid/code.cxx b/fluid/code.cxx index da40970bf..7de06ea00 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -584,7 +584,9 @@ int write_code(const char *s, const char *t) { fprintf(header_file, "#define %s\n", define_name); } - write_declare("#include "); + if (avoid_early_includes==0) { + write_declare("#include "); + } if (t && include_H_from_C) { if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) { write_c("#include \"%s\"\n", fl_filename_name(t)); diff --git a/fluid/file.cxx b/fluid/file.cxx index 59177cb9d..0e6fbe4d2 100644 --- a/fluid/file.cxx +++ b/fluid/file.cxx @@ -383,6 +383,8 @@ int write_file(const char *filename, int selected_only) { write_string("\nuse_FL_COMMAND"); if (utf8_in_src) write_string("\nutf8_in_src"); + if (avoid_early_includes) + write_string("\navoid_early_includes"); if (i18n_type) { write_string("\ni18n_type %d", i18n_type); write_string("\ni18n_include"); write_word(i18n_include); @@ -504,6 +506,10 @@ static void read_children(Fl_Type *p, int paste, Strategy strategy, char skip_op utf8_in_src=1; goto CONTINUE; } + if (!strcmp(c,"avoid_early_includes")) { + avoid_early_includes=1; + goto CONTINUE; + } if (!strcmp(c,"i18n_type")) { i18n_type = atoi(read_word()); goto CONTINUE;