1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextxml.h
3 // Purpose: XML and HTML I/O for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTXML_H_
13 #define _WX_RICHTEXTXML_H_
19 #include "wx/hashmap.h"
20 #include "wx/richtext/richtextbuffer.h"
21 #include "wx/richtext/richtextstyles.h"
23 #if wxUSE_RICHTEXT && wxUSE_XML
26 * wxRichTextXMLHandler
29 class WXDLLIMPEXP_FWD_XML wxXmlNode
;
30 class WXDLLIMPEXP_FWD_XML wxXmlDocument
;
32 class WXDLLIMPEXP_RICHTEXT wxRichTextXMLHandler
: public wxRichTextFileHandler
34 DECLARE_DYNAMIC_CLASS(wxRichTextXMLHandler
)
36 wxRichTextXMLHandler(const wxString
& name
= wxT("XML"), const wxString
& ext
= wxT("xml"), int type
= wxRICHTEXT_TYPE_XML
)
37 : wxRichTextFileHandler(name
, ext
, type
)
44 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
45 /// Recursively export an object
46 bool ExportXML(wxOutputStream
& stream
, wxRichTextObject
& obj
, int level
);
47 bool ExportStyleDefinition(wxOutputStream
& stream
, wxRichTextStyleDefinition
* def
, int level
);
48 wxString
AddAttributes(const wxRichTextAttr
& attr
, bool isPara
= false);
49 bool WriteProperties(wxOutputStream
& stream
, const wxRichTextProperties
& properties
, int level
);
50 void OutputString(wxOutputStream
& stream
, const wxString
& str
);
51 void OutputStringEnt(wxOutputStream
& stream
, const wxString
& str
);
52 void OutputIndentation(wxOutputStream
& stream
, int indent
);
53 static wxString
AttributeToXML(const wxString
& str
);
56 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
57 bool ExportXML(wxXmlNode
* parent
, wxRichTextObject
& obj
);
58 bool ExportStyleDefinition(wxXmlNode
* parent
, wxRichTextStyleDefinition
* def
);
59 bool AddAttributes(wxXmlNode
* node
, wxRichTextAttr
& attr
, bool isPara
= false);
60 bool WriteProperties(wxXmlNode
* node
, const wxRichTextProperties
& properties
);
63 /// Make a string from the given property. This can be overridden for custom variants.
64 virtual wxString
MakeStringFromProperty(const wxVariant
& var
);
66 /// Create a proprty from the string read from the XML file.
67 virtual wxVariant
MakePropertyFromString(const wxString
& name
, const wxString
& value
, const wxString
& type
);
69 /// Recursively import an object
70 bool ImportXML(wxRichTextBuffer
* buffer
, wxRichTextObject
* obj
, wxXmlNode
* node
);
71 bool ImportStyleDefinition(wxRichTextStyleSheet
* sheet
, wxXmlNode
* node
);
72 bool ImportProperties(wxRichTextObject
* obj
, wxXmlNode
* node
);
73 bool ImportProperties(wxRichTextProperties
& properties
, wxXmlNode
* node
);
75 /// Import style parameters
76 bool ImportStyle(wxRichTextAttr
& attr
, wxXmlNode
* node
, bool isPara
= false);
79 /// Creates an object given an XML element name
80 virtual wxRichTextObject
* CreateObjectForXMLName(wxRichTextObject
* parent
, const wxString
& name
) const;
82 /// Can we save using this handler?
83 virtual bool CanSave() const { return true; }
85 /// Can we load using this handler?
86 virtual bool CanLoad() const { return true; }
89 wxMBConv
* GetConvMem() const { return m_convMem
; }
90 wxMBConv
* GetConvFile() const { return m_convFile
; }
94 bool HasParam(wxXmlNode
* node
, const wxString
& param
);
95 wxXmlNode
*GetParamNode(wxXmlNode
* node
, const wxString
& param
);
96 wxString
GetNodeContent(wxXmlNode
*node
);
97 wxString
GetParamValue(wxXmlNode
*node
, const wxString
& param
);
98 wxString
GetText(wxXmlNode
*node
, const wxString
& param
= wxEmptyString
, bool translate
= false);
99 static wxXmlNode
* FindNode(wxXmlNode
* node
, const wxString
& name
);
102 Call with XML node name, C++ class name so that wxRTC can read in the node.
103 If you add a custom object, call this.
105 static void RegisterNodeName(const wxString
& nodeName
, const wxString
& className
) { sm_nodeNameToClassMap
[nodeName
] = className
; }
108 Cleans up the mapping between node name and C++ class.
110 static void ClearNodeToClassMap() { sm_nodeNameToClassMap
.clear(); }
114 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
115 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
118 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
119 // Used during saving
121 wxMBConv
* m_convFile
;
124 static wxStringToStringHashMap sm_nodeNameToClassMap
;
128 // wxUSE_RICHTEXT && wxUSE_XML
131 // _WX_RICHTEXTXML_H_