Added wxRichTextXMLHandler::RegisterNodeName so custom content classes can be added without
breaking XML loading git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71399 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
1e58c8b944
commit
1aca9fcdfc
@ -16,6 +16,7 @@
|
||||
* Includes
|
||||
*/
|
||||
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/richtext/richtextbuffer.h"
|
||||
#include "wx/richtext/richtextstyles.h"
|
||||
|
||||
@ -97,6 +98,17 @@ public:
|
||||
wxString GetText(wxXmlNode *node, const wxString& param = wxEmptyString, bool translate = false);
|
||||
static wxXmlNode* FindNode(wxXmlNode* node, const wxString& name);
|
||||
|
||||
/**
|
||||
Call with XML node name, C++ class name so that wxRTC can read in the node.
|
||||
If you add a custom object, call this.
|
||||
*/
|
||||
static void RegisterNodeName(const wxString& nodeName, const wxString& className) { sm_nodeNameToClassMap[nodeName] = className; }
|
||||
|
||||
/**
|
||||
Cleans up the mapping between node name and C++ class.
|
||||
*/
|
||||
static void ClearNodeToClassMap() { sm_nodeNameToClassMap.clear(); }
|
||||
|
||||
protected:
|
||||
#if wxUSE_STREAMS
|
||||
virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
|
||||
@ -108,6 +120,8 @@ protected:
|
||||
wxMBConv* m_convMem;
|
||||
wxMBConv* m_convFile;
|
||||
#endif
|
||||
|
||||
static wxStringToStringHashMap sm_nodeNameToClassMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
Recursively exports an object to the stream.
|
||||
*/
|
||||
bool ExportXML(wxOutputStream& stream, wxRichTextObject& obj, int level);
|
||||
|
||||
|
||||
/**
|
||||
Helper function: gets node context.
|
||||
*/
|
||||
@ -86,6 +86,17 @@ public:
|
||||
*/
|
||||
bool ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* obj, wxXmlNode* node);
|
||||
|
||||
/**
|
||||
Call with XML node name, C++ class name so that wxRTC can read in the node.
|
||||
If you add a custom object, call this.
|
||||
*/
|
||||
static void RegisterNodeName(const wxString& nodeName, const wxString& className) { sm_nodeNameToClassMap[nodeName] = className; }
|
||||
|
||||
/**
|
||||
Cleans up the mapping between node name and C++ class.
|
||||
*/
|
||||
static void ClearNodeToClassMap() { sm_nodeNameToClassMap.clear(); }
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "wx/richtext/richtextstyles.h"
|
||||
#include "wx/richtext/richtextimagedlg.h"
|
||||
#include "wx/richtext/richtextsizepage.h"
|
||||
#include "wx/richtext/richtextxml.h"
|
||||
|
||||
#include "wx/listimpl.cpp"
|
||||
#include "wx/arrimpl.cpp"
|
||||
@ -9855,6 +9856,17 @@ public:
|
||||
wxRichTextBuffer::SetRenderer(new wxRichTextStdRenderer);
|
||||
wxRichTextBuffer::InitStandardHandlers();
|
||||
wxRichTextParagraph::InitDefaultTabs();
|
||||
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("text"), wxT("wxRichTextPlainText"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("symbol"), wxT("wxRichTextPlainText"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("image"), wxT("wxRichTextImage"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("paragraph"), wxT("wxRichTextParagraph"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("paragraphlayout"), wxT("wxRichTextParagraphLayoutBox"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("textbox"), wxT("wxRichTextBox"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("cell"), wxT("wxRichTextCell"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("table"), wxT("wxRichTextTable"));
|
||||
wxRichTextXMLHandler::RegisterNodeName(wxT("field"), wxT("wxRichTextField"));
|
||||
|
||||
return true;
|
||||
}
|
||||
void OnExit()
|
||||
@ -9862,6 +9874,7 @@ public:
|
||||
wxRichTextBuffer::CleanUpHandlers();
|
||||
wxRichTextBuffer::CleanUpDrawingHandlers();
|
||||
wxRichTextBuffer::CleanUpFieldTypes();
|
||||
wxRichTextXMLHandler::ClearNodeToClassMap();
|
||||
wxRichTextDecimalToRoman(-1);
|
||||
wxRichTextParagraph::ClearDefaultTabs();
|
||||
wxRichTextCtrl::ClearAvailableFontNames();
|
||||
|
@ -89,6 +89,8 @@ static inline void AddString(wxString& str, const wxColour& col) { str << wxT("#
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxRichTextXMLHandler, wxRichTextFileHandler)
|
||||
|
||||
wxStringToStringHashMap wxRichTextXMLHandler::sm_nodeNameToClassMap;
|
||||
|
||||
void wxRichTextXMLHandler::Init()
|
||||
{
|
||||
#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
|
||||
@ -158,24 +160,12 @@ bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& s
|
||||
/// Creates an object given an XML element name
|
||||
wxRichTextObject* wxRichTextXMLHandler::CreateObjectForXMLName(wxRichTextObject* WXUNUSED(parent), const wxString& name) const
|
||||
{
|
||||
if (name == wxT("text") || name == wxT("symbol"))
|
||||
return new wxRichTextPlainText;
|
||||
else if (name == wxT("image"))
|
||||
return new wxRichTextImage;
|
||||
else if (name == wxT("paragraph"))
|
||||
return new wxRichTextParagraph;
|
||||
else if (name == wxT("paragraphlayout"))
|
||||
return new wxRichTextParagraphLayoutBox;
|
||||
else if (name == wxT("textbox"))
|
||||
return new wxRichTextBox;
|
||||
else if (name == wxT("cell"))
|
||||
return new wxRichTextCell;
|
||||
else if (name == wxT("table"))
|
||||
return new wxRichTextTable;
|
||||
else if (name == wxT("field"))
|
||||
return new wxRichTextField;
|
||||
else
|
||||
// The standard node to class mappings are added in wxRichTextModule::OnInit in richtextbuffer.cpp
|
||||
wxStringToStringHashMap::const_iterator it = sm_nodeNameToClassMap.find(name);
|
||||
if (it == sm_nodeNameToClassMap.end())
|
||||
return NULL;
|
||||
else
|
||||
return wxDynamicCast(wxCreateDynamicObject(it->second), wxRichTextObject);
|
||||
}
|
||||
|
||||
/// Recursively import an object
|
||||
|
Loading…
Reference in New Issue
Block a user