filters

texthandler.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 TEXTHANDLER_H
21#define TEXTHANDLER_H
22
23#include "tablehandler.h"
24#include "versionmagic.h"
25
26#include <wv2/handlers.h>
27#include <tqstring.h>
28#include <tqobject.h>
29#include <tqdom.h>
30
31#include <string>
32
33namespace wvWare {
34 class Style;
35 class Parser;
36 class FunctorBase;
37 namespace Word97 {
38 class PAP;
39 }
40}
41
42class KWordReplacementHandler : public wvWare::InlineReplacementHandler
43{
44public:
45 virtual wvWare::U8 hardLineBreak();
46 virtual wvWare::U8 nonBreakingHyphen();
47 virtual wvWare::U8 nonRequiredHyphen();
48};
49
50
51class KWordTextHandler : public TQObject, public wvWare::TextHandler
52{
53 TQ_OBJECT
54
55public:
56 KWordTextHandler( wvWare::SharedPtr<wvWare::Parser> parser );
57
58 void setFrameSetElement( const TQDomElement& frameset );
59
61
62 virtual void sectionStart( wvWare::SharedPtr<const wvWare::Word97::SEP> sep );
63 virtual void sectionEnd();
64 virtual void pageBreak();
65 virtual void headersFound( const wvWare::HeaderFunctor& parseHeaders );
66 virtual void footnoteFound( wvWare::FootnoteData::Type type, wvWare::UChar character,
67 wvWare::SharedPtr<const wvWare::Word97::CHP> chp, const wvWare::FootnoteFunctor& parseFootnote );
68
69 virtual void paragraphStart( wvWare::SharedPtr<const wvWare::ParagraphProperties> paragraphProperties );
70 virtual void paragraphEnd();
71 virtual void fieldStart( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
72 virtual void fieldSeparator( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
73 virtual void fieldEnd( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
74 virtual void runOfText( const wvWare::UString& text, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
75
76 virtual void tableRowFound( const wvWare::TableRowFunctor& functor, wvWare::SharedPtr<const wvWare::Word97::TAP> tap );
77
78#ifdef IMAGE_IMPORT
79 virtual void pictureFound( const wvWare::PictureFunctor& picture, wvWare::SharedPtr<const wvWare::Word97::PICF> picf,
80 wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
81#endif // IMAGE_IMPORT
83
84 // Called at the beginning of a parag/style
85 void paragLayoutBegin();
86
87 // Write a <FORMAT> tag from the given CHP
88 // Returns that element into pChildElement if set (in that case even an empty FORMAT can be appended)
89 void writeFormat( TQDomElement& parentElement, const wvWare::Word97::CHP* chp, const wvWare::Word97::CHP* refChp, int pos, int len, int formatId, TQDomElement* pChildElement );
90
91 // Write the _contents_ (children) of a <LAYOUT> or <STYLE> tag, from the given parag props
92 void writeLayout( TQDomElement& parentElement, const wvWare::ParagraphProperties& paragraphProperties, const wvWare::Style* style );
93
94 // Communication with Document, without having to know about Document
95signals:
96 void firstSectionFound( wvWare::SharedPtr<const wvWare::Word97::SEP> );
97 void subDocFound( const wvWare::FunctorBase* parsingFunctor, int data );
98 void tableFound( const KWord::Table& table );
99 void pictureFound( const TQString& frameName, const TQString& pictureName, const wvWare::FunctorBase* pictureFunctor );
100
101protected:
102 void writeOutParagraph( const TQString& styleName, const TQString& text );
103 void writeCounter( TQDomElement& parentElement, const wvWare::ParagraphProperties& paragraphProperties, const wvWare::Style* style );
104 TQDomElement insertVariable( int type, wvWare::SharedPtr<const wvWare::Word97::CHP> chp, const TQString& format );
105 TQDomElement insertAnchor( const TQString& fsname );
106 TQString getFont(unsigned fc) const;
107 TQDomDocument mainDocument() const;
108
109private:
110 wvWare::SharedPtr<wvWare::Parser> m_parser;
111 TQString m_listSuffixes[9]; // The suffix for every list level seen so far
112 TQDomElement m_framesetElement;
113 int m_sectionNumber;
114 int m_footNoteNumber; // number of footnote _vars_ written out
115 int m_endNoteNumber; // number of endnote _vars_ written out
116 int m_previousOutlineLSID; // The list id of the previous outline-list item
117 int m_previousEnumLSID; // The list id of the previous enum-list item
118
119 // Current paragraph
120 TQString m_paragraph;
121 const wvWare::Style* m_currentStyle;
122 wvWare::SharedPtr<const wvWare::ParagraphProperties> m_paragraphProperties;
123 enum { NoShadow, Shadow, Imprint } m_shadowTextFound;
124 int m_index;
125 TQDomElement m_formats;
126 TQDomElement m_oldLayout;
127
128 KWord::Table* m_currentTable;
129 bool m_bInParagraph;
130
131 TQString m_fieldValue;
132 bool m_insideField;
133 bool m_fieldAfterSeparator;
134 int m_fieldType; // 0 for no field
135};
136
137#endif // TEXTHANDLER_H