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: 247
Joined: Mon Feb 24, 2014 3:14 pm

Can I copy text as HTML from wxTextCtrl?

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can I copy text as HTML from wxTextCtrl?

Post 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.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Can I copy text as HTML from wxTextCtrl?

Post by purplex88 »

Would I need convert it from Rich Text to HTML under wxTextCtrl?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can I copy text as HTML from wxTextCtrl?

Post 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
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Can I copy text as HTML from wxTextCtrl?

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can I copy text as HTML from wxTextCtrl?

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