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 - cell layouts
59 : */
60 : /*************************************************************************
61 : * Change History
62 : April 2005 Created
63 : ************************************************************************/
64 : #include "lwpcelllayout.hxx"
65 : #include "lwpfoundry.hxx"
66 : #include "lwpobjfactory.hxx"
67 : #include "lwptblcell.hxx"
68 : #include "lwptblformula.hxx"
69 : #include "lwpholder.hxx"
70 : #include "lwpnumericfmt.hxx"
71 : #include "lwptable.hxx"
72 : #include "lwpglobalmgr.hxx"
73 :
74 : #include "xfilter/xfstylemanager.hxx"
75 : #include "xfilter/xfcell.hxx"
76 : #include "xfilter/xfcellstyle.hxx"
77 : #include "xfilter/xfcolstyle.hxx"
78 :
79 23 : LwpCellLayout::LwpCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
80 : : LwpMiddleLayout(objHdr, pStrm)
81 23 : , cType(LDT_NONE)
82 23 : {}
83 :
84 159 : LwpCellLayout::~LwpCellLayout()
85 159 : {}
86 :
87 : /**
88 : * @short Get table layout pointer, if default cell layout, return NULL
89 : * @param LwpTableLayout *
90 : * @return
91 : */
92 7 : LwpTableLayout * LwpCellLayout::GetTableLayout()
93 : {
94 7 : LwpRowLayout * pRow = dynamic_cast<LwpRowLayout *>(GetParent()->obj());
95 7 : if(!pRow)
96 : {
97 0 : return NULL;
98 : }
99 7 : LwpTableLayout * pTableLayout = pRow->GetParentTableLayout();
100 7 : return pTableLayout;
101 : }
102 : /**
103 : * @short Get table pointer, if default cell layout, return NULL
104 : * @param LwpTable *
105 : * @return
106 : */
107 1 : LwpTable * LwpCellLayout::GetTable()
108 : {
109 1 : LwpTableLayout * pTableLayout = GetTableLayout();
110 1 : if(!pTableLayout)
111 : {
112 0 : return NULL;
113 : }
114 1 : LwpTable *pTable = pTableLayout->GetTable();
115 1 : return pTable;
116 : }
117 : /**
118 : * @short Set current cell layout to cell layout map
119 : * @param
120 : * @return
121 : */
122 3 : void LwpCellLayout::SetCellMap()
123 : {
124 : // this function is called from LwpTableLayout, so it can't be NULL
125 3 : GetTableLayout()->SetWordProCellMap(crowid, ccolid, this);
126 3 : }
127 : /**
128 : * @short Get actual width of this cell layout
129 : * @param
130 : * @return width (cm)
131 : */
132 0 : double LwpCellLayout::GetActualWidth()
133 : {
134 : //Get table layout
135 0 : LwpTableLayout * pTableLayout = GetTableLayout();
136 :
137 0 : if (pTableLayout == NULL)
138 : {
139 0 : return GetGeometryWidth();
140 : }
141 :
142 0 : OUString strColStyle = pTableLayout->GetColumnWidth(ccolid);
143 :
144 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
145 0 : XFColStyle *pStyle = static_cast<XFColStyle *>(pXFStyleManager->FindStyle(strColStyle));
146 0 : if(pStyle)
147 : {
148 0 : return pStyle->GetWidth();
149 : }
150 :
151 0 : return GetGeometryWidth();
152 : }
153 :
154 : /**
155 : * @short Apply padding to cell style
156 : * @param pCellStyle - pointer of XFCellStyle
157 : * @return
158 : */
159 75 : void LwpCellLayout::ApplyPadding(XFCellStyle *pCellStyle)
160 : {
161 75 : double fLeft = GetMarginsValue(MARGIN_LEFT);
162 75 : double fRight = GetMarginsValue(MARGIN_RIGHT);
163 75 : double fTop = GetMarginsValue(MARGIN_TOP);
164 75 : double fBottom = GetMarginsValue(MARGIN_BOTTOM);
165 75 : pCellStyle->SetPadding((float)fLeft,(float)fRight,(float)fTop,(float)fBottom);
166 75 : }
167 : /**
168 : * @short Apply border to cell style according to cell position, default cell layout won't use this function
169 : * @param
170 : * @return pCellStyle - pointer of XFCellStyle
171 : */
172 3 : void LwpCellLayout::ApplyBorders(XFCellStyle *pCellStyle)
173 : {
174 : // judge cell border type
175 3 : LwpCellBorderType eType = GetCellBorderType(crowid, ccolid, GetTableLayout());
176 :
177 : // get left cell and judge if neighbour border is different
178 3 : XFBorders * pBorders = GetXFBorders();
179 3 : if(!pBorders)
180 : {
181 3 : return;
182 : }
183 :
184 3 : switch (eType)
185 : {
186 : case enumNoBottomBorder:
187 1 : pBorders->SetWidth(enumXFBorderBottom, 0);
188 1 : break;
189 : case enumNoLeftBorder:
190 1 : pBorders->SetWidth(enumXFBorderLeft, 0);
191 1 : break;
192 : case enumNoLeftNoBottomBorder:
193 1 : pBorders->SetWidth(enumXFBorderBottom, 0);
194 1 : pBorders->SetWidth(enumXFBorderLeft, 0);
195 1 : break;
196 : case enumWholeBorder:
197 0 : break;
198 : default:
199 : assert(sal_False);
200 : }
201 3 : pCellStyle->SetBorders(pBorders);
202 : }
203 : /**
204 : * @short Apply watermark to cell style
205 : * @param pCellStyle - pointer of XFCellStyle
206 : * @return
207 : */
208 75 : void LwpCellLayout::ApplyWatermark(XFCellStyle *pCellStyle)
209 : {
210 75 : XFBGImage* pBGImage = GetXFBGImage();
211 75 : if(pBGImage)
212 : {
213 0 : pCellStyle->SetBackImage(pBGImage);
214 : }
215 75 : }
216 :
217 : /**
218 : * @short Apply pattern fill to cell style
219 : * @param pCellStyle - pointer of XFCellStyle
220 : * @return
221 : */
222 0 : void LwpCellLayout::ApplyPatternFill(XFCellStyle* pCellStyle)
223 : {
224 0 : XFBGImage* pXFBGImage = this->GetFillPattern();
225 0 : if (pXFBGImage)
226 : {
227 0 : pCellStyle->SetBackImage(pXFBGImage);
228 : }
229 0 : }
230 :
231 : /**
232 : * @short Apply background to cell style
233 : * @param pCellStyle - pointer of XFCellStyle
234 : * @return
235 : */
236 3 : void LwpCellLayout::ApplyBackGround(XFCellStyle* pCellStyle)
237 : {
238 3 : if (this->IsPatternFill())
239 : {
240 0 : ApplyPatternFill(pCellStyle);
241 : }
242 : else
243 : {
244 3 : ApplyBackColor(pCellStyle);
245 : }
246 3 : }
247 : /**
248 : * @short Apply back color to cell style
249 : * @param pCellStyle - pointer of XFCellStyle
250 : * @return
251 : */
252 75 : void LwpCellLayout::ApplyBackColor(XFCellStyle *pCellStyle)
253 : {
254 75 : LwpColor* pColor = GetBackColor();
255 75 : if(pColor && pColor->IsValidColor())
256 : {
257 0 : XFColor aXFColor(pColor->To24Color());
258 0 : pCellStyle->SetBackColor(aXFColor);
259 : }
260 75 : }
261 : /**
262 : * @short register style of cell layout
263 : * @param pCellStyle The style of the cell, which would be applied to the cell.
264 : * @return
265 : */
266 75 : void LwpCellLayout::ApplyFmtStyle(XFCellStyle *pCellStyle)
267 : {
268 75 : LwpLayoutNumerics* pLayoutNumerics = dynamic_cast<LwpLayoutNumerics*>(cLayNumerics.obj());
269 75 : if (!pLayoutNumerics)
270 : {
271 : // if current layout doesn't have format, go to based on layout
272 51 : LwpCellLayout* pCellLayout = dynamic_cast<LwpCellLayout*>(m_BasedOnStyle.obj());
273 51 : if (pCellLayout)
274 : {
275 3 : pLayoutNumerics = dynamic_cast<LwpLayoutNumerics*>(pCellLayout->GetNumericsObject()->obj());
276 : }
277 : }
278 :
279 : // apply format style
280 75 : if (pLayoutNumerics)
281 : {
282 27 : XFStyle* pStyle = pLayoutNumerics->Convert();
283 27 : if (pStyle)
284 : {
285 27 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
286 27 : m_NumfmtName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
287 27 : pCellStyle->SetDataStyle(m_NumfmtName);
288 : }
289 : }
290 :
291 75 : return;
292 : }
293 : /**
294 : * @short get style name according to cell position, only table default cells use this function
295 : * @param nRow - default cell position row number
296 : * @param nCol - default cell position col number
297 : * @return OUString - registered cell style name
298 : */
299 17 : OUString LwpCellLayout::GetCellStyleName(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
300 : {
301 : // judge cell border type
302 17 : LwpCellBorderType eType = GetCellBorderType(nRow, nCol, pTableLayout);
303 17 : return m_CellStyleNames[eType];
304 : }
305 : /**
306 : * Make the XFCell
307 : * @date 03/26/2005
308 : * @param aTableID - ID of the table which this cell belongs to
309 : * @param bIsTopRow - whether current cell is top row
310 : * @param bIsRightCol - whether current cell is the rightest column
311 : * @return XFCell*
312 : */
313 20 : XFCell* LwpCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
314 : {
315 : // if cell layout is aTableID's default cell layout
316 : // it can't have any content, bypass these code
317 20 : LwpTable * pTable = dynamic_cast<LwpTable *>(aTableID.obj());
318 20 : if (!pTable)
319 : {
320 : assert(sal_False);
321 0 : return NULL;
322 : }
323 20 : XFCell * pXFCell = new XFCell();
324 20 : OUString aStyleName = m_StyleName;
325 :
326 : // if cell layout is aTableID's default cell layout
327 : // we should judt its style by current positon
328 20 : if (*pTable->GetDefaultCellStyle() == *GetObjectID())
329 : {
330 17 : aStyleName = GetCellStyleName(nRow, nCol, pTable->GetTableLayout());
331 : }
332 :
333 : // content of cell
334 20 : LwpStory* pStory = dynamic_cast<LwpStory*>(m_Content.obj());
335 20 : if (pStory)
336 : {
337 3 : pStory->XFConvert(pXFCell);
338 : }
339 :
340 20 : ApplyProtect(pXFCell, aTableID);
341 20 : pXFCell->SetStyleName(aStyleName);
342 20 : return pXFCell;
343 : }
344 :
345 1 : LwpPara* LwpCellLayout::GetLastParaOfPreviousStory()
346 : {
347 1 : LwpObjectID* pPreStoryID = this->GetPreviousCellStory();
348 1 : if (pPreStoryID && !(pPreStoryID->IsNull()))
349 : {
350 0 : LwpStory* pPreStory = dynamic_cast<LwpStory*>(pPreStoryID->obj(VO_STORY));
351 0 : return dynamic_cast<LwpPara*>(pPreStory->GetLastPara()->obj(VO_PARA));
352 : }
353 : else
354 : {
355 1 : return NULL;
356 : }
357 : }
358 :
359 : /**
360 : * @short Get previous cell which used for bullet inside cell
361 : * @param
362 : * @return LwpObjectID * - object ID of cell content story
363 : */
364 1 : LwpObjectID * LwpCellLayout::GetPreviousCellStory()
365 : {
366 1 : LwpTable *pTable = GetTable();
367 1 : if (!pTable)
368 : {
369 : assert(sal_False);
370 0 : return NULL;
371 : }
372 1 : sal_uInt16 nRow = crowid;
373 1 : sal_uInt16 nCol = ccolid;
374 :
375 : // if table is reset paragraph in columns, get cell on the top side of current cell
376 1 : if (pTable->IsNumberDown())
377 : {
378 0 : if (nRow == 0)
379 : {
380 0 : return NULL;
381 : }
382 0 : nRow -=1;
383 : }
384 : else
385 : {
386 : // if not, get cell on the left side of current cell
387 1 : if (nCol == 0)
388 : {
389 1 : if (nRow == 0)
390 : {
391 1 : return NULL;
392 : }
393 : else
394 : {
395 0 : nRow--;
396 0 : nCol = pTable->GetColumn() - 1;
397 : }
398 : }
399 : else
400 : {
401 0 : nCol -=1;
402 : }
403 : }
404 :
405 : // get the object id pointer of previous cell story
406 0 : LwpTableLayout * pTableLayout = GetTableLayout();
407 0 : if (!pTableLayout)
408 : {
409 : assert(sal_False);
410 0 : return NULL;
411 : }
412 0 : return pTableLayout->SearchCellStoryMap(nRow, nCol);
413 : }
414 :
415 : /**
416 : * @short judge border type by cell neighbour
417 : * @param nRow
418 : * @param nCol
419 : * @param pTableLayout
420 : * @return LwpCellBorderType
421 : */
422 20 : LwpCellBorderType LwpCellLayout::GetCellBorderType(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
423 : {
424 20 : if (!pTableLayout)
425 : {
426 : assert(sal_False);
427 0 : return enumWholeBorder;
428 : }
429 :
430 : // get left cell and judge if neighbour border is different
431 20 : XFBorders * pBorders = GetXFBorders();
432 20 : if(!pBorders)
433 : {
434 0 : return enumWholeBorder;
435 : }
436 20 : XFBorder *pLeftBorder = pBorders->GetLeft();
437 20 : XFBorder *pBottomBorder = pBorders->GetBottom();
438 20 : sal_Bool bNoLeftBorder = sal_False;
439 20 : sal_Bool bNoBottomBorder = sal_False;
440 :
441 20 : LwpCellLayout * pLeftNeighbour = GetCellByRowCol(nRow, GetLeftColID(nCol), pTableLayout);
442 20 : if (pLeftNeighbour)
443 : {
444 15 : XFBorders * pNeighbourBorders = pLeftNeighbour->GetXFBorders();
445 15 : if (pNeighbourBorders)
446 : {
447 15 : XFBorder * pRightBorder = pNeighbourBorders->GetRight();
448 15 : if (*pLeftBorder == *pRightBorder)
449 : {
450 : // for these 2 types cell, left border should be ignored for sake of avoiding duplication border
451 : // but if left border is different with right border of left cell
452 : // we should not ignored it
453 15 : bNoLeftBorder = sal_True;
454 : }
455 15 : delete pNeighbourBorders;
456 : }
457 :
458 : }
459 :
460 20 : LwpCellLayout * pBelowNeighbour = GetCellByRowCol(GetBelowRowID(nRow), nCol, pTableLayout);
461 20 : if (pBelowNeighbour) //&& (eType == enumRightNotLastCellBorder || eType == enumLeftNotLastCellBorder) )
462 : {
463 16 : XFBorders * pBelowBorders = pBelowNeighbour->GetXFBorders();
464 16 : if (pBelowBorders)
465 : {
466 16 : XFBorder * pTopBorder = pBelowBorders->GetTop();
467 16 : if (*pTopBorder == *pBottomBorder)
468 : {
469 : // for these 2 types cell, bottom border should be ignored for sake of avoiding duplication border
470 : // but if bottom border is different with right border of left cell
471 : // we should not ignored it
472 16 : bNoBottomBorder = sal_True;
473 : }
474 16 : delete pBelowBorders;
475 : }
476 : }
477 :
478 20 : delete pBorders;
479 :
480 20 : if (bNoBottomBorder)
481 : {
482 16 : if (bNoLeftBorder)
483 : {
484 12 : return enumNoLeftNoBottomBorder;
485 : }
486 4 : return enumNoBottomBorder;
487 : }
488 4 : if (bNoLeftBorder)
489 : {
490 3 : return enumNoLeftBorder;
491 : }
492 1 : return enumWholeBorder;
493 : }
494 :
495 : /**
496 : * @short Get neighbour cell by specifying ROW+COL
497 : * @param nRow
498 : * @param nCol
499 : * @return LwpCellLayout *
500 : */
501 40 : LwpCellLayout * LwpCellLayout::GetCellByRowCol(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
502 : {
503 40 : return pTableLayout->GetCellByRowCol(nRow, nCol);
504 : }
505 : /**
506 : * @short Register table's default cell layout
507 : * @param
508 : * @return
509 : */
510 18 : void LwpCellLayout::RegisterDefaultCell()
511 : {
512 18 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
513 90 : for (sal_uInt16 eLoop = enumWholeBorder; eLoop < enumCellBorderTopLimit; eLoop++)
514 : {
515 : // register cell style
516 72 : XFCellStyle *pCellStyle = new XFCellStyle();
517 :
518 72 : ApplyPadding(pCellStyle);
519 72 : ApplyBackColor(pCellStyle);
520 72 : ApplyWatermark(pCellStyle);
521 72 : ApplyFmtStyle(pCellStyle);
522 72 : pCellStyle->SetAlignType(enumXFAlignNone, GetVerticalAlignmentType());
523 :
524 72 : XFBorders * pBorders = GetXFBorders();
525 72 : if (pBorders)
526 : {
527 16 : switch(eLoop)
528 : {
529 : case enumNoBottomBorder:
530 : // _
531 : //| |
532 : //
533 : // remove bottom line
534 4 : pBorders->SetWidth(enumXFBorderBottom, 0);
535 4 : break;
536 : case enumNoLeftNoBottomBorder:
537 : // _
538 : // |
539 : //
540 : // remove left and bottom
541 4 : pBorders->SetWidth(enumXFBorderLeft, 0);
542 4 : pBorders->SetWidth(enumXFBorderBottom, 0);
543 4 : break;
544 : case enumWholeBorder:
545 : //--
546 : //||
547 : //--
548 : // nothing to remove
549 4 : break;
550 : case enumNoLeftBorder:
551 : //
552 : //| |
553 : //--
554 : // remove left line
555 4 : pBorders->SetWidth(enumXFBorderLeft, 0);
556 4 : break;
557 : default:
558 : assert(sal_False);
559 : }
560 16 : pCellStyle->SetBorders(pBorders);
561 : }
562 72 : m_CellStyleNames[eLoop] = pXFStyleManager->AddStyle(pCellStyle)->GetStyleName();
563 : }
564 18 : }
565 : /**
566 : * @short Register 4 types of cell style and register content styles
567 : * @param
568 : * @param
569 : * @param
570 : * @return
571 : */
572 21 : void LwpCellLayout::RegisterStyle()
573 : {
574 21 : LwpVirtualLayout * pParent = dynamic_cast<LwpVirtualLayout *>(GetParent()->obj());
575 21 : if (!pParent || pParent->GetLayoutType() != LWP_ROW_LAYOUT)
576 : {
577 : // default cell layout, we must register 4 styles for it
578 18 : RegisterDefaultCell();
579 39 : return;
580 : }
581 :
582 : // register cell style
583 3 : XFCellStyle *pCellStyle = new XFCellStyle();
584 :
585 3 : ApplyPadding(pCellStyle);
586 : // ApplyBackColor(pCellStyle);
587 3 : ApplyBackGround(pCellStyle);
588 3 : ApplyWatermark(pCellStyle);
589 3 : ApplyFmtStyle(pCellStyle);
590 3 : ApplyBorders(pCellStyle);
591 :
592 3 : pCellStyle->SetAlignType(enumXFAlignNone, GetVerticalAlignmentType());
593 :
594 3 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
595 3 : m_StyleName = pXFStyleManager->AddStyle(pCellStyle)->GetStyleName();
596 :
597 : // content object register styles
598 3 : LwpObject * pObj = m_Content.obj();
599 3 : if (pObj)
600 : {
601 3 : pObj->SetFoundry(m_pFoundry);
602 3 : pObj->RegisterStyle();
603 : }
604 :
605 : //register child layout style
606 3 : RegisterChildStyle();
607 : }
608 : /**
609 : * @short Read cell layout
610 : * @param
611 : * @return
612 : */
613 23 : void LwpCellLayout::Read()
614 : {
615 23 : LwpObjectStream* pStrm = m_pObjStrm;
616 :
617 23 : LwpMiddleLayout::Read();
618 :
619 : // before the layout hierarchy rework
620 23 : if (LwpFileHeader::m_nFileRevision < 0x000b)
621 : {
622 : assert(sal_False);
623 : }
624 : else
625 : {
626 23 : crowid = pStrm->QuickReaduInt16();
627 23 : ccolid = (sal_uInt8) pStrm->QuickReaduInt16(); // written as a lushort
628 :
629 : sal_uInt16 type;
630 :
631 23 : type = pStrm->QuickReaduInt16();
632 23 : pStrm->SkipExtra();
633 23 : cType = (LeaderDotType)type;
634 :
635 23 : cLayNumerics.ReadIndexed(pStrm);
636 23 : cLayDiagonalLine.ReadIndexed(pStrm);
637 :
638 23 : pStrm->SkipExtra();
639 : }
640 23 : }
641 :
642 : /**
643 : * Apply protect attribute to cell of table
644 : * @date 04/04/2005
645 : * @param aTableID - ID of the table which the cell belongs to
646 : * @param
647 : * @return XFCell*
648 : */
649 20 : void LwpCellLayout::ApplyProtect(XFCell * pCell, LwpObjectID aTableID)
650 : {
651 20 : sal_Bool bProtected = sal_False;
652 : // judge current cell
653 20 : if (IsProtected())
654 : {
655 0 : bProtected = sal_True;
656 : }
657 : else
658 : {
659 : // judge base on
660 20 : LwpCellLayout * pBase = dynamic_cast<LwpCellLayout *>(m_BasedOnStyle.obj());
661 20 : if (pBase && pBase->IsProtected())
662 : {
663 0 : bProtected = sal_True;
664 : }
665 : else
666 : {
667 : // judge whole table
668 20 : LwpTable * pTable = dynamic_cast<LwpTable *>(aTableID.obj());
669 20 : LwpTableLayout * pTableLayout = static_cast<LwpTableLayout *>(pTable->GetTableLayout());
670 20 : LwpSuperTableLayout * pSuper = pTableLayout->GetSuperTableLayout();
671 20 : if (pSuper && pSuper->IsProtected())
672 : {
673 0 : bProtected = sal_True;
674 : }
675 : }
676 : }
677 :
678 20 : pCell->SetProtect(bProtected);
679 20 : }
680 :
681 :
682 0 : LwpConnectedCellLayout::LwpConnectedCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
683 0 : : LwpCellLayout(objHdr, pStrm)
684 0 : {}
685 :
686 0 : LwpConnectedCellLayout::~LwpConnectedCellLayout()
687 0 : {}
688 : /**
689 : * @short Set current connected cell layout to cell layout map
690 : * @param pCellLayoutMap - cell layout map reference
691 : * @return
692 : */
693 0 : void LwpConnectedCellLayout::SetCellMap()
694 : {
695 : // this function is called from LwpTableLayout, so it can't be NULL
696 0 : LwpTableLayout * pTableLayout = GetTableLayout();
697 0 : sal_uInt16 nRowSpan = m_nRealrowspan;
698 :
699 0 : for (sal_uInt16 iLoop = 0; iLoop < nRowSpan; iLoop ++)
700 : {
701 0 : for (sal_uInt16 jLoop = 0; jLoop < cnumcols; jLoop ++)
702 0 : pTableLayout->SetWordProCellMap(iLoop + crowid, jLoop + ccolid, this);
703 : }
704 0 : }
705 :
706 : /**
707 : * @short judge border type by cell neighbour
708 : * @param nRow
709 : * @param nCol
710 : * @param pTableLayout
711 : * @return LwpCellBorderType
712 : */
713 0 : LwpCellBorderType LwpConnectedCellLayout::GetCellBorderType(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
714 : {
715 0 : if (!pTableLayout)
716 : {
717 : assert(sal_False);
718 0 : return enumWholeBorder;
719 : }
720 :
721 0 : sal_uInt16 nRowSpan = m_nRealrowspan;
722 :
723 : // get left cell and judge if neighbour border is different
724 0 : XFBorders * pBorders = GetXFBorders();
725 0 : if(!pBorders)
726 : {
727 0 : return enumWholeBorder;
728 : }
729 0 : XFBorder *pLeftBorder = pBorders->GetLeft();
730 0 : XFBorder *pBottomBorder = pBorders->GetBottom();
731 0 : sal_Bool bNoLeftBorder = sal_True;
732 0 : sal_Bool bNoBottomBorder = sal_True;
733 :
734 0 : if (nCol == 0)
735 : {
736 0 : bNoLeftBorder = sal_False;
737 : }
738 : else
739 : {
740 0 : for (sal_uInt16 iLoop=0; iLoop < nRowSpan; iLoop++)
741 : {
742 0 : LwpCellLayout * pLeftNeighbour = GetCellByRowCol(nRow+iLoop, GetLeftColID(nCol), pTableLayout);
743 0 : if (pLeftNeighbour)
744 : {
745 0 : XFBorders * pNeighbourBorders = pLeftNeighbour->GetXFBorders();
746 0 : if (pNeighbourBorders)
747 : {
748 0 : XFBorder * pRightBorder = pNeighbourBorders->GetRight();
749 0 : if (*pLeftBorder != *pRightBorder)
750 : {
751 : // if left border is different with right border of left cell
752 : // we should not ignored it
753 0 : bNoLeftBorder = sal_False;
754 0 : break;
755 : }
756 0 : delete pNeighbourBorders;
757 : }
758 : }
759 : }
760 : }
761 :
762 0 : if ( (nRow + nRowSpan) == pTableLayout->GetTable()->GetRow() )
763 : {
764 0 : bNoBottomBorder = sal_False;
765 : }
766 : else
767 : {
768 0 : for (sal_uInt16 iLoop = 0; iLoop < cnumcols; iLoop ++)
769 : {
770 0 : LwpCellLayout * pBelowNeighbour = GetCellByRowCol(nRow + nRowSpan, nCol+iLoop, pTableLayout);
771 0 : if (pBelowNeighbour)
772 : {
773 0 : XFBorders * pBelowBorders = pBelowNeighbour->GetXFBorders();
774 0 : if (pBelowBorders)
775 : {
776 0 : XFBorder * pTopBorder = pBelowBorders->GetTop();
777 0 : if (*pTopBorder != *pBottomBorder)
778 : {
779 : // if bottom border is different with right border of left cell
780 : // we should not ignored it
781 0 : bNoBottomBorder = sal_False;
782 0 : break;
783 : }
784 0 : delete pBelowBorders;
785 : }
786 : }
787 : }
788 : }
789 0 : delete pBorders;
790 :
791 0 : if (bNoBottomBorder)
792 : {
793 0 : if (bNoLeftBorder)
794 : {
795 0 : return enumNoLeftNoBottomBorder;
796 : }
797 0 : return enumNoBottomBorder;
798 : }
799 0 : if (bNoLeftBorder)
800 : {
801 0 : return enumNoLeftBorder;
802 : }
803 0 : return enumWholeBorder;
804 : }
805 : /**
806 : * @short Read connected cell layout
807 : * @param
808 : * @return
809 : */
810 0 : void LwpConnectedCellLayout::Read()
811 : {
812 0 : LwpCellLayout::Read();
813 : sal_uInt16 numcols;
814 :
815 0 : cnumrows = m_pObjStrm->QuickReaduInt16();
816 0 : numcols = m_pObjStrm->QuickReaduInt16(); // written as a lushort
817 0 : cnumcols = (sal_uInt8)numcols;
818 :
819 0 : m_nRealrowspan = cnumrows;
820 0 : m_nRealcolspan = cnumcols;
821 :
822 0 : m_pObjStrm->SkipExtra();
823 0 : }
824 0 : XFCell* LwpConnectedCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
825 : {
826 0 : XFCell * pXFCell = LwpCellLayout::ConvertCell(aTableID, nRow, nCol);
827 0 : pXFCell->SetColumnSpaned(cnumcols);
828 : // if(!m_bSplitFlag)
829 : // {
830 : // }
831 0 : return pXFCell;
832 : }
833 : /**
834 : * @short parse connected cell layout
835 : * @param pOutputStream - output stream
836 : * @return
837 : */
838 0 : void LwpConnectedCellLayout::Parse(IXFStream* /*pOutputStream*/)
839 : {
840 0 : }
841 :
842 0 : LwpHiddenCellLayout::LwpHiddenCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
843 0 : : LwpCellLayout(objHdr, pStrm)
844 0 : {}
845 :
846 0 : LwpHiddenCellLayout::~LwpHiddenCellLayout()
847 0 : {}
848 : /**
849 : * @short Set current hidden cell layout to cell layout map
850 : * @param
851 : * @return
852 : */
853 0 : void LwpHiddenCellLayout::SetCellMap()
854 : {
855 0 : return;
856 : }
857 : /**
858 : * @short Read hidden cell layout
859 : * @param
860 : * @return
861 : */
862 0 : void LwpHiddenCellLayout::Read()
863 : {
864 0 : LwpCellLayout::Read();
865 :
866 0 : cconnectedlayout.ReadIndexed(m_pObjStrm);
867 0 : m_pObjStrm->SkipExtra();
868 :
869 0 : }
870 : /**
871 : * @short Convert hidden cell layout
872 : * @param aTableID - Object ID of table
873 : * @return XFCell * - pointer to converted cell
874 : */
875 :
876 0 : XFCell* LwpHiddenCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
877 : {
878 0 : if (!cconnectedlayout.obj())
879 0 : return NULL;
880 0 : LwpConnectedCellLayout* pConnCell = dynamic_cast<LwpConnectedCellLayout* >(cconnectedlayout.obj());
881 :
882 0 : if (nRow < (pConnCell->GetNumrows()+pConnCell->GetRowID()))
883 0 : return NULL;
884 : // if the hidden cell should be displayed for limit of SODC
885 : // use the default cell layout
886 0 : XFCell* pXFCell = NULL;
887 0 : LwpTable *pTable = dynamic_cast<LwpTable *>(aTableID.obj());
888 0 : if (pTable)
889 : {
890 0 : LwpCellLayout *pDefault = dynamic_cast<LwpCellLayout *>(pTable->GetDefaultCellStyle()->obj());
891 0 : if (pDefault)
892 : {
893 0 : pXFCell = pDefault->ConvertCell(aTableID, nRow, nCol);
894 : }
895 : else
896 : {
897 0 : pXFCell = pConnCell->ConvertCell(aTableID, nRow, nCol);
898 : }
899 0 : pXFCell->SetColumnSpaned(pConnCell->GetNumcols());
900 : }
901 : else
902 : {
903 : assert(sal_False);
904 : }
905 0 : return pXFCell;
906 : }
907 : /**
908 : * @short parse hidden cell layout
909 : * @param pOutputStream - output stream
910 : * @return
911 : */
912 0 : void LwpHiddenCellLayout::Parse(IXFStream* /*pOutputStream*/)
913 : {
914 0 : }
915 :
916 :
917 0 : LwpParallelColumnsBlock::LwpParallelColumnsBlock(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpCellLayout(objHdr, pStrm)
918 0 : {}
919 :
920 0 : LwpParallelColumnsBlock::~LwpParallelColumnsBlock()
921 0 : {}
922 :
923 0 : void LwpParallelColumnsBlock::Read()
924 : {
925 0 : LwpCellLayout::Read();
926 0 : m_pObjStrm->SkipExtra();
927 0 : }
928 :
929 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|