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
38class SwCharFormat;
39class SdrObject;
40class SdrOle2Obj;
42class SwNumFormat;
43class SwTextNode;
44class SwNoTextNode;
46class SwDoc;
47class SwNumRule;
48
49namespace sw
50{
51 namespace util
52 {
54 {
55 public:
56 bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
57 };
58 }
59}
60
61namespace 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
102 public:
103 Frame(const SwFrameFormat &rFlyFrame, SwPosition aPos);
104 Frame(const Graphic&, 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.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
202namespace 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
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);
417
434
445 bool HasPageBreak(const SwNode &rNode);
446
459
461 tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon& rPolyPoly, const SwNoTextNode* pNd, bool bCorrectCrop);
462
474 {
475 private:
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:
614 };
615 }
616}
617
618#endif
619
620/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Represents the style of a text portion.
Definition: charfmt.hxx:27
Definition: doc.hxx:192
Style of a layout element.
Definition: frmfmt.hxx:62
Layout frame for SwNoTextNode, i.e. graphics and OLE nodes (including charts).
Definition: ndnotxt.hxx:30
Base class of the Writer document model elements.
Definition: node.hxx:84
SwContentNode * GetContentNode()
Definition: node.hxx:643
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
Represents the style of a paragraph.
Definition: fmtcol.hxx:59
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:86
Make inserting an OLE object into a Writer document easy.
css::uno::Reference< css::embed::XEmbeddedObject > mxIPRef
DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc)=delete
DrawingOLEAdaptor(SdrOle2Obj &rObj, SfxObjectShell &rPers)
Take ownership of a SdrOle2Objs OLE object.
~DrawingOLEAdaptor()
Destructor will destroy the owned OLE object if not transferred.
bool TransferToDoc(OUString &rName)
Transfer ownership of the OLE object to a document's SvPersist.
DrawingOLEAdaptor & operator=(const DrawingOLEAdaptor &)=delete
bool operator()(sal_uInt16 nA, sal_uInt16 nB) const
Make setting a drawing object's layer in a Writer document easy.
void SendObjectToHeaven(SdrObject &rObject) const
Make Object lives in the top layer.
void SendObjectToHell(SdrObject &rObject) const
Make Object live in the bottom drawing layer.
void SetObjectLayer(SdrObject &rObject, Layer eLayer) const
SdrLayerID mnHellLayer
SetLayer(const SwDoc &rDoc)
Normal constructor.
SdrLayerID mnHeavenLayer
SdrLayerID mnFormLayer
Make exporting a Writer Frame easy.
void SetPosition(SwPosition const &rPos)
const Size & GetSize() const
The Size of the contained element.
Graphic maGrf
bool HasGraphic() const
const SwFrameFormat * mpFlyFrame
const Size & GetLayoutSize() const
The layout size of the contained element.
const Graphic & GetGraphic() const
WriterSource GetWriterType() const
Get the type of frame that this wraps.
bool RefersToSameFrameAs(const Frame &rOther) const
Does this ww8::Frame refer to the same writer content as another.
WriterSource meWriterType
const SwFrameFormat & GetFrameFormat() const
Get the writer SwFrameFormat that this object describes.
Frame(const SwFrameFormat &rFlyFrame, SwPosition aPos)
const SwNode * GetContent() const
Get the first node of content in the frame.
Size maLayoutSize
SwPosition maPos
bool IsInline() const
Is this frame inline (as character)
const SwPosition & GetPosition() const
Get the position this frame is anchored at.
const SwContentNode * GetContentNode() const
Get the node this frame is anchored into.
const SwNode * mpStartFrameContent
void ForceTreatAsInline()
Even if the frame isn't an inline frame, force it to behave as one.
DocumentType eType
sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool, const SfxItemPool &rSrcPool, sal_uInt16 nWhich)
Map an ID valid in one SfxItemPool to its equivalent in another.
sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet, const SwDoc &rDoc, sal_uInt16 nWhich)
Map a SwDoc WhichId to the equivalent Id for a given SfxItemSet.
ww8::ParaStyles GetParaStyles(const SwDoc &rDoc)
Get the Paragraph Styles of a SwDoc.
SwCharFormat * GetCharStyle(SwDoc &rDoc, const OUString &rName)
Get a Character Style which fits a given name.
tools::Polygon PolygonFromPolyPolygon(const tools::PolyPolygon &rPolyPoly)
Make a best fit Polygon from a PolyPolygon.
ww8::Frames GetFrames(const SwDoc &rDoc, SwPaM const *pPaM)
Get the Floating elements in a SwDoc.
const SwNumRule * GetNormalNumRuleFromTextNode(const SwTextNode &rTextNode)
const SwNumFormat * GetNumFormatFromTextNode(const SwTextNode &rTextNode)
Get the Numbering Format used on a paragraph.
void ClearOverridesFromSet(const SwFormatCharFormat &rFormat, SfxItemSet &rSet)
Remove properties from an SfxItemSet which a SwFormatCharFormat overrides.
const SwNumFormat * GetNumFormatFromSwNumRuleLevel(const SwNumRule &rRule, int nLevel)
Get the Numbering Format for a given level from a numbering rule.
const SwNumRule * GetNumRuleFromTextNode(const SwTextNode &rTextNode)
void GetPoolItems(const SfxItemSet &rSet, ww8::PoolItems &rItems, bool bExportParentItemSet)
Get the SfxPoolItems of a SfxItemSet.
const SfxPoolItem * SearchPoolItems(const ww8::PoolItems &rItems, sal_uInt16 eType)
const T & item_cast(const SfxPoolItem &rItem)
Provide a dynamic_cast style cast for SfxPoolItems.
SwNoTextNode * GetNoTextNodeFromSwFrameFormat(const SwFrameFormat &rFormat)
Get the SwNoTextNode associated with a SwFrameFormat if here is one.
SwTextFormatColl * GetParaStyle(SwDoc &rDoc, const OUString &rName)
Get a Paragraph Style which fits a given name.
void SortByAssignedOutlineStyleListLevel(ww8::ParaStyles &rStyles)
Sort sequence of Paragraph Styles by assigned outline style list level.
const T * HasItem(const ww8::PoolItems &rItems, sal_uInt16 eType)
bool HasPageBreak(const SwNode &rNd)
Does a node have a "page break before" applied.
ww8::Frames GetFramesInNode(const ww8::Frames &rFrames, const SwNode &rNode)
Get the Frames anchored to a given node.
void UpdateFramePositions(ww8::Frames &rFrames)
fix up frame positions, must be called after SetRedlineFlags
const SwCharFormat * GetSwCharFormat(const SwFormatINetFormat &rINet, SwDoc &rDoc)
Definition: ww8atr.cxx:1673
tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon &rPolyPoly, const SwNoTextNode *pNd, bool bCorrectCrop)
Undo all scaling / move tricks of the wrap polygon done during import.
Dialog to specify the properties of date form field.
std::vector< Frame > Frames
STL container of Frames.
std::map< sal_uInt16, const SfxPoolItem *, sw::util::ItemSort > PoolItems
STL container of SfxPoolItems (Attributes)
std::vector< SwTextFormatColl * > ParaStyles
STL container of Paragraph Styles (SwTextFormatColl)
std::vector< Frame >::iterator FrameIter
STL iterator for Frames.
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80