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 <ooxml/resourceids.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 0 : 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(unsigned int nestedTableLevel) = 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 0 : ~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 0 : TableManagerState()
157 0 : : mbRowEnd(false), mbInCell(false), mbCellEnd(false)
158 : {
159 0 : }
160 :
161 0 : virtual ~TableManagerState()
162 : {
163 0 : }
164 :
165 0 : void startLevel()
166 : {
167 0 : PropertiesPointer pProps;
168 0 : mTableProps.push(pProps);
169 0 : }
170 :
171 0 : void endLevel()
172 : {
173 0 : mTableProps.pop();
174 0 : }
175 :
176 : /**
177 : Reset to initial state at beginning of row.
178 : */
179 0 : void resetCellSpecifics()
180 : {
181 0 : mbRowEnd = false;
182 0 : mbInCell = false;
183 0 : mbCellEnd = false;
184 0 : }
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 0 : void resetCellProps()
202 : {
203 0 : mpCellProps.reset();
204 0 : }
205 :
206 0 : void setCellProps(PropertiesPointer pProps)
207 : {
208 0 : mpCellProps = pProps;
209 0 : }
210 :
211 0 : PropertiesPointer getCellProps()
212 : {
213 0 : return mpCellProps;
214 : }
215 :
216 0 : void resetRowProps()
217 : {
218 0 : mpRowProps.reset();
219 0 : }
220 :
221 0 : void setRowProps(PropertiesPointer pProps)
222 : {
223 0 : mpRowProps = pProps;
224 0 : }
225 :
226 0 : PropertiesPointer getRowProps()
227 : {
228 0 : return mpRowProps;
229 : }
230 :
231 0 : void resetTableProps()
232 : {
233 0 : if (mTableProps.size() > 0)
234 0 : mTableProps.top().reset();
235 0 : }
236 :
237 0 : void setTableProps(PropertiesPointer pProps)
238 : {
239 0 : if (mTableProps.size() > 0)
240 0 : mTableProps.top() = pProps;
241 0 : }
242 :
243 0 : PropertiesPointer getTableProps()
244 : {
245 0 : PropertiesPointer pResult;
246 :
247 0 : if (mTableProps.size() > 0)
248 0 : pResult = mTableProps.top();
249 :
250 0 : return pResult;
251 : }
252 :
253 0 : void setInCell(bool bInCell)
254 : {
255 0 : mbInCell = bInCell;
256 0 : }
257 :
258 0 : bool isInCell() const
259 : {
260 0 : return mbInCell;
261 : }
262 :
263 0 : void setCellEnd(bool bCellEnd)
264 : {
265 0 : mbCellEnd = bCellEnd;
266 0 : }
267 :
268 0 : bool isCellEnd() const
269 : {
270 0 : return mbCellEnd;
271 : }
272 :
273 0 : void setRowEnd(bool bRowEnd)
274 : {
275 0 : mbRowEnd = bRowEnd;
276 0 : }
277 :
278 0 : bool isRowEnd() const
279 : {
280 0 : 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 0 : PropertiesPointer getCellProps()
308 : {
309 0 : return mState.getCellProps();
310 : }
311 :
312 0 : void setCellProps(PropertiesPointer pProps)
313 : {
314 0 : mState.setCellProps(pProps);
315 0 : }
316 :
317 0 : void resetCellProps()
318 : {
319 0 : mState.resetCellProps();
320 0 : }
321 :
322 0 : PropertiesPointer getRowProps()
323 : {
324 0 : return mState.getRowProps();
325 : }
326 :
327 0 : void setRowProps(PropertiesPointer pProps)
328 : {
329 0 : mState.setRowProps(pProps);
330 0 : }
331 :
332 0 : void resetRowProps()
333 : {
334 0 : mState.resetRowProps();
335 0 : }
336 :
337 0 : void setInCell(bool bInCell)
338 : {
339 0 : mState.setInCell(bInCell);
340 0 : }
341 :
342 0 : bool isInCell() const
343 : {
344 0 : return mState.isInCell();
345 : }
346 :
347 0 : void setCellEnd(bool bCellEnd)
348 : {
349 0 : mState.setCellEnd(bCellEnd);
350 0 : }
351 :
352 0 : bool isCellEnd() const
353 : {
354 0 : return mState.isCellEnd();
355 : }
356 :
357 0 : void setRowEnd(bool bRowEnd)
358 : {
359 0 : mState.setRowEnd(bRowEnd);
360 0 : }
361 :
362 0 : bool isRowEnd() const
363 : {
364 0 : return mState.isRowEnd();
365 : }
366 :
367 0 : PropertiesPointer getTableProps()
368 : {
369 0 : return mState.getTableProps();
370 : }
371 :
372 0 : void setTableProps(PropertiesPointer pProps)
373 : {
374 0 : mState.setTableProps(pProps);
375 0 : }
376 :
377 0 : void resetTableProps()
378 : {
379 0 : mState.resetTableProps();
380 0 : }
381 :
382 0 : T getHandle()
383 : {
384 0 : return mCurHandle;
385 : }
386 :
387 0 : void setHandle(const T & rHandle)
388 : {
389 0 : mCurHandle = rHandle;
390 0 : }
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 : typename RowData<T, PropertiesPointer>::Pointer_t mpUnfinishedRow;
412 : bool mbKeepUnfinishedRow;
413 :
414 : typedef typename TableDataHandler<T, PropertiesPointer>::Pointer_t TableDataHandlerPointer_t;
415 :
416 : /**
417 : handler for resolveCurrentTable
418 : */
419 : TableDataHandlerPointer_t mpTableDataHandler;
420 :
421 : /**
422 : Set flag which indicates the current handle is in a cell.
423 : */
424 : void inCell();
425 :
426 : /**
427 : Set flag which indicate the current handle is at the end of a cell.
428 : */
429 : void endCell();
430 :
431 : /**
432 : Set the table depth of the current cell.
433 :
434 : @param nDepth the cell depth
435 : */
436 : void cellDepth(sal_uInt32 nDepth);
437 :
438 : /**
439 : Set flag indication the current handle is at the end of a row.
440 : */
441 : void endRow();
442 :
443 : /**
444 : Resolve the current table to the TableDataHandler.
445 : */
446 : void resolveCurrentTable();
447 :
448 : /**
449 : Open a cell at current level.
450 : */
451 :
452 : void openCell(const T & handle, PropertiesPointer pProps);
453 :
454 : /**
455 : Close a cell at current level.
456 : */
457 : void closeCell(const T & handle);
458 :
459 : /**
460 : Ensure a cell is open at the current level.
461 : */
462 : void ensureOpenCell(PropertiesPointer pProps);
463 :
464 : protected:
465 :
466 : /**
467 : Return current table depth.
468 : */
469 : sal_uInt32 getTableDepthNew() { return mnTableDepthNew; }
470 :
471 : /**
472 : Return the current table difference, i.e. 1 if we are in the first cell of a new table, etc.
473 : */
474 0 : sal_uInt32 getTableDepthDifference() { return mnTableDepthNew - mnTableDepth; }
475 :
476 : /**
477 : Action to be carried out at the end of the last paragraph of a
478 : cell.
479 : */
480 : virtual void endOfCellAction();
481 :
482 : /**
483 : Action to be carried out at the end of the "table row"
484 : paragraph.
485 : */
486 : virtual void endOfRowAction();
487 : /** let the derived class clear their table related data
488 : */
489 : virtual void clearData();
490 :
491 : /** Should we keep the unfinished row in endLevel to initialize the table
492 : data in the following startLevel.
493 : */
494 0 : void setKeepUnfinishedRow(bool bKeep)
495 : {
496 0 : mbKeepUnfinishedRow = bKeep;
497 0 : }
498 :
499 :
500 : public:
501 : TableManager();
502 0 : virtual ~TableManager(){}
503 :
504 : /**
505 : Set handler for resolveCurrentTable.
506 :
507 : @param pTableDataHandler the handler
508 : */
509 : void setHandler(TableDataHandlerPointer_t pTableDataHandler);
510 :
511 : /**
512 : Set the current handle.
513 :
514 : @param rHandle the handle
515 : */
516 : virtual void handle(const T & rHandle);
517 :
518 : /**
519 : Start a new table level.
520 :
521 : A new context is pushed onto the table data stack,
522 : */
523 : virtual void startLevel();
524 :
525 : /**
526 : End a table level.
527 :
528 : The current table is resolved and the context is popped from
529 : the stack.
530 : */
531 : virtual void endLevel();
532 :
533 : /**
534 : * Signal that the next paragraph definitely won't be part of any table.
535 : */
536 0 : void endTable()
537 : {
538 0 : setRowEnd(false);
539 0 : }
540 :
541 : /**
542 : Tells whether a table has been started or not
543 : */
544 : bool isInTable();
545 :
546 : /**
547 : Handle the start of a paragraph group.
548 : */
549 : virtual void startParagraphGroup();
550 :
551 : /**
552 : Handle the end of a paragraph group.
553 : */
554 : virtual void endParagraphGroup();
555 :
556 : /**
557 : Handle an SPRM at curent handle.
558 :
559 : @param rSprm the SPRM
560 : */
561 : virtual bool sprm(Sprm & rSprm);
562 :
563 : /**
564 : Handle properties at current handle.
565 :
566 : @param pProps the properites
567 : */
568 : virtual void props(PropertiesPointer pProps);
569 :
570 : /**
571 : Handle occurrence of character 0x7.
572 : */
573 : virtual void handle0x7();
574 :
575 : /**
576 : Handle 8 bit text at current handle.
577 :
578 : @param data array of characters
579 : @param len number of characters to handle
580 : */
581 : virtual void text(const sal_uInt8 * data, size_t len);
582 :
583 : /**
584 : Handle 16 bit text at current handle.
585 :
586 : @param data array of characters
587 : @param len number of characters to handle
588 : */
589 : virtual void utext(const sal_uInt8 * data, size_t len);
590 :
591 : /**
592 : Handle properties of the current cell.
593 :
594 : @param pProps the properties
595 : */
596 : virtual void cellProps(PropertiesPointer pProps);
597 :
598 : /**
599 : Handle properties of a certain cell in the current row.
600 :
601 : @paran i index of the cell in the current row
602 : @param pProps the properties
603 : */
604 : virtual void cellPropsByCell(unsigned int i, PropertiesPointer pProps);
605 :
606 : /**
607 : Handle properties of the current row.
608 :
609 : @param pProps the properties
610 : */
611 : virtual void insertRowProps(PropertiesPointer pProps);
612 :
613 : /**
614 : Handle properties of the current table.
615 :
616 : @param pProps the properties
617 : */
618 : virtual void insertTableProps(PropertiesPointer pProps);
619 :
620 : /**
621 : Return if table manager has detected paragraph to ignore.
622 :
623 : If this function returns true the current paragraph contains
624 : only control information, e.g. end of row.
625 : */
626 : virtual bool isIgnore() const;
627 :
628 :
629 : #ifdef DEBUG_TABLE
630 : void setTagLogger(TagLogger::Pointer_t _tagLogger)
631 : {
632 : mpTableLogger = _tagLogger;
633 : }
634 : #endif
635 : };
636 :
637 : template <typename T, typename PropertiesPointer>
638 0 : TableManager<T, PropertiesPointer>::TableManager()
639 0 : : mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow( false )
640 : {
641 0 : setRowEnd(false);
642 0 : setInCell(false);
643 0 : setCellEnd(false);
644 0 : }
645 :
646 : template <typename T, typename PropertiesPointer>
647 0 : void TableManager<T, PropertiesPointer>::cellDepth(sal_uInt32 nDepth)
648 : {
649 : #ifdef DEBUG_TABLE
650 : if (mpTableLogger != NULL)
651 : {
652 : mpTableLogger->startElement("tablemanager.cellDepth");
653 : mpTableLogger->attribute("depth", nDepth);
654 : mpTableLogger->endElement();
655 : }
656 : #endif
657 :
658 0 : mnTableDepthNew = nDepth;
659 0 : }
660 :
661 : template <typename T, typename PropertiesPointer>
662 0 : void TableManager<T, PropertiesPointer>::inCell()
663 : {
664 : #ifdef DEBUG_TABLE
665 : if (mpTableLogger != NULL)
666 : mpTableLogger->element("tablemanager.inCell");
667 : #endif
668 0 : setInCell(true);
669 :
670 0 : if (mnTableDepthNew < 1)
671 0 : mnTableDepthNew = 1;
672 0 : }
673 :
674 : template <typename T, typename PropertiesPointer>
675 0 : void TableManager<T, PropertiesPointer>::endCell()
676 : {
677 : #ifdef DEBUG_TABLE
678 : if (mpTableLogger != NULL)
679 : mpTableLogger->element("tablemanager.endCell");
680 : #endif
681 :
682 0 : setCellEnd(true);
683 0 : }
684 :
685 : template <typename T, typename PropertiesPointer>
686 0 : void TableManager<T, PropertiesPointer>::endRow()
687 : {
688 : #ifdef DEBUG_TABLE
689 : if (mpTableLogger != NULL)
690 : mpTableLogger->element("tablemanager.endRow");
691 : #endif
692 :
693 0 : setRowEnd(true);
694 0 : }
695 :
696 : template <typename T, typename PropertiesPointer>
697 0 : void TableManager<T, PropertiesPointer>::setHandler
698 : (typename TableDataHandler<T, PropertiesPointer>::Pointer_t pTableDataHandler)
699 : {
700 0 : mpTableDataHandler = pTableDataHandler;
701 0 : }
702 :
703 : template <typename T, typename PropertiesPointer>
704 0 : void TableManager<T, PropertiesPointer>::handle(const T & rHandle)
705 : {
706 : #ifdef DEBUG_TABLE
707 : if (mpTableLogger)
708 : {
709 : mpTableLogger->startElement("tablemanager.handle");
710 : mpTableLogger->chars(toString(rHandle));
711 : mpTableLogger->endElement();
712 : }
713 : #endif
714 :
715 0 : setHandle(rHandle);
716 0 : }
717 :
718 : template <typename T, typename PropertiesPointer>
719 0 : bool TableManager<T, PropertiesPointer>::isInTable()
720 : {
721 0 : bool bInTable = false;
722 0 : if ( !mTableDataStack.empty() )
723 0 : bInTable = mTableDataStack.top()->getDepth() > 0;
724 0 : return bInTable;
725 : }
726 :
727 : template <typename T, typename PropertiesPointer>
728 0 : void TableManager<T, PropertiesPointer>::startLevel()
729 : {
730 : #ifdef DEBUG_TABLE
731 : if (mpTableLogger != NULL)
732 : {
733 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
734 :
735 : if (mTableDataStack.size() > 0)
736 : pTableData = mTableDataStack.top();
737 :
738 : mpTableLogger->startElement("tablemanager.startLevel");
739 : mpTableLogger->attribute("level", mTableDataStack.size());
740 :
741 : if (pTableData.get() != NULL)
742 : mpTableLogger->attribute("openCell",
743 : pTableData->isCellOpen() ? "yes" : "no");
744 :
745 : mpTableLogger->endElement();
746 : }
747 : #endif
748 :
749 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData
750 0 : (new TableData<T, PropertiesPointer>(mTableDataStack.size()));
751 :
752 : // If we have an unfinished row stored here, then push it to the new TableData
753 0 : if ( mpUnfinishedRow )
754 : {
755 0 : for (unsigned int i = 0; i < mpUnfinishedRow->getCellCount(); ++i)
756 : {
757 0 : pTableData->addCell( mpUnfinishedRow->getCellStart(i),
758 : mpUnfinishedRow->getCellProperties(i) );
759 0 : pTableData->endCell( mpUnfinishedRow->getCellEnd(i) );
760 : }
761 0 : mpUnfinishedRow.reset();
762 : }
763 :
764 0 : mTableDataStack.push(pTableData);
765 0 : mState.startLevel();
766 0 : }
767 :
768 : template <typename T, typename PropertiesPointer>
769 0 : void TableManager<T, PropertiesPointer>::endLevel()
770 : {
771 0 : if (mpTableDataHandler.get() != NULL)
772 0 : resolveCurrentTable();
773 :
774 : // Store the unfinished row as it will be used for the next table
775 0 : if ( mbKeepUnfinishedRow )
776 0 : mpUnfinishedRow = mTableDataStack.top()->getCurrentRow();
777 0 : mState.endLevel();
778 0 : mTableDataStack.pop();
779 :
780 : #ifdef DEBUG_TABLE
781 : if (mpTableLogger != NULL)
782 : {
783 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
784 :
785 : if (mTableDataStack.size() > 0)
786 : pTableData = mTableDataStack.top();
787 :
788 : mpTableLogger->startElement("tablemanager.endLevel");
789 : mpTableLogger->attribute("level", mTableDataStack.size());
790 :
791 : if (pTableData.get() != NULL)
792 : mpTableLogger->attribute("openCell",
793 : pTableData->isCellOpen() ? "yes" : "no");
794 :
795 : mpTableLogger->endElement();
796 : }
797 : #endif
798 0 : }
799 :
800 : template <typename T, typename PropertiesPointer>
801 0 : void TableManager<T, PropertiesPointer>::startParagraphGroup()
802 : {
803 0 : mState.resetCellSpecifics();
804 0 : mnTableDepthNew = 0;
805 0 : }
806 :
807 : template <typename T, typename PropertiesPointer>
808 0 : void TableManager<T, PropertiesPointer>::endParagraphGroup()
809 : {
810 0 : sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth;
811 :
812 0 : PropertiesPointer pEmptyProps;
813 :
814 0 : while (nTableDepthDifference > 0)
815 : {
816 0 : ensureOpenCell(pEmptyProps);
817 0 : startLevel();
818 :
819 0 : --nTableDepthDifference;
820 : }
821 0 : while (nTableDepthDifference < 0)
822 : {
823 0 : endLevel();
824 :
825 0 : ++nTableDepthDifference;
826 : }
827 :
828 0 : mnTableDepth = mnTableDepthNew;
829 :
830 0 : if (mnTableDepth > 0)
831 : {
832 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData =
833 0 : mTableDataStack.top();
834 :
835 0 : if (isRowEnd())
836 : {
837 0 : endOfRowAction();
838 0 : mTableDataStack.top()->endRow(getRowProps());
839 0 : resetRowProps();
840 : }
841 :
842 0 : else if (isInCell())
843 : {
844 0 : ensureOpenCell(getCellProps());
845 :
846 0 : if (isCellEnd())
847 : {
848 0 : endOfCellAction();
849 0 : closeCell(getHandle());
850 : }
851 : }
852 0 : resetCellProps();
853 0 : }
854 0 : }
855 :
856 : template <typename T, typename PropertiesPointer>
857 0 : bool TableManager<T, PropertiesPointer>::sprm(Sprm & rSprm)
858 : {
859 0 : bool bRet = true;
860 0 : switch (rSprm.getId())
861 : {
862 : case NS_ooxml::LN_tblDepth:
863 : {
864 0 : Value::Pointer_t pValue = rSprm.getValue();
865 :
866 0 : cellDepth(pValue->getInt());
867 : }
868 0 : break;
869 : case NS_ooxml::LN_inTbl:
870 0 : inCell();
871 0 : break;
872 : case NS_ooxml::LN_tblCell:
873 0 : endCell();
874 0 : break;
875 : case NS_ooxml::LN_tblRow:
876 0 : endRow();
877 0 : break;
878 : default:
879 0 : bRet = false;
880 : }
881 0 : return bRet;
882 : }
883 : template <typename T, typename PropertiesPointer>
884 0 : void TableManager<T, PropertiesPointer>::props(PropertiesPointer pProps)
885 : {
886 0 : setProps(pProps);
887 0 : }
888 :
889 : template <typename T, typename PropertiesPointer>
890 0 : void TableManager<T, PropertiesPointer>::handle0x7()
891 : {
892 : #ifdef DEBUG_TABLE
893 : if (mpTableLogger != NULL)
894 : mpTableLogger->startElement("tablemanager.handle0x7");
895 : #endif
896 :
897 0 : if (mnTableDepthNew < 1)
898 0 : mnTableDepthNew = 1;
899 :
900 0 : if (isInCell())
901 0 : endCell();
902 : else
903 0 : endRow();
904 :
905 : #ifdef DEBUG_TABLE
906 : if (mpTableLogger != NULL)
907 : mpTableLogger->endElement();
908 : #endif
909 0 : }
910 :
911 : template <typename T, typename PropertiesPointer>
912 0 : void TableManager<T, PropertiesPointer>::text(const sal_uInt8 * data, size_t len)
913 : {
914 : // optimization: cell/row end characters are the last characters in a run
915 0 : if (len > 0)
916 : {
917 0 : if (data[len - 1] == 0x7)
918 0 : handle0x7();
919 : }
920 0 : }
921 :
922 : template <typename T, typename PropertiesPointer>
923 0 : void TableManager<T, PropertiesPointer>::utext(const sal_uInt8 * data, size_t len)
924 : {
925 : // optimization: cell/row end characters are the last characters in a run
926 :
927 0 : if (len > 0)
928 : {
929 0 : sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8);
930 0 : if (nChar == 0x7)
931 0 : handle0x7();
932 : }
933 0 : }
934 :
935 : template <typename T, typename PropertiesPointer>
936 0 : void TableManager<T, PropertiesPointer>::cellProps(PropertiesPointer pProps)
937 : {
938 : #ifdef DEBUG_TABLE
939 : if (mpTableLogger != NULL)
940 : mpTableLogger->startElement("tablemanager.cellProps");
941 : #endif
942 :
943 0 : if(getCellProps().get())
944 0 : getCellProps()->InsertProps(pProps);
945 : else
946 0 : setCellProps(pProps);
947 :
948 : #ifdef DEBUG_TABLE
949 : if (mpTableLogger != NULL)
950 : mpTableLogger->endElement();
951 : #endif
952 0 : }
953 :
954 : template <typename T, typename PropertiesPointer>
955 0 : void TableManager<T, PropertiesPointer>::cellPropsByCell
956 : (unsigned int i, PropertiesPointer pProps)
957 : {
958 : #ifdef DEBUG_TABLE
959 : if (mpTableLogger != NULL)
960 : mpTableLogger->startElement("tablemanager.cellPropsByCell");
961 : #endif
962 :
963 0 : mTableDataStack.top()->insertCellProperties(i, pProps);
964 :
965 : #ifdef DEBUG_TABLE
966 : if (mpTableLogger != NULL)
967 : mpTableLogger->endElement();
968 : #endif
969 0 : }
970 :
971 : template <typename T, typename PropertiesPointer>
972 0 : void TableManager<T, PropertiesPointer>::insertRowProps(PropertiesPointer pProps)
973 : {
974 : #ifdef DEBUG_TABLE
975 : if (mpTableLogger != NULL)
976 : mpTableLogger->startElement("tablemanager.insertRowProps");
977 : #endif
978 :
979 0 : if( getRowProps().get() )
980 0 : getRowProps()->InsertProps(pProps);
981 : else
982 0 : setRowProps(pProps);
983 :
984 : #ifdef DEBUG_TABLE
985 : if (mpTableLogger != NULL)
986 : mpTableLogger->endElement();
987 : #endif
988 0 : }
989 :
990 : template <typename T, typename PropertiesPointer>
991 0 : void TableManager<T, PropertiesPointer>::insertTableProps(PropertiesPointer pProps)
992 : {
993 : #ifdef DEBUG_TABLE
994 : if (mpTableLogger != NULL)
995 : mpTableLogger->startElement("tablemanager.insertTableProps");
996 : #endif
997 :
998 0 : if( getTableProps().get() && getTableProps() != pProps)
999 0 : getTableProps()->InsertProps(pProps);
1000 : else
1001 0 : setTableProps(pProps);
1002 :
1003 : #ifdef DEBUG_TABLE
1004 : if (mpTableLogger != NULL)
1005 : mpTableLogger->endElement();
1006 : #endif
1007 0 : }
1008 :
1009 : template <typename T, typename PropertiesPointer>
1010 0 : void TableManager<T, PropertiesPointer>::resolveCurrentTable()
1011 : {
1012 : #ifdef DEBUG_TABLE
1013 : if (mpTableLogger != NULL)
1014 : mpTableLogger->startElement("tablemanager.resolveCurrentTable");
1015 : #endif
1016 :
1017 0 : if (mpTableDataHandler.get() != NULL)
1018 : {
1019 : try
1020 : {
1021 : typename TableData<T, PropertiesPointer>::Pointer_t
1022 0 : pTableData = mTableDataStack.top();
1023 :
1024 0 : unsigned int nRows = pTableData->getRowCount();
1025 :
1026 0 : mpTableDataHandler->startTable(nRows, pTableData->getDepth(), getTableProps());
1027 :
1028 0 : for (unsigned int nRow = 0; nRow < nRows; ++nRow)
1029 : {
1030 0 : typename RowData<T, PropertiesPointer>::Pointer_t pRowData = pTableData->getRow(nRow);
1031 :
1032 0 : unsigned int nCells = pRowData->getCellCount();
1033 :
1034 0 : mpTableDataHandler->startRow(nCells, pRowData->getProperties());
1035 :
1036 0 : for (unsigned int nCell = 0; nCell < nCells; ++nCell)
1037 : {
1038 0 : mpTableDataHandler->startCell
1039 : (pRowData->getCellStart(nCell),
1040 : pRowData->getCellProperties(nCell));
1041 :
1042 0 : mpTableDataHandler->endCell(pRowData->getCellEnd(nCell));
1043 : }
1044 :
1045 0 : mpTableDataHandler->endRow();
1046 : }
1047 :
1048 0 : mpTableDataHandler->endTable(mTableDataStack.size() - 1);
1049 : }
1050 0 : catch (uno::Exception const& e)
1051 : {
1052 : (void) e;
1053 : #if OSL_DEBUG_LEVEL > 0
1054 : SAL_WARN("writerfilter", "resolving of current table failed with: " << e.Message);
1055 : #endif
1056 : }
1057 : }
1058 0 : resetTableProps();
1059 0 : clearData();
1060 :
1061 : #ifdef DEBUG_TABLE
1062 : if (mpTableLogger != NULL)
1063 : mpTableLogger->endElement();
1064 : #endif
1065 0 : }
1066 :
1067 : template <typename T, typename PropertiesPointer>
1068 0 : void TableManager<T, PropertiesPointer>::endOfCellAction()
1069 : {
1070 0 : }
1071 :
1072 : template <typename T, typename PropertiesPointer>
1073 0 : void TableManager<T, PropertiesPointer>::endOfRowAction()
1074 : {
1075 0 : }
1076 :
1077 : template <typename T, typename PropertiesPointer>
1078 0 : bool TableManager<T, PropertiesPointer>::isIgnore() const
1079 : {
1080 0 : return isRowEnd();
1081 : }
1082 :
1083 : template <typename T, typename PropertiesPointer>
1084 0 : void TableManager<T, PropertiesPointer>::clearData()
1085 : {
1086 0 : }
1087 :
1088 : template <typename T, typename PropertiesPointer>
1089 0 : void TableManager<T, PropertiesPointer>::openCell
1090 : (const T & rHandle, PropertiesPointer pProps)
1091 : {
1092 : #ifdef DEBUG_TABLE
1093 : mpTableLogger->startElement("tablemanager.openCell");
1094 : mpTableLogger->chars(toString(rHandle));
1095 : mpTableLogger->endElement();
1096 : #endif
1097 :
1098 0 : if (mTableDataStack.size() > 0)
1099 : {
1100 : typename TableData<T, PropertiesPointer>::Pointer_t
1101 0 : pTableData = mTableDataStack.top();
1102 :
1103 0 : pTableData->addCell(rHandle, pProps);
1104 : }
1105 0 : }
1106 :
1107 : template <typename T, typename PropertiesPointer>
1108 0 : void TableManager<T, PropertiesPointer>::closeCell
1109 : (const T & rHandle)
1110 : {
1111 : #ifdef DEBUG_TABLE
1112 : mpTableLogger->startElement("tablemanager.closeCell");
1113 : mpTableLogger->chars(toString(rHandle));
1114 : mpTableLogger->endElement();
1115 : #endif
1116 :
1117 0 : if (mTableDataStack.size() > 0)
1118 : {
1119 : typename TableData<T, PropertiesPointer>::Pointer_t
1120 0 : pTableData = mTableDataStack.top();
1121 :
1122 0 : pTableData->endCell(rHandle);
1123 : }
1124 0 : }
1125 :
1126 : template <typename T, typename PropertiesPointer>
1127 0 : void TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProps)
1128 : {
1129 : #ifdef DEBUG_TABLE
1130 : mpTableLogger->startElement("tablemanager.ensureOpenCell");
1131 : #endif
1132 :
1133 0 : if (mTableDataStack.size() > 0)
1134 : {
1135 : typename TableData<T, PropertiesPointer>::Pointer_t
1136 0 : pTableData = mTableDataStack.top();
1137 :
1138 0 : if (pTableData.get() != NULL)
1139 : {
1140 0 : if (!pTableData->isCellOpen())
1141 0 : openCell(getHandle(), pProps);
1142 : else
1143 0 : pTableData->insertCellProperties(pProps);
1144 0 : }
1145 : }
1146 : #ifdef DEBUG_TABLE
1147 : mpTableLogger->endElement();
1148 : #endif
1149 0 : }
1150 :
1151 : }
1152 :
1153 : #endif // INCLUDED_TABLE_MANAGER_HXX
1154 :
1155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|