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,
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 ************************************************************************/
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
)
80 m_ConnCellList
.clear();
83 LwpRowLayout::~LwpRowLayout()
87 * @short register row style
93 void LwpRowLayout::SetRowMap()
95 LwpObjectID
& rCellID
= GetChildHead();
96 LwpCellLayout
* pCellLayout
= dynamic_cast<LwpCellLayout
*>(rCellID
.obj().get());
100 pCellLayout
->SetCellMap();
102 rCellID
= pCellLayout
->GetNext();
103 pCellLayout
= dynamic_cast<LwpCellLayout
*>(rCellID
.obj().get());
107 * @short register row style
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
));
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();
132 pTableLayout
->GetTable();
134 // register cells' style
135 LwpObjectID
& rCellID
= GetChildHead();
136 LwpCellLayout
* pCellLayout
= dynamic_cast<LwpCellLayout
*>(rCellID
.obj().get());
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
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
);
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.
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
);
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
; )
206 if (nMarkConnCell
== -1)
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
);
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
);
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
));
255 double fHeight
= pRowStyle
->GetRowHeight();
257 XFRowStyle
* pNewStyle
= new XFRowStyle
;
258 *pNewStyle
= *pRowStyle
;
259 LwpTableLayout
* pTableLayout
= GetParentTableLayout();
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();
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
);
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())
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
)
313 if (m_ConnCellList
[i
]->GetColID()>=nStartCol
)
315 if (m_ConnCellList
[i
]->GetNumrows()>nSpannRows
)
317 nSpannRows
= m_ConnCellList
[i
]->GetNumrows();
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
)
338 if (m_ConnCellList
[i
]->GetNumrows() == nMaxRows
)
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)
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();
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
++)
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
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;
394 pCell
= pCellLayout
->ConvertCell(pTable
->GetObjectID(),crowid
,i
);
397 rCellID
= pCellLayout
->GetNext();
398 pCellLayout
= dynamic_cast<LwpCellLayout
*>(rCellID
.obj().get());
402 // if table has default cell layout, use it to ConvertCell
403 // otherwise use blank cell
404 LwpCellLayout
* pDefaultCell
= pTableLayout
->GetDefaultCellLayout();
407 pCell
= pDefaultCell
->ConvertCell(
408 pTable
->GetObjectID(),crowid
, i
);
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());
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())
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: */