filters

document.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 DOCUMENT_H
00021 #define DOCUMENT_H
00022 
00023 #include "tablehandler.h"
00024 
00025 #include <wv2/handlers.h>
00026 #include <wv2/functor.h>
00027 
00028 #include <qstring.h>
00029 #include <qdom.h>
00030 #include <qobject.h>
00031 #include <qstringlist.h>
00032 
00033 #include <queue>
00034 #include <string>
00035 
00036 class KoStoreDevice;
00037 class KoSize;
00038 
00039 namespace wvWare {
00040     class Parser;
00041     namespace Word97 {
00042         class BRC;
00043     }
00044 }
00045 class KoRect;
00046 class KoFilterChain;
00047 class KWordReplacementHandler;
00048 class KWordTableHandler;
00049 class KWordPictureHandler;
00050 class KWordTextHandler;
00051 
00052 class Document : public QObject, public wvWare::SubDocumentHandler
00053 {
00054     Q_OBJECT
00055 public:
00056     Document( const std::string& fileName, QDomDocument& mainDocument, QDomDocument &documentInfo, QDomElement& framesetsElement, KoFilterChain* chain );
00057     virtual ~Document();
00058 
00059     bool hasParser() const { return m_parser != 0L; }
00060     bool bodyFound() const { return m_bodyFound; }
00061 
00062     virtual void bodyStart();
00063     virtual void bodyEnd();
00064 
00065     virtual void headerStart( wvWare::HeaderData::Type type );
00066     virtual void headerEnd();
00067 
00068     virtual void footnoteStart();
00069     virtual void footnoteEnd();
00070 
00071     bool parse();
00072 
00073     void processSubDocQueue();
00074 
00075     void finishDocument();
00076 
00077     typedef const wvWare::FunctorBase* FunctorPtr;
00078     struct SubDocument
00079     {
00080         SubDocument( FunctorPtr ptr, int d, const QString& n, const QString& extra )
00081             : functorPtr(ptr), data(d), name(n), extraName(extra) {}
00082         ~SubDocument() {}
00083         FunctorPtr functorPtr;
00084         int data;
00085         QString name;
00086         QString extraName;
00087     };
00088 
00089     // Called by PictureHandler
00090     KoStoreDevice* createPictureFrameSet( const KoSize& size );
00091 
00092 protected slots:
00093     // Connected to the KWordTextHandler only when parsing the body
00094     void slotFirstSectionFound( wvWare::SharedPtr<const wvWare::Word97::SEP> );
00095 
00096     // Add to our parsing queue, for headers, footers, footnotes, text boxes etc.
00097     // Note that a header functor will parse ALL the header/footers (of the section)
00098     void slotSubDocFound( const wvWare::FunctorBase* functor, int data );
00099 
00100     // Add to our parsing queue, for tables
00101     void slotTableFound( const KWord::Table& table );
00102 
00103     // Write out the frameset and add the key to the PICTURES tag
00104     void slotPictureFound( const QString& frameName, const QString& pictureName, const wvWare::FunctorBase* );
00105 
00106     // Similar to footnoteStart/footnoteEnd but for cells.
00107     // This is connected to KWordTableHandler
00108     void slotTableCellStart( int row, int column, int rowSize, int columnSize, const KoRect& cellRect, const QString& 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 );
00109     void slotTableCellEnd();
00110 
00111 private:
00112     void processStyles();
00113     void processAssociatedStrings();
00114     enum NewFrameBehavior { Reconnect=0, NoFollowup=1, Copy=2 };
00115     QDomElement createInitialFrame( QDomElement& parentFramesetElem, double left, double right, double top, double bottom, bool autoExtend, NewFrameBehavior nfb );
00116     void generateFrameBorder( QDomElement& 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 );
00117 
00118     QDomDocument& m_mainDocument;
00119     QDomDocument& m_documentInfo;
00120     QDomElement& m_framesetsElement;
00121     KWordReplacementHandler* m_replacementHandler;
00122     KWordTableHandler* m_tableHandler;
00123     KWordPictureHandler* m_pictureHandler;
00124     KWordTextHandler* m_textHandler;
00125     KoFilterChain* m_chain;
00126     wvWare::SharedPtr<wvWare::Parser> m_parser;
00127     std::queue<SubDocument> m_subdocQueue;
00128     std::queue<KWord::Table> m_tableQueue;
00129     QStringList m_pictureList; // for <PICTURES>
00130     unsigned char m_headerFooters; // a mask of HeaderData::Type bits
00131     bool m_bodyFound;
00132     int m_footNoteNumber; // number of footnote _framesets_ written out
00133     int m_endNoteNumber; // number of endnote _framesets_ written out
00134 };
00135 
00136 #endif // DOCUMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys