summaryrefslogtreecommitdiff
path: root/sw/source/core/doc/docdraw.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/core/doc/docdraw.cxx')
-rw-r--r--sw/source/core/doc/docdraw.cxx98
1 files changed, 83 insertions, 15 deletions
diff --git a/sw/source/core/doc/docdraw.cxx b/sw/source/core/doc/docdraw.cxx
index c070519cfbf9..f5a37d00ab21 100644
--- a/sw/source/core/doc/docdraw.cxx
+++ b/sw/source/core/doc/docdraw.cxx
@@ -24,6 +24,7 @@
#include <svx/svdogrp.hxx>
#include <editeng/measfld.hxx>
#include <sal/log.hxx>
+#include <osl/diagnose.h>
#include <fmtanchr.hxx>
#include <charatr.hxx>
#include <frmfmt.hxx>
@@ -53,7 +54,6 @@
#include <vector>
using namespace ::com::sun::star;
-using namespace ::com::sun::star::linguistic2;
/** local method to determine positioning and alignment attributes for a drawing
* object, which is newly connected to the layout.
@@ -94,7 +94,7 @@ static void lcl_AdjustPositioningAttr( SwDrawFrameFormat* _pFrameFormat,
// If no anchor frame exist - e.g. because no layout exists - the
// default layout direction is taken.
const SvxFrameDirectionItem& rDirItem =
- _pFrameFormat->GetAttrSet().GetPool()->GetDefaultItem( RES_FRAMEDIR );
+ _pFrameFormat->GetAttrSet().GetPool()->GetUserOrPoolDefaultItem( RES_FRAMEDIR );
switch ( rDirItem.GetValue() )
{
case SvxFrameDirection::Vertical_LR_TB:
@@ -134,7 +134,7 @@ static void lcl_AdjustPositioningAttr( SwDrawFrameFormat* _pFrameFormat,
}
// use geometry of drawing object
- const SwRect aObjRect = _rSdrObj.GetSnapRect();
+ const tools::Rectangle aObjRect = _rSdrObj.GetSnapRect();
if ( bVert )
{
@@ -171,9 +171,9 @@ static void lcl_AdjustPositioningAttr( SwDrawFrameFormat* _pFrameFormat,
const SwAnchoredObject* pAnchoredObj = pContact->GetAnchoredObj( &_rSdrObj );
if ( auto pAnchoredDrawObj = dynamic_cast<const SwAnchoredDrawObject*>( pAnchoredObj) )
{
- const SwRect aObjRect = _rSdrObj.GetSnapRect();
+ const tools::Rectangle aObjRect = _rSdrObj.GetSnapRect();
const_cast<SwAnchoredDrawObject*>(pAnchoredDrawObj)
- ->SetLastObjRect( aObjRect.SVRect() );
+ ->SetLastObjRect( aObjRect );
}
}
}
@@ -198,7 +198,7 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
std::unique_ptr<SwUndoDrawGroup> pUndo;
if (GetIDocumentUndoRedo().DoesUndo())
- pUndo.reset(new SwUndoDrawGroup( static_cast<sal_uInt16>(rMrkList.GetMarkCount()), *this));
+ pUndo.reset(new SwUndoDrawGroup( o3tl::narrowing<sal_uInt16>(rMrkList.GetMarkCount()), *this));
// #i53320#
bool bGroupMembersNotPositioned( false );
@@ -207,6 +207,8 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
static_cast<SwAnchoredDrawObject*>(pMyContact->GetAnchoredObj( pObj ));
bGroupMembersNotPositioned = pAnchoredDrawObj->NotYetPositioned();
}
+
+ std::map<const SdrObject*, SwFrameFormat*> vSavedTextBoxes;
// Destroy ContactObjects and formats.
for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
@@ -220,6 +222,11 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
OSL_ENSURE( bGroupMembersNotPositioned == pAnchoredDrawObj->NotYetPositioned(),
"<SwDoc::GroupSelection(..)> - group members have different positioning status!" );
#endif
+ // Before the format will be killed, save its textbox for later use.
+ if (auto pShapeFormat = pContact->GetFormat())
+ if (auto pTextBoxNode = pShapeFormat->GetOtherTextBoxFormats())
+ for (const auto& rTextBoxElement : pTextBoxNode->GetAllTextBoxes())
+ vSavedTextBoxes.emplace(rTextBoxElement);
pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
// Deletes itself!
@@ -246,6 +253,18 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
pFormat->SetPositionLayoutDir(
text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
+ // Add the saved textboxes to the new format.
+ auto pTextBoxNode = std::make_shared<SwTextBoxNode>(
+ SwTextBoxNode(static_cast<SwFrameFormat*>(pFormat)));
+ for (const auto& pTextBoxEntry : vSavedTextBoxes)
+ {
+ pTextBoxNode->AddTextBox(const_cast<SdrObject*>(pTextBoxEntry.first),
+ pTextBoxEntry.second);
+ pTextBoxEntry.second->SetOtherTextBoxFormats(pTextBoxNode);
+ }
+ pFormat->SetOtherTextBoxFormats(pTextBoxNode);
+ vSavedTextBoxes.clear();
+
rDrawView.GroupMarked();
OSL_ENSURE( rMrkList.GetMarkCount() == 1, "GroupMarked more or none groups." );
@@ -283,6 +302,27 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
return pNewContact;
}
+static void lcl_CollectTextBoxesForSubGroupObj(SwFrameFormat* pTargetFormat, std::shared_ptr<SwTextBoxNode> pTextBoxNode,
+ SdrObject* pSourceObjs)
+{
+ if (auto pChildrenObjs = pSourceObjs->getChildrenOfSdrObject())
+ for (const rtl::Reference<SdrObject>& pSubObj : *pChildrenObjs)
+ lcl_CollectTextBoxesForSubGroupObj(pTargetFormat, pTextBoxNode, pSubObj.get());
+ else
+ {
+ if (auto pTextBox = pTextBoxNode->GetTextBox(pSourceObjs))
+ {
+ if (!pTargetFormat->GetOtherTextBoxFormats())
+ {
+ pTargetFormat->SetOtherTextBoxFormats(std::make_shared<SwTextBoxNode>(SwTextBoxNode(pTargetFormat)));
+ }
+ pTargetFormat->GetOtherTextBoxFormats()->AddTextBox(pSourceObjs, pTextBox);
+ pTextBox->SetOtherTextBoxFormats(pTargetFormat->GetOtherTextBoxFormats());
+ }
+ }
+}
+
+
void SwDoc::UnGroupSelection( SdrView& rDrawView )
{
bool const bUndo = GetIDocumentUndoRedo().DoesUndo();
@@ -310,6 +350,11 @@ void SwDoc::UnGroupSelection( SdrView& rDrawView )
if ( auto pObjGroup = dynamic_cast<SdrObjGroup*>(pObj) )
{
SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
+
+ std::shared_ptr<SwTextBoxNode> pTextBoxNode;
+ if (auto pGroupFormat = pContact->GetFormat())
+ pTextBoxNode = pGroupFormat->GetOtherTextBoxFormats();
+
SwFormatAnchor aAnch( pContact->GetFormat()->GetAnchor() );
SdrObjList *pLst = pObjGroup->GetSubList();
@@ -326,13 +371,33 @@ void SwDoc::UnGroupSelection( SdrView& rDrawView )
SwDrawFrameFormat *pFormat = MakeDrawFrameFormat( GetUniqueShapeName(),
GetDfltFrameFormat() );
pFormat->SetFormatAttr( aAnch );
+
+ if (pTextBoxNode)
+ {
+ if (!pObj->getChildrenOfSdrObject())
+ {
+ if (auto pTextBoxFormat = pTextBoxNode->GetTextBox(pSubObj))
+ {
+ auto pNewTextBoxNode =std::make_shared<SwTextBoxNode>(SwTextBoxNode(pFormat));
+ pNewTextBoxNode->AddTextBox(pSubObj, pTextBoxFormat);
+ pFormat->SetOtherTextBoxFormats(pNewTextBoxNode);
+ pTextBoxFormat->SetOtherTextBoxFormats(pNewTextBoxNode);
+ }
+ }
+ else
+ {
+ lcl_CollectTextBoxesForSubGroupObj(pFormat, pTextBoxNode, pSubObj);
+ }
+ }
// #i36010# - set layout direction of the position
pFormat->SetPositionLayoutDir(
text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
+ if (pSubObj->GetName().isEmpty())
+ pSubObj->SetName(pFormat->GetName());
pFormatsAndObjs[i].emplace_back( pFormat, pSubObj );
if( bUndo )
- pUndo->AddObj( static_cast<sal_uInt16>(i2), pFormat );
+ pUndo->AddObj( o3tl::narrowing<sal_uInt16>(i2), pFormat );
}
}
}
@@ -397,14 +462,17 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView )
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
if( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) == nullptr )
{
- SwDrawContact *pC = static_cast<SwDrawContact*>(GetUserCall(pObj));
- SwDrawFrameFormat *pFrameFormat = static_cast<SwDrawFrameFormat*>(pC->GetFormat());
- if( pFrameFormat &&
- RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId() )
+ if (SwDrawContact* pC = static_cast<SwDrawContact*>(GetUserCall(pObj)))
{
- rDrawView.MarkObj( pObj, rDrawView.Imp().GetPageView(), true );
- --i;
- getIDocumentLayoutAccess().DelLayoutFormat( pFrameFormat );
+ SwDrawFrameFormat* pFrameFormat
+ = static_cast<SwDrawFrameFormat*>(pC->GetFormat());
+ if (pFrameFormat
+ && RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId())
+ {
+ rDrawView.MarkObj(pObj, rDrawView.Imp().GetPageView(), true);
+ --i;
+ getIDocumentLayoutAccess().DelLayoutFormat(pFrameFormat);
+ }
}
}
}
@@ -416,7 +484,7 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView )
{
std::unique_ptr<SwUndoDrawDelete> pUndo;
if (GetIDocumentUndoRedo().DoesUndo())
- pUndo.reset(new SwUndoDrawDelete( static_cast<sal_uInt16>(rMrkList.GetMarkCount()), *this ));
+ pUndo.reset(new SwUndoDrawDelete( o3tl::narrowing<sal_uInt16>(rMrkList.GetMarkCount()), *this ));
// Destroy ContactObjects, save formats.
for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )