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 "types.hxx"
30 #include <svl/itempool.hxx>
31 #include <svl/itemset.hxx>
32 #include <svx/svdtypes.hxx>
33 #include <format.hxx>
34 #include <node.hxx>
35 #include <pam.hxx>
36 #include <tools/poly.hxx>
37 #include <doc.hxx>
38 #include <vcl/graph.hxx>
39 
40 class SwTextFormatColl;
41 class SwCharFormat;
42 class SdrObject;
43 class SdrOle2Obj;
44 class OutlinerParaObject;
45 class SwNumFormat;
46 class SwTextNode;
47 class SwNoTextNode;
48 class SwFormatCharFormat;
49 class SwDoc;
50 class SwNumRule;
51 
52 namespace sw
53 {
54  namespace util
55  {
56  class ItemSort
57  {
58  public:
59  bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
60  };
61  }
62 }
63 
64 namespace ww8
65 {
67  typedef std::vector<SwTextFormatColl *> ParaStyles;
69  typedef std::map<sal_uInt16, const SfxPoolItem *, sw::util::ItemSort> PoolItems;
70 
87  class Frame
88  {
89  public:
91  private:
95  // #i43447# - Size of the frame in the layout.
96  // Especially needed for graphics, whose layout size can differ from its
97  // size, because it is scaled into its environment.
99 
103  bool mbForBullet:1;
105  public:
106  Frame(const SwFrameFormat &rFlyFrame, const SwPosition &rPos);
107  Frame(const Graphic&, const SwPosition &);
108 
114  const SwFrameFormat &GetFrameFormat() const { return *mpFlyFrame; }
115 
121  const SwPosition &GetPosition() const { return maPos; }
122  void SetPosition(SwPosition const& rPos) { maPos = rPos; }
123 
130  { return maPos.nNode.GetNode().GetContentNode(); }
131 
138 
144  bool IsInline() const { return mbIsInline; }
145 
154  void ForceTreatAsInline();
155 
161  const SwNode *GetContent() const { return mpStartFrameContent; }
162  const Graphic &GetGraphic() const { return maGrf; }
163  bool HasGraphic() const { return mbForBullet; }
164 
170  bool RefersToSameFrameAs(const Frame &rOther) const
171  {
172  if (mbForBullet && rOther.mbForBullet)
173  return (maGrf == rOther.maGrf);
174  else if ((!mbForBullet) && (!rOther.mbForBullet))
175  return (mpFlyFrame == rOther.mpFlyFrame);
176 
177  return false;
178  }
179 
185  const Size& GetSize() const { return maSize; }
186 
193  const Size& GetLayoutSize() const
194  {
195  return maLayoutSize;
196  }
197  };
198 
200  typedef std::vector<Frame> Frames;
202  typedef std::vector<Frame>::iterator FrameIter;
203 }
204 
205 namespace sw
206 {
207  namespace util
208  {
226  template<class T> const T & item_cast(const SfxPoolItem &rItem)
227  {
228  if (dynamic_cast<const T *>(&rItem) == nullptr)
229  throw std::bad_cast();
230  return static_cast<const T &>(rItem);
231  }
232 
248  template<class T> const T * item_cast(const SfxPoolItem *pItem)
249  {
250  return dynamic_cast<const T *>(pItem);
251  }
252 
275  template<class T> const T & ItemGet(const SwContentNode &rNode,
276  sal_uInt16 eType)
277  {
278  return item_cast<T>(rNode.GetAttr(eType));
279  }
280 
301  template<class T> const T & ItemGet(const SwFormat &rFormat,
302  sal_uInt16 eType)
303  {
304  return item_cast<T>(rFormat.GetFormatAttr(eType));
305  }
306 
329  template<class T> const T & ItemGet(const SfxItemSet &rSet,
330  sal_uInt16 eType)
331  {
332  return item_cast<T>(rSet.Get(eType));
333  }
334 
361  template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
362  sal_uInt16 eType)
363  {
364  return item_cast<T>(rPool.GetDefaultItem(eType));
365  }
366 
394  template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
395  sal_uInt16 eType)
396  {
397  return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
398  }
399 
411  ww8::ParaStyles GetParaStyles(const SwDoc &rDoc);
412 
426  SwTextFormatColl* GetParaStyle(SwDoc &rDoc, const OUString& rName);
427 
441  SwCharFormat* GetCharStyle(SwDoc &rDoc, const OUString& rName);
442 
456 
469  void GetPoolItems(const SfxItemSet &rSet, ww8::PoolItems &rItems, bool bExportParentItemSet );
470 
471  const SfxPoolItem *SearchPoolItems(const ww8::PoolItems &rItems,
472  sal_uInt16 eType);
473 
474  template<class T> const T* HasItem(const ww8::PoolItems &rItems,
475  sal_uInt16 eType)
476  {
477  return item_cast<T>(SearchPoolItems(rItems, eType));
478  }
479 
497  void ClearOverridesFromSet(const SwFormatCharFormat &rFormat, SfxItemSet &rSet);
498 
516  ww8::Frames GetFrames(const SwDoc &rDoc, SwPaM const *pPaM);
517 
519  void UpdateFramePositions(ww8::Frames & rFrames);
520 
533  ww8::Frames GetFramesInNode(const ww8::Frames &rFrames, const SwNode &rNode);
534 
550  const SwNumFormat* GetNumFormatFromTextNode(const SwTextNode &rTextNode);
551 
564  int nLevel);
565 
566  const SwNumRule* GetNumRuleFromTextNode(const SwTextNode &rTextNd);
567  const SwNumRule* GetNormalNumRuleFromTextNode(const SwTextNode &rTextNd);
568 
585 
596  bool HasPageBreak(const SwNode &rNode);
597 
610 
613 
624  class SetLayer
625  {
626  private:
628  enum Layer {eHeaven, eHell};
629  void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
630  public:
631 
637  void SendObjectToHell(SdrObject &rObject) const;
638 
644  void SendObjectToHeaven(SdrObject &rObject) const;
645 
652  explicit SetLayer(const SwDoc &rDoc);
653  };
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: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 drop-down 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