]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextxml.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / richtext / richtextxml.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextxml.h
3 // Purpose: XML and HTML I/O for wxRichTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-09-30
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_RICHTEXTXML_H_
12 #define _WX_RICHTEXTXML_H_
13
14 /*!
15 * Includes
16 */
17
18 #include "wx/hashmap.h"
19 #include "wx/richtext/richtextbuffer.h"
20 #include "wx/richtext/richtextstyles.h"
21
22 #if wxUSE_RICHTEXT && wxUSE_XML
23
24 /*!
25 * wxRichTextXMLHandler
26 */
27
28 class WXDLLIMPEXP_FWD_XML wxXmlNode;
29 class WXDLLIMPEXP_FWD_XML wxXmlDocument;
30
31 class WXDLLIMPEXP_RICHTEXT wxRichTextXMLHandler: public wxRichTextFileHandler
32 {
33 DECLARE_DYNAMIC_CLASS(wxRichTextXMLHandler)
34 public:
35 wxRichTextXMLHandler(const wxString& name = wxT("XML"), const wxString& ext = wxT("xml"), int type = wxRICHTEXT_TYPE_XML)
36 : wxRichTextFileHandler(name, ext, type)
37 { Init(); }
38
39 void Init();
40
41 #if wxUSE_STREAMS
42
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);
53 #endif
54
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);
60 #endif
61
62 /// Make a string from the given property. This can be overridden for custom variants.
63 virtual wxString MakeStringFromProperty(const wxVariant& var);
64
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);
67
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);
72 bool ImportProperties(wxRichTextProperties& properties, wxXmlNode* node);
73
74 /// Import style parameters
75 bool ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bool isPara = false);
76 #endif
77
78 /// Creates an object given an XML element name
79 virtual wxRichTextObject* CreateObjectForXMLName(wxRichTextObject* parent, const wxString& name) const;
80
81 /// Can we save using this handler?
82 virtual bool CanSave() const { return true; }
83
84 /// Can we load using this handler?
85 virtual bool CanLoad() const { return true; }
86
87 // Used during saving
88 wxMBConv* GetConvMem() const { return m_convMem; }
89 wxMBConv* GetConvFile() const { return m_convFile; }
90
91 // Implementation
92
93 bool HasParam(wxXmlNode* node, const wxString& param);
94 wxXmlNode *GetParamNode(wxXmlNode* node, const wxString& param);
95 wxString GetNodeContent(wxXmlNode *node);
96 wxString GetParamValue(wxXmlNode *node, const wxString& param);
97 wxString GetText(wxXmlNode *node, const wxString& param = wxEmptyString, bool translate = false);
98 static wxXmlNode* FindNode(wxXmlNode* node, const wxString& name);
99
100 /**
101 Call with XML node name, C++ class name so that wxRTC can read in the node.
102 If you add a custom object, call this.
103 */
104 static void RegisterNodeName(const wxString& nodeName, const wxString& className) { sm_nodeNameToClassMap[nodeName] = className; }
105
106 /**
107 Cleans up the mapping between node name and C++ class.
108 */
109 static void ClearNodeToClassMap() { sm_nodeNameToClassMap.clear(); }
110
111 protected:
112 #if wxUSE_STREAMS
113 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
114 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
115 #endif
116
117 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
118 // Used during saving
119 wxMBConv* m_convMem;
120 wxMBConv* m_convFile;
121 #endif
122
123 static wxStringToStringHashMap sm_nodeNameToClassMap;
124 };
125
126 #endif
127 // wxUSE_RICHTEXT && wxUSE_XML
128
129 #endif
130 // _WX_RICHTEXTXML_H_