const consistent for Clone(). Load/Save split to DoLoad/DoSave. Build fixes, warning...
[wxWidgets.git] / include / wx / richtext / richtextxml.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richeditxml.h
3 // Purpose: XML and HTML I/O for wxRichTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-09-30
7 // RCS-ID: $Id$
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
19 #include "wx/defs.h"
20
21 #if wxUSE_RICHTEXT
22
23 #include "wx/richtext/richtextbuffer.h"
24
25 /*!
26 * wxRichTextXMLHandler
27 */
28
29 class WXDLLIMPEXP_XML wxXmlNode;
30
31 class WXDLLIMPEXP_ADV wxRichTextXMLHandler: public wxRichTextFileHandler
32 {
33 DECLARE_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 { }
38
39 #if wxUSE_STREAMS
40 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
41 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
42
43 /// Recursively export an object
44 bool ExportXML(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextObject& obj, int level);
45
46 /// Recursively import an object
47 bool ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node);
48
49 /// Create style parameters
50 wxString CreateStyle(const wxTextAttrEx& attr, bool isPara = false);
51
52 /// Get style parameters
53 bool GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool isPara = false);
54 #endif
55
56 /// Can we save using this handler?
57 virtual bool CanSave() const { return true; }
58
59 /// Can we load using this handler?
60 virtual bool CanLoad() const { return true; }
61
62 // Implementation
63
64 bool HasParam(wxXmlNode* node, const wxString& param);
65 wxXmlNode *GetParamNode(wxXmlNode* node, const wxString& param);
66 wxString GetNodeContent(wxXmlNode *node);
67 wxString GetParamValue(wxXmlNode *node, const wxString& param);
68 wxString GetText(wxXmlNode *node, const wxString& param = wxEmptyString, bool translate = false);
69
70 protected:
71
72 };
73
74 /*!
75 * wxRichTextHTMLHandler
76 */
77
78 class WXDLLIMPEXP_ADV wxRichTextHTMLHandler: public wxRichTextFileHandler
79 {
80 DECLARE_CLASS(wxRichTextHTMLHandler)
81 public:
82 wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML)
83 : wxRichTextFileHandler(name, ext, type)
84 { }
85
86 #if wxUSE_STREAMS
87 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
88 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
89 #endif
90
91 /// Can we save using this handler?
92 virtual bool CanSave() const { return true; }
93
94 /// Can we load using this handler?
95 virtual bool CanLoad() const { return false; }
96
97 /// Can we handle this filename (if using files)? By default, checks the extension.
98 virtual bool CanHandle(const wxString& filename) const;
99
100 /// Output character formatting
101 virtual void OutputCharacterFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxOutputStream& stream, bool start);
102
103 /// Output paragraph formatting
104 virtual void OutputParagraphFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxOutputStream& stream, bool start);
105
106 protected:
107
108 };
109
110 #endif
111 // wxUSE_RICHTEXT
112
113 #endif
114 // _WX_RICHTEXTXML_H_