/* -*- 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 .
*/
SelectionType nSelectionType = rWrtShell.GetSelectionType(); auto pItemSet_TextAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, true ); auto pItemSet_ParAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool );
rWrtShell.StartAction();
rWrtShell.Push();
// modify the "Point and Mark" of the cursor // in order to select only the last character of the // selection(s) and then to get the attributes of this single character if( nSelectionType == SelectionType::Text )
{ // get the current PaM, the cursor // if there several selection it currently point // on the last (sort by there creation time) selection
SwPaM* pCursor = rWrtShell.GetCursor();
// clear the selection leaving just the cursor
pCursor->DeleteMark();
pCursor->SetMark();
} else
{ bool rightToLeft = rWrtShell.IsInRightToLeftText(); // if there were no selection (only a cursor) and the cursor was at // the end of the paragraph then don't move if ( rWrtShell.IsEndPara() && !rightToLeft )
dontMove = true;
// revert left and right if ( rightToLeft )
{ if (pCursor->GetPoint()->GetContentIndex() == 0)
dontMove = true; else
bForwardSelection = !bForwardSelection;
}
}
// move the cursor in order to select one character if (!dontMove)
pCursor->Move( bForwardSelection ? fnMoveBackward : fnMoveForward );
}
if(pItemSet_TextAttr)
{ if( nSelectionType & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic) )
rWrtShell.GetFlyFrameAttr(*pItemSet_TextAttr); else
{ // get the text attributes from named and automatic formatting
rWrtShell.GetCurAttr(*pItemSet_TextAttr);
if( nSelectionType & SelectionType::Text )
{ // get the paragraph attributes (could be character properties) // from named and automatic formatting
rWrtShell.GetCurParAttr(*pItemSet_ParAttr);
}
}
} elseif ( nSelectionType & SelectionType::DrawObject )
{
SdrView* pDrawView = rWrtShell.GetDrawView(); if(pDrawView)
{ if( pDrawView->GetMarkedObjectList().GetMarkCount() != 0 )
{
pItemSet_TextAttr = std::make_unique<SfxItemSet>( pDrawView->GetAttrFromMarked(true/*bOnlyHardAttr*/) ); //remove attributes defining the type/data of custom shapes
pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE);
pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_DATA);
pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
}
}
}
if(nSelectionType & (SelectionType::Table | SelectionType::TableCell))
{ if (nSelectionType & SelectionType::TableCell)
{ //only copy all table attributes if really cells are selected (not only text in tables)
m_pTableItemSet = std::make_unique<SfxItemSetFixed<
RES_PAGEDESC, RES_BREAK,
RES_BACKGROUND, RES_SHADOW, // RES_BOX is inbetween
RES_KEEP, RES_KEEP,
RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT,
RES_FRAMEDIR, RES_FRAMEDIR,
RES_ROW_SPLIT, RES_ROW_SPLIT,
RES_BOXATR_FORMAT, RES_BOXATR_FORMAT,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW, // SID_ATTR_BORDER_OUTER is inbetween
SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE,
FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION,
FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE>>(rPool);
} else
{ //selection in table should copy number format
m_pTableItemSet = std::make_unique<SfxItemSetFixed<
RES_BOXATR_FORMAT, RES_BOXATR_FORMAT>>(rPool);
}
if( nSelectionType & SelectionType::Text )
{ // if text is selected save the named character format
SwFormat* pFormat = rWrtShell.GetCurCharFormat(); if( pFormat )
m_aCharStyle = pFormat->GetName();
// and the named paragraph format
pFormat = rWrtShell.GetCurTextFormatColl(); if( pFormat )
m_aParaStyle = pFormat->GetName();
}
if (m_pItemSet_TextAttr && !( nSelectionType & SelectionType::DrawObject))
{ // reset all direct formatting before applying anything
o3tl::sorted_vector<sal_uInt16> aAttrs; for (sal_uInt16 nWhich = RES_CHRATR_BEGIN; nWhich < RES_CHRATR_END; nWhich++)
aAttrs.insert(nWhich);
rWrtShell.ResetAttr({ aAttrs });
}
if( nSelectionType & SelectionType::Text )
{ // apply the named text and paragraph formatting if( pPool )
{ // if there is a named text format recorded and the user wants to apply it if(!m_aCharStyle.isEmpty() && !bNoCharacterFormats )
{ // look for the named text format in the pool
SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aCharStyle.toString(), SfxStyleFamily::Char));
// if the style is found if( pStyle )
{
SwFormatCharFormat aFormat(pStyle->GetCharFormat()); // store the attributes from this style in aItemVector in order // not to apply them as automatic formatting attributes later in the code
lcl_AppendSetItems( aItemVector, aFormat.GetCharFormat()->GetAttrSet());
// apply the named format
rWrtShell.SetAttrItem( aFormat );
}
}
if (!bNoParagraphFormats)
{ const SwNumRule* pNumRule
= rWrtShell.GetNumRuleAtCurrCursorPos(); if (pNumRule && !pNumRule->IsOutlineRule())
{
rWrtShell.NumOrBulletOff();
} // if there is a named paragraph format recorded and the user wants to apply it if(!m_aParaStyle.isEmpty())
{ // look for the named paragraph format in the pool
SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aParaStyle.toString(), SfxStyleFamily::Para)); if( pStyle )
{ // store the attributes from this style in aItemVector in order // not to apply them as automatic formatting attributes later in the code
lcl_AppendSetItems( aItemVector, pStyle->GetCollection()->GetAttrSet());
// apply the named format
rWrtShell.SetTextFormatColl( pStyle->GetCollection() );
}
}
}
}
// apply the paragraph automatic attributes if ( m_pItemSet_ParAttr && m_pItemSet_ParAttr->Count() != 0 && !bNoParagraphFormats )
{ // temporary SfxItemSet
std::unique_ptr<SfxItemSet> pTemplateItemSet(lcl_CreateEmptyItemSet(
nSelectionType, *m_pItemSet_ParAttr->GetPool())); // no need to verify the existence of pTemplateItemSet as we // know that here the selection type is SEL_TXT
pTemplateItemSet->Put( *m_pItemSet_ParAttr );
// remove attribute that were applied by named text and paragraph formatting
lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
// apply the paragraph automatic attributes to all the nodes in the selection
rWrtShell.SetAttrSet(*pTemplateItemSet);
// store the attributes in aItemVector in order not to apply them as // text automatic formatting attributes later in the code
lcl_AppendSetItems( aItemVector, *pTemplateItemSet);
}
}
if(pTemplateItemSet)
{ // copy the stored automatic text attributes in a temporary SfxItemSet
pTemplateItemSet->Put( *m_pItemSet_TextAttr );
// only attributes that were not apply by named style attributes and automatic // paragraph attributes should be applied
lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
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.