00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WKSCONTENTLISTENER_H
00026 #define WKSCONTENTLISTENER_H
00027
00028 #include <vector>
00029
00030 #include <librevenge/librevenge.h>
00031
00032 #include "libwps_internal.h"
00033
00034 #include "WPSEntry.h"
00035 #include "WPSGraphicStyle.h"
00036
00037 #include "WPSListener.h"
00038
00039 class WPSCellFormat;
00040 class WPSGraphicShape;
00041 class WPSGraphicStyle;
00042 class WPSList;
00043 class WPSPageSpan;
00044 struct WPSParagraph;
00045 struct WPSTabStop;
00046
00047 struct WKSContentParsingState;
00048 struct WKSDocumentParsingState;
00049
00050 class WKSContentListener : public WPSListener
00051 {
00052 public:
00054 struct FormulaInstruction
00055 {
00056 enum What { F_Operator, F_Function, F_Cell, F_CellList, F_Long, F_Double, F_Text };
00058 FormulaInstruction() : m_type(F_Text), m_content(""), m_longValue(0), m_doubleValue(0), m_sheetName("")
00059 {
00060 for (int i=0; i<2; ++i)
00061 {
00062 m_position[i]=Vec2i(0,0);
00063 m_positionRelative[i]=Vec2b(false,false);
00064 }
00065 }
00067 librevenge::RVNGPropertyList getPropertyList() const;
00069 friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
00071 What m_type;
00073 std::string m_content;
00075 double m_longValue;
00077 double m_doubleValue;
00079 Vec2i m_position[2];
00081 Vec2b m_positionRelative[2];
00083 librevenge::RVNGString m_sheetName;
00084 };
00086 struct CellContent
00087 {
00089 enum ContentType { C_NONE, C_TEXT, C_NUMBER, C_FORMULA, C_UNKNOWN };
00091 CellContent() : m_contentType(C_UNKNOWN), m_value(0.0), m_valueSet(false), m_textEntry(), m_formula() { }
00093 ~CellContent() {}
00095 friend std::ostream &operator<<(std::ostream &o, CellContent const &cell);
00096
00098 bool empty() const
00099 {
00100 if (m_contentType == C_NUMBER) return false;
00101 if (m_contentType == C_TEXT && !m_textEntry.valid()) return false;
00102 if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
00103 return true;
00104 }
00106 void setValue(double value)
00107 {
00108 m_value = value;
00109 m_valueSet = true;
00110 }
00112 bool isValueSet() const
00113 {
00114 return m_valueSet;
00115 }
00117 bool hasText() const
00118 {
00119 return m_textEntry.valid();
00120 }
00122 static bool double2Date(double val, int &Y, int &M, int &D);
00124 static bool double2Time(double val, int &H, int &M, int &S);
00125
00127 ContentType m_contentType;
00129 double m_value;
00131 bool m_valueSet;
00133 WPSEntry m_textEntry;
00135 std::vector<FormulaInstruction> m_formula;
00136 };
00137
00138 WKSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface);
00139 virtual ~WKSContentListener();
00140
00141 void setDocumentLanguage(int lcid);
00142
00143 void startDocument();
00144 void endDocument();
00145 void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
00146
00147
00148
00150 void insertCharacter(uint8_t character);
00154 void insertUnicode(uint32_t character);
00156 void insertUnicodeString(librevenge::RVNGString const &str);
00157
00158 void insertTab();
00159 void insertEOL(bool softBreak=false);
00160 void insertBreak(const uint8_t breakType);
00161
00162
00164 void setFont(const WPSFont &font);
00166 WPSFont const &getFont() const;
00167
00168
00170 bool isParagraphOpened() const;
00172 void setParagraph(const WPSParagraph ¶);
00174 WPSParagraph const &getParagraph() const;
00175
00176
00178 void insertField(FieldType type);
00180 void insertDateTimeField(char const *format);
00181
00182
00184 void insertComment(WPSSubDocumentPtr &subDocument);
00186 void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
00187 std::string type="image/pict", WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle());
00189 void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj,
00190 WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle());
00192 void insertPicture(WPSPosition const &pos, WPSGraphicShape const &shape, WPSGraphicStyle const &style);
00194 void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
00195 WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle());
00196
00197
00199 void openSheet(std::vector<float> const &colWidth, librevenge::RVNGUnit unit, librevenge::RVNGString const &name="");
00201 void closeSheet();
00203 void openSheetRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
00205 void closeSheetRow();
00210 void openSheetCell(WPSCell const &cell, CellContent const &content, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList());
00212 void closeSheetCell();
00213
00214 protected:
00215 void _openPageSpan();
00216 void _closePageSpan();
00217
00218 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos);
00219 bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style);
00220 void _closeFrame();
00221
00222 void _startSubDocument();
00223 void _endSubDocument();
00224
00225 void _openParagraph();
00226 void _closeParagraph();
00227 void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
00228 void _resetParagraphState(const bool isListElement=false);
00229
00230 void _openSpan();
00231 void _closeSpan();
00232
00233 void _flushText();
00234 void _flushDeferredTabs();
00235
00236 void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
00237
00241 shared_ptr<WKSContentParsingState> _pushParsingState();
00243 void _popParsingState();
00244
00245 protected:
00246 shared_ptr<WKSDocumentParsingState> m_ds;
00247 shared_ptr<WKSContentParsingState> m_ps;
00248 std::vector<shared_ptr<WKSContentParsingState> > m_psStack;
00249 librevenge::RVNGSpreadsheetInterface *m_documentInterface;
00250
00251 private:
00252 WKSContentListener(const WKSContentListener &);
00253 WKSContentListener &operator=(const WKSContentListener &);
00254 };
00255
00256 #endif
00257