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
60 /*************************************************************************
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
)
83 m_ConnCellList
.clear();
86 LwpRowLayout::~LwpRowLayout()
90 * @short register row style
96 void LwpRowLayout::SetRowMap()
98 LwpObjectID
& rCellID
= GetChildHead();
99 LwpCellLayout
* pCellLayout
= dynamic_cast<LwpCellLayout
*>(rCellID
.obj().get());
103 pCellLayout
->SetCellMap();
105 rCellID
= pCellLayout
->GetNext();
106 pCellLayout
= dynamic_cast<LwpCellLayout
*>(rCellID
.obj().get());
110 * @short register row style
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
));
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();
135 pTableLayout
->GetTable();
137 // register cells' style
138 LwpObjectID
& rCellID
= GetChildHead();
139 LwpCellLayout
* pCellLayout
= dynamic_cast<LwpCellLayout
*>(rCellID
.obj().get());
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
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
);
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.
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
);
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
; )
209 if (nMarkConnCell
== -1)
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
);
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
);
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
));
258 double fHeight
= pRowStyle
->GetRowHeight();
260 XFRowStyle
* pNewStyle
= new XFRowStyle
;
261 *pNewStyle
= *pRowStyle
;
262 LwpTableLayout
* pTableLayout
= GetParentTableLayout();
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();
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
);
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())
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
)
316 if (m_ConnCellList
[i
]->GetColID()>=nStartCol
)
318 if (m_ConnCellList
[i
]->GetNumrows()>nSpannRows
)
320 nSpannRows
= m_ConnCellList
[i
]->GetNumrows();
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
)
341 if (m_ConnCellList
[i
]->GetNumrows() == nMaxRows
)
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)
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
++)
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 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())
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: */