]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtextxml.cpp
wxSizer::Fit() now sets client size
[wxWidgets.git] / src / richtext / richtextxml.cpp
CommitLineData
5d7836c4 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/richtext/richtextxml.cpp
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// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
61399247 16 #pragma hdrstop
5d7836c4
JS
17#endif
18
fcdbeefa 19#if wxUSE_RICHTEXT && wxUSE_XML
b01ca8b6
JS
20
21#include "wx/richtext/richtextxml.h"
22
5d7836c4 23#ifndef WX_PRECOMP
88a7a4e1 24 #include "wx/intl.h"
02761f6c 25 #include "wx/module.h"
5d7836c4
JS
26#endif
27
5d7836c4
JS
28#include "wx/filename.h"
29#include "wx/clipbrd.h"
30#include "wx/wfstream.h"
31#include "wx/sstream.h"
5d7836c4 32#include "wx/txtstrm.h"
0ca07313 33#include "wx/tokenzr.h"
5d7836c4
JS
34#include "wx/xml/xml.h"
35
5d7836c4
JS
36IMPLEMENT_DYNAMIC_CLASS(wxRichTextXMLHandler, wxRichTextFileHandler)
37
38#if wxUSE_STREAMS
7fe8059f 39bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
5d7836c4
JS
40{
41 if (!stream.IsOk())
42 return false;
43
85d8909b 44 buffer->ResetAndClearCommands();
42688aea 45 buffer->Clear();
5d7836c4
JS
46
47 wxXmlDocument* xmlDoc = new wxXmlDocument;
48 bool success = true;
49
b71e9aa4
JS
50 // This is the encoding to convert to (memory encoding rather than file encoding)
51 wxString encoding(wxT("UTF-8"));
52
53#if !wxUSE_UNICODE && wxUSE_INTL
54 encoding = wxLocale::GetSystemEncodingName();
55#endif
56
57 if (!xmlDoc->Load(stream, encoding))
5d7836c4 58 {
42688aea 59 buffer->ResetAndClearCommands();
5d7836c4
JS
60 success = false;
61 }
62 else
63 {
64 if (xmlDoc->GetRoot() && xmlDoc->GetRoot()->GetType() == wxXML_ELEMENT_NODE && xmlDoc->GetRoot()->GetName() == wxT("richtext"))
65 {
66 wxXmlNode* child = xmlDoc->GetRoot()->GetChildren();
67 while (child)
68 {
69 if (child->GetType() == wxXML_ELEMENT_NODE)
70 {
71 wxString name = child->GetName();
72 if (name == wxT("richtext-version"))
73 {
74 }
75 else
76 ImportXML(buffer, child);
77 }
7fe8059f 78
5d7836c4
JS
79 child = child->GetNext();
80 }
81 }
82 else
83 {
84 success = false;
85 }
86 }
7fe8059f 87
5d7836c4
JS
88 delete xmlDoc;
89
90 buffer->UpdateRanges();
91
92 return success;
93}
94
95/// Recursively import an object
96bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node)
97{
98 wxString name = node->GetName();
99
100 bool doneChildren = false;
101
102 if (name == wxT("paragraphlayout"))
103 {
288b6107 104 wxString partial = node->GetAttribute(wxT("partialparagraph"), wxEmptyString);
0ca07313
JS
105 if (partial == wxT("true"))
106 buffer->SetPartialParagraph(true);
5d7836c4
JS
107 }
108 else if (name == wxT("paragraph"))
109 {
110 wxRichTextParagraph* para = new wxRichTextParagraph(buffer);
111 buffer->AppendChild(para);
112
113 GetStyle(para->GetAttributes(), node, true);
114
115 wxXmlNode* child = node->GetChildren();
116 while (child)
117 {
118 wxString childName = child->GetName();
119 if (childName == wxT("text"))
120 {
121 wxString text;
122 wxXmlNode* textChild = child->GetChildren();
123 while (textChild)
124 {
125 if (textChild->GetType() == wxXML_TEXT_NODE ||
126 textChild->GetType() == wxXML_CDATA_SECTION_NODE)
127 {
128 wxString text2 = textChild->GetContent();
129
130 // Strip whitespace from end
88a7a4e1
WS
131 if (!text2.empty() && text2[text2.length()-1] == wxT('\n'))
132 text2 = text2.Mid(0, text2.length()-1);
5d7836c4 133
88a7a4e1 134 if (!text2.empty() && text2[0] == wxT('"'))
5d7836c4 135 text2 = text2.Mid(1);
88a7a4e1
WS
136 if (!text2.empty() && text2[text2.length()-1] == wxT('"'))
137 text2 = text2.Mid(0, text2.length() - 1);
5d7836c4 138
5d7836c4
JS
139 text += text2;
140 }
141 textChild = textChild->GetNext();
142 }
143
144 wxRichTextPlainText* textObject = new wxRichTextPlainText(text, para);
145 GetStyle(textObject->GetAttributes(), child, false);
146
147 para->AppendChild(textObject);
148 }
7b907278
JS
149 else if (childName == wxT("symbol"))
150 {
151 // This is a symbol that XML can't read in the normal way
152 wxString text;
153 wxXmlNode* textChild = child->GetChildren();
154 while (textChild)
155 {
156 if (textChild->GetType() == wxXML_TEXT_NODE ||
157 textChild->GetType() == wxXML_CDATA_SECTION_NODE)
158 {
159 wxString text2 = textChild->GetContent();
160 text += text2;
161 }
162 textChild = textChild->GetNext();
163 }
87eaa6f6 164
7b907278
JS
165 wxString actualText;
166 actualText << (wxChar) wxAtoi(text);
167
168 wxRichTextPlainText* textObject = new wxRichTextPlainText(actualText, para);
169 GetStyle(textObject->GetAttributes(), child, false);
170
171 para->AppendChild(textObject);
172 }
5d7836c4
JS
173 else if (childName == wxT("image"))
174 {
175 int imageType = wxBITMAP_TYPE_PNG;
288b6107 176 wxString value = node->GetAttribute(wxT("imagetype"), wxEmptyString);
7fe8059f 177 if (!value.empty())
5d7836c4
JS
178 imageType = wxAtoi(value);
179
180 wxString data;
181
182 wxXmlNode* imageChild = child->GetChildren();
183 while (imageChild)
184 {
185 wxString childName = imageChild->GetName();
186 if (childName == wxT("data"))
187 {
188 wxXmlNode* dataChild = imageChild->GetChildren();
189 while (dataChild)
190 {
191 data = dataChild->GetContent();
192 // wxLogDebug(data);
193 dataChild = dataChild->GetNext();
194 }
7fe8059f 195
5d7836c4
JS
196 }
197 imageChild = imageChild->GetNext();
198 }
199
7fe8059f 200 if (!data.empty())
5d7836c4
JS
201 {
202 wxRichTextImage* imageObj = new wxRichTextImage(para);
203 para->AppendChild(imageObj);
204
205 wxStringInputStream strStream(data);
206
88a7a4e1 207 imageObj->GetImageBlock().ReadHex(strStream, data.length(), imageType);
5d7836c4
JS
208 }
209 }
210 child = child->GetNext();
211 }
212
213 doneChildren = true;
214 }
d2d0adc7
JS
215 else if (name == wxT("stylesheet"))
216 {
217 if (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET)
218 {
219 wxRichTextStyleSheet* sheet = new wxRichTextStyleSheet;
288b6107
VS
220 wxString sheetName = node->GetAttribute(wxT("name"), wxEmptyString);
221 wxString sheetDescription = node->GetAttribute(wxT("description"), wxEmptyString);
42688aea
JS
222 sheet->SetName(sheetName);
223 sheet->SetDescription(sheetDescription);
87eaa6f6 224
d2d0adc7
JS
225 wxXmlNode* child = node->GetChildren();
226 while (child)
227 {
228 ImportStyleDefinition(sheet, child);
87eaa6f6 229
d2d0adc7
JS
230 child = child->GetNext();
231 }
87eaa6f6 232
d2d0adc7
JS
233 // Notify that styles have changed. If this is vetoed by the app,
234 // the new sheet will be deleted. If it is not vetoed, the
235 // old sheet will be deleted and replaced with the new one.
236 buffer->SetStyleSheetAndNotify(sheet);
237 }
238 doneChildren = true;
239 }
5d7836c4
JS
240
241 if (!doneChildren)
242 {
243 wxXmlNode* child = node->GetChildren();
244 while (child)
245 {
246 ImportXML(buffer, child);
247 child = child->GetNext();
248 }
7fe8059f 249 }
5d7836c4
JS
250
251 return true;
252}
253
d2d0adc7
JS
254bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wxXmlNode* node)
255{
87eaa6f6 256 wxString styleType = node->GetName();
288b6107
VS
257 wxString styleName = node->GetAttribute(wxT("name"), wxEmptyString);
258 wxString baseStyleName = node->GetAttribute(wxT("basestyle"), wxEmptyString);
87eaa6f6 259
d2d0adc7
JS
260 if (styleName.IsEmpty())
261 return false;
87eaa6f6 262
d2d0adc7
JS
263 if (styleType == wxT("characterstyle"))
264 {
265 wxRichTextCharacterStyleDefinition* def = new wxRichTextCharacterStyleDefinition(styleName);
266 def->SetBaseStyle(baseStyleName);
267
268 wxXmlNode* child = node->GetChildren();
269 while (child)
270 {
271 if (child->GetName() == wxT("style"))
272 {
44cc96a8 273 wxTextAttr attr;
d2d0adc7
JS
274 GetStyle(attr, child, false);
275 def->SetStyle(attr);
276 }
277 child = child->GetNext();
278 }
87eaa6f6 279
d2d0adc7
JS
280 sheet->AddCharacterStyle(def);
281 }
282 else if (styleType == wxT("paragraphstyle"))
283 {
284 wxRichTextParagraphStyleDefinition* def = new wxRichTextParagraphStyleDefinition(styleName);
285
288b6107 286 wxString nextStyleName = node->GetAttribute(wxT("nextstyle"), wxEmptyString);
d2d0adc7
JS
287 def->SetNextStyle(nextStyleName);
288 def->SetBaseStyle(baseStyleName);
289
290 wxXmlNode* child = node->GetChildren();
291 while (child)
292 {
293 if (child->GetName() == wxT("style"))
294 {
44cc96a8 295 wxTextAttr attr;
d2d0adc7
JS
296 GetStyle(attr, child, false);
297 def->SetStyle(attr);
298 }
299 child = child->GetNext();
300 }
301
302 sheet->AddParagraphStyle(def);
303 }
304 else if (styleType == wxT("liststyle"))
305 {
306 wxRichTextListStyleDefinition* def = new wxRichTextListStyleDefinition(styleName);
307
288b6107 308 wxString nextStyleName = node->GetAttribute(wxT("nextstyle"), wxEmptyString);
d2d0adc7
JS
309 def->SetNextStyle(nextStyleName);
310 def->SetBaseStyle(baseStyleName);
311
312 wxXmlNode* child = node->GetChildren();
313 while (child)
314 {
315 if (child->GetName() == wxT("style"))
316 {
44cc96a8 317 wxTextAttr attr;
d2d0adc7
JS
318 GetStyle(attr, child, false);
319
288b6107 320 wxString styleLevel = child->GetAttribute(wxT("level"), wxEmptyString);
d2d0adc7 321 if (styleLevel.IsEmpty())
87eaa6f6 322 {
d2d0adc7
JS
323 def->SetStyle(attr);
324 }
325 else
326 {
327 int level = wxAtoi(styleLevel);
328 if (level > 0 && level <= 10)
329 {
330 def->SetLevelAttributes(level-1, attr);
331 }
332 }
333 }
334 child = child->GetNext();
335 }
336
337 sheet->AddListStyle(def);
338 }
87eaa6f6 339
d2d0adc7
JS
340 return true;
341}
5d7836c4
JS
342
343//-----------------------------------------------------------------------------
344// xml support routines
345//-----------------------------------------------------------------------------
346
347bool wxRichTextXMLHandler::HasParam(wxXmlNode* node, const wxString& param)
348{
349 return (GetParamNode(node, param) != NULL);
350}
351
352wxXmlNode *wxRichTextXMLHandler::GetParamNode(wxXmlNode* node, const wxString& param)
353{
354 wxCHECK_MSG(node, NULL, wxT("You can't access node data before it was initialized!"));
355
356 wxXmlNode *n = node->GetChildren();
357
358 while (n)
359 {
360 if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
361 return n;
362 n = n->GetNext();
363 }
364 return NULL;
365}
366
367
368wxString wxRichTextXMLHandler::GetNodeContent(wxXmlNode *node)
369{
370 wxXmlNode *n = node;
371 if (n == NULL) return wxEmptyString;
372 n = n->GetChildren();
373
374 while (n)
375 {
376 if (n->GetType() == wxXML_TEXT_NODE ||
377 n->GetType() == wxXML_CDATA_SECTION_NODE)
378 return n->GetContent();
379 n = n->GetNext();
380 }
381 return wxEmptyString;
382}
383
384
385wxString wxRichTextXMLHandler::GetParamValue(wxXmlNode *node, const wxString& param)
386{
7fe8059f 387 if (param.empty())
5d7836c4
JS
388 return GetNodeContent(node);
389 else
390 return GetNodeContent(GetParamNode(node, param));
391}
392
393wxString wxRichTextXMLHandler::GetText(wxXmlNode *node, const wxString& param, bool WXUNUSED(translate))
394{
395 wxXmlNode *parNode = GetParamNode(node, param);
396 if (!parNode)
397 parNode = node;
398 wxString str1(GetNodeContent(parNode));
399 return str1;
400}
401
1e967276
JS
402// For use with earlier versions of wxWidgets
403#ifndef WXUNUSED_IN_UNICODE
404#if wxUSE_UNICODE
405#define WXUNUSED_IN_UNICODE(x) WXUNUSED(x)
406#else
407#define WXUNUSED_IN_UNICODE(x) x
408#endif
409#endif
410
5d7836c4
JS
411// write string to output:
412inline static void OutputString(wxOutputStream& stream, const wxString& str,
7fe8059f 413 wxMBConv *WXUNUSED_IN_UNICODE(convMem) = NULL, wxMBConv *convFile = NULL)
5d7836c4 414{
7fe8059f 415 if (str.empty()) return;
5d7836c4 416#if wxUSE_UNICODE
0bab774b
JS
417 if (convFile)
418 {
419 const wxWX2MBbuf buf(str.mb_str(*convFile));
420 stream.Write((const char*)buf, strlen((const char*)buf));
421 }
422 else
423 {
424 const wxWX2MBbuf buf(str.mb_str(wxConvUTF8));
425 stream.Write((const char*)buf, strlen((const char*)buf));
426 }
5d7836c4
JS
427#else
428 if ( convFile == NULL )
429 stream.Write(str.mb_str(), str.Len());
430 else
431 {
432 wxString str2(str.wc_str(*convMem), *convFile);
433 stream.Write(str2.mb_str(), str2.Len());
434 }
435#endif
436}
437
438// Same as above, but create entities first.
439// Translates '<' to "&lt;", '>' to "&gt;" and '&' to "&amp;"
440static void OutputStringEnt(wxOutputStream& stream, const wxString& str,
441 wxMBConv *convMem = NULL, wxMBConv *convFile = NULL)
442{
443 wxString buf;
444 size_t i, last, len;
445 wxChar c;
7fe8059f 446
5d7836c4
JS
447 len = str.Len();
448 last = 0;
449 for (i = 0; i < len; i++)
450 {
451 c = str.GetChar(i);
88a7a4e1 452
b71e9aa4
JS
453 // Original code excluded "&amp;" but we _do_ want to convert
454 // the ampersand beginning &amp; because otherwise when read in,
455 // the original "&amp;" becomes "&".
456
5d7836c4 457 if (c == wxT('<') || c == wxT('>') || c == wxT('"') ||
b71e9aa4 458 (c == wxT('&') /* && (str.Mid(i+1, 4) != wxT("amp;")) */ ))
5d7836c4
JS
459 {
460 OutputString(stream, str.Mid(last, i - last), convMem, convFile);
461 switch (c)
462 {
463 case wxT('<'):
464 OutputString(stream, wxT("&lt;"), NULL, NULL);
465 break;
466 case wxT('>'):
467 OutputString(stream, wxT("&gt;"), NULL, NULL);
468 break;
469 case wxT('&'):
470 OutputString(stream, wxT("&amp;"), NULL, NULL);
471 break;
472 case wxT('"'):
473 OutputString(stream, wxT("&quot;"), NULL, NULL);
474 break;
475 default: break;
476 }
477 last = i + 1;
478 }
07854e5e 479 else if (wxUChar(c) > 127)
7b907278
JS
480 {
481 OutputString(stream, str.Mid(last, i - last), convMem, convFile);
482
483 wxString s(wxT("&#"));
484 s << (int) c;
485 s << wxT(";");
486 OutputString(stream, s, NULL, NULL);
487 last = i + 1;
488 }
5d7836c4
JS
489 }
490 OutputString(stream, str.Mid(last, i - last), convMem, convFile);
491}
492
493inline static void OutputIndentation(wxOutputStream& stream, int indent)
494{
495 wxString str = wxT("\n");
496 for (int i = 0; i < indent; i++)
497 str << wxT(' ') << wxT(' ');
498 OutputString(stream, str, NULL, NULL);
499}
500
5d7836c4
JS
501// Convert a colour to a 6-digit hex string
502static wxString ColourToHexString(const wxColour& col)
503{
504 wxString hex;
505
506 hex += wxDecToHex(col.Red());
507 hex += wxDecToHex(col.Green());
508 hex += wxDecToHex(col.Blue());
509
510 return hex;
511}
512
513// Convert 6-digit hex string to a colour
b71e9aa4 514static wxColour HexStringToColour(const wxString& hex)
5d7836c4 515{
7fe8059f
WS
516 unsigned char r = (unsigned char)wxHexToDec(hex.Mid(0, 2));
517 unsigned char g = (unsigned char)wxHexToDec(hex.Mid(2, 2));
518 unsigned char b = (unsigned char)wxHexToDec(hex.Mid(4, 2));
5d7836c4
JS
519
520 return wxColour(r, g, b);
521}
522
7fe8059f 523bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
5d7836c4
JS
524{
525 if (!stream.IsOk())
526 return false;
527
528 wxString version(wxT("1.0") ) ;
b71e9aa4
JS
529
530 bool deleteConvFile = false;
531 wxString fileEncoding;
532 wxMBConv* convFile = NULL;
533
5d7836c4 534#if wxUSE_UNICODE
b71e9aa4
JS
535 fileEncoding = wxT("UTF-8");
536 convFile = & wxConvUTF8;
5d7836c4 537#else
b71e9aa4
JS
538 fileEncoding = wxT("ISO-8859-1");
539 convFile = & wxConvISO8859_1;
5d7836c4 540#endif
7fe8059f 541
b71e9aa4 542 // If SetEncoding has been called, change the output encoding.
88a7a4e1 543 if (!m_encoding.empty() && m_encoding.Lower() != fileEncoding.Lower())
b71e9aa4
JS
544 {
545 if (m_encoding == wxT("<System>"))
546 {
4aae00c6 547#if wxUSE_INTL
b71e9aa4 548 fileEncoding = wxLocale::GetSystemEncodingName();
4aae00c6
VS
549 // if !wxUSE_INTL, we fall back to UTF-8 or ISO-8859-1 below
550#endif
b71e9aa4
JS
551 }
552 else
553 {
554 fileEncoding = m_encoding;
555 }
556
557 // GetSystemEncodingName may not have returned a name
88a7a4e1 558 if (fileEncoding.empty())
5d7836c4 559#if wxUSE_UNICODE
b71e9aa4 560 fileEncoding = wxT("UTF-8");
5d7836c4 561#else
b71e9aa4
JS
562 fileEncoding = wxT("ISO-8859-1");
563#endif
564 convFile = new wxCSConv(fileEncoding);
565 deleteConvFile = true;
5d7836c4 566 }
b71e9aa4
JS
567
568#if !wxUSE_UNICODE
569 wxMBConv* convMem = wxConvCurrent;
570#else
571 wxMBConv* convMem = NULL;
5d7836c4 572#endif
7fe8059f 573
b71e9aa4 574 wxString s ;
5d7836c4 575 s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
86501081 576 version, fileEncoding);
5d7836c4
JS
577 OutputString(stream, s, NULL, NULL);
578 OutputString(stream, wxT("<richtext version=\"1.0.0.0\" xmlns=\"http://www.wxwidgets.org\">") , NULL, NULL);
579
580 int level = 1;
5d7836c4 581
d2d0adc7
JS
582 if (buffer->GetStyleSheet() && (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
583 {
584 OutputIndentation(stream, level);
42688aea
JS
585 wxString nameAndDescr;
586 if (!buffer->GetStyleSheet()->GetName().IsEmpty())
587 nameAndDescr << wxT(" name=\"") << buffer->GetStyleSheet()->GetName() << wxT("\"");
588 if (!buffer->GetStyleSheet()->GetDescription().IsEmpty())
589 nameAndDescr << wxT(" description=\"") << buffer->GetStyleSheet()->GetDescription() << wxT("\"");
590 OutputString(stream, wxString(wxT("<stylesheet")) + nameAndDescr + wxT(">"), convMem, convFile);
d2d0adc7
JS
591
592 int i;
593
594 for (i = 0; i < (int) buffer->GetStyleSheet()->GetCharacterStyleCount(); i++)
595 {
596 wxRichTextCharacterStyleDefinition* def = buffer->GetStyleSheet()->GetCharacterStyle(i);
597 ExportStyleDefinition(stream, convMem, convFile, def, level + 1);
598 }
599
600 for (i = 0; i < (int) buffer->GetStyleSheet()->GetParagraphStyleCount(); i++)
601 {
602 wxRichTextParagraphStyleDefinition* def = buffer->GetStyleSheet()->GetParagraphStyle(i);
603 ExportStyleDefinition(stream, convMem, convFile, def, level + 1);
604 }
605
606 for (i = 0; i < (int) buffer->GetStyleSheet()->GetListStyleCount(); i++)
607 {
608 wxRichTextListStyleDefinition* def = buffer->GetStyleSheet()->GetListStyle(i);
609 ExportStyleDefinition(stream, convMem, convFile, def, level + 1);
610 }
611
612 OutputIndentation(stream, level);
613 OutputString(stream, wxT("</stylesheet>"), convMem, convFile);
614 }
615
616
617 bool success = ExportXML(stream, convMem, convFile, *buffer, level);
87eaa6f6 618
5d7836c4
JS
619 OutputString(stream, wxT("\n</richtext>") , NULL, NULL);
620 OutputString(stream, wxT("\n"), NULL, NULL);
7fe8059f 621
b71e9aa4
JS
622 if (deleteConvFile)
623 delete convFile;
88a7a4e1 624
b71e9aa4 625 return success;
5d7836c4
JS
626}
627
628/// Recursively export an object
629bool wxRichTextXMLHandler::ExportXML(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextObject& obj, int indent)
630{
631 wxString objectName;
632 if (obj.IsKindOf(CLASSINFO(wxRichTextParagraphLayoutBox)))
633 objectName = wxT("paragraphlayout");
634 else if (obj.IsKindOf(CLASSINFO(wxRichTextParagraph)))
635 objectName = wxT("paragraph");
636 else if (obj.IsKindOf(CLASSINFO(wxRichTextPlainText)))
637 objectName = wxT("text");
638 else if (obj.IsKindOf(CLASSINFO(wxRichTextImage)))
639 objectName = wxT("image");
640 else
641 objectName = wxT("object");
87eaa6f6 642
7b907278 643 bool terminateTag = true;
5d7836c4
JS
644
645 if (obj.IsKindOf(CLASSINFO(wxRichTextPlainText)))
646 {
7b907278 647 wxRichTextPlainText& textObj = (wxRichTextPlainText&) obj;
87eaa6f6 648
7b907278 649 wxString style = CreateStyle(obj.GetAttributes(), false);
87eaa6f6 650
7b907278
JS
651 int i;
652 int last = 0;
653 const wxString& text = textObj.GetText();
654 int len = (int) text.Length();
655 for (i = 0; i < len; i++)
656 {
657 int c = (int) text[i];
658 if (c < 32 && c != 9 && c != 10 && c != 13)
659 {
660 if (i > 0)
661 {
662 OutputIndentation(stream, indent);
663 OutputString(stream, wxT("<") + objectName, convMem, convFile);
5d7836c4 664
7b907278 665 OutputString(stream, style + wxT(">"), convMem, convFile);
7fe8059f 666
7b907278
JS
667 wxString fragment(text.Mid(last, i-last));
668 if (!fragment.empty() && (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' ')))
669 {
670 OutputString(stream, wxT("\""), convMem, convFile);
671 OutputStringEnt(stream, fragment, convMem, convFile);
672 OutputString(stream, wxT("\""), convMem, convFile);
673 }
674 else
675 OutputStringEnt(stream, fragment, convMem, convFile);
7fe8059f 676
7b907278 677 OutputString(stream, wxT("</text>"), convMem, convFile);
87eaa6f6
JS
678 }
679
7b907278
JS
680
681 // Output this character as a number in a separate tag, because XML can't cope
87eaa6f6 682 // with entities below 32 except for 9, 10 and 13
7b907278
JS
683 last = i + 1;
684 OutputIndentation(stream, indent);
685 OutputString(stream, wxT("<symbol"), convMem, convFile);
7fe8059f 686
7b907278 687 OutputString(stream, style + wxT(">"), convMem, convFile);
87eaa6f6 688 OutputString(stream, wxString::Format(wxT("%d"), c), convMem, convFile);
7b907278
JS
689
690 OutputString(stream, wxT("</symbol>"), convMem, convFile);
691 }
692 }
87eaa6f6 693
7b907278
JS
694 wxString fragment;
695 if (last == 0)
696 fragment = text;
697 else
698 fragment = text.Mid(last, i-last);
699
700 if (last < len)
5d7836c4 701 {
7b907278
JS
702 OutputIndentation(stream, indent);
703 OutputString(stream, wxT("<") + objectName, convMem, convFile);
704
705 OutputString(stream, style + wxT(">"), convMem, convFile);
706
707 if (!fragment.empty() && (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' ')))
708 {
709 OutputString(stream, wxT("\""), convMem, convFile);
710 OutputStringEnt(stream, fragment, convMem, convFile);
711 OutputString(stream, wxT("\""), convMem, convFile);
712 }
713 else
714 OutputStringEnt(stream, fragment, convMem, convFile);
5d7836c4
JS
715 }
716 else
7b907278 717 terminateTag = false;
5d7836c4
JS
718 }
719 else if (obj.IsKindOf(CLASSINFO(wxRichTextImage)))
720 {
721 wxRichTextImage& imageObj = (wxRichTextImage&) obj;
722
723 if (imageObj.GetImage().Ok() && !imageObj.GetImageBlock().Ok())
724 imageObj.MakeBlock();
725
726 OutputIndentation(stream, indent);
b71e9aa4 727 OutputString(stream, wxT("<") + objectName, convMem, convFile);
5d7836c4
JS
728 if (!imageObj.GetImageBlock().Ok())
729 {
730 // No data
b71e9aa4 731 OutputString(stream, wxT(">"), convMem, convFile);
5d7836c4
JS
732 }
733 else
734 {
b71e9aa4 735 OutputString(stream, wxString::Format(wxT(" imagetype=\"%d\">"), (int) imageObj.GetImageBlock().GetImageType()));
5d7836c4
JS
736 }
737
738 OutputIndentation(stream, indent+1);
b71e9aa4 739 OutputString(stream, wxT("<data>"), convMem, convFile);
5d7836c4
JS
740
741 imageObj.GetImageBlock().WriteHex(stream);
742
b71e9aa4 743 OutputString(stream, wxT("</data>"), convMem, convFile);
5d7836c4
JS
744 }
745 else if (obj.IsKindOf(CLASSINFO(wxRichTextCompositeObject)))
746 {
747 OutputIndentation(stream, indent);
b71e9aa4 748 OutputString(stream, wxT("<") + objectName, convMem, convFile);
7fe8059f 749
5d7836c4
JS
750 bool isPara = false;
751 if (objectName == wxT("paragraph") || objectName == wxT("paragraphlayout"))
752 isPara = true;
753
754 wxString style = CreateStyle(obj.GetAttributes(), isPara);
87eaa6f6 755
0ca07313
JS
756 if (objectName == wxT("paragraphlayout") && ((wxRichTextParagraphLayoutBox&) obj).GetPartialParagraph())
757 style << wxT(" partialparagraph=\"true\"");
758
b71e9aa4 759 OutputString(stream, style + wxT(">"), convMem, convFile);
7fe8059f 760
5d7836c4
JS
761 wxRichTextCompositeObject& composite = (wxRichTextCompositeObject&) obj;
762 size_t i;
763 for (i = 0; i < composite.GetChildCount(); i++)
764 {
765 wxRichTextObject* child = composite.GetChild(i);
766 ExportXML(stream, convMem, convFile, *child, indent+1);
767 }
768 }
769
770 if (objectName != wxT("text"))
771 OutputIndentation(stream, indent);
772
7b907278
JS
773 if (terminateTag)
774 OutputString(stream, wxT("</") + objectName + wxT(">"), convMem, convFile);
5d7836c4
JS
775
776 return true;
777}
778
d2d0adc7
JS
779bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextStyleDefinition* def, int level)
780{
87eaa6f6 781 wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
d2d0adc7
JS
782 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
783 wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
87eaa6f6 784
d2d0adc7
JS
785 wxString baseStyle = def->GetBaseStyle();
786 wxString baseStyleProp;
787 if (!baseStyle.IsEmpty())
788 baseStyleProp = wxT(" basestyle=\"") + baseStyle + wxT("\"");
87eaa6f6 789
42688aea
JS
790 wxString descr = def->GetDescription();
791 wxString descrProp;
792 if (!descr.IsEmpty())
793 descrProp = wxT(" description=\"") + descr + wxT("\"");
87eaa6f6 794
d2d0adc7
JS
795 if (charDef)
796 {
797 OutputIndentation(stream, level);
42688aea 798 OutputString(stream, wxT("<characterstyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
87eaa6f6 799
d2d0adc7
JS
800 level ++;
801
802 wxString style = CreateStyle(def->GetStyle(), false);
803
804 OutputIndentation(stream, level);
805 OutputString(stream, wxT("<style ") + style + wxT(">"), convMem, convFile);
87eaa6f6 806
d2d0adc7
JS
807 OutputIndentation(stream, level);
808 OutputString(stream, wxT("</style>"), convMem, convFile);
809
810 level --;
811
812 OutputIndentation(stream, level);
813 OutputString(stream, wxT("</characterstyle>"), convMem, convFile);
814 }
815 else if (listDef)
816 {
817 OutputIndentation(stream, level);
87eaa6f6 818
d2d0adc7
JS
819 if (!listDef->GetNextStyle().IsEmpty())
820 baseStyleProp << wxT(" basestyle=\"") << listDef->GetNextStyle() << wxT("\"");
87eaa6f6 821
42688aea 822 OutputString(stream, wxT("<liststyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
87eaa6f6 823
d2d0adc7
JS
824 level ++;
825
826 wxString style = CreateStyle(def->GetStyle(), false);
827
828 OutputIndentation(stream, level);
829 OutputString(stream, wxT("<style ") + style + wxT(">"), convMem, convFile);
87eaa6f6 830
d2d0adc7
JS
831 OutputIndentation(stream, level);
832 OutputString(stream, wxT("</style>"), convMem, convFile);
833
834 int i;
835 for (i = 0; i < 10; i ++)
836 {
44cc96a8 837 wxTextAttr* levelAttr = listDef->GetLevelAttributes(i);
d2d0adc7
JS
838 if (levelAttr)
839 {
840 wxString style = CreateStyle(def->GetStyle(), false);
841 wxString levelStr = wxString::Format(wxT(" level=\"%d\" "), (i+1));
842
843 OutputIndentation(stream, level);
844 OutputString(stream, wxT("<style ") + levelStr + style + wxT(">"), convMem, convFile);
87eaa6f6 845
d2d0adc7
JS
846 OutputIndentation(stream, level);
847 OutputString(stream, wxT("</style>"), convMem, convFile);
848 }
849 }
850
851 level --;
852
853 OutputIndentation(stream, level);
854 OutputString(stream, wxT("</liststyle>"), convMem, convFile);
855 }
856 else if (paraDef)
857 {
858 OutputIndentation(stream, level);
87eaa6f6
JS
859
860 if (!paraDef->GetNextStyle().IsEmpty())
861 baseStyleProp << wxT(" basestyle=\"") << paraDef->GetNextStyle() << wxT("\"");
862
42688aea 863 OutputString(stream, wxT("<paragraphstyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
87eaa6f6 864
d2d0adc7
JS
865 level ++;
866
867 wxString style = CreateStyle(def->GetStyle(), false);
868
869 OutputIndentation(stream, level);
870 OutputString(stream, wxT("<style ") + style + wxT(">"), convMem, convFile);
87eaa6f6 871
d2d0adc7
JS
872 OutputIndentation(stream, level);
873 OutputString(stream, wxT("</style>"), convMem, convFile);
87eaa6f6 874
d2d0adc7
JS
875 level --;
876
877 OutputIndentation(stream, level);
878 OutputString(stream, wxT("</paragraphstyle>"), convMem, convFile);
879 }
880
881 return true;
882}
883
5d7836c4 884/// Create style parameters
44cc96a8 885wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttr& attr, bool isPara)
5d7836c4
JS
886{
887 wxString str;
0ca07313 888 if (attr.HasTextColour() && attr.GetTextColour().Ok())
5d7836c4
JS
889 {
890 str << wxT(" textcolor=\"#") << ColourToHexString(attr.GetTextColour()) << wxT("\"");
891 }
0ca07313 892 if (attr.HasBackgroundColour() && attr.GetBackgroundColour().Ok())
5d7836c4
JS
893 {
894 str << wxT(" bgcolor=\"#") << ColourToHexString(attr.GetBackgroundColour()) << wxT("\"");
895 }
896
44cc96a8
JS
897 if (attr.HasFontSize())
898 str << wxT(" fontsize=\"") << attr.GetFontSize() << wxT("\"");
87eaa6f6 899
44cc96a8
JS
900 //if (attr.HasFontFamily())
901 // str << wxT(" fontfamily=\"") << attr.GetFont().GetFamily() << wxT("\"");
0ca07313 902
44cc96a8
JS
903 if (attr.HasFontItalic())
904 str << wxT(" fontstyle=\"") << attr.GetFontStyle() << wxT("\"");
0ca07313 905
44cc96a8
JS
906 if (attr.HasFontWeight())
907 str << wxT(" fontweight=\"") << attr.GetFontWeight() << wxT("\"");
0ca07313 908
44cc96a8
JS
909 if (attr.HasFontUnderlined())
910 str << wxT(" fontunderlined=\"") << (int) attr.GetFontUnderlined() << wxT("\"");
0ca07313 911
44cc96a8
JS
912 if (attr.HasFontFaceName())
913 str << wxT(" fontface=\"") << attr.GetFontFaceName() << wxT("\"");
5d7836c4 914
42688aea
JS
915 if (attr.HasTextEffects())
916 {
917 str << wxT(" texteffects=\"");
918 str << attr.GetTextEffects();
919 str << wxT("\"");
1f65137f
JS
920
921 str << wxT(" texteffectflags=\"");
922 str << attr.GetTextEffectFlags();
923 str << wxT("\"");
42688aea
JS
924 }
925
7fe8059f 926 if (!attr.GetCharacterStyleName().empty())
f089713f 927 str << wxT(" characterstyle=\"") << wxString(attr.GetCharacterStyleName()) << wxT("\"");
5d7836c4 928
03cd2124
JS
929 if (attr.HasURL())
930 str << wxT(" url=\"") << attr.GetURL() << wxT("\"");
931
5d7836c4
JS
932 if (isPara)
933 {
0ca07313
JS
934 if (attr.HasAlignment())
935 str << wxT(" alignment=\"") << (int) attr.GetAlignment() << wxT("\"");
936
937 if (attr.HasLeftIndent())
938 {
939 str << wxT(" leftindent=\"") << (int) attr.GetLeftIndent() << wxT("\"");
940 str << wxT(" leftsubindent=\"") << (int) attr.GetLeftSubIndent() << wxT("\"");
941 }
942
943 if (attr.HasRightIndent())
944 str << wxT(" rightindent=\"") << (int) attr.GetRightIndent() << wxT("\"");
945
946 if (attr.HasParagraphSpacingAfter())
947 str << wxT(" parspacingafter=\"") << (int) attr.GetParagraphSpacingAfter() << wxT("\"");
948
949 if (attr.HasParagraphSpacingBefore())
950 str << wxT(" parspacingbefore=\"") << (int) attr.GetParagraphSpacingBefore() << wxT("\"");
951
952 if (attr.HasLineSpacing())
953 str << wxT(" linespacing=\"") << (int) attr.GetLineSpacing() << wxT("\"");
954
955 if (attr.HasBulletStyle())
956 str << wxT(" bulletstyle=\"") << (int) attr.GetBulletStyle() << wxT("\"");
957
958 if (attr.HasBulletNumber())
959 str << wxT(" bulletnumber=\"") << (int) attr.GetBulletNumber() << wxT("\"");
960
d2d0adc7 961 if (attr.HasBulletText())
7b907278 962 {
d2d0adc7
JS
963 // If using a bullet symbol, convert to integer in case it's a non-XML-friendly character.
964 // Otherwise, assume it's XML-friendly text such as outline numbering, e.g. 1.2.3.1
965 if (!attr.GetBulletText().IsEmpty() && (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL))
966 str << wxT(" bulletsymbol=\"") << (int) (attr.GetBulletText()[0]) << wxT("\"");
967 else
968 str << wxT(" bullettext=\"") << attr.GetBulletText() << wxT("\"");
87eaa6f6 969
7b907278
JS
970 str << wxT(" bulletfont=\"") << attr.GetBulletFont() << wxT("\"");
971 }
5d7836c4 972
f089713f
JS
973 if (attr.HasBulletName())
974 str << wxT(" bulletname=\"") << attr.GetBulletName() << wxT("\"");
975
7fe8059f 976 if (!attr.GetParagraphStyleName().empty())
5d7836c4 977 str << wxT(" parstyle=\"") << wxString(attr.GetParagraphStyleName()) << wxT("\"");
87eaa6f6 978
f089713f
JS
979 if (!attr.GetListStyleName().empty())
980 str << wxT(" liststyle=\"") << wxString(attr.GetListStyleName()) << wxT("\"");
87eaa6f6 981
0ca07313
JS
982 if (attr.HasTabs())
983 {
984 str << wxT(" tabs=\"");
985 size_t i;
986 for (i = 0; i < attr.GetTabs().GetCount(); i++)
987 {
988 if (i > 0)
989 str << wxT(",");
990 str << attr.GetTabs()[i];
991 }
87eaa6f6 992 str << wxT("\"");
0ca07313 993 }
87eaa6f6 994
42688aea
JS
995 if (attr.HasPageBreak())
996 {
997 str << wxT(" pagebreak=\"1\"");
998 }
4d6d8bf4
JS
999
1000 if (attr.HasOutlineLevel())
1001 str << wxT(" outlinelevel=\"") << (int) attr.GetOutlineLevel() << wxT("\"");
1002
5d7836c4
JS
1003 }
1004
1005 return str;
1006}
1007
1008/// Get style parameters
44cc96a8 1009bool wxRichTextXMLHandler::GetStyle(wxTextAttr& attr, wxXmlNode* node, bool isPara)
5d7836c4
JS
1010{
1011 wxString fontFacename;
1012 int fontSize = 12;
44cc96a8 1013 // int fontFamily = wxDEFAULT;
5d7836c4
JS
1014 int fontWeight = wxNORMAL;
1015 int fontStyle = wxNORMAL;
1016 bool fontUnderlined = false;
87eaa6f6 1017
44cc96a8 1018 // int fontFlags = 0;
0ca07313 1019
288b6107 1020 fontFacename = node->GetAttribute(wxT("fontface"), wxEmptyString);
0ca07313 1021 if (!fontFacename.IsEmpty())
44cc96a8 1022 attr.SetFontFaceName(fontFacename);
5d7836c4 1023
0ca07313 1024 wxString value;
288b6107 1025 //value = node->GetAttribute(wxT("fontfamily"), wxEmptyString);
0ca07313
JS
1026 //if (!value.empty())
1027 // fontFamily = wxAtoi(value);
5d7836c4 1028
288b6107 1029 value = node->GetAttribute(wxT("fontstyle"), wxEmptyString);
7fe8059f 1030 if (!value.empty())
0ca07313 1031 {
5d7836c4 1032 fontStyle = wxAtoi(value);
44cc96a8 1033 attr.SetFontStyle(fontStyle);
0ca07313 1034 }
5d7836c4 1035
288b6107 1036 value = node->GetAttribute(wxT("fontsize"), wxEmptyString);
7fe8059f 1037 if (!value.empty())
0ca07313 1038 {
5d7836c4 1039 fontSize = wxAtoi(value);
44cc96a8 1040 attr.SetFontSize(fontSize);
0ca07313 1041 }
5d7836c4 1042
288b6107 1043 value = node->GetAttribute(wxT("fontweight"), wxEmptyString);
7fe8059f 1044 if (!value.empty())
0ca07313 1045 {
5d7836c4 1046 fontWeight = wxAtoi(value);
44cc96a8 1047 attr.SetFontWeight(fontWeight);
0ca07313 1048 }
5d7836c4 1049
288b6107 1050 value = node->GetAttribute(wxT("fontunderlined"), wxEmptyString);
7fe8059f 1051 if (!value.empty())
0ca07313 1052 {
5d7836c4 1053 fontUnderlined = wxAtoi(value) != 0;
44cc96a8 1054 attr.SetFontUnderlined(fontUnderlined);
0ca07313 1055 }
87eaa6f6 1056
288b6107 1057 value = node->GetAttribute(wxT("textcolor"), wxEmptyString);
7fe8059f 1058 if (!value.empty())
5d7836c4
JS
1059 {
1060 if (value[0] == wxT('#'))
1061 attr.SetTextColour(HexStringToColour(value.Mid(1)));
1062 else
1063 attr.SetTextColour(value);
1064 }
1065
288b6107 1066 value = node->GetAttribute(wxT("backgroundcolor"), wxEmptyString);
7fe8059f 1067 if (!value.empty())
5d7836c4
JS
1068 {
1069 if (value[0] == wxT('#'))
1070 attr.SetBackgroundColour(HexStringToColour(value.Mid(1)));
1071 else
1072 attr.SetBackgroundColour(value);
1073 }
1074
288b6107 1075 value = node->GetAttribute(wxT("characterstyle"), wxEmptyString);
7fe8059f 1076 if (!value.empty())
5d7836c4
JS
1077 attr.SetCharacterStyleName(value);
1078
288b6107 1079 value = node->GetAttribute(wxT("texteffects"), wxEmptyString);
42688aea
JS
1080 if (!value.IsEmpty())
1081 {
1082 attr.SetTextEffects(wxAtoi(value));
1083 }
1084
288b6107 1085 value = node->GetAttribute(wxT("texteffectflags"), wxEmptyString);
1f65137f
JS
1086 if (!value.IsEmpty())
1087 {
1088 attr.SetTextEffectFlags(wxAtoi(value));
1089 }
1090
03cd2124
JS
1091 value = node->GetAttribute(wxT("url"), wxEmptyString);
1092 if (!value.empty())
1093 attr.SetURL(value);
1094
5d7836c4
JS
1095 // Set paragraph attributes
1096 if (isPara)
1097 {
288b6107 1098 value = node->GetAttribute(wxT("alignment"), wxEmptyString);
7fe8059f 1099 if (!value.empty())
5d7836c4
JS
1100 attr.SetAlignment((wxTextAttrAlignment) wxAtoi(value));
1101
1102 int leftSubIndent = 0;
1103 int leftIndent = 0;
0ca07313 1104 bool hasLeftIndent = false;
87eaa6f6 1105
288b6107 1106 value = node->GetAttribute(wxT("leftindent"), wxEmptyString);
7fe8059f 1107 if (!value.empty())
0ca07313 1108 {
5d7836c4 1109 leftIndent = wxAtoi(value);
0ca07313
JS
1110 hasLeftIndent = true;
1111 }
1112
288b6107 1113 value = node->GetAttribute(wxT("leftsubindent"), wxEmptyString);
7fe8059f 1114 if (!value.empty())
0ca07313 1115 {
5d7836c4 1116 leftSubIndent = wxAtoi(value);
0ca07313
JS
1117 hasLeftIndent = true;
1118 }
1119
1120 if (hasLeftIndent)
1121 attr.SetLeftIndent(leftIndent, leftSubIndent);
5d7836c4 1122
288b6107 1123 value = node->GetAttribute(wxT("rightindent"), wxEmptyString);
7fe8059f 1124 if (!value.empty())
5d7836c4
JS
1125 attr.SetRightIndent(wxAtoi(value));
1126
288b6107 1127 value = node->GetAttribute(wxT("parspacingbefore"), wxEmptyString);
7fe8059f 1128 if (!value.empty())
5d7836c4
JS
1129 attr.SetParagraphSpacingBefore(wxAtoi(value));
1130
288b6107 1131 value = node->GetAttribute(wxT("parspacingafter"), wxEmptyString);
7fe8059f 1132 if (!value.empty())
5d7836c4
JS
1133 attr.SetParagraphSpacingAfter(wxAtoi(value));
1134
288b6107 1135 value = node->GetAttribute(wxT("linespacing"), wxEmptyString);
7fe8059f 1136 if (!value.empty())
5d7836c4
JS
1137 attr.SetLineSpacing(wxAtoi(value));
1138
288b6107 1139 value = node->GetAttribute(wxT("bulletstyle"), wxEmptyString);
7fe8059f 1140 if (!value.empty())
5d7836c4
JS
1141 attr.SetBulletStyle(wxAtoi(value));
1142
288b6107 1143 value = node->GetAttribute(wxT("bulletnumber"), wxEmptyString);
7fe8059f 1144 if (!value.empty())
5d7836c4
JS
1145 attr.SetBulletNumber(wxAtoi(value));
1146
288b6107 1147 value = node->GetAttribute(wxT("bulletsymbol"), wxEmptyString);
7fe8059f 1148 if (!value.empty())
d2d0adc7
JS
1149 {
1150 wxChar ch = wxAtoi(value);
1151 wxString s;
1152 s << ch;
1153 attr.SetBulletText(s);
1154 }
1155
288b6107 1156 value = node->GetAttribute(wxT("bullettext"), wxEmptyString);
d2d0adc7
JS
1157 if (!value.empty())
1158 attr.SetBulletText(value);
7b907278 1159
288b6107 1160 value = node->GetAttribute(wxT("bulletfont"), wxEmptyString);
7b907278
JS
1161 if (!value.empty())
1162 attr.SetBulletFont(value);
5d7836c4 1163
288b6107 1164 value = node->GetAttribute(wxT("bulletname"), wxEmptyString);
f089713f
JS
1165 if (!value.empty())
1166 attr.SetBulletName(value);
1167
288b6107 1168 value = node->GetAttribute(wxT("parstyle"), wxEmptyString);
7fe8059f 1169 if (!value.empty())
5d7836c4 1170 attr.SetParagraphStyleName(value);
87eaa6f6 1171
288b6107 1172 value = node->GetAttribute(wxT("liststyle"), wxEmptyString);
f089713f
JS
1173 if (!value.empty())
1174 attr.SetListStyleName(value);
87eaa6f6 1175
288b6107 1176 value = node->GetAttribute(wxT("tabs"), wxEmptyString);
0ca07313
JS
1177 if (!value.empty())
1178 {
1179 wxArrayInt tabs;
1180 wxStringTokenizer tkz(value, wxT(","));
1181 while (tkz.HasMoreTokens())
1182 {
1183 wxString token = tkz.GetNextToken();
1184 tabs.Add(wxAtoi(token));
1185 }
1186 attr.SetTabs(tabs);
1187 }
87eaa6f6 1188
288b6107 1189 value = node->GetAttribute(wxT("pagebreak"), wxEmptyString);
42688aea
JS
1190 if (!value.IsEmpty())
1191 {
1192 attr.SetPageBreak(wxAtoi(value) != 0);
1193 }
4d6d8bf4 1194
288b6107 1195 value = node->GetAttribute(wxT("outlinelevel"), wxEmptyString);
4d6d8bf4
JS
1196 if (!value.IsEmpty())
1197 {
aa097547 1198 attr.SetOutlineLevel(wxAtoi(value));
4d6d8bf4 1199 }
5d7836c4
JS
1200 }
1201
1202 return true;
1203}
1204
1205#endif
b71e9aa4 1206 // wxUSE_STREAMS
88a7a4e1 1207
5d7836c4 1208#endif
fcdbeefa 1209 // wxUSE_RICHTEXT && wxUSE_XML
7b907278 1210