/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
while (nWhich)
{ // determine current template to every family
UIName aName;
SwTableAutoFormat aTableAutoFormat(TableStyleName(u"dummy"_ustr)); // needed to check if can take a table auto format at current cursor position switch (nWhich)
{ case SID_STYLE_APPLY:
{// here the template and its family are passed to the StyleBox // so that this family is being showed if(pShell->IsFrameSelected())
{
SwFrameFormat* pFormat = pShell->GetSelectedFrameFormat(); if( pFormat )
aName = pFormat->GetName();
} elseif (pShell->GetSelectionType() == SelectionType::PostIt)
{
OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pShell); if (SfxStyleSheetBase* pStyle = pOLV ? pOLV->GetStyleSheet() : nullptr)
aName = UIName(pStyle->GetName());
} else
{
SwTextFormatColl* pColl = pShell->GetCurTextFormatColl(); if(pColl)
aName = pColl->GetName();
}
rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
} break; case SID_STYLE_FAMILY1: if( !pShell->IsFrameSelected() )
{
SwCharFormat* pFormat = pShell->GetCurCharFormat(); if(pFormat)
aName = pFormat->GetName(); else
aName = UIName(SwResId(STR_POOLCHR_STANDARD));
rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
} break;
case SID_STYLE_EDIT: case SID_STYLE_FONT: case SID_STYLE_DELETE: case SID_STYLE_HIDE: case SID_STYLE_SHOW: case SID_STYLE_WATERCAN: case SID_STYLE_FAMILY: case SID_STYLE_UPDATE_BY_EXAMPLE: case SID_STYLE_NEW_BY_EXAMPLE:
{
OUString aParam;
SfxStyleFamily nFamily = SfxStyleFamily::Para;
SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
SwWrtShell* pActShell = nullptr;
if(m_bNew)
{ if(SfxStyleFamily::Frame == m_nFamily || SfxStyleFamily::Para == m_nFamily)
{ // clear FillStyle so that it works as a derived attribute
SfxItemSet aTmpSet(*m_pDlg->GetOutputItemSet());
namespace
{ /// Checks if there is an Endnote page style in use, and makes sure it has the same orientation /// with the Default (Standard) page style. void syncEndnoteOrientation(const uno::Reference< style::XStyleFamiliesSupplier >& xStyleFamSupp)
{ if (!xStyleFamSupp.is())
{
SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null."); return;
}
uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamSupp->getStyleFamilies();
// Language-independent name of the "Default Style" is "Standard"
uno::Reference<css::style::XStyle> xDefaultPageStyle(xPageStyles->getByName(u"Standard"_ustr),
uno::UNO_QUERY); if (!xDefaultPageStyle.is()) return;
if (xEndnotePageStyle->isUserDefined() || !xEndnotePageStyle->isInUse()) return;
if( bNew )
{ if (!bBasic)
{ // start undo action in order to get only one undo action for the // UI new style + change style operations
m_pWrtShell->StartUndo();
}
if (!bBasic)
{ //Get the undo id for the type of style that was created in order to re-use that comment for the grouped //create style + change style operations
m_pWrtShell->GetLastUndoInfo(nullptr, &nNewStyleUndoId);
}
} else
{
pStyle = m_xBasePool->Find( rName.toString(), nFamily );
SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
}
if(!pStyle) return;
// put dialogues together
rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) ); if( SfxStyleFamily::Para == nFamily )
{
SfxItemSet& rSet = xTmp->GetItemSet();
::SwToSfxPageDescAttr( rSet ); // merge list level indent attributes into the item set if needed
xTmp->MergeIndentAttrsOfListStyle( rSet );
if(SfxStyleFamily::Page == nFamily || SfxStyleFamily::Para == nFamily)
{ // create needed items for XPropertyList entries from the DrawModel so that // the Area TabPage can access them
SfxItemSet& rSet = xTmp->GetItemSet(); const SwDrawModel* pDrawModel = GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
if (!bBasic)
{ // prior to the dialog the HtmlMode at the DocShell is being sunk
sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
// In HTML mode, we do not always have a printer. In order to show // the correct page size in the Format - Page dialog, we have to // get one here. if( ( HTMLMODE_ON & nHtmlMode ) &&
!pCurrShell->getIDocumentDeviceAccess().getPrinter( false ) )
pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess().getPrinter( true ) );
PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast<sal_uInt16>(eMetric)));
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); if (!pDialogParent)
{
SAL_WARN("sw.ui", "no parent for dialog supplied, assuming document frame is good enough");
pDialogParent = GetView()->GetFrameWeld();
}
VclPtr<SfxAbstractApplyTabDialog> pDlg(pFact->CreateTemplateDialog(pDialogParent,
*xTmp, nFamily, sPage, pCurrShell, bNew)); auto pApplyStyleHelper = std::make_shared<ApplyStyle>(*this, bNew, xTmp, nFamily, pDlg.get(), m_xBasePool, bModified);
pDlg->SetApplyHdl(LINK(pApplyStyleHelper.get(), ApplyStyle, ApplyHdl));
std::shared_ptr<SfxRequest> pRequest; if (pReq)
{
pRequest = std::make_shared<SfxRequest>(*pReq);
pReq->Ignore(); // the 'old' request is not relevant any more
}
if (bNew)
{ switch( nFamily )
{ case SfxStyleFamily::Para:
{ if(!xTmp->GetParent().isEmpty())
{
SwTextFormatColl* pColl = m_pWrtShell->FindTextFormatCollByName(UIName(xTmp->GetParent())); if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
{
GetDoc()->GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoTextFormatCollCreate>(xTmp->GetCollection(), pColl, *GetDoc()));
}
}
} break; case SfxStyleFamily::Char:
{ if(!xTmp->GetParent().isEmpty())
{
SwCharFormat* pCFormat = m_pWrtShell->FindCharFormatByName(UIName(xTmp->GetParent())); if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
{
GetDoc()->GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoCharFormatCreate>(xTmp->GetCharFormat(), pCFormat, *GetDoc()));
}
}
} break; case SfxStyleFamily::Frame:
{ if(!xTmp->GetParent().isEmpty())
{
SwFrameFormat* pFFormat = m_pWrtShell->GetDoc()->FindFrameFormatByName(UIName(xTmp->GetParent())); if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
{
GetDoc()->GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoFrameFormatCreate>(xTmp->GetFrameFormat(), pFFormat, *GetDoc()));
}
}
} break; case SfxStyleFamily::Pseudo:
{ if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
{
GetDoc()->GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoNumruleCreate>(xTmp->GetNumRule(),
*GetDoc()));
}
} break; default: break;
}
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, xTmp->GetName()); //Group the create style and change style operations together under the //one "create style" comment
m_pWrtShell->EndUndo(nNewStyleUndoId, &aRewriter);
}
if (RET_OK != nResult)
{ if (bNew)
{
GetWrtShell()->Undo();
m_xDoc->GetIDocumentUndoRedo().ClearRedo();
}
if (!bDocModified)
m_xDoc->getIDocumentState().ResetModified();
}
// Update Watermark if new page style was created if (nSlot == SID_STYLE_NEW && nFamily == SfxStyleFamily::Page)
{
SwWrtShell* pShell = GetWrtShell(); const SfxWatermarkItem aWatermark = pShell->GetWatermark();
pShell->SetWatermark(aWatermark);
}
pApplyStyleHelper->m_pDlg.disposeAndClear(); if (pRequest)
pRequest->Done();
if (bIsDefaultPage && bDocModified)
{
uno::Reference< style::XStyleFamiliesSupplier > xStyleFamSupp(GetModel(), uno::UNO_QUERY);
if (!xStyleFamSupp.is())
{
SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null."); return;
}
syncEndnoteOrientation(xStyleFamSupp);
}
});
} else
{ // prior to the dialog the HtmlMode at the DocShell is being sunk
PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
#define MAX_CHAR_IN_INLINE_HEADING 120 bool SwDocShell::MakeInlineHeading(SwWrtShell *pSh, SwTextFormatColl* pColl, const sal_uInt16 nMode)
{ // insert an inline heading frame, if only MAX_CHAR_IN_INLINE_HEADING or less // characters are selected beginning of a single paragraph, but not the full paragraph // TODO extend it for multiple selections if ( pSh->IsSelOnePara() && !pSh->IsSelFullPara() && pSh->IsSelStartPara() &&
GetView()->GetSelectionText().getLength() < MAX_CHAR_IN_INLINE_HEADING &&
0 < GetView()->GetSelectionText().getLength() )
{
SwTextFormatColl *pLocal = pColl? pColl: (*GetDoc()->GetTextFormatColls())[0]; // don't put inline heading in a frame (it would be enough to limit for inline heading // frames, but the recent FN_INSERT_FRAME cannot handle the insertion inside a frame // correctly) // TODO: allow to insert inline headings in a (not an Inline Heading) text frame if ( pSh->GetCursor()->GetPointNode() !=
*SwOutlineNodes::GetRootNode( &pSh->GetCursor()->GetPointNode(), /*bInlineHeading=*/false ) )
{ returnfalse;
}
// put inside a single Undo
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, pLocal->GetName());
GetWrtShell()->StartUndo(SwUndoId::SETFMTCOLL, &aRewriter);
// anchor as character
SfxUInt16Item aAnchor(FN_INSERT_FRAME, static_cast<sal_uInt16>(1));
SvxSizeItem aSizeItem(FN_PARAM_2, Size(1, 1));
GetView()->GetViewFrame().GetDispatcher()->ExecuteList(FN_INSERT_FRAME,
SfxCallMode::SYNCHRON|SfxCallMode::RECORD, { &aAnchor, &aSizeItem }); if ( pSh->IsFrameSelected() )
{ // use the associated borderless frame style "Inline Heading"
SwDocStyleSheet* pStyle2 = static_cast<SwDocStyleSheet*>(
m_xBasePool->Find( "Inline Heading", SfxStyleFamily::Frame));
SAL_WARN_IF( !pStyle2, "sw.ui", "Style not found" ); if(pStyle2)
pSh->SetFrameFormat( pStyle2->GetFrameFormat() );
// select the text content of the frame, and apply the paragraph style
pSh->UnSelectFrame();
pSh->LeaveSelFrameMode();
pSh->MoveSection( GoCurrSection, fnSectionEnd );
pSh->SelAll();
// zero the upper and lower margins of the paragraph (also an interoperability issue)
SfxItemSetFixed<RES_UL_SPACE, RES_UL_SPACE> aSet2(pSh->GetAttrPool());
pSh->GetCurAttr( aSet2 );
SvxULSpaceItem aUL( 0, 0, RES_UL_SPACE );
pSh->SetAttrItem( aUL );
break;
} case SfxStyleFamily::Para:
{ if (OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pSh))
pOLV->SetStyleSheet(rName); else
{ // When outline-folding is enabled, MakeAllOutlineContentTemporarilyVisible makes // application of a paragraph style that has an outline-level greater than the previous // outline node become folded content of the previous outline node if the previous // outline node's content is folded.
MakeAllOutlineContentTemporarilyVisible a(GetDoc());
// if the first 120 or less characters are selected, but not the full paragraph, // create an inline heading from the selected text
SwTextFormatColl* pColl = pStyle->GetCollection(); if ( MakeInlineHeading( pSh, pColl, nMode ) ) break;
// #i62675# // clear also list attributes at affected text nodes, if paragraph // style has the list style attribute set. const SetAttrMode nAttrModeFlag
= (nMode & KEY_MOD1) ? SetAttrMode::REMOVE_ALL_ATTR : SetAttrMode::DEFAULT; constbool bResetListAttrs
= nAttrModeFlag == SetAttrMode::REMOVE_ALL_ATTR
|| (pColl && pColl->GetItemState(RES_PARATR_NUMRULE) == SfxItemState::SET);
pSh->SetTextFormatColl(pColl, bResetListAttrs, nAttrModeFlag);
} break;
} case SfxStyleFamily::Frame:
{ if ( pSh->IsFrameSelected() )
pSh->SetFrameFormat( pStyle->GetFrameFormat() ); break;
} case SfxStyleFamily::Page:
{
pSh->SetPageStyle(pStyle->GetPageDesc()->GetName()); break;
} case SfxStyleFamily::Pseudo:
{ // reset indent attribute on applying list style // continue list of list style const SwNumRule* pNumRule = pStyle->GetNumRule(); if (pNumRule->GetName() == SwResId(STR_POOLNUMRULE_NOLIST))
{ if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
pViewFrm->GetDispatcher()->Execute(FN_NUM_BULLET_OFF); break;
} const OUString sListIdForStyle =pNumRule->GetDefaultListId();
pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true ); break;
} case SfxStyleFamily::Table:
{
pSh->SetTableStyle(TableStyleName(pStyle->GetName())); break;
} default:
OSL_FAIL("Unknown family");
}
pSh->EndAllAction();
GetWrtShell()->StartUndo(SwUndoId::INSFMTATTR, &aRewriter);
GetWrtShell()->FillByEx(pColl); // also apply template to remove hard set attributes
GetWrtShell()->SetTextFormatColl( pColl );
GetWrtShell()->EndUndo();
GetWrtShell()->EndAllAction();
} break;
} case SfxStyleFamily::Frame:
{
SwFrameFormat* pFrame = pStyle->GetFrameFormat(); if( pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault() )
{
SfxItemSet aSet( GetPool(), aFrameFormatSetRange );
pCurrWrtShell->StartAllAction();
pCurrWrtShell->GetFlyFrameAttr( aSet );
// #i105535# // no update of anchor attribute
aSet.ClearItem( RES_ANCHOR );
pFrame->SetFormatAttr( aSet );
// also apply template to remove hard set attributes
pCurrWrtShell->SetFrameFormat( pFrame, true );
pCurrWrtShell->EndAllAction();
}
} break; case SfxStyleFamily::Char:
{
SwCharFormat* pChar = pStyle->GetCharFormat(); if( pChar && !pChar->IsDefault() )
{
pCurrWrtShell->StartAllAction();
pCurrWrtShell->FillByEx(pChar); // also apply template to remove hard set attributes
pCurrWrtShell->EndAllAction();
}
// NewByExample void SwDocShell::MakeByExample( const UIName &rName, SfxStyleFamily nFamily,
SfxStyleSearchBits nMask, SwWrtShell* pShell )
{
SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find(
rName.toString(), nFamily ) ); if(!pStyle)
{ // preserve the current mask of PI, then the new one is // immediately merged with the viewable area if( SfxStyleSearchBits::All == nMask || SfxStyleSearchBits::Used == nMask )
nMask = SfxStyleSearchBits::UserDefined; else
nMask |= SfxStyleSearchBits::UserDefined;
if (nFamily == SfxStyleFamily::Para || nFamily == SfxStyleFamily::Char || nFamily == SfxStyleFamily::Frame)
{ // Prevent undo append from being done during paragraph, character, and frame style Make. Do it later
::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName.toString(), nFamily, nMask));
} else
{
pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName.toString(), nFamily, nMask));
}
}
switch(nFamily)
{ case SfxStyleFamily::Para:
{
SwTextFormatColl* pColl = pStyle->GetCollection(); if(pColl && !pColl->IsDefault())
{
pCurrWrtShell->StartAllAction();
pCurrWrtShell->FillByEx(pColl); // also apply template to remove hard set attributes
SwTextFormatColl * pDerivedFrom = pCurrWrtShell->GetCurTextFormatColl();
pColl->SetDerivedFrom(pDerivedFrom);
// set the mask at the Collection:
sal_uInt16 nId = pColl->GetPoolFormatId() & 0x87ff; switch( nMask & static_cast<SfxStyleSearchBits>(0x0fff) )
{ case SfxStyleSearchBits::SwText:
nId |= COLL_TEXT_BITS; break; case SfxStyleSearchBits::SwChapter:
nId |= COLL_DOC_BITS; break; case SfxStyleSearchBits::SwList:
nId |= COLL_LISTS_BITS; break; case SfxStyleSearchBits::SwIndex:
nId |= COLL_REGISTER_BITS; break; case SfxStyleSearchBits::SwExtra:
nId |= COLL_EXTRA_BITS; break; case SfxStyleSearchBits::SwHtml:
nId |= COLL_HTML_BITS; break; default: break;
}
pColl->SetPoolFormatId(nId);
SfxItemSet aSet(GetPool(), aFrameFormatSetRange );
pCurrWrtShell->GetFlyFrameAttr( aSet );
aSet.ClearItem(RES_ANCHOR); // tdf#112574 no anchor in styles
SwFrameFormat* pFFormat = pCurrWrtShell->GetSelectedFrameFormat();
pFrame->SetDerivedFrom( pFFormat );
pFrame->SetFormatAttr( aSet ); if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
{
GetDoc()->GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoFrameFormatCreate>(pFrame, pFFormat, *GetDoc()));
} // also apply template to remove hard set attributes
pCurrWrtShell->SetFrameFormat(pFrame);
pCurrWrtShell->EndAllAction();
}
} break; case SfxStyleFamily::Char:
{
SwCharFormat* pChar = pStyle->GetCharFormat(); if(pChar && !pChar->IsDefault())
{
pCurrWrtShell->StartAllAction();
pCurrWrtShell->FillByEx( pChar );
SwCharFormat * pDerivedFrom = pCurrWrtShell->GetCurCharFormat();
pChar->SetDerivedFrom( pDerivedFrom );
SwFormatCharFormat aFormat( pChar );
if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
{ // Looks like sometimes pDerivedFrom can be null and this is not supported by redo code // So use default format as a derived from in such situations
GetDoc()->GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoCharFormatCreate>(
pChar, pDerivedFrom ? pDerivedFrom : GetDoc()->GetDfltCharFormat(),
*GetDoc()));
}
pCurrWrtShell->SetAttrItem(aFormat);
pCurrWrtShell->EndAllAction();
}
} break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.