summaryrefslogtreecommitdiffstats
path: root/sw/source/core/frmedt
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/core/frmedt')
-rw-r--r--sw/source/core/frmedt/fecopy.cxx40
-rw-r--r--sw/source/core/frmedt/fefly1.cxx60
-rw-r--r--sw/source/core/frmedt/feshview.cxx59
3 files changed, 130 insertions, 29 deletions
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index 1d8b0ef680..01eee5072f 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -195,18 +195,20 @@ void SwFEShell::Copy( SwDoc& rClpDoc, const OUString* pNewClpText )
}
else
{
- SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall( pObj ));
- SwFrameFormat *pFormat = pContact->GetFormat();
- SwFormatAnchor aAnchor( pFormat->GetAnchor() );
- if ((RndStdIds::FLY_AT_PARA == aAnchor.GetAnchorId()) ||
- (RndStdIds::FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
- (RndStdIds::FLY_AT_FLY == aAnchor.GetAnchorId()) ||
- (RndStdIds::FLY_AS_CHAR == aAnchor.GetAnchorId()))
+ if (SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall( pObj )))
{
- aAnchor.SetAnchor( &aPos );
- }
+ SwFrameFormat *pFormat = pContact->GetFormat();
+ SwFormatAnchor aAnchor( pFormat->GetAnchor() );
+ if ((RndStdIds::FLY_AT_PARA == aAnchor.GetAnchorId()) ||
+ (RndStdIds::FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
+ (RndStdIds::FLY_AT_FLY == aAnchor.GetAnchorId()) ||
+ (RndStdIds::FLY_AS_CHAR == aAnchor.GetAnchorId()))
+ {
+ aAnchor.SetAnchor( &aPos );
+ }
- rClpDoc.getIDocumentLayoutAccess().CopyLayoutFormat( *pFormat, aAnchor, true, true );
+ rClpDoc.getIDocumentLayoutAccess().CopyLayoutFormat( *pFormat, aAnchor, true, true );
+ }
}
}
}
@@ -297,6 +299,9 @@ bool SwFEShell::CopyDrawSel( SwFEShell& rDestShell, const Point& rSttPt,
SdrObject *pObj = aMrkList.GetMark( i )->GetMarkedSdrObj();
SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall( pObj ));
+ if (!pContact)
+ continue;
+
SwFrameFormat *pFormat = pContact->GetFormat();
const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
@@ -1088,9 +1093,24 @@ bool SwFEShell::Paste(SwDoc& rClpDoc, bool bNestedTable)
--aIndexBefore;
+ // copying to the clipboard, the section is inserted
+ // at the start of the nodes, followed by empty text node
+ bool const isSourceSection(aCpyPam.Start()->GetNode().IsSectionNode()
+ && aCpyPam.End()->GetNodeIndex() == aCpyPam.Start()->GetNode().EndOfSectionIndex() + 1
+ && aCpyPam.End()->GetNode().IsTextNode()
+ && aCpyPam.End()->GetNode().GetTextNode()->Len() == 0);
+
rClpDoc.getIDocumentContentOperations().CopyRange(aCpyPam, rInsPos, SwCopyFlags::CheckPosInFly);
// Note: aCpyPam is invalid now
+ if (isSourceSection
+ && aIndexBefore.GetNode().IsStartNode()
+ && rInsPos.GetNode().GetTextNode()->Len() == 0)
+ { // if there is an empty text node at the start, it
+ // should be *replaced* by the section, so delete it
+ GetDoc()->getIDocumentContentOperations().DelFullPara(rPaM);
+ }
+
++aIndexBefore;
SwPaM aPaM(aIndexBefore.GetNode(), rInsPos.GetNode());
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 93ad4212cf..d6ff8b2969 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -382,11 +382,13 @@ const SwFrameFormat* SwFEShell::IsFlyInFly()
return nullptr;
return pFly->GetFormat();
}
- else if ( rMrkList.GetMarkCount() != 1 ||
- !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()) )
+ else if ( rMrkList.GetMarkCount() != 1 )
return nullptr;
SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
+ SwContact* pContact = GetUserCall( pObj );
+ if (!pContact)
+ return nullptr;
SwFrameFormat *pFormat = FindFrameFormat( pObj );
if( pFormat && RndStdIds::FLY_AT_FLY == pFormat->GetAnchor().GetAnchorId() )
@@ -398,7 +400,7 @@ const SwFrameFormat* SwFEShell::IsFlyInFly()
}
else
{
- pFly = static_cast<SwDrawContact*>(GetUserCall(pObj))->GetAnchorFrame(pObj);
+ pFly = static_cast<SwDrawContact*>(pContact)->GetAnchorFrame(pObj);
}
OSL_ENSURE( pFly, "IsFlyInFly: Where's my anchor?" );
@@ -491,11 +493,12 @@ Point SwFEShell::FindAnchorPos( const Point& rAbsPos, bool bMoveIt )
SdrObject* pObj = rMrkList.GetMark(0)->GetMarkedSdrObj();
- if (!GetUserCall(pObj))
+ SwContact* pContact = ::GetUserCall( pObj );
+ if (!pContact)
return aRet;
// #i28701#
- SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
+ SwAnchoredObject* pAnchoredObj = pContact->GetAnchoredObj( pObj );
SwFrameFormat* pFormat = pAnchoredObj->GetFrameFormat();
const RndStdIds nAnchorId = pFormat->GetAnchor().GetAnchorId();
@@ -890,6 +893,43 @@ const SwFrameFormat *SwFEShell::NewFlyFrame( const SfxItemSet& rSet, bool bAnchV
return pRet;
}
+namespace
+{
+/// If pCursor points to an as-char anchored graphic node, then set the node's anchor position on
+/// pAnchor and rPam.
+bool SetAnchorOnGrfNodeForAsChar(SwShellCursor *pCursor, SwFormatAnchor* pAnchor, std::optional<SwPaM>& rPam)
+{
+ const SwPosition* pPoint = pCursor->GetPoint();
+ if (pAnchor->GetAnchorId() != RndStdIds::FLY_AS_CHAR)
+ {
+ return false;
+ }
+
+ if (!pPoint->GetNode().IsGrfNode())
+ {
+ return false;
+ }
+
+ SwFrameFormat* pFrameFormat = pPoint->GetNode().GetFlyFormat();
+ if (!pFrameFormat)
+ {
+ return false;
+ }
+
+ const SwPosition* pContentAnchor = pFrameFormat->GetAnchor().GetContentAnchor();
+ if (!pContentAnchor)
+ {
+ return false;
+ }
+
+ SwPosition aPosition(*pContentAnchor);
+ ++aPosition.nContent;
+ pAnchor->SetAnchor(&aPosition);
+ rPam.emplace(aPosition);
+ return true;
+}
+}
+
void SwFEShell::Insert( const OUString& rGrfName, const OUString& rFltName,
const Graphic* pGraphic,
const SfxItemSet* pFlyAttrSet )
@@ -905,6 +945,7 @@ void SwFEShell::Insert( const OUString& rGrfName, const OUString& rFltName,
break;
// Has the anchor not been set or been set incompletely?
+ std::optional<SwPaM> oPam;
if( pFlyAttrSet )
{
if( const SwFormatAnchor* pItem = pFlyAttrSet->GetItemIfSet( RES_ANCHOR, false ) )
@@ -917,6 +958,13 @@ void SwFEShell::Insert( const OUString& rGrfName, const OUString& rFltName,
case RndStdIds::FLY_AS_CHAR:
if( !pAnchor->GetAnchorNode() )
{
+ if (SetAnchorOnGrfNodeForAsChar(pCursor, pAnchor, oPam))
+ {
+ // Don't anchor the image on the previous image, rather insert them next
+ // to each other.
+ break;
+ }
+
pAnchor->SetAnchor( pCursor->GetPoint() );
}
break;
@@ -940,7 +988,7 @@ void SwFEShell::Insert( const OUString& rGrfName, const OUString& rFltName,
}
}
pFormat = GetDoc()->getIDocumentContentOperations().InsertGraphic(
- *pCursor, rGrfName,
+ oPam.has_value() ? *oPam : *pCursor, rGrfName,
rFltName, pGraphic,
pFlyAttrSet,
nullptr, nullptr );
diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx
index 9154758364..353cb5214e 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -68,6 +68,7 @@
#include <rootfrm.hxx>
#include <pagefrm.hxx>
#include <sectfrm.hxx>
+#include <rowfrm.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <dview.hxx>
@@ -376,22 +377,27 @@ bool SwFEShell::MoveAnchor( SwMove nDir )
const SdrMarkList& pMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
if (1 != pMrkList.GetMarkCount())
return false;
+
+ SdrObject *pObj = pMrkList.GetMark( 0 )->GetMarkedSdrObj();
+ SwDrawContact* pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
+ if (!pContact)
+ return false;
+
SwFrame* pOld;
SwFlyFrame* pFly = nullptr;
- SdrObject *pObj = pMrkList.GetMark( 0 )->GetMarkedSdrObj();
if (SwVirtFlyDrawObj* pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pObj))
{
pFly = pVirtO->GetFlyFrame();
pOld = pFly->AnchorFrame();
}
else
- pOld = static_cast<SwDrawContact*>(GetUserCall(pObj))->GetAnchorFrame( pObj );
+ pOld = pContact->GetAnchorFrame( pObj );
bool bRet = false;
if( pOld )
{
SwFrame* pNew = pOld;
// #i28701#
- SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
+ SwAnchoredObject* pAnchoredObj = pContact->GetAnchoredObj( pObj );
SwFrameFormat* pFormat = pAnchoredObj->GetFrameFormat();
SwFormatAnchor aAnch( pFormat->GetAnchor() );
RndStdIds nAnchorId = aAnch.GetAnchorId();
@@ -874,7 +880,11 @@ static void lcl_NotifyNeighbours( const SdrMarkList *pLst )
}
else
{
- SwFrame* pAnch = static_cast<SwDrawContact*>( GetUserCall(pO) )->GetAnchorFrame( pO );
+ SwDrawContact* pContact = static_cast<SwDrawContact*>(GetUserCall(pO));
+ if (!pContact)
+ continue;
+
+ SwFrame* pAnch = pContact->GetAnchorFrame( pO );
if( !pAnch )
continue;
pPage = pAnch->FindPageFrame();
@@ -1316,12 +1326,15 @@ bool SwFEShell::ShouldObjectBeSelected(const Point& rPt)
{
if ( pObj->GetLayer() == rIDDMA.GetHellId() )
{
- const SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
- const SwFrameFormat* pFormat = pAnchoredObj->GetFrameFormat();
- const SwFormatSurround& rSurround = pFormat->GetSurround();
- if ( rSurround.GetSurround() == css::text::WrapTextMode_THROUGH )
+ if (const SwContact* pContact = ::GetUserCall( pObj ))
{
- bObjInBackground = true;
+ const SwAnchoredObject* pAnchoredObj = pContact->GetAnchoredObj( pObj );
+ const SwFrameFormat* pFormat = pAnchoredObj->GetFrameFormat();
+ const SwFormatSurround& rSurround = pFormat->GetSurround();
+ if ( rSurround.GetSurround() == css::text::WrapTextMode_THROUGH )
+ {
+ bObjInBackground = true;
+ }
}
}
}
@@ -1392,6 +1405,27 @@ bool SwFEShell::ShouldObjectBeSelected(const Point& rPt)
}
}
}
+
+ // within table row, where image cropped by the fixed table row height,
+ // click position must be in the cell, where the image anchored as character
+ if ( bRet && pContact && pContact->ObjAnchoredAsChar() )
+ {
+ if ( const SwTableBox *pBox = pContact->GetAnchorNode().GetTableBox() )
+ {
+ SwIterator<SwRowFrame, SwFormat> aIter( *pBox->GetUpper()->GetFrameFormat() );
+ bool bContainsClickPosition = false;
+ for (SwRowFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
+ {
+ if ( pFrame->getFrameArea().Contains( rPt ) )
+ {
+ bContainsClickPosition = true;
+ break;
+ }
+ }
+ if ( !bContainsClickPosition )
+ bRet = false;
+ }
+ }
}
}
@@ -2330,7 +2364,7 @@ bool SwFEShell::IsGroupSelected(bool bAllowDiagams)
// Thus, use corresponding method instead of checking type.
if ( pObj->IsGroupObject() &&
// --> #i38505# No ungroup allowed for 3d objects
- !pObj->Is3DObj() &&
+ !pObj->Is3DObj() && GetUserCall(pObj) &&
RndStdIds::FLY_AS_CHAR != static_cast<SwDrawContact*>(GetUserCall(pObj))->
GetFormat()->GetAnchor().GetAnchorId() )
{
@@ -2659,7 +2693,6 @@ bool SwFEShell::GetObjAttr( SfxItemSet &rSet ) const
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
- // --> make code robust
OSL_ENSURE( pContact, "<SwFEShell::GetObjAttr(..)> - missing <pContact>." );
if ( pContact )
{
@@ -2689,8 +2722,8 @@ void SwFEShell::SetObjAttr( const SfxItemSet& rSet )
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
- SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
- GetDoc()->SetAttr( rSet, *pContact->GetFormat() );
+ if (SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj)))
+ GetDoc()->SetAttr( rSet, *pContact->GetFormat() );
}
EndUndo( SwUndoId::INSATTR );