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/richtext/richtextbuffer.h"
20 #include "wx/richtext/richtextstyles.h"
22 #if wxUSE_RICHTEXT && wxUSE_XML
25 * wxRichTextXMLHandler
28 class WXDLLIMPEXP_FWD_XML wxXmlNode
;
29 class WXDLLIMPEXP_FWD_XML wxXmlDocument
;
31 class WXDLLIMPEXP_RICHTEXT wxRichTextXMLHandler
: public wxRichTextFileHandler
33 DECLARE_CLASS(wxRichTextXMLHandler
)
35 wxRichTextXMLHandler(const wxString
& name
= wxT("XML"), const wxString
& ext
= wxT("xml"), int type
= wxRICHTEXT_TYPE_XML
)
36 : wxRichTextFileHandler(name
, ext
, type
)
43 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
44 /// Recursively export an object
45 bool ExportXML(wxOutputStream
& stream
, wxRichTextObject
& obj
, int level
);
46 bool ExportStyleDefinition(wxOutputStream
& stream
, wxRichTextStyleDefinition
* def
, int level
);
47 wxString
AddAttributes(const wxRichTextAttr
& attr
, bool isPara
= false);
48 bool WriteProperties(wxOutputStream
& stream
, const wxRichTextProperties
& properties
, int level
);
49 void OutputString(wxOutputStream
& stream
, const wxString
& str
);
50 void OutputStringEnt(wxOutputStream
& stream
, const wxString
& str
);
51 void OutputIndentation(wxOutputStream
& stream
, int indent
);
52 static wxString
AttributeToXML(const wxString
& str
);
55 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
56 bool ExportXML(wxXmlNode
* parent
, wxRichTextObject
& obj
);
57 bool ExportStyleDefinition(wxXmlNode
* parent
, wxRichTextStyleDefinition
* def
);
58 bool AddAttributes(wxXmlNode
* node
, wxRichTextAttr
& attr
, bool isPara
= false);
59 bool WriteProperties(wxXmlNode
* node
, const wxRichTextProperties
& properties
);
62 /// Make a string from the given property. This can be overridden for custom variants.
63 virtual wxString
MakeStringFromProperty(const wxVariant
& var
);
65 /// Create a proprty from the string read from the XML file.
66 virtual wxVariant
MakePropertyFromString(const wxString
& name
, const wxString
& value
, const wxString
& type
);
68 /// Recursively import an object
69 bool ImportXML(wxRichTextBuffer
* buffer
, wxRichTextObject
* obj
, wxXmlNode
* node
);
70 bool ImportStyleDefinition(wxRichTextStyleSheet
* sheet
, wxXmlNode
* node
);
71 bool ImportProperties(wxRichTextObject
* obj
, wxXmlNode
* node
);
73 /// Import style parameters
74 bool ImportStyle(wxRichTextAttr
& attr
, wxXmlNode
* node
, bool isPara
= false);
77 /// Creates an object given an XML element name
78 virtual wxRichTextObject
* CreateObjectForXMLName(wxRichTextObject
* parent
, const wxString
& name
) const;
80 /// Can we save using this handler?
81 virtual bool CanSave() const { return true; }
83 /// Can we load using this handler?
84 virtual bool CanLoad() const { return true; }
87 wxMBConv
* GetConvMem() const { return m_convMem
; }
88 wxMBConv
* GetConvFile() const { return m_convFile
; }
92 bool HasParam(wxXmlNode
* node
, const wxString
& param
);
93 wxXmlNode
*GetParamNode(wxXmlNode
* node
, const wxString
& param
);
94 wxString
GetNodeContent(wxXmlNode
*node
);
95 wxString
GetParamValue(wxXmlNode
*node
, const wxString
& param
);
96 wxString
GetText(wxXmlNode
*node
, const wxString
& param
= wxEmptyString
, bool translate
= false);
97 static wxXmlNode
* FindNode(wxXmlNode
* node
, const wxString
& name
);
101 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
102 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
105 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
106 // Used during saving
108 wxMBConv
* m_convFile
;
113 // wxUSE_RICHTEXT && wxUSE_XML
116 // _WX_RICHTEXTXML_H_