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