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"
21 #include <swtypes.hxx>
23 #include <com/sun/star/style/LineSpacingMode.hpp>
24 #include <com/sun/star/style/ParagraphAdjust.hpp>
25 #include <com/sun/star/style/DropCapFormat.hpp>
26 #include <com/sun/star/style/LineSpacing.hpp>
27 #include <com/sun/star/text/RelOrientation.hpp>
28 #include <com/sun/star/text/VertOrientation.hpp>
29 #include <com/sun/star/text/HorizontalAdjust.hpp>
30 #include <com/sun/star/text/DocumentStatistic.hpp>
31 #include <com/sun/star/text/HoriOrientation.hpp>
32 #include <com/sun/star/text/HoriOrientationFormat.hpp>
33 #include <com/sun/star/text/NotePrintMode.hpp>
34 #include <com/sun/star/text/SizeType.hpp>
35 #include <com/sun/star/text/VertOrientationFormat.hpp>
36 #include <com/sun/star/text/WrapTextMode.hpp>
37 #include <o3tl/any.hxx>
38 #include <unostyle.hxx>
39 #include <SwStyleNameMapper.hxx>
41 #include "charfmt.hxx"
43 #include <libxml/xmlwriter.h>
45 using namespace ::com::sun::star
;
48 SfxPoolItem
* SwFormatDrop::CreateDefault() { return new SwFormatDrop
; }
49 SfxPoolItem
* SwRegisterItem::CreateDefault() { return new SwRegisterItem
; }
50 SfxPoolItem
* SwNumRuleItem::CreateDefault() { return new SwNumRuleItem
; }
52 SwFormatDrop::SwFormatDrop()
53 : SfxPoolItem( RES_PARATR_DROP
),
55 pDefinedIn( nullptr ),
57 nReadFormat( USHRT_MAX
),
64 SwFormatDrop::SwFormatDrop( const SwFormatDrop
&rCpy
)
65 : SfxPoolItem( RES_PARATR_DROP
),
66 SwClient( rCpy
.GetRegisteredInNonConst() ),
67 pDefinedIn( nullptr ),
68 nDistance( rCpy
.GetDistance() ),
69 nReadFormat( rCpy
.nReadFormat
),
70 nLines( rCpy
.GetLines() ),
71 nChars( rCpy
.GetChars() ),
72 bWholeWord( rCpy
.GetWholeWord() )
76 SwFormatDrop::~SwFormatDrop()
80 void SwFormatDrop::SetCharFormat( SwCharFormat
*pNew
)
83 if ( GetRegisteredIn() )
84 GetRegisteredInNonConst()->Remove( this );
87 nReadFormat
= USHRT_MAX
;
90 void SwFormatDrop::Modify( const SfxPoolItem
*, const SfxPoolItem
* )
94 if( dynamic_cast< const SwFormat
*>( pDefinedIn
) == nullptr)
95 pDefinedIn
->ModifyNotification( this, this );
96 else if( pDefinedIn
->HasWriterListeners() &&
97 !pDefinedIn
->IsModifyLocked() )
99 // Notify those who are dependent on the format on our own.
100 // The format itself wouldn't pass on the notify as it does not get past the check.
101 pDefinedIn
->ModifyBroadcast( this, this );
106 bool SwFormatDrop::GetInfo( SfxPoolItem
& ) const
108 return true; // Continue
111 bool SwFormatDrop::operator==( const SfxPoolItem
& rAttr
) const
113 assert(SfxPoolItem::operator==(rAttr
));
114 return ( nLines
== static_cast<const SwFormatDrop
&>(rAttr
).GetLines() &&
115 nChars
== static_cast<const SwFormatDrop
&>(rAttr
).GetChars() &&
116 nDistance
== static_cast<const SwFormatDrop
&>(rAttr
).GetDistance() &&
117 bWholeWord
== static_cast<const SwFormatDrop
&>(rAttr
).GetWholeWord() &&
118 GetCharFormat() == static_cast<const SwFormatDrop
&>(rAttr
).GetCharFormat() &&
119 pDefinedIn
== static_cast<const SwFormatDrop
&>(rAttr
).pDefinedIn
);
122 SfxPoolItem
* SwFormatDrop::Clone( SfxItemPool
* ) const
124 return new SwFormatDrop( *this );
127 bool SwFormatDrop::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
129 switch(nMemberId
&~CONVERT_TWIPS
)
131 case MID_DROPCAP_LINES
: rVal
<<= (sal_Int16
)nLines
; break;
132 case MID_DROPCAP_COUNT
: rVal
<<= (sal_Int16
)nChars
; break;
133 case MID_DROPCAP_DISTANCE
: rVal
<<= (sal_Int16
) convertTwipToMm100(nDistance
); break;
134 case MID_DROPCAP_FORMAT
:
136 style::DropCapFormat aDrop
;
137 aDrop
.Lines
= nLines
;
138 aDrop
.Count
= nChars
;
139 aDrop
.Distance
= convertTwipToMm100(nDistance
);
143 case MID_DROPCAP_WHOLE_WORD
:
146 case MID_DROPCAP_CHAR_STYLE_NAME
:
150 sName
= SwStyleNameMapper::GetProgName(
151 GetCharFormat()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);
159 bool SwFormatDrop::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
161 switch(nMemberId
&~CONVERT_TWIPS
)
163 case MID_DROPCAP_LINES
:
167 if(nTemp
>=1 && nTemp
< 0x7f)
168 nLines
= (sal_uInt8
)nTemp
;
171 case MID_DROPCAP_COUNT
:
175 if(nTemp
>=1 && nTemp
< 0x7f)
176 nChars
= (sal_uInt8
)nTemp
;
179 case MID_DROPCAP_DISTANCE
:
183 nDistance
= (sal_Int16
) convertMm100ToTwip((sal_Int32
)nVal
);
188 case MID_DROPCAP_FORMAT
:
190 if(rVal
.getValueType() == ::cppu::UnoType
<style::DropCapFormat
>::get())
192 auto pDrop
= o3tl::doAccess
<style::DropCapFormat
>(rVal
);
193 nLines
= pDrop
->Lines
;
194 nChars
= pDrop
->Count
;
195 nDistance
= convertMm100ToTwip(pDrop
->Distance
);
201 case MID_DROPCAP_WHOLE_WORD
:
202 bWholeWord
= *o3tl::doAccess
<bool>(rVal
);
204 case MID_DROPCAP_CHAR_STYLE_NAME
:
205 OSL_FAIL("char format cannot be set in PutValue()!");
211 SfxPoolItem
* SwRegisterItem::Clone( SfxItemPool
* ) const
213 return new SwRegisterItem( *this );
216 SfxPoolItem
* SwNumRuleItem::Clone( SfxItemPool
* ) const
218 return new SwNumRuleItem( *this );
220 bool SwNumRuleItem::operator==( const SfxPoolItem
& rAttr
) const
222 assert(SfxPoolItem::operator==(rAttr
));
224 return GetValue() == static_cast<const SwNumRuleItem
&>(rAttr
).GetValue();
227 bool SwNumRuleItem::QueryValue( uno::Any
& rVal
, sal_uInt8
) const
229 OUString sRet
= SwStyleNameMapper::GetProgName(GetValue(), nsSwGetPoolIdFromName::GET_POOLID_NUMRULE
);
234 bool SwNumRuleItem::PutValue( const uno::Any
& rVal
, sal_uInt8
)
238 SetValue(SwStyleNameMapper::GetUIName(uName
, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE
));
242 void SwNumRuleItem::dumpAsXml(xmlTextWriterPtr pWriter
) const
244 xmlTextWriterStartElement(pWriter
, BAD_CAST("swNumRuleItem"));
245 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
246 xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
247 xmlTextWriterEndElement(pWriter
);
250 SfxPoolItem
* SwParaConnectBorderItem::Clone( SfxItemPool
* ) const
252 return new SwParaConnectBorderItem( *this );
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */