Pass HTML string to Fl_Browser or Fl_Browser for display

19 views
Skip to first unread message

Anmol Mishra

unread,
Apr 19, 2020, 5:19:43 PM4/19/20
to fltk.general
Hi. The load methods for both Fl_Browser  and Fl_Browser  require a file based input.
I am linking FLKT into an app where I want to include a license file.

const char *licenseData =
#include "test.txt"
;
 

In the text file I do this:

R"(Line 1
Line 2
Line 3
Line 4
Line 5
Line 6)"

Is there a way I can pass this string directly to the browser ??

 help->load (licenseData);

or

browser->load (licenseData);

Albrecht Schlosser

unread,
Apr 19, 2020, 5:46:10 PM4/19/20
to fltkg...@googlegroups.com
On 4/19/20 10:50 PM Anmol Mishra wrote:
> Hi. The load methods for both Fl_Browser  and Fl_Browser  require a file
> based input.
> I am linking FLKT into an app where I want to include a license file.
>
> |constchar*licenseData =#include"test.txt";|
>
> In the text file I do this:
>
> |R"(Line1Line2Line3Line4Line5Line6)"|
>
>
> Is there a way I can pass this string directly to the browser ??
>
>  help->load (|licenseData|);
>
> or
>
> browser->load (|licenseData|);

In the title you mention "HTML string". If this is really what you have
you should consider using an Fl_Help_View widget instead of an
Fl_Browser because Fl_Help_View can display -- at least basic -- HTML
contents. If your HTML is simple enough this might be what you want.
You'd load the text from memory with the value(const char *) method.
https://www.fltk.org/doc-1.4/classFl__Help__View.html#adefe614a70fbe249dd9cb47278c1cb02

If your text is not HTML (despite the message title) I'd suggest to look
for Fl_Multiline_Output which has also a value() method.

Fl_Browser would need input line by line with its add() method (AFAICT),
but this is likely not what you want.

Greg Ercolano

unread,
Apr 19, 2020, 9:01:18 PM4/19/20
to fltkg...@googlegroups.com
On 2020-04-19 13:50, Anmol Mishra wrote:
> Hi. The load methods for both Fl_Browser  and Fl_Browser  require a file based input.
> I am linking FLKT into an app where I want to include a license file.

I'm not sure I'd use Fl_Browser for this purpose, among other things it interprets
characters like "@" as special codes for colors and fonts and such.

I have a commercial application that manages its own license files,
and the administration tool uses Fl_Text_Editor to display it, so that it looks
exactly like the original text, and people can copy/paste if need be.

If you want it to be 'read only' so the user can only view and not change
the contents, use Fl_Text_Display instead. Then they can still copy/paste
/from/ the widget, but not to it. Example:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Text_Display.H>

int main() {
Fl_Window *win = new Fl_Window(640, 480);
Fl_Text_Buffer *buff = new Fl_Text_Buffer();
Fl_Text_Display *disp = new Fl_Text_Display(20, 20, 640-40, 480-40, "Display");
disp->buffer(buff);
win->resizable(*disp);
win->show();
buff->text("line 0\nline 1\nline 2\n"
"line 3\nline 4\nline 5\n"
"line 6\nline 7\nline 8\n"
"line 9\nline 10\nline 11\n"
"line 12\nline 13\nline 14\n"
"line 15\nline 16\nline 17\n"
"line 18\nline 19\nline 20\n"
"line 21\nline 22\nline 23\n");
return(Fl::run());
}

So in your case in place of buff->text("..."); you would just use:

buff->text(licenseData);

..instead.

That all said, if you want to use Fl_Browser, then I'd suggest making a small
function that breaks the string up into NULL terminated lines, and appends them
to the browser.

Anmol Mishra

unread,
Apr 20, 2020, 4:30:26 PM4/20/20
to fltk.general
Thanks for the answers. The Fl_Help_View value() method did the trick.
Reply all
Reply to author
Forward
0 new messages