Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwprowlayout.cxx
blob1e83779de6267e663def4bbb134cc4bca9cfcc2f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /**
57 * @file
58 * For LWP filter architecture prototype - row layouts
61 #include "lwprowlayout.hxx"
62 #include "lwptable.hxx"
63 #include "lwpglobalmgr.hxx"
64 #include "xfilter/xfstylemanager.hxx"
65 #include "xfilter/xfrow.hxx"
66 #include "xfilter/xfrowstyle.hxx"
67 #include "xfilter/xftablestyle.hxx"
68 #include "xfilter/xftable.hxx"
69 #include "xfilter/xfcell.hxx"
70 #include "xfilter/xfcellstyle.hxx"
72 LwpRowLayout::LwpRowLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
73 : LwpVirtualLayout(objHdr, pStrm)
74 , crowid(0)
75 , cheight(0)
76 , cLeaderDotCount(0)
77 , cLeaderDotY(0)
78 , cRowFlags(0)
80 m_ConnCellList.clear();
83 LwpRowLayout::~LwpRowLayout()
86 /**
87 * @short register row style
88 * @param
89 * @param
90 * @param
91 * @return
93 void LwpRowLayout::SetRowMap()
95 LwpObjectID& rCellID= GetChildHead();
96 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
98 while(pCellLayout)
100 pCellLayout->SetCellMap();
102 rCellID = pCellLayout->GetNext();
103 pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
107 * @short register row style
108 * @param
109 * @param
110 * @param
111 * @return
113 void LwpRowLayout::RegisterStyle()
115 // register row style
116 XFRowStyle *pRowStyle = new XFRowStyle();
118 if (m_nDirection & 0x0030)
120 pRowStyle->SetMinRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
122 else
124 pRowStyle->SetRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
126 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
127 m_StyleName = pXFStyleManager->AddStyle(pRowStyle).m_pStyle->GetStyleName();
129 LwpTableLayout* pTableLayout = GetParentTableLayout();
130 if (pTableLayout)
132 pTableLayout->GetTable();
134 // register cells' style
135 LwpObjectID& rCellID= GetChildHead();
136 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
138 while(pCellLayout)
140 pCellLayout->SetFoundry(m_pFoundry);
141 pCellLayout->RegisterStyle();
142 rCellID = pCellLayout->GetNext();
143 pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
148 * @short register row style
149 * @param
150 * @param
151 * @param
152 * @return
154 void LwpRowLayout::Read()
156 #define MAXUNIT (0x7fffffffL) // Highest positive UNIT value
157 LwpObjectStream* pStrm = m_pObjStrm;
159 LwpVirtualLayout::Read();
161 //skip CLiteLayout data;
162 LwpAtomHolder ContentClass;
163 ContentClass.Read(pStrm);
164 pStrm->SkipExtra();
166 // Row layout content
167 crowid = pStrm->QuickReaduInt16();
168 cheight = pStrm->QuickReadInt32();
169 cLeaderDotCount = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
170 cLeaderDotY = MAXUNIT; // Sentinel meaning "not calculated yet"
171 cRowFlags = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
173 pStrm->SkipExtra();
177 * @short Parse rows with connect cell
178 * @param pXFTable - pointer to created XFTable
180 void LwpRowLayout::ConvertRow(rtl::Reference<XFTable> const & pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
182 LwpTableLayout* pTableLayout = GetParentTableLayout();
183 LwpTable* pTable = pTableLayout->GetTable();
185 //calculate the connected cell position
186 sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
188 //if there is no connected cell
189 if (nMarkConnCell == -1)
191 ConvertCommonRow(pXFTable,nStartCol,nEndCol);
192 return;
195 //register connect row style
196 sal_uInt16 nRowMark = crowid + GetCurMaxSpannedRows(nStartCol,nEndCol);
197 XFRow* pXFRow = new XFRow;
198 RegisterCurRowStyle(pXFRow,nRowMark);
200 //if there is connected cell
201 for (sal_uInt8 i=nStartCol; i<nEndCol; )
203 XFCell* pXFCell;
204 sal_uInt8 nColMark;
206 if (nMarkConnCell == -1)
207 nColMark = nEndCol;
208 else
209 nColMark = m_ConnCellList[nMarkConnCell]->GetColID();
211 if (nColMark > i)//create subtable
213 pXFCell = new XFCell;
214 pXFCell->SetColumnSpaned(nColMark-i);
215 XFTable* pSubTable = new XFTable;
216 pTableLayout->ConvertTable(pSubTable,crowid,nRowMark,i,nColMark);
217 pXFCell->Add(pSubTable);
218 i = nColMark;
220 else
222 sal_uInt8 nColID = m_ConnCellList[nMarkConnCell]->GetColID()
223 +m_ConnCellList[nMarkConnCell]->GetNumcols()-1;
224 pXFCell = m_ConnCellList[nMarkConnCell]->ConvertCell(
225 pTable->GetObjectID(),
226 crowid+m_ConnCellList[nMarkConnCell]->GetNumrows()-1,
227 m_ConnCellList[nMarkConnCell]->GetColID());
229 //set all cell in this merge cell to cellsmap
230 for (sal_uInt16 nRowLoop = crowid;nRowLoop<nRowMark ;nRowLoop++)
231 for (sal_uInt8 nColLoop = i;nColLoop<nColID+1;nColLoop++)
232 pTableLayout->SetCellsMap(nRowLoop,nColLoop,pXFCell);
234 i += m_ConnCellList[nMarkConnCell]->GetNumcols();
235 nMarkConnCell = FindNextMarkConnCell(static_cast<sal_uInt16>(nMarkConnCell),nEndCol);
238 if (pXFCell)
239 pXFRow->AddCell(pXFCell);
241 pXFTable->AddRow(pXFRow);
245 * @short register row style in SODC table
246 * @param pXFRow - pointer of row
247 * @param nRowMark - spanned row number
249 void LwpRowLayout::RegisterCurRowStyle(XFRow* pXFRow,sal_uInt16 nRowMark)
251 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
252 XFRowStyle* pRowStyle = static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(m_StyleName));
253 if (!pRowStyle)
254 return;
255 double fHeight = pRowStyle->GetRowHeight();
257 XFRowStyle* pNewStyle = new XFRowStyle;
258 *pNewStyle = *pRowStyle;
259 LwpTableLayout* pTableLayout = GetParentTableLayout();
260 if (!pTableLayout)
262 delete pNewStyle;
263 return;
265 std::map<sal_uInt16,LwpRowLayout*> RowsMap = pTableLayout->GetRowsMap();
267 for (sal_uInt16 i=crowid+1; i<nRowMark;i++)
269 std::map<sal_uInt16,LwpRowLayout*>::iterator iter = RowsMap.find(i);
270 if (iter == RowsMap.end())
272 pRowStyle = static_cast<XFRowStyle*>(
273 pXFStyleManager->FindStyle(pTableLayout->GetDefaultRowStyleName()));
274 fHeight += pRowStyle->GetRowHeight();
276 else
278 pRowStyle = static_cast<XFRowStyle*>(
279 pXFStyleManager->FindStyle(iter->second->GetStyleName()));
280 fHeight+=pRowStyle->GetRowHeight();
284 if (m_nDirection & 0x0030)
286 pNewStyle->SetMinRowHeight((float)fHeight);
288 else
290 pNewStyle->SetRowHeight((float)fHeight);
293 pXFRow->SetStyleName(pXFStyleManager->AddStyle(pNewStyle).m_pStyle->GetStyleName());
297 * @short find max merge cell in a given column range
298 * @param nStartCol - start column ID
299 * @param nEndCol - end column ID
301 sal_Int32 LwpRowLayout::FindMarkConnCell(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
303 if (m_ConnCellList.empty())
304 return -1;
306 sal_uInt16 nSpannRows = 1;
307 sal_Int32 nMarkConnCell = -1;
309 for (size_t i=0;i<m_ConnCellList.size();i++)
311 if (m_ConnCellList[i]->GetColID()>=nEndCol)
312 break;
313 if (m_ConnCellList[i]->GetColID()>=nStartCol)
315 if (m_ConnCellList[i]->GetNumrows()>nSpannRows)
317 nSpannRows = m_ConnCellList[i]->GetNumrows();
318 nMarkConnCell = i;
322 return nMarkConnCell;
326 * @short find next merge cell with the same spanned row number with current merge cell
327 * @param nStartCol - start column ID
328 * @param nEndCol - end column ID
330 sal_Int32 LwpRowLayout::FindNextMarkConnCell(sal_uInt16 nMarkConnCell,sal_uInt8 nEndCol)
332 sal_uInt16 nMaxRows = m_ConnCellList[nMarkConnCell]->GetNumrows();
334 for (size_t i=nMarkConnCell+1;i<m_ConnCellList.size();i++)
336 if (m_ConnCellList[i]->GetColID()>=nEndCol)
337 break;
338 if (m_ConnCellList[i]->GetNumrows() == nMaxRows)
340 return i;
343 return -1;
346 * @short get max spanned row numbers in a given column range
347 * @param nStartCol - start column ID
348 * @param nEndCol - end column ID
350 sal_uInt16 LwpRowLayout::GetCurMaxSpannedRows(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
352 sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
353 if (nMarkConnCell == -1)
354 return 1;
355 else
356 return m_ConnCellList[nMarkConnCell]->GetNumrows();
359 * @short convert row with rowlayout,but no merge cells
360 * @param pXFTable - pointer of table
361 * @param nStartCol - start column ID
362 * @param nEndCol - end column ID
364 void LwpRowLayout::ConvertCommonRow(rtl::Reference<XFTable> const & pXFTable, sal_uInt8 nStartCol, sal_uInt8 nEndCol)
366 LwpTableLayout* pTableLayout = GetParentTableLayout();
367 if (!pTableLayout)
368 return;
370 XFRow* pRow = new XFRow;
371 pRow->SetStyleName(m_StyleName);
373 XFCell * pCell = nullptr;
374 LwpTable* pTable = pTableLayout->GetTable();
375 sal_uInt8 nCellStartCol,nCellEndCol;
377 for (sal_uInt8 i = nStartCol; i < nEndCol ; i++)
379 // add row to table
380 LwpObjectID& rCellID= GetChildHead();
381 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
382 nCellStartCol = i;//mark the begin position of cell
383 nCellEndCol = i;//mark the end position of cell
384 while(pCellLayout)
386 if (pCellLayout->GetColID() == i)
388 if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
390 LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
391 nCellEndCol = i+pConnCell->GetNumcols()-1;
392 i = nCellEndCol;
394 pCell = pCellLayout->ConvertCell(pTable->GetObjectID(),crowid,i);
395 break;
397 rCellID = pCellLayout->GetNext();
398 pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
400 if (!pCellLayout)
402 // if table has default cell layout, use it to ConvertCell
403 // otherwise use blank cell
404 LwpCellLayout * pDefaultCell = pTableLayout->GetDefaultCellLayout();
405 if (pDefaultCell)
407 pCell = pDefaultCell->ConvertCell(
408 pTable->GetObjectID(),crowid, i);
410 else
412 pCell = new XFCell;
415 pRow->AddCell(pCell);
417 for (sal_uInt8 j=nCellStartCol;j<=nCellEndCol;j++)
418 pTableLayout->SetCellsMap(crowid,j,pCell);//set to cellsmap
421 pXFTable->AddRow(pRow);
424 * @short collect merge cell info when register row styles
426 void LwpRowLayout::CollectMergeInfo()
428 LwpObjectID& rCellID= GetChildHead();
429 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
431 while(pCellLayout)
433 if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
435 LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
436 m_ConnCellList.push_back(pConnCell);
438 rCellID = pCellLayout->GetNext();
439 pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
443 * @short split merge cells in this row
444 * @param nEffectRows - max spanned number of prevoius row
446 void LwpRowLayout::SetCellSplit(sal_uInt16 nEffectRows)
448 for (LwpConnectedCellLayout* pConnCell : m_ConnCellList)
450 sal_uInt16 nRowSpan = pConnCell->GetRowID()+pConnCell->GetNumrows();
451 if ( nRowSpan > nEffectRows )
453 pConnCell->SetNumrows(nEffectRows - pConnCell->GetRowID());
458 * @short check if the row has merge cell
460 bool LwpRowLayout::GetMergeCellFlag()
462 if (m_ConnCellList.empty())
463 return false;
464 else
465 return true;
468 LwpRowHeadingLayout::LwpRowHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
469 : LwpRowLayout(objHdr, pStrm)
472 LwpRowHeadingLayout::~LwpRowHeadingLayout()
474 void LwpRowHeadingLayout::Read()
476 LwpRowLayout::Read();
478 cRowLayout.ReadIndexed(m_pObjStrm);
479 m_pObjStrm->SkipExtra();
482 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */