1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextxml.cpp
3 // Purpose: XML and HTML I/O for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_RICHTEXT && wxUSE_XML
21 #include "wx/richtext/richtextxml.h"
25 #include "wx/module.h"
29 #include "wx/filename.h"
30 #include "wx/clipbrd.h"
31 #include "wx/wfstream.h"
32 #include "wx/sstream.h"
33 #include "wx/txtstrm.h"
34 #include "wx/mstream.h"
35 #include "wx/tokenzr.h"
36 #include "wx/stopwatch.h"
37 #include "wx/xml/xml.h"
39 // Set to 1 for slower wxXmlDocument method, 0 for faster direct method.
40 // If we make wxXmlDocument::Save more efficient, we might switch to this
42 #define wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT 0
44 #if wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT && !wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
45 # error Must define wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT in richtextxml.h to use this method.
48 #if !wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT && !wxRICHTEXT_HAVE_DIRECT_OUTPUT
49 # error Must define wxRICHTEXT_HAVE_DIRECT_OUTPUT in richtextxml.h to use this method.
52 // Set to 1 to time file saving
53 #define wxRICHTEXT_USE_OUTPUT_TIMINGS 0
55 // Convert a colour to a 6-digit hex string
56 static wxString
ColourToHexString(const wxColour
& col
)
60 hex
+= wxDecToHex(col
.Red());
61 hex
+= wxDecToHex(col
.Green());
62 hex
+= wxDecToHex(col
.Blue());
67 // Convert 6-digit hex string to a colour
68 static wxColour
HexStringToColour(const wxString
& hex
)
70 unsigned char r
= (unsigned char)wxHexToDec(hex
.Mid(0, 2));
71 unsigned char g
= (unsigned char)wxHexToDec(hex
.Mid(2, 2));
72 unsigned char b
= (unsigned char)wxHexToDec(hex
.Mid(4, 2));
74 return wxColour(r
, g
, b
);
77 static inline wxString
MakeString(const int& v
) { return wxString::Format(wxT("%d"), v
); }
78 static inline wxString
MakeString(const long& v
) { return wxString::Format(wxT("%ld"), v
); }
79 static inline wxString
MakeString(const double& v
) { return wxString::Format(wxT("%.2f"), (float) v
); }
80 static inline wxString
MakeString(const wxString
& s
) { return s
; }
81 static inline wxString
MakeString(const wxColour
& col
) { return wxT("#") + ColourToHexString(col
); }
83 static inline void AddString(wxString
& str
, const int& v
) { str
<< wxString::Format(wxT("%d"), v
); }
84 static inline void AddString(wxString
& str
, const long& v
) { str
<< wxString::Format(wxT("%ld"), v
); }
85 static inline void AddString(wxString
& str
, const double& v
) { str
<< wxString::Format(wxT("%.2f"), (float) v
); }
86 static inline void AddString(wxString
& str
, const wxChar
* s
) { str
<< s
; }
87 static inline void AddString(wxString
& str
, const wxString
& s
) { str
<< s
; }
88 static inline void AddString(wxString
& str
, const wxColour
& col
) { str
<< wxT("#") << ColourToHexString(col
); }
90 IMPLEMENT_DYNAMIC_CLASS(wxRichTextXMLHandler
, wxRichTextFileHandler
)
92 wxStringToStringHashMap
wxRichTextXMLHandler::sm_nodeNameToClassMap
;
94 void wxRichTextXMLHandler::Init()
96 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
104 bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
109 buffer
->ResetAndClearCommands();
112 wxXmlDocument
* xmlDoc
= new wxXmlDocument
;
115 // This is the encoding to convert to (memory encoding rather than file encoding)
116 wxString
encoding(wxT("UTF-8"));
118 #if !wxUSE_UNICODE && wxUSE_INTL
119 encoding
= wxLocale::GetSystemEncodingName();
122 if (!xmlDoc
->Load(stream
, encoding
))
124 buffer
->ResetAndClearCommands();
129 if (xmlDoc
->GetRoot() && xmlDoc
->GetRoot()->GetType() == wxXML_ELEMENT_NODE
&& xmlDoc
->GetRoot()->GetName() == wxT("richtext"))
131 wxXmlNode
* child
= xmlDoc
->GetRoot()->GetChildren();
134 if (child
->GetType() == wxXML_ELEMENT_NODE
)
136 wxString name
= child
->GetName();
137 if (name
== wxT("richtext-version"))
141 ImportXML(buffer
, buffer
, child
);
144 child
= child
->GetNext();
155 buffer
->UpdateRanges();
160 /// Creates an object given an XML element name
161 wxRichTextObject
* wxRichTextXMLHandler::CreateObjectForXMLName(wxRichTextObject
* WXUNUSED(parent
), const wxString
& name
) const
163 // The standard node to class mappings are added in wxRichTextModule::OnInit in richtextbuffer.cpp
164 wxStringToStringHashMap::const_iterator it
= sm_nodeNameToClassMap
.find(name
);
165 if (it
== sm_nodeNameToClassMap
.end())
168 return wxDynamicCast(wxCreateDynamicObject(it
->second
), wxRichTextObject
);
171 /// Recursively import an object
172 bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer
* buffer
, wxRichTextObject
* obj
, wxXmlNode
* node
)
174 bool recurse
= false;
175 obj
->ImportFromXML(buffer
, node
, this, & recurse
);
177 // TODO: how to control whether to import children.
179 wxRichTextCompositeObject
* compositeParent
= wxDynamicCast(obj
, wxRichTextCompositeObject
);
180 if (recurse
&& compositeParent
)
182 wxXmlNode
* child
= node
->GetChildren();
185 if (child
->GetName() != wxT("stylesheet"))
187 wxRichTextObject
* childObj
= CreateObjectForXMLName(obj
, child
->GetName());
190 compositeParent
->AppendChild(childObj
);
191 ImportXML(buffer
, childObj
, child
);
194 child
= child
->GetNext();
201 bool wxRichTextXMLHandler::ImportProperties(wxRichTextObject
* obj
, wxXmlNode
* node
)
203 return ImportProperties(obj
->GetProperties(), node
);
206 bool wxRichTextXMLHandler::ImportProperties(wxRichTextProperties
& properties
, wxXmlNode
* node
)
208 wxXmlNode
* child
= node
->GetChildren();
211 if (child
->GetName() == wxT("properties"))
213 wxXmlNode
* propertyChild
= child
->GetChildren();
214 while (propertyChild
)
216 if (propertyChild
->GetName() == wxT("property"))
218 wxString name
= propertyChild
->GetAttribute(wxT("name"), wxEmptyString
);
219 wxString value
= propertyChild
->GetAttribute(wxT("value"), wxEmptyString
);
220 wxString type
= propertyChild
->GetAttribute(wxT("type"), wxEmptyString
);
222 wxVariant var
= MakePropertyFromString(name
, value
, type
);
225 properties
.SetProperty(var
);
228 propertyChild
= propertyChild
->GetNext();
231 child
= child
->GetNext();
236 bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet
* sheet
, wxXmlNode
* node
)
238 wxString styleType
= node
->GetName();
239 wxString styleName
= node
->GetAttribute(wxT("name"), wxEmptyString
);
240 wxString baseStyleName
= node
->GetAttribute(wxT("basestyle"), wxEmptyString
);
242 if (styleName
.empty())
245 if (styleType
== wxT("characterstyle"))
247 wxRichTextCharacterStyleDefinition
* def
= new wxRichTextCharacterStyleDefinition(styleName
);
248 def
->SetBaseStyle(baseStyleName
);
250 wxXmlNode
* child
= node
->GetChildren();
253 if (child
->GetName() == wxT("style"))
256 ImportStyle(attr
, child
, false);
259 child
= child
->GetNext();
262 ImportProperties(def
->GetProperties(), node
);
264 sheet
->AddCharacterStyle(def
);
266 else if (styleType
== wxT("paragraphstyle"))
268 wxRichTextParagraphStyleDefinition
* def
= new wxRichTextParagraphStyleDefinition(styleName
);
270 wxString nextStyleName
= node
->GetAttribute(wxT("nextstyle"), wxEmptyString
);
271 def
->SetNextStyle(nextStyleName
);
272 def
->SetBaseStyle(baseStyleName
);
274 wxXmlNode
* child
= node
->GetChildren();
277 if (child
->GetName() == wxT("style"))
280 ImportStyle(attr
, child
, true);
283 child
= child
->GetNext();
286 ImportProperties(def
->GetProperties(), node
);
288 sheet
->AddParagraphStyle(def
);
290 else if (styleType
== wxT("boxstyle"))
292 wxRichTextBoxStyleDefinition
* def
= new wxRichTextBoxStyleDefinition(styleName
);
294 def
->SetBaseStyle(baseStyleName
);
296 wxXmlNode
* child
= node
->GetChildren();
299 if (child
->GetName() == wxT("style"))
302 ImportStyle(attr
, child
, true);
305 child
= child
->GetNext();
308 ImportProperties(def
->GetProperties(), node
);
310 sheet
->AddBoxStyle(def
);
312 else if (styleType
== wxT("liststyle"))
314 wxRichTextListStyleDefinition
* def
= new wxRichTextListStyleDefinition(styleName
);
316 wxString nextStyleName
= node
->GetAttribute(wxT("nextstyle"), wxEmptyString
);
317 def
->SetNextStyle(nextStyleName
);
318 def
->SetBaseStyle(baseStyleName
);
320 wxXmlNode
* child
= node
->GetChildren();
323 if (child
->GetName() == wxT("style"))
326 ImportStyle(attr
, child
, true);
328 wxString styleLevel
= child
->GetAttribute(wxT("level"), wxEmptyString
);
329 if (styleLevel
.empty())
335 int level
= wxAtoi(styleLevel
);
336 if (level
> 0 && level
<= 10)
338 def
->SetLevelAttributes(level
-1, attr
);
342 child
= child
->GetNext();
345 ImportProperties(def
->GetProperties(), node
);
347 sheet
->AddListStyle(def
);
353 //-----------------------------------------------------------------------------
354 // xml support routines
355 //-----------------------------------------------------------------------------
357 bool wxRichTextXMLHandler::HasParam(wxXmlNode
* node
, const wxString
& param
)
359 return (GetParamNode(node
, param
) != NULL
);
362 wxXmlNode
*wxRichTextXMLHandler::GetParamNode(wxXmlNode
* node
, const wxString
& param
)
364 wxCHECK_MSG(node
, NULL
, wxT("You can't access node data before it was initialized!"));
366 wxXmlNode
*n
= node
->GetChildren();
370 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
378 wxString
wxRichTextXMLHandler::GetNodeContent(wxXmlNode
*node
)
381 if (n
== NULL
) return wxEmptyString
;
382 n
= n
->GetChildren();
386 if (n
->GetType() == wxXML_TEXT_NODE
||
387 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
388 return n
->GetContent();
391 return wxEmptyString
;
395 wxString
wxRichTextXMLHandler::GetParamValue(wxXmlNode
*node
, const wxString
& param
)
398 return GetNodeContent(node
);
400 return GetNodeContent(GetParamNode(node
, param
));
403 wxString
wxRichTextXMLHandler::GetText(wxXmlNode
*node
, const wxString
& param
, bool WXUNUSED(translate
))
405 wxXmlNode
*parNode
= GetParamNode(node
, param
);
408 wxString
str1(GetNodeContent(parNode
));
412 wxXmlNode
* wxRichTextXMLHandler::FindNode(wxXmlNode
* node
, const wxString
& name
)
414 if (node
->GetName() == name
&& name
== wxT("stylesheet"))
417 wxXmlNode
* child
= node
->GetChildren();
420 if (child
->GetName() == name
)
422 child
= child
->GetNext();
427 // For use with earlier versions of wxWidgets
428 #ifndef WXUNUSED_IN_UNICODE
430 #define WXUNUSED_IN_UNICODE(x) WXUNUSED(x)
432 #define WXUNUSED_IN_UNICODE(x) x
436 // write string to output
437 inline static void OutputString(wxOutputStream
& stream
, const wxString
& str
,
438 wxMBConv
*WXUNUSED_IN_UNICODE(convMem
), wxMBConv
*convFile
)
440 if (str
.empty()) return;
444 const wxWX2MBbuf
buf(str
.mb_str(*convFile
));
445 stream
.Write((const char*)buf
, strlen((const char*)buf
));
449 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
450 stream
.Write((const char*)buf
, strlen((const char*)buf
));
453 if ( convFile
== NULL
)
454 stream
.Write(str
.mb_str(), str
.Len());
457 wxString
str2(str
.wc_str(*convMem
), *convFile
);
458 stream
.Write(str2
.mb_str(), str2
.Len());
463 static void OutputIndentation(wxOutputStream
& stream
, int indent
)
465 wxString str
= wxT("\n");
466 for (int i
= 0; i
< indent
; i
++)
467 str
<< wxT(' ') << wxT(' ');
468 ::OutputString(stream
, str
, NULL
, NULL
);
471 // Same as above, but create entities first.
472 // Translates '<' to "<", '>' to ">" and '&' to "&"
473 static void OutputStringEnt(wxOutputStream
& stream
, const wxString
& str
,
474 wxMBConv
*convMem
= NULL
, wxMBConv
*convFile
= NULL
)
482 for (i
= 0; i
< len
; i
++)
486 // Original code excluded "&" but we _do_ want to convert
487 // the ampersand beginning & because otherwise when read in,
488 // the original "&" becomes "&".
490 if (c
== wxT('<') || c
== wxT('>') || c
== wxT('"') ||
491 (c
== wxT('&') /* && (str.Mid(i+1, 4) != wxT("amp;")) */ ))
493 OutputString(stream
, str
.Mid(last
, i
- last
), convMem
, convFile
);
497 OutputString(stream
, wxT("<"), NULL
, NULL
);
500 OutputString(stream
, wxT(">"), NULL
, NULL
);
503 OutputString(stream
, wxT("&"), NULL
, NULL
);
506 OutputString(stream
, wxT("""), NULL
, NULL
);
512 else if (wxUChar(c
) > 127)
514 OutputString(stream
, str
.Mid(last
, i
- last
), convMem
, convFile
);
516 wxString
s(wxT("&#"));
520 s
<< (int) wxUChar(c
);
523 OutputString(stream
, s
, NULL
, NULL
);
527 OutputString(stream
, str
.Mid(last
, i
- last
), convMem
, convFile
);
530 void wxRichTextXMLHandler::OutputString(wxOutputStream
& stream
, const wxString
& str
)
532 ::OutputString(stream
, str
, m_convMem
, m_convFile
);
535 void wxRichTextXMLHandler::OutputStringEnt(wxOutputStream
& stream
, const wxString
& str
)
537 ::OutputStringEnt(stream
, str
, m_convMem
, m_convFile
);
540 void wxRichTextXMLHandler::OutputIndentation(wxOutputStream
& stream
, int indent
)
542 wxString str
= wxT("\n");
543 for (int i
= 0; i
< indent
; i
++)
544 str
<< wxT(' ') << wxT(' ');
545 ::OutputString(stream
, str
, NULL
, NULL
);
548 wxString
wxRichTextXMLHandler::AttributeToXML(const wxString
& str
)
556 for (i
= 0; i
< len
; i
++)
560 // Original code excluded "&" but we _do_ want to convert
561 // the ampersand beginning & because otherwise when read in,
562 // the original "&" becomes "&".
564 if (c
== wxT('<') || c
== wxT('>') || c
== wxT('"') ||
565 (c
== wxT('&') /* && (str.Mid(i+1, 4) != wxT("amp;")) */ ))
567 str1
+= str
.Mid(last
, i
- last
);
577 str1
+= wxT("&");
580 str1
+= wxT(""");
586 else if (wxUChar(c
) > 127)
588 str1
+= str
.Mid(last
, i
- last
);
590 wxString
s(wxT("&#"));
594 s
<< (int) wxUChar(c
);
601 str1
+= str
.Mid(last
, i
- last
);
605 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
607 static inline void AddAttribute(wxString
& str
, const wxString
& name
, const int& v
)
609 str
<< wxT(" ") << name
<< wxT("=\"") << wxString::Format(wxT("%d"), v
) << wxT("\"");
612 static inline void AddAttribute(wxString
& str
, const wxString
& name
, const long& v
)
614 str
<< wxT(" ") << name
<< wxT("=\"") << wxString::Format(wxT("%ld"), v
) << wxT("\"");
617 static inline void AddAttribute(wxString
& str
, const wxString
& name
, const double& v
)
619 str
<< wxT(" ") << name
<< wxT("=\"") << wxString::Format(wxT("%.2f"), (float) v
) << wxT("\"");
622 static inline void AddAttribute(wxString
& str
, const wxString
& name
, const wxChar
* s
)
624 str
<< wxT(" ") << name
<< wxT("=\"") << s
<< wxT("\"");
627 static inline void AddAttribute(wxString
& str
, const wxString
& name
, const wxString
& s
)
629 str
<< wxT(" ") << name
<< wxT("=\"") << s
<< wxT("\"");
632 static inline void AddAttribute(wxString
& str
, const wxString
& name
, const wxColour
& col
)
634 str
<< wxT(" ") << name
<< wxT("=\"") << wxT("#") << ColourToHexString(col
) << wxT("\"");
637 static inline void AddAttribute(wxString
& str
, const wxString
& name
, const wxTextAttrDimension
& dim
)
641 wxString value
= MakeString(dim
.GetValue()) + wxT(",") + MakeString((int) dim
.GetFlags());
642 str
<< wxT(" ") << name
<< wxT("=\"");
648 static inline void AddAttribute(wxString
& str
, const wxString
& rootName
, const wxTextAttrDimensions
& dims
)
650 if (dims
.GetLeft().IsValid())
651 AddAttribute(str
, rootName
+ wxString(wxT("-left")), dims
.GetLeft());
652 if (dims
.GetRight().IsValid())
653 AddAttribute(str
, rootName
+ wxString(wxT("-right")), dims
.GetRight());
654 if (dims
.GetTop().IsValid())
655 AddAttribute(str
, rootName
+ wxString(wxT("-top")), dims
.GetTop());
656 if (dims
.GetBottom().IsValid())
657 AddAttribute(str
, rootName
+ wxString(wxT("-bottom")), dims
.GetBottom());
660 static inline void AddAttribute(wxString
& str
, const wxString
& rootName
, const wxTextAttrBorder
& border
)
662 if (border
.HasStyle())
663 AddAttribute(str
, rootName
+ wxString(wxT("-style")), border
.GetStyle());
664 if (border
.HasColour())
665 AddAttribute(str
, rootName
+ wxString(wxT("-color")), border
.GetColour());
666 if (border
.HasWidth())
667 AddAttribute(str
, rootName
+ wxString(wxT("-width")), border
.GetWidth());
670 static inline void AddAttribute(wxString
& str
, const wxString
& rootName
, const wxTextAttrBorders
& borders
)
672 AddAttribute(str
, rootName
+ wxString(wxT("-left")), borders
.GetLeft());
673 AddAttribute(str
, rootName
+ wxString(wxT("-right")), borders
.GetRight());
674 AddAttribute(str
, rootName
+ wxString(wxT("-top")), borders
.GetTop());
675 AddAttribute(str
, rootName
+ wxString(wxT("-bottom")), borders
.GetBottom());
679 // wxRICHTEXT_HAVE_DIRECT_OUTPUT
681 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
683 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& name
, const int& v
)
685 node
->AddAttribute(name
, MakeString(v
));
688 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& name
, const long& v
)
690 node
->AddAttribute(name
, MakeString(v
));
693 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& name
, const double& v
)
695 node
->AddAttribute(name
, MakeString(v
));
698 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& name
, const wxString
& s
)
700 node
->AddAttribute(name
, s
);
703 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& name
, const wxColour
& col
)
705 node
->AddAttribute(name
, MakeString(col
));
708 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& name
, const wxTextAttrDimension
& dim
)
712 wxString value
= MakeString(dim
.GetValue()) + wxT(",") + MakeString(dim
.GetFlags());
713 AddAttribute(node
, name
, value
);
717 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& rootName
, const wxTextAttrDimensions
& dims
)
719 if (dims
.GetLeft().IsValid())
720 AddAttribute(node
, rootName
+ wxString(wxT("-left")), dims
.GetLeft());
721 if (dims
.GetRight().IsValid())
722 AddAttribute(node
, rootName
+ wxString(wxT("-right")), dims
.GetRight());
723 if (dims
.GetTop().IsValid())
724 AddAttribute(node
, rootName
+ wxString(wxT("-top")), dims
.GetTop());
725 if (dims
.GetBottom().IsValid())
726 AddAttribute(node
, rootName
+ wxString(wxT("-bottom")), dims
.GetBottom());
729 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& rootName
, const wxTextAttrBorder
& border
)
731 if (border
.HasStyle())
732 AddAttribute(node
, rootName
+ wxString(wxT("-style")), border
.GetStyle());
733 if (border
.HasColour())
734 AddAttribute(node
, rootName
+ wxString(wxT("-color")), border
.GetColour());
735 if (border
.HasWidth())
736 AddAttribute(node
, rootName
+ wxString(wxT("-width")), border
.GetWidth());
739 static inline void AddAttribute(wxXmlNode
* node
, const wxString
& rootName
, const wxTextAttrBorders
& borders
)
741 AddAttribute(node
, rootName
+ wxString(wxT("-left")), borders
.GetLeft());
742 AddAttribute(node
, rootName
+ wxString(wxT("-right")), borders
.GetRight());
743 AddAttribute(node
, rootName
+ wxString(wxT("-top")), borders
.GetTop());
744 AddAttribute(node
, rootName
+ wxString(wxT("-bottom")), borders
.GetBottom());
747 // wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
749 bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
754 wxString
version(wxT("1.0") ) ;
756 bool deleteConvFile
= false;
757 wxString fileEncoding
;
758 //wxMBConv* convFile = NULL;
761 fileEncoding
= wxT("UTF-8");
762 m_convFile
= & wxConvUTF8
;
764 fileEncoding
= wxT("ISO-8859-1");
765 m_convFile
= & wxConvISO8859_1
;
768 // If SetEncoding has been called, change the output encoding.
769 if (!m_encoding
.empty() && m_encoding
.Lower() != fileEncoding
.Lower())
771 if (m_encoding
== wxT("<System>"))
774 fileEncoding
= wxLocale::GetSystemEncodingName();
775 // if !wxUSE_INTL, we fall back to UTF-8 or ISO-8859-1 below
780 fileEncoding
= m_encoding
;
783 // GetSystemEncodingName may not have returned a name
784 if (fileEncoding
.empty())
786 fileEncoding
= wxT("UTF-8");
788 fileEncoding
= wxT("ISO-8859-1");
790 m_convFile
= new wxCSConv(fileEncoding
);
791 deleteConvFile
= true;
794 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT && wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT
795 #if wxRICHTEXT_USE_OUTPUT_TIMINGS
796 wxStopWatch stopwatch
;
798 wxXmlDocument
* doc
= new wxXmlDocument
;
799 doc
->SetFileEncoding(fileEncoding
);
801 wxXmlNode
* rootNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("richtext"));
802 doc
->SetRoot(rootNode
);
803 rootNode
->AddAttribute(wxT("version"), wxT("1.0.0.0"));
804 rootNode
->AddAttribute(wxT("xmlns"), wxT("http://www.wxwidgets.org"));
806 if (buffer
->GetStyleSheet() && (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET
))
808 wxXmlNode
* styleSheetNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("stylesheet"));
809 rootNode
->AddChild(styleSheetNode
);
811 wxString nameAndDescr
;
813 if (!buffer
->GetStyleSheet()->GetName().empty())
814 styleSheetNode
->AddAttribute(wxT("name"), buffer
->GetStyleSheet()->GetName());
816 if (!buffer
->GetStyleSheet()->GetDescription().empty())
817 styleSheetNode
->AddAttribute(wxT("description"), buffer
->GetStyleSheet()->GetDescription());
820 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetCharacterStyleCount(); i
++)
822 wxRichTextCharacterStyleDefinition
* def
= buffer
->GetStyleSheet()->GetCharacterStyle(i
);
823 ExportStyleDefinition(styleSheetNode
, def
);
826 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetParagraphStyleCount(); i
++)
828 wxRichTextParagraphStyleDefinition
* def
= buffer
->GetStyleSheet()->GetParagraphStyle(i
);
829 ExportStyleDefinition(styleSheetNode
, def
);
832 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetListStyleCount(); i
++)
834 wxRichTextListStyleDefinition
* def
= buffer
->GetStyleSheet()->GetListStyle(i
);
835 ExportStyleDefinition(styleSheetNode
, def
);
838 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetBoxStyleCount(); i
++)
840 wxRichTextBoxStyleDefinition
* def
= buffer
->GetStyleSheet()->GetBoxStyle(i
);
841 ExportStyleDefinition(styleSheetNode
, def
);
844 WriteProperties(styleSheetNode
, buffer
->GetStyleSheet()->GetProperties());
846 bool success
= ExportXML(rootNode
, *buffer
);
847 #if wxRICHTEXT_USE_OUTPUT_TIMINGS
848 long t
= stopwatch
.Time();
849 wxLogDebug(wxT("Creating the document took %ldms"), t
);
850 wxMessageBox(wxString::Format(wxT("Creating the document took %ldms"), t
));
854 #if wxRICHTEXT_USE_OUTPUT_TIMINGS
857 success
= doc
->Save(stream
);
858 #if wxRICHTEXT_USE_OUTPUT_TIMINGS
860 wxLogDebug(wxT("Save() took %ldms"), t2
);
861 wxMessageBox(wxString::Format(wxT("Save() took %ldms"), t2
));
868 // !(wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT && wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT)
871 m_convMem
= wxConvCurrent
;
877 s
.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
878 version
, fileEncoding
);
879 OutputString(stream
, s
);
880 OutputString(stream
, wxT("<richtext version=\"1.0.0.0\" xmlns=\"http://www.wxwidgets.org\">"));
884 if (buffer
->GetStyleSheet() && (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET
))
886 OutputIndentation(stream
, level
);
887 wxString nameAndDescr
;
888 if (!buffer
->GetStyleSheet()->GetName().empty())
889 nameAndDescr
<< wxT(" name=\"") << buffer
->GetStyleSheet()->GetName() << wxT("\"");
890 if (!buffer
->GetStyleSheet()->GetDescription().empty())
891 nameAndDescr
<< wxT(" description=\"") << buffer
->GetStyleSheet()->GetDescription() << wxT("\"");
892 OutputString(stream
, wxString(wxT("<stylesheet")) + nameAndDescr
+ wxT(">"));
896 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetCharacterStyleCount(); i
++)
898 wxRichTextCharacterStyleDefinition
* def
= buffer
->GetStyleSheet()->GetCharacterStyle(i
);
899 ExportStyleDefinition(stream
, def
, level
+ 1);
902 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetParagraphStyleCount(); i
++)
904 wxRichTextParagraphStyleDefinition
* def
= buffer
->GetStyleSheet()->GetParagraphStyle(i
);
905 ExportStyleDefinition(stream
, def
, level
+ 1);
908 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetListStyleCount(); i
++)
910 wxRichTextListStyleDefinition
* def
= buffer
->GetStyleSheet()->GetListStyle(i
);
911 ExportStyleDefinition(stream
, def
, level
+ 1);
914 for (i
= 0; i
< (int) buffer
->GetStyleSheet()->GetBoxStyleCount(); i
++)
916 wxRichTextBoxStyleDefinition
* def
= buffer
->GetStyleSheet()->GetBoxStyle(i
);
917 ExportStyleDefinition(stream
, def
, level
+ 1);
920 WriteProperties(stream
, buffer
->GetStyleSheet()->GetProperties(), level
);
922 OutputIndentation(stream
, level
);
923 OutputString(stream
, wxT("</stylesheet>"));
927 bool success
= ExportXML(stream
, *buffer
, level
);
929 OutputString(stream
, wxT("\n</richtext>"));
930 OutputString(stream
, wxT("\n"));
941 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
943 /// Recursively export an object
944 bool wxRichTextXMLHandler::ExportXML(wxOutputStream
& stream
, wxRichTextObject
& obj
, int indent
)
946 obj
.ExportXML(stream
, indent
, this);
951 bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream
& stream
, wxRichTextStyleDefinition
* def
, int level
)
953 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
);
954 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
);
955 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
956 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
958 wxString name
= def
->GetName();
961 nameProp
= wxT(" name=\"") + AttributeToXML(name
) + wxT("\"");
963 wxString baseStyle
= def
->GetBaseStyle();
964 wxString baseStyleProp
;
965 if (!baseStyle
.empty())
966 baseStyleProp
= wxT(" basestyle=\"") + AttributeToXML(baseStyle
) + wxT("\"");
968 wxString descr
= def
->GetDescription();
971 descrProp
= wxT(" description=\"") + AttributeToXML(descr
) + wxT("\"");
975 OutputIndentation(stream
, level
);
976 OutputString(stream
, wxT("<characterstyle") + nameProp
+ baseStyleProp
+ descrProp
+ wxT(">"));
980 wxString style
= AddAttributes(def
->GetStyle(), false);
982 OutputIndentation(stream
, level
);
983 OutputString(stream
, wxT("<style ") + style
+ wxT(">"));
985 OutputIndentation(stream
, level
);
986 OutputString(stream
, wxT("</style>"));
990 OutputIndentation(stream
, level
);
991 OutputString(stream
, wxT("</characterstyle>"));
995 OutputIndentation(stream
, level
);
997 if (!listDef
->GetNextStyle().empty())
998 baseStyleProp
<< wxT(" nextstyle=\"") << AttributeToXML(listDef
->GetNextStyle()) << wxT("\"");
1000 OutputString(stream
, wxT("<liststyle") + nameProp
+ baseStyleProp
+ descrProp
+ wxT(">"));
1004 wxString style
= AddAttributes(def
->GetStyle(), true);
1006 OutputIndentation(stream
, level
);
1007 OutputString(stream
, wxT("<style ") + style
+ wxT(">"));
1009 OutputIndentation(stream
, level
);
1010 OutputString(stream
, wxT("</style>"));
1013 for (i
= 0; i
< 10; i
++)
1015 wxRichTextAttr
* levelAttr
= listDef
->GetLevelAttributes(i
);
1018 wxString style
= AddAttributes(def
->GetStyle(), true);
1019 wxString levelStr
= wxString::Format(wxT(" level=\"%d\" "), (i
+1));
1021 OutputIndentation(stream
, level
);
1022 OutputString(stream
, wxT("<style ") + levelStr
+ style
+ wxT(">"));
1024 OutputIndentation(stream
, level
);
1025 OutputString(stream
, wxT("</style>"));
1031 OutputIndentation(stream
, level
);
1032 OutputString(stream
, wxT("</liststyle>"));
1036 OutputIndentation(stream
, level
);
1038 if (!paraDef
->GetNextStyle().empty())
1039 baseStyleProp
<< wxT(" nextstyle=\"") << AttributeToXML(paraDef
->GetNextStyle()) << wxT("\"");
1041 OutputString(stream
, wxT("<paragraphstyle") + nameProp
+ baseStyleProp
+ descrProp
+ wxT(">"));
1045 wxString style
= AddAttributes(def
->GetStyle(), true);
1047 OutputIndentation(stream
, level
);
1048 OutputString(stream
, wxT("<style ") + style
+ wxT(">"));
1050 OutputIndentation(stream
, level
);
1051 OutputString(stream
, wxT("</style>"));
1055 OutputIndentation(stream
, level
);
1056 OutputString(stream
, wxT("</paragraphstyle>"));
1060 OutputIndentation(stream
, level
);
1062 OutputString(stream
, wxT("<boxstyle") + nameProp
+ baseStyleProp
+ descrProp
+ wxT(">"));
1066 wxString style
= AddAttributes(def
->GetStyle(), true);
1068 OutputIndentation(stream
, level
);
1069 OutputString(stream
, wxT("<style ") + style
+ wxT(">"));
1071 OutputIndentation(stream
, level
);
1072 OutputString(stream
, wxT("</style>"));
1076 OutputIndentation(stream
, level
);
1077 OutputString(stream
, wxT("</boxstyle>"));
1080 WriteProperties(stream
, def
->GetProperties(), level
);
1085 /// Create a string containing style attributes
1086 wxString
wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr
& attr
, bool isPara
)
1089 if (attr
.HasTextColour() && attr
.GetTextColour().IsOk())
1090 AddAttribute(str
, wxT("textcolor"), attr
.GetTextColour());
1092 if (attr
.HasBackgroundColour() && attr
.GetBackgroundColour().IsOk())
1093 AddAttribute(str
, wxT("bgcolor"), attr
.GetBackgroundColour());
1095 if (attr
.HasFontPointSize())
1096 AddAttribute(str
, wxT("fontpointsize"), attr
.GetFontSize());
1097 else if (attr
.HasFontPixelSize())
1098 AddAttribute(str
, wxT("fontpixelsize"), attr
.GetFontSize());
1100 if (attr
.HasFontFamily())
1101 AddAttribute(str
, wxT("fontfamily"), attr
.GetFontFamily());
1103 if (attr
.HasFontItalic())
1104 AddAttribute(str
, wxT("fontstyle"), attr
.GetFontStyle());
1106 if (attr
.HasFontWeight())
1107 AddAttribute(str
, wxT("fontweight"), attr
.GetFontWeight());
1109 if (attr
.HasFontUnderlined())
1110 AddAttribute(str
, wxT("fontunderlined"), (int) attr
.GetFontUnderlined());
1112 if (attr
.HasFontFaceName())
1113 AddAttribute(str
, wxT("fontface"), AttributeToXML(attr
.GetFontFaceName()));
1115 if (attr
.HasTextEffects())
1117 AddAttribute(str
, wxT("texteffects"), attr
.GetTextEffects());
1118 AddAttribute(str
, wxT("texteffectflags"), attr
.GetTextEffectFlags());
1121 if (!attr
.GetCharacterStyleName().empty())
1122 AddAttribute(str
, wxT("characterstyle"), AttributeToXML(attr
.GetCharacterStyleName()));
1125 AddAttribute(str
, wxT("url"), AttributeToXML(attr
.GetURL()));
1129 if (attr
.HasAlignment())
1130 AddAttribute(str
, wxT("alignment"), (int) attr
.GetAlignment());
1132 if (attr
.HasLeftIndent())
1134 AddAttribute(str
, wxT("leftindent"), (int) attr
.GetLeftIndent());
1135 AddAttribute(str
, wxT("leftsubindent"), (int) attr
.GetLeftSubIndent());
1138 if (attr
.HasRightIndent())
1139 AddAttribute(str
, wxT("rightindent"), (int) attr
.GetRightIndent());
1141 if (attr
.HasParagraphSpacingAfter())
1142 AddAttribute(str
, wxT("parspacingafter"), (int) attr
.GetParagraphSpacingAfter());
1144 if (attr
.HasParagraphSpacingBefore())
1145 AddAttribute(str
, wxT("parspacingbefore"), (int) attr
.GetParagraphSpacingBefore());
1147 if (attr
.HasLineSpacing())
1148 AddAttribute(str
, wxT("linespacing"), (int) attr
.GetLineSpacing());
1150 if (attr
.HasBulletStyle())
1151 AddAttribute(str
, wxT("bulletstyle"), (int) attr
.GetBulletStyle());
1153 if (attr
.HasBulletNumber())
1154 AddAttribute(str
, wxT("bulletnumber"), (int) attr
.GetBulletNumber());
1156 if (attr
.HasBulletText())
1158 // If using a bullet symbol, convert to integer in case it's a non-XML-friendly character.
1159 // Otherwise, assume it's XML-friendly text such as outline numbering, e.g. 1.2.3.1
1160 if (!attr
.GetBulletText().empty() && (attr
.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL
))
1161 AddAttribute(str
, wxT("bulletsymbol"), (int) (attr
.GetBulletText()[0]));
1163 AddAttribute(str
, wxT("bullettext"), AttributeToXML(attr
.GetBulletText()));
1165 AddAttribute(str
, wxT("bulletfont"), attr
.GetBulletFont());
1168 if (attr
.HasBulletName())
1169 AddAttribute(str
, wxT("bulletname"), AttributeToXML(attr
.GetBulletName()));
1171 if (!attr
.GetParagraphStyleName().empty())
1172 AddAttribute(str
, wxT("parstyle"), AttributeToXML(attr
.GetParagraphStyleName()));
1174 if (!attr
.GetListStyleName().empty())
1175 AddAttribute(str
, wxT("liststyle"), AttributeToXML(attr
.GetListStyleName()));
1177 if (!attr
.GetTextBoxAttr().GetBoxStyleName().empty())
1178 AddAttribute(str
, wxT("boxstyle"), AttributeToXML(attr
.GetTextBoxAttr().GetBoxStyleName()));
1184 for (i
= 0; i
< attr
.GetTabs().GetCount(); i
++)
1186 if (i
> 0) strTabs
<< wxT(",");
1187 strTabs
<< attr
.GetTabs()[i
];
1189 AddAttribute(str
, wxT("tabs"), strTabs
);
1192 if (attr
.HasPageBreak())
1194 AddAttribute(str
, wxT("pagebreak"), 1);
1197 if (attr
.HasOutlineLevel())
1198 AddAttribute(str
, wxT("outlinelevel"), (int) attr
.GetOutlineLevel());
1201 AddAttribute(str
, wxT("margin"), attr
.GetTextBoxAttr().GetMargins());
1202 AddAttribute(str
, wxT("padding"), attr
.GetTextBoxAttr().GetPadding());
1203 AddAttribute(str
, wxT("position"), attr
.GetTextBoxAttr().GetPosition());
1204 AddAttribute(str
, wxT("border"), attr
.GetTextBoxAttr().GetBorder());
1205 AddAttribute(str
, wxT("outline"), attr
.GetTextBoxAttr().GetOutline());
1206 AddAttribute(str
, wxT("width"), attr
.GetTextBoxAttr().GetWidth());
1207 AddAttribute(str
, wxT("height"), attr
.GetTextBoxAttr().GetHeight());
1208 AddAttribute(str
, wxT("minwidth"), attr
.GetTextBoxAttr().GetMinSize().GetWidth());
1209 AddAttribute(str
, wxT("minheight"), attr
.GetTextBoxAttr().GetMinSize().GetHeight());
1210 AddAttribute(str
, wxT("maxwidth"), attr
.GetTextBoxAttr().GetMaxSize().GetWidth());
1211 AddAttribute(str
, wxT("maxheight"), attr
.GetTextBoxAttr().GetMaxSize().GetHeight());
1213 if (attr
.GetTextBoxAttr().HasVerticalAlignment())
1216 if (attr
.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP
)
1218 else if (attr
.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE
)
1219 value
= wxT("centre");
1220 else if (attr
.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM
)
1221 value
= wxT("bottom");
1223 value
= wxT("none");
1224 AddAttribute(str
, wxT("verticalalignment"), value
);
1227 if (attr
.GetTextBoxAttr().HasFloatMode())
1230 if (attr
.GetTextBoxAttr().GetFloatMode() == wxTEXT_BOX_ATTR_FLOAT_LEFT
)
1231 value
= wxT("left");
1232 else if (attr
.GetTextBoxAttr().GetFloatMode() == wxTEXT_BOX_ATTR_FLOAT_RIGHT
)
1233 value
= wxT("right");
1235 value
= wxT("none");
1236 AddAttribute(str
, wxT("float"), value
);
1239 if (attr
.GetTextBoxAttr().HasClearMode())
1242 if (attr
.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_LEFT
)
1243 value
= wxT("left");
1244 else if (attr
.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_RIGHT
)
1245 value
= wxT("right");
1246 else if (attr
.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_BOTH
)
1247 value
= wxT("both");
1249 value
= wxT("none");
1250 AddAttribute(str
, wxT("clear"), value
);
1253 if (attr
.GetTextBoxAttr().HasCollapseBorders())
1254 AddAttribute(str
, wxT("collapse-borders"), (int) attr
.GetTextBoxAttr().GetCollapseBorders());
1259 // Make a string from the given property. This can be overridden for custom variants.
1260 wxString
wxRichTextXMLHandler::MakeStringFromProperty(const wxVariant
& var
)
1262 return var
.MakeString();
1265 // Create a proprty from the string read from the XML file.
1266 wxVariant
wxRichTextXMLHandler::MakePropertyFromString(const wxString
& name
, const wxString
& value
, const wxString
& WXUNUSED(type
))
1268 wxVariant
var(value
, name
);
1269 // TODO: use type to create using common types
1273 // Write the properties
1274 bool wxRichTextXMLHandler::WriteProperties(wxOutputStream
& stream
, const wxRichTextProperties
& properties
, int level
)
1276 if (properties
.GetCount() > 0)
1280 OutputIndentation(stream
, level
);
1281 OutputString(stream
, wxT("<properties>"));
1286 for (i
= 0; i
< properties
.GetCount(); i
++)
1288 const wxVariant
& var
= properties
[i
];
1291 const wxString
& name
= var
.GetName();
1292 wxString value
= MakeStringFromProperty(var
);
1294 OutputIndentation(stream
, level
);
1295 OutputString(stream
, wxT("<property name=\"") + name
+
1296 wxT("\" type=\"") + var
.GetType() + wxT("\" value=\""));
1297 OutputStringEnt(stream
, value
);
1298 OutputString(stream
, wxT("\"/>"));
1304 OutputIndentation(stream
, level
);
1305 OutputString(stream
, wxT("</properties>"));
1315 // wxRICHTEXT_HAVE_DIRECT_OUTPUT
1317 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
1318 bool wxRichTextXMLHandler::ExportXML(wxXmlNode
* parent
, wxRichTextObject
& obj
)
1320 obj
.ExportXML(parent
, this);
1325 bool wxRichTextXMLHandler::ExportStyleDefinition(wxXmlNode
* parent
, wxRichTextStyleDefinition
* def
)
1327 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
);
1328 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
);
1329 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
1330 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
1332 wxString baseStyle
= def
->GetBaseStyle();
1333 wxString descr
= def
->GetDescription();
1335 wxXmlNode
* defNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxEmptyString
);
1336 parent
->AddChild(defNode
);
1337 if (!baseStyle
.empty())
1338 defNode
->AddAttribute(wxT("basestyle"), baseStyle
);
1340 defNode
->AddAttribute(wxT("description"), descr
);
1342 wxXmlNode
* styleNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("style"));
1343 defNode
->AddChild(styleNode
);
1347 defNode
->SetName(wxT("characterstyle"));
1348 AddAttributes(styleNode
, def
->GetStyle(), false);
1352 defNode
->SetName(wxT("liststyle"));
1354 if (!listDef
->GetNextStyle().empty())
1355 defNode
->AddAttribute(wxT("nextstyle"), listDef
->GetNextStyle());
1357 AddAttributes(styleNode
, def
->GetStyle(), true);
1360 for (i
= 0; i
< 10; i
++)
1362 wxRichTextAttr
* levelAttr
= listDef
->GetLevelAttributes(i
);
1365 wxXmlNode
* levelNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("style"));
1366 defNode
->AddChild(levelNode
);
1367 levelNode
->AddAttribute(wxT("level"), MakeString(i
+1));
1368 AddAttributes(levelNode
, * levelAttr
, true);
1374 defNode
->SetName(wxT("boxstyle"));
1376 AddAttributes(styleNode
, def
->GetStyle(), true);
1380 defNode
->SetName(wxT("paragraphstyle"));
1382 if (!paraDef
->GetNextStyle().empty())
1383 defNode
->AddAttribute(wxT("nextstyle"), paraDef
->GetNextStyle());
1385 AddAttributes(styleNode
, def
->GetStyle(), true);
1388 WriteProperties(defNode
, def
->GetProperties());
1393 bool wxRichTextXMLHandler::AddAttributes(wxXmlNode
* node
, wxRichTextAttr
& attr
, bool isPara
)
1395 if (attr
.HasTextColour() && attr
.GetTextColour().IsOk())
1396 node
->AddAttribute(wxT("textcolor"), MakeString(attr
.GetTextColour()));
1397 if (attr
.HasBackgroundColour() && attr
.GetBackgroundColour().IsOk())
1398 node
->AddAttribute(wxT("bgcolor"), MakeString(attr
.GetBackgroundColour()));
1400 if (attr
.HasFontPointSize())
1401 node
->AddAttribute(wxT("fontpointsize"), MakeString(attr
.GetFontSize()));
1402 else if (attr
.HasFontPixelSize())
1403 node
->AddAttribute(wxT("fontpixelsize"), MakeString(attr
.GetFontSize()));
1404 if (attr
.HasFontFamily())
1405 node
->AddAttribute(wxT("fontfamily"), MakeString(attr
.GetFontFamily()));
1406 if (attr
.HasFontItalic())
1407 node
->AddAttribute(wxT("fontstyle"), MakeString(attr
.GetFontStyle()));
1408 if (attr
.HasFontWeight())
1409 node
->AddAttribute(wxT("fontweight"), MakeString(attr
.GetFontWeight()));
1410 if (attr
.HasFontUnderlined())
1411 node
->AddAttribute(wxT("fontunderlined"), MakeString((int) attr
.GetFontUnderlined()));
1412 if (attr
.HasFontFaceName())
1413 node
->AddAttribute(wxT("fontface"), attr
.GetFontFaceName());
1415 if (attr
.HasTextEffects())
1417 node
->AddAttribute(wxT("texteffects"), MakeString(attr
.GetTextEffects()));
1418 node
->AddAttribute(wxT("texteffectflags"), MakeString(attr
.GetTextEffectFlags()));
1420 if (attr
.HasCharacterStyleName() && !attr
.GetCharacterStyleName().empty())
1421 node
->AddAttribute(wxT("characterstyle"), attr
.GetCharacterStyleName());
1424 node
->AddAttribute(wxT("url"), attr
.GetURL()); // TODO: do we need to wrap this in AttributeToXML?
1428 if (attr
.HasAlignment())
1429 node
->AddAttribute(wxT("alignment"), MakeString((int) attr
.GetAlignment()));
1431 if (attr
.HasLeftIndent())
1433 node
->AddAttribute(wxT("leftindent"), MakeString((int) attr
.GetLeftIndent()));
1434 node
->AddAttribute(wxT("leftsubindent"), MakeString((int) attr
.GetLeftSubIndent()));
1437 if (attr
.HasRightIndent())
1438 node
->AddAttribute(wxT("rightindent"), MakeString((int) attr
.GetRightIndent()));
1440 if (attr
.HasParagraphSpacingAfter())
1441 node
->AddAttribute(wxT("parspacingafter"), MakeString((int) attr
.GetParagraphSpacingAfter()));
1443 if (attr
.HasParagraphSpacingBefore())
1444 node
->AddAttribute(wxT("parspacingbefore"), MakeString((int) attr
.GetParagraphSpacingBefore()));
1446 if (attr
.HasLineSpacing())
1447 node
->AddAttribute(wxT("linespacing"), MakeString((int) attr
.GetLineSpacing()));
1449 if (attr
.HasBulletStyle())
1450 node
->AddAttribute(wxT("bulletstyle"), MakeString((int) attr
.GetBulletStyle()));
1452 if (attr
.HasBulletNumber())
1453 node
->AddAttribute(wxT("bulletnumber"), MakeString((int) attr
.GetBulletNumber()));
1455 if (attr
.HasBulletText())
1457 // If using a bullet symbol, convert to integer in case it's a non-XML-friendly character.
1458 // Otherwise, assume it's XML-friendly text such as outline numbering, e.g. 1.2.3.1
1459 if (!attr
.GetBulletText().empty() && (attr
.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL
))
1460 node
->AddAttribute(wxT("bulletsymbol"), MakeString((int) (attr
.GetBulletText()[0])));
1462 node
->AddAttribute(wxT("bullettext"), attr
.GetBulletText());
1464 if (!attr
.GetBulletFont().empty())
1465 node
->AddAttribute(wxT("bulletfont"), attr
.GetBulletFont());
1468 if (attr
.HasBulletName())
1469 node
->AddAttribute(wxT("bulletname"), attr
.GetBulletName());
1471 if (!attr
.GetParagraphStyleName().empty())
1472 node
->AddAttribute(wxT("parstyle"), attr
.GetParagraphStyleName());
1474 if (!attr
.GetListStyleName().empty())
1475 node
->AddAttribute(wxT("liststyle"), attr
.GetListStyleName());
1477 if (!attr
.GetTextBoxAttr().GetBoxStyleName().empty())
1478 node
->AddAttribute(wxT("boxstyle"), attr
.GetTextBoxAttr().GetBoxStyleName());
1484 for (i
= 0; i
< attr
.GetTabs().GetCount(); i
++)
1488 tabs
<< attr
.GetTabs()[i
];
1490 node
->AddAttribute(wxT("tabs"), tabs
);
1493 if (attr
.HasPageBreak())
1494 node
->AddAttribute(wxT("pagebreak"), wxT("1"));
1496 if (attr
.HasOutlineLevel())
1497 node
->AddAttribute(wxT("outlinelevel"), MakeString((int) attr
.GetOutlineLevel()));
1500 AddAttribute(node
, wxT("margin"), attr
.GetTextBoxAttr().GetMargins());
1501 AddAttribute(node
, wxT("padding"), attr
.GetTextBoxAttr().GetPadding());
1502 AddAttribute(node
, wxT("position"), attr
.GetTextBoxAttr().GetPosition());
1503 AddAttribute(node
, wxT("border"), attr
.GetTextBoxAttr().GetBorder());
1504 AddAttribute(node
, wxT("outline"), attr
.GetTextBoxAttr().GetOutline());
1505 AddAttribute(node
, wxT("width"), attr
.GetTextBoxAttr().GetWidth());
1506 AddAttribute(node
, wxT("height"), attr
.GetTextBoxAttr().GetHeight());
1507 AddAttribute(node
, wxT("minwidth"), attr
.GetTextBoxAttr().GetMinSize().GetWidth());
1508 AddAttribute(node
, wxT("minheight"), attr
.GetTextBoxAttr().GetMinSize().GetHeight());
1509 AddAttribute(node
, wxT("maxwidth"), attr
.GetTextBoxAttr().GetMaxSize().GetWidth());
1510 AddAttribute(node
, wxT("maxheight"), attr
.GetTextBoxAttr().GetMaxSize().GetHeight());
1512 if (attr
.GetTextBoxAttr().HasVerticalAlignment())
1515 if (attr
.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP
)
1517 else if (attr
.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE
)
1518 value
= wxT("centre");
1519 else if (attr
.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM
)
1520 value
= wxT("bottom");
1522 value
= wxT("none");
1523 AddAttribute(node
, wxT("verticalalignment"), value
);
1526 if (attr
.GetTextBoxAttr().HasFloatMode())
1529 if (attr
.GetTextBoxAttr().GetFloatMode() == wxTEXT_BOX_ATTR_FLOAT_LEFT
)
1530 value
= wxT("left");
1531 else if (attr
.GetTextBoxAttr().GetFloatMode() == wxTEXT_BOX_ATTR_FLOAT_RIGHT
)
1532 value
= wxT("right");
1534 value
= wxT("none");
1535 AddAttribute(node
, wxT("float"), value
);
1538 if (attr
.GetTextBoxAttr().HasClearMode())
1541 if (attr
.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_LEFT
)
1542 value
= wxT("left");
1543 else if (attr
.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_RIGHT
)
1544 value
= wxT("right");
1545 else if (attr
.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_BOTH
)
1546 value
= wxT("both");
1548 value
= wxT("none");
1549 AddAttribute(node
, wxT("clear"), value
);
1552 if (attr
.GetTextBoxAttr().HasCollapseBorders())
1553 AddAttribute(node
, wxT("collapse-borders"), (int) attr
.GetTextBoxAttr().GetCollapseBorders());
1558 bool wxRichTextXMLHandler::WriteProperties(wxXmlNode
* node
, const wxRichTextProperties
& properties
)
1560 if (properties
.GetCount() > 0)
1562 wxXmlNode
* propertiesNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("properties"));
1563 node
->AddChild(propertiesNode
);
1565 for (i
= 0; i
< properties
.GetCount(); i
++)
1567 const wxVariant
& var
= properties
[i
];
1570 wxXmlNode
* propertyNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("property"));
1571 propertiesNode
->AddChild(propertyNode
);
1573 const wxString
& name
= var
.GetName();
1574 wxString value
= MakeStringFromProperty(var
);
1576 AddAttribute(propertyNode
, wxT("name"), name
);
1577 AddAttribute(propertyNode
, wxT("type"), var
.GetType());
1578 AddAttribute(propertyNode
, wxT("value"), value
);
1586 // wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
1588 /// Replace face name with current name for platform.
1589 /// TODO: introduce a virtual function or settable table to
1590 /// do this comprehensively.
1591 bool wxRichTextFixFaceName(wxString
& facename
)
1593 if (facename
.empty())
1597 if (facename
== wxT("Times"))
1599 facename
= wxT("Times New Roman");
1602 else if (facename
== wxT("Helvetica"))
1604 facename
= wxT("Arial");
1607 else if (facename
== wxT("Courier"))
1609 facename
= wxT("Courier New");
1615 if (facename
== wxT("Times New Roman"))
1617 facename
= wxT("Times");
1620 else if (facename
== wxT("Arial"))
1622 facename
= wxT("Helvetica");
1625 else if (facename
== wxT("Courier New"))
1627 facename
= wxT("Courier");
1635 static inline long wxRichTextColourStringToLong(const wxString
& colStr
)
1637 if (!colStr
.IsEmpty())
1639 wxColour
col(colStr
);
1640 return col
.GetRGB();
1646 static inline wxTextAttrDimension
wxRichTextParseDimension(const wxString
& dimStr
)
1648 wxString valuePart
= dimStr
.BeforeFirst(wxT(','));
1650 if (dimStr
.Contains(wxT(",")))
1651 flagsPart
= dimStr
.AfterFirst(wxT(','));
1652 wxTextAttrDimension dim
;
1653 dim
.SetValue(wxAtoi(valuePart
));
1654 dim
.SetFlags(wxAtoi(flagsPart
));
1659 /// Import style parameters
1660 bool wxRichTextXMLHandler::ImportStyle(wxRichTextAttr
& attr
, wxXmlNode
* node
, bool isPara
)
1662 wxXmlAttribute
* xmlAttr
= node
->GetAttributes();
1666 const wxString
& name
= xmlAttr
->GetName();
1667 const wxString
& value
= xmlAttr
->GetValue();
1670 if (name
== wxT("fontface"))
1675 if (GetFlags() & wxRICHTEXT_HANDLER_CONVERT_FACENAMES
)
1676 wxRichTextFixFaceName(v
);
1677 attr
.SetFontFaceName(v
);
1680 else if (name
== wxT("fontfamily"))
1683 attr
.SetFontFamily((wxFontFamily
)wxAtoi(value
));
1685 else if (name
== wxT("fontstyle"))
1688 attr
.SetFontStyle((wxFontStyle
)wxAtoi(value
));
1690 else if (name
== wxT("fontsize") || name
== wxT("fontpointsize"))
1693 attr
.SetFontPointSize(wxAtoi(value
));
1695 else if (name
== wxT("fontpixelsize"))
1698 attr
.SetFontPixelSize(wxAtoi(value
));
1700 else if (name
== wxT("fontweight"))
1703 attr
.SetFontWeight((wxFontWeight
) wxAtoi(value
));
1705 else if (name
== wxT("fontunderlined"))
1708 attr
.SetFontUnderlined(wxAtoi(value
) != 0);
1710 else if (name
== wxT("textcolor"))
1714 if (value
[0] == wxT('#'))
1715 attr
.SetTextColour(HexStringToColour(value
.Mid(1)));
1717 attr
.SetTextColour(value
);
1720 else if (name
== wxT("bgcolor"))
1724 if (value
[0] == wxT('#'))
1725 attr
.SetBackgroundColour(HexStringToColour(value
.Mid(1)));
1727 attr
.SetBackgroundColour(value
);
1730 else if (name
== wxT("characterstyle"))
1733 attr
.SetCharacterStyleName(value
);
1735 else if (name
== wxT("texteffects"))
1738 attr
.SetTextEffects(wxAtoi(value
));
1740 else if (name
== wxT("texteffectflags"))
1743 attr
.SetTextEffectFlags(wxAtoi(value
));
1745 else if (name
== wxT("url"))
1752 if (name
== wxT("alignment"))
1755 attr
.SetAlignment((wxTextAttrAlignment
) wxAtoi(value
));
1757 else if (name
== wxT("leftindent"))
1760 attr
.SetLeftIndent(wxAtoi(value
), attr
.GetLeftSubIndent());
1762 else if (name
== wxT("leftsubindent"))
1765 attr
.SetLeftIndent(attr
.GetLeftIndent(), wxAtoi(value
));
1767 else if (name
== wxT("rightindent"))
1770 attr
.SetRightIndent(wxAtoi(value
));
1772 else if (name
== wxT("parspacingbefore"))
1775 attr
.SetParagraphSpacingBefore(wxAtoi(value
));
1777 else if (name
== wxT("parspacingafter"))
1780 attr
.SetParagraphSpacingAfter(wxAtoi(value
));
1782 else if (name
== wxT("linespacing"))
1785 attr
.SetLineSpacing(wxAtoi(value
));
1787 else if (name
== wxT("bulletstyle"))
1790 attr
.SetBulletStyle(wxAtoi(value
));
1792 else if (name
== wxT("bulletnumber"))
1795 attr
.SetBulletNumber(wxAtoi(value
));
1797 else if (name
== wxT("bulletsymbol"))
1801 wxChar ch
= wxAtoi(value
);
1804 attr
.SetBulletText(s
);
1807 else if (name
== wxT("bullettext"))
1811 attr
.SetBulletText(value
);
1814 else if (name
== wxT("bulletfont"))
1818 attr
.SetBulletFont(value
);
1821 else if (name
== wxT("bulletname"))
1825 attr
.SetBulletName(value
);
1828 else if (name
== wxT("parstyle"))
1832 attr
.SetParagraphStyleName(value
);
1835 else if (name
== wxT("liststyle"))
1839 attr
.SetListStyleName(value
);
1842 else if (name
== wxT("boxstyle"))
1846 attr
.GetTextBoxAttr().SetBoxStyleName(value
);
1849 else if (name
== wxT("tabs"))
1854 wxStringTokenizer
tkz(value
, wxT(","));
1855 while (tkz
.HasMoreTokens())
1857 wxString token
= tkz
.GetNextToken();
1858 tabs
.Add(wxAtoi(token
));
1863 else if (name
== wxT("pagebreak"))
1867 attr
.SetPageBreak(wxAtoi(value
) != 0);
1870 else if (name
== wxT("outlinelevel"))
1874 attr
.SetOutlineLevel(wxAtoi(value
));
1887 if (name
== wxT("width"))
1889 attr
.GetTextBoxAttr().GetWidth().SetValue(wxRichTextParseDimension(value
));
1891 else if (name
== wxT("height"))
1893 attr
.GetTextBoxAttr().GetHeight().SetValue(wxRichTextParseDimension(value
));
1895 else if (name
== wxT("minwidth"))
1897 attr
.GetTextBoxAttr().GetMinSize().GetWidth().SetValue(wxRichTextParseDimension(value
));
1899 else if (name
== wxT("minheight"))
1901 attr
.GetTextBoxAttr().GetMinSize().GetHeight().SetValue(wxRichTextParseDimension(value
));
1903 else if (name
== wxT("maxwidth"))
1905 attr
.GetTextBoxAttr().GetMaxSize().GetWidth().SetValue(wxRichTextParseDimension(value
));
1907 else if (name
== wxT("maxheight"))
1909 attr
.GetTextBoxAttr().GetMaxSize().GetHeight().SetValue(wxRichTextParseDimension(value
));
1912 else if (name
== wxT("verticalalignment"))
1914 if (value
== wxT("top"))
1915 attr
.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP
);
1916 else if (value
== wxT("centre"))
1917 attr
.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE
);
1918 else if (value
== wxT("bottom"))
1919 attr
.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM
);
1920 else if (value
== wxT("none"))
1921 attr
.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_NONE
);
1923 else if (name
== wxT("float"))
1925 if (value
== wxT("left"))
1926 attr
.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_LEFT
);
1927 else if (value
== wxT("right"))
1928 attr
.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_RIGHT
);
1929 else if (value
== wxT("none"))
1930 attr
.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_NONE
);
1932 else if (name
== wxT("clear"))
1934 if (value
== wxT("left"))
1935 attr
.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_LEFT
);
1936 else if (value
== wxT("right"))
1937 attr
.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_RIGHT
);
1938 else if (value
== wxT("both"))
1939 attr
.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_BOTH
);
1940 else if (value
== wxT("none"))
1941 attr
.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_NONE
);
1943 else if (name
== wxT("collapse-borders"))
1944 attr
.GetTextBoxAttr().SetCollapseBorders((wxTextBoxAttrCollapseMode
) wxAtoi(value
));
1946 else if (name
.Contains(wxT("border-")))
1948 if (name
== wxT("border-left-style"))
1949 attr
.GetTextBoxAttr().GetBorder().GetLeft().SetStyle(wxAtoi(value
));
1950 else if (name
== wxT("border-right-style"))
1951 attr
.GetTextBoxAttr().GetBorder().GetRight().SetStyle(wxAtoi(value
));
1952 else if (name
== wxT("border-top-style"))
1953 attr
.GetTextBoxAttr().GetBorder().GetTop().SetStyle(wxAtoi(value
));
1954 else if (name
== wxT("border-bottom-style"))
1955 attr
.GetTextBoxAttr().GetBorder().GetBottom().SetStyle(wxAtoi(value
));
1957 else if (name
== wxT("border-left-colour"))
1958 attr
.GetTextBoxAttr().GetBorder().GetLeft().SetColour(wxRichTextColourStringToLong(value
));
1959 else if (name
== wxT("border-right-colour"))
1960 attr
.GetTextBoxAttr().GetBorder().GetRight().SetColour(wxRichTextColourStringToLong(value
));
1961 else if (name
== wxT("border-top-colour"))
1962 attr
.GetTextBoxAttr().GetBorder().GetTop().SetColour(wxRichTextColourStringToLong(value
));
1963 else if (name
== wxT("border-bottom-colour"))
1964 attr
.GetTextBoxAttr().GetBorder().GetBottom().SetColour(wxRichTextColourStringToLong(value
));
1966 else if (name
== wxT("border-left-width"))
1967 attr
.GetTextBoxAttr().GetBorder().GetLeft().SetWidth(wxRichTextParseDimension(value
));
1968 else if (name
== wxT("border-right-width"))
1969 attr
.GetTextBoxAttr().GetBorder().GetRight().SetWidth(wxRichTextParseDimension(value
));
1970 else if (name
== wxT("border-top-width"))
1971 attr
.GetTextBoxAttr().GetBorder().GetTop().SetWidth(wxRichTextParseDimension(value
));
1972 else if (name
== wxT("border-bottom-width"))
1973 attr
.GetTextBoxAttr().GetBorder().GetBottom().SetWidth(wxRichTextParseDimension(value
));
1975 else if (name
.Contains(wxT("outline-")))
1977 if (name
== wxT("outline-left-style"))
1978 attr
.GetTextBoxAttr().GetOutline().GetLeft().SetStyle(wxAtoi(value
));
1979 else if (name
== wxT("outline-right-style"))
1980 attr
.GetTextBoxAttr().GetOutline().GetRight().SetStyle(wxAtoi(value
));
1981 else if (name
== wxT("outline-top-style"))
1982 attr
.GetTextBoxAttr().GetOutline().GetTop().SetStyle(wxAtoi(value
));
1983 else if (name
== wxT("outline-bottom-style"))
1984 attr
.GetTextBoxAttr().GetOutline().GetBottom().SetStyle(wxAtoi(value
));
1986 else if (name
== wxT("outline-left-colour"))
1987 attr
.GetTextBoxAttr().GetOutline().GetLeft().SetColour(wxRichTextColourStringToLong(value
));
1988 else if (name
== wxT("outline-right-colour"))
1989 attr
.GetTextBoxAttr().GetOutline().GetRight().SetColour(wxRichTextColourStringToLong(value
));
1990 else if (name
== wxT("outline-top-colour"))
1991 attr
.GetTextBoxAttr().GetOutline().GetTop().SetColour(wxRichTextColourStringToLong(value
));
1992 else if (name
== wxT("outline-bottom-colour"))
1993 attr
.GetTextBoxAttr().GetOutline().GetBottom().SetColour(wxRichTextColourStringToLong(value
));
1995 else if (name
== wxT("outline-left-width"))
1996 attr
.GetTextBoxAttr().GetOutline().GetLeft().SetWidth(wxRichTextParseDimension(value
));
1997 else if (name
== wxT("outline-right-width"))
1998 attr
.GetTextBoxAttr().GetOutline().GetRight().SetWidth(wxRichTextParseDimension(value
));
1999 else if (name
== wxT("outline-top-width"))
2000 attr
.GetTextBoxAttr().GetOutline().GetTop().SetWidth(wxRichTextParseDimension(value
));
2001 else if (name
== wxT("outline-bottom-width"))
2002 attr
.GetTextBoxAttr().GetOutline().GetBottom().SetWidth(wxRichTextParseDimension(value
));
2004 else if (name
.Contains(wxT("margin-")))
2006 if (name
== wxT("margin-left"))
2007 attr
.GetTextBoxAttr().GetMargins().GetLeft().SetValue(wxRichTextParseDimension(value
));
2008 else if (name
== wxT("margin-right"))
2009 attr
.GetTextBoxAttr().GetMargins().GetRight().SetValue(wxRichTextParseDimension(value
));
2010 else if (name
== wxT("margin-top"))
2011 attr
.GetTextBoxAttr().GetMargins().GetTop().SetValue(wxRichTextParseDimension(value
));
2012 else if (name
== wxT("margin-bottom"))
2013 attr
.GetTextBoxAttr().GetMargins().GetBottom().SetValue(wxRichTextParseDimension(value
));
2015 else if (name
.Contains(wxT("padding-")))
2017 if (name
== wxT("padding-left"))
2018 attr
.GetTextBoxAttr().GetPadding().GetLeft().SetValue(wxRichTextParseDimension(value
));
2019 else if (name
== wxT("padding-right"))
2020 attr
.GetTextBoxAttr().GetPadding().GetRight().SetValue(wxRichTextParseDimension(value
));
2021 else if (name
== wxT("padding-top"))
2022 attr
.GetTextBoxAttr().GetPadding().GetTop().SetValue(wxRichTextParseDimension(value
));
2023 else if (name
== wxT("padding-bottom"))
2024 attr
.GetTextBoxAttr().GetPadding().GetBottom().SetValue(wxRichTextParseDimension(value
));
2026 else if (name
.Contains(wxT("position-")))
2028 if (name
== wxT("position-left"))
2029 attr
.GetTextBoxAttr().GetPosition().GetLeft().SetValue(wxRichTextParseDimension(value
));
2030 else if (name
== wxT("position-right"))
2031 attr
.GetTextBoxAttr().GetPosition().GetRight().SetValue(wxRichTextParseDimension(value
));
2032 else if (name
== wxT("position-top"))
2033 attr
.GetTextBoxAttr().GetPosition().GetTop().SetValue(wxRichTextParseDimension(value
));
2034 else if (name
== wxT("position-bottom"))
2035 attr
.GetTextBoxAttr().GetPosition().GetBottom().SetValue(wxRichTextParseDimension(value
));
2039 xmlAttr
= xmlAttr
->GetNext();
2048 // Import this object from XML
2049 bool wxRichTextObject::ImportFromXML(wxRichTextBuffer
* WXUNUSED(buffer
), wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
)
2051 handler
->ImportProperties(this, node
);
2052 handler
->ImportStyle(GetAttributes(), node
, UsesParagraphAttributes());
2059 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2060 // Export this object directly to the given stream.
2061 bool wxRichTextObject::ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
)
2063 ::OutputIndentation(stream
, indent
);
2064 ::OutputString(stream
, wxT("<") + GetXMLNodeName(), handler
->GetConvMem(), handler
->GetConvFile());
2066 wxString style
= handler
->AddAttributes(GetAttributes(), true);
2068 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2070 if (GetProperties().GetCount() > 0)
2072 handler
->WriteProperties(stream
, GetProperties(), indent
);
2075 wxRichTextCompositeObject
* composite
= wxDynamicCast(this, wxRichTextCompositeObject
);
2079 for (i
= 0; i
< composite
->GetChildCount(); i
++)
2081 wxRichTextObject
* child
= composite
->GetChild(i
);
2082 child
->ExportXML(stream
, indent
+1, handler
);
2086 ::OutputIndentation(stream
, indent
);
2087 ::OutputString(stream
, wxT("</") + GetXMLNodeName() + wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2092 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2093 // Export this object to the given parent node, usually creating at least one child node.
2094 bool wxRichTextObject::ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
)
2096 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, GetXMLNodeName());
2097 parent
->AddChild(elementNode
);
2098 handler
->AddAttributes(elementNode
, GetAttributes(), true);
2099 handler
->WriteProperties(elementNode
, GetProperties());
2101 wxRichTextCompositeObject
* composite
= wxDynamicCast(this, wxRichTextCompositeObject
);
2105 for (i
= 0; i
< composite
->GetChildCount(); i
++)
2107 wxRichTextObject
* child
= composite
->GetChild(i
);
2108 child
->ExportXML(elementNode
, handler
);
2116 // Import this object from XML
2117 bool wxRichTextPlainText::ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
)
2119 wxRichTextObject::ImportFromXML(buffer
, node
, handler
, recurse
);
2121 if (node
->GetName() == wxT("text"))
2124 wxXmlNode
* textChild
= node
->GetChildren();
2127 if (textChild
->GetType() == wxXML_TEXT_NODE
||
2128 textChild
->GetType() == wxXML_CDATA_SECTION_NODE
)
2130 wxString text2
= textChild
->GetContent();
2132 // Strip whitespace from end
2133 if (!text2
.empty() && text2
[text2
.length()-1] == wxT('\n'))
2134 text2
= text2
.Mid(0, text2
.length()-1);
2136 if (!text2
.empty() && text2
[0] == wxT('"'))
2137 text2
= text2
.Mid(1);
2138 if (!text2
.empty() && text2
[text2
.length()-1] == wxT('"'))
2139 text2
= text2
.Mid(0, text2
.length() - 1);
2143 textChild
= textChild
->GetNext();
2148 else if (node
->GetName() == wxT("symbol"))
2150 // This is a symbol that XML can't read in the normal way
2152 wxXmlNode
* textChild
= node
->GetChildren();
2155 if (textChild
->GetType() == wxXML_TEXT_NODE
||
2156 textChild
->GetType() == wxXML_CDATA_SECTION_NODE
)
2158 wxString text2
= textChild
->GetContent();
2161 textChild
= textChild
->GetNext();
2164 wxString actualText
;
2165 actualText
<< (wxChar
) wxAtoi(text
);
2166 SetText(actualText
);
2174 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2175 // Export this object directly to the given stream.
2176 bool wxRichTextPlainText::ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
)
2178 wxString style
= handler
->AddAttributes(GetAttributes(), false);
2182 const wxString
& text
= GetText();
2183 int len
= (int) text
.Length();
2188 ::OutputIndentation(stream
, indent
);
2189 ::OutputString(stream
, wxT("<text"), handler
->GetConvMem(), handler
->GetConvFile());
2190 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2191 if (GetProperties().GetCount() > 0)
2193 handler
->WriteProperties(stream
, GetProperties(), indent
);
2194 ::OutputIndentation(stream
, indent
);
2196 ::OutputString(stream
, wxT("</text>"), handler
->GetConvMem(), handler
->GetConvFile());
2198 else for (i
= 0; i
< len
; i
++)
2201 int c
= (int) text
[i
];
2203 int c
= (int) wxUChar(text
[i
]);
2205 if ((c
< 32 || c
== 34) && /* c != 9 && */ c
!= 10 && c
!= 13)
2209 wxString
fragment(text
.Mid(last
, i
-last
));
2210 if (!fragment
.empty())
2212 ::OutputIndentation(stream
, indent
);
2213 ::OutputString(stream
, wxT("<text"), handler
->GetConvMem(), handler
->GetConvFile());
2215 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2217 if (!fragment
.empty() && (fragment
[0] == wxT(' ') || fragment
[fragment
.length()-1] == wxT(' ')))
2219 ::OutputString(stream
, wxT("\""), handler
->GetConvMem(), handler
->GetConvFile());
2220 ::OutputStringEnt(stream
, fragment
, handler
->GetConvMem(), handler
->GetConvFile());
2221 ::OutputString(stream
, wxT("\""), handler
->GetConvMem(), handler
->GetConvFile());
2224 ::OutputStringEnt(stream
, fragment
, handler
->GetConvMem(), handler
->GetConvFile());
2226 if (GetProperties().GetCount() > 0)
2228 handler
->WriteProperties(stream
, GetProperties(), indent
);
2229 ::OutputIndentation(stream
, indent
);
2231 ::OutputString(stream
, wxT("</text>"), handler
->GetConvMem(), handler
->GetConvFile());
2236 // Output this character as a number in a separate tag, because XML can't cope
2237 // with entities below 32 except for 10 and 13
2239 ::OutputIndentation(stream
, indent
);
2240 ::OutputString(stream
, wxT("<symbol"), handler
->GetConvMem(), handler
->GetConvFile());
2242 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2243 ::OutputString(stream
, wxString::Format(wxT("%d"), c
), handler
->GetConvMem(), handler
->GetConvFile());
2245 if (GetProperties().GetCount() > 0)
2247 handler
->WriteProperties(stream
, GetProperties(), indent
);
2248 ::OutputIndentation(stream
, indent
);
2250 ::OutputString(stream
, wxT("</symbol>"), handler
->GetConvMem(), handler
->GetConvFile());
2258 fragment
= text
.Mid(last
, i
-last
);
2262 ::OutputIndentation(stream
, indent
);
2263 ::OutputString(stream
, wxT("<text"), handler
->GetConvMem(), handler
->GetConvFile());
2265 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2267 if (GetProperties().GetCount() > 0)
2269 handler
->WriteProperties(stream
, GetProperties(), indent
);
2270 ::OutputIndentation(stream
, indent
);
2273 if (!fragment
.empty() && (fragment
[0] == wxT(' ') || fragment
[fragment
.length()-1] == wxT(' ')))
2275 ::OutputString(stream
, wxT("\""), handler
->GetConvMem(), handler
->GetConvFile());
2276 ::OutputStringEnt(stream
, fragment
, handler
->GetConvMem(), handler
->GetConvFile());
2277 ::OutputString(stream
, wxT("\""), handler
->GetConvMem(), handler
->GetConvFile());
2280 ::OutputStringEnt(stream
, fragment
, handler
->GetConvMem(), handler
->GetConvFile());
2282 ::OutputString(stream
, wxT("</text>"), handler
->GetConvMem(), handler
->GetConvFile());
2288 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2289 // Export this object to the given parent node, usually creating at least one child node.
2290 bool wxRichTextPlainText::ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
)
2294 const wxString
& text
= GetText();
2295 int len
= (int) text
.Length();
2301 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("text"));
2302 parent
->AddChild(elementNode
);
2304 handler
->AddAttributes(elementNode
, GetAttributes(), false);
2305 handler
->WriteProperties(elementNode
, GetProperties());
2307 else for (i
= 0; i
< len
; i
++)
2310 int c
= (int) text
[i
];
2312 int c
= (int) wxUChar(text
[i
]);
2314 if ((c
< 32 || c
== 34) && c
!= 10 && c
!= 13)
2318 wxString
fragment(text
.Mid(last
, i
-last
));
2319 if (!fragment
.empty())
2321 // TODO: I'm assuming wxXmlDocument will output quotes if necessary
2322 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("text"));
2323 parent
->AddChild(elementNode
);
2324 handler
->AddAttributes(elementNode
, GetAttributes(), false);
2325 handler
->WriteProperties(elementNode
, GetProperties());
2327 wxXmlNode
* textNode
= new wxXmlNode(wxXML_TEXT_NODE
, wxT("text"));
2328 elementNode
->AddChild(textNode
);
2330 if (fragment
[0] == wxT(' ') || fragment
[fragment
.length()-1] == wxT(' '))
2331 fragment
= wxT("\"") + fragment
+ wxT("\"");
2333 textNode
->SetContent(fragment
);
2338 // Output this character as a number in a separate tag, because XML can't cope
2339 // with entities below 32 except for 10 and 13
2341 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("symbol"));
2342 parent
->AddChild(elementNode
);
2344 handler
->AddAttributes(elementNode
, GetAttributes(), false);
2345 handler
->WriteProperties(elementNode
, GetProperties());
2347 wxXmlNode
* textNode
= new wxXmlNode(wxXML_TEXT_NODE
, wxT("text"));
2348 elementNode
->AddChild(textNode
);
2349 textNode
->SetContent(wxString::Format(wxT("%d"), c
));
2359 fragment
= text
.Mid(last
, i
-last
);
2363 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("text"));
2364 parent
->AddChild(elementNode
);
2365 handler
->AddAttributes(elementNode
, GetAttributes(), false);
2367 wxXmlNode
* textNode
= new wxXmlNode(wxXML_TEXT_NODE
, wxT("text"));
2368 elementNode
->AddChild(textNode
);
2370 if (fragment
[0] == wxT(' ') || fragment
[fragment
.length()-1] == wxT(' '))
2371 fragment
= wxT("\"") + fragment
+ wxT("\"");
2373 textNode
->SetContent(fragment
);
2380 // Import this object from XML
2381 bool wxRichTextImage::ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
)
2383 wxRichTextObject::ImportFromXML(buffer
, node
, handler
, recurse
);
2385 wxBitmapType imageType
= wxBITMAP_TYPE_PNG
;
2386 wxString value
= node
->GetAttribute(wxT("imagetype"), wxEmptyString
);
2389 int type
= wxAtoi(value
);
2391 // note: 0 == wxBITMAP_TYPE_INVALID
2392 if (type
<= 0 || type
>= wxBITMAP_TYPE_MAX
)
2394 wxLogWarning("Invalid bitmap type specified for <image> tag: %d", type
);
2398 imageType
= (wxBitmapType
)type
;
2404 wxXmlNode
* imageChild
= node
->GetChildren();
2407 wxString childName
= imageChild
->GetName();
2408 if (childName
== wxT("data"))
2410 wxXmlNode
* dataChild
= imageChild
->GetChildren();
2413 data
= dataChild
->GetContent();
2414 // wxLogDebug(data);
2415 dataChild
= dataChild
->GetNext();
2419 imageChild
= imageChild
->GetNext();
2424 wxStringInputStream
strStream(data
);
2426 GetImageBlock().ReadHex(strStream
, data
.length(), imageType
);
2434 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2435 // Export this object directly to the given stream.
2436 bool wxRichTextImage::ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
)
2438 wxString style
= handler
->AddAttributes(GetAttributes(), false);
2440 ::OutputIndentation(stream
, indent
);
2441 ::OutputString(stream
, wxT("<image"), handler
->GetConvMem(), handler
->GetConvFile());
2442 if (!GetImageBlock().IsOk())
2445 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2449 ::OutputString(stream
, wxString::Format(wxT(" imagetype=\"%d\""), (int) GetImageBlock().GetImageType()) + style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2451 if (GetProperties().GetCount() > 0)
2453 handler
->WriteProperties(stream
, GetProperties(), indent
);
2454 ::OutputIndentation(stream
, indent
);
2457 ::OutputIndentation(stream
, indent
+1);
2458 ::OutputString(stream
, wxT("<data>"), handler
->GetConvMem(), handler
->GetConvFile());
2460 // wxStopWatch stopwatch;
2462 GetImageBlock().WriteHex(stream
);
2464 // wxLogDebug(wxT("Image conversion to hex took %ldms"), stopwatch.Time());
2466 ::OutputString(stream
, wxT("</data>\n"), handler
->GetConvMem(), handler
->GetConvFile());
2467 ::OutputIndentation(stream
, indent
);
2468 ::OutputString(stream
, wxT("</image>"), handler
->GetConvMem(), handler
->GetConvFile());
2473 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2474 // Export this object to the given parent node, usually creating at least one child node.
2475 bool wxRichTextImage::ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
)
2477 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("image"));
2478 parent
->AddChild(elementNode
);
2480 if (GetImageBlock().IsOk())
2481 elementNode
->AddAttribute(wxT("imagetype"), MakeString((int) GetImageBlock().GetImageType()));
2483 handler
->AddAttributes(elementNode
, GetAttributes(), false);
2484 handler
->WriteProperties(elementNode
, GetProperties());
2486 wxXmlNode
* dataNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, wxT("data"));
2487 elementNode
->AddChild(dataNode
);
2488 wxXmlNode
* textNode
= new wxXmlNode(wxXML_TEXT_NODE
, wxT("text"));
2489 dataNode
->AddChild(textNode
);
2494 wxMemoryOutputStream stream
;
2495 if (GetImageBlock().WriteHex(stream
))
2497 if (stream
.GetSize() > 0)
2499 int size
= stream
.GetSize();
2501 int size2
= stream
.GetOutputStreamBuffer()->GetIntPosition();
2502 wxASSERT(size
== size2
);
2504 unsigned char* data
= new unsigned char[size
];
2505 stream
.CopyTo(data
, size
);
2506 strData
= wxString((const char*) data
, wxConvUTF8
, size
);
2510 strData
= wxEmptyString
;
2516 wxStringOutputStream
strStream(& strData
);
2517 GetImageBlock().WriteHex(strStream
);
2521 textNode
->SetContent(strData
);
2522 textNode
->SetNoConversion(true); // optimize speed
2529 // Import this object from XML
2530 bool wxRichTextParagraphLayoutBox::ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
)
2532 wxRichTextObject::ImportFromXML(buffer
, node
, handler
, recurse
);
2536 wxString partial
= node
->GetAttribute(wxT("partialparagraph"), wxEmptyString
);
2537 if (partial
== wxT("true"))
2538 SetPartialParagraph(true);
2540 wxXmlNode
* child
= wxRichTextXMLHandler::FindNode(node
, wxT("stylesheet"));
2541 if (child
&& (handler
->GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET
))
2543 wxRichTextStyleSheet
* sheet
= new wxRichTextStyleSheet
;
2544 wxString sheetName
= child
->GetAttribute(wxT("name"), wxEmptyString
);
2545 wxString sheetDescription
= child
->GetAttribute(wxT("description"), wxEmptyString
);
2546 sheet
->SetName(sheetName
);
2547 sheet
->SetDescription(sheetDescription
);
2549 wxXmlNode
* child2
= child
->GetChildren();
2552 handler
->ImportStyleDefinition(sheet
, child2
);
2554 child2
= child2
->GetNext();
2556 handler
->ImportProperties(sheet
->GetProperties(), child
);
2558 // Notify that styles have changed. If this is vetoed by the app,
2559 // the new sheet will be deleted. If it is not vetoed, the
2560 // old sheet will be deleted and replaced with the new one.
2561 buffer
->SetStyleSheetAndNotify(sheet
);
2567 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2568 // Export this object directly to the given stream.
2569 bool wxRichTextParagraphLayoutBox::ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
)
2571 ::OutputIndentation(stream
, indent
);
2572 wxString nodeName
= GetXMLNodeName();
2573 ::OutputString(stream
, wxT("<") + nodeName
, handler
->GetConvMem(), handler
->GetConvFile());
2575 wxString style
= handler
->AddAttributes(GetAttributes(), true);
2577 if (GetPartialParagraph())
2578 style
<< wxT(" partialparagraph=\"true\"");
2580 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2582 if (GetProperties().GetCount() > 0)
2584 handler
->WriteProperties(stream
, GetProperties(), indent
);
2588 for (i
= 0; i
< GetChildCount(); i
++)
2590 wxRichTextObject
* child
= GetChild(i
);
2591 child
->ExportXML(stream
, indent
+1, handler
);
2594 ::OutputIndentation(stream
, indent
);
2595 ::OutputString(stream
, wxT("</") + nodeName
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2600 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2601 // Export this object to the given parent node, usually creating at least one child node.
2602 bool wxRichTextParagraphLayoutBox::ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
)
2604 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, GetXMLNodeName());
2605 parent
->AddChild(elementNode
);
2606 handler
->AddAttributes(elementNode
, GetAttributes(), true);
2607 handler
->WriteProperties(elementNode
, GetProperties());
2609 if (GetPartialParagraph())
2610 elementNode
->AddAttribute(wxT("partialparagraph"), wxT("true"));
2613 for (i
= 0; i
< GetChildCount(); i
++)
2615 wxRichTextObject
* child
= GetChild(i
);
2616 child
->ExportXML(elementNode
, handler
);
2623 // Import this object from XML
2624 bool wxRichTextTable::ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
)
2626 wxRichTextBox::ImportFromXML(buffer
, node
, handler
, recurse
);
2630 m_rowCount
= wxAtoi(node
->GetAttribute(wxT("rows"), wxEmptyString
));
2631 m_colCount
= wxAtoi(node
->GetAttribute(wxT("cols"), wxEmptyString
));
2633 wxXmlNode
* child
= node
->GetChildren();
2636 wxRichTextObject
* childObj
= handler
->CreateObjectForXMLName(this, child
->GetName());
2639 AppendChild(childObj
);
2640 handler
->ImportXML(buffer
, childObj
, child
);
2642 child
= child
->GetNext();
2645 m_cells
.Add(wxRichTextObjectPtrArray(), m_rowCount
);
2647 for (i
= 0; i
< m_rowCount
; i
++)
2649 wxRichTextObjectPtrArray
& colArray
= m_cells
[i
];
2650 for (j
= 0; j
< m_colCount
; j
++)
2652 int idx
= i
* m_colCount
+ j
;
2653 if (idx
< (int) GetChildren().GetCount())
2655 wxRichTextCell
* cell
= wxDynamicCast(GetChildren().Item(idx
)->GetData(), wxRichTextCell
);
2665 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2666 // Export this object directly to the given stream.
2667 bool wxRichTextTable::ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
)
2669 ::OutputIndentation(stream
, indent
);
2670 wxString nodeName
= GetXMLNodeName();
2671 ::OutputString(stream
, wxT("<") + nodeName
, handler
->GetConvMem(), handler
->GetConvFile());
2673 wxString style
= handler
->AddAttributes(GetAttributes(), true);
2675 style
<< wxT(" rows=\"") << m_rowCount
<< wxT("\"");
2676 style
<< wxT(" cols=\"") << m_colCount
<< wxT("\"");
2678 ::OutputString(stream
, style
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2680 if (GetProperties().GetCount() > 0)
2682 handler
->WriteProperties(stream
, GetProperties(), indent
);
2686 for (i
= 0; i
< m_rowCount
; i
++)
2688 for (j
= 0; j
< m_colCount
; j
++)
2690 wxRichTextCell
* cell
= GetCell(i
, j
);
2691 cell
->ExportXML(stream
, indent
+1, handler
);
2695 ::OutputIndentation(stream
, indent
);
2696 ::OutputString(stream
, wxT("</") + nodeName
+ wxT(">"), handler
->GetConvMem(), handler
->GetConvFile());
2702 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2703 // Export this object to the given parent node, usually creating at least one child node.
2704 bool wxRichTextTable::ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
)
2706 wxXmlNode
* elementNode
= new wxXmlNode(wxXML_ELEMENT_NODE
, GetXMLNodeName());
2707 parent
->AddChild(elementNode
);
2708 handler
->AddAttributes(elementNode
, GetAttributes(), true);
2709 handler
->WriteProperties(elementNode
, GetProperties());
2711 elementNode
->AddAttribute(wxT("rows"), wxString::Format(wxT("%d"), m_rowCount
));
2712 elementNode
->AddAttribute(wxT("cols"), wxString::Format(wxT("%d"), m_colCount
));
2715 for (i
= 0; i
< m_rowCount
; i
++)
2717 for (j
= 0; j
< m_colCount
; j
++)
2719 wxRichTextCell
* cell
= GetCell(i
, j
);
2720 cell
->ExportXML(elementNode
, handler
);
2730 // wxUSE_RICHTEXT && wxUSE_XML