Commit afbb4861 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

гиперлинки

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@55303 954022d7-b5bf-4e40-9824-e11837661b57
parent 0ca8157f
......@@ -8,6 +8,7 @@
#include "style_table_properties.h"
#include "odf_text_context.h"
#include "paragraph_elements.h"
namespace cpdoccore {
namespace odf {
......@@ -165,6 +166,37 @@ void parsing_ref (const std::wstring & ref, int & col,int & row)
}
void ods_conversion_context::add_hyperlink(std::wstring & ref, std::wstring & link, std::wstring & display)
{
//////////////////////////////////////////////////////////////////
std::vector<std::wstring> ref_cells;
boost::algorithm::split(ref_cells,ref, boost::algorithm::is_any_of(L":"), boost::algorithm::token_compress_on);
if (ref_cells.size()>1)
{
// x , - ,
int start_col = -1, start_row = -1;
int end_col = -1, end_row = -1;
parsing_ref (ref_cells[0], start_col, start_row);
parsing_ref (ref_cells[1], end_col, end_row);
for (long col = start_col; col <= end_col; col++)
{
for (long row = start_row; row <= end_row; row++)
{
current_table().add_hyperlink(ref,col,row,link);
// , -
}
}
}
else
{
int col = -1, row = -1;
parsing_ref (ref_cells[0], col, row);
current_table().add_hyperlink(ref,col,row,link);
}
}
void ods_conversion_context::add_merge_cells(std::wstring & ref)
{
std::vector<std::wstring> ref_cells;
......@@ -221,7 +253,6 @@ void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
current_table().start_cell(cell_elm, style_elm);
current_table().set_cell_ref(ref,col,row);
current_table().set_cell_format_value(number_format);
}
......@@ -314,31 +345,39 @@ void ods_conversion_context::add_text_content(std::wstring & text)
current_text_context_->add_text_content(text);
}
}
void ods_conversion_context::start_text_paragraph()
void ods_conversion_context::start_cell_text()
{
//if (current_text_context_)
//{
// style_elm = styles_context().find_odf_style_default(style_family::TableRow);
//}
//else
end_text_context();
start_text_context();
////////////
office_element_ptr paragr_elm;
create_element(L"text", L"p",paragr_elm,this);
current_text_context_->start_paragraph(paragr_elm);
if (current_table().is_cell_hyperlink())
{
/* styles_context().create_style(L"",style_family::TableRow, true, false, -1);
style_elm = styles_context().last_state().get_office_element();
ods_hyperlink_state & state = current_table().current_hyperlink();
style* _style = dynamic_cast<style*>(style_elm.get());
if (!_style)return; */
office_element_ptr text_a_elm;
create_element(L"text", L"a", text_a_elm, this);
office_element_ptr paragr_elm;
create_element(L"text", L"p",paragr_elm,this);
text_a* text_a_ = dynamic_cast<text_a*>(text_a_elm.get());
if (text_a_ == NULL)return;
text_a_->common_xlink_attlist_.type_ = xlink_type(xlink_type::Simple);
text_a_->common_xlink_attlist_.href_ = state.link;
current_text_context_->start_paragraph(paragr_elm);
current_text_context_->start_element(text_a_elm); // ???
}
}
void ods_conversion_context::end_text_paragraph()
void ods_conversion_context::end_cell_text()
{
if (current_text_context_)
{
if (current_table().is_cell_hyperlink()) current_text_context_->end_element();
current_text_context_->end_paragraph();
}
}
......
......@@ -31,19 +31,20 @@ public:
void end_cell(){}
void end_rows();
void add_merge_cells(std::wstring & ref);
void start_cell_text();
void add_text_content(std::wstring & text);
void end_cell_text();
void add_merge_cells(std::wstring & ref);
void add_hyperlink(std::wstring & ref, std::wstring & link, std::wstring & display);
///////////////////////////////////////////////////////
ods_table_state & current_table() { return ods_table_context_.state();}
odf_text_context* current_text_context(){return current_text_context_;}
/////////////////////////////////////////////////////
void start_text_context();
void end_text_context();
void start_text_paragraph();//
void end_text_paragraph();
void add_text_content(std::wstring & text);
private:
ods_table_context ods_table_context_;
......
......@@ -23,7 +23,6 @@ public:
void start_table(office_element_ptr & elm,std::wstring & name);
void end_table();
unsigned int columns_count();
ods_table_state & state();
......
......@@ -198,11 +198,31 @@ void ods_table_state::set_row_height(double height)
row_properties->style_table_row_properties_attlist_.style_row_height_ = length(height/22.85,length::cm);
}
bool ods_table_state::is_cell_hyperlink()
{
if (cells_.size()<1)return false;
return cells_.back().hyperlink_idx >=0 ? true : false;
}
int ods_table_state::is_cell_hyperlink(int col, int row)
{
for (long i=0; i< hyperlinks_.size();i++)
{
if (hyperlinks_[i].col == col && hyperlinks_[i].row == row)
{
return i;
}
}
return -1;
}
int ods_table_state::current_column() const
{
return current_table_column_;
}
int ods_table_state::current_row() const
{
return current_table_row_;
......@@ -236,6 +256,16 @@ office_element_ptr & ods_table_state::current_cell_element()
{
}
}
ods_hyperlink_state & ods_table_state::current_hyperlink()
{
if ((cells_.size()>0 && hyperlinks_.size()>0) && (cells_.back().hyperlink_idx>=0) )
{
return hyperlinks_[cells_.back().hyperlink_idx];
}
else
{
}
}
office_value_type::type oox_valuetype_2_odf(int oox_fmt)
{
switch (oox_fmt)
......@@ -279,11 +309,13 @@ void ods_table_state::start_cell(office_element_ptr & elm, office_element_ptr &
cell->table_table_cell_attlist_.table_style_name_= style_name;
ods_cell_state state;
state.elm = elm; state.repeated = 1; state.style_name = style_name; state.style_elm = style_elm;
state.row=0; state.col =0;
state.row=current_table_row_; state.col =current_table_column_+1;
current_table_column_++;
state.hyperlink_idx = is_cell_hyperlink(state.col, state.row);
current_table_column_ += state.repeated;
cells_.push_back(state);
}
......@@ -330,6 +362,16 @@ void ods_table_state::set_cell_type(int type)
cell->table_table_cell_attlist_.common_value_and_type_attlist_->office_value_type_ = cell_type;
}
}
void ods_table_state::add_hyperlink(std::wstring & ref,int col, int row, std::wstring & link)
{
ods_hyperlink_state state;
/*state.elm = text_a_elm; */state.row=row; state.col =col; state.ref = ref, state.link = link;
hyperlinks_.push_back(state);
}
void ods_table_state::set_merge_cells(int start_col, int start_row, int end_col, int end_row)
{
// () -
......@@ -364,10 +406,7 @@ void ods_table_state::set_merge_cells(int start_col, int start_row, int end_col,
}
}
}
//void ods_table_state::add_cell_element(office_element_ptr & child)
//{
// cells_.back().elm->add_child_element(child);
//}
void ods_table_state::set_cell_text(odf_text_context* text_context)
{
if (text_context == NULL)return;
......@@ -424,17 +463,10 @@ void ods_table_state::set_cell_value(std::wstring & value)
//
}
void ods_table_state::set_cell_ref (std::wstring & ref, int col, int row)
{
if (cells_.size() < 1)return;
cells_.back().ref = ref;
cells_.back().col = col;
cells_.back().row = row;
}
void ods_table_state::end_cell()
{
}
void ods_table_state::add_default_cell(office_element_ptr & elm, int repeated)
{
current_row_element()->add_child_element(elm);
......@@ -443,12 +475,15 @@ void ods_table_state::add_default_cell(office_element_ptr & elm, int repeated)
if (cell == NULL)return;
ods_cell_state state;
state.elm = elm; state.repeated = repeated; /*state.style_name = style_name;*//* state.style_elm = style_elm;*/
state.row=current_table_row_; state.col =current_table_column_;
state.elm = elm; state.repeated = repeated;
state.row=current_table_row_; state.col =current_table_column_+1;
state.hyperlink_idx = is_cell_hyperlink(state.col, state.row);
cells_.push_back(state);
current_table_column_+=repeated;
current_table_column_+= state.repeated;
cell->table_table_cell_attlist_.table_number_columns_repeated_ = repeated;
......
......@@ -8,7 +8,6 @@
//#include "ods_table_metrics.h"
//#include "ods_drawing_context.h"
//#include "ods_comments_context.h"
//#include "ods_hyperlinks.h"
#include "office_elements.h"
#include "office_elements_create.h"
......@@ -35,10 +34,19 @@ struct ods_element_state
};
struct ods_cell_state : ods_element_state
{
int col;
int row;
int hyperlink_idx;
};
struct ods_hyperlink_state
{
std::wstring ref;
int col;
int row;
std::wstring link;
};
class ods_table_state
......@@ -63,32 +71,32 @@ public:
void add_row(office_element_ptr & elm, int repeated ,office_element_ptr & style);//const std::wstring & StyleName, const std::wstring & defaultCellStyleName);
void set_row_hidden(bool Val);
//void set_row_collapsed(bool Val);
void set_row_optimal_height(bool val);
void set_row_height(double height);
void set_row_default_cell_style(std::wstring & style_name);
//void start_cell(/*size_t columnsSpanned, size_t rowsSpanned*/);
void start_cell(office_element_ptr & elm ,office_element_ptr & style);
void end_cell();
void add_default_cell(office_element_ptr & cell, int repeated);
void set_cell_ref (std::wstring & ref, int col, int row);
void set_cell_format_value(int format);
void set_cell_type(int type);
void set_cell_value(std::wstring & value);
void set_cell_text(odf_text_context *text_context);
///////////////////////////////
void add_hyperlink(std::wstring & ref,int col, int row, std::wstring & link);
void set_merge_cells(int start_col, int start_row, int end_col, int end_row);
// void start_covered_cell();
// void end_covered_cell();
office_element_ptr & current_row_element();
office_element_ptr & current_cell_element();
bool is_cell_hyperlink();
int is_cell_hyperlink(int col, int row);
ods_hyperlink_state & current_hyperlink();
int current_column() const;
int current_row() const;
......@@ -100,18 +108,10 @@ public:
// void table_column_last_width(double w) { table_column_last_width_ = w; }
// double table_column_last_width() const { return table_column_last_width_; };
// void start_hyperlink();
//std::wstring end_hyperlink(std::wstring const & ref, std::wstring const & href, std::wstring const & display);
//void serialize_table_format(std::wostream & _Wostream);
//void serialize_merge_cells(std::wostream & _Wostream);
// void serialize_hyperlinks(std::wostream & _Wostream);
private:
ods_conversion_context & context_;
office_element_ptr office_table_;
office_element_ptr office_table_;
style* office_table_style_;//??? office_element_ptr ???
std::wstring row_default_cell_style_name_;
......@@ -127,6 +127,7 @@ private:
std::vector<office_element_ptr> current_level_;// ("0- - )
std::vector<ods_cell_state> cells_;
std::vector<ods_hyperlink_state> hyperlinks_;
// xlsx_merge_cells merge_cells_;
// xlsx_table_metrics xlsx_table_metrics_;
......
......@@ -248,14 +248,14 @@ void text_a::serialize(std::wostream & _Wostream)
{
common_xlink_attlist_.serialize(CP_GET_XML_NODE());
CP_XML_ATTR(L"office:name", office_name_);
CP_XML_ATTR_OPT(L"office:name", office_name_);
CP_XML_ATTR_OPT(L"office:target-frame-name", office_target_frame_name_);
CP_XML_ATTR(L"text:style-name", text_style_name_);
CP_XML_ATTR(L"text:visited-style-name", text_visited_style_name_);
CP_XML_ATTR_OPT(L"text:style-name", text_style_name_);
CP_XML_ATTR_OPT(L"text:visited-style-name", text_visited_style_name_);
BOOST_FOREACH(const office_element_ptr & element, paragraph_content_)
{
element->serialize(_Wostream);
element->serialize(CP_XML_STREAM());
}
}
}
......
......@@ -321,11 +321,11 @@ public:
common_xlink_attlist common_xlink_attlist_;
::std::wstring office_name_;
_CP_OPT(std::wstring) office_name_;
_CP_OPT(target_frame_name) office_target_frame_name_;
style_ref text_style_name_;
style_ref text_visited_style_name_;
_CP_OPT(style_ref) text_style_name_;
_CP_OPT(style_ref) text_visited_style_name_;
office_element_ptr_array paragraph_content_;
};
......
......@@ -101,6 +101,12 @@ void XlsxConverter::convert(OOX::Spreadsheet::CWorksheet *oox_sheet)
if (oox_sheet->m_oSheetPr.IsInit())
convert(oox_sheet->m_oSheetPr.GetPointer());
// .. .
for (long hyp = 0; oox_sheet->m_oHyperlinks.IsInit() && hyp < oox_sheet->m_oHyperlinks->m_arrItems.GetSize(); hyp++)
{
convert(oox_sheet->m_oHyperlinks->m_arrItems[hyp],oox_sheet);
}
//
ods_context->start_columns();
for (long col = 0 ; oox_sheet->m_oCols.IsInit() && col < oox_sheet->m_oCols->m_arrItems.GetSize(); col++)
......@@ -123,10 +129,42 @@ void XlsxConverter::convert(OOX::Spreadsheet::CWorksheet *oox_sheet)
if (oox_sheet->m_oMergeCells->m_arrItems[mrg]->m_oRef.IsInit())
ods_context->add_merge_cells(string2std_string(oox_sheet->m_oMergeCells->m_arrItems[mrg]->m_oRef.get()));
}
//
//m_oDrawing
//
//m_mapComments
//m_oAutofilter
}
void XlsxConverter::convert(OOX::Spreadsheet::CHyperlink *oox_hyperlink,OOX::Spreadsheet::CWorksheet *oox_sheet)
{
if (oox_hyperlink == NULL)return;
if (oox_sheet == NULL)return;
std::wstring ref = oox_hyperlink->m_oRef.IsInit() ? string2std_string(oox_hyperlink->m_oRef.get()) : L"";
std::wstring link;
if (oox_hyperlink->m_oRid.IsInit() && oox_sheet->GetCurRls())
{
OOX::Rels::CRelationShip* oRels = NULL;
oox_sheet->GetCurRls()->GetRel( OOX::RId(oox_hyperlink->m_oRid->GetValue()), &oRels);
if(NULL != oRels && _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink") == oRels->Type() )
{
if(oRels->IsExternal())
link= oRels->Target().GetPath();
}
}
std::wstring display = oox_hyperlink->m_oDisplay.IsInit() ? string2std_string(oox_hyperlink->m_oDisplay.get()) : L"";
ods_context->add_hyperlink(ref, link, display);
}
void XlsxConverter::convert(OOX::Spreadsheet::CRow *oox_row)
{
if (oox_row == NULL)return;
int row_number = oox_row->m_oR.IsInit() ? oox_row->m_oR->GetValue() : -1;
bool _default = true;
......@@ -227,17 +265,15 @@ void XlsxConverter::convert_sharing_string(int number)
if (pSi == NULL)return;
ods_context->start_text_context();
ods_context->start_text_paragraph(); // . ( - )
ods_context->start_cell_text();
for(int i = 0; i < pSi->m_arrItems.GetSize(); ++i)
{
convert(pSi->m_arrItems[i]);
}
for(int i = 0; i < pSi->m_arrItems.GetSize(); ++i)
{
convert(pSi->m_arrItems[i]);
}
ods_context->end_text_paragraph();
ods_context->current_table().set_cell_text( ods_context->current_text_context());
ods_context->end_text_context();
ods_context->end_cell_text();
ods_context->current_table().set_cell_text( ods_context->current_text_context());
}
void XlsxConverter::convert(OOX::Spreadsheet::WritingElement *oox_unknown)
{
......
......@@ -76,6 +76,7 @@ namespace Oox2Odf
void convert(OOX::Spreadsheet::CText *oox_text);
void convert(OOX::Spreadsheet::CFormula *oox_formula);
void convert(OOX::Spreadsheet::CHyperlink *oox_hyperlink,OOX::Spreadsheet::CWorksheet *oox_sheet);
void convert(OOX::Spreadsheet::CSheetFormatPr *oox_sheet_format_pr);
void convert(OOX::Spreadsheet::CSheetPr *oox_sheet_pr);
......
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