diff --git a/include/orcus/spreadsheet/import_interface.hpp b/include/orcus/spreadsheet/import_interface.hpp
index cc83e5a518aea73c6b204bf65445667b7651516e..59b619dfc374297d712ef86811243b6936dc7691 100644
--- a/include/orcus/spreadsheet/import_interface.hpp
+++ b/include/orcus/spreadsheet/import_interface.hpp
@@ -116,6 +116,8 @@ public:
// cell protection
virtual void set_cell_hidden(bool b) = 0;
virtual void set_cell_locked(bool b) = 0;
+ virtual void set_cell_print_content(bool b) = 0;
+ virtual void set_cell_formula_hidden(bool b) = 0;
virtual size_t commit_cell_protection() = 0;
// number format
diff --git a/include/orcus/spreadsheet/styles.hpp b/include/orcus/spreadsheet/styles.hpp
index 3cf019e739368d723bfcb9b7b0eb558224a93bc3..7ab7452849b871f02b24a925829f87ece8739456 100644
--- a/include/orcus/spreadsheet/styles.hpp
+++ b/include/orcus/spreadsheet/styles.hpp
@@ -84,6 +84,8 @@ struct ORCUS_SPM_DLLPUBLIC protection_t
{
bool locked;
bool hidden;
+ bool print_content;
+ bool formula_hidden;
protection_t();
void reset();
@@ -117,6 +119,7 @@ struct ORCUS_SPM_DLLPUBLIC cell_format_t
bool apply_fill:1;
bool apply_border:1;
bool apply_alignment:1;
+ bool apply_protection:1;
cell_format_t();
void reset();
@@ -165,6 +168,8 @@ public:
virtual void set_cell_hidden(bool b);
virtual void set_cell_locked(bool b);
+ virtual void set_cell_print_content(bool b);
+ virtual void set_cell_formula_hidden(bool b);
virtual size_t commit_cell_protection();
virtual void set_number_format_count(size_t n);
diff --git a/src/liborcus/odf_styles.hpp b/src/liborcus/odf_styles.hpp
index 9e6bf7a88ce455af093190e3721032540530b9ec..62a392b69ecfa41dea5bb6912571350bfcff6e55 100644
--- a/src/liborcus/odf_styles.hpp
+++ b/src/liborcus/odf_styles.hpp
@@ -48,11 +48,12 @@ struct odf_style
size_t font;
size_t fill;
size_t border;
+ size_t protection;
size_t xf;
bool automatic_style;
- cell() : font(0), fill(0), border(0),
+ cell() : font(0), fill(0), border(0), protection(0),
xf(0), automatic_style(false) {}
};
diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp
index b62edfc154ad1a7e8820c7a57482c3a73f4f1bdd..75548d4ec73a4ddcd718f63dc81ff00f4a406af1 100644
--- a/src/liborcus/odf_styles_context.cpp
+++ b/src/liborcus/odf_styles_context.cpp
@@ -169,7 +169,12 @@ public:
m_background_red(0),
m_background_green(0),
m_background_blue(0),
- m_background_color(false)
+ m_background_color(false),
+ m_locked(false),
+ m_hidden(false),
+ m_formula_hidden(false),
+ m_print_content(false),
+ m_cell_protection(false)
{}
private:
@@ -179,6 +184,11 @@ private:
spreadsheet::color_elem_t m_background_blue;
bool m_background_color;
+ bool m_locked;
+ bool m_hidden;
+ bool m_formula_hidden;
+ bool m_print_content;
+ bool m_cell_protection;
border_map_type m_border_style_dir_pair;
@@ -249,6 +259,39 @@ public:
;
}
}
+
+ else if(attr.ns == NS_odf_style)
+ {
+ switch(attr.name)
+ {
+ case XML_print_content:
+ {
+ m_cell_protection = true;
+ m_print_content = attr.value == "true";
+ }
+ break;
+ case XML_cell_protect:
+ {
+ m_cell_protection = true;
+ if (attr.value == "protected")
+ m_locked = true;
+ else if (attr.value == "hidden-and-protected")
+ {
+ m_locked = true;
+ m_hidden = true;
+ }
+ else if (attr.value == "formula-hidden")
+ m_formula_hidden = true;
+ else if (attr.value == "protected formula-hidden" || attr.value == "formula-hidden protected")
+ {
+ m_formula_hidden = true;
+ m_locked = true;
+ }
+ }
+ default:
+ ;
+ }
+ }
}
bool has_background_color() const { return m_background_color; }
@@ -263,6 +306,12 @@ public:
bool has_border() const { return !m_border_style_dir_pair.empty(); }
+ bool has_protection() const { return m_cell_protection; }
+ bool is_locked() const { return m_locked; }
+ bool is_hidden() const { return m_hidden; }
+ bool is_formula_hidden() const { return m_formula_hidden; }
+ bool is_print_content() const { return m_print_content; }
+
const border_map_type& get_border_attrib() const
{
return m_border_style_dir_pair;
@@ -466,6 +515,15 @@ void styles_context::start_element(xmlns_id_t ns, xml_token_t name, const std::v
}
size_t border_id = mp_styles->commit_border();
+
+ if (func.has_protection())
+ {
+ mp_styles->set_cell_hidden(func.is_hidden());
+ mp_styles->set_cell_locked(func.is_locked());
+ mp_styles->set_cell_print_content(func.is_print_content());
+ mp_styles->set_cell_formula_hidden(func.is_formula_hidden());
+ }
+ size_t cell_protection_id = mp_styles->commit_cell_protection();
switch (m_current_style->family)
{
case style_family_table_cell:
@@ -473,6 +531,7 @@ void styles_context::start_element(xmlns_id_t ns, xml_token_t name, const std::v
odf_style::cell* data = m_current_style->cell_data;
data->fill = fill_id;
data->border = border_id;
+ data->protection = cell_protection_id;
}
break;
default:
@@ -505,6 +564,7 @@ bool styles_context::end_element(xmlns_id_t ns, xml_token_t name)
mp_styles->set_xf_font(cell.font);
mp_styles->set_xf_fill(cell.fill);
mp_styles->set_xf_border(cell.border);
+ mp_styles->set_xf_protection(cell.protection);
size_t xf_id = 0;
if (cell.automatic_style)
xf_id = mp_styles->commit_cell_xf();
diff --git a/src/liborcus/odf_styles_context_test.cpp b/src/liborcus/odf_styles_context_test.cpp
index 838bf2d55e9cbee863553863d371c54f6fb0ec9d..c6410ec8989135e5b26441a050e8fe20809420a7 100644
--- a/src/liborcus/odf_styles_context_test.cpp
+++ b/src/liborcus/odf_styles_context_test.cpp
@@ -58,7 +58,7 @@ int main()
/* Test for Border Styles
=====================================================
*/
- assert(styles.get_border_count() == 5);
+ assert(styles.get_border_count() == 8);
/* Test that border style applies to all the sides when not specified */
style = find_cell_style_by_name("Name1", &styles);
@@ -112,5 +112,47 @@ int main()
assert(cell_border->diagonal_tl_br.border_color.green == 0x00);
assert(cell_border->diagonal_tl_br.border_width.value == 0.74);
+/* Test for Cell Protection
+ ========================================================
+*/
+ /* Test that Cell is only protected and not hidden , Print Content is true */
+ style = find_cell_style_by_name("Name5", &styles);
+ xf = style->xf;
+ cell_format = styles.get_cell_style_format(xf);
+ size_t protection = cell_format->protection;
+ assert(cell_format);
+
+ const orcus::spreadsheet::protection_t* cell_protection = styles.get_protection(protection);
+ assert(cell_protection->locked == true);
+ assert(cell_protection->hidden == true);
+ assert(cell_protection->print_content == true);
+ assert(cell_protection->formula_hidden == false);
+
+ /* Test that Cell is protected and formula is hidden , Print Content is false */
+ style = find_cell_style_by_name("Name6", &styles);
+ xf = style->xf;
+ cell_format = styles.get_cell_style_format(xf);
+ protection = cell_format->protection;
+ assert(cell_format);
+
+ cell_protection = styles.get_protection(protection);
+ assert(cell_protection->locked == true);
+ assert(cell_protection->hidden == false);
+ assert(cell_protection->print_content == false);
+ assert(cell_protection->formula_hidden == true);
+
+ /* Test that Cell is not protected by any way, Print Content is false */
+ style = find_cell_style_by_name("Name7", &styles);
+ xf = style->xf;
+ cell_format = styles.get_cell_style_format(xf);
+ protection = cell_format->protection;
+ assert(cell_format);
+
+ cell_protection = styles.get_protection(protection);
+ assert(cell_protection->locked == false);
+ assert(cell_protection->hidden == false);
+ assert(cell_protection->print_content == true);
+ assert(cell_protection->formula_hidden == false);
+
return 0;
}
diff --git a/src/spreadsheet/styles.cpp b/src/spreadsheet/styles.cpp
index 9e62c0c6c7e7c577df739576f870658ac8515060..608df44e5d043d2ee7fd3749c09b5c4863b2a977 100644
--- a/src/spreadsheet/styles.cpp
+++ b/src/spreadsheet/styles.cpp
@@ -68,7 +68,7 @@ void border_t::reset()
}
protection_t::protection_t() :
- locked(false), hidden(false)
+ locked(false), hidden(false), print_content(false), formula_hidden(false)
{
}
@@ -102,7 +102,8 @@ cell_format_t::cell_format_t() :
apply_font(false),
apply_fill(false),
apply_border(false),
- apply_alignment(false)
+ apply_alignment(false),
+ apply_protection(false)
{
}
@@ -282,6 +283,16 @@ void import_styles::set_cell_locked(bool b)
m_cur_protection.locked = b;
}
+void import_styles::set_cell_print_content(bool b)
+{
+ m_cur_protection.print_content = b;
+}
+
+void import_styles::set_cell_formula_hidden(bool b)
+{
+ m_cur_protection.formula_hidden = b;
+}
+
size_t import_styles::commit_cell_protection()
{
m_protections.push_back(m_cur_protection);
diff --git a/test/ods/styles/cell-styles.xml b/test/ods/styles/cell-styles.xml
index e9b944d1a1845d3d19bf70bd1fbe46a572c142a7..2722719917b6cfc845a6a72745498c20bedcbe83 100644
--- a/test/ods/styles/cell-styles.xml
+++ b/test/ods/styles/cell-styles.xml
@@ -12,4 +12,13 @@
+
+
+
+
+
+
+
+
+