diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2018-08-25 15:17:16 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2018-08-25 15:17:16 +0000 |
| commit | 011e5c498a1f3f197d503bf5ce806e836d667f08 (patch) | |
| tree | 7d48dd1b47908f4bf3d4ddc095c683a31a7ca44f /fluid | |
| parent | 8de0a3c4453c50ae193c0603c7e57516a8157905 (diff) | |
Added new functionality to Fluid: the 'binary data' type can now include text files as well as binary files into the source code. There is an additional check box in the dialog. Terminology is now "inlined data" instead of "binary data". Texts were modified to reflect the changes.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13026 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'fluid')
| -rw-r--r-- | fluid/Fl_Function_Type.cxx | 48 | ||||
| -rw-r--r-- | fluid/Fl_Type.h | 3 | ||||
| -rw-r--r-- | fluid/Fluid_Image.cxx | 2 | ||||
| -rw-r--r-- | fluid/code.cxx | 12 | ||||
| -rw-r--r-- | fluid/factory.cxx | 2 | ||||
| -rw-r--r-- | fluid/function_panel.cxx | 21 | ||||
| -rw-r--r-- | fluid/function_panel.fl | 30 | ||||
| -rw-r--r-- | fluid/function_panel.h | 2 |
8 files changed, 83 insertions, 37 deletions
diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index cf193dc48..38b883f27 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -770,7 +770,8 @@ Fl_Type *Fl_Data_Type::make() { o->public_ = 1; o->static_ = 1; o->filename_ = 0; - o->name("myBinaryData"); + o->text_mode_ = 0; + o->name("myInlineData"); o->add(p); o->factory = this; return o; @@ -782,11 +783,16 @@ void Fl_Data_Type::write_properties() { write_string("filename"); write_word(filename_); } + if (text_mode_) { + write_string("textmode"); + } } void Fl_Data_Type::read_property(const char *c) { if (!strcmp(c,"filename")) { storestring(read_word(), filename_, 1); + } else if (!strcmp(c,"textmode")) { + text_mode_ = 1; } else { Fl_Decl_Type::read_property(c); } @@ -804,6 +810,7 @@ void Fl_Data_Type::open() { data_choice->show(); data_class_choice->hide(); } + data_mode->value(text_mode_); data_filename->value(filename_?filename_:""); const char *c = comment(); data_comment_input->buffer()->text(c?c:""); @@ -817,7 +824,7 @@ void Fl_Data_Type::open() { else if (w == data_panel_ok) break; else if (w == data_filebrowser) { goto_source_dir(); - const char *fn = fl_file_chooser("Load Binary Data", 0L, data_filename->value(), 1); + const char *fn = fl_file_chooser("Load Data Verbose", 0L, data_filename->value(), 1); leave_source_dir(); if (fn) { if (strcmp(fn, data_filename->value())) @@ -868,6 +875,7 @@ void Fl_Data_Type::open() { static_ = ((data_choice->value()>>1)&1); } } + text_mode_ = data_mode->value(); // store the filename c = data_filename->value(); if (filename_ && strcmp(filename_, data_filename->value())) @@ -905,7 +913,7 @@ void Fl_Data_Type::write_code1() { if (filename_ && !write_sourceview) { FILE *f = fl_fopen(filename_, "rb"); if (!f) { - message = "Can't include binary file. Can't open"; + message = "Can't include data from file. Can't open"; } else { fseek(f, 0, SEEK_END); nData = ftell(f); @@ -917,38 +925,48 @@ void Fl_Data_Type::write_code1() { fclose(f); } } else { - fn = "<no filename>"; + fn = fn ? filename_ : "<no filename>"; } - if (is_in_class()) { + const char *variableType = text_mode_ ? "char" : "unsigned char"; + if (is_in_class()) { write_public(public_); write_comment_h(" "); - write_h(" static unsigned char %s[%d];\n", c, nData); - write_c("unsigned char %s::%s[%d] = /* binary data included from %s */\n", class_name(1), c, nData, fn); + write_h(" static %s %s[%d];\n", variableType, c, nData); + write_c("%s %s::%s[%d] = /* data inlined from %s */\n", variableType, class_name(1), c, nData, fn); if (message) write_c("#error %s %s\n", message, fn); - write_cdata(data, nData); + if (text_mode_) + write_cstring(data, nData); + else + write_cdata(data, nData); write_c(";\n"); } else { // the "header only" option does not apply here! if (public_) { if (static_) { - write_h("extern unsigned char %s[%d];\n", c, nData); + write_h("extern %s %s[%d];\n", variableType, c, nData); write_comment_c(); - write_c("unsigned char %s[%d] = /* binary data included from %s */\n", c, nData, fn); + write_c("%s %s[%d] = /* data inlined from %s */\n", variableType, c, nData, fn); if (message) write_c("#error %s %s\n", message, fn); - write_cdata(data, nData); + if (text_mode_) + write_cstring(data, nData); + else + write_cdata(data, nData); write_c(";\n"); } else { write_comment_h(); - write_h("#error Unsupported declaration loading binary data %s\n", fn); - write_h("unsigned char %s[3] = { 1, 2, 3 };\n", c); + write_h("#error Unsupported declaration loading inline data %s\n", fn); + write_h("%s %s[3] = { 1, 2, 3 };\n", variableType, c); } } else { write_comment_c(); if (static_) write_c("static "); - write_c("unsigned char %s[%d] = /* binary data included from %s */\n", c, nData, fn); + write_c("%s %s[%d] = /* data inlined from %s */\n", variableType, c, nData, fn); if (message) write_c("#error %s %s\n", message, fn); - write_cdata(data, nData); + if (text_mode_) + write_cstring(data, nData); + else + write_cdata(data, nData); write_c(";\n"); } } diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h index e241d197c..a55ea3c44 100644 --- a/fluid/Fl_Type.h +++ b/fluid/Fl_Type.h @@ -282,8 +282,9 @@ public: class Fl_Data_Type : public Fl_Decl_Type { const char *filename_; + int text_mode_; public: - Fl_Data_Type() : Fl_Decl_Type(), filename_(0L) { } + Fl_Data_Type() : Fl_Decl_Type(), filename_(0L), text_mode_(0) { } ~Fl_Data_Type() { if (filename_) free((void*)filename_); } diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index 653d45abc..d0572d8eb 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -99,7 +99,7 @@ void Fluid_Image::write_static() { FILE *f = fl_fopen(name(), "rb"); if (!f) { - // message = "Can't include binary file. Can't open"; + // message = "Can't inline file into source code. Can't open"; } else { fseek(f, 0, SEEK_END); size_t nData = ftell(f); diff --git a/fluid/code.cxx b/fluid/code.cxx index 02cc439bc..9d33f50d8 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -156,6 +156,18 @@ void write_cstring(const char *s, int length) { varused = 1; return; } + if (write_sourceview && ((s==NULL) || (length>1024))) { + if (length>=0) + fprintf(code_file, "\" ... %d bytes of text... \"", length); + else + fprintf(code_file, "\" ... text... \""); + return; + } + if (length==-1) { + fprintf(code_file, "\" ... undefined size text... \""); + return; + } + const char *p = s; const char *e = s+length; int linelength = 1; diff --git a/fluid/factory.cxx b/fluid/factory.cxx index 7a4353d37..2ce3065cc 100644 --- a/fluid/factory.cxx +++ b/fluid/factory.cxx @@ -983,7 +983,7 @@ Fl_Menu_Item New_Menu[] = { {"Class",0,cb,(void*)&Fl_Class_type}, {"Widget Class",0,cb,(void*)&Fl_Widget_Class_type}, {"Comment",0,cb,(void*)&Fl_Comment_type}, - {"Binary Data",0,cb,(void*)&Fl_Data_type}, + {"Inlined Data",0,cb,(void*)&Fl_Data_type}, {0}, {"Group",0,0,0,FL_SUBMENU}, {0,0,cb,(void*)&Fl_Window_type}, diff --git a/fluid/function_panel.cxx b/fluid/function_panel.cxx index ed82ed3b8..caeb22470 100644 --- a/fluid/function_panel.cxx +++ b/fluid/function_panel.cxx @@ -449,6 +449,8 @@ Fl_Menu_Item menu_data_class_choice[] = { {0,0,0,0,0,0,0,0,0} }; +Fl_Check_Button *data_mode=(Fl_Check_Button *)0; + Fl_Input *data_input=(Fl_Input *)0; Fl_Input *data_filename=(Fl_Input *)0; @@ -462,10 +464,10 @@ Fl_Return_Button *data_panel_ok=(Fl_Return_Button *)0; Fl_Button *data_panel_cancel=(Fl_Button *)0; Fl_Double_Window* make_data_panel() { - { data_panel = new Fl_Double_Window(343, 237, "Binary Data Properties"); + { data_panel = new Fl_Double_Window(343, 237, "Inline Data Properties"); data_panel->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE)); - { Fl_Group* o = new Fl_Group(10, 10, 270, 20); - { Fl_Box* o = new Fl_Box(200, 10, 80, 20); + { Fl_Group* o = new Fl_Group(10, 10, 320, 20); + { Fl_Box* o = new Fl_Box(288, 10, 42, 20); Fl_Group::current()->resizable(o); } // Fl_Box* o { data_choice = new Fl_Choice(10, 10, 185, 20); @@ -480,10 +482,17 @@ Fl_Double_Window* make_data_panel() { data_class_choice->textsize(11); data_class_choice->menu(menu_data_class_choice); } // Fl_Choice* data_class_choice + { data_mode = new Fl_Check_Button(200, 10, 78, 20, "text mode"); + data_mode->tooltip("When text mode is seleted, the returned type is \"const char[]\" and a traili\ +ng NUL will be appended to the data."); + data_mode->down_box(FL_DOWN_BOX); + data_mode->labelsize(11); + } // Fl_Check_Button* data_mode o->end(); } // Fl_Group* o { data_input = new Fl_Input(10, 52, 320, 20, "Variable Name:"); - data_input->tooltip("Binary Data variables are declared \"const unsigned char []\"."); + data_input->tooltip("Inline Data variables are declared \"const unsigned char []\" in binary mode \ +and \"const char[]\" in text mode."); data_input->labelfont(1); data_input->labelsize(11); data_input->textfont(4); @@ -492,7 +501,7 @@ Fl_Double_Window* make_data_panel() { data_input->when(FL_WHEN_NEVER); } // Fl_Input* data_input { data_filename = new Fl_Input(10, 90, 280, 20, "Filename:"); - data_filename->tooltip("Name and path of binary file that will be included."); + data_filename->tooltip("Name and path of file that will be inlined."); data_filename->labelfont(1); data_filename->labelsize(11); data_filename->textfont(4); @@ -774,7 +783,7 @@ Fl_Window* make_widgetbin() { o->image(pixmap[11]); } // Fl_Button* o { Fl_Button* o = new Fl_Button(55, 55, 24, 24); - o->tooltip("Binary Data"); + o->tooltip("Inline Data"); o->box(FL_THIN_UP_BOX); o->callback((Fl_Callback*)type_make_cb, (void*)("data")); o->image(pixmap[49]); diff --git a/fluid/function_panel.fl b/fluid/function_panel.fl index 8f9199ae7..3c1ed41c1 100644 --- a/fluid/function_panel.fl +++ b/fluid/function_panel.fl @@ -1,5 +1,5 @@ # data file for the Fltk User Interface Designer (fluid) -version 1.0400 +version 1.0304 header_name {.h} code_name {.cxx} comment {// @@ -333,16 +333,17 @@ Function {make_decl_panel()} {} { } } -Function {make_data_panel()} {} { +Function {make_data_panel()} {open +} { Fl_Window data_panel { - label {Binary Data Properties} open - xywh {595 352 343 237} type Double align 80 hide resizable size_range {343 237 0 0} + label {Inline Data Properties} open + xywh {472 191 343 237} type Double align 80 resizable size_range {343 237 0 0} visible } { Fl_Group {} {open - xywh {10 10 270 20} + xywh {10 10 320 20} } { Fl_Box {} { - xywh {200 10 80 20} resizable + xywh {288 10 42 20} resizable } Fl_Choice data_choice {open xywh {10 10 185 20} down_box BORDER_BOX labelsize 11 textsize 11 @@ -380,14 +381,18 @@ Function {make_data_panel()} {} { xywh {10 10 100 20} labelsize 11 } } + Fl_Check_Button data_mode { + label {text mode} + tooltip {When text mode is seleted, the returned type is "const char[]" and a trailing NUL will be appended to the data.} xywh {200 10 78 20} down_box DOWN_BOX labelsize 11 + } } Fl_Input data_input { - label {Variable Name:} - tooltip {Binary Data variables are declared "const unsigned char []".} xywh {10 52 320 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11 + label {Variable Name:} selected + tooltip {Inline Data variables are declared "const unsigned char []" in binary mode and "const char[]" in text mode.} xywh {10 52 320 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11 } Fl_Input data_filename { label {Filename:} - tooltip {Name and path of binary file that will be included.} xywh {10 90 280 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11 + tooltip {Name and path of file that will be inlined.} xywh {10 90 280 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11 } Fl_Button data_filebrowser { label {@fileopen} @@ -417,8 +422,7 @@ Function {make_data_panel()} {} { } } -Function {make_class_panel()} {open -} { +Function {make_class_panel()} {} { Fl_Window class_panel { label {Class Properties} open xywh {497 585 342 196} type Double labelsize 11 hide resizable modal size_range {343 188 0 0} @@ -443,7 +447,7 @@ Function {make_class_panel()} {open tooltip {Name of subclass.} xywh {10 55 320 20} labelfont 1 labelsize 11 align 5 when 0 textfont 4 textsize 11 } Fl_Text_Editor c_comment_input { - label {Comment:} selected + label {Comment:} tooltip {Class comment in Doxygen format} xywh {10 90 320 65} box DOWN_BOX labelfont 1 labelsize 11 align 5 textfont 4 textsize 11 resizable code0 {c_comment_input->buffer(new Fl_Text_Buffer());} code1 {c_comment_input->add_key_binding(FL_Tab, 0, use_tab_navigation);} @@ -595,7 +599,7 @@ else Fl_Button {} { user_data {"data"} callback type_make_cb - tooltip {Binary Data} xywh {55 55 24 24} box THIN_UP_BOX + tooltip {Inline Data} xywh {55 55 24 24} box THIN_UP_BOX code0 {o->image(pixmap[49]);} } } diff --git a/fluid/function_panel.h b/fluid/function_panel.h index c706a197c..55ad091f9 100644 --- a/fluid/function_panel.h +++ b/fluid/function_panel.h @@ -76,6 +76,8 @@ extern Fl_Menu_Item menu_decl_class_choice[]; extern Fl_Double_Window *data_panel; extern Fl_Choice *data_choice; extern Fl_Choice *data_class_choice; +#include <FL/Fl_Check_Button.H> +extern Fl_Check_Button *data_mode; extern Fl_Input *data_input; extern Fl_Input *data_filename; extern Fl_Button *data_filebrowser; |
