[master] 42a93eb - avoid early include of Fl.H option

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 42a93eb - avoid early include of Fl.H option "Matthias Melcher" 13:17 Jan 08 top right image
 
commit 42a93eb8dec6e3c637442e23e156b3f72c7f8ca7
Author:     Matthias Melcher <git@matthiasm.com>
AuthorDate: Sat Jan 8 21:55:19 2022 +0100
Commit:     Matthias Melcher <github@matthiasm.com>
CommitDate: Sat Jan 8 22:12:41 2022 +0100

    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 fluid/Fl_Menu_Type.cxx fluid/Fl_Menu_Type.cxx
index 48087e6..14f371d 100644
--- fluid/Fl_Menu_Type.cxx
+++ 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 <FL/Fl.H>");
     write_declare("#include <FL/Fl_Multi_Label.H>");
+  }
   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 fluid/Fl_Type.cxx fluid/Fl_Type.cxx
index 2669cb7..50a5986 100644
--- fluid/Fl_Type.cxx
+++ 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 fluid/Fl_Widget_Type.cxx fluid/Fl_Widget_Type.cxx
index 6ad732f..80537bb 100644
--- fluid/Fl_Widget_Type.cxx
+++ 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 <FL/Fl.H>");
     write_declare("#include <FL/%s.H>", t);
   }
   for (int n=0; n < NUM_EXTRA_CODE; n++) {
diff --git fluid/Fl_Window_Type.cxx fluid/Fl_Window_Type.cxx
index ddc94fc..d5da997 100644
--- fluid/Fl_Window_Type.cxx
+++ 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 fluid/Fl_Window_Type.h fluid/Fl_Window_Type.h
index c1f54d6..e1ddcba 100644
--- fluid/Fl_Window_Type.h
+++ 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 fluid/alignment_panel.cxx fluid/alignment_panel.cxx
index 3a76c40..26a45c7 100644
--- fluid/alignment_panel.cxx
+++ 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 <FL//Fl.H> 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 fluid/alignment_panel.fl fluid/alignment_panel.fl
index ca8fb6c..8a4595e 100644
--- fluid/alignment_panel.fl
+++ fluid/alignment_panel.fl
@@ -35,7 +35,7 @@ decl {\#include <FL/Fl_Text_Buffer.H>} {public local
 decl {\#include <FL/Fl_Text_Display.H>} {public local
 }
 
-decl {\#include <FL/filename.H>} {public local
+decl {\#include <FL/filename.H>} {selected public local
 }
 
 decl {\#include <FL/Fl_Preferences.H>} {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 <FL/Fl_Preferences.H>}
     code1 {\#include <FL/Fl_Tooltip.H>} 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 <FL//Fl.H> 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 fluid/alignment_panel.h fluid/alignment_panel.h
index 9a6e609..cccadc3 100644
--- fluid/alignment_panel.h
+++ 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 <FL/Fl_Choice.H>
 extern void i18n_type_cb(Fl_Choice*, void*);
 extern Fl_Choice *i18n_type_chooser;
diff --git fluid/code.cxx fluid/code.cxx
index da40970..7de06ea 100644
--- fluid/code.cxx
+++ 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 <FL/Fl.H>");
+  if (avoid_early_includes==0) {
+    write_declare("#include <FL/Fl.H>");
+  }
   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 fluid/file.cxx fluid/file.cxx
index 59177cb..0e6fbe4 100644
--- fluid/file.cxx
+++ 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;
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2022 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.