Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
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
16 : *
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.
20 : *
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.
25 : *
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
30 : *
31 : *
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.
38 : *
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.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /**
57 : * @file
58 : * For LWP filter architecture prototype - row layouts
59 : */
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"
74 :
75 6 : LwpRowLayout::LwpRowLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
76 6 : : LwpVirtualLayout(objHdr, pStrm)
77 : {
78 6 : m_ConnCellList.clear();
79 6 : }
80 :
81 11 : LwpRowLayout::~LwpRowLayout()
82 11 : {}
83 :
84 : /**
85 : * @short register row style
86 : * @param
87 : * @param
88 : * @param
89 : * @return
90 : */
91 5 : void LwpRowLayout::SetRowMap(void)
92 : {
93 5 : LwpObjectID *pCellID= GetChildHead();
94 5 : LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
95 :
96 13 : while(pCellLayout)
97 : {
98 3 : pCellLayout->SetCellMap();
99 :
100 3 : pCellID = pCellLayout->GetNext();
101 3 : pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
102 : }
103 5 : }
104 : /**
105 : * @short register row style
106 : * @param
107 : * @param
108 : * @param
109 : * @return
110 : */
111 5 : void LwpRowLayout::RegisterStyle()
112 : {
113 : // register row style
114 5 : XFRowStyle *pRowStyle = new XFRowStyle();
115 :
116 5 : if (m_nDirection & 0x0030)
117 : {
118 5 : pRowStyle->SetMinRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
119 : }
120 : else
121 : {
122 0 : pRowStyle->SetRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
123 : }
124 5 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
125 5 : m_StyleName = pXFStyleManager->AddStyle(pRowStyle)->GetStyleName();
126 :
127 5 : LwpTableLayout* pTableLayout = GetParentTableLayout();
128 5 : if (pTableLayout)
129 : {
130 5 : pTableLayout->GetTable();
131 : }
132 : // register cells' style
133 5 : LwpObjectID *pCellID= GetChildHead();
134 5 : LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
135 :
136 13 : while(pCellLayout)
137 : {
138 3 : pCellLayout->SetFoundry(m_pFoundry);
139 3 : pCellLayout->RegisterStyle();
140 3 : pCellID = pCellLayout->GetNext();
141 3 : pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
142 : }
143 :
144 5 : }
145 : /**
146 : * @short register row style
147 : * @param
148 : * @param
149 : * @param
150 : * @return
151 : */
152 6 : void LwpRowLayout::Read()
153 : {
154 : #define MAXUNIT (0x7fffffffL) // Highest positive UNIT value
155 6 : LwpObjectStream* pStrm = m_pObjStrm;
156 :
157 6 : LwpVirtualLayout::Read();
158 :
159 : //skip CLiteLayout data;
160 6 : LwpAtomHolder ContentClass;
161 6 : ContentClass.Read(pStrm);
162 6 : pStrm->SkipExtra();
163 :
164 : // Row layout content
165 6 : crowid = pStrm->QuickReaduInt16();
166 6 : cheight = pStrm->QuickReadInt32();
167 6 : cLeaderDotCount = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
168 6 : cLeaderDotY = MAXUNIT; // Sentinel meaning "not calculated yet"
169 6 : cRowFlags = (sal_uInt8)pStrm->QuickReaduInt16(); // was written as lushort.
170 :
171 6 : pStrm->SkipExtra();
172 6 : }
173 :
174 : /**
175 : * @short Parse rows with connect cell
176 : * @param pXFTable - pointer to created XFTable
177 : */
178 0 : void LwpRowLayout::ConvertRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
179 : {
180 0 : XFRow* pXFRow = new XFRow;
181 :
182 0 : LwpTableLayout* pTableLayout = GetParentTableLayout();
183 0 : LwpTable* pTable = pTableLayout->GetTable();
184 :
185 : //calculate the connected cell position
186 : sal_Int32 nMarkConnCell;
187 0 : nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
188 :
189 : //if there is no connected cell
190 0 : if (nMarkConnCell == -1)
191 : {
192 0 : ConvertCommonRow(pXFTable,nStartCol,nEndCol);
193 0 : return;
194 : }
195 :
196 : //register connect row style
197 0 : sal_uInt16 nRowMark = crowid + GetCurMaxSpannedRows(nStartCol,nEndCol);
198 0 : RegisterCurRowStyle(pXFRow,nRowMark);
199 :
200 : //if there is connected cell
201 0 : for (sal_uInt8 i=nStartCol; i<nEndCol; )
202 : {
203 : XFCell* pXFCell;
204 : sal_uInt8 nColMark;
205 :
206 0 : if (nMarkConnCell == -1)
207 0 : nColMark = nEndCol;
208 : else
209 0 : nColMark = m_ConnCellList[nMarkConnCell]->GetColID();
210 :
211 0 : if (nColMark > i)//create subtable
212 : {
213 0 : pXFCell = new XFCell;
214 0 : pXFCell->SetColumnSpaned(nColMark-i);
215 0 : XFTable* pSubTable = new XFTable;
216 0 : pTableLayout->ConvertTable(pSubTable,crowid,nRowMark,i,nColMark);
217 0 : pXFCell->Add(pSubTable);
218 0 : i = nColMark;
219 : }
220 : else
221 : {
222 0 : sal_uInt8 nColID = m_ConnCellList[nMarkConnCell]->GetColID()
223 0 : +m_ConnCellList[nMarkConnCell]->GetNumcols()-1;
224 0 : pXFCell = m_ConnCellList[nMarkConnCell]->ConvertCell(
225 0 : *pTable->GetObjectID(),
226 0 : crowid+m_ConnCellList[nMarkConnCell]->GetNumrows()-1,
227 0 : m_ConnCellList[nMarkConnCell]->GetColID());
228 :
229 : //set all cell in this merge cell to cellsmap
230 0 : for (sal_uInt16 nRowLoop = crowid;nRowLoop<nRowMark ;nRowLoop++)
231 0 : for (sal_uInt8 nColLoop = i;nColLoop<nColID+1;nColLoop++)
232 0 : pTableLayout->SetCellsMap(nRowLoop,nColLoop,pXFCell);
233 :
234 0 : i += m_ConnCellList[nMarkConnCell]->GetNumcols();
235 0 : nMarkConnCell = FindNextMarkConnCell(static_cast<sal_uInt16>(nMarkConnCell),nEndCol);
236 : }
237 :
238 0 : if (pXFCell)
239 0 : pXFRow->AddCell(pXFCell);
240 : }
241 0 : pXFTable->AddRow(pXFRow);
242 : }
243 :
244 : /**
245 : * @short register row style in SODC table
246 : * @param pXFRow - pointer of row
247 : * @param nRowMark - spanned row number
248 : */
249 0 : void LwpRowLayout::RegisterCurRowStyle(XFRow* pXFRow,sal_uInt16 nRowMark)
250 : {
251 : XFRowStyle* pRowStyle;
252 0 : XFRowStyle* pNewStyle = new XFRowStyle;
253 : double fHeight;
254 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
255 0 : pRowStyle = static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(m_StyleName));
256 0 : if (!pRowStyle)
257 : return;
258 0 : fHeight = pRowStyle->GetRowHeight();
259 :
260 0 : *pNewStyle = *pRowStyle;
261 0 : std::map<sal_uInt16,LwpRowLayout*>::iterator iter;
262 0 : LwpTableLayout* pTableLayout = GetParentTableLayout();
263 0 : if (!pTableLayout)
264 : return;
265 0 : std::map<sal_uInt16,LwpRowLayout*> RowsMap = pTableLayout->GetRowsMap();
266 :
267 0 : for (sal_uInt16 i=crowid+1; i<nRowMark;i++)
268 : {
269 0 : iter = RowsMap.find(i);
270 0 : if (iter == RowsMap.end())
271 : {
272 : pRowStyle = static_cast<XFRowStyle*>(
273 0 : pXFStyleManager->FindStyle(pTableLayout->GetDefaultRowStyleName()));
274 0 : fHeight += pRowStyle->GetRowHeight();
275 : }
276 : else
277 : {
278 : pRowStyle = static_cast<XFRowStyle*>(
279 0 : pXFStyleManager->FindStyle(iter->second->GetStyleName()));
280 0 : fHeight+=pRowStyle->GetRowHeight();
281 : }
282 : }
283 :
284 0 : if (m_nDirection & 0x0030)
285 : {
286 0 : pNewStyle->SetMinRowHeight((float)fHeight);
287 : }
288 : else
289 : {
290 0 : pNewStyle->SetRowHeight((float)fHeight);
291 : }
292 :
293 0 : pXFRow->SetStyleName(pXFStyleManager->AddStyle(pNewStyle)->GetStyleName());
294 : }
295 :
296 : /**
297 : * @short find max merge cell in a given column range
298 : * @param nStartCol - start column ID
299 : * @param nEndCol - end column ID
300 : */
301 5 : sal_Int32 LwpRowLayout::FindMarkConnCell(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
302 : {
303 5 : if (m_ConnCellList.empty())
304 5 : return -1;
305 :
306 0 : sal_uInt16 nSpannRows = 1;
307 0 : sal_Int32 nMarkConnCell = -1;
308 :
309 0 : for (sal_uInt16 i=0;i<m_ConnCellList.size();i++)
310 : {
311 0 : if (m_ConnCellList[i]->GetColID()>=nEndCol)
312 0 : break;
313 0 : if (m_ConnCellList[i]->GetColID()>=nStartCol)
314 : {
315 0 : if (m_ConnCellList[i]->GetNumrows()>nSpannRows)
316 : {
317 0 : nSpannRows = m_ConnCellList[i]->GetNumrows();
318 0 : nMarkConnCell = i;
319 : }
320 : }
321 : }
322 0 : return nMarkConnCell;
323 : }
324 :
325 : /**
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
329 : */
330 0 : sal_Int32 LwpRowLayout::FindNextMarkConnCell(sal_uInt16 nMarkConnCell,sal_uInt8 nEndCol)
331 : {
332 0 : sal_uInt16 nMaxRows = m_ConnCellList[nMarkConnCell]->GetNumrows();
333 :
334 0 : for (sal_uInt16 i=nMarkConnCell+1;i<m_ConnCellList.size();i++)
335 : {
336 0 : if (m_ConnCellList[i]->GetColID()>=nEndCol)
337 0 : break;
338 0 : if (m_ConnCellList[i]->GetNumrows() == nMaxRows)
339 : {
340 0 : return i;
341 : }
342 : }
343 0 : return -1;
344 : }
345 : /**
346 : * @short get max spanned row numbers in a given column range
347 : * @param nStartCol - start column ID
348 : * @param nEndCol - end column ID
349 : */
350 5 : sal_uInt16 LwpRowLayout::GetCurMaxSpannedRows(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
351 : {
352 5 : sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
353 5 : if (nMarkConnCell == -1)
354 5 : return 1;
355 : else
356 0 : return m_ConnCellList[nMarkConnCell]->GetNumrows();
357 : }
358 : /**
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
363 : */
364 5 : void LwpRowLayout::ConvertCommonRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
365 : {
366 5 : XFRow* pRow = new XFRow;
367 5 : pRow->SetStyleName(m_StyleName);
368 :
369 5 : XFCell * pCell = NULL;
370 5 : LwpTableLayout* pTableLayout = GetParentTableLayout();
371 5 : LwpTable* pTable = pTableLayout->GetTable();
372 : sal_uInt8 nCellStartCol,nCellEndCol;
373 :
374 25 : for (sal_uInt8 i = nStartCol; i < nEndCol ; i++)
375 : {
376 : // add row to table
377 20 : LwpObjectID *pCellID= GetChildHead();
378 20 : LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
379 20 : nCellStartCol = i;//mark the begin position of cell
380 20 : nCellEndCol = i;//mark the end position of cell
381 48 : while(pCellLayout)
382 : {
383 11 : if (pCellLayout->GetColID() == i)
384 : {
385 3 : if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
386 : {
387 0 : LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
388 0 : nCellEndCol = i+pConnCell->GetNumcols()-1;
389 0 : i = nCellEndCol;
390 : }
391 3 : pCell = pCellLayout->ConvertCell(*pTable->GetObjectID(),crowid,i);
392 3 : break;
393 : }
394 8 : pCellID = pCellLayout->GetNext();
395 8 : pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
396 : }
397 20 : if (!pCellLayout)
398 : {
399 : // if table has default cell layout, use it to ConvertCell
400 : // otherwise use blank cell
401 17 : LwpCellLayout * pDefaultCell = pTableLayout->GetDefaultCellLayout();
402 17 : if (pDefaultCell)
403 : {
404 : pCell = pDefaultCell->ConvertCell(
405 17 : *pTable->GetObjectID(),crowid, i);
406 : }
407 : else
408 : {
409 0 : pCell = new XFCell;
410 : }
411 : }
412 20 : pRow->AddCell(pCell);
413 :
414 40 : for (sal_uInt8 j=nCellStartCol;j<=nCellEndCol;j++)
415 20 : pTableLayout->SetCellsMap(crowid,j,pCell);//set to cellsmap
416 : }
417 :
418 5 : pXFTable->AddRow(pRow);
419 5 : }
420 : /**
421 : * @short collect merge cell info when register row styles
422 : */
423 5 : void LwpRowLayout::CollectMergeInfo()
424 : {
425 5 : LwpObjectID *pCellID= GetChildHead();
426 5 : LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
427 :
428 13 : while(pCellLayout)
429 : {
430 3 : if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
431 : {
432 0 : LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
433 0 : m_ConnCellList.push_back(pConnCell);
434 : }
435 3 : pCellID = pCellLayout->GetNext();
436 3 : pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj());
437 : }
438 5 : }
439 : /**
440 : * @short split merge cells in this row
441 : * @param nEffectRows - max spanned number of prevoius row
442 : */
443 0 : void LwpRowLayout::SetCellSplit(sal_uInt16 nEffectRows)
444 : {
445 : LwpConnectedCellLayout* pConnCell;
446 0 : for (sal_uInt32 i=0; i<m_ConnCellList.size(); i++)
447 : {
448 0 : pConnCell = m_ConnCellList[i];
449 0 : sal_uInt16 nRowSpan = pConnCell->GetRowID()+pConnCell->GetNumrows();
450 0 : if ( nRowSpan > nEffectRows )
451 : {
452 0 : pConnCell->SetNumrows(nEffectRows - pConnCell->GetRowID());
453 : }
454 : }
455 0 : }
456 : /**
457 : * @short check if the row has merge cell
458 : */
459 5 : sal_Bool LwpRowLayout::GetMergeCellFlag()
460 : {
461 5 : if (m_ConnCellList.empty())
462 5 : return sal_False;
463 : else
464 0 : return sal_True;
465 : }
466 :
467 :
468 0 : LwpRowHeadingLayout::LwpRowHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
469 0 : : LwpRowLayout(objHdr, pStrm)
470 0 : {}
471 :
472 0 : LwpRowHeadingLayout::~LwpRowHeadingLayout()
473 0 : {}
474 0 : void LwpRowHeadingLayout::Read()
475 : {
476 0 : LwpRowLayout::Read();
477 :
478 0 : cRowLayout.ReadIndexed(m_pObjStrm);
479 0 : m_pObjStrm->SkipExtra();
480 0 : }
481 :
482 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|