Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / unocore / SwXTextDefaults.cxx
blobb4107f5f15a65b803d57bbd8863a9e01547a1467
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 <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>
32 #include <doc.hxx>
33 #include <docsh.hxx>
34 #include <unomap.hxx>
35 #include <unomid.h>
36 #include <paratr.hxx>
37 #include <unocrsrhelper.hxx>
38 #include <hintids.hxx>
39 #include <fmtpdsc.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::lang;
46 SwXTextDefaults::SwXTextDefaults ( SwDoc * pNewDoc ) :
47 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT ) ),
48 m_pDoc ( pNewDoc )
52 SwXTextDefaults::~SwXTextDefaults ()
56 uno::Reference< XPropertySetInfo > SAL_CALL SwXTextDefaults::getPropertySetInfo( )
58 static uno::Reference < XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
59 return xRef;
62 void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
64 SolarMutexGuard aGuard;
65 if (!m_pDoc)
66 throw RuntimeException();
67 const SfxItemPropertyMapEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
68 if (!pMap)
69 throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
70 if ( pMap->nFlags & PropertyAttribute::READONLY)
71 throw PropertyVetoException ( "Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
73 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
74 if (RES_PAGEDESC == pMap->nWID && MID_PAGEDESC_PAGEDESCNAME == pMap->nMemberId)
76 SfxItemSetFixed<RES_PAGEDESC, RES_PAGEDESC> aSet( m_pDoc->GetAttrPool() );
77 aSet.Put(rItem);
78 SwUnoCursorHelper::SetPageDesc( aValue, *m_pDoc, aSet );
79 m_pDoc->SetDefault(aSet.Get(RES_PAGEDESC));
81 else if ((RES_PARATR_DROP == pMap->nWID && MID_DROPCAP_CHAR_STYLE_NAME == pMap->nMemberId) ||
82 (RES_TXTATR_CHARFMT == pMap->nWID))
84 OUString uStyle;
85 if(!(aValue >>= uStyle))
86 throw lang::IllegalArgumentException();
88 OUString sStyle;
89 SwStyleNameMapper::FillUIName(uStyle, sStyle, SwGetPoolIdFromName::ChrFmt );
90 SwDocStyleSheet* pStyle =
91 static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char));
92 std::unique_ptr<SwFormatDrop> pDrop;
93 std::unique_ptr<SwFormatCharFormat> pCharFormat;
94 if(!pStyle)
95 throw lang::IllegalArgumentException();
97 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *pStyle ) );
98 if (xStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat())
99 return; // don't SetCharFormat with formats from mpDfltCharFormat
101 if (RES_PARATR_DROP == pMap->nWID)
103 pDrop.reset(static_cast<SwFormatDrop*>(rItem.Clone())); // because rItem is const...
104 pDrop->SetCharFormat(xStyle->GetCharFormat());
105 m_pDoc->SetDefault(*pDrop);
107 else // RES_TXTATR_CHARFMT == pMap->nWID
109 pCharFormat.reset(static_cast<SwFormatCharFormat*>(rItem.Clone())); // because rItem is const...
110 pCharFormat->SetCharFormat(xStyle->GetCharFormat());
111 m_pDoc->SetDefault(*pCharFormat);
114 else
116 std::unique_ptr<SfxPoolItem> pNewItem(rItem.Clone());
117 pNewItem->PutValue( aValue, pMap->nMemberId);
118 m_pDoc->SetDefault(*pNewItem);
122 Any SAL_CALL SwXTextDefaults::getPropertyValue( const OUString& rPropertyName )
124 SolarMutexGuard aGuard;
125 if (!m_pDoc)
126 throw RuntimeException();
127 const SfxItemPropertyMapEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
128 if (!pMap)
129 throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
130 Any aRet;
131 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
132 rItem.QueryValue( aRet, pMap->nMemberId );
133 return aRet;
136 void SAL_CALL SwXTextDefaults::addPropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
138 OSL_FAIL ( "not implemented" );
141 void SAL_CALL SwXTextDefaults::removePropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
143 OSL_FAIL ( "not implemented" );
146 void SAL_CALL SwXTextDefaults::addVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
148 OSL_FAIL ( "not implemented" );
151 void SAL_CALL SwXTextDefaults::removeVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
153 OSL_FAIL ( "not implemented" );
156 // XPropertyState
157 PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPropertyName )
159 SolarMutexGuard aGuard;
160 PropertyState eRet = PropertyState_DIRECT_VALUE;
161 if (!m_pDoc)
162 throw RuntimeException();
163 const SfxItemPropertyMapEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
164 if (!pMap)
165 throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
167 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
168 if (IsStaticDefaultItem ( &rItem ) )
169 eRet = PropertyState_DEFAULT_VALUE;
170 return eRet;
173 Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames )
175 const sal_Int32 nCount = rPropertyNames.getLength();
176 Sequence < PropertyState > aRet ( nCount );
178 std::transform(rPropertyNames.begin(), rPropertyNames.end(), aRet.getArray(),
179 [this](const OUString& rName) -> PropertyState { return getPropertyState(rName); });
181 return aRet;
184 void SAL_CALL SwXTextDefaults::setPropertyToDefault( const OUString& rPropertyName )
186 if (!m_pDoc)
187 throw RuntimeException();
188 const SfxItemPropertyMapEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
189 if (!pMap)
190 throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
191 if ( pMap->nFlags & PropertyAttribute::READONLY)
192 throw RuntimeException( "setPropertyToDefault: property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
193 SfxItemPool& rSet (m_pDoc->GetAttrPool());
194 rSet.ResetPoolDefaultItem ( pMap->nWID );
197 Any SAL_CALL SwXTextDefaults::getPropertyDefault( const OUString& rPropertyName )
199 if (!m_pDoc)
200 throw RuntimeException();
201 const SfxItemPropertyMapEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
202 if (!pMap)
203 throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
204 Any aRet;
205 SfxItemPool& rSet (m_pDoc->GetAttrPool());
206 SfxPoolItem const*const pItem = rSet.GetPoolDefaultItem(pMap->nWID);
207 if (pItem)
209 pItem->QueryValue( aRet, pMap->nMemberId );
211 return aRet;
214 OUString SAL_CALL SwXTextDefaults::getImplementationName( )
216 return "SwXTextDefaults";
219 sal_Bool SAL_CALL SwXTextDefaults::supportsService( const OUString& rServiceName )
221 return cppu::supportsService(this, rServiceName);
224 uno::Sequence< OUString > SAL_CALL SwXTextDefaults::getSupportedServiceNames( )
226 return { "com.sun.star.text.Defaults",
227 "com.sun.star.style.CharacterProperties",
228 "com.sun.star.style.CharacterPropertiesAsian",
229 "com.sun.star.style.CharacterPropertiesComplex",
230 "com.sun.star.style.ParagraphProperties",
231 "com.sun.star.style.ParagraphPropertiesAsian",
232 "com.sun.star.style.ParagraphPropertiesComplex" };
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */