wxRTC: extracted XML utilities into a separate class for potential reuse.
[wxWidgets.git] / interface / wx / richtext / richtextxml.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextxml.h
3 // Purpose: interface of wxRichTextXMLHandler
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
7
8 /**
9 @class wxRichTextXMLHandler
10
11 A handler for loading and saving content in an XML format specific
12 to wxRichTextBuffer.
13
14 You can either add the handler to the buffer and load and save through
15 the buffer or control API, or you can create an instance of the handler
16 on the stack and call its functions directly.
17
18
19 @section richtextxmlhandler_flags Handler flags
20
21 The following flags can be used with this handler, via the handler's SetFlags()
22 function or the buffer or control's SetHandlerFlags() function:
23
24 - wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET
25 Include the style sheet in loading and saving operations.
26
27
28 @library{wxrichtext}
29 @category{richtext}
30 */
31 class wxRichTextXMLHandler : public wxRichTextFileHandler
32 {
33 public:
34 /**
35 Constructor.
36 */
37 wxRichTextXMLHandler(const wxString& name = "XML",
38 const wxString& ext = "xml",
39 int type = wxRICHTEXT_TYPE_XML);
40
41 /**
42 Returns @true.
43 */
44 virtual bool CanLoad() const;
45
46 /**
47 Returns @true.
48 */
49 virtual bool CanSave() const;
50
51 /**
52 Recursively exports an object to the stream.
53 */
54 bool ExportXML(wxOutputStream& stream, wxRichTextObject& obj, int level);
55
56 /**
57 Recursively imports an object.
58 */
59 bool ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* obj, wxXmlNode* node);
60
61 /**
62 Call with XML node name, C++ class name so that wxRTC can read in the node.
63 If you add a custom object, call this.
64 */
65 static void RegisterNodeName(const wxString& nodeName, const wxString& className) { sm_nodeNameToClassMap[nodeName] = className; }
66
67 /**
68 Cleans up the mapping between node name and C++ class.
69 */
70 static void ClearNodeToClassMap() { sm_nodeNameToClassMap.clear(); }
71
72 protected:
73
74 /**
75 Loads buffer context from the given stream.
76 */
77 virtual bool DoLoadFile(wxRichTextBuffer* buffer, wxInputStream& stream);
78
79 /**
80 Saves buffer context to the given stream.
81 */
82 virtual bool DoSaveFile(wxRichTextBuffer* buffer, wxOutputStream& stream);
83 };
84