1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
/* AbiSource
*
* Copyright (C) 2008 Firat Kiyak <firatkiyak@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/
// Class definition include
#include <OXML_Element_Row.h>
// AbiWord includes
#include <ut_types.h>
#include <ut_string.h>
#include <pd_Document.h>
OXML_Element_Row::OXML_Element_Row(const std::string & id, OXML_Element_Table* tbl) :
OXML_Element(id, TR_TAG, ROW), numCols(0), table(tbl),
m_rowNumber(0), m_currentColumnNumber(0)
{
if(tbl)
tbl->addRow(this);
}
OXML_Element_Row::~OXML_Element_Row()
{
}
UT_Error OXML_Element_Row::serialize(IE_Exp_OpenXML* exporter)
{
UT_Error err = UT_OK;
m_rowNumber = table->getCurrentRowNumber();
err = exporter->startRow();
if(err != UT_OK)
return err;
err = this->serializeProperties(exporter);
if(err != UT_OK)
return err;
err = this->serializeChildren(exporter);
if(err != UT_OK)
return err;
return exporter->finishRow();
}
UT_Error OXML_Element_Row::serializeChildren(IE_Exp_OpenXML* exporter)
{
UT_Error ret = UT_OK;
OXML_ElementVector children = getChildren();
UT_sint32 left = 0;
OXML_SharedElement_Cell cell;
//during the loop check to see if we are missing any cells due to vertical merging
//if so let's add them manually
for (OXML_ElementVector::size_type i = 0; i < children.size(); i++)
{
cell = std::static_pointer_cast<OXML_Element_Cell>(children[i]);
//go through missing cells and serialize the correct ones
for (auto it = m_missingCells.begin(); it != m_missingCells.end() && (left < cell->getLeft()); ++it )
{
auto pCell = *it;
if (pCell->getLeft() == left)
{
//found missing cell
left = pCell->getRight();
ret = pCell->serialize(exporter);
if(ret != UT_OK)
return ret;
}
}
left = cell->getRight();
ret = cell->serialize(exporter);
if(ret != UT_OK)
return ret;
}
//right most vertically merged cells
for (; left < numCols; left++) {
OXML_SharedElement_Cell temp(new OXML_Element_Cell("", table, left, left + 1, -1, 0));
temp->setRow(this);
OXML_SharedElement shared_paragraph(new OXML_Element_Paragraph(""));
ret = temp->appendElement(shared_paragraph);
if(ret != UT_OK)
return ret;
ret = temp->serialize(exporter);
if(ret != UT_OK)
return ret;
}
return ret;
}
UT_Error OXML_Element_Row::serializeProperties(IE_Exp_OpenXML* exporter)
{
UT_Error err = UT_OK;
err = exporter->startRowProperties(TARGET);
if(err != UT_OK)
return err;
std::string height = table->getRowHeight(m_rowNumber);
if(height.compare("0in"))
{
err = exporter->setRowHeight(TARGET, height.c_str());
if(err != UT_OK)
return err;
}
return exporter->finishRowProperties(TARGET);
}
UT_Error OXML_Element_Row::addChildrenToPT(PD_Document * pDocument)
{
UT_Error ret = UT_OK;
UT_Error temp = UT_OK;
const gchar * szValue = NULL;
const gchar * bgColor = NULL;
getProperty("background-color", bgColor);
std::vector<OXML_Element*>::size_type i;
OXML_ElementVector children = getChildren();
for (i = 0; i < children.size(); i++)
{
m_currentColumnNumber = i;
if(bgColor && ((children[i]->getProperty("background-color", szValue) != UT_OK) || !szValue))
{
children[i]->setProperty("background-color", bgColor);
}
temp = children[i]->addToPT(pDocument);
if (temp != UT_OK)
ret = temp;
}
return ret;
}
UT_Error OXML_Element_Row::addToPT(PD_Document * pDocument)
{
m_rowNumber = table->getCurrentRowNumber();
return addChildrenToPT(pDocument);
}
void OXML_Element_Row::setNumCols(UT_sint32 columns)
{
numCols = columns;
}
void OXML_Element_Row::setRowNumber(int row)
{
m_rowNumber = row;
}
void OXML_Element_Row::addCell(const OXML_SharedElement_Cell& cell)
{
m_cells.push_back(cell);
cell->inheritProperties(this);
}
void OXML_Element_Row::addMissingCell(const OXML_SharedElement_Cell& cell)
{
m_missingCells.push_back(cell);
cell->setRow(this);
}
bool OXML_Element_Row::incrementBottomVerticalMergeStart(const OXML_SharedElement_Cell& cell)
{
int top = cell->getTop();
int left = cell->getLeft();
for (auto it = m_cells.begin(); it != m_cells.end(); ++it)
{
auto pCell = *it;
if ((pCell->getLeft() == left) && (pCell->getTop() < top) && pCell->startsVerticalMerge())
{
pCell->setBottom(pCell->getBottom()+1);
pCell->setLastVerticalContinuationCell(cell);
return true;
}
}
return false;
}
bool OXML_Element_Row::incrementRightHorizontalMergeStart(const OXML_SharedElement_Cell& cell)
{
int top = cell->getTop();
int left = cell->getLeft();
for (auto it = m_cells.rbegin(); it < m_cells.rend(); ++it)
{
auto pCell = *it;
if ((pCell->getTop() == top) && (pCell->getLeft() < left)
&& pCell->startsHorizontalMerge())
{
pCell->setRight(pCell->getRight()+1);
pCell->setLastHorizontalContinuationCell(cell);
return true;
}
}
return false;
}
|