From cfa29fb3ca210ae4b4116e2d82b5e975036b25b4 Mon Sep 17 00:00:00 2001 From: andiwand Date: Sun, 3 Dec 2023 15:45:41 +0100 Subject: [PATCH] tmp --- src/odr/document.cpp | 4 +- src/odr/internal/abstract/document.hpp | 6 +- .../internal/abstract/document_element.hpp | 3 + src/odr/internal/odf/odf_document.cpp | 4 +- src/odr/internal/odf/odf_document.hpp | 4 +- src/odr/internal/odf/odf_element.cpp | 85 +++++-------------- src/odr/internal/odf/odf_element.hpp | 53 ++++++------ .../ooxml_presentation_document.cpp | 4 +- .../ooxml_presentation_document.hpp | 4 +- .../ooxml_presentation_element.cpp | 7 ++ .../ooxml_presentation_element.hpp | 2 + .../ooxml_spreadsheet_document.cpp | 4 +- .../ooxml_spreadsheet_document.hpp | 4 +- .../spreadsheet/ooxml_spreadsheet_element.cpp | 7 ++ .../spreadsheet/ooxml_spreadsheet_element.hpp | 2 + .../ooxml/text/ooxml_text_document.cpp | 4 +- .../ooxml/text/ooxml_text_document.hpp | 4 +- .../ooxml/text/ooxml_text_element.cpp | 7 ++ .../ooxml/text/ooxml_text_element.hpp | 2 + 19 files changed, 101 insertions(+), 109 deletions(-) diff --git a/src/odr/document.cpp b/src/odr/document.cpp index 10f54ac4..195ea91f 100644 --- a/src/odr/document.cpp +++ b/src/odr/document.cpp @@ -17,10 +17,10 @@ Document::Document(std::shared_ptr document) } } -bool Document::editable() const noexcept { return m_document->editable(); } +bool Document::editable() const noexcept { return m_document->is_editable(); } bool Document::savable(const bool encrypted) const noexcept { - return m_document->savable(encrypted); + return m_document->is_savable(encrypted); } void Document::save(const std::string &path) const { m_document->save(path); } diff --git a/src/odr/internal/abstract/document.hpp b/src/odr/internal/abstract/document.hpp index b58daa07..a6c35b6a 100644 --- a/src/odr/internal/abstract/document.hpp +++ b/src/odr/internal/abstract/document.hpp @@ -24,11 +24,11 @@ class Document { virtual ~Document() = default; /// \return `true` if the document is editable in any way. - [[nodiscard]] virtual bool editable() const noexcept = 0; + [[nodiscard]] virtual bool is_editable() const noexcept = 0; /// \param encrypted to ask for encrypted saves. - /// \return `true` if the document is savable. - [[nodiscard]] virtual bool savable(bool encrypted) const noexcept = 0; + /// \return `true` if the document is is_savable. + [[nodiscard]] virtual bool is_savable(bool encrypted) const noexcept = 0; /// \param path the destination path. virtual void save(const common::Path &path) const = 0; diff --git a/src/odr/internal/abstract/document_element.hpp b/src/odr/internal/abstract/document_element.hpp index e387ecf6..2af8badc 100644 --- a/src/odr/internal/abstract/document_element.hpp +++ b/src/odr/internal/abstract/document_element.hpp @@ -37,6 +37,9 @@ class Element { [[nodiscard]] virtual Element *last_child(const Document *) const = 0; [[nodiscard]] virtual Element *previous_sibling(const Document *) const = 0; [[nodiscard]] virtual Element *next_sibling(const Document *) const = 0; + + [[nodiscard]] virtual bool + is_editable(const abstract::Document *document) const = 0; }; class TextRoot : public virtual Element { diff --git a/src/odr/internal/odf/odf_document.cpp b/src/odr/internal/odf/odf_document.cpp index 7c4bc15a..96f0ff5f 100644 --- a/src/odr/internal/odf/odf_document.cpp +++ b/src/odr/internal/odf/odf_document.cpp @@ -34,9 +34,9 @@ Document::Document(const FileType file_type, const DocumentType document_type, m_styles_xml.document_element()); } -bool Document::editable() const noexcept { return true; } +bool Document::is_editable() const noexcept { return true; } -bool Document::savable(const bool encrypted) const noexcept { +bool Document::is_savable(const bool encrypted) const noexcept { return !encrypted; } diff --git a/src/odr/internal/odf/odf_document.hpp b/src/odr/internal/odf/odf_document.hpp index 07cc59a8..ec3f78ff 100644 --- a/src/odr/internal/odf/odf_document.hpp +++ b/src/odr/internal/odf/odf_document.hpp @@ -24,8 +24,8 @@ class Document : public common::TemplateDocument { Document(FileType file_type, DocumentType document_type, std::shared_ptr files); - bool editable() const noexcept final; - bool savable(bool encrypted) const noexcept final; + bool is_editable() const noexcept final; + bool is_savable(bool encrypted) const noexcept final; void save(const common::Path &path) const final; void save(const common::Path &path, const char *password) const final; diff --git a/src/odr/internal/odf/odf_element.cpp b/src/odr/internal/odf/odf_element.cpp index 3525fff7..7f27a312 100644 --- a/src/odr/internal/odf/odf_element.cpp +++ b/src/odr/internal/odf/odf_element.cpp @@ -58,6 +58,13 @@ Element::intermediate_style(const abstract::Document *document) const { return base; } +bool Element::is_editable(const abstract::Document *document) const { + if (m_parent == nullptr) { + return document_(document)->is_editable(); + } + return m_parent->is_editable(document); +} + const char *Element::style_name_(const abstract::Document *) const { return default_style_name(m_node); } @@ -70,14 +77,10 @@ const StyleRegistry *Element::style_(const abstract::Document *document) { return &static_cast(document)->m_style_registry; } -Root::Root(pugi::xml_node node) : Element(node) {} - ElementType Root::type(const abstract::Document *) const { return ElementType::root; } -TextRoot::TextRoot(pugi::xml_node node) : Root(node) {} - ElementType TextRoot::type(const abstract::Document *) const { return ElementType::root; } @@ -98,12 +101,6 @@ TextRoot::first_master_page(const abstract::Document *document) const { return {}; } -PresentationRoot::PresentationRoot(pugi::xml_node node) : Root(node) {} - -DrawingRoot::DrawingRoot(pugi::xml_node node) : Root(node) {} - -MasterPage::MasterPage(pugi::xml_node node) : Element(node) {} - PageLayout MasterPage::page_layout(const abstract::Document *document) const { if (auto attribute = m_node.attribute("style:page-layout-name")) { return style_(document)->page_layout(attribute.value()); @@ -111,8 +108,6 @@ PageLayout MasterPage::page_layout(const abstract::Document *document) const { return {}; } -Slide::Slide(pugi::xml_node node) : Element(node) {} - PageLayout Slide::page_layout(const abstract::Document *document) const { if (auto master_page = dynamic_cast(this->master_page(document))) { @@ -133,8 +128,6 @@ std::string Slide::name(const abstract::Document *) const { return m_node.attribute("draw:name").value(); } -Page::Page(pugi::xml_node node) : Element(node) {} - PageLayout Page::page_layout(const abstract::Document *document) const { if (auto master_page = dynamic_cast(this->master_page(document))) { @@ -154,14 +147,10 @@ std::string Page::name(const abstract::Document *) const { return m_node.attribute("draw:name").value(); } -LineBreak::LineBreak(pugi::xml_node node) : Element(node) {} - TextStyle LineBreak::style(const abstract::Document *document) const { return intermediate_style(document).text_style; } -Paragraph::Paragraph(pugi::xml_node node) : Element(node) {} - ParagraphStyle Paragraph::style(const abstract::Document *document) const { return intermediate_style(document).paragraph_style; } @@ -170,28 +159,10 @@ TextStyle Paragraph::text_style(const abstract::Document *document) const { return intermediate_style(document).text_style; } -Span::Span(pugi::xml_node node) : Element(node) {} - TextStyle Span::style(const abstract::Document *document) const { return intermediate_style(document).text_style; } -std::string Text::text(const pugi::xml_node node) { - if (node.type() == pugi::node_pcdata) { - return node.value(); - } - - std::string name = node.name(); - if (name == "text:s") { - const auto count = node.attribute("text:c").as_uint(1); - return std::string(count, ' '); - } - if (name == "text:tab") { - return "\t"; - } - return ""; -} - Text::Text(pugi::xml_node node) : Text(node, node) {} Text::Text(pugi::xml_node first, pugi::xml_node last) @@ -206,7 +177,7 @@ std::string Text::content(const abstract::Document *) const { std::string result; for (auto node = m_node; node != m_last.next_sibling(); node = node.next_sibling()) { - result += text(node); + result += text_(node); } return result; } @@ -243,26 +214,34 @@ TextStyle Text::style(const abstract::Document *document) const { return intermediate_style(document).text_style; } -Link::Link(pugi::xml_node node) : Element(node) {} +std::string Text::text_(const pugi::xml_node node) { + if (node.type() == pugi::node_pcdata) { + return node.value(); + } + + std::string name = node.name(); + if (name == "text:s") { + const auto count = node.attribute("text:c").as_uint(1); + return std::string(count, ' '); + } + if (name == "text:tab") { + return "\t"; + } + return ""; +} std::string Link::href(const abstract::Document *) const { return m_node.attribute("xlink:href").value(); } -Bookmark::Bookmark(pugi::xml_node node) : Element(node) {} - std::string Bookmark::name(const abstract::Document *) const { return m_node.attribute("text:name").value(); } -ListItem::ListItem(pugi::xml_node node) : Element(node) {} - TextStyle ListItem::style(const abstract::Document *document) const { return intermediate_style(document).text_style; } -Table::Table(pugi::xml_node node) : Element(node) {} - TableStyle Table::style(const abstract::Document *document) const { return partial_style(document).table_style; } @@ -291,20 +270,14 @@ TableDimensions Table::dimensions(const abstract::Document *) const { return result; } -TableColumn::TableColumn(pugi::xml_node node) : Element(node) {} - TableColumnStyle TableColumn::style(const abstract::Document *document) const { return partial_style(document).table_column_style; } -TableRow::TableRow(pugi::xml_node node) : Element(node) {} - TableRowStyle TableRow::style(const abstract::Document *document) const { return partial_style(document).table_row_style; } -TableCell::TableCell(pugi::xml_node node) : Element(node) {} - bool TableCell::covered(const abstract::Document *) const { return std::strcmp(m_node.name(), "table:covered-table-cell") == 0; } @@ -326,8 +299,6 @@ TableCellStyle TableCell::style(const abstract::Document *document) const { return partial_style(document).table_cell_style; } -Frame::Frame(pugi::xml_node node) : Element(node) {} - AnchorType Frame::anchor_type(const abstract::Document *) const { auto anchor_type = m_node.attribute("text:anchor-type").value(); if (std::strcmp("as-char", anchor_type) == 0) { @@ -384,8 +355,6 @@ GraphicStyle Frame::style(const abstract::Document *document) const { return intermediate_style(document).graphic_style; } -Rect::Rect(pugi::xml_node node) : Element(node) {} - std::string Rect::x(const abstract::Document *) const { return m_node.attribute("svg:x").value(); } @@ -406,8 +375,6 @@ GraphicStyle Rect::style(const abstract::Document *document) const { return intermediate_style(document).graphic_style; } -Line::Line(pugi::xml_node node) : Element(node) {} - std::string Line::x1(const abstract::Document *) const { return m_node.attribute("svg:x1").value(); } @@ -428,8 +395,6 @@ GraphicStyle Line::style(const abstract::Document *document) const { return intermediate_style(document).graphic_style; } -Circle::Circle(pugi::xml_node node) : Element(node) {} - std::string Circle::x(const abstract::Document *) const { return m_node.attribute("svg:x").value(); } @@ -450,8 +415,6 @@ GraphicStyle Circle::style(const abstract::Document *document) const { return intermediate_style(document).graphic_style; } -CustomShape::CustomShape(pugi::xml_node node) : Element(node) {} - std::optional CustomShape::x(const abstract::Document *) const { return m_node.attribute("svg:x").value(); } @@ -472,8 +435,6 @@ GraphicStyle CustomShape::style(const abstract::Document *document) const { return intermediate_style(document).graphic_style; } -Image::Image(pugi::xml_node node) : Element(node) {} - bool Image::internal(const abstract::Document *document) const { auto doc = document_(document); if (!doc || !doc->files()) { diff --git a/src/odr/internal/odf/odf_element.hpp b/src/odr/internal/odf/odf_element.hpp index 0fb0f732..5a7c6303 100644 --- a/src/odr/internal/odf/odf_element.hpp +++ b/src/odr/internal/odf/odf_element.hpp @@ -4,7 +4,6 @@ #include #include #include - #include namespace pugi { @@ -23,6 +22,8 @@ class Element : public virtual common::Element { virtual common::ResolvedStyle intermediate_style(const abstract::Document *) const; + bool is_editable(const abstract::Document *document) const override; + protected: pugi::xml_node m_node; @@ -43,14 +44,14 @@ template class DefaultElement : public Element { class Root : public Element { public: - explicit Root(pugi::xml_node); + using Element::Element; [[nodiscard]] ElementType type(const abstract::Document *) const override; }; class TextRoot final : public Root, public abstract::TextRoot { public: - explicit TextRoot(pugi::xml_node); + using Root::Root; [[nodiscard]] ElementType type(const abstract::Document *) const final; @@ -62,24 +63,24 @@ class TextRoot final : public Root, public abstract::TextRoot { class PresentationRoot final : public Root { public: - explicit PresentationRoot(pugi::xml_node); + using Root::Root; }; class DrawingRoot final : public Root { public: - explicit DrawingRoot(pugi::xml_node); + using Root::Root; }; class MasterPage final : public Element, public abstract::MasterPage { public: - explicit MasterPage(pugi::xml_node); + using Element::Element; [[nodiscard]] PageLayout page_layout(const abstract::Document *) const final; }; class Slide final : public Element, public abstract::Slide { public: - explicit Slide(pugi::xml_node); + using Element::Element; [[nodiscard]] PageLayout page_layout(const abstract::Document *) const final; @@ -91,7 +92,7 @@ class Slide final : public Element, public abstract::Slide { class Page final : public Element, public abstract::Page { public: - explicit Page(pugi::xml_node); + using Element::Element; [[nodiscard]] PageLayout page_layout(const abstract::Document *) const final; @@ -103,14 +104,14 @@ class Page final : public Element, public abstract::Page { class LineBreak final : public Element, public abstract::LineBreak { public: - explicit LineBreak(pugi::xml_node); + using Element::Element; [[nodiscard]] TextStyle style(const abstract::Document *) const final; }; class Paragraph final : public Element, public abstract::Paragraph { public: - explicit Paragraph(pugi::xml_node); + using Element::Element; [[nodiscard]] ParagraphStyle style(const abstract::Document *) const final; @@ -119,15 +120,13 @@ class Paragraph final : public Element, public abstract::Paragraph { class Span final : public Element, public abstract::Span { public: - explicit Span(pugi::xml_node); + using Element::Element; [[nodiscard]] TextStyle style(const abstract::Document *) const final; }; class Text final : public Element, public abstract::Text { public: - static std::string text(const pugi::xml_node); - explicit Text(pugi::xml_node); Text(pugi::xml_node first, pugi::xml_node last); @@ -139,32 +138,34 @@ class Text final : public Element, public abstract::Text { private: pugi::xml_node m_last; + + static std::string text_(const pugi::xml_node); }; class Link final : public Element, public abstract::Link { public: - explicit Link(pugi::xml_node); + using Element::Element; [[nodiscard]] std::string href(const abstract::Document *) const final; }; class Bookmark final : public Element, public abstract::Bookmark { public: - explicit Bookmark(pugi::xml_node); + using Element::Element; [[nodiscard]] std::string name(const abstract::Document *) const final; }; class ListItem final : public Element, public abstract::ListItem { public: - explicit ListItem(pugi::xml_node); + using Element::Element; [[nodiscard]] TextStyle style(const abstract::Document *) const final; }; class Table : public Element, public common::Table { public: - explicit Table(pugi::xml_node); + using Element::Element; [[nodiscard]] TableStyle style(const abstract::Document *) const final; @@ -174,21 +175,21 @@ class Table : public Element, public common::Table { class TableColumn final : public Element, public abstract::TableColumn { public: - explicit TableColumn(pugi::xml_node); + using Element::Element; [[nodiscard]] TableColumnStyle style(const abstract::Document *) const final; }; class TableRow final : public Element, public abstract::TableRow { public: - explicit TableRow(pugi::xml_node); + using Element::Element; [[nodiscard]] TableRowStyle style(const abstract::Document *) const final; }; class TableCell final : public Element, public abstract::TableCell { public: - explicit TableCell(pugi::xml_node); + using Element::Element; [[nodiscard]] bool covered(const abstract::Document *) const final; @@ -201,7 +202,7 @@ class TableCell final : public Element, public abstract::TableCell { class Frame final : public Element, public abstract::Frame { public: - explicit Frame(pugi::xml_node); + using Element::Element; [[nodiscard]] AnchorType anchor_type(const abstract::Document *) const final; @@ -222,7 +223,7 @@ class Frame final : public Element, public abstract::Frame { class Rect final : public Element, public abstract::Rect { public: - explicit Rect(pugi::xml_node); + using Element::Element; [[nodiscard]] std::string x(const abstract::Document *) const final; [[nodiscard]] std::string y(const abstract::Document *) const final; @@ -234,7 +235,7 @@ class Rect final : public Element, public abstract::Rect { class Line final : public Element, public abstract::Line { public: - explicit Line(pugi::xml_node); + using Element::Element; [[nodiscard]] std::string x1(const abstract::Document *) const final; [[nodiscard]] std::string y1(const abstract::Document *) const final; @@ -246,7 +247,7 @@ class Line final : public Element, public abstract::Line { class Circle final : public Element, public abstract::Circle { public: - explicit Circle(pugi::xml_node); + using Element::Element; [[nodiscard]] std::string x(const abstract::Document *) const final; [[nodiscard]] std::string y(const abstract::Document *) const final; @@ -258,7 +259,7 @@ class Circle final : public Element, public abstract::Circle { class CustomShape final : public Element, public abstract::CustomShape { public: - explicit CustomShape(pugi::xml_node); + using Element::Element; [[nodiscard]] std::optional x(const abstract::Document *) const final; @@ -272,7 +273,7 @@ class CustomShape final : public Element, public abstract::CustomShape { class Image final : public Element, public abstract::Image { public: - explicit Image(pugi::xml_node); + using Element::Element; [[nodiscard]] bool internal(const abstract::Document *) const final; diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp index c3cdaae1..3d1d30c8 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp @@ -25,9 +25,9 @@ Document::Document(std::shared_ptr filesystem) } } -bool Document::editable() const noexcept { return false; } +bool Document::is_editable() const noexcept { return false; } -bool Document::savable(const bool /*encrypted*/) const noexcept { +bool Document::is_savable(const bool /*encrypted*/) const noexcept { return false; } diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp index 77b9c434..0a89985b 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp @@ -15,8 +15,8 @@ class Document final : public common::TemplateDocument { public: explicit Document(std::shared_ptr filesystem); - [[nodiscard]] bool editable() const noexcept final; - [[nodiscard]] bool savable(bool encrypted) const noexcept final; + [[nodiscard]] bool is_editable() const noexcept final; + [[nodiscard]] bool is_savable(bool encrypted) const noexcept final; void save(const common::Path &path) const final; void save(const common::Path &path, const char *password) const final; diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp index 7f6483f6..66405bff 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp @@ -31,6 +31,13 @@ Element::intermediate_style(const abstract::Document *document) const { return base; } +bool Element::is_editable(const abstract::Document *document) const { + if (m_parent == nullptr) { + return document_(document)->is_editable(); + } + return m_parent->is_editable(document); +} + const Document *Element::document_(const abstract::Document *document) { return dynamic_cast(document); } diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp index 8fdc3a9c..4967303e 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp @@ -19,6 +19,8 @@ class Element : public common::Element { common::ResolvedStyle partial_style(const abstract::Document *) const; common::ResolvedStyle intermediate_style(const abstract::Document *) const; + bool is_editable(const abstract::Document *document) const override; + protected: static const Document *document_(const abstract::Document *); static pugi::xml_node slide_(const abstract::Document *, diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp index 43b72897..493cb214 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp @@ -52,9 +52,9 @@ Document::Document(std::shared_ptr filesystem) } } -bool Document::editable() const noexcept { return false; } +bool Document::is_editable() const noexcept { return false; } -bool Document::savable(const bool /*encrypted*/) const noexcept { +bool Document::is_savable(const bool /*encrypted*/) const noexcept { return false; } diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp index 0f1b0f4b..063c5db3 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp @@ -20,8 +20,8 @@ class Document final : public common::TemplateDocument { public: explicit Document(std::shared_ptr filesystem); - [[nodiscard]] bool editable() const noexcept final; - [[nodiscard]] bool savable(bool encrypted) const noexcept final; + [[nodiscard]] bool is_editable() const noexcept final; + [[nodiscard]] bool is_savable(bool encrypted) const noexcept final; void save(const common::Path &path) const final; void save(const common::Path &path, const char *password) const final; diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp index db32b54e..3dc8311e 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp @@ -34,6 +34,13 @@ Element::intermediate_style(const abstract::Document *document) const { return base; } +bool Element::is_editable(const abstract::Document *document) const { + if (m_parent == nullptr) { + return document_(document)->is_editable(); + } + return m_parent->is_editable(document); +} + const Document *Element::document_(const abstract::Document *document) { return dynamic_cast(document); } diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp index 479a012a..ffe92f01 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp @@ -21,6 +21,8 @@ class Element : public common::Element { virtual common::ResolvedStyle partial_style(const abstract::Document *) const; common::ResolvedStyle intermediate_style(const abstract::Document *) const; + bool is_editable(const abstract::Document *) const override; + protected: pugi::xml_node m_node; diff --git a/src/odr/internal/ooxml/text/ooxml_text_document.cpp b/src/odr/internal/ooxml/text/ooxml_text_document.cpp index ae05ca88..db428324 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_document.cpp +++ b/src/odr/internal/ooxml/text/ooxml_text_document.cpp @@ -31,9 +31,9 @@ Document::Document(std::shared_ptr filesystem) m_style_registry = StyleRegistry(m_styles_xml.document_element()); } -bool Document::editable() const noexcept { return false; } +bool Document::is_editable() const noexcept { return false; } -bool Document::savable(const bool encrypted) const noexcept { +bool Document::is_savable(const bool encrypted) const noexcept { return !encrypted; } diff --git a/src/odr/internal/ooxml/text/ooxml_text_document.hpp b/src/odr/internal/ooxml/text/ooxml_text_document.hpp index 8de3b6e5..1599580d 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_document.hpp +++ b/src/odr/internal/ooxml/text/ooxml_text_document.hpp @@ -20,8 +20,8 @@ class Document final : public common::TemplateDocument { public: explicit Document(std::shared_ptr filesystem); - [[nodiscard]] bool editable() const noexcept final; - [[nodiscard]] bool savable(bool encrypted) const noexcept final; + [[nodiscard]] bool is_editable() const noexcept final; + [[nodiscard]] bool is_savable(bool encrypted) const noexcept final; void save(const common::Path &path) const final; void save(const common::Path &path, const char *password) const final; diff --git a/src/odr/internal/ooxml/text/ooxml_text_element.cpp b/src/odr/internal/ooxml/text/ooxml_text_element.cpp index 006d3029..7d6cca0a 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_element.cpp +++ b/src/odr/internal/ooxml/text/ooxml_text_element.cpp @@ -40,6 +40,13 @@ Element::intermediate_style(const abstract::Document *document) const { return base; } +bool Element::is_editable(const abstract::Document *document) const { + if (m_parent == nullptr) { + return document_(document)->is_editable(); + } + return m_parent->is_editable(document); +} + const Document *Element::document_(const abstract::Document *document) { return dynamic_cast(document); } diff --git a/src/odr/internal/ooxml/text/ooxml_text_element.hpp b/src/odr/internal/ooxml/text/ooxml_text_element.hpp index 7dab785b..dba5fa2f 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_element.hpp +++ b/src/odr/internal/ooxml/text/ooxml_text_element.hpp @@ -23,6 +23,8 @@ class Element : public virtual common::Element { virtual common::ResolvedStyle intermediate_style(const abstract::Document *) const; + bool is_editable(const abstract::Document *) const override; + protected: pugi::xml_node m_node;