]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtextxml.cpp
wxAppTraits::SetLocale() is wxUSE_INTL=1 only
[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 {
0ca07313
JS
104 wxString partial = node->GetPropVal(wxT("partialparagraph"), wxEmptyString);
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;
176 wxString value = node->GetPropVal(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;
42688aea
JS
220 wxString sheetName = node->GetPropVal(wxT("name"), wxEmptyString);
221 wxString sheetDescription = node->GetPropVal(wxT("description"), wxEmptyString);
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();
d2d0adc7
JS
257 wxString styleName = node->GetPropVal(wxT("name"), wxEmptyString);
258 wxString baseStyleName = node->GetPropVal(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 {
273 wxTextAttrEx attr;
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
286 wxString nextStyleName = node->GetPropVal(wxT("nextstyle"), wxEmptyString);
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 {
295 wxTextAttrEx attr;
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
308 wxString nextStyleName = node->GetPropVal(wxT("nextstyle"), wxEmptyString);
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 {
317 wxTextAttrEx attr;
318 GetStyle(attr, child, false);
319
320 wxString styleLevel = child->GetPropVal(wxT("level"), wxEmptyString);
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 {
547 fileEncoding = wxLocale::GetSystemEncodingName();
548 }
549 else
550 {
551 fileEncoding = m_encoding;
552 }
553
554 // GetSystemEncodingName may not have returned a name
88a7a4e1 555 if (fileEncoding.empty())
5d7836c4 556#if wxUSE_UNICODE
b71e9aa4 557 fileEncoding = wxT("UTF-8");
5d7836c4 558#else
b71e9aa4
JS
559 fileEncoding = wxT("ISO-8859-1");
560#endif
561 convFile = new wxCSConv(fileEncoding);
562 deleteConvFile = true;
5d7836c4 563 }
b71e9aa4
JS
564
565#if !wxUSE_UNICODE
566 wxMBConv* convMem = wxConvCurrent;
567#else
568 wxMBConv* convMem = NULL;
5d7836c4 569#endif
7fe8059f 570
b71e9aa4 571 wxString s ;
5d7836c4 572 s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
b71e9aa4 573 (const wxChar*) version, (const wxChar*) fileEncoding );
5d7836c4
JS
574 OutputString(stream, s, NULL, NULL);
575 OutputString(stream, wxT("<richtext version=\"1.0.0.0\" xmlns=\"http://www.wxwidgets.org\">") , NULL, NULL);
576
577 int level = 1;
5d7836c4 578
d2d0adc7
JS
579 if (buffer->GetStyleSheet() && (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
580 {
581 OutputIndentation(stream, level);
42688aea
JS
582 wxString nameAndDescr;
583 if (!buffer->GetStyleSheet()->GetName().IsEmpty())
584 nameAndDescr << wxT(" name=\"") << buffer->GetStyleSheet()->GetName() << wxT("\"");
585 if (!buffer->GetStyleSheet()->GetDescription().IsEmpty())
586 nameAndDescr << wxT(" description=\"") << buffer->GetStyleSheet()->GetDescription() << wxT("\"");
587 OutputString(stream, wxString(wxT("<stylesheet")) + nameAndDescr + wxT(">"), convMem, convFile);
d2d0adc7
JS
588
589 int i;
590
591 for (i = 0; i < (int) buffer->GetStyleSheet()->GetCharacterStyleCount(); i++)
592 {
593 wxRichTextCharacterStyleDefinition* def = buffer->GetStyleSheet()->GetCharacterStyle(i);
594 ExportStyleDefinition(stream, convMem, convFile, def, level + 1);
595 }
596
597 for (i = 0; i < (int) buffer->GetStyleSheet()->GetParagraphStyleCount(); i++)
598 {
599 wxRichTextParagraphStyleDefinition* def = buffer->GetStyleSheet()->GetParagraphStyle(i);
600 ExportStyleDefinition(stream, convMem, convFile, def, level + 1);
601 }
602
603 for (i = 0; i < (int) buffer->GetStyleSheet()->GetListStyleCount(); i++)
604 {
605 wxRichTextListStyleDefinition* def = buffer->GetStyleSheet()->GetListStyle(i);
606 ExportStyleDefinition(stream, convMem, convFile, def, level + 1);
607 }
608
609 OutputIndentation(stream, level);
610 OutputString(stream, wxT("</stylesheet>"), convMem, convFile);
611 }
612
613
614 bool success = ExportXML(stream, convMem, convFile, *buffer, level);
87eaa6f6 615
5d7836c4
JS
616 OutputString(stream, wxT("\n</richtext>") , NULL, NULL);
617 OutputString(stream, wxT("\n"), NULL, NULL);
7fe8059f 618
b71e9aa4
JS
619 if (deleteConvFile)
620 delete convFile;
88a7a4e1 621
b71e9aa4 622 return success;
5d7836c4
JS
623}
624
625/// Recursively export an object
626bool wxRichTextXMLHandler::ExportXML(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextObject& obj, int indent)
627{
628 wxString objectName;
629 if (obj.IsKindOf(CLASSINFO(wxRichTextParagraphLayoutBox)))
630 objectName = wxT("paragraphlayout");
631 else if (obj.IsKindOf(CLASSINFO(wxRichTextParagraph)))
632 objectName = wxT("paragraph");
633 else if (obj.IsKindOf(CLASSINFO(wxRichTextPlainText)))
634 objectName = wxT("text");
635 else if (obj.IsKindOf(CLASSINFO(wxRichTextImage)))
636 objectName = wxT("image");
637 else
638 objectName = wxT("object");
87eaa6f6 639
7b907278 640 bool terminateTag = true;
5d7836c4
JS
641
642 if (obj.IsKindOf(CLASSINFO(wxRichTextPlainText)))
643 {
7b907278 644 wxRichTextPlainText& textObj = (wxRichTextPlainText&) obj;
87eaa6f6 645
7b907278 646 wxString style = CreateStyle(obj.GetAttributes(), false);
87eaa6f6 647
7b907278
JS
648 int i;
649 int last = 0;
650 const wxString& text = textObj.GetText();
651 int len = (int) text.Length();
652 for (i = 0; i < len; i++)
653 {
654 int c = (int) text[i];
655 if (c < 32 && c != 9 && c != 10 && c != 13)
656 {
657 if (i > 0)
658 {
659 OutputIndentation(stream, indent);
660 OutputString(stream, wxT("<") + objectName, convMem, convFile);
5d7836c4 661
7b907278 662 OutputString(stream, style + wxT(">"), convMem, convFile);
7fe8059f 663
7b907278
JS
664 wxString fragment(text.Mid(last, i-last));
665 if (!fragment.empty() && (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' ')))
666 {
667 OutputString(stream, wxT("\""), convMem, convFile);
668 OutputStringEnt(stream, fragment, convMem, convFile);
669 OutputString(stream, wxT("\""), convMem, convFile);
670 }
671 else
672 OutputStringEnt(stream, fragment, convMem, convFile);
7fe8059f 673
7b907278 674 OutputString(stream, wxT("</text>"), convMem, convFile);
87eaa6f6
JS
675 }
676
7b907278
JS
677
678 // Output this character as a number in a separate tag, because XML can't cope
87eaa6f6 679 // with entities below 32 except for 9, 10 and 13
7b907278
JS
680 last = i + 1;
681 OutputIndentation(stream, indent);
682 OutputString(stream, wxT("<symbol"), convMem, convFile);
7fe8059f 683
7b907278 684 OutputString(stream, style + wxT(">"), convMem, convFile);
87eaa6f6 685 OutputString(stream, wxString::Format(wxT("%d"), c), convMem, convFile);
7b907278
JS
686
687 OutputString(stream, wxT("</symbol>"), convMem, convFile);
688 }
689 }
87eaa6f6 690
7b907278
JS
691 wxString fragment;
692 if (last == 0)
693 fragment = text;
694 else
695 fragment = text.Mid(last, i-last);
696
697 if (last < len)
5d7836c4 698 {
7b907278
JS
699 OutputIndentation(stream, indent);
700 OutputString(stream, wxT("<") + objectName, convMem, convFile);
701
702 OutputString(stream, style + wxT(">"), convMem, convFile);
703
704 if (!fragment.empty() && (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' ')))
705 {
706 OutputString(stream, wxT("\""), convMem, convFile);
707 OutputStringEnt(stream, fragment, convMem, convFile);
708 OutputString(stream, wxT("\""), convMem, convFile);
709 }
710 else
711 OutputStringEnt(stream, fragment, convMem, convFile);
5d7836c4
JS
712 }
713 else
7b907278 714 terminateTag = false;
5d7836c4
JS
715 }
716 else if (obj.IsKindOf(CLASSINFO(wxRichTextImage)))
717 {
718 wxRichTextImage& imageObj = (wxRichTextImage&) obj;
719
720 if (imageObj.GetImage().Ok() && !imageObj.GetImageBlock().Ok())
721 imageObj.MakeBlock();
722
723 OutputIndentation(stream, indent);
b71e9aa4 724 OutputString(stream, wxT("<") + objectName, convMem, convFile);
5d7836c4
JS
725 if (!imageObj.GetImageBlock().Ok())
726 {
727 // No data
b71e9aa4 728 OutputString(stream, wxT(">"), convMem, convFile);
5d7836c4
JS
729 }
730 else
731 {
b71e9aa4 732 OutputString(stream, wxString::Format(wxT(" imagetype=\"%d\">"), (int) imageObj.GetImageBlock().GetImageType()));
5d7836c4
JS
733 }
734
735 OutputIndentation(stream, indent+1);
b71e9aa4 736 OutputString(stream, wxT("<data>"), convMem, convFile);
5d7836c4
JS
737
738 imageObj.GetImageBlock().WriteHex(stream);
739
b71e9aa4 740 OutputString(stream, wxT("</data>"), convMem, convFile);
5d7836c4
JS
741 }
742 else if (obj.IsKindOf(CLASSINFO(wxRichTextCompositeObject)))
743 {
744 OutputIndentation(stream, indent);
b71e9aa4 745 OutputString(stream, wxT("<") + objectName, convMem, convFile);
7fe8059f 746
5d7836c4
JS
747 bool isPara = false;
748 if (objectName == wxT("paragraph") || objectName == wxT("paragraphlayout"))
749 isPara = true;
750
751 wxString style = CreateStyle(obj.GetAttributes(), isPara);
87eaa6f6 752
0ca07313
JS
753 if (objectName == wxT("paragraphlayout") && ((wxRichTextParagraphLayoutBox&) obj).GetPartialParagraph())
754 style << wxT(" partialparagraph=\"true\"");
755
b71e9aa4 756 OutputString(stream, style + wxT(">"), convMem, convFile);
7fe8059f 757
5d7836c4
JS
758 wxRichTextCompositeObject& composite = (wxRichTextCompositeObject&) obj;
759 size_t i;
760 for (i = 0; i < composite.GetChildCount(); i++)
761 {
762 wxRichTextObject* child = composite.GetChild(i);
763 ExportXML(stream, convMem, convFile, *child, indent+1);
764 }
765 }
766
767 if (objectName != wxT("text"))
768 OutputIndentation(stream, indent);
769
7b907278
JS
770 if (terminateTag)
771 OutputString(stream, wxT("</") + objectName + wxT(">"), convMem, convFile);
5d7836c4
JS
772
773 return true;
774}
775
d2d0adc7
JS
776bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextStyleDefinition* def, int level)
777{
87eaa6f6 778 wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
d2d0adc7
JS
779 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
780 wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
87eaa6f6 781
d2d0adc7
JS
782 wxString baseStyle = def->GetBaseStyle();
783 wxString baseStyleProp;
784 if (!baseStyle.IsEmpty())
785 baseStyleProp = wxT(" basestyle=\"") + baseStyle + wxT("\"");
87eaa6f6 786
42688aea
JS
787 wxString descr = def->GetDescription();
788 wxString descrProp;
789 if (!descr.IsEmpty())
790 descrProp = wxT(" description=\"") + descr + wxT("\"");
87eaa6f6 791
d2d0adc7
JS
792 if (charDef)
793 {
794 OutputIndentation(stream, level);
42688aea 795 OutputString(stream, wxT("<characterstyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
87eaa6f6 796
d2d0adc7
JS
797 level ++;
798
799 wxString style = CreateStyle(def->GetStyle(), false);
800
801 OutputIndentation(stream, level);
802 OutputString(stream, wxT("<style ") + style + wxT(">"), convMem, convFile);
87eaa6f6 803
d2d0adc7
JS
804 OutputIndentation(stream, level);
805 OutputString(stream, wxT("</style>"), convMem, convFile);
806
807 level --;
808
809 OutputIndentation(stream, level);
810 OutputString(stream, wxT("</characterstyle>"), convMem, convFile);
811 }
812 else if (listDef)
813 {
814 OutputIndentation(stream, level);
87eaa6f6 815
d2d0adc7
JS
816 if (!listDef->GetNextStyle().IsEmpty())
817 baseStyleProp << wxT(" basestyle=\"") << listDef->GetNextStyle() << wxT("\"");
87eaa6f6 818
42688aea 819 OutputString(stream, wxT("<liststyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
87eaa6f6 820
d2d0adc7
JS
821 level ++;
822
823 wxString style = CreateStyle(def->GetStyle(), false);
824
825 OutputIndentation(stream, level);
826 OutputString(stream, wxT("<style ") + style + wxT(">"), convMem, convFile);
87eaa6f6 827
d2d0adc7
JS
828 OutputIndentation(stream, level);
829 OutputString(stream, wxT("</style>"), convMem, convFile);
830
831 int i;
832 for (i = 0; i < 10; i ++)
833 {
834 wxRichTextAttr* levelAttr = listDef->GetLevelAttributes(i);
835 if (levelAttr)
836 {
837 wxString style = CreateStyle(def->GetStyle(), false);
838 wxString levelStr = wxString::Format(wxT(" level=\"%d\" "), (i+1));
839
840 OutputIndentation(stream, level);
841 OutputString(stream, wxT("<style ") + levelStr + style + wxT(">"), convMem, convFile);
87eaa6f6 842
d2d0adc7
JS
843 OutputIndentation(stream, level);
844 OutputString(stream, wxT("</style>"), convMem, convFile);
845 }
846 }
847
848 level --;
849
850 OutputIndentation(stream, level);
851 OutputString(stream, wxT("</liststyle>"), convMem, convFile);
852 }
853 else if (paraDef)
854 {
855 OutputIndentation(stream, level);
87eaa6f6
JS
856
857 if (!paraDef->GetNextStyle().IsEmpty())
858 baseStyleProp << wxT(" basestyle=\"") << paraDef->GetNextStyle() << wxT("\"");
859
42688aea 860 OutputString(stream, wxT("<paragraphstyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
87eaa6f6 861
d2d0adc7
JS
862 level ++;
863
864 wxString style = CreateStyle(def->GetStyle(), false);
865
866 OutputIndentation(stream, level);
867 OutputString(stream, wxT("<style ") + style + wxT(">"), convMem, convFile);
87eaa6f6 868
d2d0adc7
JS
869 OutputIndentation(stream, level);
870 OutputString(stream, wxT("</style>"), convMem, convFile);
87eaa6f6 871
d2d0adc7
JS
872 level --;
873
874 OutputIndentation(stream, level);
875 OutputString(stream, wxT("</paragraphstyle>"), convMem, convFile);
876 }
877
878 return true;
879}
880
5d7836c4
JS
881/// Create style parameters
882wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttrEx& attr, bool isPara)
883{
884 wxString str;
0ca07313 885 if (attr.HasTextColour() && attr.GetTextColour().Ok())
5d7836c4
JS
886 {
887 str << wxT(" textcolor=\"#") << ColourToHexString(attr.GetTextColour()) << wxT("\"");
888 }
0ca07313 889 if (attr.HasBackgroundColour() && attr.GetBackgroundColour().Ok())
5d7836c4
JS
890 {
891 str << wxT(" bgcolor=\"#") << ColourToHexString(attr.GetBackgroundColour()) << wxT("\"");
892 }
893
894 if (attr.GetFont().Ok())
895 {
336d8ae9 896 if (attr.HasFontSize())
0ca07313 897 str << wxT(" fontsize=\"") << attr.GetFont().GetPointSize() << wxT("\"");
87eaa6f6 898
336d8ae9 899 //if (attr.HasFontFamily())
0ca07313
JS
900 // str << wxT(" fontfamily=\"") << attr.GetFont().GetFamily() << wxT("\"");
901
336d8ae9 902 if (attr.HasFontItalic())
0ca07313
JS
903 str << wxT(" fontstyle=\"") << attr.GetFont().GetStyle() << wxT("\"");
904
336d8ae9 905 if (attr.HasFontWeight())
0ca07313
JS
906 str << wxT(" fontweight=\"") << attr.GetFont().GetWeight() << wxT("\"");
907
336d8ae9 908 if (attr.HasFontUnderlined())
0ca07313
JS
909 str << wxT(" fontunderlined=\"") << (int) attr.GetFont().GetUnderlined() << wxT("\"");
910
336d8ae9 911 if (attr.HasFontFaceName())
0ca07313 912 str << wxT(" fontface=\"") << attr.GetFont().GetFaceName() << wxT("\"");
5d7836c4
JS
913 }
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
JS
928
929 if (isPara)
930 {
0ca07313
JS
931 if (attr.HasAlignment())
932 str << wxT(" alignment=\"") << (int) attr.GetAlignment() << wxT("\"");
933
934 if (attr.HasLeftIndent())
935 {
936 str << wxT(" leftindent=\"") << (int) attr.GetLeftIndent() << wxT("\"");
937 str << wxT(" leftsubindent=\"") << (int) attr.GetLeftSubIndent() << wxT("\"");
938 }
939
940 if (attr.HasRightIndent())
941 str << wxT(" rightindent=\"") << (int) attr.GetRightIndent() << wxT("\"");
942
943 if (attr.HasParagraphSpacingAfter())
944 str << wxT(" parspacingafter=\"") << (int) attr.GetParagraphSpacingAfter() << wxT("\"");
945
946 if (attr.HasParagraphSpacingBefore())
947 str << wxT(" parspacingbefore=\"") << (int) attr.GetParagraphSpacingBefore() << wxT("\"");
948
949 if (attr.HasLineSpacing())
950 str << wxT(" linespacing=\"") << (int) attr.GetLineSpacing() << wxT("\"");
951
952 if (attr.HasBulletStyle())
953 str << wxT(" bulletstyle=\"") << (int) attr.GetBulletStyle() << wxT("\"");
954
955 if (attr.HasBulletNumber())
956 str << wxT(" bulletnumber=\"") << (int) attr.GetBulletNumber() << wxT("\"");
957
d2d0adc7 958 if (attr.HasBulletText())
7b907278 959 {
d2d0adc7
JS
960 // If using a bullet symbol, convert to integer in case it's a non-XML-friendly character.
961 // Otherwise, assume it's XML-friendly text such as outline numbering, e.g. 1.2.3.1
962 if (!attr.GetBulletText().IsEmpty() && (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL))
963 str << wxT(" bulletsymbol=\"") << (int) (attr.GetBulletText()[0]) << wxT("\"");
964 else
965 str << wxT(" bullettext=\"") << attr.GetBulletText() << wxT("\"");
87eaa6f6 966
7b907278
JS
967 str << wxT(" bulletfont=\"") << attr.GetBulletFont() << wxT("\"");
968 }
5d7836c4 969
f089713f
JS
970 if (attr.HasBulletName())
971 str << wxT(" bulletname=\"") << attr.GetBulletName() << wxT("\"");
972
d2d0adc7
JS
973 if (attr.HasURL())
974 str << wxT(" url=\"") << attr.GetURL() << wxT("\"");
87eaa6f6 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
1009bool wxRichTextXMLHandler::GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool isPara)
1010{
1011 wxString fontFacename;
1012 int fontSize = 12;
1013 int fontFamily = wxDEFAULT;
1014 int fontWeight = wxNORMAL;
1015 int fontStyle = wxNORMAL;
1016 bool fontUnderlined = false;
87eaa6f6 1017
0ca07313
JS
1018 int fontFlags = 0;
1019
5d7836c4 1020 fontFacename = node->GetPropVal(wxT("fontface"), wxEmptyString);
0ca07313
JS
1021 if (!fontFacename.IsEmpty())
1022 fontFlags |= wxTEXT_ATTR_FONT_FACE;
5d7836c4 1023
0ca07313
JS
1024 wxString value;
1025 //value = node->GetPropVal(wxT("fontfamily"), wxEmptyString);
1026 //if (!value.empty())
1027 // fontFamily = wxAtoi(value);
5d7836c4
JS
1028
1029 value = node->GetPropVal(wxT("fontstyle"), wxEmptyString);
7fe8059f 1030 if (!value.empty())
0ca07313 1031 {
5d7836c4 1032 fontStyle = wxAtoi(value);
0ca07313
JS
1033 fontFlags |= wxTEXT_ATTR_FONT_ITALIC;
1034 }
5d7836c4
JS
1035
1036 value = node->GetPropVal(wxT("fontsize"), wxEmptyString);
7fe8059f 1037 if (!value.empty())
0ca07313 1038 {
5d7836c4 1039 fontSize = wxAtoi(value);
0ca07313
JS
1040 fontFlags |= wxTEXT_ATTR_FONT_SIZE;
1041 }
5d7836c4
JS
1042
1043 value = node->GetPropVal(wxT("fontweight"), wxEmptyString);
7fe8059f 1044 if (!value.empty())
0ca07313 1045 {
5d7836c4 1046 fontWeight = wxAtoi(value);
0ca07313
JS
1047 fontFlags |= wxTEXT_ATTR_FONT_WEIGHT;
1048 }
5d7836c4
JS
1049
1050 value = node->GetPropVal(wxT("fontunderlined"), wxEmptyString);
7fe8059f 1051 if (!value.empty())
0ca07313 1052 {
5d7836c4 1053 fontUnderlined = wxAtoi(value) != 0;
0ca07313
JS
1054 fontFlags |= wxTEXT_ATTR_FONT_UNDERLINE;
1055 }
87eaa6f6 1056
0ca07313 1057 attr.SetFlags(fontFlags);
87eaa6f6 1058
0ca07313
JS
1059 if (attr.HasFlag(wxTEXT_ATTR_FONT))
1060 attr.SetFont(* wxTheFontList->FindOrCreateFont(fontSize, fontFamily, fontStyle, fontWeight, fontUnderlined, fontFacename));
1061
1062 // Restore correct font flags
1063 attr.SetFlags(fontFlags);
87eaa6f6 1064
5d7836c4 1065 value = node->GetPropVal(wxT("textcolor"), wxEmptyString);
7fe8059f 1066 if (!value.empty())
5d7836c4
JS
1067 {
1068 if (value[0] == wxT('#'))
1069 attr.SetTextColour(HexStringToColour(value.Mid(1)));
1070 else
1071 attr.SetTextColour(value);
1072 }
1073
1074 value = node->GetPropVal(wxT("backgroundcolor"), wxEmptyString);
7fe8059f 1075 if (!value.empty())
5d7836c4
JS
1076 {
1077 if (value[0] == wxT('#'))
1078 attr.SetBackgroundColour(HexStringToColour(value.Mid(1)));
1079 else
1080 attr.SetBackgroundColour(value);
1081 }
1082
1083 value = node->GetPropVal(wxT("characterstyle"), wxEmptyString);
7fe8059f 1084 if (!value.empty())
5d7836c4
JS
1085 attr.SetCharacterStyleName(value);
1086
42688aea
JS
1087 value = node->GetPropVal(wxT("texteffects"), wxEmptyString);
1088 if (!value.IsEmpty())
1089 {
1090 attr.SetTextEffects(wxAtoi(value));
1091 }
1092
1f65137f
JS
1093 value = node->GetPropVal(wxT("texteffectflags"), wxEmptyString);
1094 if (!value.IsEmpty())
1095 {
1096 attr.SetTextEffectFlags(wxAtoi(value));
1097 }
1098
5d7836c4
JS
1099 // Set paragraph attributes
1100 if (isPara)
1101 {
1102 value = node->GetPropVal(wxT("alignment"), wxEmptyString);
7fe8059f 1103 if (!value.empty())
5d7836c4
JS
1104 attr.SetAlignment((wxTextAttrAlignment) wxAtoi(value));
1105
1106 int leftSubIndent = 0;
1107 int leftIndent = 0;
0ca07313 1108 bool hasLeftIndent = false;
87eaa6f6 1109
5d7836c4 1110 value = node->GetPropVal(wxT("leftindent"), wxEmptyString);
7fe8059f 1111 if (!value.empty())
0ca07313 1112 {
5d7836c4 1113 leftIndent = wxAtoi(value);
0ca07313
JS
1114 hasLeftIndent = true;
1115 }
1116
5d7836c4 1117 value = node->GetPropVal(wxT("leftsubindent"), wxEmptyString);
7fe8059f 1118 if (!value.empty())
0ca07313 1119 {
5d7836c4 1120 leftSubIndent = wxAtoi(value);
0ca07313
JS
1121 hasLeftIndent = true;
1122 }
1123
1124 if (hasLeftIndent)
1125 attr.SetLeftIndent(leftIndent, leftSubIndent);
5d7836c4
JS
1126
1127 value = node->GetPropVal(wxT("rightindent"), wxEmptyString);
7fe8059f 1128 if (!value.empty())
5d7836c4
JS
1129 attr.SetRightIndent(wxAtoi(value));
1130
1131 value = node->GetPropVal(wxT("parspacingbefore"), wxEmptyString);
7fe8059f 1132 if (!value.empty())
5d7836c4
JS
1133 attr.SetParagraphSpacingBefore(wxAtoi(value));
1134
1135 value = node->GetPropVal(wxT("parspacingafter"), wxEmptyString);
7fe8059f 1136 if (!value.empty())
5d7836c4
JS
1137 attr.SetParagraphSpacingAfter(wxAtoi(value));
1138
1139 value = node->GetPropVal(wxT("linespacing"), wxEmptyString);
7fe8059f 1140 if (!value.empty())
5d7836c4
JS
1141 attr.SetLineSpacing(wxAtoi(value));
1142
1143 value = node->GetPropVal(wxT("bulletstyle"), wxEmptyString);
7fe8059f 1144 if (!value.empty())
5d7836c4
JS
1145 attr.SetBulletStyle(wxAtoi(value));
1146
1147 value = node->GetPropVal(wxT("bulletnumber"), wxEmptyString);
7fe8059f 1148 if (!value.empty())
5d7836c4
JS
1149 attr.SetBulletNumber(wxAtoi(value));
1150
1151 value = node->GetPropVal(wxT("bulletsymbol"), wxEmptyString);
7fe8059f 1152 if (!value.empty())
d2d0adc7
JS
1153 {
1154 wxChar ch = wxAtoi(value);
1155 wxString s;
1156 s << ch;
1157 attr.SetBulletText(s);
1158 }
1159
1160 value = node->GetPropVal(wxT("bullettext"), wxEmptyString);
1161 if (!value.empty())
1162 attr.SetBulletText(value);
7b907278
JS
1163
1164 value = node->GetPropVal(wxT("bulletfont"), wxEmptyString);
1165 if (!value.empty())
1166 attr.SetBulletFont(value);
5d7836c4 1167
f089713f
JS
1168 value = node->GetPropVal(wxT("bulletname"), wxEmptyString);
1169 if (!value.empty())
1170 attr.SetBulletName(value);
1171
d2d0adc7
JS
1172 value = node->GetPropVal(wxT("url"), wxEmptyString);
1173 if (!value.empty())
1174 attr.SetURL(value);
1175
5d7836c4 1176 value = node->GetPropVal(wxT("parstyle"), wxEmptyString);
7fe8059f 1177 if (!value.empty())
5d7836c4 1178 attr.SetParagraphStyleName(value);
87eaa6f6 1179
f089713f
JS
1180 value = node->GetPropVal(wxT("liststyle"), wxEmptyString);
1181 if (!value.empty())
1182 attr.SetListStyleName(value);
87eaa6f6 1183
0ca07313
JS
1184 value = node->GetPropVal(wxT("tabs"), wxEmptyString);
1185 if (!value.empty())
1186 {
1187 wxArrayInt tabs;
1188 wxStringTokenizer tkz(value, wxT(","));
1189 while (tkz.HasMoreTokens())
1190 {
1191 wxString token = tkz.GetNextToken();
1192 tabs.Add(wxAtoi(token));
1193 }
1194 attr.SetTabs(tabs);
1195 }
87eaa6f6 1196
42688aea
JS
1197 value = node->GetPropVal(wxT("pagebreak"), wxEmptyString);
1198 if (!value.IsEmpty())
1199 {
1200 attr.SetPageBreak(wxAtoi(value) != 0);
1201 }
4d6d8bf4
JS
1202
1203 value = node->GetPropVal(wxT("outlinelevel"), wxEmptyString);
1204 if (!value.IsEmpty())
1205 {
1206 attr.SetOutlineLevel(wxAtoi(value) != 0);
1207 }
5d7836c4
JS
1208 }
1209
1210 return true;
1211}
1212
1213#endif
b71e9aa4 1214 // wxUSE_STREAMS
88a7a4e1 1215
5d7836c4 1216#endif
fcdbeefa 1217 // wxUSE_RICHTEXT && wxUSE_XML
7b907278 1218