Can I copy text as HTML from wxTextCtrl? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Mon Feb 24, 2014 3:14 pm

Can I copy text as HTML from wxTextCtrl?

Post by purplex88 » Sat Feb 02, 2019 7:02 am

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?

User avatar
doublemax
Moderator
Moderator
Posts: 13430
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can I copy text as HTML from wxTextCtrl?

Post by doublemax » Sat Feb 02, 2019 8:41 am

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.
Use the source, Luke!

purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Mon Feb 24, 2014 3:14 pm

Re: Can I copy text as HTML from wxTextCtrl?

Post by purplex88 » Sat Feb 02, 2019 1:21 pm

Would I need convert it from Rich Text to HTML under wxTextCtrl?

User avatar
doublemax
Moderator
Moderator
Posts: 13430
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can I copy text as HTML from wxTextCtrl?

Post by doublemax » Sat Feb 02, 2019 2:28 pm

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
Use the source, Luke!

purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Mon Feb 24, 2014 3:14 pm

Re: Can I copy text as HTML from wxTextCtrl?

Post by purplex88 » Sat Feb 02, 2019 8:00 pm

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?

User avatar
doublemax
Moderator
Moderator
Posts: 13430
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can I copy text as HTML from wxTextCtrl?

Post by doublemax » Sat Feb 02, 2019 9:33 pm

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.
Use the source, Luke!

Post Reply