Page 1 of 1

Can I copy text as HTML from wxTextCtrl?

Posted: Sat Feb 02, 2019 7:02 am
by purplex88
Hello, I have a wxTextCtrl with wxTE_RICH2 style enabled:

Code: Select all

m_textCtrl = new wxTextCtrl(m_panel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH2);
It copies rich text with formatting and colors.

Can I copy the text as HTML so I can paste it with formatting into other editors supporting HTML pastes?

Re: Can I copy text as HTML from wxTextCtrl?

Posted: Sat Feb 02, 2019 8:41 am
by doublemax
There is nothing built in to do that. You'd have to write something yourself. If it's only for one platform, e.g. Windows, it might be possible to find some code "out there".

Or you could switch to wxRichTextCtrl which supports export (but not import!) in HTML.

Re: Can I copy text as HTML from wxTextCtrl?

Posted: Sat Feb 02, 2019 1:21 pm
by purplex88
Would I need convert it from Rich Text to HTML under wxTextCtrl?

Re: Can I copy text as HTML from wxTextCtrl?

Posted: Sat Feb 02, 2019 2:28 pm
by doublemax
Would I need convert it from Rich Text to HTML under wxTextCtrl?
I'm note 100% sure i understand the question. But if you use wxTextCtrl, you'd have to implement the conversion to HTML yourself.

If you need a Windows version only, you could (probably, untested) get the control's content as RTF using EM_STREAMOUT / SF_RTF. And hopefully find an RTF to HTML conversion in the open source world.
https://docs.microsoft.com/en-us/window ... -streamout

Re: Can I copy text as HTML from wxTextCtrl?

Posted: Sat Feb 02, 2019 8:00 pm
by purplex88
Libraries can have limitations. Is it best if I write the HTML output myself e.g. format the text with HTML because I saved the formatting information about (highlights, colors, etc.) into a data structure?

Re: Can I copy text as HTML from wxTextCtrl?

Posted: Sat Feb 02, 2019 9:33 pm
by doublemax
Is it best if I write the HTML output myself e.g. format the text with HTML because I saved the formatting information about (highlights, colors, etc.) into a data structure?
That's probably the best solution.