From c6182d489c7cf71c9dba511e3f68671f5b17d50d Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 24 Apr 2012 11:22:18 +0000 Subject: [PATCH] Added custom properties to style definitions and style sheets git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71276 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/richtext/richtextstyles.h | 40 +++++++++++++++++++++++--- include/wx/richtext/richtextxml.h | 5 ++-- interface/wx/richtext/richtextbuffer.h | 4 +-- interface/wx/richtext/richtextstyles.h | 30 +++++++++++++++++++ src/richtext/richtextstyles.cpp | 4 ++- src/richtext/richtextxml.cpp | 22 +++++++++++++- 6 files changed, 95 insertions(+), 10 deletions(-) diff --git a/include/wx/richtext/richtextstyles.h b/include/wx/richtext/richtextstyles.h index e639144f7c..75efa9b1b0 100644 --- a/include/wx/richtext/richtextstyles.h +++ b/include/wx/richtext/richtextstyles.h @@ -101,11 +101,27 @@ public: /// Gets the style combined with the base style virtual wxRichTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const; + /** + Sets the definition's properties. + */ + wxRichTextProperties& GetProperties() { return m_properties; } + + /** + Returns the definition's properties. + */ + const wxRichTextProperties& GetProperties() const { return m_properties; } + + /** + Returns the definition's properties. + */ + void SetProperties(const wxRichTextProperties& props) { m_properties = props; } + protected: - wxString m_name; - wxString m_baseStyle; - wxString m_description; - wxRichTextAttr m_style; + wxString m_name; + wxString m_baseStyle; + wxString m_description; + wxRichTextAttr m_style; + wxRichTextProperties m_properties; }; /*! @@ -402,6 +418,21 @@ public: void SetDescription(const wxString& descr) { m_description = descr; } const wxString& GetDescription() const { return m_description; } + /** + Sets the definition's properties. + */ + wxRichTextProperties& GetProperties() { return m_properties; } + + /** + Returns the definition's properties. + */ + const wxRichTextProperties& GetProperties() const { return m_properties; } + + /** + Returns the definition's properties. + */ + void SetProperties(const wxRichTextProperties& props) { m_properties = props; } + /// Implementation /// Add a definition to one of the style lists @@ -425,6 +456,7 @@ protected: wxRichTextStyleSheet* m_previousSheet; wxRichTextStyleSheet* m_nextSheet; + wxRichTextProperties m_properties; }; #if wxUSE_HTML diff --git a/include/wx/richtext/richtextxml.h b/include/wx/richtext/richtextxml.h index d51d2043e5..44a933cb48 100644 --- a/include/wx/richtext/richtextxml.h +++ b/include/wx/richtext/richtextxml.h @@ -35,7 +35,7 @@ public: wxRichTextXMLHandler(const wxString& name = wxT("XML"), const wxString& ext = wxT("xml"), int type = wxRICHTEXT_TYPE_XML) : wxRichTextFileHandler(name, ext, type) { Init(); } - + void Init(); #if wxUSE_STREAMS @@ -69,6 +69,7 @@ public: bool ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* obj, wxXmlNode* node); bool ImportStyleDefinition(wxRichTextStyleSheet* sheet, wxXmlNode* node); bool ImportProperties(wxRichTextObject* obj, wxXmlNode* node); + bool ImportProperties(wxRichTextProperties& properties, wxXmlNode* node); /// Import style parameters bool ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bool isPara = false); @@ -76,7 +77,7 @@ public: /// Creates an object given an XML element name virtual wxRichTextObject* CreateObjectForXMLName(wxRichTextObject* parent, const wxString& name) const; - + /// Can we save using this handler? virtual bool CanSave() const { return true; } diff --git a/interface/wx/richtext/richtextbuffer.h b/interface/wx/richtext/richtextbuffer.h index 0e4c5b2d3a..3525641fd2 100644 --- a/interface/wx/richtext/richtextbuffer.h +++ b/interface/wx/richtext/richtextbuffer.h @@ -2377,7 +2377,7 @@ public: wxRichTextAttr& GetAttributes() { return m_attributes; } /** - Sets the object's properties. + Returns the object's properties. */ wxRichTextProperties& GetProperties() { return m_properties; } @@ -2387,7 +2387,7 @@ public: const wxRichTextProperties& GetProperties() const { return m_properties; } /** - Returns the object's properties. + Sets the object's properties. */ void SetProperties(const wxRichTextProperties& props) { m_properties = props; } diff --git a/interface/wx/richtext/richtextstyles.h b/interface/wx/richtext/richtextstyles.h index c1c636fef8..e89f8fa7f9 100644 --- a/interface/wx/richtext/richtextstyles.h +++ b/interface/wx/richtext/richtextstyles.h @@ -179,6 +179,21 @@ public: Sets the attributes for this style. */ void SetStyle(const wxTextAttr& style); + + /** + Returns the definition's properties. + */ + wxRichTextProperties& GetProperties(); + + /** + Returns the definition's properties. + */ + const wxRichTextProperties& GetProperties() const; + + /** + Sets the definition's properties. + */ + void SetProperties(const wxRichTextProperties& props); }; @@ -662,5 +677,20 @@ public: Sets the style sheet's name. */ void SetName(const wxString& name); + + /** + Returns the sheet's properties. + */ + wxRichTextProperties& GetProperties(); + + /** + Returns the sheet's properties. + */ + const wxRichTextProperties& GetProperties() const; + + /** + Sets the sheet's properties. + */ + void SetProperties(const wxRichTextProperties& props); }; diff --git a/src/richtext/richtextstyles.cpp b/src/richtext/richtextstyles.cpp index 86e64ccfbb..cac6a8b1d6 100644 --- a/src/richtext/richtextstyles.cpp +++ b/src/richtext/richtextstyles.cpp @@ -47,11 +47,12 @@ void wxRichTextStyleDefinition::Copy(const wxRichTextStyleDefinition& def) m_baseStyle = def.m_baseStyle; m_style = def.m_style; m_description = def.m_description; + m_properties = def.m_properties; } bool wxRichTextStyleDefinition::Eq(const wxRichTextStyleDefinition& def) const { - return (m_name == def.m_name && m_baseStyle == def.m_baseStyle && m_style == def.m_style); + return (m_name == def.m_name && m_baseStyle == def.m_baseStyle && m_style == def.m_style && m_properties == def.m_properties); } /// Gets the style combined with the base style @@ -523,6 +524,7 @@ void wxRichTextStyleSheet::Copy(const wxRichTextStyleSheet& sheet) SetName(sheet.GetName()); SetDescription(sheet.GetDescription()); + m_properties = sheet.m_properties; } /// Equality diff --git a/src/richtext/richtextxml.cpp b/src/richtext/richtextxml.cpp index f78883c8be..e798ee5935 100644 --- a/src/richtext/richtextxml.cpp +++ b/src/richtext/richtextxml.cpp @@ -207,6 +207,11 @@ bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* } bool wxRichTextXMLHandler::ImportProperties(wxRichTextObject* obj, wxXmlNode* node) +{ + return ImportProperties(obj->GetProperties(), node); +} + +bool wxRichTextXMLHandler::ImportProperties(wxRichTextProperties& properties, wxXmlNode* node) { wxXmlNode* child = node->GetChildren(); while (child) @@ -225,7 +230,7 @@ bool wxRichTextXMLHandler::ImportProperties(wxRichTextObject* obj, wxXmlNode* no wxVariant var = MakePropertyFromString(name, value, type); if (!var.IsNull()) { - obj->GetProperties().SetProperty(var); + properties.SetProperty(var); } } propertyChild = propertyChild->GetNext(); @@ -262,6 +267,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddCharacterStyle(def); } else if (styleType == wxT("paragraphstyle")) @@ -284,6 +291,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddParagraphStyle(def); } else if (styleType == wxT("boxstyle")) @@ -304,6 +313,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddBoxStyle(def); } else if (styleType == wxT("liststyle")) @@ -339,6 +350,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddListStyle(def); } @@ -835,6 +848,8 @@ bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& wxRichTextBoxStyleDefinition* def = buffer->GetStyleSheet()->GetBoxStyle(i); ExportStyleDefinition(styleSheetNode, def); } + + WriteProperties(styleSheetNode, buffer->GetStyleSheet()->GetProperties()); } bool success = ExportXML(rootNode, *buffer); #if wxRICHTEXT_USE_OUTPUT_TIMINGS @@ -910,6 +925,8 @@ bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& ExportStyleDefinition(stream, def, level + 1); } + WriteProperties(stream, buffer->GetStyleSheet()->GetProperties(), level); + OutputIndentation(stream, level); OutputString(stream, wxT("")); } @@ -1373,6 +1390,8 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxXmlNode* parent, wxRichTextSt AddAttributes(styleNode, def->GetStyle(), true); } + WriteProperties(defNode, def->GetProperties()); + return true; } @@ -2532,6 +2551,7 @@ bool wxRichTextParagraphLayoutBox::ImportFromXML(wxRichTextBuffer* buffer, wxXml child2 = child2->GetNext(); } + handler->ImportProperties(sheet->GetProperties(), child); // Notify that styles have changed. If this is vetoed by the app, // the new sheet will be deleted. If it is not vetoed, the -- 2.45.2