/* This file is part of the KDE project Copyright (C) 2004 Nicolas GOUTTE This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KWORD_1_3_PARSER_H #define KWORD_1_3_PARSER_H #include #include class KWord13Paragraph; class KWord13Document; class KWord13Frameset; class KWord13Layout; class KWord13Format; /** * Type of element * * Note: we do not care of the tags: \, \ */ enum KWord13StackItemType { KWord13TypeUnknown = 0, KWord13TypeBottom, ///< Bottom of the stack KWord13TypeIgnore, ///< Element is known but ignored KWord13TypeEmpty, ///< Element is empty KWord13TypeDocument, ///< Element is the document ( \ ) KWord13TypePaper, ///< \ KWord13TypeFrameset, ///< \ (with exceptions) KWord13TypeUnknownFrameset, ///< a \ which is not supported KWord13TypeParagraph, ///< \ KWord13TypeText, ///< \ KWord13TypeLayout, ///< \ and \ KWord13TypeFormat, ///< \, child of \ KWord13TypeLayoutFormatOne,///< \ as child of \ KWord13TypeFormatsPlural,///< \, as child of \ KWord13TypeVariable, ///< \ or \ KWord13TypePicturesPlural, ///< \, \ or \ KWord13TypePictureFrameset, ///< \ (picture, image, clipart) KWord13TypePicture, ///< \, \ or \ KWord13TypeAnchor ///< \ }; class KWord13StackItem { public: KWord13StackItem(); ~KWord13StackItem(); public: TQString itemName; ///< Name of the tag (only for error purposes) KWord13StackItemType elementType; KWord13Frameset* m_currentFrameset; }; class KWord13StackItemStack : public TQPtrStack { public: KWord13StackItemStack(void) { } ~KWord13StackItemStack(void) { } }; class KWord13Parser : public TQXmlDefaultHandler { public: KWord13Parser( KWord13Document* kwordDocument ); virtual ~KWord13Parser( void ); protected: //TQXml /// Process opening tag virtual bool startElement( const TQString&, const TQString&, const TQString& name, const TQXmlAttributes& attributes); /// Process closing tag virtual bool endElement( const TQString&, const TQString& , const TQString& qName); /// Process element's characters (between opening and closing tags) virtual bool characters ( const TQString & ch ); virtual bool warning(const TQXmlParseException& exception); virtual bool error(const TQXmlParseException& exception); virtual bool fatalError(const TQXmlParseException& exception); protected: /// Process children of \ bool startElementFormatOneProperty( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem); /// Process children of \ (with exceptions) bool startElementLayoutProperty( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem); /// Process \ bool startElementName( const TQString&, const TQXmlAttributes& attributes, KWord13StackItem *stackItem ); /// Process \ bool startElementFormat( const TQString&, const TQXmlAttributes& attributes, KWord13StackItem *stackItem ); /// Process \ and \ bool startElementLayout( const TQString&, const TQXmlAttributes&, KWord13StackItem *stackItem ); /// Process \ bool startElementParagraph( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem ); /// Process \ bool startElementFrame( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem ); /// Process \ bool startElementFrameset( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem ); /// Process opening tag of some elements that are children of \ and which only define document properties bool startElementDocumentAttributes( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem, const KWord13StackItemType& allowedParentType, const KWord13StackItemType& newType ); /// Process \ bool startElementKey( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem ); /// Process \ bool startElementAnchor( const TQString& name, const TQXmlAttributes& attributes, KWord13StackItem *stackItem ); /** * Get a picture key out of the individual \ attributes * * \note The generated key is different that one of the class KoPictureKey */ TQString calculatePictureKey( const TQString& filename, const TQString& year, const TQString& month, const TQString& day, const TQString& hour, const TQString& minute, const TQString& second, const TQString& microsecond ) const; protected: TQString indent; //DEBUG KWord13StackItemStack parserStack; KWord13Document* m_kwordDocument; KWord13Paragraph* m_currentParagraph; ///< Current paragraph KWord13Layout* m_currentLayout; ///< Current layout (or style) KWord13Format* m_currentFormat; ///< Current format }; #endif // KWORD_1_3_PARSER_H