LibreOffice Module sw (master)  1
writerhelper.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SW_SOURCE_FILTER_WW8_WRITERHELPER_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_WW8_WRITERHELPER_HXX
22 
23 #include <typeinfo>
24 #include <vector>
25 #include <map>
26 #include <com/sun/star/embed/XEmbeddedObject.hpp>
27 
28 #include <sfx2/objsh.hxx>
29 #include <svl/itempool.hxx>
30 #include <svl/itemset.hxx>
31 #include <svx/svdtypes.hxx>
32 #include <format.hxx>
33 #include <node.hxx>
34 #include <pam.hxx>
35 #include <tools/poly.hxx>
36 #include <doc.hxx>
37 #include <vcl/graph.hxx>
38 
39 class SwTextFormatColl;
40 class SwCharFormat;
41 class SdrObject;
42 class SdrOle2Obj;
43 class OutlinerParaObject;
44 class SwNumFormat;
45 class SwTextNode;
46 class SwNoTextNode;
47 class SwFormatCharFormat;
48 class SwDoc;
49 class SwNumRule;
50 
51 namespace sw
52 {
53  namespace util
54  {
55  class ItemSort
56  {
57  public:
58  bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
59  };
60  }
61 }
62 
63 namespace ww8
64 {
66  typedef std::vector<SwTextFormatColl *> ParaStyles;
68  typedef std::map<sal_uInt16, const SfxPoolItem *, sw::util::ItemSort> PoolItems;
69 
86  class Frame
87  {
88  public:
90  private:
94  // #i43447# - Size of the frame in the layout.
95  // Especially needed for graphics, whose layout size can differ from its
96  // size, because it is scaled into its environment.
98 
102  bool mbForBullet:1;
104  public:
105  Frame(const SwFrameFormat &rFlyFrame, const SwPosition &rPos);
106  Frame(const Graphic&, const SwPosition &);
107 
113  const SwFrameFormat &GetFrameFormat() const { return *mpFlyFrame; }
114 
120  const SwPosition &GetPosition() const { return maPos; }
121  void SetPosition(SwPosition const& rPos) { maPos = rPos; }
122 
129  { return maPos.nNode.GetNode().GetContentNode(); }
130 
137 
143  bool IsInline() const { return mbIsInline; }
144 
153  void ForceTreatAsInline();
154 
160  const SwNode *GetContent() const { return mpStartFrameContent; }
161  const Graphic &GetGraphic() const { return maGrf; }
162  bool HasGraphic() const { return mbForBullet; }
163 
169  bool RefersToSameFrameAs(const Frame &rOther) const
170  {
171  if (mbForBullet && rOther.mbForBullet)
172  return (maGrf == rOther.maGrf);
173  else if ((!mbForBullet) && (!rOther.mbForBullet))
174  return (mpFlyFrame == rOther.mpFlyFrame);
175 
176  return false;
177  }
178 
184  const Size& GetSize() const { return maSize; }
185 
192  const Size& GetLayoutSize() const
193  {
194  return maLayoutSize;
195  }
196  };
197 
199  typedef std::vector<Frame> Frames;
201  typedef std::vector<Frame>::iterator FrameIter;
202 }
203 
204 namespace sw
205 {
206  namespace util
207  {
225  template<class T> const T & item_cast(const SfxPoolItem &rItem)
226  {
227  assert(dynamic_cast<const T *>(&rItem) && "bad type cast");
228  return static_cast<const T &>(rItem);
229  }
230 
246  template<class T> const T * item_cast(const SfxPoolItem *pItem)
247  {
248  return dynamic_cast<const T *>(pItem);
249  }
250 
273  template<class T> const T & ItemGet(const SwContentNode &rNode,
274  sal_uInt16 eType)
275  {
276  return item_cast<T>(rNode.GetAttr(eType));
277  }
278 
299  template<class T> const T & ItemGet(const SwFormat &rFormat,
300  sal_uInt16 eType)
301  {
302  return item_cast<T>(rFormat.GetFormatAttr(eType));
303  }
304 
327  template<class T> const T & ItemGet(const SfxItemSet &rSet,
328  sal_uInt16 eType)
329  {
330  return item_cast<T>(rSet.Get(eType));
331  }
332 
359  template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
360  sal_uInt16 eType)
361  {
362  return item_cast<T>(rPool.GetDefaultItem(eType));
363  }
364 
392  template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
393  sal_uInt16 eType)
394  {
395  return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
396  }
397 
409  ww8::ParaStyles GetParaStyles(const SwDoc &rDoc);
410 
424  SwTextFormatColl* GetParaStyle(SwDoc &rDoc, const OUString& rName);
425 
439  SwCharFormat* GetCharStyle(SwDoc &rDoc, const OUString& rName);
440 
454 
467  void GetPoolItems(const SfxItemSet &rSet, ww8::PoolItems &rItems, bool bExportParentItemSet );
468 
469  const SfxPoolItem *SearchPoolItems(const ww8::PoolItems &rItems,
470  sal_uInt16 eType);
471 
472  template<class T> const T* HasItem(const ww8::PoolItems &rItems,
473  sal_uInt16 eType)
474  {
475  return item_cast<T>(SearchPoolItems(rItems, eType));
476  }
477 
495  void ClearOverridesFromSet(const SwFormatCharFormat &rFormat, SfxItemSet &rSet);
496 
514  ww8::Frames GetFrames(const SwDoc &rDoc, SwPaM const *pPaM);
515 
517  void UpdateFramePositions(ww8::Frames & rFrames);
518 
531  ww8::Frames GetFramesInNode(const ww8::Frames &rFrames, const SwNode &rNode);
532 
548  const SwNumFormat* GetNumFormatFromTextNode(const SwTextNode &rTextNode);
549 
562  int nLevel);
563 
564  const SwNumRule* GetNumRuleFromTextNode(const SwTextNode &rTextNd);
565  const SwNumRule* GetNormalNumRuleFromTextNode(const SwTextNode &rTextNd);
566 
583 
594  bool HasPageBreak(const SwNode &rNode);
595 
608 
610  tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon& rPolyPoly, const SwNoTextNode* pNd, bool bCorrectCrop);
611 
622  class SetLayer
623  {
624  private:
626  enum Layer {eHeaven, eHell};
627  void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
628  public:
629 
635  void SendObjectToHell(SdrObject &rObject) const;
636 
642  void SendObjectToHeaven(SdrObject &rObject) const;
643 
650  explicit SetLayer(const SwDoc &rDoc);
651  };
652 
653  const SwCharFormat* GetSwCharFormat(const SwFormatINetFormat& rINet, SwDoc& rDoc);
654  }
655 
656  namespace hack
657  {
679  sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
680  const SfxItemPool &rSrcPool, sal_uInt16 nWhich);
681 
706  sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
707  const SwDoc &rDoc, sal_uInt16 nWhich);
708 
724  {
725  private:
726  css::uno::Reference < css::embed::XEmbeddedObject > mxIPRef;
729  public:
740 
743 
759  bool TransferToDoc(OUString &rName);
760  private:
762  DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc) = delete;
763  };
764  }
765 }
766 
767 #endif
768 
769 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool TransferToDoc(OUString &rName)
Transfer ownership of the OLE object to a document's SvPersist.
SwNoTextNode * GetNoTextNodeFromSwFrameFormat(const SwFrameFormat &rFormat)
Get the SwNoTextNode associated with a SwFrameFormat if here is one.
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
Marks a position in the document model.
Definition: pam.hxx:36
ww8::Frames GetFramesInNode(const ww8::Frames &rFrames, const SwNode &rNode)
Get the Frames anchored to a given node.
const SfxPoolItem * SearchPoolItems(const ww8::PoolItems &rItems, sal_uInt16 eType)
Frame(const SwFrameFormat &rFlyFrame, const SwPosition &rPos)
bool HasGraphic() const
SwNodeIndex nNode
Definition: pam.hxx:38
SwPosition maPos
Make inserting an OLE object into a Writer document easy.
Definition: doc.hxx:188
SwNode & GetNode() const
Definition: ndindex.hxx:121
Dialog to specify the properties of date form field.
tools::Polygon PolygonFromPolyPolygon(const tools::PolyPolygon &rPolyPoly)
Make a best fit Polygon from a PolyPolygon.
Make setting a drawing object's layer in a Writer document easy.
void GetPoolItems(const SfxItemSet &rSet, ww8::PoolItems &rItems, bool bExportParentItemSet)
Get the SfxPoolItems of a SfxItemSet.
~DrawingOLEAdaptor()
Destructor will destroy the owned OLE object if not transferred.
SdrLayerID mnFormLayer
const SwFrameFormat * mpFlyFrame
SetLayer(const SwDoc &rDoc)
Normal constructor.
const Size & GetLayoutSize() const
The layout size of the contained element.
bool operator()(sal_uInt16 nA, sal_uInt16 nB) const
const SwNumRule * GetNumRuleFromTextNode(const SwTextNode &rTextNode)
const SwCharFormat * GetSwCharFormat(const SwFormatINetFormat &rINet, SwDoc &rDoc)
Definition: ww8atr.cxx:1661
const SwFrameFormat & GetFrameFormat() const
Get the writer SwFrameFormat that this object describes.
Base class for various Writer styles.
Definition: format.hxx:46
const T & item_cast(const SfxPoolItem &rItem)
Provide a dynamic_cast style cast for SfxPoolItems.
void SendObjectToHeaven(SdrObject &rObject) const
Make Object lives in the top layer.
SdrLayerID mnHellLayer
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon &rPolyPoly, const SwNoTextNode *pNd, bool bCorrectCrop)
Undo all scaling / move tricks of the wrap polygon done during import.
bool HasPageBreak(const SwNode &rNd)
Does a node have a "page break before" applied.
Style of a layout element.
Definition: frmfmt.hxx:59
void UpdateFramePositions(ww8::Frames &rFrames)
fix up frame positions, must be called after SetRedlineFlags
std::map< sal_uInt16, const SfxPoolItem *, sw::util::ItemSort > PoolItems
STL container of SfxPoolItems (Attributes)
std::vector< Frame >::iterator FrameIter
STL iterator for Frames.
const T & ItemGet(const SwContentNode &rNode, sal_uInt16 eType)
Extract a SfxPoolItem derived property from a SwContentNode.
void SortByAssignedOutlineStyleListLevel(ww8::ParaStyles &rStyles)
Sort sequence of Paragraph Styles by assigned outline style list level.
SwContentNode * GetContentNode()
Definition: node.hxx:617
bool RefersToSameFrameAs(const Frame &rOther) const
Does this ww8::Frame refer to the same writer content as another.
const Graphic & GetGraphic() const
const SwNumRule * GetNormalNumRuleFromTextNode(const SwTextNode &rTextNode)
void ForceTreatAsInline()
Even if the frame isn't an inline frame, force it to behave as one.
void SetPosition(SwPosition const &rPos)
void SetObjectLayer(SdrObject &rObject, Layer eLayer) const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
Represents the style of a text portion.
Definition: charfmt.hxx:26
sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool, const SfxItemPool &rSrcPool, sal_uInt16 nWhich)
Map an ID valid in one SfxItemPool to its equivalent in another.
Graphic maGrf
SwTextFormatColl * GetParaStyle(SwDoc &rDoc, const OUString &rName)
Get a Paragraph Style which fits a given name.
const SwNode * GetContent() const
Get the first node of content in the frame.
Size maLayoutSize
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
Make exporting a Writer Frame easy.
const SwContentNode * GetContentNode() const
Get the node this frame is anchored into.
DrawingOLEAdaptor(SdrOle2Obj &rObj, SfxObjectShell &rPers)
Take ownership of a SdrOle2Objs OLE object.
const T * HasItem(const ww8::PoolItems &rItems, sal_uInt16 eType)
const Size & GetSize() const
The Size of the contained element.
ww8::ParaStyles GetParaStyles(const SwDoc &rDoc)
Get the Paragraph Styles of a SwDoc.
css::uno::Reference< css::embed::XEmbeddedObject > mxIPRef
WriterSource meWriterType
const SfxPoolItem & GetFormatAttr(sal_uInt16 nWhich, bool bInParents=true) const
If bInParents is FALSE, search only in this format for attribute.
Definition: format.cxx:369
DrawingOLEAdaptor & operator=(const DrawingOLEAdaptor &)=delete
const SwNode * mpStartFrameContent
ww8::Frames GetFrames(const SwDoc &rDoc, SwPaM const *pPaM)
Get the Floating elements in a SwDoc.
const SwNumFormat * GetNumFormatFromTextNode(const SwTextNode &rTextNode)
Get the Numbering Format used on a paragraph.
void SendObjectToHell(SdrObject &rObject) const
Make Object live in the bottom drawing layer.
SdrLayerID mnHeavenLayer
bool IsInline() const
Is this frame inline (as character)
WriterSource GetWriterType() const
Get the type of frame that this wraps.
const SwNumFormat * GetNumFormatFromSwNumRuleLevel(const SwNumRule &rRule, int nLevel)
Get the Numbering Format for a given level from a numbering rule.
sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet, const SwDoc &rDoc, sal_uInt16 nWhich)
Map a SwDoc WhichId to the equivalent Id for a given SfxItemSet.
const SfxPoolItem & GetAttr(sal_uInt16 nWhich, bool bInParent=true) const
SS for PoolItems: hard attributation.
Definition: node.hxx:723
std::vector< SwTextFormatColl * > ParaStyles
STL container of Paragraph Styles (SwTextFormatColl)
void ClearOverridesFromSet(const SwFormatCharFormat &rFormat, SfxItemSet &rSet)
Remove properties from an SfxItemSet which a SwFormatCharFormat overrides.
SwCharFormat * GetCharStyle(SwDoc &rDoc, const OUString &rName)
Get a Character Style which fits a given name.
const SwPosition & GetPosition() const
Get the position this frame is anchored at.
const T & DefaultItemGet(const SfxItemPool &rPool, sal_uInt16 eType)
Extract a default SfxPoolItem derived property from a SfxItemPool.
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1319
std::vector< Frame > Frames
STL container of Frames.
Base class of the Writer document model elements.
Definition: node.hxx:81