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  if (dynamic_cast<const T *>(&rItem) == nullptr)
228  throw std::bad_cast();
229  return static_cast<const T &>(rItem);
230  }
231 
247  template<class T> const T * item_cast(const SfxPoolItem *pItem)
248  {
249  return dynamic_cast<const T *>(pItem);
250  }
251 
274  template<class T> const T & ItemGet(const SwContentNode &rNode,
275  sal_uInt16 eType)
276  {
277  return item_cast<T>(rNode.GetAttr(eType));
278  }
279 
300  template<class T> const T & ItemGet(const SwFormat &rFormat,
301  sal_uInt16 eType)
302  {
303  return item_cast<T>(rFormat.GetFormatAttr(eType));
304  }
305 
328  template<class T> const T & ItemGet(const SfxItemSet &rSet,
329  sal_uInt16 eType)
330  {
331  return item_cast<T>(rSet.Get(eType));
332  }
333 
360  template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
361  sal_uInt16 eType)
362  {
363  return item_cast<T>(rPool.GetDefaultItem(eType));
364  }
365 
393  template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
394  sal_uInt16 eType)
395  {
396  return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
397  }
398 
410  ww8::ParaStyles GetParaStyles(const SwDoc &rDoc);
411 
425  SwTextFormatColl* GetParaStyle(SwDoc &rDoc, const OUString& rName);
426 
440  SwCharFormat* GetCharStyle(SwDoc &rDoc, const OUString& rName);
441 
455 
468  void GetPoolItems(const SfxItemSet &rSet, ww8::PoolItems &rItems, bool bExportParentItemSet );
469 
470  const SfxPoolItem *SearchPoolItems(const ww8::PoolItems &rItems,
471  sal_uInt16 eType);
472 
473  template<class T> const T* HasItem(const ww8::PoolItems &rItems,
474  sal_uInt16 eType)
475  {
476  return item_cast<T>(SearchPoolItems(rItems, eType));
477  }
478 
496  void ClearOverridesFromSet(const SwFormatCharFormat &rFormat, SfxItemSet &rSet);
497 
515  ww8::Frames GetFrames(const SwDoc &rDoc, SwPaM const *pPaM);
516 
518  void UpdateFramePositions(ww8::Frames & rFrames);
519 
532  ww8::Frames GetFramesInNode(const ww8::Frames &rFrames, const SwNode &rNode);
533 
549  const SwNumFormat* GetNumFormatFromTextNode(const SwTextNode &rTextNode);
550 
563  int nLevel);
564 
565  const SwNumRule* GetNumRuleFromTextNode(const SwTextNode &rTextNd);
566  const SwNumRule* GetNormalNumRuleFromTextNode(const SwTextNode &rTextNd);
567 
584 
595  bool HasPageBreak(const SwNode &rNode);
596 
609 
612 
623  class SetLayer
624  {
625  private:
627  enum Layer {eHeaven, eHell};
628  void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
629  public:
630 
636  void SendObjectToHell(SdrObject &rObject) const;
637 
643  void SendObjectToHeaven(SdrObject &rObject) const;
644 
651  explicit SetLayer(const SwDoc &rDoc);
652  };
653  }
654 
655  namespace hack
656  {
678  sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
679  const SfxItemPool &rSrcPool, sal_uInt16 nWhich);
680 
705  sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
706  const SwDoc &rDoc, sal_uInt16 nWhich);
707 
723  {
724  private:
725  css::uno::Reference < css::embed::XEmbeddedObject > mxIPRef;
728  public:
739 
742 
758  bool TransferToDoc(OUString &rName);
759  private:
761  DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc) = delete;
762  };
763  }
764 }
765 
766 #endif
767 
768 /* 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:55
Marks a position in the document model.
Definition: pam.hxx:35
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:37
SwPosition maPos
Make inserting an OLE object into a Writer document easy.
Definition: doc.hxx:185
SwNode & GetNode() const
Definition: ndindex.hxx:118
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon &rPolyPoly, const SwNoTextNode *pNd)
Undo all scaling / move tricks of the wrap polygon done during import.
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 SwFrameFormat & GetFrameFormat() const
Get the writer SwFrameFormat that this object describes.
Base class for various Writer styles.
Definition: format.hxx:43
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:136
bool HasPageBreak(const SwNode &rNd)
Does a node have a "page break before" applied.
Style of a layout element.
Definition: frmfmt.hxx:57
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:615
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
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:379
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:730
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:1307
std::vector< Frame > Frames
STL container of Frames.
Base class of the Writer document model elements.
Definition: node.hxx:79