bump product version to 4.1.6.2
[LibreOffice.git] / lotuswordpro / source / filter / lwprowlayout.cxx
blob3c544eee0f17a1d1f88137792b33cf9ba25312e1
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
60 /*************************************************************************
61 * Change History
62 April 2005 Created
63 ************************************************************************/
64 #include "lwprowlayout.hxx"
65 #include "lwptable.hxx"
66 #include "lwpglobalmgr.hxx"
67 #include "xfilter/xfstylemanager.hxx"
68 #include "xfilter/xfrow.hxx"
69 #include "xfilter/xfrowstyle.hxx"
70 #include "xfilter/xftablestyle.hxx"
71 #include "xfilter/xftable.hxx"
72 #include "xfilter/xfcell.hxx"
73 #include "xfilter/xfcellstyle.hxx"
75 LwpRowLayout::LwpRowLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
76 : LwpVirtualLayout(objHdr, pStrm)
78 m_ConnCellList.clear();
81 LwpRowLayout::~LwpRowLayout()
84 /**
85 * @short register row style
86 * @param
87 * @param
88 * @param
89 * @return
91 void LwpRowLayout::SetRowMap(void)
93 LwpObjectID *pCellID= GetChildHead();
94 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
96 while(pCellLayout)
98 pCellLayout->SetCellMap();
100 pCellID = pCellLayout->GetNext();
101 pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
105 * @short register row style
106 * @param
107 * @param
108 * @param
109 * @return
111 void LwpRowLayout::RegisterStyle()
113 // register row style
114 XFRowStyle *pRowStyle = new XFRowStyle();
116 if (m_nDirection & 0x0030)
118 pRowStyle->SetMinRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
120 else
122 pRowStyle->SetRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
124 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
125 m_StyleName = pXFStyleManager->AddStyle(pRowStyle)->GetStyleName();
127 LwpTableLayout* pTableLayout = GetParentTableLayout();
128 if (pTableLayout)
130 pTableLayout->GetTable();
132 // register cells' style
133 LwpObjectID *pCellID= GetChildHead();
134 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
136 while(pCellLayout)
138 pCellLayout->SetFoundry(m_pFoundry);
139 pCellLayout->RegisterStyle();
140 pCellID = pCellLayout->GetNext();
141 pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
146 * @short register row style
147 * @param
148 * @param
149 * @param
150 * @return
152 void LwpRowLayout::Read()
154 #define MAXUNIT (0x7fffffffL) // Highest positive UNIT value
155 LwpObjectStream* pStrm = m_pObjStrm;
157 LwpVirtualLayout::Read();
159 //skip CLiteLayout data;
160 LwpAtomHolder ContentClass;
161 ContentClass.Read(pStrm);
162 pStrm->SkipExtra();
164 // Row layout content
165 crowid = pStrm->QuickReaduInt16();
166 cheight = pStrm->QuickReadInt32();
167 cLeaderDotCount = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
168 cLeaderDotY = MAXUNIT; // Sentinel meaning "not calculated yet"
169 cRowFlags = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
171 pStrm->SkipExtra();
175 * @short Parse rows with connect cell
176 * @param pXFTable - pointer to created XFTable
178 void LwpRowLayout::ConvertRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
180 LwpTableLayout* pTableLayout = GetParentTableLayout();
181 LwpTable* pTable = pTableLayout->GetTable();
183 //calculate the connected cell position
184 sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
186 //if there is no connected cell
187 if (nMarkConnCell == -1)
189 ConvertCommonRow(pXFTable,nStartCol,nEndCol);
190 return;
193 //register connect row style
194 sal_uInt16 nRowMark = crowid + GetCurMaxSpannedRows(nStartCol,nEndCol);
195 XFRow* pXFRow = new XFRow;
196 RegisterCurRowStyle(pXFRow,nRowMark);
198 //if there is connected cell
199 for (sal_uInt8 i=nStartCol; i<nEndCol; )
201 XFCell* pXFCell;
202 sal_uInt8 nColMark;
204 if (nMarkConnCell == -1)
205 nColMark = nEndCol;
206 else
207 nColMark = m_ConnCellList[nMarkConnCell]->GetColID();
209 if (nColMark > i)//create subtable
211 pXFCell = new XFCell;
212 pXFCell->SetColumnSpaned(nColMark-i);
213 XFTable* pSubTable = new XFTable;
214 pTableLayout->ConvertTable(pSubTable,crowid,nRowMark,i,nColMark);
215 pXFCell->Add(pSubTable);
216 i = nColMark;
218 else
220 sal_uInt8 nColID = m_ConnCellList[nMarkConnCell]->GetColID()
221 +m_ConnCellList[nMarkConnCell]->GetNumcols()-1;
222 pXFCell = m_ConnCellList[nMarkConnCell]->ConvertCell(
223 *pTable->GetObjectID(),
224 crowid+m_ConnCellList[nMarkConnCell]->GetNumrows()-1,
225 m_ConnCellList[nMarkConnCell]->GetColID());
227 //set all cell in this merge cell to cellsmap
228 for (sal_uInt16 nRowLoop = crowid;nRowLoop<nRowMark ;nRowLoop++)
229 for (sal_uInt8 nColLoop = i;nColLoop<nColID+1;nColLoop++)
230 pTableLayout->SetCellsMap(nRowLoop,nColLoop,pXFCell);
232 i += m_ConnCellList[nMarkConnCell]->GetNumcols();
233 nMarkConnCell = FindNextMarkConnCell(static_cast<sal_uInt16>(nMarkConnCell),nEndCol);
236 if (pXFCell)
237 pXFRow->AddCell(pXFCell);
239 pXFTable->AddRow(pXFRow);
243 * @short register row style in SODC table
244 * @param pXFRow - pointer of row
245 * @param nRowMark - spanned row number
247 void LwpRowLayout::RegisterCurRowStyle(XFRow* pXFRow,sal_uInt16 nRowMark)
249 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
250 XFRowStyle* pRowStyle = static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(m_StyleName));
251 if (!pRowStyle)
252 return;
253 double fHeight = pRowStyle->GetRowHeight();
255 XFRowStyle* pNewStyle = new XFRowStyle;
256 *pNewStyle = *pRowStyle;
257 LwpTableLayout* pTableLayout = GetParentTableLayout();
258 if (!pTableLayout)
260 delete pNewStyle;
261 return;
263 std::map<sal_uInt16,LwpRowLayout*> RowsMap = pTableLayout->GetRowsMap();
265 for (sal_uInt16 i=crowid+1; i<nRowMark;i++)
267 std::map<sal_uInt16,LwpRowLayout*>::iterator iter = RowsMap.find(i);
268 if (iter == RowsMap.end())
270 pRowStyle = static_cast<XFRowStyle*>(
271 pXFStyleManager->FindStyle(pTableLayout->GetDefaultRowStyleName()));
272 fHeight += pRowStyle->GetRowHeight();
274 else
276 pRowStyle = static_cast<XFRowStyle*>(
277 pXFStyleManager->FindStyle(iter->second->GetStyleName()));
278 fHeight+=pRowStyle->GetRowHeight();
282 if (m_nDirection & 0x0030)
284 pNewStyle->SetMinRowHeight((float)fHeight);
286 else
288 pNewStyle->SetRowHeight((float)fHeight);
291 pXFRow->SetStyleName(pXFStyleManager->AddStyle(pNewStyle)->GetStyleName());
295 * @short find max merge cell in a given column range
296 * @param nStartCol - start column ID
297 * @param nEndCol - end column ID
299 sal_Int32 LwpRowLayout::FindMarkConnCell(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
301 if (m_ConnCellList.empty())
302 return -1;
304 sal_uInt16 nSpannRows = 1;
305 sal_Int32 nMarkConnCell = -1;
307 for (sal_uInt16 i=0;i<m_ConnCellList.size();i++)
309 if (m_ConnCellList[i]->GetColID()>=nEndCol)
310 break;
311 if (m_ConnCellList[i]->GetColID()>=nStartCol)
313 if (m_ConnCellList[i]->GetNumrows()>nSpannRows)
315 nSpannRows = m_ConnCellList[i]->GetNumrows();
316 nMarkConnCell = i;
320 return nMarkConnCell;
324 * @short find next merge cell with the same spanned row number with current merge cell
325 * @param nStartCol - start column ID
326 * @param nEndCol - end column ID
328 sal_Int32 LwpRowLayout::FindNextMarkConnCell(sal_uInt16 nMarkConnCell,sal_uInt8 nEndCol)
330 sal_uInt16 nMaxRows = m_ConnCellList[nMarkConnCell]->GetNumrows();
332 for (sal_uInt16 i=nMarkConnCell+1;i<m_ConnCellList.size();i++)
334 if (m_ConnCellList[i]->GetColID()>=nEndCol)
335 break;
336 if (m_ConnCellList[i]->GetNumrows() == nMaxRows)
338 return i;
341 return -1;
344 * @short get max spanned row numbers in a given column range
345 * @param nStartCol - start column ID
346 * @param nEndCol - end column ID
348 sal_uInt16 LwpRowLayout::GetCurMaxSpannedRows(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
350 sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
351 if (nMarkConnCell == -1)
352 return 1;
353 else
354 return m_ConnCellList[nMarkConnCell]->GetNumrows();
357 * @short convert row with rowlayout,but no merge cells
358 * @param pXFTable - pointer of table
359 * @param nStartCol - start column ID
360 * @param nEndCol - end column ID
362 void LwpRowLayout::ConvertCommonRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
364 XFRow* pRow = new XFRow;
365 pRow->SetStyleName(m_StyleName);
367 XFCell * pCell = NULL;
368 LwpTableLayout* pTableLayout = GetParentTableLayout();
369 LwpTable* pTable = pTableLayout->GetTable();
370 sal_uInt8 nCellStartCol,nCellEndCol;
372 for (sal_uInt8 i = nStartCol; i < nEndCol ; i++)
374 // add row to table
375 LwpObjectID *pCellID= GetChildHead();
376 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
377 nCellStartCol = i;//mark the begin position of cell
378 nCellEndCol = i;//mark the end position of cell
379 while(pCellLayout)
381 if (pCellLayout->GetColID() == i)
383 if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
385 LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
386 nCellEndCol = i+pConnCell->GetNumcols()-1;
387 i = nCellEndCol;
389 pCell = pCellLayout->ConvertCell(*pTable->GetObjectID(),crowid,i);
390 break;
392 pCellID = pCellLayout->GetNext();
393 pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
395 if (!pCellLayout)
397 // if table has default cell layout, use it to ConvertCell
398 // otherwise use blank cell
399 LwpCellLayout * pDefaultCell = pTableLayout->GetDefaultCellLayout();
400 if (pDefaultCell)
402 pCell = pDefaultCell->ConvertCell(
403 *pTable->GetObjectID(),crowid, i);
405 else
407 pCell = new XFCell;
410 pRow->AddCell(pCell);
412 for (sal_uInt8 j=nCellStartCol;j<=nCellEndCol;j++)
413 pTableLayout->SetCellsMap(crowid,j,pCell);//set to cellsmap
416 pXFTable->AddRow(pRow);
419 * @short collect merge cell info when register row styles
421 void LwpRowLayout::CollectMergeInfo()
423 LwpObjectID *pCellID= GetChildHead();
424 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
426 while(pCellLayout)
428 if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
430 LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
431 m_ConnCellList.push_back(pConnCell);
433 pCellID = pCellLayout->GetNext();
434 pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
438 * @short split merge cells in this row
439 * @param nEffectRows - max spanned number of prevoius row
441 void LwpRowLayout::SetCellSplit(sal_uInt16 nEffectRows)
443 LwpConnectedCellLayout* pConnCell;
444 for (sal_uInt32 i=0; i<m_ConnCellList.size(); i++)
446 pConnCell = m_ConnCellList[i];
447 sal_uInt16 nRowSpan = pConnCell->GetRowID()+pConnCell->GetNumrows();
448 if ( nRowSpan > nEffectRows )
450 pConnCell->SetNumrows(nEffectRows - pConnCell->GetRowID());
455 * @short check if the row has merge cell
457 sal_Bool LwpRowLayout::GetMergeCellFlag()
459 if (m_ConnCellList.empty())
460 return sal_False;
461 else
462 return sal_True;
466 LwpRowHeadingLayout::LwpRowHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
467 : LwpRowLayout(objHdr, pStrm)
470 LwpRowHeadingLayout::~LwpRowHeadingLayout()
472 void LwpRowHeadingLayout::Read()
474 LwpRowLayout::Read();
476 cRowLayout.ReadIndexed(m_pObjStrm);
477 m_pObjStrm->SkipExtra();
480 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */