42 #include <com/sun/star/document/XActionLockable.hpp>
43 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
44 #include <com/sun/star/text/SizeType.hpp>
45 #include <com/sun/star/text/TextContentAnchorType.hpp>
46 #include <com/sun/star/text/WrapTextMode.hpp>
47 #include <com/sun/star/text/XTextDocument.hpp>
48 #include <com/sun/star/text/XTextFrame.hpp>
49 #include <com/sun/star/table/BorderLine2.hpp>
50 #include <com/sun/star/text/WritingMode.hpp>
51 #include <com/sun/star/text/WritingMode2.hpp>
52 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
53 #include <com/sun/star/style/ParagraphAdjust.hpp>
64 OUString sCopyableText;
70 uno::Reference<text::XText> xSrcCnt(pSdrShape->getWeakUnoShape(), uno::UNO_QUERY);
71 auto xCur = xSrcCnt->createTextCursor();
72 xCur->gotoStart(
false);
74 sCopyableText = xCur->getText()->getString();
79 uno::Reference<text::XTextContent> xTextFrame(
82 uno::Reference<text::XTextDocument> xTextDocument(
84 uno::Reference<text::XTextContentAppend> xTextContentAppend(xTextDocument->getText(),
89 uno::Reference<text::XTextContent> XSourceShape(pSourceSDRShape->
getUnoShape(),
90 uno::UNO_QUERY_THROW);
91 xTextContentAppend->insertTextContentWithProperties(
92 xTextFrame, uno::Sequence<beans::PropertyValue>(), XSourceShape->getAnchor());
94 catch (uno::Exception&)
96 xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>());
99 uno::Reference<text::XTextFrame> xRealTextFrame(xTextFrame, uno::UNO_QUERY);
100 auto pTextFrame =
dynamic_cast<SwXTextFrame*
>(xRealTextFrame.get());
101 assert(
nullptr != pTextFrame);
104 assert(
nullptr != dynamic_cast<SwDrawFrameFormat*>(pShape));
105 assert(
nullptr != dynamic_cast<SwFlyFrameFormat*>(pFormat));
111 uno::Reference<beans::XPropertySet> xPropertySet(xTextFrame, uno::UNO_QUERY);
124 uno::Reference<container::XNamed> xNamed(xTextFrame, uno::UNO_QUERY);
128 uno::Reference<text::XTextRange> xTextBox(xTextFrame, uno::UNO_QUERY_THROW);
143 uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
164 text::WritingMode
eMode;
171 if (bCopyText && !sCopyableText.isEmpty())
176 auto pSourceText =
dynamic_cast<SdrTextObj*
>(pSdrShape);
177 uno::Reference<text::XTextRange> xDestText(xRealTextFrame, uno::UNO_QUERY);
179 xDestText->setString(sCopyableText);
182 pSourceText->SetText(OUString());
218 if (pOtherFormat->
Which() != nOtherType)
230 uno::Reference<drawing::XShape> xShape(pObj->
getWeakUnoShape(), uno::UNO_QUERY);
253 for (
const auto pFormat : rSpzFrameFormats)
264 throw lang::IndexOutOfBoundsException();
273 if (nCount == nIndex)
282 throw lang::IndexOutOfBoundsException();
291 sal_Int32 nOrder = 0;
292 for (std::size_t
i = 0;
i < pPage->GetObjCount(); ++
i)
303 SAL_WARN(
"sw.core",
"SwTextBoxHelper::getOrdNum: no page or page doesn't contain the object");
317 if (!isTextBox(pFormat, nType))
324 auto pShape =
dynamic_cast<SwXShape*
>(xShape.get());
332 uno::Reference<text::XTextFrame>
340 auto pSdrObj = pFrameFormat->FindSdrObject();
341 if (pSdrObj && pSdrObj->IsTextBox())
343 return uno::Reference<css::text::XTextFrame>(pSdrObj->getUnoShape(),
348 return uno::Reference<css::text::XTextFrame>();
355 uno::Reference<T>
const xInterface(
367 lcl_queryInterface<text::XTextAppend>(pShape, aRet);
371 lcl_queryInterface<text::XText>(pShape, aRet);
375 lcl_queryInterface<text::XTextRange>(pShape, aRet);
392 uno::Reference<document::XActionLockable> xLockable(pCustomShape->getUnoShape(),
394 sal_Int16 nLocks = 0;
396 nLocks = xLockable->resetActionLocks();
399 xLockable->setActionLocks(nLocks);
404 aRet = pSdrShape->GetCurrentBoundRect();
407 if (!bAbsolute && pSdrShape)
410 Point aPoint(pSdrShape->GetSnapRect().Center());
411 Size aSize(pSdrShape->GetLogicRect().GetSize());
412 aPoint.AdjustX(-(aSize.Width() / 2));
413 aPoint.AdjustY(-(aSize.Height() / 2));
415 aRet.
Move(-1 * aLogicRect.
Left(), -1 * aLogicRect.
Top());
422 const css::uno::Any& rValue)
432 uno::Reference<text::XTextCursor> xCursor = xTextFrame->getText()->createTextCursor();
435 xCursor->gotoStart(
false);
436 xCursor->gotoEnd(
true);
437 uno::Reference<beans::XPropertySet> xFrameParaProps(xCursor, uno::UNO_QUERY);
440 const auto eValue = rValue.get<drawing::TextHorizontalAdjust>();
443 case drawing::TextHorizontalAdjust::TextHorizontalAdjust_CENTER:
444 xFrameParaProps->setPropertyValue(
446 uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_CENTER));
448 case drawing::TextHorizontalAdjust::TextHorizontalAdjust_LEFT:
449 xFrameParaProps->setPropertyValue(
451 uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_LEFT));
453 case drawing::TextHorizontalAdjust::TextHorizontalAdjust_RIGHT:
454 xFrameParaProps->setPropertyValue(
456 uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_RIGHT));
460 "SwTextBoxHelper::syncProperty: unhandled TextHorizontalAdjust: "
461 << static_cast<sal_Int32>(eValue));
467 if (rPropertyName ==
u"CustomShapeGeometry")
489 auto it = aCustomShapeGeometry.
find(
"TextPreRotateAngle");
490 if (it == aCustomShapeGeometry.
end())
492 it = aCustomShapeGeometry.
find(
"TextRotateAngle");
495 if (it != aCustomShapeGeometry.
end())
497 auto nAngle = it->second.has<sal_Int32>() ? it->second.get<sal_Int32>() : 0;
500 nAngle = it->second.has<
double>() ? it->second.get<
double>() : 0;
503 sal_Int16 nDirection = 0;
507 nDirection = text::WritingMode2::TB_RL;
510 nDirection = text::WritingMode2::BT_LR;
513 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled property value: "
514 "CustomShapeGeometry:TextPreRotateAngle: "
539 text::WritingMode
eMode;
541 if (rValue >>= eMode)
543 else if (rValue >>= eMode2)
547 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled property: "
548 << static_cast<OUString>(rPropertyName));
552 css::uno::Any& rValue)
579 SAL_WARN(
"sw.core",
"SwTextBoxHelper::getProperty: unhandled member-id: "
580 << static_cast<sal_uInt16>(nMemberID));
594 uno::Reference<beans::XPropertySet>
const xPropertySet(
597 return xPropertySet->getPropertyValue(sPropName);
601 const css::uno::Any& rValue)
614 OUString aPropertyName;
615 bool bAdjustX =
false;
616 bool bAdjustY =
false;
617 bool bAdjustSize =
false;
634 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled member-id: "
635 << static_cast<sal_uInt16>(nMemberID)
636 <<
" (which-id: " << nWID <<
")");
651 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled member-id: "
652 << static_cast<sal_uInt16>(nMemberID)
653 <<
" (which-id: " << nWID <<
")");
672 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled member-id: "
673 << static_cast<sal_uInt16>(nMemberID)
674 <<
" (which-id: " << nWID <<
")");
704 uno::Reference<beans::XPropertySet>
const xPropertySet(
711 if (aValue.get<text::TextContentAnchorType>()
712 == text::TextContentAnchorType::TextContentAnchorType_AS_CHARACTER)
714 xPropertySet->setPropertyValue(
717 text::TextContentAnchorType::TextContentAnchorType_AT_PARAGRAPH));
725 if (aValue.get<text::TextContentAnchorType>()
726 == text::TextContentAnchorType::TextContentAnchorType_AT_PAGE)
728 xPropertySet->setPropertyValue(
733 if (aValue.get<text::TextContentAnchorType>()
734 == text::TextContentAnchorType::TextContentAnchorType_AT_PARAGRAPH
735 || aValue.get<text::TextContentAnchorType>()
736 == text::TextContentAnchorType::TextContentAnchorType_AT_CHARACTER)
748 "SwTextBoxHelper::syncProperty: Anchor without content!");
754 aNewHOri.
SetPos(aNewHOri.GetPos() + aRect.
getX());
756 aNewVOri.
SetPos(aNewVOri.GetPos() + aRect.
getY());
764 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled member-id: "
765 << static_cast<sal_uInt16>(nMemberID)
766 <<
" (which-id: " << nWID <<
")");
772 uno::Reference<text::XTextRange> xRange;
793 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled member-id: "
794 << static_cast<sal_uInt16>(nMemberID)
795 <<
" (which-id: " << nWID <<
")");
818 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled member-id: "
819 << static_cast<sal_uInt16>(nMemberID)
820 <<
" (which-id: " << nWID <<
")");
837 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled member-id: "
838 << static_cast<sal_uInt16>(nMemberID)
839 <<
" (which-id: " << nWID <<
")");
844 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncProperty: unhandled which-id: "
845 << nWID <<
" (member-id: " << static_cast<sal_uInt16>(nMemberID)
850 if (aPropertyName.isEmpty())
854 if (bAdjustX || bAdjustY || bAdjustSize)
859 if (bAdjustX || bAdjustY)
862 if (aValue >>= nValue)
871 else if (bAdjustSize)
880 uno::Reference<beans::XPropertySet>
const xPropertySet(
882 xPropertySet->setPropertyValue(aPropertyName, aValue);
886 std::map<const SwFrameFormat*, const SwFrameFormat*>& rLinks)
888 for (
const auto pFormat : rFormats)
891 rLinks[pFormat] = pTextBox;
899 for (
const auto& rIt : rOld)
901 auto aTextBoxIt = rSavedLinks.find(rIt.GetFormat());
902 if (aTextBoxIt != rSavedLinks.end())
905 for (
const auto& rJt : rOld)
907 if (rJt.GetFormat() == aTextBoxIt->second)
908 rNew[i]->SetFormatAttr(rNew[j]->GetContent());
918 text::TextContentAnchorType aAnchorType;
921 case RndStdIds::FLY_AS_CHAR:
922 aAnchorType = text::TextContentAnchorType::TextContentAnchorType_AS_CHARACTER;
924 case RndStdIds::FLY_AT_CHAR:
925 aAnchorType = text::TextContentAnchorType::TextContentAnchorType_AT_CHARACTER;
927 case RndStdIds::FLY_AT_PARA:
928 aAnchorType = text::TextContentAnchorType::TextContentAnchorType_AT_PARAGRAPH;
930 case RndStdIds::FLY_AT_PAGE:
931 aAnchorType = text::TextContentAnchorType::TextContentAnchorType_AT_PAGE;
933 case RndStdIds::FLY_AT_FLY:
934 aAnchorType = text::TextContentAnchorType::TextContentAnchorType_AT_FRAME;
937 aAnchorType = text::TextContentAnchorType::TextContentAnchorType_AT_PARAGRAPH;
938 SAL_WARN(
"sw.core",
"SwTextBoxHelper::mapAnchorType: Unknown AnchorType!");
957 switch (pItem->
Which())
962 const text::TextContentAnchorType aNewAnchorType
975 aTextBoxSet.Put(aOrient);
982 aTextBoxSet.Put(aSize);
989 const text::TextContentAnchorType aNewAnchorType
1002 aTextBoxSet.Put(aOrient);
1016 if (!aRect.IsEmpty())
1018 aVertOrient.SetPos(aVertOrient.GetPos() + aRect.getY());
1019 aTextBoxSet.Put(aVertOrient);
1021 aHoriOrient.SetPos(aHoriOrient.GetPos() + aRect.getX());
1022 aTextBoxSet.Put(aHoriOrient);
1024 aSize.SetWidth(aRect.getWidth());
1025 aSize.SetHeight(aRect.getHeight());
1026 aTextBoxSet.Put(aSize);
1036 const text::TextContentAnchorType aNewAnchorType
1043 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncFlyFrameAttr: The anchor of the "
1044 "shape different from the textframe!");
1049 SAL_WARN(
"sw.core",
"SwTextBoxHelper::syncFlyFrameAttr: unhandled which-id: "
1054 pItem = aIter.NextItem();
1055 }
while (pItem && (0 != pItem->
Which()));
1057 if (aTextBoxSet.Count())
1065 uno::Reference<drawing::XShape> xShape(pObj->
getUnoShape(), uno::UNO_QUERY);
1068 uno::Reference<beans::XPropertySet>
const xPropertySet(xShape, uno::UNO_QUERY);
1070 auto pParentFormat = getOtherTextBoxFormat(getOtherTextBoxFormat(xShape),
RES_FLYFRMFMT);
1091 const bool bIsAutoGrow
1098 uno::Any(bIsAutoWrap ? text::SizeType::FIX : text::SizeType::MIN));
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(120)
const css::uno::WeakReference< css::uno::XInterface > & getWeakUnoShape() const
#define UNO_NAME_TEXT_WORDWRAP
static sal_Int32 getCount(const SwDoc &rDoc)
Count number of shapes in the document, excluding TextBoxes.
static css::uno::Any getByIndex(SdrPage const *pPage, sal_Int32 nIndex)
Get a shape by index, excluding TextBoxes.
void SetHeight(tools::Long n)
#define UNO_NAME_HORI_ORIENT_POSITION
#define UNO_NAME_TEXT_RIGHTDIST
SwDocShell * GetDocShell()
#define UNO_NAME_BOTTOM_BORDER
static bool hasTextFrame(const SdrObject *pObj)
Returns true if the SdrObject has a SwTextFrame otherwise false.
#define UNO_NAME_RELATIVE_HEIGHT_RELATION
#define UNO_NAME_IS_FOLLOWING_TEXT_FLOW
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
static void destroy(SwFrameFormat *pShape)
Destroy a TextBox for a shape.
#define UNO_NAME_ALLOW_OVERLAP
constexpr TypedWhichId< SdrTextVertAdjustItem > RES_TEXT_VERT_ADJUST(130)
virtual void SetModified()=0
Must be called manually at changes of format.
#define MID_VERTORIENT_RELATION
static sal_Int32 getOrdNum(const SdrObject *pObject)
Get the order of the shape, excluding TextBoxes.
#define UNO_NAME_TEXT_LOWERDIST
SdrObject * GetObj(size_t nNum) const
virtual bool IsTextBox() const
size_t GetObjCount() const
OUString GetUniqueFrameName() const
#define RIGHT_BORDER_DISTANCE
Content, content of frame (header, footer, fly).
constexpr TypedWhichId< SvxOpaqueItem > RES_OPAQUE(99)
#define UNO_NAME_WRITING_MODE
#define UNO_NAME_ANCHOR_PAGE_NO
#define UNO_NAME_VERT_ORIENT
#define UNO_NAME_TEXT_UPPERDIST
EmbeddedObjectRef * pObject
static SwFrameFormat * getOtherTextBoxFormat(const SwFrameFormat *pFormat, sal_uInt16 nType)
If we have an associated TextFrame, then return that.
const SwFrameFormats * GetSpzFrameFormats() const
std::map< const SwFrameFormat *, const SwFrameFormat * > SavedLink
Maps a draw format to a fly format.
static css::uno::Any queryInterface(const SwFrameFormat *pShape, const css::uno::Type &rType)
Get interface of a shape's TextBox, if there is any.
virtual const tools::Rectangle & GetSnapRect() const
constexpr auto convertTwipToMm100(N n)
static css::uno::Reference< css::text::XTextFrame > getUnoTextFrame(css::uno::Reference< css::drawing::XShape > const &xShape)
If we have an associated TextFrame, then return its XTextFrame.
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(102)
#define UNO_NAME_RELATIVE_WIDTH_RELATION
#define UNO_NAME_CHAIN_NEXT_NAME
virtual css::uno::Reference< css::uno::XInterface > getUnoShape()
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
SdrPage * getSdrPageFromSdrObject() const
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
#define MID_FOLLOW_TEXT_FLOW
virtual void DelLayoutFormat(SwFrameFormat *pFormat)=0
static bool isTextBox(const SwFrameFormat *pFormat, sal_uInt16 nType)
Is the frame format a text box?
#define UNO_NAME_VERT_ORIENT_RELATION
#define UNO_NAME_TEXT_WRITINGMODE
css::uno::Reference< css::frame::XModel > GetBaseModel() const
constexpr TypedWhichId< SwFormatWrapInfluenceOnObjPos > RES_WRAP_INFLUENCE_ON_OBJPOS(125)
#define LEFT_BORDER_DISTANCE
static void saveLinks(const SwFrameFormats &rFormats, std::map< const SwFrameFormat *, const SwFrameFormat * > &rLinks)
Saves the current shape -> textbox links in a map, so they can be restored later. ...
static void lcl_queryInterface(const SwFrameFormat *pShape, uno::Any &rAny)
#define UNO_NAME_HORI_ORIENT
#define MID_CHAIN_NEXTNAME
static void create(SwFrameFormat *pShape, bool bCopyText=false)
Create a TextBox for a shape.
#define MID_ANCHOR_ANCHORTYPE
#define MID_HORIORIENT_POSITION
static void updateTextBoxMargin(SdrObject *pObj)
Copy shape attributes to the text frame.
#define UNO_NAME_RIGHT_BORDER
#define MID_FRMSIZE_WIDTH_TYPE
#define UNO_NAME_FILL_TRANSPARENCE
static void restoreLinks(std::set< ZSortFly > &rOld, std::vector< SwFrameFormat * > &rNew, SavedLink &rSavedLinks)
Undo the effect of saveLinks() + individual resetLink() calls.
#define UNO_NAME_PARA_ADJUST
#define MID_VERTORIENT_POSITION
#define BOTTOM_BORDER_DISTANCE
static css::text::TextContentAnchorType mapAnchorType(const RndStdIds &rAnchorID)
There are two types of enum of anchor type, so this function maps this.
static void getProperty(SwFrameFormat const *pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, css::uno::Any &rValue)
Get a property of the underlying TextFrame.
sal_uInt32 GetOrdNum() const
IDocumentState const & getIDocumentState() const
#define UNO_NAME_LEFT_BORDER
#define MID_FRMSIZE_IS_AUTO_HEIGHT
#define UNO_NAME_LEFT_BORDER_DISTANCE
#define UNO_NAME_CHAIN_PREV_NAME
bool SetFlyFrameAttr(SwFrameFormat &rFlyFormat, SfxItemSet &rSet)
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
constexpr TypedWhichId< SwFormatContent > RES_CNTNT(95)
bool XTextRangeToSwPaM(SwUnoInternalPaM &rToFill, const uno::Reference< text::XTextRange > &xTextRange,::sw::TextRangeMode const eMode)
#define UNO_NAME_RIGHT_MARGIN
#define UNO_NAME_TOP_BORDER
sal_uInt16 const aFrameFormatSetRange[]
#define UNO_NAME_TOP_BORDER_DISTANCE
#define UNO_NAME_TEXT_VERT_ADJUST
#define UNO_NAME_SURROUND
#define MID_HORIORIENT_ORIENT
#define MID_FRMSIZE_REL_HEIGHT_RELATION
constexpr TypedWhichId< SwFormatChain > RES_CHAIN(114)
#define MID_CHAIN_PREVNAME
iterator find(const OUString &rKey)
Any makeAny(Color const &value)
#define UNO_NAME_LEFT_MARGIN
#define MID_VERTORIENT_ORIENT
#define UNO_NAME_BOTTOM_BORDER_DISTANCE
#define UNO_NAME_ANCHOR_TYPE
#define UNO_NAME_TEXT_LEFTDIST
#define MID_FRMSIZE_REL_WIDTH_RELATION
#define UNO_NAME_HORI_ORIENT_RELATION
static SW_DLLPUBLIC css::uno::Reference< css::text::XTextFrame > CreateXTextFrame(SwDoc &rDoc, SwFrameFormat *pFrameFormat)
#define TOP_BORDER_DISTANCE
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
#define UNO_NAME_TEXT_AUTOGROWHEIGHT
static css::uno::Reference< css::uno::XInterface > MakeInstance(SwServiceType nObjectType, SwDoc &rDoc)
bool GetTextBounds(tools::Rectangle &rTextBound) const
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
static tools::Rectangle getTextRectangle(SwFrameFormat *pShape, bool bAbsolute=true)
Return the textbox rectangle of a draw shape (in twips).
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(157)
constexpr TypedWhichId< SvxBoxItem > RES_BOX(106)
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(154)
#define UNO_NAME_FRAME_ISAUTOMATIC_HEIGHT
#define MID_HORIORIENT_RELATION
#define UNO_NAME_TEXT_HORZADJUST
static void syncFlyFrameAttr(SwFrameFormat &rShape, SfxItemSet const &rSet)
Similar to syncProperty(), but used by the internal API (e.g. for UI purposes).
#define SAL_WARN(area, stream)
static void syncProperty(SwFrameFormat *pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, const css::uno::Any &rValue)
Sync property of TextBox with the one of the shape.
#define UNO_NAME_SIZE_TYPE
#define UNO_NAME_RIGHT_BORDER_DISTANCE
#define UNO_NAME_WIDTH_TYPE
#define UNO_NAME_VERT_ORIENT_POSITION
constexpr TypedWhichId< SwFormatFollowTextFlow > RES_FOLLOW_TEXT_FLOW(123)
constexpr TypedWhichId< SwFormatAnchor > RES_ANCHOR(104)
const SwAttrPool & GetAttrPool() const
#define MID_ALLOW_OVERLAP
static void getShapeWrapThrough(const SwFrameFormat *pTextBox, bool &rWrapThrough)
If pTextBox is a textbox, then set rWrapThrough to the surround of its shape.
#define UNO_NAME_TEXT_VERTADJUST