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

WP6ContentListener.h

Go to the documentation of this file.
00001 /* libwpd
00002  * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00003  * Copyright (C) 2002 Marc Maurer (uwog@uwog.net)
00004  * Copyright (C) 2005-2006 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 "WPXContentListener.h"
00032 #include "WP6FileStructure.h"
00033 
00034 #include <stack>
00035 #include <map>
00036 #include <vector>
00037 
00038 class WPXHLListenerImpl;
00039 class WPXTable;
00040 
00041 enum WP6StyleState { NORMAL, DOCUMENT_NOTE, DOCUMENT_NOTE_GLOBAL,
00042                      BEGIN_BEFORE_NUMBERING,
00043                      BEGIN_NUMBERING_BEFORE_DISPLAY_REFERENCING,
00044                      DISPLAY_REFERENCING,
00045                      BEGIN_NUMBERING_AFTER_DISPLAY_REFERENCING,
00046                      BEGIN_AFTER_NUMBERING, STYLE_BODY, STYLE_END };
00047 
00048 enum WP6ListType { ORDERED, UNORDERED };
00049 
00050 const int STATE_MEMORY = 3;
00051 class WP6StyleStateSequence
00052 {
00053 public:
00054         WP6StyleStateSequence() : m_stateSequence(), m_currentState(), m_previousState() { clear(); }
00055         void setCurrentState(WP6StyleState state) { for (int i=(STATE_MEMORY-1); i>0; i--) m_stateSequence[i] = m_stateSequence[i-1]; m_stateSequence[0]=state; }
00056         const WP6StyleState getCurrentState() const { return m_stateSequence[0]; /*currentState;*/ }
00057         const WP6StyleState getPreviousState() const { return m_stateSequence[1]; /*m_previousState;*/ }
00058         void clear() { m_stateSequence.clear(); for (int i=0; i<STATE_MEMORY; i++) m_stateSequence.push_back(NORMAL); }
00059 
00060 private:
00061         std::vector<WP6StyleState> m_stateSequence;
00062         WP6StyleState m_currentState;
00063         WP6StyleState m_previousState;
00064 };
00065 
00066 typedef struct _WP6ContentParsingState WP6ContentParsingState;
00067 struct _WP6ContentParsingState
00068 {
00069         _WP6ContentParsingState(WPXTableList tableList, int nextTableIndice = 0);
00070         ~_WP6ContentParsingState();
00071         WPXString m_bodyText;
00072         WPXString m_textBeforeNumber;
00073         WPXString m_textBeforeDisplayReference;
00074         WPXString m_numberText;
00075         WPXString m_textAfterDisplayReference;
00076         WPXString m_textAfterNumber;
00077 
00078         float m_paragraphMarginBottomRelative;
00079         float m_paragraphMarginBottomAbsolute;
00080 
00081         int m_numRemovedParagraphBreaks;
00082         
00083         int m_numListExtraTabs;
00084         bool m_isListReference;
00085 
00086         WPXTableList m_tableList;
00087         WPXTable *m_currentTable;
00088         int m_nextTableIndice;
00089 
00090         std::stack<int> m_listLevelStack;
00091         std::stack<WP6ListType> m_listTypeStack;
00092         uint16_t m_currentOutlineHash; // probably should replace Hash with Key in these sorts of cases
00093         uint8_t m_oldListLevel;
00094         WP6StyleStateSequence m_styleStateSequence;
00095         bool m_putativeListElementHasParagraphNumber;
00096         bool m_putativeListElementHasDisplayReferenceNumber;
00097 
00098         int m_noteTextPID;
00099         int m_numNestedNotes;
00100 
00101         uint16_t m_leaderCharacter;
00102         uint8_t m_leaderNumSpaces;
00103         std::vector<WPXTabStop> m_tempTabStops;
00104         std::vector<bool> m_tempUsePreWP9LeaderMethod;
00105 private:
00106         _WP6ContentParsingState(const _WP6ContentParsingState&);
00107         _WP6ContentParsingState& operator=(const _WP6ContentParsingState&);
00108 };
00109 
00110 struct _WP6ListLevel
00111 {
00112         int m_level;
00113         bool m_isListElementOpenAtLevel;
00114 };
00115 
00116 class WP6OutlineDefinition
00117 {
00118  public:
00119         WP6OutlineDefinition();
00120         WP6OutlineDefinition(const WP6OutlineLocation outlineLocation, const uint8_t *numberingMethods,
00121                           const uint8_t tabBehaviourFlag);
00122         void update(const uint8_t *numberingMethods, const uint8_t tabBehaviourFlag);
00123 
00124         WPXNumberingType getListType(int level) { return m_listTypes[level]; }
00125 
00126 protected:
00127         void _updateNumberingMethods(const WP6OutlineLocation outlineLocation, const uint8_t *numberingMethods);
00128 
00129 private:
00130         WPXNumberingType m_listTypes[WP6_NUM_LIST_LEVELS];
00131 };
00132 
00133 class WP6ContentListener : public WP6Listener, protected WPXContentListener
00134 {
00135 public:
00136         WP6ContentListener(std::list<WPXPageSpan> &pageList, WPXTableList tableList, WPXHLListenerImpl *listenerImpl);
00137         ~WP6ContentListener();
00138 
00139         void startDocument() { WPXContentListener::startDocument(); };
00140         void setDate(const uint16_t type, const uint16_t year, 
00141                      const uint8_t month, const uint8_t day, 
00142                      const uint8_t hour, const uint8_t minute, 
00143                      const uint8_t second, const uint8_t dayOfWeek, 
00144                      const uint8_t timeZone, const uint8_t unused);
00145         void setExtendedInformation(const uint16_t type, const WPXString &data);
00146         void setAlignmentCharacter(const uint16_t character);
00147         void setLeaderCharacter(const uint16_t character, const uint8_t numSpaces);
00148         void defineTabStops(const bool isRelative, const std::vector<WPXTabStop> &tabStops, 
00149                                     const std::vector<bool> &usePreWP9LeaderMethods);
00150         void insertCharacter(const uint16_t character);
00151         void insertTab(const uint8_t tabType, float tabPosition);
00152         void handleLineBreak();
00153         void insertEOL();
00154         void insertBreak(const uint8_t breakType) { WPXContentListener::insertBreak(breakType); };
00155         void lineSpacingChange(const float lineSpacing) { WPXContentListener::lineSpacingChange(lineSpacing); };
00156         void justificationChange(const uint8_t justification) { WPXContentListener::justificationChange(justification); };
00157         void characterColorChange(const uint8_t red, const uint8_t green, const uint8_t blue);
00158         void characterShadingChange(const uint8_t shading);
00159         void highlightChange(const bool isOn, const RGBSColor color);
00160         void fontChange(const uint16_t matchedFontPointSize, const uint16_t fontPID);
00161         void attributeChange(const bool isOn, const uint8_t attribute);
00162         void spacingAfterParagraphChange(const float spacingRelative, const float spacingAbsolute);
00163         void pageMarginChange(const uint8_t /* side */, const uint16_t /* margin */) {}
00164         void pageFormChange(const uint16_t /* length */, const uint16_t /* width */, const WPXFormOrientation /* orientation */) {}
00165         void marginChange(const uint8_t side, const uint16_t margin);
00166         void paragraphMarginChange(const uint8_t side, const int16_t margin);
00167         void indentFirstLineChange(const int16_t offset);
00168         void columnChange(const WPXTextColumnType columnType, const uint8_t numColumns, const std::vector<float> &columnWidth,
00169                                   const std::vector<bool> &isFixedWidth);
00170         void updateOutlineDefinition(const WP6OutlineLocation outlineLocation, const uint16_t outlineHash,
00171                                              const uint8_t *numberingMethods, const uint8_t tabBehaviourFlag);
00172 
00173         void paragraphNumberOn(const uint16_t outlineHash, const uint8_t level, const uint8_t flag);
00174         void paragraphNumberOff();
00175         void displayNumberReferenceGroupOn(const uint8_t subGroup, const uint8_t level);
00176         void displayNumberReferenceGroupOff(const uint8_t subGroup);
00177         void styleGroupOn(const uint8_t subGroup);
00178         void styleGroupOff(const uint8_t subGroup);
00179         void globalOn(const uint8_t systemStyle);
00180         void globalOff();
00181         void noteOn(const uint16_t textPID);
00182         void noteOff(const WPXNoteType noteType);
00183         void headerFooterGroup(const uint8_t /* headerFooterType */, const uint8_t /* occurenceBits */, const uint16_t /* textPID */) {}
00184         void suppressPageCharacteristics(const uint8_t /* suppressCode */) {}
00185         void endDocument() { WPXContentListener::endDocument(); };
00186 
00187         void defineTable(const uint8_t position, const uint16_t leftOffset);
00188         void addTableColumnDefinition(const uint32_t width, const uint32_t leftGutter, const uint32_t rightGutter,
00189                                 const uint32_t attributes, const uint8_t alignment);
00190         void startTable();
00191         void insertRow(const uint16_t rowHeight, const bool isMinimumHeight, const bool isHeaderRow);
00192         void insertCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits,
00193                                 const RGBSColor * cellFgColor, const RGBSColor * cellBgColor,
00194                                 const RGBSColor * cellBorderColor, const WPXVerticalAlignment cellVerticalAlignment, 
00195                                 const bool useCellAttributes, const uint32_t cellAttributes);
00196         void endTable();
00197 
00198         void undoChange(const uint8_t undoType, const uint16_t undoLevel);
00199 
00200 protected:
00201         void _handleSubDocument(const WPXSubDocument *subDocument, const bool isHeaderFooter, WPXTableList tableList, int nextTableIndice = 0);
00202 
00203         //void _handleLineBreakElementBegin();
00204         void _paragraphNumberOn(const uint16_t outlineHash, const uint8_t level);
00205         void _flushText();
00206         void _handleListChange(const uint16_t outlineHash);
00207 
00208         void _changeList();
00209 
00210 private:
00211         WP6ContentListener(const WP6ContentListener&);
00212         WP6ContentListener& operator=(const WP6ContentListener&);
00213         WP6ContentParsingState *m_parseState;
00214 
00215         std::map<uint16_t,WP6OutlineDefinition *> m_outlineDefineHash;
00216 };
00217 
00218 #endif /* WP6CONTENTLISTENER_H */

Generated on Sat Aug 20 05:20:56 2022 for libwpd by doxygen 1.3.5