libwpd: WP6ContentListener.h Source File documentation

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

# WP6ContentListener.h

Go to the documentation of this file.

    00001 /* libwpd
    00002  * Copyright (C) 2002 William Lachance (william.lachance@sympatico.ca)
    00003  * Copyright (C) 2002 Marc Maurer (j.m.maurer@student.utwente.nl)
    00004  * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU Library General Public
    00008  * License as published by the Free Software Foundation; either
    00009  * version 2 of the License, or (at your option) any later version.
    00010  *
    00011  * This library is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  * Library General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU Library General Public
    00017  * License along with this library; if not, write to the Free Software
    00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
    00019  *
    00020  * For further information visit http://libwpd.sourceforge.net
    00021  */
    00022
    00023 /* "This product is not manufactured, approved, or supported by
    00024  * Corel Corporation or Corel Corporation Limited."
    00025  */
    00026
    00027 #ifndef WP6CONTENTLISTENER_H
    00028 #define WP6CONTENTLISTENER_H
    00029
    00030 #include "WP6Listener.h"
    00031 #include "WPXListener.h"
    00032 #include "WP6FileStructure.h"
    00033
    00034 #include <stack>
    00035 #include <map>
    00036 #include <vector>
    00037
    00038 class WPXHLListenerImpl;
    00039 class WP6LLParser;
    00040 class WPXTable;
    00041
    00042 enum WP6StyleState { NORMAL, DOCUMENT_NOTE, DOCUMENT_NOTE_GLOBAL,
    00043                      BEGIN_BEFORE_NUMBERING,
    00044                      BEGIN_NUMBERING_BEFORE_DISPLAY_REFERENCING,
    00045                      DISPLAY_REFERENCING,
    00046                      BEGIN_NUMBERING_AFTER_DISPLAY_REFERENCING,
    00047                      BEGIN_AFTER_NUMBERING, STYLE_BODY, STYLE_END };
    00048
    00049 enum WP6ListType { ORDERED, UNORDERED };
    00050
    00051 const int STATE_MEMORY = 3;
    00052 class WP6StyleStateSequence
    00053 {
    00054 public:
    00055         WP6StyleStateSequence() { clear(); }
    00056         void setCurrentState(WP6StyleState state) { for (int i=(STATE_MEMORY-1); i>0; i--) m_stateSequence[i] = m_stateSequence[i-1]; m_stateSequence[0]=state; }
    00057         const WP6StyleState getCurrentState() const { return m_stateSequence[0]; /*currentState;*/ }
    00058         const WP6StyleState getPreviousState() const { return m_stateSequence[1]; /*m_previousState;*/ }
    00059         void clear() { m_stateSequence.clear(); for (int i=0; i<STATE_MEMORY; i++) m_stateSequence.push_back(NORMAL); }
    00060
    00061 private:
    00062         std::vector<WP6StyleState> m_stateSequence;
    00063         WP6StyleState m_currentState;
    00064         WP6StyleState m_previousState;
    00065 };
    00066
    00067 typedef struct _WP6ParsingState WP6ParsingState;
    00068 struct _WP6ParsingState
    00069 {
    00070         _WP6ParsingState(WPXTableList tableList, int nextTableIndice = 0);
    00071         ~_WP6ParsingState();
    00072         WPXString m_bodyText;
    00073         WPXString m_textBeforeNumber;
    00074         WPXString m_textBeforeDisplayReference;
    00075         WPXString m_numberText;
    00076         WPXString m_textAfterDisplayReference;
    00077         WPXString m_textAfterNumber;
    00078
    00079         float m_paragraphMarginBottomRelative;
    00080         float m_paragraphMarginBottomAbsolute;
    00081
    00082         int m_numRemovedParagraphBreaks;
    00083
    00084         int m_numListExtraTabs;
    00085         bool m_isListReference;
    00086
    00087         WPXTableList m_tableList;
    00088         WPXTable *m_currentTable;
    00089         int m_nextTableIndice;
    00090
    00091         std::stack<int> m_listLevelStack;
    00092         std::stack<WP6ListType> m_listTypeStack;
    00093         uint16_t m_currentOutlineHash; // probably should replace Hash with Key in these sorts of cases
    00094         uint8_t m_oldListLevel;
    00095         WP6StyleStateSequence m_styleStateSequence;
    00096         bool m_putativeListElementHasParagraphNumber;
    00097         bool m_putativeListElementHasDisplayReferenceNumber;
    00098
    00099         int m_noteTextPID;
    00100
    00101         uint16_t m_leaderCharacter;
    00102         uint8_t m_leaderNumSpaces;
    00103         std::vector<WPXTabStop> m_tempTabStops;
    00104         std::vector<bool> m_tempUsePreWP9LeaderMethod;
    00105 };
    00106
    00107 struct _WP6ListLevel
    00108 {
    00109         int m_level;
    00110         bool m_isListElementOpenAtLevel;
    00111 };
    00112
    00113 class WP6OutlineDefinition
    00114 {
    00115  public:
    00116         WP6OutlineDefinition();
    00117         WP6OutlineDefinition(const WP6OutlineLocation outlineLocation, const uint8_t *numberingMethods,
    00118                           const uint8_t tabBehaviourFlag);
    00119         void update(const uint8_t *numberingMethods, const uint8_t tabBehaviourFlag);
    00120
    00121         WPXNumberingType getListType(int level) { return m_listTypes[level]; }
    00122
    00123 protected:
    00124         void _updateNumberingMethods(const WP6OutlineLocation outlineLocation, const uint8_t *numberingMethods);
    00125
    00126 private:
    00127         WPXNumberingType m_listTypes[WP6_NUM_LIST_LEVELS];
    00128 };
    00129
    00130 class WP6ContentListener : public WP6Listener
    00131 {
    00132 public:
    00133         WP6ContentListener(std::vector<WPXPageSpan *> *pageList, WPXTableList tableList, WPXHLListenerImpl *listenerImpl);
    00134         virtual ~WP6ContentListener();
    00135
    00136         // for getting low-level messages from the parser
    00137         virtual void setDate(const uint16_t year, const uint8_t month, const uint8_t day,
    00138                                                 const uint8_t hour, const uint8_t minute, const uint8_t second,
    00139                                                 const uint8_t dayOfWeek, const uint8_t timeZone, const uint8_t unused) {}
    00140         virtual void setExtendedInformation(const uint16_t type, const WPXString &data);
    00141         virtual void setAlignmentCharacter(const uint16_t character);
    00142         virtual void setLeaderCharacter(const uint16_t character, const uint8_t numSpaces);
    00143         virtual void defineTabStops(const bool isRelative, const std::vector<WPXTabStop> &tabStops,
    00144                                     const std::vector<bool> &usePreWP9LeaderMethods);
    00145         virtual void insertCharacter(const uint16_t character);
    00146         virtual void insertTab(const uint8_t tabType, const float tabPosition);
    00147         virtual void handleLineBreak();
    00148         virtual void insertEOL();
    00149         virtual void characterColorChange(const uint8_t red, const uint8_t green, const uint8_t blue);
    00150         virtual void characterShadingChange(const uint8_t shading);
    00151         virtual void highlightChange(const bool isOn, const RGBSColor color);
    00152         virtual void fontChange(const uint16_t matchedFontPointSize, const uint16_t fontPID);
    00153         virtual void attributeChange(const bool isOn, const uint8_t attribute);
    00154         virtual void spacingAfterParagraphChange(const float spacingRelative, const float spacingAbsolute);
    00155         virtual void pageMarginChange(const uint8_t side, const uint16_t margin) {}
    00156         virtual void pageFormChange(const uint16_t length, const uint16_t width, const WPXFormOrientation orientation, const bool isPersistent) {}
    00157         virtual void marginChange(const uint8_t side, const uint16_t margin);
    00158         virtual void paragraphMarginChange(const uint8_t side, const int16_t margin);
    00159         virtual void indentFirstLineChange(const int16_t offset);
    00160         virtual void columnChange(const WPXTextColumnType columnType, const uint8_t numColumns, const std::vector<float> &columnWidth,
    00161                                   const std::vector<bool> &isFixedWidth);
    00162         virtual void updateOutlineDefinition(const WP6OutlineLocation outlineLocation, const uint16_t outlineHash,
    00163                                              const uint8_t *numberingMethods, const uint8_t tabBehaviourFlag);
    00164
    00165         virtual void paragraphNumberOn(const uint16_t outlineHash, const uint8_t level, const uint8_t flag);
    00166         virtual void paragraphNumberOff();
    00167         virtual void displayNumberReferenceGroupOn(const uint8_t subGroup, const uint8_t level);
    00168         virtual void displayNumberReferenceGroupOff(const uint8_t subGroup);
    00169         virtual void styleGroupOn(const uint8_t subGroup);
    00170         virtual void styleGroupOff(const uint8_t subGroup);
    00171         virtual void globalOn(const uint8_t systemStyle);
    00172         virtual void globalOff();
    00173         virtual void noteOn(const uint16_t textPID);
    00174         virtual void noteOff(const WPXNoteType noteType);
    00175         virtual void headerFooterGroup(const uint8_t headerFooterType, const uint8_t occurenceBits, const uint16_t textPID) {}
    00176         virtual void suppressPageCharacteristics(const uint8_t suppressCode) {}
    00177         virtual void endDocument();
    00178
    00179         virtual void defineTable(const uint8_t position, const uint16_t leftOffset);
    00180         virtual void addTableColumnDefinition(const uint32_t width, const uint32_t leftGutter, const uint32_t rightGutter,
    00181                                 const uint32_t attributes, const uint8_t alignment);
    00182         virtual void startTable();
    00183         virtual void insertRow(const uint16_t rowHeight, const bool isMinimumHeight, const bool isHeaderRow);
    00184         virtual void insertCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits,
    00185                                 const RGBSColor * cellFgColor, const RGBSColor * cellBgColor,
    00186                                 const RGBSColor * cellBorderColor, const WPXVerticalAlignment cellVerticalAlignment,
    00187                                 const bool useCellAttributes, const uint32_t cellAttributes);
    00188         virtual void endTable();
    00189
    00190
    00191 protected:
    00192         virtual void _handleSubDocument(const WPXSubDocument *subDocument, const bool isHeaderFooter, WPXTableList tableList, int nextTableIndice = 0);
    00193
    00194         //void _handleLineBreakElementBegin();
    00195         void _paragraphNumberOn(const uint16_t outlineHash, const uint8_t level);
    00196         void _flushText();
    00197         void _handleListChange(const uint16_t outlineHash);
    00198
    00199         void _changeList();
    00200
    00201 private:
    00202         WP6ParsingState *m_parseState;
    00203
    00204         std::map<uint16_t,WP6OutlineDefinition *> m_outlineDefineHash;
    00205 };
    00206
    00207 #endif /* WP6CONTENTLISTENER_H */