sw/inc/fesh.hxx | 1 sw/source/core/frmedt/fefly1.cxx | 10 ++++++ sw/source/core/frmedt/fews.cxx | 56 +++++++++++++++++++++++++++++++------ sw/source/core/inc/UndoInsert.hxx | 1 sw/source/core/undo/unins.cxx | 16 +++++++--- sw/source/uibase/shells/basesh.cxx | 16 +++------- 6 files changed, 77 insertions(+), 23 deletions(-)
New commits: commit 93ab0ff24cb71c36c9e7958046e96d7472b5af90 Author: Caolán McNamara <caol...@redhat.com> Date: Thu Sep 10 15:46:57 2015 +0100 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 diff --git a/sw/source/core/frmedt/fews.cxx b/sw/source/core/frmedt/fews.cxx index 8227b30..35be44c 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 d2a7378..b3b21e5 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 9d194de..1fda3b9 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); commit d961c9273104f552a8207e63c33e33f1e265565d Author: Caolán McNamara <caol...@redhat.com> Date: Thu Sep 10 15:10:52 2015 +0100 split out useful code as standalone makeItemSetFromFormatAnchor Change-Id: I385549b4841dfc715aa984bcc257d78c9f1c3ed4 diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx index 317b2f8..6e66129 100644 --- a/sw/inc/fesh.hxx +++ b/sw/inc/fesh.hxx @@ -380,6 +380,7 @@ public: bool IsFrmSelected() const; bool GetFlyFrmAttr( SfxItemSet &rSet ) const; bool SetFlyFrmAttr( SfxItemSet &rSet ); + SfxItemSet makeItemSetFromFormatAnchor(SfxItemPool& rPool, const SwFormatAnchor &rAnchor) const; bool ResetFlyFrmAttr( sal_uInt16 nWhich, const SfxItemSet* pSet = 0 ); const SwFrameFormat *NewFlyFrm( const SfxItemSet &rSet, bool bAnchValid = false, SwFrameFormat *pParent = 0 ); diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx index d814cfd..3f126fb 100644 --- a/sw/source/core/frmedt/fefly1.cxx +++ b/sw/source/core/frmedt/fefly1.cxx @@ -1053,6 +1053,16 @@ bool SwFEShell::SetFlyFrmAttr( SfxItemSet& rSet ) return bRet; } +SfxItemSet SwFEShell::makeItemSetFromFormatAnchor(SfxItemPool& rPool, const SwFormatAnchor &rAnchor) const +{ + // The set also includes VERT/HORI_ORIENT, because the align + // shall be changed in FEShell::SetFlyFrmAttr/SetFlyFrmAnchor, + // possibly as a result of the anchor change. + SfxItemSet aSet(rPool, RES_VERT_ORIENT, RES_ANCHOR); + aSet.Put(rAnchor); + return aSet; +} + bool SwFEShell::SetDrawingAttr( SfxItemSet& rSet ) { bool bRet = false; diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index 66a5072..07eb9ee 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -1008,16 +1008,12 @@ void SwBaseShell::Execute(SfxRequest &rReq) ? FLY_AS_CHAR : FLY_AT_CHAR; rSh.StartUndo(); - if( rSh.IsObjSelected() ) - rSh.ChgAnchor( eSet ); - else if( rSh.IsFrmSelected() ) - { - // The set also includes VERT/HORI_ORIENT, because the align - // shall be changed in FEShell::SetFlyFrmAttr/SetFlyFrmAnchor, - // possibly as a result of the anchor change. - SfxItemSet aSet( GetPool(), RES_VERT_ORIENT, RES_ANCHOR ); - SwFormatAnchor aAnc( eSet, rSh.GetPhyPageNum() ); - aSet.Put( aAnc ); + if (rSh.IsObjSelected()) + rSh.ChgAnchor(eSet); + else if (rSh.IsFrmSelected()) + { + SwFormatAnchor aAnc(eSet, rSh.GetPhyPageNum()); + SfxItemSet aSet(rSh.makeItemSetFromFormatAnchor(GetPool(), aAnc)); rSh.SetFlyFrmAttr(aSet); } // if new anchor is 'as char' and it is a Math object and the usual
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits