fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwprowlayout.cxx
blobe7bae0f15dfc96023831c238f8bd43a0ec47ecac
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)
77 , crowid(0)
78 , cheight(0)
79 , cLeaderDotCount(0)
80 , cLeaderDotY(0)
81 , cRowFlags(0)
83 m_ConnCellList.clear();
86 LwpRowLayout::~LwpRowLayout()
89 /**
90 * @short register row style
91 * @param
92 * @param
93 * @param
94 * @return
96 void LwpRowLayout::SetRowMap()
98 LwpObjectID& rCellID= GetChildHead();
99 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
101 while(pCellLayout)
103 pCellLayout->SetCellMap();
105 rCellID = pCellLayout->GetNext();
106 pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
110 * @short register row style
111 * @param
112 * @param
113 * @param
114 * @return
116 void LwpRowLayout::RegisterStyle()
118 // register row style
119 XFRowStyle *pRowStyle = new XFRowStyle();
121 if (m_nDirection & 0x0030)
123 pRowStyle->SetMinRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
125 else
127 pRowStyle->SetRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
129 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
130 m_StyleName = pXFStyleManager->AddStyle(pRowStyle).m_pStyle->GetStyleName();
132 LwpTableLayout* pTableLayout = GetParentTableLayout();
133 if (pTableLayout)
135 pTableLayout->GetTable();
137 // register cells' style
138 LwpObjectID& rCellID= GetChildHead();
139 LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
141 while(pCellLayout)
143 pCellLayout->SetFoundry(m_pFoundry);
144 pCellLayout->RegisterStyle();
145 rCellID = pCellLayout->GetNext();
146 pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
151 * @short register row style
152 * @param
153 * @param
154 * @param
155 * @return
157 void LwpRowLayout::Read()
159 #define MAXUNIT (0x7fffffffL) // Highest positive UNIT value
160 LwpObjectStream* pStrm = m_pObjStrm;
162 LwpVirtualLayout::Read();
164 //skip CLiteLayout data;
165 LwpAtomHolder ContentClass;
166 ContentClass.Read(pStrm);
167 pStrm->SkipExtra();
169 // Row layout content
170 crowid = pStrm->QuickReaduInt16();
171 cheight = pStrm->QuickReadInt32();
172 cLeaderDotCount = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
173 cLeaderDotY = MAXUNIT; // Sentinel meaning "not calculated yet"
174 cRowFlags = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
176 pStrm->SkipExtra();
180 * @short Parse rows with connect cell
181 * @param pXFTable - pointer to created XFTable
183 void LwpRowLayout::ConvertRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
185 LwpTableLayout* pTableLayout = GetParentTableLayout();
186 LwpTable* pTable = pTableLayout->GetTable();
188 //calculate the connected cell position
189 sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
191 //if there is no connected cell
192 if (nMarkConnCell == -1)
194 ConvertCommonRow(pXFTable,nStartCol,nEndCol);
195 return;
198 //register connect row style
199 sal_uInt16 nRowMark = crowid + GetCurMaxSpannedRows(nStartCol,nEndCol);
200 XFRow* pXFRow = new XFRow;
201 RegisterCurRowStyle(pXFRow,nRowMark);
203 //if there is connected cell
204 for (sal_uInt8 i=nStartCol; i<nEndCol; )
206 XFCell* pXFCell;
207 sal_uInt8 nColMark;
209 if (nMarkConnCell == -1)
210 nColMark = nEndCol;
211 else
212 nColMark = m_ConnCellList[nMarkConnCell]->GetColID();
214 if (nColMark > i)//create subtable
216 pXFCell = new XFCell;
217 pXFCell->SetColumnSpaned(nColMark-i);
218 XFTable* pSubTable = new XFTable;
219 pTableLayout->ConvertTable(pSubTable,crowid,nRowMark,i,nColMark);
220 pXFCell->Add(pSubTable);
221 i = nColMark;
223 else
225 sal_uInt8 nColID = m_ConnCellList[nMarkConnCell]->GetColID()
226 +m_ConnCellList[nMarkConnCell]->GetNumcols()-1;
227 pXFCell = m_ConnCellList[nMarkConnCell]->ConvertCell(
228 pTable->GetObjectID(),
229 crowid+m_ConnCellList[nMarkConnCell]->GetNumrows()-1,
230 m_ConnCellList[nMarkConnCell]->GetColID());
232 //set all cell in this merge cell to cellsmap
233 for (sal_uInt16 nRowLoop = crowid;nRowLoop<nRowMark ;nRowLoop++)
234 for (sal_uInt8 nColLoop = i;nColLoop<nColID+1;nColLoop++)
235 pTableLayout->SetCellsMap(nRowLoop,nColLoop,pXFCell);
237 i += m_ConnCellList[nMarkConnCell]->GetNumcols();
238 nMarkConnCell = FindNextMarkConnCell(static_cast<sal_uInt16>(nMarkConnCell),nEndCol);
241 if (pXFCell)
242 pXFRow->AddCell(pXFCell);
244 pXFTable->AddRow(pXFRow);
248 * @short register row style in SODC table
249 * @param pXFRow - pointer of row
250 * @param nRowMark - spanned row number
252 void LwpRowLayout::RegisterCurRowStyle(XFRow* pXFRow,sal_uInt16 nRowMark)
254 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
255 XFRowStyle* pRowStyle = static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(m_StyleName));
256 if (!pRowStyle)
257 return;
258 double fHeight = pRowStyle->GetRowHeight();
260 XFRowStyle* pNewStyle = new XFRowStyle;
261 *pNewStyle = *pRowStyle;
262 LwpTableLayout* pTableLayout = GetParentTableLayout();
263 if (!pTableLayout)
265 delete pNewStyle;
266 return;
268 std::map<sal_uInt16,LwpRowLayout*> RowsMap = pTableLayout->GetRowsMap();
270 for (sal_uInt16 i=crowid+1; i<nRowMark;i++)
272 std::map<sal_uInt16,LwpRowLayout*>::iterator iter = RowsMap.find(i);
273 if (iter == RowsMap.end())
275 pRowStyle = static_cast<XFRowStyle*>(
276 pXFStyleManager->FindStyle(pTableLayout->GetDefaultRowStyleName()));
277 fHeight += pRowStyle->GetRowHeight();
279 else
281 pRowStyle = static_cast<XFRowStyle*>(
282 pXFStyleManager->FindStyle(iter->second->GetStyleName()));
283 fHeight+=pRowStyle->GetRowHeight();
287 if (m_nDirection & 0x0030)
289 pNewStyle->SetMinRowHeight((float)fHeight);
291 else
293 pNewStyle->SetRowHeight((float)fHeight);
296 pXFRow->SetStyleName(pXFStyleManager->AddStyle(pNewStyle).m_pStyle->GetStyleName());
300 * @short find max merge cell in a given column range
301 * @param nStartCol - start column ID
302 * @param nEndCol - end column ID
304 sal_Int32 LwpRowLayout::FindMarkConnCell(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
306 if (m_ConnCellList.empty())
307 return -1;
309 sal_uInt16 nSpannRows = 1;
310 sal_Int32 nMarkConnCell = -1;
312 for (sal_uInt16 i=0;i<m_ConnCellList.size();i++)
314 if (m_ConnCellList[i]->GetColID()>=nEndCol)
315 break;
316 if (m_ConnCellList[i]->GetColID()>=nStartCol)
318 if (m_ConnCellList[i]->GetNumrows()>nSpannRows)
320 nSpannRows = m_ConnCellList[i]->GetNumrows();
321 nMarkConnCell = i;
325 return nMarkConnCell;
329 * @short find next merge cell with the same spanned row number with current merge cell
330 * @param nStartCol - start column ID
331 * @param nEndCol - end column ID
333 sal_Int32 LwpRowLayout::FindNextMarkConnCell(sal_uInt16 nMarkConnCell,sal_uInt8 nEndCol)
335 sal_uInt16 nMaxRows = m_ConnCellList[nMarkConnCell]->GetNumrows();
337 for (sal_uInt16 i=nMarkConnCell+1;i<m_ConnCellList.size();i++)
339 if (m_ConnCellList[i]->GetColID()>=nEndCol)
340 break;
341 if (m_ConnCellList[i]->GetNumrows() == nMaxRows)
343 return i;
346 return -1;
349 * @short get max spanned row numbers in a given column range
350 * @param nStartCol - start column ID
351 * @param nEndCol - end column ID
353 sal_uInt16 LwpRowLayout::GetCurMaxSpannedRows(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
355 sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
356 if (nMarkConnCell == -1)
357 return 1;
358 else
359 return m_ConnCellList[nMarkConnCell]->GetNumrows();
362 * @short convert row with rowlayout,but no merge cells
363 * @param pXFTable - pointer of table
364 * @param nStartCol - start column ID
365 * @param nEndCol - end column ID
367 void LwpRowLayout::ConvertCommonRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
369 XFRow* pRow = new XFRow;
370 pRow->SetStyleName(m_StyleName);
372 XFCell * pCell = NULL;
373 LwpTableLayout* pTableLayout = GetParentTableLayout();
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 LwpConnectedCellLayout* pConnCell;
449 for (sal_uInt32 i=0; i<m_ConnCellList.size(); i++)
451 pConnCell = m_ConnCellList[i];
452 sal_uInt16 nRowSpan = pConnCell->GetRowID()+pConnCell->GetNumrows();
453 if ( nRowSpan > nEffectRows )
455 pConnCell->SetNumrows(nEffectRows - pConnCell->GetRowID());
460 * @short check if the row has merge cell
462 bool LwpRowLayout::GetMergeCellFlag()
464 if (m_ConnCellList.empty())
465 return false;
466 else
467 return true;
470 LwpRowHeadingLayout::LwpRowHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
471 : LwpRowLayout(objHdr, pStrm)
474 LwpRowHeadingLayout::~LwpRowHeadingLayout()
476 void LwpRowHeadingLayout::Read()
478 LwpRowLayout::Read();
480 cRowLayout.ReadIndexed(m_pObjStrm);
481 m_pObjStrm->SkipExtra();
484 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */