filters

oowriterimport.h
1/* This file is part of the KDE project
2 Copyright (C) 2002 Laurent Montel <lmontel@mandrakesoft.com>
3 Copyright (C) 2003 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef OoWriter_IMPORT_H__
22#define OoWriter_IMPORT_H__
23
24#include <KoFilter.h>
25
26#include <tqdict.h>
27#include <tqdom.h>
28#include <KoStyleStack.h>
29#include <liststylestack.h>
30
31class KZip;
32
33class OoWriterImport : public KoFilter
34{
35 TQ_OBJECT
36
37public:
38 OoWriterImport( KoFilter * parent, const char * name, const TQStringList & );
39 virtual ~OoWriterImport();
40
41 virtual KoFilter::ConversionStatus convert( TQCString const & from, TQCString const & to );
42
43private:
44 void prepareDocument( TQDomDocument& mainDocument, TQDomElement& framesetsElem );
45 void finishDocumentContent( TQDomDocument& mainDocument );
46 void writePageLayout( TQDomDocument& mainDocument, const TQString& masterPageName );
47 void parseList( TQDomDocument& doc, const TQDomElement& list, TQDomElement& currentFramesetElement );
48 bool pushListLevelStyle( const TQString& listStyleName, int level );
49 bool pushListLevelStyle( const TQString& listStyleName, TQDomElement& fullListStyle, int level );
50 void applyListStyle( TQDomDocument& doc, TQDomElement& layoutElement, const TQDomElement& paragraph );
51 void writeCounter( TQDomDocument& doc, TQDomElement& layoutElement, bool heading, int level, bool ordered );
52 TQDomElement parseParagraph( TQDomDocument& doc, const TQDomElement& paragraph );
53 void parseSpanOrSimilar( TQDomDocument& doc, const TQDomElement& parent, TQDomElement& kwordParagraph, TQDomElement& kwordFormats, TQString& paragraphText, uint& pos);
54 // Reads from m_styleStack, writes the text properties to parentElement
55 void writeFormat( TQDomDocument& doc, TQDomElement& parentElement, int id, int pos, int length );
56 // Reads from m_styleStack, writes the paragraph properties to layoutElement
57 void writeLayout( TQDomDocument& doc, TQDomElement& layoutElement );
58 enum NewFrameBehavior { Reconnect=0, NoFollowup=1, Copy=2 };
59 TQDomElement createInitialFrame( TQDomElement& parentFramesetElem, double left, double right, double top, double bottom, bool autoExtend, NewFrameBehavior nfb );
60 void createStyles( TQDomDocument &doc );
61 void createDocumentInfo( TQDomDocument &docinfo );
62 void createDocumentContent( TQDomDocument &doccontent, TQDomElement& mainFramesetElement );
63 void parseBodyOrSimilar( TQDomDocument &doc, const TQDomElement& parent, TQDomElement& currentFramesetElement );
64 KoFilter::ConversionStatus loadAndParse(const TQString& filename, TQDomDocument& doc);
65 KoFilter::ConversionStatus openFile();
66 bool createStyleMap( const TQDomDocument & styles, TQDomDocument& doc );
67 void insertStyles( const TQDomElement& element, TQDomDocument& doc );
68 void importDateTimeStyle( const TQDomElement& parent );
69 void fillStyleStack( const TQDomElement& object, const char* nsURI, const TQString& attrName );
70 void addStyles( const TQDomElement* style );
71 void importFootnotesConfiguration( TQDomDocument& doc, const TQDomElement& elem, bool endnote );
72 void importFootnote( TQDomDocument& doc, const TQDomElement& object, TQDomElement& formats, uint pos, const TQString& tagName );
73 TQString appendPicture( TQDomDocument& doc, const TQDomElement& object );
74 TQString appendTextBox( TQDomDocument& doc, const TQDomElement& object );
75 void appendTOC( TQDomDocument& doc, const TQDomElement& toc );
76 void importFrame( TQDomElement& frameElementOut, const TQDomElement& object, bool isText );
77 void importCommonFrameProperties( TQDomElement& frameElementOut );
78 void importHeaderFooter( TQDomDocument& doc, const TQDomElement& headerFooter, bool isHeader, TQDomElement& style );
79 void anchorFrameset( TQDomDocument& doc, TQDomElement& formats, uint pos, const TQString& frameName );
80 void appendField(TQDomDocument& doc, TQDomElement& outputFormats, TQDomElement& object, uint pos);
81 void appendKWordVariable(TQDomDocument& doc, TQDomElement& formats, const TQDomElement& object, uint pos,
82 const TQString& key, int type, TQDomElement& child);
83 void appendBookmark( TQDomDocument& doc, int paragId, int pos, const TQString& name );
84 void appendBookmark( TQDomDocument& doc, int paragId, int pos, int endParagId, int endPos, const TQString& name );
85 void parseTable( TQDomDocument &doc, const TQDomElement& parent, TQDomElement& currentFramesetElement );
86 void parseInsideOfTable( TQDomDocument &doc, const TQDomElement& parent, TQDomElement& currentFramesetElement,
87 const TQString& tableName, const TQMemArray<double> & columnLefts, uint& row, uint& column );
88 static TQString kWordStyleName( const TQString& ooStyleName );
89
90 TQDomDocument m_content;
91 TQDomDocument m_meta;
92 TQDomDocument m_settings;
93 TQDomDocument m_stylesDoc;
94
95 TQDict<TQDomElement> m_styles;
96 TQDict<TQDomElement> m_masterPages;
97 TQDict<TQDomElement> m_listStyles;
98
99 KoStyleStack m_styleStack;
100 TQDomElement m_defaultStyle;
101 ListStyleStack m_listStyleStack;
102 TQDomElement m_outlineStyle;
103 bool m_insideOrderedList;
104 bool m_nextItemIsListItem; // only the first elem inside list-item is numbered
105 bool m_hasTOC;
106 bool m_hasHeader;
107 bool m_hasFooter;
108 int m_restartNumbering;
109 TQString m_currentListStyleName;
110 TQString m_currentMasterPage;
111 TQDomElement m_currentFrameset; // set by parseBodyOrSimilar
112
113 struct BookmarkStart {
114 BookmarkStart() {} // for stupid TQValueList
115 BookmarkStart( const TQString&s, int par, int ind )
116 : frameSetName( s ), paragId( par ), pos( ind ) {}
117 TQString frameSetName;
118 int paragId;
119 int pos;
120 };
121 typedef TQMap<TQString, BookmarkStart> BookmarkStartsMap;
122 BookmarkStartsMap m_bookmarkStarts;
123
124 typedef TQMap<TQString, TQString> DataFormatsMap;
125 DataFormatsMap m_dateTimeFormats; // maybe generalize to include number formats.
126
127 uint m_pictureNumber; // Number of the picture (increment *before* use)
128 KZip* m_zip; // Input KZip file
129};
130
131#endif
132