]> git.saurik.com Git - wxWidgets.git/blame - include/wx/richtext/richtextxml.h
No real changes, just add wxSizerItem::AddBorderToSize() helper.
[wxWidgets.git] / include / wx / richtext / richtextxml.h
CommitLineData
5d7836c4 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/richtext/richtextxml.h
5d7836c4
JS
3// Purpose: XML and HTML I/O for wxRichTextCtrl
4// Author: Julian Smart
7fe8059f 5// Modified by:
5d7836c4 6// Created: 2005-09-30
7fe8059f 7// RCS-ID: $Id$
5d7836c4
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_RICHTEXTXML_H_
13#define _WX_RICHTEXTXML_H_
14
15/*!
16 * Includes
17 */
18
1aca9fcd 19#include "wx/hashmap.h"
b01ca8b6 20#include "wx/richtext/richtextbuffer.h"
d2d0adc7 21#include "wx/richtext/richtextstyles.h"
5d7836c4 22
fcdbeefa 23#if wxUSE_RICHTEXT && wxUSE_XML
5d7836c4 24
5d7836c4
JS
25/*!
26 * wxRichTextXMLHandler
27 */
28
b5dbe15d 29class WXDLLIMPEXP_FWD_XML wxXmlNode;
bec80f4f 30class WXDLLIMPEXP_FWD_XML wxXmlDocument;
5d7836c4 31
3b2cb431 32class WXDLLIMPEXP_RICHTEXT wxRichTextXMLHandler: public wxRichTextFileHandler
5d7836c4 33{
48dd0055 34 DECLARE_DYNAMIC_CLASS(wxRichTextXMLHandler)
5d7836c4
JS
35public:
36 wxRichTextXMLHandler(const wxString& name = wxT("XML"), const wxString& ext = wxT("xml"), int type = wxRICHTEXT_TYPE_XML)
37 : wxRichTextFileHandler(name, ext, type)
bec80f4f 38 { Init(); }
c6182d48 39
bec80f4f 40 void Init();
5d7836c4
JS
41
42#if wxUSE_STREAMS
bec80f4f
JS
43
44#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
5d7836c4 45 /// Recursively export an object
bec80f4f
JS
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);
54#endif
55
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);
61#endif
62
63 /// Make a string from the given property. This can be overridden for custom variants.
64 virtual wxString MakeStringFromProperty(const wxVariant& var);
65
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);
5d7836c4
JS
68
69 /// Recursively import an object
bec80f4f 70 bool ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* obj, wxXmlNode* node);
d2d0adc7 71 bool ImportStyleDefinition(wxRichTextStyleSheet* sheet, wxXmlNode* node);
bec80f4f 72 bool ImportProperties(wxRichTextObject* obj, wxXmlNode* node);
c6182d48 73 bool ImportProperties(wxRichTextProperties& properties, wxXmlNode* node);
5d7836c4 74
bec80f4f
JS
75 /// Import style parameters
76 bool ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bool isPara = false);
5d7836c4
JS
77#endif
78
bec80f4f
JS
79 /// Creates an object given an XML element name
80 virtual wxRichTextObject* CreateObjectForXMLName(wxRichTextObject* parent, const wxString& name) const;
c6182d48 81
5d7836c4
JS
82 /// Can we save using this handler?
83 virtual bool CanSave() const { return true; }
84
85 /// Can we load using this handler?
86 virtual bool CanLoad() const { return true; }
87
bec80f4f
JS
88 // Used during saving
89 wxMBConv* GetConvMem() const { return m_convMem; }
90 wxMBConv* GetConvFile() const { return m_convFile; }
91
5d7836c4
JS
92// Implementation
93
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);
603f702b 99 static wxXmlNode* FindNode(wxXmlNode* node, const wxString& name);
5d7836c4 100
1aca9fcd
JS
101 /**
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.
104 */
105 static void RegisterNodeName(const wxString& nodeName, const wxString& className) { sm_nodeNameToClassMap[nodeName] = className; }
106
107 /**
108 Cleans up the mapping between node name and C++ class.
109 */
110 static void ClearNodeToClassMap() { sm_nodeNameToClassMap.clear(); }
111
5d7836c4 112protected:
6f02a879
VZ
113#if wxUSE_STREAMS
114 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
115 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
116#endif
bec80f4f
JS
117
118#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
119 // Used during saving
120 wxMBConv* m_convMem;
121 wxMBConv* m_convFile;
122#endif
1aca9fcd
JS
123
124 static wxStringToStringHashMap sm_nodeNameToClassMap;
5d7836c4
JS
125};
126
5d7836c4 127#endif
fcdbeefa 128 // wxUSE_RICHTEXT && wxUSE_XML
5d7836c4
JS
129
130#endif
131 // _WX_RICHTEXTXML_H_