merge the formfield patch from ooo-build
[ooovba.git] / writerperfect / source / filter / DocumentCollector.hxx
blobc7219ebbcb01a543f03d5f22fda66411c6efe060
1 /* DocumentCollector: Collects sections and runs of text from a
2 * file (and styles to go along with them) and writes them
3 * to a target file
5 * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca)
6 * Copyright (C) 2003-2004 Net Integration Technologies (http://www.net-itech.com)
7 * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * For further information visit http://libwpd.sourceforge.net
27 /* "This product is not manufactured, approved, or supported by
28 * Corel Corporation or Corel Corporation Limited."
31 #ifndef _DOCUMENTCOLLECTOR_HXX
32 #define _DOCUMENTCOLLECTOR_HXX
33 #include "SectionStyle.hxx"
35 #if defined _MSC_VER
36 #pragma warning( push, 1 )
37 #endif
38 #include <libwps/libwps.h>
39 #include <libwpd/libwpd.h>
40 #if defined _MSC_VER
41 #pragma warning( pop )
42 #endif
43 #include <vector>
44 #include <map>
45 #include <stack>
46 #include <string.h>
48 class DocumentElement;
49 class DocumentHandler;
50 class TagOpenElement;
51 class FontStyle;
52 class ListStyle;
54 class ParagraphStyle;
55 class SpanStyle;
56 class TableStyle;
57 class PageSpan;
59 // the state we use for writing the final document
60 typedef struct _WriterDocumentState WriterDocumentState;
61 struct _WriterDocumentState
63 _WriterDocumentState();
65 bool mbFirstElement;
66 bool mbInFakeSection;
67 bool mbListElementOpenedAtCurrentLevel;
68 bool mbTableCellOpened;
69 bool mbHeaderRow;
70 bool mbInNote;
73 enum WriterListType { unordered, ordered };
75 struct ltstr
77 bool operator()(const WPXString & s1, const WPXString & s2) const
79 return strcmp(s1.cstr(), s2.cstr()) < 0;
83 class DocumentCollector : public WPXHLListenerImpl
85 public:
86 DocumentCollector(WPSInputStream *pInput, DocumentHandler *pHandler);
87 virtual ~DocumentCollector();
88 bool filter();
90 virtual void setDocumentMetaData(const WPXPropertyList & /* propList */) {}
91 virtual void startDocument() {}
92 virtual void endDocument() {}
94 virtual void openPageSpan(const WPXPropertyList &propList);
95 virtual void closePageSpan() {}
97 virtual void openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns);
98 virtual void closeSection();
100 virtual void openHeader(const WPXPropertyList &propList);
101 virtual void closeHeader();
102 virtual void openFooter(const WPXPropertyList &propList);
103 virtual void closeFooter();
105 virtual void openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops);
106 virtual void closeParagraph();
108 virtual void openSpan(const WPXPropertyList &propList);
109 virtual void closeSpan();
112 virtual void insertTab();
113 virtual void insertText(const WPXString &text);
114 virtual void insertLineBreak();
116 virtual void defineOrderedListLevel(const WPXPropertyList &propList);
117 virtual void defineUnorderedListLevel(const WPXPropertyList &propList);
118 virtual void openOrderedListLevel(const WPXPropertyList &propList);
119 virtual void openUnorderedListLevel(const WPXPropertyList &propList);
120 virtual void closeOrderedListLevel();
121 virtual void closeUnorderedListLevel();
122 virtual void openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops);
123 virtual void closeListElement();
125 virtual void openFootnote(const WPXPropertyList &propList);
126 virtual void closeFootnote();
127 virtual void openEndnote(const WPXPropertyList &propList);
128 virtual void closeEndnote();
130 virtual void openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns);
131 virtual void openTableRow(const WPXPropertyList &propList);
132 virtual void closeTableRow();
133 virtual void openTableCell(const WPXPropertyList &propList);
134 virtual void closeTableCell();
135 virtual void insertCoveredTableCell(const WPXPropertyList &propList);
136 virtual void closeTable();
137 virtual bool parseSourceDocument(WPSInputStream &input) = 0;
139 protected:
140 void _resetDocumentState();
141 bool _writeTargetDocument(DocumentHandler *pHandler);
142 void _writeDefaultStyles(DocumentHandler *pHandler);
143 void _writeMasterPages(DocumentHandler *pHandler);
144 void _writePageMasters(DocumentHandler *pHandler);
145 void _allocateFontName(const WPXString &);
147 private:
148 void _openListLevel(TagOpenElement *pListLevelOpenElement);
149 void _closeListLevel(const char *szListType);
151 WPSInputStream *mpInput;
152 DocumentHandler *mpHandler;
153 bool mbUsed; // whether or not it has been before (you can only use me once!)
155 WriterDocumentState mWriterDocumentState;
157 // paragraph styles
158 std::map<WPXString, ParagraphStyle *, ltstr> mTextStyleHash;
160 // span styles
161 std::map<WPXString, SpanStyle *, ltstr> mSpanStyleHash;
163 // font styles
164 std::map<WPXString, FontStyle *, ltstr> mFontHash;
166 // section styles
167 std::vector<SectionStyle *> mSectionStyles;
168 float mfSectionSpaceAfter;
170 // table styles
171 std::vector<TableStyle *> mTableStyles;
173 // list styles
174 unsigned int miNumListStyles;
176 // style elements
177 std::vector<DocumentElement *> mStylesElements;
178 // content elements
179 std::vector<DocumentElement *> mBodyElements;
180 // the current set of elements that we're writing to
181 std::vector<DocumentElement *> * mpCurrentContentElements;
183 // page state
184 std::vector<PageSpan *> mPageSpans;
185 PageSpan *mpCurrentPageSpan;
186 int miNumPageStyles;
188 // list styles / state
189 ListStyle *mpCurrentListStyle;
190 unsigned int miCurrentListLevel;
191 unsigned int miLastListLevel;
192 unsigned int miLastListNumber;
193 std::vector<ListStyle *> mListStyles;
194 bool mbListContinueNumbering;
195 bool mbListElementOpened;
196 bool mbListElementParagraphOpened;
198 // table state
199 TableStyle *mpCurrentTableStyle;
202 #endif