Kaydet (Commit) 93ab0ff2 authored tarafından Caolán McNamara's avatar Caolán McNamara

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
üst d961c927
......@@ -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();
}
}
......
......@@ -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; }
......
......@@ -1014,15 +1014,23 @@ 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment