All (in particular Greg),
I've pushed up some work I've done on my own project (ported back to FLTK) to put Fl_Table to work.
I don't expect this to be eligible for inclusion with FLTK - though I would have no objections.
(I use STL and and templates and other things not allowed in FLTK -- but maybe allowed in the examples)
Where Fl_Table does not own (or make assumptions about) the data, this class keeps a pointer to an std::vector< T > or a std::vector < std::vector < T > >. A small amount of template specialization is needed for the exact type -- examples for int, double, string are included.
This widget tries to look and behave a bit more like a 'real' spreadsheet. Importantly, it has the ability to copy/paste blocks of data both internally and to external spreadsheets like MS Excel.
...
Thanks to everyone for their work on FLTK
- and in this case particular thanks to everyone who has contributed to the Fl_Table functionality.
Hopefully this is interesting to some of you.
1 Fix compiler error: ‘sin’ was not declared in this scope 2 Fix "copy-paste bug": dynamic-stack-buffer-overflow 3 Fix compiler warnings [-Wsuggest-override] 4 Fix compiler warnings [-Wsign-compare]All patches are in the attached file 'SpreadSheetWidget_patches.tgz'. Feel free to apply these to your code.
If we allowed STL and more in the examples folder, then users and devs wouldn't be able to compile the entire project with older compilers (or explicit settings to use only C++98 as I'm doing to make sure it works). Therefore I wouldn't want to allow C++11 (or higher) code in examples yet, but our plan is to *allow* C++11 or higher in FLTK 1.5 whose development will be started soon after 1.4.0 has been released and stabilized, if necessary, in a few 1.4.x patch releases. This would be the time to add your extended example - if we decided to use it.
Where Fl_Table does not own (or make assumptions about) the data, this class keeps a pointer to an std::vector< T > or a std::vector < std::vector < T > >. A small amount of template specialization is needed for the exact type -- examples for int, double, string are included.
This widget tries to look and behave a bit more like a 'real' spreadsheet. Importantly, it has the ability to copy/paste blocks of data both internally and to external spreadsheets like MS Excel.Wow, that's awesome. I confirm that I could copy e.g. 3x3 cells to LibreOffice (aka `Calc`) on my Linux system.
Minor issue: copying back to your spreadsheet seems to "ignore" empty fields, i.e. the field(s) right to empty fields are moved to the wrong column:
Source in LibreOffice Calc:
Result as copied to your spreadsheet:
- and in this case particular thanks to everyone who has contributed to the Fl_Table functionality.
Hopefully this is interesting to some of you.I didn't look too much into the code and details but I couldn't resist to try to build and test it (as you can see above). However, I had to fix one compilation error (1) and I also fixed a bug (2) and some more compiler warnings (3 and 4). The warnings are obviously benign but anyway...
1 Fix compiler error: ‘sin’ was not declared in this scope 2 Fix "copy-paste bug": dynamic-stack-buffer-overflow 3 Fix compiler warnings [-Wsuggest-override] 4 Fix compiler warnings [-Wsign-compare] All patches are in the attached file 'SpreadSheetWidget_patches.tgz'. Feel free to apply these to your code.
Note 1: I used `fltk-config --compile SpreadSheetWidget.cxx -g -fsanitize=address -fno-omit-frame-pointer` to build the program with Address Sanitizer (ASAN) which requires that you have it installed on your system. See bug report 'copy-paste-bug.txt' in attached file.
Note 2: The copy-paste-bug results from FL_PASTE returning the real size of the pasted string excluding the terminating NUL byte in `Fl::event_length()`. You need to take care of this in the buffer allocation on the stack (see patch).
https://www.fltk.org/doc-1.4/group__fl__events.html#ga38f2de89fbdf59ad2cd4dca93f472911
Note 3: You *might* want to use `memcpy()` instead of `strcpy()` to copy the contents of `Fl::event_text()` because it *can* contain embedded NUL bytes but then parsing the contents with `strtok()` would likely fail anyway. That's probably never happening in a real spreadsheet usage but I wanted to mention it at least.