summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-06-02 18:43:08 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-06-02 18:43:08 -0400
commit63385c4a40af709217a75af73dfbcc900aba03d3 (patch)
tree41cd619bfe6ed8f97f125065b756d5f75c925a29
parenteb1950424d583b9d6711c11316a4d6ffd7daea08 (diff)
downloadorcus-63385c4a40af709217a75af73dfbcc900aba03d3.tar.gz
Add import_cell_protection interface & impl and use it in xls-xml
Although xls-xml currently doesn't import cell protection attributes. We'll tackle that with #159.
-rw-r--r--include/orcus/spreadsheet/factory.hpp20
-rw-r--r--include/orcus/spreadsheet/import_interface_styles.hpp23
-rw-r--r--src/liborcus/spreadsheet_interface.cpp2
-rw-r--r--src/liborcus/xls_xml_context.cpp7
-rw-r--r--src/spreadsheet/factory_styles.cpp73
5 files changed, 123 insertions, 2 deletions
diff --git a/include/orcus/spreadsheet/factory.hpp b/include/orcus/spreadsheet/factory.hpp
index 57f3dbd2..731686aa 100644
--- a/include/orcus/spreadsheet/factory.hpp
+++ b/include/orcus/spreadsheet/factory.hpp
@@ -77,6 +77,7 @@ public:
virtual iface::import_font_style* get_font_style() override;
virtual iface::import_fill_style* get_fill_style() override;
virtual iface::import_border_style* get_border_style() override;
+ virtual iface::import_cell_protection* get_cell_protection() override;
virtual void set_font_count(size_t n) override;
virtual void set_fill_count(size_t n) override;
@@ -185,6 +186,25 @@ public:
void reset();
};
+class ORCUS_SPM_DLLPUBLIC import_cell_protection : public iface::import_cell_protection
+{
+ struct impl;
+ std::unique_ptr<impl> mp_impl;
+
+public:
+ import_cell_protection() = delete;
+ import_cell_protection(styles& _styles_model, string_pool& sp);
+ virtual ~import_cell_protection() override;
+
+ virtual void set_hidden(bool b) override;
+ virtual void set_locked(bool b) override;
+ virtual void set_print_content(bool b) override;
+ virtual void set_formula_hidden(bool b) override;
+ virtual size_t commit() override;
+
+ void reset();
+};
+
class ORCUS_SPM_DLLPUBLIC export_factory : public iface::export_factory
{
struct impl;
diff --git a/include/orcus/spreadsheet/import_interface_styles.hpp b/include/orcus/spreadsheet/import_interface_styles.hpp
index 3b985b98..f509d01f 100644
--- a/include/orcus/spreadsheet/import_interface_styles.hpp
+++ b/include/orcus/spreadsheet/import_interface_styles.hpp
@@ -22,6 +22,7 @@ namespace orcus { namespace spreadsheet { namespace iface {
class import_font_style;
class import_fill_style;
class import_border_style;
+class import_cell_protection;
/**
* Interface for styles. Note that because the default style must have an
@@ -72,6 +73,16 @@ public:
virtual import_border_style* get_border_style() = 0;
/**
+ * Return a pointer to the interface instance for importing cell protection
+ * attributes. Note that the import_styles implementer <i>must</i> return a
+ * non-null pointer.
+ *
+ * @return pointer to the interface instance for importing cell protection
+ * attributes.
+ */
+ virtual import_cell_protection* get_cell_protection() = 0;
+
+ /**
* Set the total number of font styles. This may be called before importing
* any of the font styles. This will give the implementer a chance to
* allocate storage. Note that it may not always be called.
@@ -262,6 +273,18 @@ public:
virtual size_t commit() = 0;
};
+class ORCUS_DLLPUBLIC import_cell_protection
+{
+public:
+ virtual ~import_cell_protection();
+
+ virtual void set_hidden(bool b) = 0;
+ virtual void set_locked(bool b) = 0;
+ virtual void set_print_content(bool b) = 0;
+ virtual void set_formula_hidden(bool b) = 0;
+ virtual size_t commit() = 0;
+};
+
}}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/src/liborcus/spreadsheet_interface.cpp b/src/liborcus/spreadsheet_interface.cpp
index 497c4feb..aa16fb28 100644
--- a/src/liborcus/spreadsheet_interface.cpp
+++ b/src/liborcus/spreadsheet_interface.cpp
@@ -31,6 +31,8 @@ import_fill_style::~import_fill_style() {}
import_border_style::~import_border_style() {}
+import_cell_protection::~import_cell_protection() {}
+
import_sheet_properties::~import_sheet_properties() {}
import_named_expression::~import_named_expression() {}
diff --git a/src/liborcus/xls_xml_context.cpp b/src/liborcus/xls_xml_context.cpp
index 77adf3a6..0b76b141 100644
--- a/src/liborcus/xls_xml_context.cpp
+++ b/src/liborcus/xls_xml_context.cpp
@@ -1871,7 +1871,12 @@ void xls_xml_context::commit_default_style()
border_style->commit();
- styles->commit_cell_protection();
+ auto* cell_protection = styles->get_cell_protection();
+ if (!cell_protection)
+ throw interface_error("implementer must provide a concrete instance of import_cell_protection.");
+
+ cell_protection->commit();
+
styles->commit_number_format();
styles->commit_cell_style_xf();
diff --git a/src/spreadsheet/factory_styles.cpp b/src/spreadsheet/factory_styles.cpp
index ef988eff..4bfc2a75 100644
--- a/src/spreadsheet/factory_styles.cpp
+++ b/src/spreadsheet/factory_styles.cpp
@@ -35,6 +35,7 @@ struct import_styles::impl
import_font_style font_style;
import_fill_style fill_style;
import_border_style border_style;
+ import_cell_protection cell_protection;
fill_t cur_fill;
fill_active_t cur_fill_active;
@@ -53,7 +54,8 @@ struct import_styles::impl
str_pool(sp),
font_style(_styles_model, sp),
fill_style(_styles_model, sp),
- border_style(_styles_model, sp)
+ border_style(_styles_model, sp),
+ cell_protection(_styles_model, sp)
{}
};
@@ -80,6 +82,12 @@ iface::import_border_style* import_styles::get_border_style()
return &mp_impl->border_style;
}
+iface::import_cell_protection* import_styles::get_cell_protection()
+{
+ mp_impl->cell_protection.reset();
+ return &mp_impl->cell_protection;
+}
+
void import_styles::set_font_count(size_t n)
{
mp_impl->styles_model.reserve_font_store(n);
@@ -558,6 +566,69 @@ void import_border_style::reset()
mp_impl->cur_border.reset();
mp_impl->cur_border_active.reset();
}
+
+struct import_cell_protection::impl
+{
+ styles& styles_model;
+ string_pool& str_pool;
+
+ protection_t cur_protection;
+ protection_active_t cur_protection_active;
+
+ impl(styles& _styles_model, string_pool& sp) :
+ styles_model(_styles_model), str_pool(sp) {}
+};
+
+import_cell_protection::import_cell_protection(styles& _styles_model, string_pool& sp) :
+ mp_impl(std::make_unique<impl>(_styles_model, sp))
+{
+}
+
+import_cell_protection::~import_cell_protection()
+{
+}
+
+void import_cell_protection::set_hidden(bool b)
+{
+ mp_impl->cur_protection.hidden = b;
+ mp_impl->cur_protection_active.hidden = true;
+}
+
+void import_cell_protection::set_locked(bool b)
+{
+ mp_impl->cur_protection.locked = b;
+ mp_impl->cur_protection_active.locked = true;
+}
+
+void import_cell_protection::set_print_content(bool b)
+{
+ mp_impl->cur_protection.print_content = b;
+ mp_impl->cur_protection_active.print_content = true;
+}
+
+void import_cell_protection::set_formula_hidden(bool b)
+{
+ mp_impl->cur_protection.formula_hidden = b;
+ mp_impl->cur_protection_active.formula_hidden = true;
+}
+
+size_t import_cell_protection::commit()
+{
+ size_t cp_id = mp_impl->styles_model.append_protection(
+ mp_impl->cur_protection, mp_impl->cur_protection_active);
+
+ mp_impl->cur_protection.reset();
+ mp_impl->cur_protection_active.reset();
+
+ return cp_id;
+}
+
+void import_cell_protection::reset()
+{
+ mp_impl->cur_protection.reset();
+ mp_impl->cur_protection_active.reset();
+}
+
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */