Page 1 of 1

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

Posted: Mon Aug 12, 2019 11:40 am
by Rudra
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.

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

Posted: Mon Aug 12, 2019 3:44 pm
by doublemax
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.

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

Posted: Tue Aug 13, 2019 7:21 am
by Rudra
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);