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