[wxMSW][wx3.0.3] wxRichTextCtrl: Loading HTML string. 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
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 221
Joined: Fri Sep 13, 2013 2:59 pm

[wxMSW][wx3.0.3] wxRichTextCtrl: Loading HTML string.

Post by Rudra » Mon Aug 12, 2019 11:40 am

Hi,

I looked into forum and found following links that says loading HTML content is not supported in wxRichTextCtrl.

viewtopic.php?t=38274
viewtopic.php?t=45019

I have a function in which I can save the RTC's content as HTML and edit later if needed. I can save the data as HTML but couldn't populate it back.
as wxRichTextHTMLHandler::LoadFile is not implemented.

Can you please suggest any workaround for this? Can I save the richtext in different format so I can load it back? Let me know if there a other way to where user can create, save, load, and edit rich text.

Please suggest.

Thanks,
R.

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

Re: [wxMSW][wx3.0.3] wxRichTextCtrl: Loading HTML string.

Post by doublemax » Mon Aug 12, 2019 3:44 pm

Can you please suggest any workaround for this? Can I save the richtext in different format so I can load it back? Let me know if there a other way to where user can create, save, load, and edit rich text.
Unfortunately that's a big limitation of wxRTC. The only format it can read and write while retaining style information is its proprietary XML based format. That is technically human readable (and editable), but you need to know what you're doing.
Use the source, Luke!

Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 221
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.3] wxRichTextCtrl: Loading HTML string.

Post by Rudra » Tue Aug 13, 2019 7:21 am

Thanks for the reply. I was stuck.

I tried XML handler and it works for me. I can save the rich text as XML and load it later.
Code is as follows,

Code: Select all

// Save
wxStringOutputStream strStream(m_rtcStr);
wxRichTextXMLHandler xmlHander;
xmlHander.SetFlags(wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64);  // save embedded image as base 64 str
if(xmlHander.SaveFile(&m_rtcCtrl->GetBuffer(), strStream) == false)
	return;
	
// Load
wxRichTextXMLHandler xmlHander;
wxStringInputStream strStream(m_rtcStr);
xmlHander.SetFlags(wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64);
xmlHander.LoadFile(&m_rtcCtrl->GetBuffer(), strStream);

Post Reply