From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- sw/source/core/para/paratr.cxx | 221 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 sw/source/core/para/paratr.cxx (limited to 'sw/source/core/para') diff --git a/sw/source/core/para/paratr.cxx b/sw/source/core/para/paratr.cxx new file mode 100644 index 0000000000..f724ac21c0 --- /dev/null +++ b/sw/source/core/para/paratr.cxx @@ -0,0 +1,221 @@ +/* -*- 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + + +SfxPoolItem* SwFormatDrop::CreateDefault() { return new SwFormatDrop; } +SfxPoolItem* SwRegisterItem::CreateDefault() { return new SwRegisterItem; } +SfxPoolItem* SwNumRuleItem::CreateDefault() { return new SwNumRuleItem; } + +SwFormatDrop::SwFormatDrop() + : SfxPoolItem( RES_PARATR_DROP ), + SwClient( nullptr ), + m_pDefinedIn( nullptr ), + m_nDistance( 0 ), + m_nLines( 0 ), + m_nChars( 0 ), + m_bWholeWord( false ) +{ +} + +SwFormatDrop::SwFormatDrop( const SwFormatDrop &rCpy ) + : SfxPoolItem( RES_PARATR_DROP ), + SwClient( rCpy.GetRegisteredInNonConst() ), + m_pDefinedIn( nullptr ), + m_nDistance( rCpy.GetDistance() ), + m_nLines( rCpy.GetLines() ), + m_nChars( rCpy.GetChars() ), + m_bWholeWord( rCpy.GetWholeWord() ) +{ +} + +SwFormatDrop::~SwFormatDrop() +{ +} + +void SwFormatDrop::SetCharFormat( SwCharFormat *pNew ) +{ + assert(!pNew || !pNew->IsDefault()); // expose cases that lead to use-after-free + // Rewire + EndListeningAll(); + if(pNew) + pNew->Add( this ); +} + +bool SwFormatDrop::GetInfo( SfxPoolItem& ) const +{ + return true; // Continue +} + +bool SwFormatDrop::operator==( const SfxPoolItem& rAttr ) const +{ + assert(SfxPoolItem::operator==(rAttr)); + return ( m_nLines == static_cast(rAttr).GetLines() && + m_nChars == static_cast(rAttr).GetChars() && + m_nDistance == static_cast(rAttr).GetDistance() && + m_bWholeWord == static_cast(rAttr).GetWholeWord() && + GetCharFormat() == static_cast(rAttr).GetCharFormat() && + m_pDefinedIn == static_cast(rAttr).m_pDefinedIn ); +} + +SwFormatDrop* SwFormatDrop::Clone( SfxItemPool* ) const +{ + return new SwFormatDrop( *this ); +} + +bool SwFormatDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const +{ + switch(nMemberId&~CONVERT_TWIPS) + { + case MID_DROPCAP_LINES : rVal <<= static_cast(m_nLines); break; + case MID_DROPCAP_COUNT : rVal <<= static_cast(m_nChars); break; + case MID_DROPCAP_DISTANCE : rVal <<= static_cast(convertTwipToMm100(m_nDistance)); break; + case MID_DROPCAP_FORMAT: + { + style::DropCapFormat aDrop; + aDrop.Lines = m_nLines ; + aDrop.Count = m_nChars ; + aDrop.Distance = convertTwipToMm100(m_nDistance); + rVal <<= aDrop; + } + break; + case MID_DROPCAP_WHOLE_WORD: + rVal <<= m_bWholeWord; + break; + case MID_DROPCAP_CHAR_STYLE_NAME : + { + OUString sName; + if(GetCharFormat()) + sName = SwStyleNameMapper::GetProgName( + GetCharFormat()->GetName(), SwGetPoolIdFromName::ChrFmt ); + rVal <<= sName; + } + break; + } + return true; +} + +bool SwFormatDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) +{ + switch(nMemberId&~CONVERT_TWIPS) + { + case MID_DROPCAP_LINES : + { + sal_Int8 nTemp = 0; + rVal >>= nTemp; + if(nTemp >=1 && nTemp < 0x7f) + m_nLines = static_cast(nTemp); + } + break; + case MID_DROPCAP_COUNT : + { + sal_Int16 nTemp = 0; + rVal >>= nTemp; + if(nTemp >=1 && nTemp < 0x7f) + m_nChars = static_cast(nTemp); + } + break; + case MID_DROPCAP_DISTANCE : + { + sal_Int16 nVal = 0; + if ( rVal >>= nVal ) + m_nDistance = o3tl::toTwips(nVal, o3tl::Length::mm100); + else + return false; + break; + } + case MID_DROPCAP_FORMAT: + { + if(rVal.getValueType() == ::cppu::UnoType::get()) + { + auto pDrop = o3tl::doAccess(rVal); + m_nLines = pDrop->Lines; + m_nChars = pDrop->Count; + m_nDistance = o3tl::toTwips(pDrop->Distance, o3tl::Length::mm100); + } + } + break; + case MID_DROPCAP_WHOLE_WORD: + m_bWholeWord = *o3tl::doAccess(rVal); + break; + case MID_DROPCAP_CHAR_STYLE_NAME : + OSL_FAIL("char format cannot be set in PutValue()!"); + break; + } + return true; +} + +SwRegisterItem* SwRegisterItem::Clone( SfxItemPool * ) const +{ + return new SwRegisterItem( *this ); +} + +SwNumRuleItem* SwNumRuleItem::Clone( SfxItemPool * ) const +{ + return new SwNumRuleItem( *this ); +} + +bool SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const +{ + assert(SfxPoolItem::operator==(rAttr)); + + return GetValue() == static_cast(rAttr).GetValue(); +} + +bool SwNumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const +{ + OUString sRet = SwStyleNameMapper::GetProgName(GetValue(), SwGetPoolIdFromName::NumRule ); + rVal <<= sRet; + return true; +} + +bool SwNumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 ) +{ + OUString uName; + rVal >>= uName; + SetValue(SwStyleNameMapper::GetUIName(uName, SwGetPoolIdFromName::NumRule)); + return true; +} + +void SwNumRuleItem::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRuleItem")); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr())); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr())); + (void)xmlTextWriterEndElement(pWriter); +} + +SwParaConnectBorderItem* SwParaConnectBorderItem::Clone( SfxItemPool * ) const +{ + return new SwParaConnectBorderItem( *this ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3