Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef INCLUDED_TABLE_MANAGER_HXX
21 : : #define INCLUDED_TABLE_MANAGER_HXX
22 : :
23 : : #include <resourcemodel/TableData.hxx>
24 : :
25 : : #include <resourcemodel/WW8ResourceModel.hxx>
26 : :
27 : : #include <doctok/sprmids.hxx>
28 : :
29 : : #include <boost/shared_ptr.hpp>
30 : : #include <stack>
31 : : #include "util.hxx"
32 : : #include "TagLogger.hxx"
33 : :
34 : : #if OSL_DEBUG_LEVEL > 0
35 : : # include <rtl/strbuf.hxx>
36 : : #endif
37 : :
38 : : namespace writerfilter
39 : : {
40 : :
41 : : using namespace ::std;
42 : :
43 : : /**
44 : : Class to handle events generated by TableManager::resolveCurrentTable
45 : : */
46 : : template <typename T, typename PropertiesPointer>
47 : 506 : class TableDataHandler
48 : : {
49 : : public:
50 : : typedef boost::shared_ptr<TableDataHandler> Pointer_t;
51 : :
52 : : /**
53 : : Handle start of table.
54 : :
55 : : @param nRows number of rows in the table
56 : : @param nDepth depth of the table in surrounding table hierarchy
57 : : @param pProps properties of the table
58 : : */
59 : : virtual void startTable(unsigned int nRows, unsigned int nDepth,
60 : : PropertiesPointer pProps) = 0;
61 : :
62 : : /**
63 : : Handle end of table.
64 : : */
65 : : virtual void endTable() = 0;
66 : :
67 : : /**
68 : : Handle start of row.
69 : :
70 : : @param nCols number of columns in the table
71 : : @param pProps properties of the row
72 : : */
73 : : virtual void startRow(unsigned int nCols,
74 : : PropertiesPointer pProps) = 0;
75 : :
76 : : /**
77 : : Handle end of row.
78 : : */
79 : : virtual void endRow() = 0;
80 : :
81 : : /**
82 : : Handle start of cell.
83 : :
84 : : @param rT start handle of the cell
85 : : @param pProps properties of the cell
86 : : */
87 : : virtual void startCell(const T & rT, PropertiesPointer pProps) = 0;
88 : :
89 : : /**
90 : : Handle end of cell.
91 : :
92 : : @param rT end handle of cell
93 : : */
94 : : virtual void endCell(const T & rT) = 0;
95 : :
96 : : protected:
97 : 506 : ~TableDataHandler() {}
98 : : };
99 : :
100 : : template <typename T, typename PropertiesPointer>
101 : : /**
102 : : The table manager.
103 : :
104 : : This class gets forwarded events from the tokenizer. It gathers the
105 : : table data and after ending the table generates events for the
106 : : table structure. The events have to be handles by a TableDataHandler.
107 : :
108 : : */
109 : : class TableManager
110 : : {
111 : : #ifdef DEBUG_TABLE
112 : : TagLogger::Pointer_t mpTableLogger;
113 : : #endif
114 : :
115 : : class TableManagerState
116 : : {
117 : : /**
118 : : properties at the current point in document
119 : : */
120 : : PropertiesPointer mpProps;
121 : :
122 : : /**
123 : : properties of the current cell
124 : : */
125 : : PropertiesPointer mpCellProps;
126 : :
127 : : /**
128 : : properties of the current row
129 : : */
130 : : PropertiesPointer mpRowProps;
131 : :
132 : : /**
133 : : properties of the current table
134 : : */
135 : : stack<PropertiesPointer> mTableProps;
136 : :
137 : : /**
138 : : true if at the end of a row
139 : : */
140 : : bool mbRowEnd;
141 : :
142 : : /**
143 : : true when in a cell
144 : : */
145 : : bool mbInCell;
146 : :
147 : : /**
148 : : true when at the end of a cell
149 : : */
150 : : bool mbCellEnd;
151 : :
152 : : public:
153 : : /**
154 : : Constructor
155 : : */
156 : 632 : TableManagerState()
157 [ + - ][ + - ]: 632 : : mbRowEnd(false), mbInCell(false), mbCellEnd(false)
[ + - ][ + - ]
158 : : {
159 : 632 : }
160 : :
161 : 632 : virtual ~TableManagerState()
162 : : {
163 [ + - ][ + - ]: 632 : }
[ - + ]
164 : :
165 : 740 : void startLevel()
166 : : {
167 [ + - ]: 740 : PropertiesPointer pProps;
168 [ + - ][ + - ]: 740 : mTableProps.push(pProps);
169 : 740 : }
170 : :
171 : 740 : void endLevel()
172 : : {
173 : 740 : mTableProps.pop();
174 : 740 : }
175 : :
176 : : /**
177 : : Reset to initial state at beginning of row.
178 : : */
179 : 2591 : void resetCellSpecifics()
180 : : {
181 : 2591 : mbRowEnd = false;
182 : 2591 : mbInCell = false;
183 : 2591 : mbCellEnd = false;
184 : 2591 : }
185 : :
186 : : void resetProps()
187 : : {
188 : : mpProps.reset();
189 : : }
190 : :
191 : 0 : void setProps(PropertiesPointer pProps)
192 : : {
193 : 0 : mpProps = pProps;
194 : 0 : }
195 : :
196 : : PropertiesPointer getProps()
197 : : {
198 : : return mpProps;
199 : : }
200 : :
201 : 650 : void resetCellProps()
202 : : {
203 : 650 : mpCellProps.reset();
204 : 650 : }
205 : :
206 : 442 : void setCellProps(PropertiesPointer pProps)
207 : : {
208 : 442 : mpCellProps = pProps;
209 : 442 : }
210 : :
211 : 1327 : PropertiesPointer getCellProps()
212 : : {
213 : 1327 : return mpCellProps;
214 : : }
215 : :
216 : 127 : void resetRowProps()
217 : : {
218 : 127 : mpRowProps.reset();
219 : 127 : }
220 : :
221 : 106 : void setRowProps(PropertiesPointer pProps)
222 : : {
223 : 106 : mpRowProps = pProps;
224 : 106 : }
225 : :
226 : 259 : PropertiesPointer getRowProps()
227 : : {
228 : 259 : return mpRowProps;
229 : : }
230 : :
231 : 671 : void resetTableProps()
232 : : {
233 [ + - ]: 671 : if (mTableProps.size() > 0)
234 : 671 : mTableProps.top().reset();
235 : 671 : }
236 : :
237 : 87 : void setTableProps(PropertiesPointer pProps)
238 : : {
239 [ + - ]: 87 : if (mTableProps.size() > 0)
240 : 87 : mTableProps.top() = pProps;
241 : 87 : }
242 : :
243 : 978 : PropertiesPointer getTableProps()
244 : : {
245 : 978 : PropertiesPointer pResult;
246 : :
247 [ + - ]: 978 : if (mTableProps.size() > 0)
248 [ + - ][ + - ]: 978 : pResult = mTableProps.top();
249 : :
250 : 978 : return pResult;
251 : : }
252 : :
253 : 1490 : void setInCell(bool bInCell)
254 : : {
255 : 1490 : mbInCell = bInCell;
256 : 1490 : }
257 : :
258 : 550 : bool isInCell() const
259 : : {
260 : 550 : return mbInCell;
261 : : }
262 : :
263 : 1146 : void setCellEnd(bool bCellEnd)
264 : : {
265 : 1146 : mbCellEnd = bCellEnd;
266 : 1146 : }
267 : :
268 : 523 : bool isCellEnd() const
269 : : {
270 : 523 : return mbCellEnd;
271 : : }
272 : :
273 : 765 : void setRowEnd(bool bRowEnd)
274 : : {
275 : 765 : mbRowEnd = bRowEnd;
276 : 765 : }
277 : :
278 : 4133 : bool isRowEnd() const
279 : : {
280 : 4133 : return mbRowEnd;
281 : : }
282 : : };
283 : :
284 : : /**
285 : : handle for the current position in document
286 : : */
287 : : T mCurHandle;
288 : :
289 : : TableManagerState mState;
290 : :
291 : : protected:
292 : : PropertiesPointer getProps()
293 : : {
294 : : return mState.getProps();
295 : : }
296 : :
297 : 0 : void setProps(PropertiesPointer pProps)
298 : : {
299 [ # # ]: 0 : mState.setProps(pProps);
300 : 0 : }
301 : :
302 : : void resetProps()
303 : : {
304 : : mState.resetProps();
305 : : }
306 : :
307 : 1327 : PropertiesPointer getCellProps()
308 : : {
309 : 1327 : return mState.getCellProps();
310 : : }
311 : :
312 : 442 : void setCellProps(PropertiesPointer pProps)
313 : : {
314 [ + - ]: 442 : mState.setCellProps(pProps);
315 : 442 : }
316 : :
317 : 650 : void resetCellProps()
318 : : {
319 : 650 : mState.resetCellProps();
320 : 650 : }
321 : :
322 : 259 : PropertiesPointer getRowProps()
323 : : {
324 : 259 : return mState.getRowProps();
325 : : }
326 : :
327 : 106 : void setRowProps(PropertiesPointer pProps)
328 : : {
329 [ + - ]: 106 : mState.setRowProps(pProps);
330 : 106 : }
331 : :
332 : 127 : void resetRowProps()
333 : : {
334 : 127 : mState.resetRowProps();
335 : 127 : }
336 : :
337 : 1490 : void setInCell(bool bInCell)
338 : : {
339 : 1490 : mState.setInCell(bInCell);
340 : 1490 : }
341 : :
342 : 550 : bool isInCell() const
343 : : {
344 : 550 : return mState.isInCell();
345 : : }
346 : :
347 : 1146 : void setCellEnd(bool bCellEnd)
348 : : {
349 : 1146 : mState.setCellEnd(bCellEnd);
350 : 1146 : }
351 : :
352 : 523 : bool isCellEnd() const
353 : : {
354 : 523 : return mState.isCellEnd();
355 : : }
356 : :
357 : 765 : void setRowEnd(bool bRowEnd)
358 : : {
359 : 765 : mState.setRowEnd(bRowEnd);
360 : 765 : }
361 : :
362 : 4133 : bool isRowEnd() const
363 : : {
364 : 4133 : return mState.isRowEnd();
365 : : }
366 : :
367 : 978 : PropertiesPointer getTableProps()
368 : : {
369 : 978 : return mState.getTableProps();
370 : : }
371 : :
372 : 87 : void setTableProps(PropertiesPointer pProps)
373 : : {
374 [ + - ]: 87 : mState.setTableProps(pProps);
375 : 87 : }
376 : :
377 : 671 : void resetTableProps()
378 : : {
379 : 671 : mState.resetTableProps();
380 : 671 : }
381 : :
382 : 1060 : T getHandle()
383 : : {
384 : 1060 : return mCurHandle;
385 : : }
386 : :
387 : 1474 : void setHandle(const T & rHandle)
388 : : {
389 : 1474 : mCurHandle = rHandle;
390 : 1474 : }
391 : :
392 : : private:
393 : : typedef boost::shared_ptr<T> T_p;
394 : :
395 : : /**
396 : : depth of the current cell
397 : : */
398 : : sal_uInt32 mnTableDepthNew;
399 : :
400 : : /**
401 : : depth of the previous cell
402 : : */
403 : : sal_uInt32 mnTableDepth;
404 : :
405 : : /**
406 : : stack of table data
407 : :
408 : : for each level of nested tables there is one frame in the stack
409 : : */
410 : : stack<typename TableData<T, PropertiesPointer>::Pointer_t > mTableDataStack;
411 : :
412 : : typedef typename TableDataHandler<T, PropertiesPointer>::Pointer_t TableDataHandlerPointer_t;
413 : :
414 : : /**
415 : : handler for resolveCurrentTable
416 : : */
417 : : TableDataHandlerPointer_t mpTableDataHandler;
418 : :
419 : : /**
420 : : Set flag which indicates the current handle is in a cell.
421 : : */
422 : : void inCell();
423 : :
424 : : /**
425 : : Set flag which indicate the current handle is at the end of a cell.
426 : : */
427 : : void endCell();
428 : :
429 : : /**
430 : : Set the table depth of the current cell.
431 : :
432 : : @param nDepth the cell depth
433 : : */
434 : : void cellDepth(sal_uInt32 nDepth);
435 : :
436 : : /**
437 : : Set flag indication the current handle is at the end of a row.
438 : : */
439 : : void endRow();
440 : :
441 : : /**
442 : : Resolve the current table to the TableDataHandler.
443 : : */
444 : : void resolveCurrentTable();
445 : :
446 : : /**
447 : : Open a cell at current level.
448 : : */
449 : :
450 : : void openCell(const T & handle, PropertiesPointer pProps);
451 : :
452 : : /**
453 : : Close a cell at current level.
454 : : */
455 : : void closeCell(const T & handle);
456 : :
457 : : /**
458 : : Ensure a cell is open at the current level.
459 : : */
460 : : void ensureOpenCell(PropertiesPointer pProps);
461 : :
462 : : protected:
463 : :
464 : : /**
465 : : Return current table depth.
466 : : */
467 : 0 : sal_uInt32 getTableDepthNew() { return mnTableDepthNew; }
468 : :
469 : : /**
470 : : Action to be carried out at the end of the last paragraph of a
471 : : cell.
472 : : */
473 : : virtual void endOfCellAction();
474 : :
475 : : /**
476 : : Action to be carried out at the end of the "table row"
477 : : paragraph.
478 : : */
479 : : virtual void endOfRowAction();
480 : : /** let the derived class clear their table related data
481 : : */
482 : : virtual void clearData();
483 : :
484 : :
485 : : public:
486 : : TableManager();
487 [ + - ][ + - ]: 632 : virtual ~TableManager(){}
[ - + ]
488 : :
489 : : /**
490 : : Set handler for resolveCurrentTable.
491 : :
492 : : @param pTableDataHandler the handler
493 : : */
494 : : void setHandler(TableDataHandlerPointer_t pTableDataHandler);
495 : :
496 : : /**
497 : : Set the current handle.
498 : :
499 : : @param rHandle the handle
500 : : */
501 : : virtual void handle(const T & rHandle);
502 : :
503 : : /**
504 : : Start a new table level.
505 : :
506 : : A new context is pushed onto the table data stack,
507 : : */
508 : : virtual void startLevel();
509 : :
510 : : /**
511 : : End a table level.
512 : :
513 : : The current table is resolved and the context is popped from
514 : : the stack.
515 : : */
516 : : virtual void endLevel();
517 : :
518 : : /**
519 : : Handle the start of a paragraph group.
520 : : */
521 : : virtual void startParagraphGroup();
522 : :
523 : : /**
524 : : Handle the end of a paragraph group.
525 : : */
526 : : virtual void endParagraphGroup();
527 : :
528 : : /**
529 : : Handle an SPRM at curent handle.
530 : :
531 : : @param rSprm the SPRM
532 : : */
533 : : virtual bool sprm(Sprm & rSprm);
534 : :
535 : : /**
536 : : Handle properties at current handle.
537 : :
538 : : @param pProps the properites
539 : : */
540 : : virtual void props(PropertiesPointer pProps);
541 : :
542 : : /**
543 : : Handle occurrence of character 0x7.
544 : : */
545 : : virtual void handle0x7();
546 : :
547 : : /**
548 : : Handle 8 bit text at current handle.
549 : :
550 : : @param data array of characters
551 : : @param len number of characters to handle
552 : : */
553 : : virtual void text(const sal_uInt8 * data, size_t len);
554 : :
555 : : /**
556 : : Handle 16 bit text at current handle.
557 : :
558 : : @param data array of characters
559 : : @param len number of characters to handle
560 : : */
561 : : virtual void utext(const sal_uInt8 * data, size_t len);
562 : :
563 : : /**
564 : : Handle properties of the current cell.
565 : :
566 : : @param pProps the properties
567 : : */
568 : : virtual void cellProps(PropertiesPointer pProps);
569 : :
570 : : /**
571 : : Handle properties of a certain cell in the current row.
572 : :
573 : : @paran i index of the cell in the current row
574 : : @param pProps the properties
575 : : */
576 : : virtual void cellPropsByCell(unsigned int i, PropertiesPointer pProps);
577 : :
578 : : /**
579 : : Handle properties of the current row.
580 : :
581 : : @param pProps the properties
582 : : */
583 : : virtual void insertRowProps(PropertiesPointer pProps);
584 : :
585 : : /**
586 : : Handle properties of the current table.
587 : :
588 : : @param pProps the properties
589 : : */
590 : : virtual void insertTableProps(PropertiesPointer pProps);
591 : :
592 : : /**
593 : : Return if table manager has detected paragraph to ignore.
594 : :
595 : : If this function returns true the current paragraph contains
596 : : only control information, e.g. end of row.
597 : : */
598 : : virtual bool isIgnore() const;
599 : :
600 : :
601 : : #ifdef DEBUG_TABLE
602 : : void setTagLogger(TagLogger::Pointer_t _tagLogger)
603 : : {
604 : : mpTableLogger = _tagLogger;
605 : : }
606 : : #endif
607 : : };
608 : :
609 : : template <typename T, typename PropertiesPointer>
610 : 632 : TableManager<T, PropertiesPointer>::TableManager()
611 [ + - ][ + - ]: 632 : : mnTableDepthNew(0), mnTableDepth(0)
[ + - ][ + - ]
612 : : {
613 [ + - ]: 632 : setRowEnd(false);
614 [ + - ]: 632 : setInCell(false);
615 [ + - ]: 632 : setCellEnd(false);
616 : 632 : }
617 : :
618 : : template <typename T, typename PropertiesPointer>
619 : 588 : void TableManager<T, PropertiesPointer>::cellDepth(sal_uInt32 nDepth)
620 : : {
621 : : #ifdef DEBUG_TABLE
622 : : if (mpTableLogger != NULL)
623 : : {
624 : : mpTableLogger->startElement("tablemanager.cellDepth");
625 : : mpTableLogger->attribute("depth", nDepth);
626 : : mpTableLogger->endElement();
627 : : }
628 : : #endif
629 : :
630 : 588 : mnTableDepthNew = nDepth;
631 : 588 : }
632 : :
633 : : template <typename T, typename PropertiesPointer>
634 : 858 : void TableManager<T, PropertiesPointer>::inCell()
635 : : {
636 : : #ifdef DEBUG_TABLE
637 : : if (mpTableLogger != NULL)
638 : : mpTableLogger->element("tablemanager.inCell");
639 : : #endif
640 : 858 : setInCell(true);
641 : :
642 [ + + ]: 858 : if (mnTableDepthNew < 1)
643 : 360 : mnTableDepthNew = 1;
644 : 858 : }
645 : :
646 : : template <typename T, typename PropertiesPointer>
647 : 514 : void TableManager<T, PropertiesPointer>::endCell()
648 : : {
649 : : #ifdef DEBUG_TABLE
650 : : if (mpTableLogger != NULL)
651 : : mpTableLogger->element("tablemanager.endCell");
652 : : #endif
653 : :
654 : 514 : setCellEnd(true);
655 : 514 : }
656 : :
657 : : template <typename T, typename PropertiesPointer>
658 : 133 : void TableManager<T, PropertiesPointer>::endRow()
659 : : {
660 : : #ifdef DEBUG_TABLE
661 : : if (mpTableLogger != NULL)
662 : : mpTableLogger->element("tablemanager.endRow");
663 : : #endif
664 : :
665 : 133 : setRowEnd(true);
666 : 133 : }
667 : :
668 : : template <typename T, typename PropertiesPointer>
669 : 563 : void TableManager<T, PropertiesPointer>::setHandler
670 : : (typename TableDataHandler<T, PropertiesPointer>::Pointer_t pTableDataHandler)
671 : : {
672 : 563 : mpTableDataHandler = pTableDataHandler;
673 : 563 : }
674 : :
675 : : template <typename T, typename PropertiesPointer>
676 : 1474 : void TableManager<T, PropertiesPointer>::handle(const T & rHandle)
677 : : {
678 : : #ifdef DEBUG_TABLE
679 : : if (mpTableLogger)
680 : : {
681 : : mpTableLogger->startElement("tablemanager.handle");
682 : : mpTableLogger->chars(toString(rHandle));
683 : : mpTableLogger->endElement();
684 : : }
685 : : #endif
686 : :
687 : 1474 : setHandle(rHandle);
688 : 1474 : }
689 : :
690 : : template <typename T, typename PropertiesPointer>
691 : 740 : void TableManager<T, PropertiesPointer>::startLevel()
692 : : {
693 : : #ifdef DEBUG_TABLE
694 : : if (mpTableLogger != NULL)
695 : : {
696 : : typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
697 : :
698 : : if (mTableDataStack.size() > 0)
699 : : pTableData = mTableDataStack.top();
700 : :
701 : : mpTableLogger->startElement("tablemanager.startLevel");
702 : : mpTableLogger->attribute("level", mTableDataStack.size());
703 : :
704 : : if (pTableData.get() != NULL)
705 : : mpTableLogger->attribute("openCell",
706 : : pTableData->isCellOpen() ? "yes" : "no");
707 : :
708 : : mpTableLogger->endElement();
709 : : }
710 : : #endif
711 : :
712 : : typename TableData<T, PropertiesPointer>::Pointer_t pTableData
713 [ + - ][ + - ]: 740 : (new TableData<T, PropertiesPointer>(mTableDataStack.size()));
[ + - ]
714 : :
715 [ + - ]: 740 : mTableDataStack.push(pTableData);
716 [ + - ][ + - ]: 740 : mState.startLevel();
717 : 740 : }
718 : :
719 : : template <typename T, typename PropertiesPointer>
720 : 740 : void TableManager<T, PropertiesPointer>::endLevel()
721 : : {
722 [ + + ]: 740 : if (mpTableDataHandler.get() != NULL)
723 : 671 : resolveCurrentTable();
724 : :
725 : 740 : mState.endLevel();
726 : 740 : mTableDataStack.pop();
727 : :
728 : : #ifdef DEBUG_TABLE
729 : : if (mpTableLogger != NULL)
730 : : {
731 : : typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
732 : :
733 : : if (mTableDataStack.size() > 0)
734 : : pTableData = mTableDataStack.top();
735 : :
736 : : mpTableLogger->startElement("tablemanager.endLevel");
737 : : mpTableLogger->attribute("level", mTableDataStack.size());
738 : :
739 : : if (pTableData.get() != NULL)
740 : : mpTableLogger->attribute("openCell",
741 : : pTableData->isCellOpen() ? "yes" : "no");
742 : :
743 : : mpTableLogger->endElement();
744 : : }
745 : : #endif
746 : 740 : }
747 : :
748 : : template <typename T, typename PropertiesPointer>
749 : 2591 : void TableManager<T, PropertiesPointer>::startParagraphGroup()
750 : : {
751 : 2591 : mState.resetCellSpecifics();
752 : 2591 : mnTableDepthNew = 0;
753 : 2591 : }
754 : :
755 : : template <typename T, typename PropertiesPointer>
756 : 2555 : void TableManager<T, PropertiesPointer>::endParagraphGroup()
757 : : {
758 : 2555 : sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth;
759 : :
760 [ + - ]: 2555 : PropertiesPointer pEmptyProps;
761 : :
762 [ + + ]: 2663 : while (nTableDepthDifference > 0)
763 : : {
764 [ + - ][ + - ]: 108 : ensureOpenCell(pEmptyProps);
[ + - ]
765 [ + - ]: 108 : startLevel();
766 : :
767 : 108 : --nTableDepthDifference;
768 : : }
769 [ + + ]: 2663 : while (nTableDepthDifference < 0)
770 : : {
771 [ + - ]: 108 : endLevel();
772 : :
773 : 108 : ++nTableDepthDifference;
774 : : }
775 : :
776 : 2555 : mnTableDepth = mnTableDepthNew;
777 : :
778 [ + + ]: 2555 : if (mnTableDepth > 0)
779 : : {
780 : : typename TableData<T, PropertiesPointer>::Pointer_t pTableData =
781 [ + - ][ + - ]: 650 : mTableDataStack.top();
782 : :
783 [ + - ][ + + ]: 650 : if (isRowEnd())
784 : : {
785 [ + - ]: 127 : endOfRowAction();
786 [ + - ][ + - ]: 127 : pTableData->endRow(getRowProps());
[ + - ]
787 [ + - ]: 127 : resetRowProps();
788 : : }
789 : :
790 [ + - ][ + - ]: 523 : else if (isInCell())
791 : : {
792 [ + - ][ + - ]: 523 : ensureOpenCell(getCellProps());
[ + - ]
793 : :
794 [ + - ][ + + ]: 523 : if (isCellEnd())
795 : : {
796 [ + - ]: 514 : endOfCellAction();
797 [ # + - ]: 514 : closeCell(getHandle());
[ # # ]
798 : : }
799 : : }
800 [ + - ][ + - ]: 2555 : resetCellProps();
[ + - ]
801 : : }
802 : 2555 : }
803 : :
804 : : template <typename T, typename PropertiesPointer>
805 : 60126 : bool TableManager<T, PropertiesPointer>::sprm(Sprm & rSprm)
806 : : {
807 : 60126 : bool bRet = true;
808 [ + + + + : 60126 : switch (rSprm.getId())
+ ]
809 : : {
810 : : case NS_sprm::LN_PTableDepth:
811 : : {
812 [ + - ][ + - ]: 588 : Value::Pointer_t pValue = rSprm.getValue();
813 : :
814 [ + - ][ + - ]: 588 : cellDepth(pValue->getInt());
815 : : }
816 : 588 : break;
817 : : case NS_sprm::LN_PFInTable:
818 : 858 : inCell();
819 : 858 : break;
820 : : case NS_sprm::LN_PCell:
821 : 514 : endCell();
822 : 514 : break;
823 : : case NS_sprm::LN_PFTtp:
824 : : case NS_sprm::LN_PRow:
825 : 106 : endRow();
826 : 106 : break;
827 : : default:
828 : 58060 : bRet = false;
829 : : }
830 : 60126 : return bRet;
831 : : }
832 : : template <typename T, typename PropertiesPointer>
833 : 0 : void TableManager<T, PropertiesPointer>::props(PropertiesPointer pProps)
834 : : {
835 [ # # ]: 0 : setProps(pProps);
836 : 0 : }
837 : :
838 : : template <typename T, typename PropertiesPointer>
839 : 27 : void TableManager<T, PropertiesPointer>::handle0x7()
840 : : {
841 : : #ifdef DEBUG_TABLE
842 : : if (mpTableLogger != NULL)
843 : : mpTableLogger->startElement("tablemanager.handle0x7");
844 : : #endif
845 : :
846 [ + + ]: 27 : if (mnTableDepthNew < 1)
847 : 21 : mnTableDepthNew = 1;
848 : :
849 [ - + ]: 27 : if (isInCell())
850 : 0 : endCell();
851 : : else
852 : 27 : endRow();
853 : :
854 : : #ifdef DEBUG_TABLE
855 : : if (mpTableLogger != NULL)
856 : : mpTableLogger->endElement();
857 : : #endif
858 : 27 : }
859 : :
860 : : template <typename T, typename PropertiesPointer>
861 : 0 : void TableManager<T, PropertiesPointer>::text(const sal_uInt8 * data, size_t len)
862 : : {
863 : : // optimization: cell/row end characters are the last characters in a run
864 [ # # ]: 0 : if (len > 0)
865 : : {
866 [ # # ]: 0 : if (data[len - 1] == 0x7)
867 : 0 : handle0x7();
868 : : }
869 : 0 : }
870 : :
871 : : template <typename T, typename PropertiesPointer>
872 : 13650 : void TableManager<T, PropertiesPointer>::utext(const sal_uInt8 * data, size_t len)
873 : : {
874 : : // optimization: cell/row end characters are the last characters in a run
875 : :
876 [ + - ]: 13650 : if (len > 0)
877 : : {
878 : 13650 : sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8);
879 [ + + ]: 13650 : if (nChar == 0x7)
880 : 27 : handle0x7();
881 : : }
882 : 13650 : }
883 : :
884 : : template <typename T, typename PropertiesPointer>
885 : 623 : void TableManager<T, PropertiesPointer>::cellProps(PropertiesPointer pProps)
886 : : {
887 : : #ifdef DEBUG_TABLE
888 : : if (mpTableLogger != NULL)
889 : : mpTableLogger->startElement("tablemanager.cellProps");
890 : : #endif
891 : :
892 [ + + ]: 623 : if(getCellProps().get())
893 [ + - # ]: 181 : getCellProps()->insert( pProps );
[ + - # # ]
[ + - ][ + - ]
[ + - ]
894 : : else
895 [ + - ]: 442 : setCellProps(pProps);
896 : :
897 : : #ifdef DEBUG_TABLE
898 : : if (mpTableLogger != NULL)
899 : : mpTableLogger->endElement();
900 : : #endif
901 : 623 : }
902 : :
903 : : template <typename T, typename PropertiesPointer>
904 : 0 : void TableManager<T, PropertiesPointer>::cellPropsByCell
905 : : (unsigned int i, PropertiesPointer pProps)
906 : : {
907 : : #ifdef DEBUG_TABLE
908 : : if (mpTableLogger != NULL)
909 : : mpTableLogger->startElement("tablemanager.cellPropsByCell");
910 : : #endif
911 : :
912 [ # # ][ # # ]: 0 : mTableDataStack.top()->insertCellProperties(i, pProps);
913 : :
914 : : #ifdef DEBUG_TABLE
915 : : if (mpTableLogger != NULL)
916 : : mpTableLogger->endElement();
917 : : #endif
918 : 0 : }
919 : :
920 : : template <typename T, typename PropertiesPointer>
921 : 119 : void TableManager<T, PropertiesPointer>::insertRowProps(PropertiesPointer pProps)
922 : : {
923 : : #ifdef DEBUG_TABLE
924 : : if (mpTableLogger != NULL)
925 : : mpTableLogger->startElement("tablemanager.insertRowProps");
926 : : #endif
927 : :
928 [ + + ]: 119 : if( getRowProps().get() )
929 [ + - # ]: 13 : getRowProps()->insert( pProps );
[ + - # # ]
[ + - ][ + - ]
[ + - ]
930 : : else
931 [ + - ]: 106 : setRowProps(pProps);
932 : :
933 : : #ifdef DEBUG_TABLE
934 : : if (mpTableLogger != NULL)
935 : : mpTableLogger->endElement();
936 : : #endif
937 : 119 : }
938 : :
939 : : template <typename T, typename PropertiesPointer>
940 : 197 : void TableManager<T, PropertiesPointer>::insertTableProps(PropertiesPointer pProps)
941 : : {
942 : : #ifdef DEBUG_TABLE
943 : : if (mpTableLogger != NULL)
944 : : mpTableLogger->startElement("tablemanager.insertTableProps");
945 : : #endif
946 : :
947 [ + + ]: 197 : if( getTableProps().get() )
948 [ + - # ]: 110 : getTableProps()->insert( pProps );
[ + - # # ]
[ + - ][ + - ]
[ + - ]
949 : : else
950 [ + - ]: 87 : setTableProps(pProps);
951 : :
952 : : #ifdef DEBUG_TABLE
953 : : if (mpTableLogger != NULL)
954 : : mpTableLogger->endElement();
955 : : #endif
956 : 197 : }
957 : :
958 : : template <typename T, typename PropertiesPointer>
959 : 671 : void TableManager<T, PropertiesPointer>::resolveCurrentTable()
960 : : {
961 : : #ifdef DEBUG_TABLE
962 : : if (mpTableLogger != NULL)
963 : : mpTableLogger->startElement("tablemanager.resolveCurrentTable");
964 : : #endif
965 : :
966 [ + - ]: 671 : if (mpTableDataHandler.get() != NULL)
967 : : {
968 : : try
969 : : {
970 : : typename TableData<T, PropertiesPointer>::Pointer_t
971 [ + - ][ + - ]: 671 : pTableData = mTableDataStack.top();
972 : :
973 : 671 : unsigned int nRows = pTableData->getRowCount();
974 : :
975 [ + - ][ + - ]: 671 : mpTableDataHandler->startTable(nRows, pTableData->getDepth(), getTableProps());
[ + - ]
976 : :
977 [ + + ]: 798 : for (unsigned int nRow = 0; nRow < nRows; ++nRow)
978 : : {
979 [ + - ]: 127 : typename RowData<T, PropertiesPointer>::Pointer_t pRowData = pTableData->getRow(nRow);
980 : :
981 : 127 : unsigned int nCells = pRowData->getCellCount();
982 : :
983 [ + - ][ + - ]: 127 : mpTableDataHandler->startRow(nCells, pRowData->getProperties());
[ + - ]
984 : :
985 [ + + ]: 641 : for (unsigned int nCell = 0; nCell < nCells; ++nCell)
986 : : {
987 [ + - ][ + - ]: 514 : mpTableDataHandler->startCell
[ + - ][ + - ]
988 : : (pRowData->getCellStart(nCell),
989 : : pRowData->getCellProperties(nCell));
990 : :
991 [ + - ][ + - ]: 514 : mpTableDataHandler->endCell(pRowData->getCellEnd(nCell));
992 : : }
993 : :
994 [ + - ][ + - ]: 127 : mpTableDataHandler->endRow();
995 : : }
996 : :
997 [ + - ][ + - ]: 671 : mpTableDataHandler->endTable();
[ # # ]
998 : : }
999 : 0 : catch (uno::Exception const& e)
1000 : : {
1001 : : (void) e;
1002 : : #if OSL_DEBUG_LEVEL > 0
1003 : : SAL_WARN("writerfilter", "resolving of current table failed with: " << e.Message);
1004 : : #endif
1005 : : }
1006 : : }
1007 : 671 : resetTableProps();
1008 : 671 : clearData();
1009 : :
1010 : : #ifdef DEBUG_TABLE
1011 : : if (mpTableLogger != NULL)
1012 : : mpTableLogger->endElement();
1013 : : #endif
1014 : 671 : }
1015 : :
1016 : : template <typename T, typename PropertiesPointer>
1017 : 0 : void TableManager<T, PropertiesPointer>::endOfCellAction()
1018 : : {
1019 : 0 : }
1020 : :
1021 : : template <typename T, typename PropertiesPointer>
1022 : 0 : void TableManager<T, PropertiesPointer>::endOfRowAction()
1023 : : {
1024 : 0 : }
1025 : :
1026 : : template <typename T, typename PropertiesPointer>
1027 : 3483 : bool TableManager<T, PropertiesPointer>::isIgnore() const
1028 : : {
1029 : 3483 : return isRowEnd();
1030 : : }
1031 : :
1032 : : template <typename T, typename PropertiesPointer>
1033 : 0 : void TableManager<T, PropertiesPointer>::clearData()
1034 : : {
1035 : 0 : }
1036 : :
1037 : : template <typename T, typename PropertiesPointer>
1038 : 546 : void TableManager<T, PropertiesPointer>::openCell
1039 : : (const T & rHandle, PropertiesPointer pProps)
1040 : : {
1041 : : #ifdef DEBUG_TABLE
1042 : : mpTableLogger->startElement("tablemanager.openCell");
1043 : : mpTableLogger->chars(toString(rHandle));
1044 : : mpTableLogger->endElement();
1045 : : #endif
1046 : :
1047 [ + - ]: 546 : if (mTableDataStack.size() > 0)
1048 : : {
1049 : : typename TableData<T, PropertiesPointer>::Pointer_t
1050 [ + - ][ + - ]: 546 : pTableData = mTableDataStack.top();
1051 : :
1052 [ + - ][ + - ]: 546 : pTableData->addCell(rHandle, pProps);
[ + - ][ + - ]
1053 : : }
1054 : 546 : }
1055 : :
1056 : : template <typename T, typename PropertiesPointer>
1057 : 514 : void TableManager<T, PropertiesPointer>::closeCell
1058 : : (const T & rHandle)
1059 : : {
1060 : : #ifdef DEBUG_TABLE
1061 : : mpTableLogger->startElement("tablemanager.closeCell");
1062 : : mpTableLogger->chars(toString(rHandle));
1063 : : mpTableLogger->endElement();
1064 : : #endif
1065 : :
1066 [ + - ]: 514 : if (mTableDataStack.size() > 0)
1067 : : {
1068 : : typename TableData<T, PropertiesPointer>::Pointer_t
1069 [ + - ][ + - ]: 514 : pTableData = mTableDataStack.top();
1070 : :
1071 [ + - ][ + - ]: 514 : pTableData->endCell(rHandle);
1072 : : }
1073 : 514 : }
1074 : :
1075 : : template <typename T, typename PropertiesPointer>
1076 : 631 : void TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProps)
1077 : : {
1078 : : #ifdef DEBUG_TABLE
1079 : : mpTableLogger->startElement("tablemanager.ensureOpenCell");
1080 : : #endif
1081 : :
1082 [ + - ]: 631 : if (mTableDataStack.size() > 0)
1083 : : {
1084 : : typename TableData<T, PropertiesPointer>::Pointer_t
1085 [ + - ][ + - ]: 631 : pTableData = mTableDataStack.top();
1086 : :
1087 [ + - ]: 631 : if (pTableData.get() != NULL)
1088 : : {
1089 [ + - ][ + + ]: 631 : if (!pTableData->isCellOpen())
1090 [ + - ]: 546 : openCell(getHandle(), pProps);
[ # + - ]
[ # # + - ]
[ # # ]
1091 : : else
1092 [ + - ][ + - ]: 631 : pTableData->insertCellProperties(pProps);
[ + - ][ + - ]
1093 : : }
1094 : : }
1095 : : #ifdef DEBUG_TABLE
1096 : : mpTableLogger->endElement();
1097 : : #endif
1098 : 631 : }
1099 : :
1100 : : }
1101 : :
1102 : : #endif // INCLUDED_TABLE_MANAGER_HXX
1103 : :
1104 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|