1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include <com/sun/star/style/DropCapFormat.hpp>
23 #include <o3tl/any.hxx>
24 #include <SwStyleNameMapper.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
),
41 m_pDefinedIn( nullptr ),
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
73 bool SwFormatDrop::GetInfo( SfxPoolItem
& ) const
75 return true; // Continue
78 bool SwFormatDrop::operator==( const SfxPoolItem
& rAttr
) const
80 assert(SfxPoolItem::operator==(rAttr
));
81 return ( m_nLines
== static_cast<const SwFormatDrop
&>(rAttr
).GetLines() &&
82 m_nChars
== static_cast<const SwFormatDrop
&>(rAttr
).GetChars() &&
83 m_nDistance
== static_cast<const SwFormatDrop
&>(rAttr
).GetDistance() &&
84 m_bWholeWord
== static_cast<const SwFormatDrop
&>(rAttr
).GetWholeWord() &&
85 GetCharFormat() == static_cast<const SwFormatDrop
&>(rAttr
).GetCharFormat() &&
86 m_pDefinedIn
== static_cast<const SwFormatDrop
&>(rAttr
).m_pDefinedIn
);
89 SwFormatDrop
* SwFormatDrop::Clone( SfxItemPool
* ) const
91 return new SwFormatDrop( *this );
94 bool SwFormatDrop::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
96 switch(nMemberId
&~CONVERT_TWIPS
)
98 case MID_DROPCAP_LINES
: rVal
<<= static_cast<sal_Int16
>(m_nLines
); break;
99 case MID_DROPCAP_COUNT
: rVal
<<= static_cast<sal_Int16
>(m_nChars
); break;
100 case MID_DROPCAP_DISTANCE
: rVal
<<= static_cast<sal_Int16
>(convertTwipToMm100(m_nDistance
)); break;
101 case MID_DROPCAP_FORMAT
:
103 style::DropCapFormat aDrop
;
104 aDrop
.Lines
= m_nLines
;
105 aDrop
.Count
= m_nChars
;
106 aDrop
.Distance
= convertTwipToMm100(m_nDistance
);
110 case MID_DROPCAP_WHOLE_WORD
:
111 rVal
<<= m_bWholeWord
;
113 case MID_DROPCAP_CHAR_STYLE_NAME
:
117 sName
= SwStyleNameMapper::GetProgName(
118 GetCharFormat()->GetName(), SwGetPoolIdFromName::ChrFmt
);
126 bool SwFormatDrop::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
128 switch(nMemberId
&~CONVERT_TWIPS
)
130 case MID_DROPCAP_LINES
:
134 if(nTemp
>=1 && nTemp
< 0x7f)
135 m_nLines
= static_cast<sal_uInt8
>(nTemp
);
138 case MID_DROPCAP_COUNT
:
142 if(nTemp
>=1 && nTemp
< 0x7f)
143 m_nChars
= static_cast<sal_uInt8
>(nTemp
);
146 case MID_DROPCAP_DISTANCE
:
150 m_nDistance
= o3tl::toTwips(nVal
, o3tl::Length::mm100
);
155 case MID_DROPCAP_FORMAT
:
157 if(rVal
.getValueType() == ::cppu::UnoType
<style::DropCapFormat
>::get())
159 auto pDrop
= o3tl::doAccess
<style::DropCapFormat
>(rVal
);
160 m_nLines
= pDrop
->Lines
;
161 m_nChars
= pDrop
->Count
;
162 m_nDistance
= o3tl::toTwips(pDrop
->Distance
, o3tl::Length::mm100
);
166 case MID_DROPCAP_WHOLE_WORD
:
167 m_bWholeWord
= *o3tl::doAccess
<bool>(rVal
);
169 case MID_DROPCAP_CHAR_STYLE_NAME
:
170 OSL_FAIL("char format cannot be set in PutValue()!");
176 SwRegisterItem
* SwRegisterItem::Clone( SfxItemPool
* ) const
178 return new SwRegisterItem( *this );
181 SwNumRuleItem
* SwNumRuleItem::Clone( SfxItemPool
* ) const
183 return new SwNumRuleItem( *this );
186 bool SwNumRuleItem::operator==( const SfxPoolItem
& rAttr
) const
188 assert(SfxPoolItem::operator==(rAttr
));
190 return GetValue() == static_cast<const SwNumRuleItem
&>(rAttr
).GetValue();
193 bool SwNumRuleItem::QueryValue( uno::Any
& rVal
, sal_uInt8
) const
195 OUString sRet
= SwStyleNameMapper::GetProgName(GetValue(), SwGetPoolIdFromName::NumRule
);
200 bool SwNumRuleItem::PutValue( const uno::Any
& rVal
, sal_uInt8
)
204 SetValue(SwStyleNameMapper::GetUIName(uName
, SwGetPoolIdFromName::NumRule
));
208 void SwNumRuleItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
210 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwNumRuleItem"));
211 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
212 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
213 (void)xmlTextWriterEndElement(pWriter
);
216 SwParaConnectBorderItem
* SwParaConnectBorderItem::Clone( SfxItemPool
* ) const
218 return new SwParaConnectBorderItem( *this );
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */