Update ooo320-m1
[ooovba.git] / writerfilter / source / doctok / WW8DocumentImpl.hxx
blobd852516ee8ffe152091bbd35c5e63ee5f874b108
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8DocumentImpl.hxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_WW8_DOCUMENT_IMPL_HXX
32 #define INCLUDED_WW8_DOCUMENT_IMPL_HXX
34 #include <set>
35 #include <WW8PieceTable.hxx>
36 #include <WW8BinTable.hxx>
37 #include <resources.hxx>
38 #ifndef INCLUDED_WW8_RESOURCE_MODEL_HXX
39 #include <resourcemodel/WW8ResourceModel.hxx>
40 #endif
41 #include <PLCF.hxx>
42 #include <WW8Sttbf.hxx>
43 #include <XNoteHelper.hxx>
45 namespace writerfilter {
46 namespace doctok
49 class WW8DocumentImpl;
51 /**
52 A bookmark.
54 class Bookmark : public writerfilter::Reference<Properties>
56 /// bookmark first descriptor
57 writerfilter::Reference<Properties>::Pointer_t mpBKF;
59 /// name of bookmark
60 rtl::OUString mName;
62 public:
63 Bookmark(writerfilter::Reference<Properties>::Pointer_t pBKF,
64 rtl::OUString & rName);
66 /**
67 Resolve bookmark to handler.
69 @param rHandler handler to send events to
71 virtual void resolve(Properties & rHandler);
73 virtual string getType() const;
76 /**
77 A helper for bookmarks.
79 class BookmarkHelper
81 /// PLCF containing Cps and BKFs for the bookmarks
82 PLCF<WW8BKF>::Pointer_t mpStartCps;
84 /// Cps of the ends of bookmarks
85 WW8StructBase::Pointer_t mpEndCps;
87 /// STTBF containing the names of bookmarks
88 WW8Sttbf::Pointer_t mpNames;
90 /// piece table for converting CPs to FCs
91 WW8PieceTable::Pointer_t mpPieceTable;
93 /// document to insert CpAndFcs to
94 WW8DocumentImpl * mpDoc;
96 /**
97 Return start CpAndFc for a bookmark.
99 @param nPos index of the bookmark
101 CpAndFc getStartCpAndFc(sal_uInt32 nPos);
104 Return end CpAndFc for a bookmark.
106 @param nPos index of the bookmark
108 CpAndFc getEndCpAndFc(sal_uInt32 nPos);
111 Return the name of a bookmark.
113 @param nPos index of the bookmark
115 rtl::OUString getName(sal_uInt32 nPos);
118 Return index of a bookmark.
120 @param rCpAndFc CpAndFc of the bookmark
122 sal_uInt32 getIndex(const CpAndFc & rCpAndFc);
124 public:
125 typedef boost::shared_ptr<BookmarkHelper> Pointer_t;
127 BookmarkHelper(PLCF<WW8BKF>::Pointer_t pStartCps,
128 WW8StructBase::Pointer_t pEndCps,
129 WW8Sttbf::Pointer_t pNames,
130 WW8PieceTable::Pointer_t pPieceTable,
131 WW8DocumentImpl * pDoc)
132 : mpStartCps(pStartCps), mpEndCps(pEndCps), mpNames(pNames),
133 mpPieceTable(pPieceTable), mpDoc(pDoc)
138 Initialize.
140 Inserts CpAndFcs for the bookmark starts and ends into the
141 document.
143 void init();
146 Return BKF of a bookmark.
148 @param rCpAndFc CpAndFc of the bookmark
150 writerfilter::Reference<Properties>::Pointer_t getBKF
151 (const CpAndFc & rCpAndFc);
154 Return the name of a bookmark.
156 @param rCpAndFc CpAndFc of the bookmark
158 rtl::OUString getName(const CpAndFc & rCp);
161 Return bookmark.
162 @param rCpAndFc CpAndFc of the bookmark
164 writerfilter::Reference<Properties>::Pointer_t
165 getBookmark(const CpAndFc & rCpAndFc);
169 Helper for shapes.
171 class ShapeHelper
173 public:
174 typedef hash_map<CpAndFc, WW8FSPA::Pointer_t, CpAndFcHash> Map_t;
176 private:
177 WW8DocumentImpl * mpDoc;
178 Map_t mMap;
180 public:
181 typedef boost::shared_ptr<ShapeHelper> Pointer_t;
182 ShapeHelper(PLCF<WW8FSPA>::Pointer_t pPlcspaMom,
183 PLCF<WW8FSPA>::Pointer_t pPlcspaHdr,
184 WW8DocumentImpl * pDoc);
186 void init();
188 writerfilter::Reference<Properties>::Pointer_t
189 getShape(const CpAndFc & rCpAndFc);
194 Helper for fields.
196 class FieldHelper
198 public:
199 typedef hash_map<CpAndFc, WW8FLD::Pointer_t,
200 CpAndFcHash> Map_t;
202 private:
203 WW8DocumentImpl * mpDoc;
204 Map_t mMap;
205 public:
207 typedef boost::shared_ptr<FieldHelper> Pointer_t;
208 FieldHelper(PLCF<WW8FLD>::Pointer_t pPlcffldMom,
209 WW8DocumentImpl * pDoc);
211 void init();
213 writerfilter::Reference<Properties>::Pointer_t
214 getField(const CpAndFc & rCpAndFc);
216 WW8FLD::Pointer_t getWW8FLD(const CpAndFc & rCpAndFc);
219 /**
220 Helper for Breaks.
222 class BreakHelper
224 public:
225 typedef hash_map<CpAndFc, WW8BKD::Pointer_t,
226 CpAndFcHash> Map_t;
227 private:
228 WW8DocumentImpl * mpDoc;
229 Map_t mMap;
230 public:
231 typedef boost::shared_ptr<BreakHelper> Pointer_t;
232 BreakHelper(PLCF<WW8BKD>::Pointer_t pPlcfbkdMom,
233 WW8DocumentImpl * pDoc);
235 void init();
237 writerfilter::Reference<Properties>::Pointer_t
238 getBreak(const CpAndFc & rCpAndFc);
242 Implementation class for document.
244 class WW8DocumentImpl : public WW8Document
246 /// true if the document is contained in another document
247 bool bSubDocument;
249 /// picture location
250 sal_uInt32 mfcPicLoc;
252 /// true if FFDATA structure is found at offset mfcPicLoc in data stream
253 bool mbPicIsData;
255 /// current field descriptor
256 WW8FLD::Pointer_t mpFLD;
258 /// CpAndFcs in the document where properties change
259 CpAndFcs mCpAndFcs;
261 /// CpAndFc pointing to the start of the document
262 CpAndFc mCpAndFcStart;
264 /// CpAndFc pointing to the end of the document
265 CpAndFc mCpAndFcEnd;
267 /// pointer to the cache of FKPs containing character properties
268 WW8FKPCache::Pointer_t mpCHPFKPCache;
270 /// pointer to the cache of FPKs containing paragraph properties
271 WW8FKPCache::Pointer_t mpPAPFKPCache;
273 /// pointer to the stream containing the whole document
274 WW8Stream::Pointer_t mpStream;
276 /// pointer to the substream of the document containing table like
277 /// structures
278 WW8Stream::Pointer_t mpTableStream;
280 /// pointer to the substream of the document containing the
281 /// document contents and formatting information
282 WW8Stream::Pointer_t mpDocStream;
284 /// pointer to the data stream of the document
285 WW8Stream::Pointer_t mpDataStream;
287 /// pointer to the compound object stream of the document
288 WW8Stream::Pointer_t mpCompObjStream;
290 /// pointer to the piece table
291 WW8PieceTable::Pointer_t mpPieceTable;
293 /// pointer to the bin table for paragraph properties
294 WW8BinTable::Pointer_t mpBinTablePAPX;
296 /// pointer to the bin table for character properties
297 WW8BinTable::Pointer_t mpBinTableCHPX;
299 /// PLCF containing the section descriptions
300 PLCF<WW8SED>::Pointer_t mpSEDs;
302 /// pointer to the file information block
303 WW8Fib::Pointer_t mpFib;
305 /// pointer to the offsets of headers/footers
306 WW8StructBase::Pointer_t mpHeaderOffsets;
308 /// pointer to the helper for footnotes
309 XNoteHelper<WW8FRD>::Pointer_t mpFootnoteHelper;
311 /// pointer to the helper for endnotes
312 XNoteHelper<WW8FRD>::Pointer_t mpEndnoteHelper;
314 /// pointer to the helper for annotations
315 XNoteHelper<WW8ATRD>::Pointer_t mpAnnotationHelper;
317 /// pointer to the helper for bookmarks
318 BookmarkHelper::Pointer_t mpBookmarkHelper;
320 /// pointer to the helper for fields
321 FieldHelper::Pointer_t mpFieldHelper;
323 /// pointer to the helper for shapes
324 ShapeHelper::Pointer_t mpShapeHelper;
326 /// pointer to the helper for breaks
327 BreakHelper::Pointer_t mpBreakHelper;
330 /// cache for the Cp where main text flow end
331 CpAndFc mDocumentEndCpAndFc;
333 /// cache for the Cp where footnotes section ends
334 CpAndFc mFootnoteEndCpAndFc;
336 /// cache for the Cp where header section ends
337 CpAndFc mHeaderEndCpAndFc;
339 /// cache for the Cp where annotation section ends
340 CpAndFc mAnnotationEndCpAndFc;
342 /// cache for the Cp where endnote section ends
343 CpAndFc mEndnoteEndCpAndFc;
345 /// cache for the Cp where textbox section ends
346 CpAndFc mTextboxEndCpAndFc;
348 /// cache for the Cp where textbox in header section ends
349 CpAndFc mTextboxHeaderEndCpAndFc;
351 /// DffBlock of document
352 DffBlock::Pointer_t mpDffBlock;
354 /// Textbox stories
355 PLCF<WW8FTXBXS>::Pointer_t mpTextBoxStories;
357 bool mbInSection;
358 bool mbInParagraphGroup;
359 bool mbInCharacterGroup;
361 bool isSpecial(sal_uInt32 nChar);
363 WW8Stream::Pointer_t getSubStream(const ::rtl::OUString & sId) const;
366 Parse bin table and create CpAndFcs for all points in the
367 document where properties of the given type change.
369 @param rTable bin table to parse
370 @param eType_ type of CpAndFcs to create
372 void parseBinTableCpAndFcs(WW8BinTable & rTable, PropertyType eType_);
374 void startCharacterGroup(Stream & rStream);
375 void endCharacterGroup(Stream & rStream);
376 void startParagraphGroup(Stream & rStream);
377 void endParagraphGroup(Stream & rStream);
378 void startSectionGroup(Stream & rStream);
379 void endSectionGroup(Stream & rStream);
380 void text(Stream & rStream, const sal_uInt8 * data, size_t len);
381 void utext(Stream & rStream, const sal_uInt8 * data, size_t len);
383 public:
384 WW8DocumentImpl(WW8Stream::Pointer_t rpStream);
385 WW8DocumentImpl(const WW8DocumentImpl & rSrc,
386 const CpAndFc & rStart, const CpAndFc & rEnd);
387 virtual ~WW8DocumentImpl();
389 virtual WW8DocumentImpl & Assign(const WW8DocumentImpl & rSrc);
391 virtual string getType() const;
393 virtual WW8Document::Pointer_t getSubDocument(SubDocumentId nId);
394 virtual WW8DocumentIterator::Pointer_t getIterator
395 (const CpAndFc & rCpAndFc);
396 virtual WW8DocumentIterator::Pointer_t begin();
397 virtual WW8DocumentIterator::Pointer_t end();
399 virtual WW8Stream::Sequence getText(const CpAndFc & rStart);
401 WW8Fib::Pointer_t getFib() const;
404 Returns the document stream.
407 WW8Stream::Pointer_t getDocStream() const;
410 Returns the data stream.
412 WW8Stream::Pointer_t getDataStream() const;
415 Returns distance in bytes to next CpAndFc.
417 @param rCpAndFc CpAndFc to start at
419 sal_uInt32 getByteLength(const CpAndFc & rCpAndFc) const;
422 Returns first character position in document.
424 const CpAndFc & getFirstCp() const;
427 Returns last character position in document.
429 const CpAndFc & getLastCp() const;
432 Returns next character position with change in properties.
434 @param rCpAndFc position to start at
436 CpAndFc getNextCp(const CpAndFc & rCpAndFc) const;
439 Returns previous character position with change in properties.
441 @param rCpAndFc position to start at
443 CpAndFc getPrevCp(const CpAndFc & rCpAndFc) const;
446 Returns character position where main text flow ends.
448 CpAndFc getDocumentEndCp() const;
451 Returns character position where footnotes end.
453 CpAndFc getFootnodeEndCp() const;
456 Returns character position where headers end.
458 CpAndFc getHeaderEndCp() const;
461 Returns character position where annatations end.
463 CpAndFc getAnnotationEndCp() const;
466 Returns character position where endnotes end.
468 CpAndFc getEndnoteEndCp() const;
471 Returns character position where textboxes end.
473 CpAndFc getTextboxEndCp() const;
476 Returns character positoion where textboxes in headers end.
478 CpAndFc getTextboxHeaderEndCp() const;
481 Insert CpAndFc to set of CpAndFcs.
483 @param rCpAndFc CpAndFc to insert
485 void insertCpAndFc(const CpAndFc & rCpAndFc);
488 Return FKP for certain CpAndFc.
490 @param rCpAndFc CpAndFc for which the FKP is looked for
492 WW8FKP::Pointer_t getFKP(const CpAndFc & rCpAndFc);
495 Return FKP containing character properties.
497 @param nIndex index of FKP to return
498 @param bComplex true if FKP contains complex FCs
500 WW8FKP::Pointer_t getFKPCHPX(sal_uInt32 nIndex, bool bComplex);
503 Return FKP containing paragraph properties.
505 @param nIndex index of FKP to return
506 @param bComplex true if FKP contains complex FCs
508 WW8FKP::Pointer_t getFKPPAPX(sal_uInt32 nIndex, bool bComplex);
511 Return property set valid at a certain CpAndFc.
513 @param rCpAndFc CpAndFc to look at
515 writerfilter::Reference<Properties>::Pointer_t
516 getProperties(const CpAndFc & rCpAndFc);
519 Return subdocument referenced at a certain point in document.
521 @param rCpAndFc CpAndFc where subdocument is referenced
523 writerfilter::Reference<Stream>::Pointer_t
524 getSubDocument(const CpAndFc & rCpAndFc);
527 Return section description at a certain CpAndFc.
529 @param rCpAndFc CpAndFc to look at
531 WW8SED * getSED(const CpAndFc & rCpAndFc) const;
534 Return reference to list table.
536 writerfilter::Reference<Table>::Pointer_t getListTable() const;
539 Return reference to table of list level overrides.
541 writerfilter::Reference<Table>::Pointer_t getLFOTable() const;
544 Return reference to font table.
546 writerfilter::Reference<Table>::Pointer_t getFontTable() const;
549 Return reference to style sheet.
551 writerfilter::Reference<Table>::Pointer_t getStyleSheet() const;
554 Return count of headers/footers.
556 sal_uInt32 getHeaderCount() const;
559 Return CpAndFc for a header or footer.
561 @param nPos index in the list of headers and footers
563 CpAndFc getHeaderCpAndFc(sal_uInt32 nPos);
566 Return subdocument for header/footer.
568 @param nPos index in the list of headers and footers
570 writerfilter::Reference<Stream>::Pointer_t getHeader(sal_uInt32 nPos);
573 Return count of footnotes.
575 sal_uInt32 getFootnoteCount() const;
578 Return subdocument for footnote.
580 @param nPos index of the footnote
582 writerfilter::Reference<Stream>::Pointer_t getFootnote(sal_uInt32 nPos);
585 Return subdocument for footnote at a certain position in document.
587 @param rCpAndFc position in document
589 writerfilter::Reference<Stream>::Pointer_t getFootnote
590 (const CpAndFc & rCpAndFc);
593 Return count of endnotes.
595 sal_uInt32 getEndnoteCount() const;
598 Return subdocument for an endnote.
600 @param nPos index of the endnote
602 writerfilter::Reference<Stream>::Pointer_t getEndnote(sal_uInt32 nPos);
605 Return subdocument for an endnote.
607 @param rCpAndFc CpAndFc where endnote is referenced
609 writerfilter::Reference<Stream>::Pointer_t getEndnote
610 (const CpAndFc & rCpAndFc);
613 Return count of annotations.
615 sal_uInt32 getAnnotationCount() const;
618 Return subdocument for an annotation.
620 @param nPos index of the annotation
622 writerfilter::Reference<Stream>::Pointer_t getAnnotation(sal_uInt32 nPos);
625 Return subdocument for an annotation.
627 @param rCpAndFc CpAndFc where annotation is referenced
629 writerfilter::Reference<Stream>::Pointer_t getAnnotation
630 (const CpAndFc & rCpAndFc);
633 Return bookmark.
635 @param rCpAndFc CpAndFc where bookmark begins or ends
637 writerfilter::Reference<Properties>::Pointer_t
638 getBookmark(const CpAndFc & rCpAndFc) const;
641 Return shape.
643 @param rCpAndFc CpAndFc of the shape
645 writerfilter::Reference<Properties>::Pointer_t
646 getShape(const CpAndFc & rCpAndFc) const;
648 writerfilter::Reference<Properties>::Pointer_t
649 getShape(sal_uInt32 nSpid);
652 Return blip.
654 @param nBlib number of the blip to return
656 writerfilter::Reference<Properties>::Pointer_t
657 getBlip(sal_uInt32 nBlib);
660 Return break descriptor.
662 @param rCpAndFc CpAndFc of the break
664 writerfilter::Reference<Properties>::Pointer_t
665 getBreak(const CpAndFc & rCpAndFc) const;
669 Return field.
671 @param rCpAndFc CpAndFc of the field
673 writerfilter::Reference<Properties>::Pointer_t
674 getField(const CpAndFc & rCpAndFc) const;
677 Return current field descriptor.
679 WW8FLD::Pointer_t getCurrentFLD() const;
682 Return stream of text box.
684 @param nShpId shape id of text box
686 writerfilter::Reference<Stream>::Pointer_t
687 getTextboxText(sal_uInt32 nShpId) const;
690 Return file character position according to a character
691 position.
693 @param cp the character position
695 Fc cp2fc(const Cp & cp) const;
698 Return the character position according to file character
699 position.
701 @param fc the file character position
703 Cp fc2cp(const Fc & fc) const;
706 Return CpAndFc related to character position.
708 @param cp the character position
710 CpAndFc getCpAndFc(const Cp & cp, PropertyType type = PROP_DOC) const;
713 Return CpAndFc related to file character position.
715 @param fc the file character position
717 CpAndFc getCpAndFc(const Fc & fc, PropertyType type = PROP_DOC) const;
719 sal_uInt32 getPicLocation() const;
720 void setPicLocation(sal_uInt32 fcPicLoc);
722 bool isPicData();
723 void setPicIsData(bool bPicIsData);
726 Create events for the document.
728 @param rHandler handler to send the events to
730 void resolve(Stream & rHandler);
733 Resolve text.
735 The text of the given iterator is split at special
736 characters. Each run of non-special characters is send as one
737 event. Each run of special characters is send as one event.
739 @param pIt iterator whose text is to be resolved
740 @param rStream handler for the events
742 void resolveText(WW8DocumentIterator::Pointer_t pIt, Stream & rStream);
745 Resolve the picture at mfcPicLoc.
747 @param rStream
749 void resolvePicture(Stream & rStream);
752 Resolve special char.
754 @param nChar the special char
755 @param rStream the stream handler to resolve the special char to
757 void resolveSpecialChar(sal_uInt32 nChar, Stream & rStream);
761 Implentation class for an iterator in a document.
763 class WW8DocumentIteratorImpl : public WW8DocumentIterator
765 /// pointer to the document
766 WW8DocumentImpl * mpDocument;
768 /// CpAndFc the iterator is pointing to
769 CpAndFc mCpAndFc;
771 public:
772 WW8DocumentIteratorImpl(WW8DocumentImpl * pDocument,
773 const CpAndFc & rCpAndFc)
774 : mpDocument(pDocument), mCpAndFc(rCpAndFc)
778 virtual ~WW8DocumentIteratorImpl();
781 Increase the iterator to the next character position.
783 WW8DocumentIterator & operator++();
786 Decrease the iterator to the previous character position.
788 WW8DocumentIterator & operator--();
790 virtual writerfilter::Reference<Properties>::Pointer_t getProperties()
791 const;
792 //void setAttributes(const IAttributeSet & aAttributeSet);
794 virtual writerfilter::Reference<Stream>::Pointer_t getSubDocument() const;
796 /** Return if the text the iterator points to is complex.
798 @attention The definition of a complex run of text in Word is
799 counter-intuitive: Complex runs use 8-bit encoding for characters,
800 non-complex ones use 16 bits.
802 bool isComplex() const;
803 virtual PropertyType getPropertyType() const;
805 virtual WW8Stream::Sequence getText();
806 virtual bool equal(const WW8DocumentIterator & rIt) const;
808 virtual string toString() const;
809 virtual void dump(ostream & o) const;
812 Return pointer to the shape at character position the iterator
813 is pointing to.
815 virtual writerfilter::Reference<Properties>::Pointer_t getShape() const;
818 Return pointer to section description at character position the
819 iterator points to.
821 WW8SED * getSED() const;
825 Return string for property type.
827 string propertyTypeToString(PropertyType nType);
830 #endif // INCLUDED_WW8_DOCUMENT_IMPL_HXX