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 <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <vcl/svapp.hxx>
23 #include <osl/diagnose.h>
24 #include <svl/itemprop.hxx>
26 #include <SwXTextDefaults.hxx>
27 #include <SwStyleNameMapper.hxx>
28 #include <fchrfmt.hxx>
29 #include <charfmt.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <docstyle.hxx>
37 #include <unocrsrhelper.hxx>
38 #include <hintids.hxx>
39 #include <fmtpdsc.hxx>
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::lang
;
47 SwXTextDefaults::SwXTextDefaults ( SwDoc
* pNewDoc
) :
48 m_pPropSet( aSwMapProvider
.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT
) ),
53 SwXTextDefaults::~SwXTextDefaults ()
57 uno::Reference
< XPropertySetInfo
> SAL_CALL
SwXTextDefaults::getPropertySetInfo( )
59 static uno::Reference
< XPropertySetInfo
> xRef
= m_pPropSet
->getPropertySetInfo();
63 void SAL_CALL
SwXTextDefaults::setPropertyValue( const OUString
& rPropertyName
, const Any
& aValue
)
65 SolarMutexGuard aGuard
;
67 throw RuntimeException();
68 const SfxItemPropertyMapEntry
*pMap
= m_pPropSet
->getPropertyMap().getByName( rPropertyName
);
70 throw UnknownPropertyException( "Unknown property: " + rPropertyName
, getXWeak() );
71 if ( pMap
->nFlags
& PropertyAttribute::READONLY
)
72 throw PropertyVetoException ( "Property is read-only: " + rPropertyName
, getXWeak() );
74 const SfxPoolItem
& rItem
= m_pDoc
->GetDefault(pMap
->nWID
);
75 if (RES_PAGEDESC
== pMap
->nWID
&& MID_PAGEDESC_PAGEDESCNAME
== pMap
->nMemberId
)
77 SfxItemSetFixed
<RES_PAGEDESC
, RES_PAGEDESC
> aSet( m_pDoc
->GetAttrPool() );
79 SwUnoCursorHelper::SetPageDesc( aValue
, *m_pDoc
, aSet
);
80 m_pDoc
->SetDefault(aSet
.Get(RES_PAGEDESC
));
82 else if ((RES_PARATR_DROP
== pMap
->nWID
&& MID_DROPCAP_CHAR_STYLE_NAME
== pMap
->nMemberId
) ||
83 (RES_TXTATR_CHARFMT
== pMap
->nWID
))
86 if(!(aValue
>>= uStyle
))
87 throw lang::IllegalArgumentException();
90 SwStyleNameMapper::FillUIName(ProgName(uStyle
), sStyle
, SwGetPoolIdFromName::ChrFmt
);
91 SwDocStyleSheet
* pStyle
=
92 static_cast<SwDocStyleSheet
*>(m_pDoc
->GetDocShell()->GetStyleSheetPool()->Find(sStyle
, SfxStyleFamily::Char
));
93 std::unique_ptr
<SwFormatDrop
> pDrop
;
94 std::unique_ptr
<SwFormatCharFormat
> pCharFormat
;
96 throw lang::IllegalArgumentException();
98 rtl::Reference
< SwDocStyleSheet
> xStyle( new SwDocStyleSheet( *pStyle
) );
99 if (xStyle
->GetCharFormat() == m_pDoc
->GetDfltCharFormat())
100 return; // don't SetCharFormat with formats from mpDfltCharFormat
102 if (RES_PARATR_DROP
== pMap
->nWID
)
104 pDrop
.reset(static_cast<SwFormatDrop
*>(rItem
.Clone())); // because rItem is const...
105 pDrop
->SetCharFormat(xStyle
->GetCharFormat());
106 m_pDoc
->SetDefault(*pDrop
);
108 else // RES_TXTATR_CHARFMT == pMap->nWID
110 pCharFormat
.reset(static_cast<SwFormatCharFormat
*>(rItem
.Clone())); // because rItem is const...
111 pCharFormat
->SetCharFormat(xStyle
->GetCharFormat());
112 m_pDoc
->SetDefault(*pCharFormat
);
117 std::unique_ptr
<SfxPoolItem
> pNewItem(rItem
.Clone());
118 pNewItem
->PutValue( aValue
, pMap
->nMemberId
);
119 m_pDoc
->SetDefault(*pNewItem
);
123 Any SAL_CALL
SwXTextDefaults::getPropertyValue( const OUString
& rPropertyName
)
125 SolarMutexGuard aGuard
;
127 throw RuntimeException();
128 const SfxItemPropertyMapEntry
*pMap
= m_pPropSet
->getPropertyMap().getByName( rPropertyName
);
130 throw UnknownPropertyException( "Unknown property: " + rPropertyName
, getXWeak() );
132 const SfxPoolItem
& rItem
= m_pDoc
->GetDefault(pMap
->nWID
);
133 rItem
.QueryValue( aRet
, pMap
->nMemberId
);
137 void SAL_CALL
SwXTextDefaults::addPropertyChangeListener( const OUString
& /*rPropertyName*/, const uno::Reference
< XPropertyChangeListener
>& /*xListener*/ )
139 OSL_FAIL ( "not implemented" );
142 void SAL_CALL
SwXTextDefaults::removePropertyChangeListener( const OUString
& /*rPropertyName*/, const uno::Reference
< XPropertyChangeListener
>& /*xListener*/ )
144 OSL_FAIL ( "not implemented" );
147 void SAL_CALL
SwXTextDefaults::addVetoableChangeListener( const OUString
& /*rPropertyName*/, const uno::Reference
< XVetoableChangeListener
>& /*xListener*/ )
149 OSL_FAIL ( "not implemented" );
152 void SAL_CALL
SwXTextDefaults::removeVetoableChangeListener( const OUString
& /*rPropertyName*/, const uno::Reference
< XVetoableChangeListener
>& /*xListener*/ )
154 OSL_FAIL ( "not implemented" );
158 PropertyState SAL_CALL
SwXTextDefaults::getPropertyState( const OUString
& rPropertyName
)
160 SolarMutexGuard aGuard
;
161 PropertyState eRet
= PropertyState_DIRECT_VALUE
;
163 throw RuntimeException();
164 const SfxItemPropertyMapEntry
*pMap
= m_pPropSet
->getPropertyMap().getByName( rPropertyName
);
166 throw UnknownPropertyException( "Unknown property: " + rPropertyName
, getXWeak() );
168 const SfxPoolItem
& rItem
= m_pDoc
->GetDefault(pMap
->nWID
);
169 if (IsStaticDefaultItem ( &rItem
) )
170 eRet
= PropertyState_DEFAULT_VALUE
;
174 Sequence
< PropertyState
> SAL_CALL
SwXTextDefaults::getPropertyStates( const Sequence
< OUString
>& rPropertyNames
)
176 const sal_Int32 nCount
= rPropertyNames
.getLength();
177 Sequence
< PropertyState
> aRet ( nCount
);
179 std::transform(rPropertyNames
.begin(), rPropertyNames
.end(), aRet
.getArray(),
180 [this](const OUString
& rName
) -> PropertyState
{ return getPropertyState(rName
); });
185 void SAL_CALL
SwXTextDefaults::setPropertyToDefault( const OUString
& rPropertyName
)
188 throw RuntimeException();
189 const SfxItemPropertyMapEntry
*pMap
= m_pPropSet
->getPropertyMap().getByName( rPropertyName
);
191 throw UnknownPropertyException( "Unknown property: " + rPropertyName
, getXWeak() );
192 if ( pMap
->nFlags
& PropertyAttribute::READONLY
)
193 throw RuntimeException( "setPropertyToDefault: property is read-only: " + rPropertyName
, getXWeak() );
194 SfxItemPool
& rSet (m_pDoc
->GetAttrPool());
195 rSet
.ResetUserDefaultItem ( pMap
->nWID
);
198 Any SAL_CALL
SwXTextDefaults::getPropertyDefault( const OUString
& rPropertyName
)
201 throw RuntimeException();
202 const SfxItemPropertyMapEntry
*pMap
= m_pPropSet
->getPropertyMap().getByName( rPropertyName
);
204 throw UnknownPropertyException( "Unknown property: " + rPropertyName
, getXWeak() );
206 SfxItemPool
& rSet (m_pDoc
->GetAttrPool());
207 SfxPoolItem
const*const pItem
= rSet
.GetUserDefaultItem(pMap
->nWID
);
210 pItem
->QueryValue( aRet
, pMap
->nMemberId
);
215 OUString SAL_CALL
SwXTextDefaults::getImplementationName( )
217 return u
"SwXTextDefaults"_ustr
;
220 sal_Bool SAL_CALL
SwXTextDefaults::supportsService( const OUString
& rServiceName
)
222 return cppu::supportsService(this, rServiceName
);
225 uno::Sequence
< OUString
> SAL_CALL
SwXTextDefaults::getSupportedServiceNames( )
227 return { u
"com.sun.star.text.Defaults"_ustr
,
228 u
"com.sun.star.style.CharacterProperties"_ustr
,
229 u
"com.sun.star.style.CharacterPropertiesAsian"_ustr
,
230 u
"com.sun.star.style.CharacterPropertiesComplex"_ustr
,
231 u
"com.sun.star.style.ParagraphProperties"_ustr
,
232 u
"com.sun.star.style.ParagraphPropertiesAsian"_ustr
,
233 u
"com.sun.star.style.ParagraphPropertiesComplex"_ustr
};
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */