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 .
19 #ifndef INCLUDED_SW_INC_UNOSTYLE_HXX
20 #define INCLUDED_SW_INC_UNOSTYLE_HXX
22 #include <svl/listener.hxx>
23 #include <svl/style.hxx>
24 #include "unocoll.hxx"
25 #include "tblafmt.hxx"
26 #include <com/sun/star/style/XStyle.hpp>
27 #include <com/sun/star/style/XStyleLoader.hpp>
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/beans/XPropertyState.hpp>
31 #include <cppuhelper/implbase.hxx>
33 #include <com/sun/star/style/XAutoStyleFamily.hpp>
34 #include <com/sun/star/style/XAutoStyles.hpp>
35 #include <com/sun/star/style/XAutoStyle.hpp>
37 #include "istyleaccess.hxx"
41 namespace com::sun::star::document
{ class XEventsSupplier
; }
44 class SwAutoStylesEnumImpl
;
47 class SwXStyleFamilies final
: public cppu::WeakImplHelper
49 css::container::XIndexAccess
,
50 css::container::XNameAccess
,
51 css::lang::XServiceInfo
,
52 css::style::XStyleLoader
54 public SwUnoCollection
56 SwDocShell
* m_pDocShell
;
58 std::map
<SfxStyleFamily
, css::uno::Reference
<css::container::XNameContainer
>> m_vFamilies
;
60 virtual ~SwXStyleFamilies() override
;
62 SwXStyleFamilies(SwDocShell
& rDocShell
);
65 virtual css::uno::Any SAL_CALL
getByName(const OUString
& Name
) override
;
66 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
67 virtual sal_Bool SAL_CALL
hasByName(const OUString
& Name
) override
;
70 virtual sal_Int32 SAL_CALL
getCount() override
;
71 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 nIndex
) override
;
74 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
75 virtual sal_Bool SAL_CALL
hasElements( ) override
;
78 virtual void SAL_CALL
loadStylesFromURL(const OUString
& rURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& aOptions
) override
;
79 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getStyleLoaderOptions() override
;
82 virtual OUString SAL_CALL
getImplementationName() override
;
83 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
84 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
86 static css::uno::Reference
<css::style::XStyle
> CreateStyle(SfxStyleFamily eFamily
, SwDoc
& rDoc
);
87 // FIXME: This is very ugly as is the whole conditional paragraph style
88 // hackety. Should be folded into CreateStyle hopefully one day
89 static css::uno::Reference
<css::style::XStyle
> CreateStyleCondParagraph(SwDoc
& rDoc
);
97 virtual void SetItem(sal_uInt16 eAtr
, const SfxPoolItem
& rItem
) =0;
98 virtual const SfxPoolItem
* GetItem(sal_uInt16 eAtr
) =0;
99 virtual css::document::XEventsSupplier
& GetEventsSupplier() =0;
100 virtual ~ICoreFrameStyle() {};
104 // access to all automatic style families
105 class SwXAutoStyles final
:
106 public cppu::WeakImplHelper
< css::style::XAutoStyles
>,
107 public SwUnoCollection
109 SwDocShell
*m_pDocShell
;
110 css::uno::Reference
< css::style::XAutoStyleFamily
> m_xAutoCharStyles
;
111 css::uno::Reference
< css::style::XAutoStyleFamily
> m_xAutoRubyStyles
;
112 css::uno::Reference
< css::style::XAutoStyleFamily
> m_xAutoParaStyles
;
113 virtual ~SwXAutoStyles() override
;
116 SwXAutoStyles(SwDocShell
& rDocShell
);
119 virtual sal_Int32 SAL_CALL
getCount() override
;
120 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 nIndex
) override
;
123 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
124 virtual sal_Bool SAL_CALL
hasElements( ) override
;
127 virtual css::uno::Any SAL_CALL
getByName(const OUString
& Name
) override
;
128 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
129 virtual sal_Bool SAL_CALL
hasByName(const OUString
& Name
) override
;
133 // access to a family of automatic styles (character or paragraph or ...)
134 class SwXAutoStyleFamily final
: public cppu::WeakImplHelper
< css::style::XAutoStyleFamily
>, public SvtListener
136 SwDocShell
*m_pDocShell
;
137 IStyleAccess::SwAutoStyleFamily m_eFamily
;
141 SwXAutoStyleFamily(SwDocShell
* pDocShell
, IStyleAccess::SwAutoStyleFamily eFamily
);
142 virtual ~SwXAutoStyleFamily() override
;
145 virtual css::uno::Reference
< css::style::XAutoStyle
> SAL_CALL
insertStyle( const css::uno::Sequence
< css::beans::PropertyValue
>& Values
) override
;
148 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration( ) override
;
151 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
152 virtual sal_Bool SAL_CALL
hasElements( ) override
;
154 virtual void Notify( const SfxHint
&) override
;
157 class SwXAutoStylesEnumerator final
: public cppu::WeakImplHelper
< css::container::XEnumeration
>, public SvtListener
159 std::unique_ptr
<SwAutoStylesEnumImpl
> m_pImpl
;
161 SwXAutoStylesEnumerator( SwDoc
& rDoc
, IStyleAccess::SwAutoStyleFamily eFam
);
162 virtual ~SwXAutoStylesEnumerator() override
;
165 virtual sal_Bool SAL_CALL
hasMoreElements( ) override
;
166 virtual css::uno::Any SAL_CALL
nextElement( ) override
;
168 virtual void Notify( const SfxHint
&) override
;
171 // an automatic style
172 class SwXAutoStyle final
: public cppu::WeakImplHelper
174 css::beans::XPropertySet
,
175 css::beans::XPropertyState
,
176 css::style::XAutoStyle
181 std::shared_ptr
<SfxItemSet
> mpSet
;
182 IStyleAccess::SwAutoStyleFamily meFamily
;
185 /// @throws css::beans::UnknownPropertyException
186 /// @throws css::lang::WrappedTargetException
187 /// @throws css::uno::RuntimeException
188 css::uno::Sequence
< css::uno::Any
> GetPropertyValues_Impl( const css::uno::Sequence
< OUString
>& aPropertyNames
);
192 SwXAutoStyle( SwDoc
* pDoc
, std::shared_ptr
<SfxItemSet
> const & pInitSet
, IStyleAccess::SwAutoStyleFamily eFam
);
193 virtual ~SwXAutoStyle() override
;
196 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
197 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
198 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
199 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
200 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
201 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
202 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
205 virtual void SAL_CALL
setPropertyValues( const css::uno::Sequence
< OUString
>& aPropertyNames
, const css::uno::Sequence
< css::uno::Any
>& aValues
) override
;
206 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPropertyValues( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
207 virtual void SAL_CALL
addPropertiesChangeListener( const css::uno::Sequence
< OUString
>& aPropertyNames
, const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& xListener
) override
;
208 virtual void SAL_CALL
removePropertiesChangeListener( const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& xListener
) override
;
209 virtual void SAL_CALL
firePropertiesChangeEvent( const css::uno::Sequence
< OUString
>& aPropertyNames
, const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& xListener
) override
;
212 virtual css::beans::PropertyState SAL_CALL
getPropertyState( const OUString
& PropertyName
) override
;
213 virtual css::uno::Sequence
< css::beans::PropertyState
> SAL_CALL
getPropertyStates( const css::uno::Sequence
< OUString
>& aPropertyName
) override
;
214 virtual void SAL_CALL
setPropertyToDefault( const OUString
& PropertyName
) override
;
215 virtual css::uno::Any SAL_CALL
getPropertyDefault( const OUString
& aPropertyName
) override
;
217 //XMultiPropertyStates
218 virtual void SAL_CALL
setAllPropertiesToDefault( ) override
;
219 virtual void SAL_CALL
setPropertiesToDefault( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
220 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPropertyDefaults( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
223 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getProperties() override
;
225 virtual void Notify( const SfxHint
& ) override
;
229 typedef std::map
<OUString
, sal_Int32
> CellStyleNameMap
;
231 /// A text table style is a UNO API wrapper for a SwTableAutoFormat
232 class SwXTextTableStyle final
: public cppu::WeakImplHelper
235 css::beans::XPropertySet
,
236 css::container::XNameContainer
,
237 css::lang::XServiceInfo
240 SwDocShell
* m_pDocShell
;
241 SwTableAutoFormat
* m_pTableAutoFormat
;
242 /// Stores SwTableAutoFormat when this is not a physical style.
243 std::unique_ptr
<SwTableAutoFormat
> m_pTableAutoFormat_Impl
;
244 /// If true, then it points to a core object, if false, then this is a created, but not-yet-inserted format.
259 FIRST_ROW_START_COLUMN_STYLE
,
260 FIRST_ROW_END_COLUMN_STYLE
,
261 LAST_ROW_START_COLUMN_STYLE
,
262 LAST_ROW_END_COLUMN_STYLE
,
263 FIRST_ROW_EVEN_COLUMN_STYLE
,
264 LAST_ROW_EVEN_COLUMN_STYLE
,
268 /// Fills m_aCellStyles with SwXTextCellStyles pointing to children of this style.
269 void UpdateCellStylesMapping();
270 static const CellStyleNameMap
& GetCellStyleNameMap();
271 css::uno::Reference
<css::style::XStyle
> m_aCellStyles
[STYLE_COUNT
];
273 SwXTextTableStyle(SwDocShell
* pDocShell
, SwTableAutoFormat
* pTableAutoFormat
);
274 /// Create non physical style
275 SwXTextTableStyle(SwDocShell
* pDocShell
, const OUString
& rTableAutoFormatName
);
277 /// This function looks for a SwTableAutoFormat with given name. Returns nullptr if could not be found.
278 static SwTableAutoFormat
* GetTableAutoFormat(SwDocShell
* pDocShell
, const OUString
& sName
);
279 /// Returns box format assigned to this style
280 SwTableAutoFormat
* GetTableFormat();
284 virtual sal_Bool SAL_CALL
isUserDefined() override
;
285 virtual sal_Bool SAL_CALL
isInUse() override
;
286 virtual OUString SAL_CALL
getParentStyle() override
;
287 virtual void SAL_CALL
setParentStyle(const OUString
& aParentStyle
) override
;
290 virtual OUString SAL_CALL
getName() override
;
291 virtual void SAL_CALL
setName(const OUString
& rName
) override
;
294 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
295 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
296 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) override
;
297 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
298 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& aListener
) override
;
299 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
300 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
303 virtual css::uno::Any SAL_CALL
getByName(const OUString
& rName
) override
;
304 virtual css::uno::Sequence
<OUString
> SAL_CALL
getElementNames() override
;
305 virtual sal_Bool SAL_CALL
hasByName(const OUString
& rName
) override
;
308 virtual void SAL_CALL
insertByName(const OUString
& rName
, const css::uno::Any
& aElement
) override
;
309 virtual void SAL_CALL
replaceByName(const OUString
& rName
, const css::uno::Any
& aElement
) override
;
310 virtual void SAL_CALL
removeByName(const OUString
& rName
) override
;
313 virtual css::uno::Type SAL_CALL
getElementType() override
;
314 virtual sal_Bool SAL_CALL
hasElements() override
;
317 virtual OUString SAL_CALL
getImplementationName() override
;
318 virtual sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
;
319 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
321 static css::uno::Reference
<css::style::XStyle
> CreateXTextTableStyle(SwDocShell
* pDocShell
, const OUString
& rTableAutoFormatName
);
324 /// A text cell style is a UNO API wrapper for a SwBoxAutoFormat core class
325 class SwXTextCellStyle final
: public cppu::WeakImplHelper
328 css::beans::XPropertySet
,
329 css::beans::XPropertyState
,
330 css::lang::XServiceInfo
333 SwDocShell
* m_pDocShell
;
334 SwBoxAutoFormat
* m_pBoxAutoFormat
;
335 /// Stores SwBoxAutoFormat when this is not a physical style.
336 std::shared_ptr
<SwBoxAutoFormat
> m_pBoxAutoFormat_Impl
;
337 OUString m_sParentStyle
;
339 /// If true, then it points to a core object, if false, then this is a created, but not-yet-inserted format.
343 SwXTextCellStyle(SwDocShell
* pDocShell
, SwBoxAutoFormat
* pBoxAutoFormat
, const OUString
& sParentStyle
);
344 /// Create non physical style
345 SwXTextCellStyle(SwDocShell
* pDocShell
, const OUString
& sName
);
348 * This function looks for a SwBoxAutoFormat with given name. Parses the name and returns parent name.
349 * @param pDocShell pointer to a SwDocShell.
350 * @param sName Name of a SwBoxAutoFormat to look for.
351 * @param pParentName Optional output. Pointer to an OUString where parsed parent name will be returned.
352 * @return Pointer to a SwBoxAutoFormat, nullptr if not found.
354 static SwBoxAutoFormat
* GetBoxAutoFormat(SwDocShell
* pDocShell
, const OUString
& sName
, OUString
* pParentName
);
355 /// returns box format assigned to this style
356 SwBoxAutoFormat
* GetBoxFormat();
357 /// Sets the address of SwBoxAutoFormat this style is bound to. Usable only when style is physical.
358 void SetBoxFormat(SwBoxAutoFormat
* pBoxFormat
);
360 bool IsPhysical() const;
363 virtual sal_Bool SAL_CALL
isUserDefined() override
;
364 virtual sal_Bool SAL_CALL
isInUse() override
;
365 virtual OUString SAL_CALL
getParentStyle() override
;
366 virtual void SAL_CALL
setParentStyle(const OUString
& aParentStyle
) override
;
369 virtual OUString SAL_CALL
getName() override
;
370 virtual void SAL_CALL
setName(const OUString
& sName
) override
;
373 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
374 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
375 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) override
;
376 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
377 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& aListener
) override
;
378 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
379 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
382 virtual css::beans::PropertyState SAL_CALL
getPropertyState(const OUString
& PropertyName
) override
;
383 virtual css::uno::Sequence
<css::beans::PropertyState
> SAL_CALL
getPropertyStates(const css::uno::Sequence
< OUString
>& aPropertyName
) override
;
384 virtual void SAL_CALL
setPropertyToDefault(const OUString
& PropertyName
) override
;
385 virtual css::uno::Any SAL_CALL
getPropertyDefault(const OUString
& aPropertyName
) override
;
388 virtual OUString SAL_CALL
getImplementationName() override
;
389 virtual sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
;
390 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
392 static css::uno::Reference
<css::style::XStyle
> CreateXTextCellStyle(SwDocShell
* pDocShell
, const OUString
& sName
);
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */