update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwprowlayout.cxx
blob4f37aa417fb04e3e1890cbc9f74944d49fd4aa04
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /**
56 * @file
57 * For LWP filter architecture prototype - row layouts
59 /*************************************************************************
60 * Change History
61 April 2005 Created
62 ************************************************************************/
63 #include "lwprowlayout.hxx"
64 #include "lwptable.hxx"
65 #include "lwpglobalmgr.hxx"
66 #include "xfilter/xfstylemanager.hxx"
67 #include "xfilter/xfrow.hxx"
68 #include "xfilter/xfrowstyle.hxx"
69 #include "xfilter/xftablestyle.hxx"
70 #include "xfilter/xftable.hxx"
71 #include "xfilter/xfcell.hxx"
72 #include "xfilter/xfcellstyle.hxx"
74 LwpRowLayout::LwpRowLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
75 : LwpVirtualLayout(objHdr, pStrm)
77 m_ConnCellList.clear();
80 LwpRowLayout::~LwpRowLayout()
83 /**
84 * @short register row style
85 * @param
86 * @param
87 * @param
88 * @return
90 void LwpRowLayout::SetRowMap(void)
92 LwpObjectID *pCellID= GetChildHead();
93 LwpCellLayout * pCellLayout = static_cast<LwpCellLayout *>(pCellID->obj());
95 while(pCellLayout)
97 pCellLayout->SetCellMap();
99 pCellID = pCellLayout->GetNext();
100 pCellLayout = static_cast<LwpCellLayout *>(pCellID->obj());
104 * @short register row style
105 * @param
106 * @param
107 * @param
108 * @return
110 void LwpRowLayout::RegisterStyle()
112 // register row style
113 XFRowStyle *pRowStyle = new XFRowStyle();
115 if (m_nDirection & 0x0030)
117 pRowStyle->SetMinRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
119 else
121 pRowStyle->SetRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
123 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
124 m_StyleName = pXFStyleManager->AddStyle(pRowStyle)->GetStyleName();
126 LwpTableLayout* pTableLayout = GetParentTableLayout();
127 LwpTable * pTable = NULL;
128 if (pTableLayout)
130 pTable = pTableLayout->GetTable();
132 // register cells' style
133 LwpObjectID *pCellID= GetChildHead();
134 LwpCellLayout * pCellLayout = static_cast<LwpCellLayout *>(pCellID->obj());
136 while(pCellLayout)
138 pCellLayout->SetFoundry(m_pFoundry);
139 pCellLayout->RegisterStyle();
140 pCellID = pCellLayout->GetNext();
141 pCellLayout = static_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 XFRow* pXFRow = new XFRow;
182 LwpTableLayout* pTableLayout = GetParentTableLayout();
183 LwpTable* pTable = pTableLayout->GetTable();
185 //calculate the connected cell position
186 sal_Int32 nMarkConnCell;
187 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
189 //if there is no connected cell
190 if (nMarkConnCell == -1)
192 ConvertCommonRow(pXFTable,nStartCol,nEndCol);
193 return;
196 //register connect row style
197 sal_uInt16 nRowMark = crowid + GetCurMaxSpannedRows(nStartCol,nEndCol);
198 RegisterCurRowStyle(pXFRow,nRowMark);
200 sal_Bool bIsRight = sal_False;
201 sal_Bool bIsTop = sal_False;
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 XFRowStyle* pRowStyle;
255 XFRowStyle* pNewStyle = new XFRowStyle;
256 double fHeight;
257 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
258 pRowStyle = static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(m_StyleName));
259 if (!pRowStyle)
260 return;
261 fHeight = pRowStyle->GetRowHeight();
263 *pNewStyle = *pRowStyle;
264 std::map<sal_uInt16,LwpRowLayout*>::iterator iter;
265 LwpTableLayout* pTableLayout = GetParentTableLayout();
266 if (!pTableLayout)
267 return;
268 std::map<sal_uInt16,LwpRowLayout*> RowsMap = pTableLayout->GetRowsMap();
270 for (sal_uInt16 i=crowid+1; i<nRowMark;i++)
272 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)->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.size() == 0)
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;
373 LwpTableLayout* pTableLayout = GetParentTableLayout();
374 LwpTable* pTable = pTableLayout->GetTable();
375 sal_Bool bIsRight = sal_False;
376 sal_Bool bIsTop = sal_False;
377 sal_uInt8 nCellStartCol,nCellEndCol;
379 for (sal_uInt8 i = nStartCol; i < nEndCol ; i++)
381 // add row to table
382 LwpObjectID *pCellID= GetChildHead();
383 LwpCellLayout * pCellLayout = static_cast<LwpCellLayout *>(pCellID->obj());
384 nCellStartCol = i;//mark the begin position of cell
385 nCellEndCol = i;//mark the end position of cell
386 while(pCellLayout)
388 if (pCellLayout->GetColID() == i)
390 if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
392 LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
393 nCellEndCol = i+pConnCell->GetNumcols()-1;
394 i = nCellEndCol;
396 pCell = pCellLayout->ConvertCell(*pTable->GetObjectID(),crowid,i);
397 break;
399 pCellID = pCellLayout->GetNext();
400 pCellLayout = static_cast<LwpCellLayout *>(pCellID->obj());
402 if (!pCellLayout)
404 // if table has default cell layout, use it to ConvertCell
405 // otherwise use blank cell
406 LwpCellLayout * pDefaultCell = pTableLayout->GetDefaultCellLayout();
407 if (pDefaultCell)
409 pCell = pDefaultCell->ConvertCell(
410 *pTable->GetObjectID(),crowid, i);
412 else
414 pCell = new XFCell;
417 pRow->AddCell(pCell);
419 for (sal_uInt8 j=nCellStartCol;j<=nCellEndCol;j++)
420 pTableLayout->SetCellsMap(crowid,j,pCell);//set to cellsmap
423 pXFTable->AddRow(pRow);
426 * @short collect merge cell info when register row styles
428 void LwpRowLayout::CollectMergeInfo()
430 LwpObjectID *pCellID= GetChildHead();
431 LwpCellLayout * pCellLayout = static_cast<LwpCellLayout *>(pCellID->obj());
433 while(pCellLayout)
435 if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
437 LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
438 m_ConnCellList.push_back(pConnCell);
440 pCellID = pCellLayout->GetNext();
441 pCellLayout = static_cast<LwpCellLayout *>(pCellID->obj());
445 * @short split merge cells in this row
446 * @param nEffectRows - max spanned number of prevoius row
448 void LwpRowLayout::SetCellSplit(sal_uInt16 nEffectRows)
450 LwpConnectedCellLayout* pConnCell;
451 for (sal_uInt32 i=0; i<m_ConnCellList.size(); i++)
453 pConnCell = m_ConnCellList[i];
454 sal_uInt16 nRowSpan = pConnCell->GetRowID()+pConnCell->GetNumrows();
455 if ( nRowSpan > nEffectRows )
457 pConnCell->SetNumrows(nEffectRows - pConnCell->GetRowID());
462 * @short check if the row has merge cell
464 sal_Bool LwpRowLayout::GetMergeCellFlag()
466 if (m_ConnCellList.size() == 0)
467 return sal_False;
468 else
469 return sal_True;
473 LwpRowHeadingLayout::LwpRowHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
474 : LwpRowLayout(objHdr, pStrm)
477 LwpRowHeadingLayout::~LwpRowHeadingLayout()
479 void LwpRowHeadingLayout::Read()
481 LwpRowLayout::Read();
483 cRowLayout.ReadIndexed(m_pObjStrm);
484 m_pObjStrm->SkipExtra();
487 LwpRowLayout * LwpRowHeadingLayout::GetRowLayout()
489 LwpRowLayout * pRow = static_cast<LwpRowLayout *>(cRowLayout.obj());
490 return pRow;