I'm trying to realize a HTML-Editor, able to load html code, display it, take changes to it and beeing able to save it as html again (as you would expect it from an email program with Italic, Bold, fonts, images etc).
This editor should be able to be compiled for WinNT and iOS with wxWidgets 2.9.2 and I am creating this project with VS2008 Express with Windows 10.
There were several classes, which I had an eye on. First of I took the wxRichTectCtrl sample, which is able to take formatted text (rich text) and pictures and save it as html allready. But unfortunately it loads html files only in plain text (with html tags).
Then I had the wxHTMLWindow, which was able to display (parse) formatted text, but doesn't allow editing it.
My last attempt was to take the wxHTMLParser itself, to do what the wxHTMLWindow does. I used the example from here:
viewtopic.php?t=1119
Which is:
LinkParser.h
Code: Select all
#ifndef __LINKPARSER_H
#define __LINKPARSER_H
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/html/htmlpars.h>
class LinkParser : public wxHtmlParser
{
wxArrayString stringArray;
wxString m_src;
public:
LinkParser(const wxString& src);
wxArrayString GetLinks();
void AddString(wxString txt);
wxObject* GetProduct(){return NULL;}
void AddText(const wxChar* txt);
};
class LinkTagHandler : public wxHtmlTagHandler
{ LinkParser* m_Parser;
public:
LinkTagHandler();
LinkTagHandler(LinkParser* p);
wxString GetSupportedTags();
bool HandleTag(const wxHtmlTag& tag);
};
#endif
Code: Select all
#include "LinkParser.h"
LinkTagHandler::LinkTagHandler()
{
m_Parser = NULL;
}
LinkTagHandler::LinkTagHandler(LinkParser *p)
{
m_Parser = p;
}
wxString LinkTagHandler::GetSupportedTags()
{
return "A";
}
bool LinkTagHandler::HandleTag(const wxHtmlTag& tag)
{
if (tag.HasParam( wxT("HREF") ))
{ wxString href(tag.GetParam( wxT("HREF") ));
m_Parser->AddString(href);
ParseInner(tag);
return true;
}
else
return false;
}
///////////////////////////////////////////////////////////////////////////////
LinkParser::LinkParser(const wxString& url)
:m_src(url)
{
AddTagHandler( new LinkTagHandler(this) );
}
void LinkParser::AddString(wxString txt)
{
stringArray.Add(txt);
}
void LinkParser::AddText(const wxChar* txt)
{
}
wxArrayString LinkParser::GetLinks()
{
Parse(m_src);
return stringArray;
}
Do you have any idea, how I could get a hold onto the rich text, displayed by the wxHtmlWindow?
I tried to derive from that class and get a hold on the input, which should be in:
htmlwin.cpp
Code: Select all
bool HtmlEditor::DoSetPage(const wxString& source)
{
[...]
m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc);
Do you know about an elegant way to parse the content of a whole html file into rich text?
Or how to get hold on what is displayed by wxHtmlWindow? (Hopefully its not a browser doing this job, whos code I'm unable to get my hand on?)
Or if I should take a look into wxScintilla for this purpose?
Thank you very much in advance
Natu