]> git.saurik.com Git - wxWidgets.git/blobdiff - src/richtext/richtextxml.cpp
another fix for the default button in the dialog
[wxWidgets.git] / src / richtext / richtextxml.cpp
index 801c5d2fbcf1fabf206a4ae4678fadad0b860c8b..3e03c7055988ff723424cb0f82550bc7e440b577 100644 (file)
@@ -41,6 +41,7 @@ bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& s
     if (!stream.IsOk())
         return false;
 
+    buffer->ResetAndClearCommands();
     buffer->Clear();
 
     wxXmlDocument* xmlDoc = new wxXmlDocument;
@@ -55,6 +56,7 @@ bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& s
 
     if (!xmlDoc->Load(stream, encoding))
     {
+        buffer->ResetAndClearCommands();
         success = false;
     }
     else
@@ -215,6 +217,10 @@ bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node)
         if (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET)
         {
             wxRichTextStyleSheet* sheet = new wxRichTextStyleSheet;
+            wxString sheetName = node->GetPropVal(wxT("name"), wxEmptyString);
+            wxString sheetDescription = node->GetPropVal(wxT("description"), wxEmptyString);
+            sheet->SetName(sheetName);
+            sheet->SetDescription(sheetDescription);
             
             wxXmlNode* child = node->GetChildren();
             while (child)
@@ -573,7 +579,12 @@ bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream&
     if (buffer->GetStyleSheet() && (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
     {
         OutputIndentation(stream, level);
-        OutputString(stream, wxT("<stylesheet>"), convMem, convFile);
+        wxString nameAndDescr;
+        if (!buffer->GetStyleSheet()->GetName().IsEmpty())
+            nameAndDescr << wxT(" name=\"") << buffer->GetStyleSheet()->GetName() << wxT("\"");
+        if (!buffer->GetStyleSheet()->GetDescription().IsEmpty())
+            nameAndDescr << wxT(" description=\"") << buffer->GetStyleSheet()->GetDescription() << wxT("\"");
+        OutputString(stream, wxString(wxT("<stylesheet")) + nameAndDescr + wxT(">"), convMem, convFile);
 
         int i;
 
@@ -773,10 +784,15 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxMBCon
     if (!baseStyle.IsEmpty())
         baseStyleProp = wxT(" basestyle=\"") + baseStyle + wxT("\"");
     
+    wxString descr = def->GetDescription();
+    wxString descrProp;
+    if (!descr.IsEmpty())
+        descrProp = wxT(" description=\"") + descr + wxT("\"");
+    
     if (charDef)
     {
         OutputIndentation(stream, level);
-        OutputString(stream, wxT("<characterstyle") + baseStyleProp + wxT(">"), convMem, convFile);
+        OutputString(stream, wxT("<characterstyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
         
         level ++;
 
@@ -800,7 +816,7 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxMBCon
         if (!listDef->GetNextStyle().IsEmpty())
             baseStyleProp << wxT(" basestyle=\"") << listDef->GetNextStyle() << wxT("\"");
         
-        OutputString(stream, wxT("<liststyle") + baseStyleProp + wxT(">"), convMem, convFile);
+        OutputString(stream, wxT("<liststyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
         
         level ++;
 
@@ -841,7 +857,7 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxMBCon
         if (!listDef->GetNextStyle().IsEmpty())
             baseStyleProp << wxT(" basestyle=\"") << listDef->GetNextStyle() << wxT("\"");
         
-        OutputString(stream, wxT("<paragraphstyle") + baseStyleProp + wxT(">"), convMem, convFile);
+        OutputString(stream, wxT("<paragraphstyle") + baseStyleProp + descrProp + wxT(">"), convMem, convFile);
         
         level ++;
 
@@ -877,25 +893,36 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttrEx& attr, bool isPara
 
     if (attr.GetFont().Ok())
     {
-        if (attr.HasSize())
+        if (attr.HasFontSize())
             str << wxT(" fontsize=\"") << attr.GetFont().GetPointSize() << wxT("\"");
         
-        //if (attr.HasFamily())
+        //if (attr.HasFontFamily())
         //    str << wxT(" fontfamily=\"") << attr.GetFont().GetFamily() << wxT("\"");
 
-        if (attr.HasItalic())
+        if (attr.HasFontItalic())
             str << wxT(" fontstyle=\"") << attr.GetFont().GetStyle() << wxT("\"");
 
-        if (attr.HasWeight())
+        if (attr.HasFontWeight())
             str << wxT(" fontweight=\"") << attr.GetFont().GetWeight() << wxT("\"");
 
-        if (attr.HasUnderlined())
+        if (attr.HasFontUnderlined())
             str << wxT(" fontunderlined=\"") << (int) attr.GetFont().GetUnderlined() << wxT("\"");
 
-        if (attr.HasFaceName())
+        if (attr.HasFontFaceName())
             str << wxT(" fontface=\"") << attr.GetFont().GetFaceName() << wxT("\"");
     }
 
+    if (attr.HasTextEffects())
+    {
+        str << wxT(" texteffects=\"");
+        str << attr.GetTextEffects();
+        str << wxT("\"");
+
+        str << wxT(" texteffectflags=\"");
+        str << attr.GetTextEffectFlags();
+        str << wxT("\"");
+    }
+
     if (!attr.GetCharacterStyleName().empty())
         str << wxT(" characterstyle=\"") << wxString(attr.GetCharacterStyleName()) << wxT("\"");
 
@@ -964,6 +991,15 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttrEx& attr, bool isPara
             }
             str << wxT("\"");            
         }
+        
+        if (attr.HasPageBreak())
+        {
+            str << wxT(" pagebreak=\"1\"");
+        }
+
+        if (attr.HasOutlineLevel())
+            str << wxT(" outlinelevel=\"") << (int) attr.GetOutlineLevel() << wxT("\"");
+
     }
 
     return str;
@@ -1048,6 +1084,18 @@ bool wxRichTextXMLHandler::GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool is
     if (!value.empty())
         attr.SetCharacterStyleName(value);
 
+    value = node->GetPropVal(wxT("texteffects"), wxEmptyString);
+    if (!value.IsEmpty())
+    {
+        attr.SetTextEffects(wxAtoi(value));
+    }
+
+    value = node->GetPropVal(wxT("texteffectflags"), wxEmptyString);
+    if (!value.IsEmpty())
+    {
+        attr.SetTextEffectFlags(wxAtoi(value));
+    }
+
     // Set paragraph attributes
     if (isPara)
     {
@@ -1145,6 +1193,18 @@ bool wxRichTextXMLHandler::GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool is
             }
             attr.SetTabs(tabs);
         }
+        
+        value = node->GetPropVal(wxT("pagebreak"), wxEmptyString);
+        if (!value.IsEmpty())
+        {
+            attr.SetPageBreak(wxAtoi(value) != 0);
+        }
+
+        value = node->GetPropVal(wxT("outlinelevel"), wxEmptyString);
+        if (!value.IsEmpty())
+        {
+            attr.SetOutlineLevel(wxAtoi(value) != 0);
+        }
     }
 
     return true;