diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-09-10 15:46:57 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-09-10 16:09:26 +0100 |
commit | 93ab0ff24cb71c36c9e7958046e96d7472b5af90 (patch) | |
tree | fa4c4c1e0516ac175c5d3b0fa86eaf39802fd75d | |
parent | d961c9273104f552a8207e63c33e33f1e265565d (diff) |
Related: tdf#93676 default to as-char inside captions
This will (hopefull) improve round-tripping to doc[x] for new documents because
word can only have as-char elements inside frames so we get a like-for-like
conversion if the defaults are used.
Change-Id: I3913b9b624dd5ba57ed07140bced8e3dca289cf5
-rw-r--r-- | sw/source/core/frmedt/fews.cxx | 56 | ||||
-rw-r--r-- | sw/source/core/inc/UndoInsert.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/undo/unins.cxx | 16 |
3 files changed, 60 insertions, 13 deletions
diff --git a/sw/source/core/frmedt/fews.cxx b/sw/source/core/frmedt/fews.cxx index 8227b3039697..35be44c6c65c 100644 --- a/sw/source/core/frmedt/fews.cxx +++ b/sw/source/core/frmedt/fews.cxx @@ -48,6 +48,7 @@ #include <ndtxt.hxx> #include <dflyobj.hxx> #include <dcontact.hxx> +#include <UndoInsert.hxx> using namespace com::sun::star; @@ -395,14 +396,18 @@ void SwFEShell::InsertLabel( const SwLabelType eType, const OUString &rText, con if( LTYPE_DRAW==eType || pCnt ) { StartAllAction(); + SwRewriter aRewriter(SwUndoInsertLabel::CreateRewriter(rText)); + StartUndo(UNDO_INSERTLABEL, &aRewriter); sal_uLong nIdx = 0; + bool bInnerCntIsFly = false; SwFlyFrameFormat* pFlyFormat = 0; switch( eType ) { case LTYPE_OBJECT: case LTYPE_FLY: - if( pCnt->IsInFly() ) + bInnerCntIsFly = pCnt->IsInFly(); + if (bInnerCntIsFly) { // pass down index to the startnode for flys nIdx = pCnt->FindFlyFrm()-> @@ -423,7 +428,6 @@ void SwFEShell::InsertLabel( const SwLabelType eType, const OUString &rText, con { SwDrawView *pDView = Imp()->GetDrawView(); const SdrMarkList& rMrkList = pDView->GetMarkedObjectList(); - StartUndo(); // copy marked drawing objects to // local list to perform the corresponding action for each object @@ -452,7 +456,6 @@ void SwFEShell::InsertLabel( const SwLabelType eType, const OUString &rText, con aDrawObjs.pop_back(); } - EndUndo(); } break; default: @@ -460,14 +463,49 @@ void SwFEShell::InsertLabel( const SwLabelType eType, const OUString &rText, con } if( nIdx ) - pFlyFormat = GetDoc()->InsertLabel( eType, rText, rSeparator, rNumberSeparator, bBefore, nId, - nIdx, rCharacterStyle, bCpyBrd ); + { + pFlyFormat = GetDoc()->InsertLabel(eType, rText, rSeparator, + rNumberSeparator, bBefore, nId, + nIdx, rCharacterStyle, bCpyBrd); + + //if we succeeded in putting a caption on the content, and the + //content was a frame/graphic, then set the contained element + //to as-char anchoring because that's all msword is able to + //do when inside a frame, and in writer for freshly captioned + //elements it's largely irrelevent what the anchor of the contained + //type is but making it as-char by default results in very + //good roundtripping + if (pFlyFormat && bInnerCntIsFly) + { + SwNodeIndex aAnchIdx(*pFlyFormat->GetContent().GetContentIdx(), 1); + SwTextNode *pTxtNode = aAnchIdx.GetNode().GetTextNode(); + + SwFormatAnchor aAnc(FLY_AS_CHAR); + sal_Int32 nInsertPos = bBefore ? pTxtNode->Len() : 0; + SwPosition aPos(*pTxtNode, nInsertPos); + + aAnc.SetAnchor(&aPos); + + SfxItemSet aSet(makeItemSetFromFormatAnchor(GetDoc()->GetAttrPool(), aAnc)); - SwFlyFrm* pFrm; - const Point aPt( GetCrsrDocPos() ); - if( pFlyFormat && 0 != ( pFrm = pFlyFormat->GetFrm( &aPt ))) - SelectFlyFrm( *pFrm, true ); + SwFlyFrm *pFly = GetSelectedOrCurrFlyFrm(); + SwFlyFrameFormat* pInnerFlyFormat = pFly->GetFormat(); + GetDoc()->SetFlyFrmAttr(*pInnerFlyFormat, aSet); + //put a hard-break after the graphic to keep it separated + //from the caption text if the outer frame is resized + SwIndex aIdx(pTxtNode, bBefore ? nInsertPos : 1); + pTxtNode->InsertText(OUString("\n"), aIdx); + } + } + + if (pFlyFormat) + { + const Point aPt(GetCrsrDocPos()); + if (SwFlyFrm* pFrm = pFlyFormat->GetFrm(&aPt)) + SelectFlyFrm(*pFrm, true); + } + EndUndo(); EndAllActionAndCall(); } } diff --git a/sw/source/core/inc/UndoInsert.hxx b/sw/source/core/inc/UndoInsert.hxx index d2a7378af6e9..b3b21e502914 100644 --- a/sw/source/core/inc/UndoInsert.hxx +++ b/sw/source/core/inc/UndoInsert.hxx @@ -205,6 +205,7 @@ public: @return the rewriter of this undo object */ virtual SwRewriter GetRewriter() const SAL_OVERRIDE; + static SwRewriter CreateRewriter(const OUString &rStr); void SetNodePos( sal_uLong nNd ) { if( LTYPE_OBJECT != eType ) NODE.nNode = nNd; } diff --git a/sw/source/core/undo/unins.cxx b/sw/source/core/undo/unins.cxx index 9d194deb0bb0..1fda3b988566 100644 --- a/sw/source/core/undo/unins.cxx +++ b/sw/source/core/undo/unins.cxx @@ -1015,14 +1015,22 @@ void SwUndoInsertLabel::RepeatImpl(::sw::RepeatContext & rContext) // #111827# SwRewriter SwUndoInsertLabel::GetRewriter() const { + return CreateRewriter(sText); +} + +SwRewriter SwUndoInsertLabel::CreateRewriter(const OUString &rStr) +{ SwRewriter aRewriter; OUString aTmpStr; - aTmpStr += SW_RES(STR_START_QUOTE); - aTmpStr += ShortenString(sText, nUndoStringLength, - OUString(SW_RES(STR_LDOTS))); - aTmpStr += SW_RES(STR_END_QUOTE); + if (!rStr.isEmpty()) + { + aTmpStr += SW_RES(STR_START_QUOTE); + aTmpStr += ShortenString(rStr, nUndoStringLength, + OUString(SW_RES(STR_LDOTS))); + aTmpStr += SW_RES(STR_END_QUOTE); + } aRewriter.AddRule(UndoArg1, aTmpStr); |