filters

kword/msword/document.h
1/* This file is part of the KOffice project
2 Copyright (C) 2002 Werner Trobin <trobin@kde.org>
3 Copyright (C) 2002 David Faure <faure@kde.org>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef DOCUMENT_H
21#define DOCUMENT_H
22
23#include "tablehandler.h"
24
25#include <wv2/handlers.h>
26#include <wv2/functor.h>
27
28#include <tqstring.h>
29#include <tqdom.h>
30#include <tqobject.h>
31#include <tqstringlist.h>
32
33#include <queue>
34#include <string>
35
36class KoStoreDevice;
37class KoSize;
38
39namespace wvWare {
40 class Parser;
41 namespace Word97 {
42 class BRC;
43 }
44}
45class KoRect;
46class KoFilterChain;
47class KWordReplacementHandler;
48class KWordTableHandler;
49class KWordPictureHandler;
50class KWordTextHandler;
51
52class Document : public TQObject, public wvWare::SubDocumentHandler
53{
54 TQ_OBJECT
55
56public:
57 Document( const std::string& fileName, TQDomDocument& mainDocument, TQDomDocument &documentInfo, TQDomElement& framesetsElement, KoFilterChain* chain );
58 virtual ~Document();
59
60 bool hasParser() const { return m_parser != 0L; }
61 bool bodyFound() const { return m_bodyFound; }
62
63 virtual void bodyStart();
64 virtual void bodyEnd();
65
66 virtual void headerStart( wvWare::HeaderData::Type type );
67 virtual void headerEnd();
68
69 virtual void footnoteStart();
70 virtual void footnoteEnd();
71
72 bool parse();
73
74 void processSubDocQueue();
75
76 void finishDocument();
77
78 typedef const wvWare::FunctorBase* FunctorPtr;
79 struct SubDocument
80 {
81 SubDocument( FunctorPtr ptr, int d, const TQString& n, const TQString& extra )
82 : functorPtr(ptr), data(d), name(n), extraName(extra) {}
83 ~SubDocument() {}
84 FunctorPtr functorPtr;
85 int data;
86 TQString name;
87 TQString extraName;
88 };
89
90 // Called by PictureHandler
91 KoStoreDevice* createPictureFrameSet( const KoSize& size );
92
93protected slots:
94 // Connected to the KWordTextHandler only when parsing the body
95 void slotFirstSectionFound( wvWare::SharedPtr<const wvWare::Word97::SEP> );
96
97 // Add to our parsing queue, for headers, footers, footnotes, text boxes etc.
98 // Note that a header functor will parse ALL the header/footers (of the section)
99 void slotSubDocFound( const wvWare::FunctorBase* functor, int data );
100
101 // Add to our parsing queue, for tables
102 void slotTableFound( const KWord::Table& table );
103
104 // Write out the frameset and add the key to the PICTURES tag
105 void slotPictureFound( const TQString& frameName, const TQString& pictureName, const wvWare::FunctorBase* );
106
107 // Similar to footnoteStart/footnoteEnd but for cells.
108 // This is connected to KWordTableHandler
109 void slotTableCellStart( int row, int column, int rowSize, int columnSize, const KoRect& cellRect, const TQString& tableName, const wvWare::Word97::BRC& brcTop, const wvWare::Word97::BRC& brcBottom, const wvWare::Word97::BRC& brcLeft, const wvWare::Word97::BRC& brcRight, const wvWare::Word97::SHD& shd );
110 void slotTableCellEnd();
111
112private:
113 void processStyles();
114 void processAssociatedStrings();
115 enum NewFrameBehavior { Reconnect=0, NoFollowup=1, Copy=2 };
116 TQDomElement createInitialFrame( TQDomElement& parentFramesetElem, double left, double right, double top, double bottom, bool autoExtend, NewFrameBehavior nfb );
117 void generateFrameBorder( TQDomElement& frameElementOut, const wvWare::Word97::BRC& brcTop, const wvWare::Word97::BRC& brcBottom, const wvWare::Word97::BRC& brcLeft, const wvWare::Word97::BRC& brcRight, const wvWare::Word97::SHD& shd );
118
119 TQDomDocument& m_mainDocument;
120 TQDomDocument& m_documentInfo;
121 TQDomElement& m_framesetsElement;
122 KWordReplacementHandler* m_replacementHandler;
123 KWordTableHandler* m_tableHandler;
124 KWordPictureHandler* m_pictureHandler;
125 KWordTextHandler* m_textHandler;
126 KoFilterChain* m_chain;
127 wvWare::SharedPtr<wvWare::Parser> m_parser;
128 std::queue<SubDocument> m_subdocQueue;
129 std::queue<KWord::Table> m_tableQueue;
130 TQStringList m_pictureList; // for <PICTURES>
131 unsigned char m_headerFooters; // a mask of HeaderData::Type bits
132 bool m_bodyFound;
133 int m_footNoteNumber; // number of footnote _framesets_ written out
134 int m_endNoteNumber; // number of endnote _framesets_ written out
135};
136
137#endif // DOCUMENT_H
This class hold a whole document with its headers, footers, footnotes, endnotes, content,...
virtual ~Document()
Destructor.