Expanded FL_Table example

23 views
Skip to first unread message

Rob McDonald

unread,
Jun 18, 2024, 8:05:04 PMJun 18
to fltk.general
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.

If you paste a block of data that extends beyond the current data's limits, the underlying data store will be expanded to accommodate.  There is an option to turn off this expansion behavior (separately for rows / columns).  If you try to paste in a way that is disabled, it will beep and the paste will not succeed.

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.

Rob

Albrecht Schlosser

unread,
Jun 20, 2024, 9:45:47 AMJun 20
to fltkg...@googlegroups.com
On 6/19/24 02:05 Rob McDonald wrote:
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.


Thanks for sharing your 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)

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.

I'm not very much familiar with Fl_Table and its usage, hence I would like to see Greg's comment(s) on your example, but also comments of other devs and even users who may find this extended example useful.


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:



...

Thanks to everyone for their work on FLTK

Welcome!


- 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.

SpreadSheetWidget_patches.tgz

Rob McDonald

unread,
Jun 20, 2024, 10:38:49 AMJun 20
to fltk.general
On Thursday, June 20, 2024 at 6:45:47 AM UTC-7 Albrecht-S wrote:
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.

I totally understand.

Thanks for taking some time to play with it and give feedback.

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:




Thanks for this.  It looks like I'm going to have to move away from strtok() to something that doesn't skip repeated delimiters...

Although I haven't found it explicitly documented anywhere, it appears that spreadsheets (Excel, Sheets, Open Office, etc.) copy blocks of data to the clipboard as tab delimited strings, with \n between rows and no trailing \n.  Empty fields result in repeated tabs, which strtok() does not differentiate.
 
- 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.

Thanks for these fixes and the detailed work.  Much appreciated,

Rob 



 
Reply all
Reply to author
Forward
0 new messages