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 .
21 #include <rtl/ref.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 "coreframestyle.hxx"
38 #include "istyleaccess.hxx"
42 namespace com::sun::star::document
{ class XEventsSupplier
; }
45 class SwAutoStylesEnumImpl
;
48 class SwXTextCellStyle
;
52 class SwXStyleFamilies final
: public cppu::WeakImplHelper
54 css::container::XIndexAccess
,
55 css::container::XNameAccess
,
56 css::lang::XServiceInfo
,
57 css::style::XStyleLoader
59 public SwUnoCollection
61 SwDocShell
* m_pDocShell
;
63 std::map
<SfxStyleFamily
, css::uno::Reference
<css::container::XNameContainer
>> m_vFamilies
;
65 virtual ~SwXStyleFamilies() override
;
67 SwXStyleFamilies(SwDocShell
& rDocShell
);
70 virtual css::uno::Any SAL_CALL
getByName(const OUString
& Name
) override
;
71 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
72 virtual sal_Bool SAL_CALL
hasByName(const OUString
& Name
) override
;
75 virtual sal_Int32 SAL_CALL
getCount() override
;
76 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 nIndex
) override
;
79 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
80 virtual sal_Bool SAL_CALL
hasElements( ) override
;
83 virtual void SAL_CALL
loadStylesFromURL(const OUString
& rURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& aOptions
) override
;
84 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getStyleLoaderOptions() override
;
87 virtual OUString SAL_CALL
getImplementationName() override
;
88 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
89 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
91 static css::uno::Reference
<css::style::XStyle
> CreateStyle(SfxStyleFamily eFamily
, SwDoc
& rDoc
);
92 static rtl::Reference
<SwXStyle
> CreateStyleCharOrParaOrPseudo(SfxStyleFamily eFamily
, SwDoc
& rDoc
);
93 static rtl::Reference
<SwXPageStyle
> CreateStylePage(SwDoc
& rDoc
);
94 static rtl::Reference
<SwXFrameStyle
> CreateStyleFrame(SwDoc
& rDoc
);
95 static rtl::Reference
<SwXTextTableStyle
> CreateStyleTable(SwDoc
& rDoc
);
96 static rtl::Reference
<SwXTextCellStyle
> CreateStyleCell(SwDoc
& rDoc
);
97 // FIXME: This is very ugly as is the whole conditional paragraph style
98 // hackety. Should be folded into CreateStyle hopefully one day
99 static css::uno::Reference
<css::style::XStyle
> CreateStyleCondParagraph(SwDoc
& rDoc
);
102 // access to all automatic style families
103 class SwXAutoStyles final
:
104 public cppu::WeakImplHelper
< css::style::XAutoStyles
>,
105 public SwUnoCollection
107 SwDocShell
*m_pDocShell
;
108 css::uno::Reference
< css::style::XAutoStyleFamily
> m_xAutoCharStyles
;
109 css::uno::Reference
< css::style::XAutoStyleFamily
> m_xAutoRubyStyles
;
110 css::uno::Reference
< css::style::XAutoStyleFamily
> m_xAutoParaStyles
;
111 virtual ~SwXAutoStyles() override
;
114 SwXAutoStyles(SwDocShell
& rDocShell
);
117 virtual sal_Int32 SAL_CALL
getCount() override
;
118 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 nIndex
) override
;
121 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
122 virtual sal_Bool SAL_CALL
hasElements( ) override
;
125 virtual css::uno::Any SAL_CALL
getByName(const OUString
& Name
) override
;
126 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
127 virtual sal_Bool SAL_CALL
hasByName(const OUString
& Name
) override
;
131 // access to a family of automatic styles (character or paragraph or ...)
132 class SwXAutoStyleFamily final
: public cppu::WeakImplHelper
< css::style::XAutoStyleFamily
>, public SvtListener
134 SwDocShell
*m_pDocShell
;
135 IStyleAccess::SwAutoStyleFamily m_eFamily
;
139 SwXAutoStyleFamily(SwDocShell
* pDocShell
, IStyleAccess::SwAutoStyleFamily eFamily
);
140 virtual ~SwXAutoStyleFamily() override
;
143 virtual css::uno::Reference
< css::style::XAutoStyle
> SAL_CALL
insertStyle( const css::uno::Sequence
< css::beans::PropertyValue
>& Values
) override
;
146 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration( ) override
;
149 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
150 virtual sal_Bool SAL_CALL
hasElements( ) override
;
152 virtual void Notify( const SfxHint
&) override
;
155 class SwXAutoStylesEnumerator final
: public cppu::WeakImplHelper
< css::container::XEnumeration
>, public SvtListener
157 std::unique_ptr
<SwAutoStylesEnumImpl
> m_pImpl
;
159 SwXAutoStylesEnumerator( SwDoc
& rDoc
, IStyleAccess::SwAutoStyleFamily eFam
);
160 virtual ~SwXAutoStylesEnumerator() override
;
163 virtual sal_Bool SAL_CALL
hasMoreElements( ) override
;
164 virtual css::uno::Any SAL_CALL
nextElement( ) override
;
166 virtual void Notify( const SfxHint
&) override
;
169 // an automatic style
170 class SwXAutoStyle final
: public cppu::WeakImplHelper
172 css::beans::XPropertySet
,
173 css::beans::XPropertyState
,
174 css::style::XAutoStyle
179 std::shared_ptr
<SfxItemSet
> mpSet
;
180 IStyleAccess::SwAutoStyleFamily meFamily
;
183 /// @throws css::beans::UnknownPropertyException
184 /// @throws css::lang::WrappedTargetException
185 /// @throws css::uno::RuntimeException
186 css::uno::Sequence
< css::uno::Any
> GetPropertyValues_Impl( const css::uno::Sequence
< OUString
>& aPropertyNames
);
190 SwXAutoStyle( SwDoc
* pDoc
, std::shared_ptr
<SfxItemSet
> pInitSet
, IStyleAccess::SwAutoStyleFamily eFam
);
191 virtual ~SwXAutoStyle() override
;
194 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
195 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
196 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
197 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
198 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
199 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
200 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
203 virtual void SAL_CALL
setPropertyValues( const css::uno::Sequence
< OUString
>& aPropertyNames
, const css::uno::Sequence
< css::uno::Any
>& aValues
) override
;
204 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPropertyValues( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
205 virtual void SAL_CALL
addPropertiesChangeListener( const css::uno::Sequence
< OUString
>& aPropertyNames
, const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& xListener
) override
;
206 virtual void SAL_CALL
removePropertiesChangeListener( const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& xListener
) override
;
207 virtual void SAL_CALL
firePropertiesChangeEvent( const css::uno::Sequence
< OUString
>& aPropertyNames
, const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& xListener
) override
;
210 virtual css::beans::PropertyState SAL_CALL
getPropertyState( const OUString
& PropertyName
) override
;
211 virtual css::uno::Sequence
< css::beans::PropertyState
> SAL_CALL
getPropertyStates( const css::uno::Sequence
< OUString
>& aPropertyName
) override
;
212 virtual void SAL_CALL
setPropertyToDefault( const OUString
& PropertyName
) override
;
213 virtual css::uno::Any SAL_CALL
getPropertyDefault( const OUString
& aPropertyName
) override
;
215 //XMultiPropertyStates
216 virtual void SAL_CALL
setAllPropertiesToDefault( ) override
;
217 virtual void SAL_CALL
setPropertiesToDefault( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
218 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPropertyDefaults( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
221 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getProperties() override
;
223 virtual void Notify( const SfxHint
& ) override
;
227 typedef std::map
<OUString
, sal_Int32
> CellStyleNameMap
;
229 /// A text table style is a UNO API wrapper for a SwTableAutoFormat
230 class SwXTextTableStyle final
: public cppu::WeakImplHelper
233 css::beans::XPropertySet
,
234 css::container::XNameContainer
,
235 css::lang::XServiceInfo
238 SwDocShell
* m_pDocShell
;
239 SwTableAutoFormat
* m_pTableAutoFormat
;
240 /// Stores SwTableAutoFormat when this is not a physical style.
241 std::unique_ptr
<SwTableAutoFormat
> m_pTableAutoFormat_Impl
;
242 /// If true, then it points to a core object, if false, then this is a created, but not-yet-inserted format.
257 FIRST_ROW_START_COLUMN_STYLE
,
258 FIRST_ROW_END_COLUMN_STYLE
,
259 LAST_ROW_START_COLUMN_STYLE
,
260 LAST_ROW_END_COLUMN_STYLE
,
261 FIRST_ROW_EVEN_COLUMN_STYLE
,
262 LAST_ROW_EVEN_COLUMN_STYLE
,
266 /// Fills m_aCellStyles with SwXTextCellStyles pointing to children of this style.
267 void UpdateCellStylesMapping();
268 static const CellStyleNameMap
& GetCellStyleNameMap();
269 rtl::Reference
<SwXTextCellStyle
> m_aCellStyles
[STYLE_COUNT
];
271 SwXTextTableStyle(SwDocShell
* pDocShell
, SwTableAutoFormat
* pTableAutoFormat
);
272 /// Create non physical style
273 SwXTextTableStyle(SwDocShell
* pDocShell
, const OUString
& rTableAutoFormatName
);
275 /// This function looks for a SwTableAutoFormat with given name. Returns nullptr if could not be found.
276 static SwTableAutoFormat
* GetTableAutoFormat(SwDocShell
* pDocShell
, std::u16string_view sName
);
277 /// Returns box format assigned to this style
278 SwTableAutoFormat
* GetTableFormat();
282 virtual sal_Bool SAL_CALL
isUserDefined() override
;
283 virtual sal_Bool SAL_CALL
isInUse() override
;
284 virtual OUString SAL_CALL
getParentStyle() override
;
285 virtual void SAL_CALL
setParentStyle(const OUString
& aParentStyle
) override
;
288 virtual OUString SAL_CALL
getName() override
;
289 virtual void SAL_CALL
setName(const OUString
& rName
) override
;
292 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
293 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
294 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) override
;
295 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
296 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& aListener
) override
;
297 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
298 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
301 virtual css::uno::Any SAL_CALL
getByName(const OUString
& rName
) override
;
302 virtual css::uno::Sequence
<OUString
> SAL_CALL
getElementNames() override
;
303 virtual sal_Bool SAL_CALL
hasByName(const OUString
& rName
) override
;
306 virtual void SAL_CALL
insertByName(const OUString
& rName
, const css::uno::Any
& aElement
) override
;
307 virtual void SAL_CALL
replaceByName(const OUString
& rName
, const css::uno::Any
& aElement
) override
;
308 virtual void SAL_CALL
removeByName(const OUString
& rName
) override
;
311 virtual css::uno::Type SAL_CALL
getElementType() override
;
312 virtual sal_Bool SAL_CALL
hasElements() override
;
315 virtual OUString SAL_CALL
getImplementationName() override
;
316 virtual sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
;
317 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
319 static rtl::Reference
<SwXTextTableStyle
> CreateXTextTableStyle(SwDocShell
* pDocShell
, const OUString
& rTableAutoFormatName
);
322 /// A text cell style is a UNO API wrapper for a SwBoxAutoFormat core class
323 class SwXTextCellStyle final
: public cppu::WeakImplHelper
326 css::beans::XPropertySet
,
327 css::beans::XPropertyState
,
328 css::lang::XServiceInfo
331 SwDocShell
* m_pDocShell
;
332 SwBoxAutoFormat
* m_pBoxAutoFormat
;
333 /// Stores SwBoxAutoFormat when this is not a physical style.
334 std::shared_ptr
<SwBoxAutoFormat
> m_pBoxAutoFormat_Impl
;
335 OUString m_sParentStyle
;
337 /// If true, then it points to a core object, if false, then this is a created, but not-yet-inserted format.
341 SwXTextCellStyle(SwDocShell
* pDocShell
, SwBoxAutoFormat
* pBoxAutoFormat
, OUString sParentStyle
);
342 /// Create non physical style
343 SwXTextCellStyle(SwDocShell
* pDocShell
, OUString sName
);
346 * This function looks for a SwBoxAutoFormat with given name. Parses the name and returns parent name.
347 * @param pDocShell pointer to a SwDocShell.
348 * @param sName Name of a SwBoxAutoFormat to look for.
349 * @param pParentName Optional output. Pointer to an OUString where parsed parent name will be returned.
350 * @return Pointer to a SwBoxAutoFormat, nullptr if not found.
352 static SwBoxAutoFormat
* GetBoxAutoFormat(SwDocShell
* pDocShell
, std::u16string_view sName
, OUString
* pParentName
);
353 /// returns box format assigned to this style
354 SwBoxAutoFormat
* GetBoxFormat();
355 /// Sets the address of SwBoxAutoFormat this style is bound to. Usable only when style is physical.
356 void SetBoxFormat(SwBoxAutoFormat
* pBoxFormat
);
358 bool IsPhysical() const;
361 virtual sal_Bool SAL_CALL
isUserDefined() override
;
362 virtual sal_Bool SAL_CALL
isInUse() override
;
363 virtual OUString SAL_CALL
getParentStyle() override
;
364 virtual void SAL_CALL
setParentStyle(const OUString
& aParentStyle
) override
;
367 virtual OUString SAL_CALL
getName() override
;
368 virtual void SAL_CALL
setName(const OUString
& sName
) override
;
371 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
372 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
373 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) override
;
374 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
375 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& aListener
) override
;
376 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
377 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& PropertyName
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
380 virtual css::beans::PropertyState SAL_CALL
getPropertyState(const OUString
& PropertyName
) override
;
381 virtual css::uno::Sequence
<css::beans::PropertyState
> SAL_CALL
getPropertyStates(const css::uno::Sequence
< OUString
>& aPropertyName
) override
;
382 virtual void SAL_CALL
setPropertyToDefault(const OUString
& PropertyName
) override
;
383 virtual css::uno::Any SAL_CALL
getPropertyDefault(const OUString
& aPropertyName
) override
;
386 virtual OUString SAL_CALL
getImplementationName() override
;
387 virtual sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
;
388 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
390 static rtl::Reference
<SwXTextCellStyle
> CreateXTextCellStyle(SwDocShell
* pDocShell
, const OUString
& sName
);
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */