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 <vector>
24 #include <map>
25 #include <com/sun/star/embed/XEmbeddedObject.hpp>
26 
27 #include <sfx2/objsh.hxx>
28 #include <svl/itempool.hxx>
29 #include <svl/itemset.hxx>
30 #include <svx/svdtypes.hxx>
31 #include <node.hxx>
32 #include <pam.hxx>
33 #include <tools/poly.hxx>
34 #include <doc.hxx>
35 #include <vcl/graph.hxx>
36 
37 class SwTextFormatColl;
38 class SwCharFormat;
39 class SdrObject;
40 class SdrOle2Obj;
41 class OutlinerParaObject;
42 class SwNumFormat;
43 class SwTextNode;
44 class SwNoTextNode;
45 class SwFormatCharFormat;
46 class SwDoc;
47 class SwNumRule;
48 
49 namespace sw
50 {
51  namespace util
52  {
53  class ItemSort
54  {
55  public:
56  bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
57  };
58  }
59 }
60 
61 namespace ww8
62 {
64  typedef std::vector<SwTextFormatColl *> ParaStyles;
66  typedef std::map<sal_uInt16, const SfxPoolItem *, sw::util::ItemSort> PoolItems;
67 
84  class Frame
85  {
86  public:
88  private:
92  // #i43447# - Size of the frame in the layout.
93  // Especially needed for graphics, whose layout size can differ from its
94  // size, because it is scaled into its environment.
96 
99  bool mbIsInline;
100  bool mbForBullet:1;
102  public:
103  Frame(const SwFrameFormat &rFlyFrame, const SwPosition &rPos);
104  Frame(const Graphic&, const SwPosition &);
105 
111  const SwFrameFormat &GetFrameFormat() const { return *mpFlyFrame; }
112 
118  const SwPosition &GetPosition() const { return maPos; }
119  void SetPosition(SwPosition const& rPos) { maPos = rPos; }
120 
127  { return maPos.nNode.GetNode().GetContentNode(); }
128 
135 
141  bool IsInline() const { return mbIsInline; }
142 
151  void ForceTreatAsInline();
152 
158  const SwNode *GetContent() const { return mpStartFrameContent; }
159  const Graphic &GetGraphic() const { return maGrf; }
160  bool HasGraphic() const { return mbForBullet; }
161 
167  bool RefersToSameFrameAs(const Frame &rOther) const
168  {
169  if (mbForBullet && rOther.mbForBullet)
170  return (maGrf == rOther.maGrf);
171  else if ((!mbForBullet) && (!rOther.mbForBullet))
172  return (mpFlyFrame == rOther.mpFlyFrame);
173 
174  return false;
175  }
176 
182  const Size& GetSize() const { return maSize; }
183 
190  const Size& GetLayoutSize() const
191  {
192  return maLayoutSize;
193  }
194  };
195 
197  typedef std::vector<Frame> Frames;
199  typedef std::vector<Frame>::iterator FrameIter;
200 }
201 
202 namespace sw
203 {
204  namespace util
205  {
223  template<class T> const T & item_cast(const SfxPoolItem &rItem)
224  {
225  assert(dynamic_cast<const T *>(&rItem) && "bad type cast");
226  return static_cast<const T &>(rItem);
227  }
228 
244  template<class T> const T * item_cast(const SfxPoolItem *pItem)
245  {
246  return dynamic_cast<const T *>(pItem);
247  }
248 
260  ww8::ParaStyles GetParaStyles(const SwDoc &rDoc);
261 
275  SwTextFormatColl* GetParaStyle(SwDoc &rDoc, const OUString& rName);
276 
290  SwCharFormat* GetCharStyle(SwDoc &rDoc, const OUString& rName);
291 
305 
318  void GetPoolItems(const SfxItemSet &rSet, ww8::PoolItems &rItems, bool bExportParentItemSet );
319 
320  const SfxPoolItem *SearchPoolItems(const ww8::PoolItems &rItems,
321  sal_uInt16 eType);
322 
323  template<class T> const T* HasItem(const ww8::PoolItems &rItems,
324  sal_uInt16 eType)
325  {
326  return item_cast<T>(SearchPoolItems(rItems, eType));
327  }
328 
346  void ClearOverridesFromSet(const SwFormatCharFormat &rFormat, SfxItemSet &rSet);
347 
365  ww8::Frames GetFrames(const SwDoc &rDoc, SwPaM const *pPaM);
366 
368  void UpdateFramePositions(ww8::Frames & rFrames);
369 
382  ww8::Frames GetFramesInNode(const ww8::Frames &rFrames, const SwNode &rNode);
383 
399  const SwNumFormat* GetNumFormatFromTextNode(const SwTextNode &rTextNode);
400 
413  int nLevel);
414 
415  const SwNumRule* GetNumRuleFromTextNode(const SwTextNode &rTextNd);
416  const SwNumRule* GetNormalNumRuleFromTextNode(const SwTextNode &rTextNd);
417 
434 
445  bool HasPageBreak(const SwNode &rNode);
446 
459 
461  tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon& rPolyPoly, const SwNoTextNode* pNd, bool bCorrectCrop);
462 
473  class SetLayer
474  {
475  private:
477  enum Layer {eHeaven, eHell};
478  void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
479  public:
480 
486  void SendObjectToHell(SdrObject &rObject) const;
487 
493  void SendObjectToHeaven(SdrObject &rObject) const;
494 
501  explicit SetLayer(const SwDoc &rDoc);
502  };
503 
504  const SwCharFormat* GetSwCharFormat(const SwFormatINetFormat& rINet, SwDoc& rDoc);
505  }
506 
507  namespace hack
508  {
530  sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
531  const SfxItemPool &rSrcPool, sal_uInt16 nWhich);
532 
557  sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
558  const SwDoc &rDoc, sal_uInt16 nWhich);
559 
575  {
576  private:
577  css::uno::Reference < css::embed::XEmbeddedObject > mxIPRef;
580  public:
591 
594 
610  bool TransferToDoc(OUString &rName);
611  private:
613  DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc) = delete;
614  };
615  }
616 }
617 
618 #endif
619 
620 /* 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:187
SwNode & GetNode() const
Definition: ndindex.hxx:128
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:1656
const SwFrameFormat & GetFrameFormat() const
Get the writer SwFrameFormat that this object describes.
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.
void SortByAssignedOutlineStyleListLevel(ww8::ParaStyles &rStyles)
Sort sequence of Paragraph Styles by assigned outline style list level.
SwContentNode * GetContentNode()
Definition: node.hxx:625
bool RefersToSameFrameAs(const Frame &rOther) const
Does this ww8::Frame refer to the same writer content as another.
const Graphic & GetGraphic() const
Layout frame for SwNoTextNode, i.e. graphics and OLE nodes (including charts).
Definition: ndnotxt.hxx:29
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
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
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
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.
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.
std::vector< Frame > Frames
STL container of Frames.
Base class of the Writer document model elements.
Definition: node.hxx:81