LibreOffice Module sw (master) 1
SwXTextDefaults.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/beans/PropertyAttribute.hpp>
21
22#include <vcl/svapp.hxx>
23#include <osl/diagnose.h>
24#include <svl/itemprop.hxx>
25
26#include <SwXTextDefaults.hxx>
27#include <SwStyleNameMapper.hxx>
28#include <fchrfmt.hxx>
29#include <charfmt.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>
40
41using namespace ::com::sun::star;
42using namespace ::com::sun::star::uno;
43using namespace ::com::sun::star::beans;
44using namespace ::com::sun::star::lang;
45
47 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT ) ),
48 m_pDoc ( pNewDoc )
49{
50}
51
53{
54}
55
56uno::Reference< XPropertySetInfo > SAL_CALL SwXTextDefaults::getPropertySetInfo( )
57{
58 static uno::Reference < XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
59 return xRef;
60}
61
62void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
63{
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 ) );
72
73 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
75 {
77 aSet.Put(rItem);
78 SwUnoCursorHelper::SetPageDesc( aValue, *m_pDoc, aSet );
80 }
81 else if ((RES_PARATR_DROP == pMap->nWID && MID_DROPCAP_CHAR_STYLE_NAME == pMap->nMemberId) ||
82 (RES_TXTATR_CHARFMT == pMap->nWID))
83 {
84 OUString uStyle;
85 if(!(aValue >>= uStyle))
86 throw lang::IllegalArgumentException();
87
88 OUString sStyle;
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();
96
98 if (xStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat())
99 return; // don't SetCharFormat with formats from mpDfltCharFormat
100
101 if (RES_PARATR_DROP == pMap->nWID)
102 {
103 pDrop.reset(static_cast<SwFormatDrop*>(rItem.Clone())); // because rItem is const...
104 pDrop->SetCharFormat(xStyle->GetCharFormat());
105 m_pDoc->SetDefault(*pDrop);
106 }
107 else // RES_TXTATR_CHARFMT == pMap->nWID
108 {
109 pCharFormat.reset(static_cast<SwFormatCharFormat*>(rItem.Clone())); // because rItem is const...
110 pCharFormat->SetCharFormat(xStyle->GetCharFormat());
111 m_pDoc->SetDefault(*pCharFormat);
112 }
113 }
114 else
115 {
116 std::unique_ptr<SfxPoolItem> pNewItem(rItem.Clone());
117 pNewItem->PutValue( aValue, pMap->nMemberId);
118 m_pDoc->SetDefault(*pNewItem);
119 }
120}
121
122Any SAL_CALL SwXTextDefaults::getPropertyValue( const OUString& rPropertyName )
123{
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;
134}
135
136void SAL_CALL SwXTextDefaults::addPropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
137{
138 OSL_FAIL ( "not implemented" );
139}
140
141void SAL_CALL SwXTextDefaults::removePropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
142{
143 OSL_FAIL ( "not implemented" );
144}
145
146void SAL_CALL SwXTextDefaults::addVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
147{
148 OSL_FAIL ( "not implemented" );
149}
150
151void SAL_CALL SwXTextDefaults::removeVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
152{
153 OSL_FAIL ( "not implemented" );
154}
155
156// XPropertyState
157PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPropertyName )
158{
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 ) );
166
167 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
168 if (IsStaticDefaultItem ( &rItem ) )
169 eRet = PropertyState_DEFAULT_VALUE;
170 return eRet;
171}
172
173Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames )
174{
175 const sal_Int32 nCount = rPropertyNames.getLength();
176 Sequence < PropertyState > aRet ( nCount );
177
178 std::transform(rPropertyNames.begin(), rPropertyNames.end(), aRet.getArray(),
179 [this](const OUString& rName) -> PropertyState { return getPropertyState(rName); });
180
181 return aRet;
182}
183
184void SAL_CALL SwXTextDefaults::setPropertyToDefault( const OUString& rPropertyName )
185{
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 ) );
194 rSet.ResetPoolDefaultItem ( pMap->nWID );
195}
196
197Any SAL_CALL SwXTextDefaults::getPropertyDefault( const OUString& rPropertyName )
198{
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;
206 SfxPoolItem const*const pItem = rSet.GetPoolDefaultItem(pMap->nWID);
207 if (pItem)
208 {
209 pItem->QueryValue( aRet, pMap->nMemberId );
210 }
211 return aRet;
212}
213
215{
216 return "SwXTextDefaults";
217}
218
219sal_Bool SAL_CALL SwXTextDefaults::supportsService( const OUString& rServiceName )
220{
221 return cppu::supportsService(this, rServiceName);
222}
223
224uno::Sequence< OUString > SAL_CALL SwXTextDefaults::getSupportedServiceNames( )
225{
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" };
233}
234
235/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxItemPropertyMapEntry * getByName(std::u16string_view rName) const
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1152
Definition: doc.hxx:197
const SwCharFormat * GetDfltCharFormat() const
Definition: doc.hxx:768
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in current document.
Definition: docfmt.cxx:548
const SfxPoolItem & GetDefault(sal_uInt16 nFormatHint) const
Get the default attribute in this document.
Definition: docfmt.cxx:672
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1337
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
If SwFormatDrop is a Client, it is the CharFormat that describes the font for the DropCaps.
Definition: paratr.hxx:72
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
SwXTextDefaults(SwDoc *pNewDoc)
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &rPropertyName) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual ~SwXTextDefaults() override
const SfxItemPropertySet * m_pPropSet
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &aValue) override
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &rPropertyNames) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &rPropertyName) override
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL setPropertyToDefault(const OUString &rPropertyName) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
int nCount
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
constexpr TypedWhichId< SwFormatDrop > RES_PARATR_DROP(70)
bool SetPageDesc(const css::uno::Any &rValue, SwDoc &rDoc, SfxItemSet &rSet)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool IsStaticDefaultItem(const SfxPoolItem *pItem)
static SfxItemSet & rSet
unsigned char sal_Bool
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:88
#define PROPERTY_MAP_TEXT_DEFAULT
Definition: unomap.hxx:65
#define MID_PAGEDESC_PAGEDESCNAME
Definition: unomid.h:26
#define MID_DROPCAP_CHAR_STYLE_NAME
Definition: unomid.h:65