filters

texthandler.h

00001 /* This file is part of the KOffice project
00002    Copyright (C) 2002 Werner Trobin <trobin@kde.org>
00003    Copyright (C) 2002 David Faure <faure@kde.org>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef TEXTHANDLER_H
00021 #define TEXTHANDLER_H
00022 
00023 #include "tablehandler.h"
00024 #include "versionmagic.h"
00025 
00026 #include <wv2/handlers.h>
00027 #include <qstring.h>
00028 #include <qobject.h>
00029 #include <qdom.h>
00030 
00031 #include <string>
00032 
00033 namespace wvWare {
00034     class Style;
00035     class Parser;
00036     class FunctorBase;
00037     namespace Word97 {
00038         class PAP;
00039     }
00040 }
00041 
00042 class KWordReplacementHandler : public wvWare::InlineReplacementHandler
00043 {
00044 public:
00045     virtual wvWare::U8 hardLineBreak();
00046     virtual wvWare::U8 nonBreakingHyphen();
00047     virtual wvWare::U8 nonRequiredHyphen();
00048 };
00049 
00050 
00051 class KWordTextHandler : public QObject, public wvWare::TextHandler
00052 {
00053     Q_OBJECT
00054 public:
00055     KWordTextHandler( wvWare::SharedPtr<wvWare::Parser> parser );
00056 
00057     void setFrameSetElement( const QDomElement& frameset );
00058 
00060 
00061     virtual void sectionStart( wvWare::SharedPtr<const wvWare::Word97::SEP> sep );
00062     virtual void sectionEnd();
00063     virtual void pageBreak();
00064     virtual void headersFound( const wvWare::HeaderFunctor& parseHeaders );
00065     virtual void footnoteFound( wvWare::FootnoteData::Type type, wvWare::UChar character,
00066                                 wvWare::SharedPtr<const wvWare::Word97::CHP> chp, const wvWare::FootnoteFunctor& parseFootnote );
00067 
00068     virtual void paragraphStart( wvWare::SharedPtr<const wvWare::ParagraphProperties> paragraphProperties );
00069     virtual void paragraphEnd();
00070     virtual void fieldStart( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
00071     virtual void fieldSeparator( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
00072     virtual void fieldEnd( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
00073     virtual void runOfText( const wvWare::UString& text, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
00074 
00075     virtual void tableRowFound( const wvWare::TableRowFunctor& functor, wvWare::SharedPtr<const wvWare::Word97::TAP> tap );
00076 
00077 #ifdef IMAGE_IMPORT
00078     virtual void pictureFound( const wvWare::PictureFunctor& picture, wvWare::SharedPtr<const wvWare::Word97::PICF> picf,
00079                                wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
00080 #endif // IMAGE_IMPORT
00081 
00082 
00083     // Called at the beginning of a parag/style
00084     void paragLayoutBegin();
00085 
00086     // Write a <FORMAT> tag from the given CHP
00087     // Returns that element into pChildElement if set (in that case even an empty FORMAT can be appended)
00088     void writeFormat( QDomElement& parentElement, const wvWare::Word97::CHP* chp, const wvWare::Word97::CHP* refChp, int pos, int len, int formatId, QDomElement* pChildElement );
00089 
00090     // Write the _contents_ (children) of a <LAYOUT> or <STYLE> tag, from the given parag props
00091     void writeLayout( QDomElement& parentElement, const wvWare::ParagraphProperties& paragraphProperties, const wvWare::Style* style );
00092 
00093     // Communication with Document, without having to know about Document
00094 signals:
00095     void firstSectionFound( wvWare::SharedPtr<const wvWare::Word97::SEP> );
00096     void subDocFound( const wvWare::FunctorBase* parsingFunctor, int data );
00097     void tableFound( const KWord::Table& table );
00098     void pictureFound( const QString& frameName, const QString& pictureName, const wvWare::FunctorBase* pictureFunctor );
00099 
00100 protected:
00101     void writeOutParagraph( const QString& styleName, const QString& text );
00102     void writeCounter( QDomElement& parentElement, const wvWare::ParagraphProperties& paragraphProperties, const wvWare::Style* style );
00103     QDomElement insertVariable( int type, wvWare::SharedPtr<const wvWare::Word97::CHP> chp, const QString& format );
00104     QDomElement insertAnchor( const QString& fsname );
00105     QString getFont(unsigned fc) const;
00106     QDomDocument mainDocument() const;
00107 
00108 private:
00109     wvWare::SharedPtr<wvWare::Parser> m_parser;
00110     QString m_listSuffixes[9]; // The suffix for every list level seen so far
00111     QDomElement m_framesetElement;
00112     int m_sectionNumber;
00113     int m_footNoteNumber; // number of footnote _vars_ written out
00114     int m_endNoteNumber; // number of endnote _vars_ written out
00115     int m_previousOutlineLSID; // The list id of the previous outline-list item
00116     int m_previousEnumLSID; // The list id of the previous enum-list item
00117 
00118     // Current paragraph
00119     QString m_paragraph;
00120     const wvWare::Style* m_currentStyle;
00121     wvWare::SharedPtr<const wvWare::ParagraphProperties> m_paragraphProperties;
00122     enum { NoShadow, Shadow, Imprint } m_shadowTextFound;
00123     int m_index;
00124     QDomElement m_formats;
00125     QDomElement m_oldLayout;
00126 
00127     KWord::Table* m_currentTable;
00128     bool m_bInParagraph;
00129 
00130     QString m_fieldValue;
00131     bool m_insideField;
00132     bool m_fieldAfterSeparator;
00133     int m_fieldType; // 0 for no field
00134 };
00135 
00136 #endif // TEXTHANDLER_H
KDE Home | KDE Accessibility Home | Description of Access Keys