nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / para / paratr.cxx
blob08be02090f0da7fb46819546b6365de7f8b68a16
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <unomid.h>
22 #include <com/sun/star/style/DropCapFormat.hpp>
23 #include <o3tl/any.hxx>
24 #include <SwStyleNameMapper.hxx>
25 #include <paratr.hxx>
26 #include <charfmt.hxx>
27 #include <libxml/xmlwriter.h>
28 #include <osl/diagnose.h>
29 #include <tools/UnitConversion.hxx>
31 using namespace ::com::sun::star;
34 SfxPoolItem* SwFormatDrop::CreateDefault() { return new SwFormatDrop; }
35 SfxPoolItem* SwRegisterItem::CreateDefault() { return new SwRegisterItem; }
36 SfxPoolItem* SwNumRuleItem::CreateDefault() { return new SwNumRuleItem; }
38 SwFormatDrop::SwFormatDrop()
39 : SfxPoolItem( RES_PARATR_DROP ),
40 SwClient( nullptr ),
41 m_pDefinedIn( nullptr ),
42 m_nDistance( 0 ),
43 m_nLines( 0 ),
44 m_nChars( 0 ),
45 m_bWholeWord( false )
49 SwFormatDrop::SwFormatDrop( const SwFormatDrop &rCpy )
50 : SfxPoolItem( RES_PARATR_DROP ),
51 SwClient( rCpy.GetRegisteredInNonConst() ),
52 m_pDefinedIn( nullptr ),
53 m_nDistance( rCpy.GetDistance() ),
54 m_nLines( rCpy.GetLines() ),
55 m_nChars( rCpy.GetChars() ),
56 m_bWholeWord( rCpy.GetWholeWord() )
60 SwFormatDrop::~SwFormatDrop()
64 void SwFormatDrop::SetCharFormat( SwCharFormat *pNew )
66 assert(!pNew || !pNew->IsDefault()); // expose cases that lead to use-after-free
67 // Rewire
68 EndListeningAll();
69 if(pNew)
70 pNew->Add( this );
73 void SwFormatDrop::SwClientNotify(const SwModify&, const SfxHint&)
75 if(!m_pDefinedIn)
76 return;
77 if(dynamic_cast<const SwFormat*>(m_pDefinedIn) == nullptr)
79 sw::BroadcastingModify aMod;
80 m_pDefinedIn->SwClientNotifyCall(aMod, sw::LegacyModifyHint(this, this));
82 else if(m_pDefinedIn->HasWriterListeners() && !m_pDefinedIn->IsModifyLocked())
84 // Notify those who are dependent on the format on our own.
85 // The format itself wouldn't pass on the notify as it does not get past the check.
86 m_pDefinedIn->CallSwClientNotify(sw::LegacyModifyHint(this, this));
90 bool SwFormatDrop::GetInfo( SfxPoolItem& ) const
92 return true; // Continue
95 bool SwFormatDrop::operator==( const SfxPoolItem& rAttr ) const
97 assert(SfxPoolItem::operator==(rAttr));
98 return ( m_nLines == static_cast<const SwFormatDrop&>(rAttr).GetLines() &&
99 m_nChars == static_cast<const SwFormatDrop&>(rAttr).GetChars() &&
100 m_nDistance == static_cast<const SwFormatDrop&>(rAttr).GetDistance() &&
101 m_bWholeWord == static_cast<const SwFormatDrop&>(rAttr).GetWholeWord() &&
102 GetCharFormat() == static_cast<const SwFormatDrop&>(rAttr).GetCharFormat() &&
103 m_pDefinedIn == static_cast<const SwFormatDrop&>(rAttr).m_pDefinedIn );
106 SwFormatDrop* SwFormatDrop::Clone( SfxItemPool* ) const
108 return new SwFormatDrop( *this );
111 bool SwFormatDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
113 switch(nMemberId&~CONVERT_TWIPS)
115 case MID_DROPCAP_LINES : rVal <<= static_cast<sal_Int16>(m_nLines); break;
116 case MID_DROPCAP_COUNT : rVal <<= static_cast<sal_Int16>(m_nChars); break;
117 case MID_DROPCAP_DISTANCE : rVal <<= static_cast<sal_Int16>(convertTwipToMm100(m_nDistance)); break;
118 case MID_DROPCAP_FORMAT:
120 style::DropCapFormat aDrop;
121 aDrop.Lines = m_nLines ;
122 aDrop.Count = m_nChars ;
123 aDrop.Distance = convertTwipToMm100(m_nDistance);
124 rVal <<= aDrop;
126 break;
127 case MID_DROPCAP_WHOLE_WORD:
128 rVal <<= m_bWholeWord;
129 break;
130 case MID_DROPCAP_CHAR_STYLE_NAME :
132 OUString sName;
133 if(GetCharFormat())
134 sName = SwStyleNameMapper::GetProgName(
135 GetCharFormat()->GetName(), SwGetPoolIdFromName::ChrFmt );
136 rVal <<= sName;
138 break;
140 return true;
143 bool SwFormatDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
145 switch(nMemberId&~CONVERT_TWIPS)
147 case MID_DROPCAP_LINES :
149 sal_Int8 nTemp = 0;
150 rVal >>= nTemp;
151 if(nTemp >=1 && nTemp < 0x7f)
152 m_nLines = static_cast<sal_uInt8>(nTemp);
154 break;
155 case MID_DROPCAP_COUNT :
157 sal_Int16 nTemp = 0;
158 rVal >>= nTemp;
159 if(nTemp >=1 && nTemp < 0x7f)
160 m_nChars = static_cast<sal_uInt8>(nTemp);
162 break;
163 case MID_DROPCAP_DISTANCE :
165 sal_Int16 nVal = 0;
166 if ( rVal >>= nVal )
167 m_nDistance = static_cast<sal_Int16>(convertMm100ToTwip(static_cast<sal_Int32>(nVal)));
168 else
169 return false;
170 break;
172 case MID_DROPCAP_FORMAT:
174 if(rVal.getValueType() == ::cppu::UnoType<style::DropCapFormat>::get())
176 auto pDrop = o3tl::doAccess<style::DropCapFormat>(rVal);
177 m_nLines = pDrop->Lines;
178 m_nChars = pDrop->Count;
179 m_nDistance = convertMm100ToTwip(pDrop->Distance);
182 break;
183 case MID_DROPCAP_WHOLE_WORD:
184 m_bWholeWord = *o3tl::doAccess<bool>(rVal);
185 break;
186 case MID_DROPCAP_CHAR_STYLE_NAME :
187 OSL_FAIL("char format cannot be set in PutValue()!");
188 break;
190 return true;
193 SwRegisterItem* SwRegisterItem::Clone( SfxItemPool * ) const
195 return new SwRegisterItem( *this );
198 SwNumRuleItem* SwNumRuleItem::Clone( SfxItemPool * ) const
200 return new SwNumRuleItem( *this );
203 bool SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const
205 assert(SfxPoolItem::operator==(rAttr));
207 return GetValue() == static_cast<const SwNumRuleItem&>(rAttr).GetValue();
210 bool SwNumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const
212 OUString sRet = SwStyleNameMapper::GetProgName(GetValue(), SwGetPoolIdFromName::NumRule );
213 rVal <<= sRet;
214 return true;
217 bool SwNumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 )
219 OUString uName;
220 rVal >>= uName;
221 SetValue(SwStyleNameMapper::GetUIName(uName, SwGetPoolIdFromName::NumRule));
222 return true;
225 void SwNumRuleItem::dumpAsXml(xmlTextWriterPtr pWriter) const
227 xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRuleItem"));
228 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
229 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
230 xmlTextWriterEndElement(pWriter);
233 SwParaConnectBorderItem* SwParaConnectBorderItem::Clone( SfxItemPool * ) const
235 return new SwParaConnectBorderItem( *this );
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */