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 : #include "lwpcelllayout.hxx"
62 : #include "lwpfoundry.hxx"
63 : #include "lwpobjfactory.hxx"
64 : #include "lwptblcell.hxx"
65 : #include "lwptblformula.hxx"
66 : #include "lwpholder.hxx"
67 : #include "lwpnumericfmt.hxx"
68 : #include "lwptable.hxx"
69 : #include "lwpglobalmgr.hxx"
70 :
71 : #include "xfilter/xfstylemanager.hxx"
72 : #include "xfilter/xfcell.hxx"
73 : #include "xfilter/xfcellstyle.hxx"
74 : #include "xfilter/xfcolstyle.hxx"
75 :
76 0 : LwpCellLayout::LwpCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
77 : : LwpMiddleLayout(objHdr, pStrm)
78 : , crowid(0)
79 : , ccolid(0)
80 0 : , cType(LDT_NONE)
81 : {
82 0 : }
83 :
84 0 : LwpCellLayout::~LwpCellLayout()
85 0 : {}
86 :
87 : /**
88 : * @short Get table layout pointer, if default cell layout, return NULL
89 : * @param LwpTableLayout *
90 : * @return
91 : */
92 0 : LwpTableLayout * LwpCellLayout::GetTableLayout()
93 : {
94 0 : LwpRowLayout * pRow = dynamic_cast<LwpRowLayout *>(GetParent()->obj());
95 0 : if(!pRow)
96 : {
97 0 : return NULL;
98 : }
99 0 : LwpTableLayout * pTableLayout = pRow->GetParentTableLayout();
100 0 : return pTableLayout;
101 : }
102 : /**
103 : * @short Get table pointer, if default cell layout, return NULL
104 : * @param LwpTable *
105 : * @return
106 : */
107 0 : LwpTable * LwpCellLayout::GetTable()
108 : {
109 0 : LwpTableLayout * pTableLayout = GetTableLayout();
110 0 : if(!pTableLayout)
111 : {
112 0 : return NULL;
113 : }
114 0 : LwpTable *pTable = pTableLayout->GetTable();
115 0 : return pTable;
116 : }
117 : /**
118 : * @short Set current cell layout to cell layout map
119 : * @param
120 : * @return
121 : */
122 0 : void LwpCellLayout::SetCellMap()
123 : {
124 : // this function is called from LwpTableLayout, so it can't be NULL
125 0 : GetTableLayout()->SetWordProCellMap(crowid, ccolid, this);
126 0 : }
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 0 : void LwpCellLayout::ApplyPadding(XFCellStyle *pCellStyle)
160 : {
161 0 : double fLeft = GetMarginsValue(MARGIN_LEFT);
162 0 : double fRight = GetMarginsValue(MARGIN_RIGHT);
163 0 : double fTop = GetMarginsValue(MARGIN_TOP);
164 0 : double fBottom = GetMarginsValue(MARGIN_BOTTOM);
165 0 : pCellStyle->SetPadding((float)fLeft,(float)fRight,(float)fTop,(float)fBottom);
166 0 : }
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 0 : void LwpCellLayout::ApplyBorders(XFCellStyle *pCellStyle)
173 : {
174 : // judge cell border type
175 0 : LwpCellBorderType eType = GetCellBorderType(crowid, ccolid, GetTableLayout());
176 :
177 : // get left cell and judge if neighbour border is different
178 0 : XFBorders * pBorders = GetXFBorders();
179 0 : if(!pBorders)
180 : {
181 0 : return;
182 : }
183 :
184 0 : switch (eType)
185 : {
186 : case enumNoBottomBorder:
187 0 : pBorders->SetWidth(enumXFBorderBottom, 0);
188 0 : break;
189 : case enumNoLeftBorder:
190 0 : pBorders->SetWidth(enumXFBorderLeft, 0);
191 0 : break;
192 : case enumNoLeftNoBottomBorder:
193 0 : pBorders->SetWidth(enumXFBorderBottom, 0);
194 0 : pBorders->SetWidth(enumXFBorderLeft, 0);
195 0 : break;
196 : case enumWholeBorder:
197 0 : break;
198 : default:
199 : assert(false);
200 : }
201 0 : pCellStyle->SetBorders(pBorders);
202 : }
203 : /**
204 : * @short Apply watermark to cell style
205 : * @param pCellStyle - pointer of XFCellStyle
206 : * @return
207 : */
208 0 : void LwpCellLayout::ApplyWatermark(XFCellStyle *pCellStyle)
209 : {
210 0 : XFBGImage* pBGImage = GetXFBGImage();
211 0 : if(pBGImage)
212 : {
213 0 : pCellStyle->SetBackImage(pBGImage);
214 : }
215 0 : }
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 0 : void LwpCellLayout::ApplyBackGround(XFCellStyle* pCellStyle)
237 : {
238 0 : if (this->IsPatternFill())
239 : {
240 0 : ApplyPatternFill(pCellStyle);
241 : }
242 : else
243 : {
244 0 : ApplyBackColor(pCellStyle);
245 : }
246 0 : }
247 : /**
248 : * @short Apply back color to cell style
249 : * @param pCellStyle - pointer of XFCellStyle
250 : * @return
251 : */
252 0 : void LwpCellLayout::ApplyBackColor(XFCellStyle *pCellStyle)
253 : {
254 0 : LwpColor* pColor = GetBackColor();
255 0 : if(pColor && pColor->IsValidColor())
256 : {
257 0 : XFColor aXFColor(pColor->To24Color());
258 0 : pCellStyle->SetBackColor(aXFColor);
259 : }
260 0 : }
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 0 : void LwpCellLayout::ApplyFmtStyle(XFCellStyle *pCellStyle)
267 : {
268 0 : LwpLayoutNumerics* pLayoutNumerics = dynamic_cast<LwpLayoutNumerics*>(cLayNumerics.obj());
269 0 : if (!pLayoutNumerics)
270 : {
271 : // if current layout doesn't have format, go to based on layout
272 0 : LwpCellLayout* pCellLayout = dynamic_cast<LwpCellLayout*>(m_BasedOnStyle.obj());
273 0 : if (pCellLayout)
274 : {
275 0 : pLayoutNumerics = dynamic_cast<LwpLayoutNumerics*>(pCellLayout->GetNumericsObject()->obj());
276 : }
277 : }
278 :
279 : // apply format style
280 0 : if (pLayoutNumerics)
281 : {
282 0 : XFStyle* pStyle = pLayoutNumerics->Convert();
283 0 : if (pStyle)
284 : {
285 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
286 0 : m_NumfmtName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
287 0 : pCellStyle->SetDataStyle(m_NumfmtName);
288 : }
289 : }
290 :
291 0 : 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 0 : OUString LwpCellLayout::GetCellStyleName(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
300 : {
301 : // judge cell border type
302 0 : LwpCellBorderType eType = GetCellBorderType(nRow, nCol, pTableLayout);
303 0 : 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 0 : 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 0 : LwpTable * pTable = dynamic_cast<LwpTable *>(aTableID.obj());
318 0 : if (!pTable)
319 : {
320 : assert(false);
321 0 : return NULL;
322 : }
323 0 : XFCell * pXFCell = new XFCell();
324 0 : 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 0 : if (*pTable->GetDefaultCellStyle() == *GetObjectID())
329 : {
330 0 : aStyleName = GetCellStyleName(nRow, nCol, pTable->GetTableLayout());
331 : }
332 :
333 : // content of cell
334 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(m_Content.obj());
335 0 : if (pStory)
336 : {
337 0 : pStory->XFConvert(pXFCell);
338 : }
339 :
340 0 : ApplyProtect(pXFCell, aTableID);
341 0 : pXFCell->SetStyleName(aStyleName);
342 0 : return pXFCell;
343 : }
344 :
345 0 : LwpPara* LwpCellLayout::GetLastParaOfPreviousStory()
346 : {
347 0 : LwpObjectID* pPreStoryID = this->GetPreviousCellStory();
348 0 : 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 0 : 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 0 : LwpObjectID * LwpCellLayout::GetPreviousCellStory()
365 : {
366 0 : LwpTable *pTable = GetTable();
367 0 : if (!pTable)
368 : {
369 : assert(false);
370 0 : return NULL;
371 : }
372 0 : sal_uInt16 nRow = crowid;
373 0 : sal_uInt16 nCol = ccolid;
374 :
375 : // if table is reset paragraph in columns, get cell on the top side of current cell
376 0 : 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 0 : if (nCol == 0)
388 : {
389 0 : if (nRow == 0)
390 : {
391 0 : 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(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 0 : LwpCellBorderType LwpCellLayout::GetCellBorderType(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
423 : {
424 0 : if (!pTableLayout)
425 : {
426 : assert(false);
427 0 : return enumWholeBorder;
428 : }
429 :
430 : // get left cell and judge if neighbour border is different
431 0 : XFBorders * pBorders = GetXFBorders();
432 0 : if(!pBorders)
433 : {
434 0 : return enumWholeBorder;
435 : }
436 0 : XFBorder *pLeftBorder = pBorders->GetLeft();
437 0 : XFBorder *pBottomBorder = pBorders->GetBottom();
438 0 : sal_Bool bNoLeftBorder = sal_False;
439 0 : sal_Bool bNoBottomBorder = sal_False;
440 :
441 0 : LwpCellLayout * pLeftNeighbour = GetCellByRowCol(nRow, GetLeftColID(nCol), pTableLayout);
442 0 : if (pLeftNeighbour)
443 : {
444 0 : XFBorders * pNeighbourBorders = pLeftNeighbour->GetXFBorders();
445 0 : if (pNeighbourBorders)
446 : {
447 0 : XFBorder * pRightBorder = pNeighbourBorders->GetRight();
448 0 : 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 0 : bNoLeftBorder = sal_True;
454 : }
455 0 : delete pNeighbourBorders;
456 : }
457 :
458 : }
459 :
460 0 : LwpCellLayout * pBelowNeighbour = GetCellByRowCol(GetBelowRowID(nRow), nCol, pTableLayout);
461 0 : if (pBelowNeighbour) //&& (eType == enumRightNotLastCellBorder || eType == enumLeftNotLastCellBorder) )
462 : {
463 0 : XFBorders * pBelowBorders = pBelowNeighbour->GetXFBorders();
464 0 : if (pBelowBorders)
465 : {
466 0 : XFBorder * pTopBorder = pBelowBorders->GetTop();
467 0 : 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 0 : bNoBottomBorder = sal_True;
473 : }
474 0 : delete pBelowBorders;
475 : }
476 : }
477 :
478 0 : delete pBorders;
479 :
480 0 : if (bNoBottomBorder)
481 : {
482 0 : if (bNoLeftBorder)
483 : {
484 0 : return enumNoLeftNoBottomBorder;
485 : }
486 0 : return enumNoBottomBorder;
487 : }
488 0 : if (bNoLeftBorder)
489 : {
490 0 : return enumNoLeftBorder;
491 : }
492 0 : 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 0 : LwpCellLayout * LwpCellLayout::GetCellByRowCol(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
502 : {
503 0 : return pTableLayout->GetCellByRowCol(nRow, nCol);
504 : }
505 : /**
506 : * @short Register table's default cell layout
507 : * @param
508 : * @return
509 : */
510 0 : void LwpCellLayout::RegisterDefaultCell()
511 : {
512 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
513 0 : for (sal_uInt16 eLoop = enumWholeBorder; eLoop < enumCellBorderTopLimit; eLoop++)
514 : {
515 : // register cell style
516 0 : XFCellStyle *pCellStyle = new XFCellStyle();
517 :
518 0 : ApplyPadding(pCellStyle);
519 0 : ApplyBackColor(pCellStyle);
520 0 : ApplyWatermark(pCellStyle);
521 0 : ApplyFmtStyle(pCellStyle);
522 0 : pCellStyle->SetAlignType(enumXFAlignNone, GetVerticalAlignmentType());
523 :
524 0 : XFBorders * pBorders = GetXFBorders();
525 0 : if (pBorders)
526 : {
527 0 : switch(eLoop)
528 : {
529 : case enumNoBottomBorder:
530 :
531 : //| |
532 :
533 : // remove bottom line
534 0 : pBorders->SetWidth(enumXFBorderBottom, 0);
535 0 : break;
536 : case enumNoLeftNoBottomBorder:
537 :
538 : // |
539 :
540 : // remove left and bottom
541 0 : pBorders->SetWidth(enumXFBorderLeft, 0);
542 0 : pBorders->SetWidth(enumXFBorderBottom, 0);
543 0 : break;
544 : case enumWholeBorder:
545 :
546 : //||
547 :
548 : // nothing to remove
549 0 : break;
550 : case enumNoLeftBorder:
551 :
552 : //| |
553 :
554 : // remove left line
555 0 : pBorders->SetWidth(enumXFBorderLeft, 0);
556 0 : break;
557 : default:
558 : assert(false);
559 : }
560 0 : pCellStyle->SetBorders(pBorders);
561 : }
562 0 : m_CellStyleNames[eLoop] = pXFStyleManager->AddStyle(pCellStyle)->GetStyleName();
563 : }
564 0 : }
565 : /**
566 : * @short Register 4 types of cell style and register content styles
567 : * @param
568 : * @param
569 : * @param
570 : * @return
571 : */
572 0 : void LwpCellLayout::RegisterStyle()
573 : {
574 0 : LwpVirtualLayout * pParent = dynamic_cast<LwpVirtualLayout *>(GetParent()->obj());
575 0 : if (!pParent || pParent->GetLayoutType() != LWP_ROW_LAYOUT)
576 : {
577 : // default cell layout, we must register 4 styles for it
578 0 : RegisterDefaultCell();
579 0 : return;
580 : }
581 :
582 : // register cell style
583 0 : XFCellStyle *pCellStyle = new XFCellStyle();
584 :
585 0 : ApplyPadding(pCellStyle);
586 : // ApplyBackColor(pCellStyle);
587 0 : ApplyBackGround(pCellStyle);
588 0 : ApplyWatermark(pCellStyle);
589 0 : ApplyFmtStyle(pCellStyle);
590 0 : ApplyBorders(pCellStyle);
591 :
592 0 : pCellStyle->SetAlignType(enumXFAlignNone, GetVerticalAlignmentType());
593 :
594 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
595 0 : m_StyleName = pXFStyleManager->AddStyle(pCellStyle)->GetStyleName();
596 :
597 : // content object register styles
598 0 : LwpObject * pObj = m_Content.obj();
599 0 : if (pObj)
600 : {
601 0 : pObj->SetFoundry(m_pFoundry);
602 0 : pObj->RegisterStyle();
603 : }
604 :
605 : //register child layout style
606 0 : RegisterChildStyle();
607 : }
608 : /**
609 : * @short Read cell layout
610 : * @param
611 : * @return
612 : */
613 0 : void LwpCellLayout::Read()
614 : {
615 0 : LwpObjectStream* pStrm = m_pObjStrm;
616 :
617 0 : LwpMiddleLayout::Read();
618 :
619 : // before the layout hierarchy rework
620 0 : if (LwpFileHeader::m_nFileRevision < 0x000b)
621 : {
622 : assert(false);
623 : }
624 : else
625 : {
626 0 : crowid = pStrm->QuickReaduInt16();
627 0 : ccolid = (sal_uInt8) pStrm->QuickReaduInt16(); // written as a lushort
628 :
629 : sal_uInt16 type;
630 :
631 0 : type = pStrm->QuickReaduInt16();
632 0 : pStrm->SkipExtra();
633 0 : cType = (LeaderDotType)type;
634 :
635 0 : cLayNumerics.ReadIndexed(pStrm);
636 0 : cLayDiagonalLine.ReadIndexed(pStrm);
637 :
638 0 : pStrm->SkipExtra();
639 : }
640 0 : }
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 0 : void LwpCellLayout::ApplyProtect(XFCell * pCell, LwpObjectID aTableID)
650 : {
651 0 : sal_Bool bProtected = sal_False;
652 : // judge current cell
653 0 : if (IsProtected())
654 : {
655 0 : bProtected = sal_True;
656 : }
657 : else
658 : {
659 : // judge base on
660 0 : LwpCellLayout * pBase = dynamic_cast<LwpCellLayout *>(m_BasedOnStyle.obj());
661 0 : if (pBase && pBase->IsProtected())
662 : {
663 0 : bProtected = sal_True;
664 : }
665 : else
666 : {
667 : // judge whole table
668 0 : LwpTable * pTable = dynamic_cast<LwpTable *>(aTableID.obj());
669 0 : LwpTableLayout * pTableLayout = pTable ? static_cast<LwpTableLayout *>(pTable->GetTableLayout()) : NULL;
670 0 : LwpSuperTableLayout * pSuper = pTableLayout ? pTableLayout->GetSuperTableLayout() : NULL;
671 0 : if (pSuper && pSuper->IsProtected())
672 : {
673 0 : bProtected = sal_True;
674 : }
675 : }
676 : }
677 :
678 0 : pCell->SetProtect(bProtected);
679 0 : }
680 :
681 0 : LwpConnectedCellLayout::LwpConnectedCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
682 : : LwpCellLayout(objHdr, pStrm)
683 : , cnumrows(0)
684 : , cnumcols(0)
685 : , m_nRealrowspan(0)
686 0 : , m_nRealcolspan(0)
687 : {
688 0 : }
689 :
690 0 : LwpConnectedCellLayout::~LwpConnectedCellLayout()
691 0 : {}
692 : /**
693 : * @short Set current connected cell layout to cell layout map
694 : * @param pCellLayoutMap - cell layout map reference
695 : * @return
696 : */
697 0 : void LwpConnectedCellLayout::SetCellMap()
698 : {
699 : // this function is called from LwpTableLayout, so it can't be NULL
700 0 : LwpTableLayout * pTableLayout = GetTableLayout();
701 0 : sal_uInt16 nRowSpan = m_nRealrowspan;
702 :
703 0 : for (sal_uInt16 iLoop = 0; iLoop < nRowSpan; iLoop ++)
704 : {
705 0 : for (sal_uInt16 jLoop = 0; jLoop < cnumcols; jLoop ++)
706 0 : pTableLayout->SetWordProCellMap(iLoop + crowid, jLoop + ccolid, this);
707 : }
708 0 : }
709 :
710 : /**
711 : * @short judge border type by cell neighbour
712 : * @param nRow
713 : * @param nCol
714 : * @param pTableLayout
715 : * @return LwpCellBorderType
716 : */
717 0 : LwpCellBorderType LwpConnectedCellLayout::GetCellBorderType(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
718 : {
719 0 : if (!pTableLayout)
720 : {
721 : assert(false);
722 0 : return enumWholeBorder;
723 : }
724 :
725 0 : sal_uInt16 nRowSpan = m_nRealrowspan;
726 :
727 : // get left cell and judge if neighbour border is different
728 0 : XFBorders * pBorders = GetXFBorders();
729 0 : if(!pBorders)
730 : {
731 0 : return enumWholeBorder;
732 : }
733 0 : XFBorder *pLeftBorder = pBorders->GetLeft();
734 0 : XFBorder *pBottomBorder = pBorders->GetBottom();
735 0 : sal_Bool bNoLeftBorder = sal_True;
736 0 : sal_Bool bNoBottomBorder = sal_True;
737 :
738 0 : if (nCol == 0)
739 : {
740 0 : bNoLeftBorder = sal_False;
741 : }
742 : else
743 : {
744 0 : for (sal_uInt16 iLoop=0; iLoop < nRowSpan; iLoop++)
745 : {
746 0 : LwpCellLayout * pLeftNeighbour = GetCellByRowCol(nRow+iLoop, GetLeftColID(nCol), pTableLayout);
747 0 : if (pLeftNeighbour)
748 : {
749 0 : boost::scoped_ptr<XFBorders> pNeighbourBorders(pLeftNeighbour->GetXFBorders());
750 0 : if (pNeighbourBorders)
751 : {
752 0 : XFBorder * pRightBorder = pNeighbourBorders->GetRight();
753 0 : if (*pLeftBorder != *pRightBorder)
754 : {
755 : // if left border is different with right border of left cell
756 : // we should not ignored it
757 0 : bNoLeftBorder = sal_False;
758 0 : break;
759 : }
760 0 : }
761 : }
762 : }
763 : }
764 :
765 0 : if ( (nRow + nRowSpan) == pTableLayout->GetTable()->GetRow() )
766 : {
767 0 : bNoBottomBorder = sal_False;
768 : }
769 : else
770 : {
771 0 : for (sal_uInt16 iLoop = 0; iLoop < cnumcols; iLoop ++)
772 : {
773 0 : LwpCellLayout * pBelowNeighbour = GetCellByRowCol(nRow + nRowSpan, nCol+iLoop, pTableLayout);
774 0 : if (pBelowNeighbour)
775 : {
776 0 : boost::scoped_ptr<XFBorders> pBelowBorders(pBelowNeighbour->GetXFBorders());
777 0 : if (pBelowBorders)
778 : {
779 0 : XFBorder * pTopBorder = pBelowBorders->GetTop();
780 0 : if (*pTopBorder != *pBottomBorder)
781 : {
782 : // if bottom border is different with right border of left cell
783 : // we should not ignored it
784 0 : bNoBottomBorder = sal_False;
785 0 : break;
786 : }
787 0 : }
788 : }
789 : }
790 : }
791 0 : delete pBorders;
792 :
793 0 : if (bNoBottomBorder)
794 : {
795 0 : if (bNoLeftBorder)
796 : {
797 0 : return enumNoLeftNoBottomBorder;
798 : }
799 0 : return enumNoBottomBorder;
800 : }
801 0 : if (bNoLeftBorder)
802 : {
803 0 : return enumNoLeftBorder;
804 : }
805 0 : return enumWholeBorder;
806 : }
807 : /**
808 : * @short Read connected cell layout
809 : * @param
810 : * @return
811 : */
812 0 : void LwpConnectedCellLayout::Read()
813 : {
814 0 : LwpCellLayout::Read();
815 : sal_uInt16 numcols;
816 :
817 0 : cnumrows = m_pObjStrm->QuickReaduInt16();
818 0 : numcols = m_pObjStrm->QuickReaduInt16(); // written as a lushort
819 0 : cnumcols = (sal_uInt8)numcols;
820 :
821 0 : m_nRealrowspan = cnumrows;
822 0 : m_nRealcolspan = cnumcols;
823 :
824 0 : m_pObjStrm->SkipExtra();
825 0 : }
826 0 : XFCell* LwpConnectedCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
827 : {
828 0 : XFCell * pXFCell = LwpCellLayout::ConvertCell(aTableID, nRow, nCol);
829 0 : pXFCell->SetColumnSpaned(cnumcols);
830 : // if(!m_bSplitFlag)
831 : // {
832 : // }
833 0 : return pXFCell;
834 : }
835 : /**
836 : * @short parse connected cell layout
837 : * @param pOutputStream - output stream
838 : * @return
839 : */
840 0 : void LwpConnectedCellLayout::Parse(IXFStream* /*pOutputStream*/)
841 : {
842 0 : }
843 :
844 0 : LwpHiddenCellLayout::LwpHiddenCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
845 0 : : LwpCellLayout(objHdr, pStrm)
846 0 : {}
847 :
848 0 : LwpHiddenCellLayout::~LwpHiddenCellLayout()
849 0 : {}
850 : /**
851 : * @short Set current hidden cell layout to cell layout map
852 : * @param
853 : * @return
854 : */
855 0 : void LwpHiddenCellLayout::SetCellMap()
856 : {
857 0 : return;
858 : }
859 : /**
860 : * @short Read hidden cell layout
861 : * @param
862 : * @return
863 : */
864 0 : void LwpHiddenCellLayout::Read()
865 : {
866 0 : LwpCellLayout::Read();
867 :
868 0 : cconnectedlayout.ReadIndexed(m_pObjStrm);
869 0 : m_pObjStrm->SkipExtra();
870 :
871 0 : }
872 : /**
873 : * @short Convert hidden cell layout
874 : * @param aTableID - Object ID of table
875 : * @return XFCell * - pointer to converted cell
876 : */
877 :
878 0 : XFCell* LwpHiddenCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
879 : {
880 0 : if (!cconnectedlayout.obj())
881 0 : return NULL;
882 0 : LwpConnectedCellLayout* pConnCell = dynamic_cast<LwpConnectedCellLayout* >(cconnectedlayout.obj());
883 :
884 0 : if (!pConnCell || nRow < (pConnCell->GetNumrows()+pConnCell->GetRowID()))
885 0 : return NULL;
886 : // if the hidden cell should be displayed for limit of SODC
887 : // use the default cell layout
888 0 : XFCell* pXFCell = NULL;
889 0 : LwpTable *pTable = dynamic_cast<LwpTable *>(aTableID.obj());
890 0 : if (pTable)
891 : {
892 0 : LwpCellLayout *pDefault = dynamic_cast<LwpCellLayout *>(pTable->GetDefaultCellStyle()->obj());
893 0 : if (pDefault)
894 : {
895 0 : pXFCell = pDefault->ConvertCell(aTableID, nRow, nCol);
896 : }
897 : else
898 : {
899 0 : pXFCell = pConnCell->ConvertCell(aTableID, nRow, nCol);
900 : }
901 0 : pXFCell->SetColumnSpaned(pConnCell->GetNumcols());
902 : }
903 : else
904 : {
905 : assert(false);
906 : }
907 0 : return pXFCell;
908 : }
909 : /**
910 : * @short parse hidden cell layout
911 : * @param pOutputStream - output stream
912 : * @return
913 : */
914 0 : void LwpHiddenCellLayout::Parse(IXFStream* /*pOutputStream*/)
915 : {
916 0 : }
917 :
918 0 : LwpParallelColumnsBlock::LwpParallelColumnsBlock(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpCellLayout(objHdr, pStrm)
919 0 : {}
920 :
921 0 : LwpParallelColumnsBlock::~LwpParallelColumnsBlock()
922 0 : {}
923 :
924 0 : void LwpParallelColumnsBlock::Read()
925 : {
926 0 : LwpCellLayout::Read();
927 0 : m_pObjStrm->SkipExtra();
928 0 : }
929 :
930 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|