Commit 250a6e5a authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatReader - sheet/workbook views

parent 82dc7ab4
......@@ -380,14 +380,52 @@ void xlsx_table_state::serialize_table_format(std::wostream & _Wostream)
CP_XML_ATTR(L"ref", L"A1:" + ref2);
}
}
CP_XML_NODE(L"sheetView")
if (odfContext.Settings().get_views_count() > 0)
{
if (odfContext.Settings().get_views_count() > 0)
CP_XML_ATTR(L"workbookViewId", 0);
// -showGridLines
CP_XML_NODE(L"sheetViews")
{
CP_XML_NODE(L"sheetView")
{
CP_XML_ATTR(L"workbookViewId", 0);
std::wstring s_col, s_row;
for (int i = 0; i < odfContext.Settings().get_table_view_count(0, tableName_); i++)
{
std::pair<std::wstring, std::wstring> value = odfContext.Settings().get_table_view(0, tableName_, i);
if (value.first == L"ZoomValue")
{
CP_XML_ATTR(L"zoomScale", value.second);
CP_XML_ATTR(L"zoomScaleNormal", value.second);
}
if (value.first == L"ShowGrid") CP_XML_ATTR(L"showGridLines", value.second);
if (value.first == L"CursorPositionX") s_col = value.second;
if (value.first == L"CursorPositionY") s_row = value.second;
}
int col = -1, row = -1;
try
{
col = boost::lexical_cast<int>(s_col);
row = boost::lexical_cast<int>(s_row);
}
catch(...){}
if (col >= 0 && row >= 0)
{
CP_XML_NODE(L"selection")
{
CP_XML_ATTR(L"sqref", getCellAddress(col, row));
CP_XML_ATTR(L"activeCellId", 0);
CP_XML_ATTR(L"activeCell", getCellAddress(col, row));
CP_XML_ATTR(L"pane", L"topLeft");
}
}
}
}
// -showRowColHeaders
// -rightToLeft
// -zoomScale
}
double default_height = (2 * context_->getMaxDigitSize().second * 72. / 96. * 100.) /100.;//in point size.
......
......@@ -291,7 +291,7 @@ void odf_document::Impl::parse_settings()
settings_config_item * sett = dynamic_cast<settings_config_item *>(elm_sett.get());
if (!sett)continue;
context_->Settings().add(sett->config_name_, elm_sett);
context_->Settings().add(sett->config_name_, sett->content_);
}
}
else if (item_set->config_name_ == L"ooo:view-settings")
......@@ -300,7 +300,7 @@ void odf_document::Impl::parse_settings()
{
settings_config_item * sett = dynamic_cast<settings_config_item *>(elm_sett.get());
if (sett)
context_->Settings().add_view(sett->config_name_, elm_sett);
context_->Settings().add_view(sett->config_name_, sett->content_);
else
{
settings_config_item_map_indexed *map_sett = dynamic_cast<settings_config_item_map_indexed *>(elm_sett.get());
......@@ -309,23 +309,42 @@ void odf_document::Impl::parse_settings()
for (int i = 0; i < map_sett->content_.size(); i++)
{
settings_config_item_map_entry *entry = dynamic_cast<settings_config_item_map_entry *>(map_sett->content_[i].get());
if (!entry) continue;
context_->Settings().start_view();
for (int j = 0; (entry) && (j < entry->content_.size()); j++)
for (int j = 0; j < entry->content_.size(); j++)
{
settings_config_item * sett = dynamic_cast<settings_config_item *>(entry->content_[j].get());
if (!sett)continue;
if (sett)
context_->Settings().add_view(sett->config_name_, sett->content_);
context_->Settings().add_view(sett->config_name_, entry->content_[j]);
settings_config_item_map_named *map_v = dynamic_cast<settings_config_item_map_named *>(entry->content_[j].get());
if (map_v)
{
for (int n = 0; n < map_v->content_.size(); n++)
{
settings_config_item_map_entry *entry_v = dynamic_cast<settings_config_item_map_entry *>(map_v->content_[n].get());
if (!entry_v) continue;
context_->Settings().start_table_view(entry_v->config_name_);
for (int k = 0; k < entry_v->content_.size(); k++)
{
sett = dynamic_cast<settings_config_item *>(entry_v->content_[k].get());
if (sett)
context_->Settings().add_view(sett->config_name_, sett->content_);
}
context_->Settings().end_table_view();
}
}
}
context_->Settings().end_view();
}
}
}
}
} }
}
}
}
void odf_document::Impl::parse_styles()
......
......@@ -121,6 +121,7 @@ const wchar_t * settings_config_item_map_entry::name = L"config-item-map-entry";
void settings_config_item_map_entry::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"config:name", config_name_, std::wstring(L""));
}
void settings_config_item_map_entry::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
......
......@@ -152,7 +152,8 @@ public:
static const ElementType type = typeOfficeSettingsConfigItemMapEntry;
CPDOCCORE_DEFINE_VISITABLE();
office_element_ptr_array content_;
std::wstring config_name_;
office_element_ptr_array content_;
private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
......
......@@ -83,21 +83,36 @@ office_element_ptr styles_lite_container::find_by_style_name(const std::wstring
}
}
//----------------------------------------------------------------------------------
struct settings_value
{
std::wstring name;
std::wstring value;
};
struct settings_elm
{
std::vector<container_element> array_;
std::vector<settings_value> array_;
boost::unordered_map<std::wstring, int> map_;
};
struct view_elm : settings_elm
{
boost::unordered_map<std::wstring, int> map_tables;
std::vector<settings_elm> tables;
};
class settings_container::Impl
{
public:
settings_container::Impl(){}
settings_container::Impl() : inViewTable(false), inView(false) {}
settings_elm common;
settings_elm common;
settings_elm common_view;
std::vector<settings_elm> views;
std::vector<view_elm> views;
bool inViewTable;
bool inView;
};
settings_container::settings_container(): impl_(new settings_container::Impl() )
......@@ -108,9 +123,9 @@ settings_container::~settings_container()
{
}
void settings_container::add(const std::wstring & name, office_element_ptr content)
void settings_container::add(const std::wstring & name, const std::wstring & value)
{
container_element ref = {name, content};
settings_value ref = {name, value};
impl_->common.array_.push_back(ref);
impl_->common.map_[name] = impl_->common.array_.size() - 1;
......@@ -118,33 +133,95 @@ void settings_container::add(const std::wstring & name, office_element_ptr conte
void settings_container::start_view ()
{
settings_elm elm;
impl_->inView = true;
view_elm elm;
impl_->views.push_back(elm);
}
void settings_container::end_view ()
{
impl_->inView = false;
}
int settings_container::get_views_count()
void settings_container::start_table_view (const std::wstring & name)
{
if (name.empty()) return;
impl_->inViewTable = true;
settings_elm elm;
impl_->views.back().tables.push_back(elm);
impl_->views.back().map_tables[name] = impl_->views.back().tables.size() - 1;
}
void settings_container::end_table_view ()
{
impl_->inViewTable = false;
}
int settings_container::get_views_count()
{
return impl_->views.size();
}
void settings_container::add_view(const std::wstring & name, office_element_ptr content)
int settings_container::get_table_view_count(int ind, std::wstring name)
{
container_element ref = {name, content};
if (ind < 0 || ind >= impl_->views.size()) return 0;
boost::unordered_map<std::wstring, int>::const_iterator i = impl_->views[ind].map_tables.find(name);
if (i != impl_->views[ind].map_tables.end())
{
return impl_->views[ind].tables[i->second].array_.size();
}
return 0;
}
void settings_container::add_view(const std::wstring & name, const std::wstring & value)
{
settings_value ref = {name, value};
if (impl_->views.empty())
if (impl_->inView)
{
if (impl_->inViewTable)
{
impl_->views.back().tables.back().array_.push_back(ref);
impl_->views.back().tables.back().map_[name] = impl_->views.back().tables.back().array_.size() - 1;
}
else
{
impl_->views.back().array_.push_back(ref);
impl_->views.back().map_[name] = impl_->views.back().array_.size() - 1;
}
}
else
{
impl_->common_view.array_.push_back(ref);
impl_->common_view.map_[name] = impl_->common_view.array_.size() - 1;
}
else
}
std::pair<std::wstring, std::wstring> settings_container::get_table_view(int index_view, const std::wstring & table_name, int index)
{
std::pair<std::wstring, std::wstring> value;
if (index < 0) return value;
if (index_view < 0 ||
index_view >= impl_->views.size()) return value;
boost::unordered_map<std::wstring, int>::const_iterator i = impl_->views[index_view].map_tables.find(table_name);
if (i == impl_->views[index_view].map_tables.end()) return value;
if (index < impl_->views[index_view].tables[i->second].array_.size())
{
impl_->views.back().array_.push_back(ref);
impl_->views.back().map_[name] = impl_->views.back().array_.size() - 1;
value.first = impl_->views[index_view].tables[i->second].array_[index].name;
value.second = impl_->views[index_view].tables[i->second].array_[index].value;
}
return value;
}
_CP_OPT(std::wstring) settings_container::find_by_name(const std::wstring & name)
{
......@@ -153,14 +230,12 @@ _CP_OPT(std::wstring) settings_container::find_by_name(const std::wstring & name
if (i != impl_->common.map_.end())
{
office_element_ptr & elm = impl_->common.array_[i->second].elm;
settings_config_item* sett = dynamic_cast<settings_config_item*>(elm.get());
if (sett)
value = sett->content_;
value = impl_->common.array_[i->second].value;
}
return value;
}
_CP_OPT(std::wstring) settings_container::find_view_by_name(const std::wstring & name, int ind)
{
_CP_OPT(std::wstring) value;
......@@ -171,10 +246,7 @@ _CP_OPT(std::wstring) settings_container::find_view_by_name(const std::wstring &
if (i != impl_->common_view.map_.end())
{
office_element_ptr & elm = impl_->common_view.array_[i->second].elm;
settings_config_item* sett = dynamic_cast<settings_config_item*>(elm.get());
if (sett)
value = sett->content_;
value = impl_->common_view.array_[i->second].value;
}
}
else
......@@ -183,10 +255,7 @@ _CP_OPT(std::wstring) settings_container::find_view_by_name(const std::wstring &
if (i != impl_->views[ind].map_.end())
{
office_element_ptr & elm = impl_->views[ind].array_[i->second].elm;
settings_config_item* sett = dynamic_cast<settings_config_item*>(elm.get());
if (sett)
value = sett->content_;
value = impl_->views[ind].array_[i->second].value;
}
else
{
......@@ -195,5 +264,6 @@ _CP_OPT(std::wstring) settings_container::find_view_by_name(const std::wstring &
}
return value;
}
}
}
\ No newline at end of file
......@@ -62,17 +62,23 @@ public:
settings_container();
~settings_container();
_CP_OPT(std::wstring) find_by_name (const std::wstring & name);
_CP_OPT(std::wstring) find_view_by_name (const std::wstring & name, int index = -1); //"-1" - common
_CP_OPT(std::wstring) find_by_name (const std::wstring & name);
_CP_OPT(std::wstring) find_view_by_name (const std::wstring & name, int index = -1); //"-1" - common
std::pair<std::wstring, std::wstring> get_table_view (int index_view, const std::wstring & table_name, int index);
int get_views_count();
int get_views_count ();
int get_table_view_count(int ind, std::wstring name);
void add (const std::wstring & name, office_element_ptr content);
void add (const std::wstring & name, const std::wstring & value);
void start_view ();
void end_view ();
void end_view ();
void add_view (const std::wstring & name, office_element_ptr content);
void start_table_view (const std::wstring & name);
void end_table_view ();
void add_view (const std::wstring & name, const std::wstring & value);
private:
class Impl;
_CP_SCOPED_PTR(Impl) impl_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment