Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / unostyle.hxx
blob3f45f52e175f51313edcabca5d910f272e09214c
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 .
19 #ifndef INCLUDED_SW_INC_UNOSTYLE_HXX
20 #define INCLUDED_SW_INC_UNOSTYLE_HXX
22 #include <svl/style.hxx>
23 #include <svl/lstner.hxx>
24 #include <unocoll.hxx>
25 #include <unomap.hxx>
26 #include <com/sun/star/style/XStyle.hpp>
27 #include <com/sun/star/lang/XUnoTunnel.hpp>
28 #include <com/sun/star/style/XStyleLoader.hpp>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/beans/XMultiPropertySet.hpp>
32 #include <com/sun/star/beans/XPropertyState.hpp>
33 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
34 #include <cppuhelper/implbase.hxx>
35 #include <com/sun/star/document/XEventsSupplier.hpp>
36 #include <calbck.hxx>
38 #include <com/sun/star/style/XAutoStyleFamily.hpp>
39 #include <com/sun/star/style/XAutoStyles.hpp>
40 #include <com/sun/star/style/XAutoStyle.hpp>
42 #include <istyleaccess.hxx>
43 #include <memory>
45 class SwDocShell;
46 class SfxItemPropertySet;
47 class SwXStyle;
48 class SwStyleProperties_Impl;
49 class SwAutoStylesEnumImpl;
50 class IStyleAccess;
51 class SfxItemSet;
52 namespace sw
54 class XStyleFamily;
57 class SwXStyleFamilies : public cppu::WeakImplHelper
59 css::container::XIndexAccess,
60 css::container::XNameAccess,
61 css::lang::XServiceInfo,
62 css::style::XStyleLoader
64 public SwUnoCollection
66 SwDocShell* m_pDocShell;
68 std::map<SfxStyleFamily, css::uno::Reference<css::container::XNameContainer>> m_vFamilies;
69 protected:
70 virtual ~SwXStyleFamilies() override;
71 public:
72 SwXStyleFamilies(SwDocShell& rDocShell);
74 //XNameAccess
75 virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
76 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
77 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
79 //XIndexAccess
80 virtual sal_Int32 SAL_CALL getCount() override;
81 virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
83 //XElementAccess
84 virtual css::uno::Type SAL_CALL getElementType( ) override;
85 virtual sal_Bool SAL_CALL hasElements( ) override;
87 //XStyleLoader
88 virtual void SAL_CALL loadStylesFromURL(const OUString& rURL, const css::uno::Sequence< css::beans::PropertyValue >& aOptions) override;
89 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getStyleLoaderOptions() override;
91 //XServiceInfo
92 virtual OUString SAL_CALL getImplementationName() override;
93 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
94 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
96 static css::uno::Reference<css::style::XStyle> CreateStyle(SfxStyleFamily eFamily, 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 namespace sw
104 class ICoreFrameStyle
106 public:
107 virtual void SetItem(enum RES_FRMATR eAtr, const SfxPoolItem& rItem) =0;
108 virtual const SfxPoolItem* GetItem(enum RES_FRMATR eAtr) =0;
109 virtual css::document::XEventsSupplier& GetEventsSupplier() =0;
110 virtual ~ICoreFrameStyle() {};
114 // access to all automatic style families
115 class SwXAutoStyles :
116 public cppu::WeakImplHelper< css::style::XAutoStyles >,
117 public SwUnoCollection
119 SwDocShell *m_pDocShell;
120 css::uno::Reference< css::style::XAutoStyleFamily > m_xAutoCharStyles;
121 css::uno::Reference< css::style::XAutoStyleFamily > m_xAutoRubyStyles;
122 css::uno::Reference< css::style::XAutoStyleFamily > m_xAutoParaStyles;
123 virtual ~SwXAutoStyles() override;
125 public:
126 SwXAutoStyles(SwDocShell& rDocShell);
128 //XIndexAccess
129 virtual sal_Int32 SAL_CALL getCount() override;
130 virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
132 //XElementAccess
133 virtual css::uno::Type SAL_CALL SAL_CALL getElementType( ) override;
134 virtual sal_Bool SAL_CALL SAL_CALL hasElements( ) override;
136 //XNameAccess
137 virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
138 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
139 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
143 // access to a family of automatic styles (character or paragraph or ...)
144 class SwXAutoStyleFamily : public cppu::WeakImplHelper< css::style::XAutoStyleFamily >,
145 public SwClient
147 SwDocShell *m_pDocShell;
148 IStyleAccess::SwAutoStyleFamily m_eFamily;
150 protected:
151 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
153 public:
154 SwXAutoStyleFamily(SwDocShell* pDocShell, IStyleAccess::SwAutoStyleFamily eFamily);
155 virtual ~SwXAutoStyleFamily() override;
157 //XAutoStyleFamily
158 virtual css::uno::Reference< css::style::XAutoStyle > SAL_CALL insertStyle( const css::uno::Sequence< css::beans::PropertyValue >& Values ) override;
160 //XEnumerationAccess
161 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override;
163 //XElementAccess
164 virtual css::uno::Type SAL_CALL SAL_CALL getElementType( ) override;
165 virtual sal_Bool SAL_CALL SAL_CALL hasElements( ) override;
169 class SwXAutoStylesEnumerator : public cppu::WeakImplHelper< css::container::XEnumeration >,
170 public SwClient
172 std::unique_ptr<SwAutoStylesEnumImpl> m_pImpl;
173 public:
174 SwXAutoStylesEnumerator( SwDoc* pDoc, IStyleAccess::SwAutoStyleFamily eFam );
175 virtual ~SwXAutoStylesEnumerator() override;
177 //XEnumeration
178 virtual sal_Bool SAL_CALL hasMoreElements( ) override;
179 virtual css::uno::Any SAL_CALL nextElement( ) override;
180 protected:
181 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
184 // an automatic style
185 class SwXAutoStyle : public cppu::WeakImplHelper
187 css::beans::XPropertySet,
188 css::beans::XPropertyState,
189 css::style::XAutoStyle
191 public SwClient
193 private:
194 std::shared_ptr<SfxItemSet> mpSet;
195 IStyleAccess::SwAutoStyleFamily meFamily;
196 SwDoc& mrDoc;
198 /// @throws css::beans::UnknownPropertyException
199 /// @throws css::lang::WrappedTargetException
200 /// @throws css::uno::RuntimeException
201 css::uno::Sequence< css::uno::Any > SAL_CALL GetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames );
203 public:
205 SwXAutoStyle( SwDoc* pDoc, std::shared_ptr<SfxItemSet> const & pInitSet, IStyleAccess::SwAutoStyleFamily eFam );
206 virtual ~SwXAutoStyle() override;
208 //XPropertySet
209 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
210 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
211 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
212 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
213 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
214 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
215 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
217 //XMultiPropertySet
218 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override;
219 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override;
220 virtual void SAL_CALL addPropertiesChangeListener( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener ) override;
221 virtual void SAL_CALL removePropertiesChangeListener( const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener ) override;
222 virtual void SAL_CALL firePropertiesChangeEvent( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener ) override;
224 //XPropertyState
225 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) override;
226 virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates( const css::uno::Sequence< OUString >& aPropertyName ) override;
227 virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) override;
228 virtual css::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) override;
230 //XMultiPropertyStates
231 virtual void SAL_CALL setAllPropertiesToDefault( ) override;
232 virtual void SAL_CALL setPropertiesToDefault( const css::uno::Sequence< OUString >& aPropertyNames ) override;
233 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyDefaults( const css::uno::Sequence< OUString >& aPropertyNames ) override;
235 // Special
236 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getProperties() override;
237 protected:
238 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
242 class SwTableAutoFormat;
243 typedef std::map<OUString, sal_Int32> CellStyleNameMap;
245 /// A text table style is a uno api wrapper for a SwTableAutoFormat
246 class SwXTextTableStyle : public cppu::WeakImplHelper
248 css::style::XStyle,
249 css::beans::XPropertySet,
250 css::container::XNameContainer,
251 css::lang::XServiceInfo
254 SwDocShell* m_pDocShell;
255 SwTableAutoFormat* m_pTableAutoFormat;
256 /// Stores SwTableAutoFormat when this is not a physical style.
257 std::unique_ptr<SwTableAutoFormat> m_pTableAutoFormat_Impl;
258 /// If true, then it points to a core object, if false, then this is a created, but not-yet-inserted format.
259 bool m_bPhysical;
261 enum {
262 FIRST_ROW_STYLE = 0,
263 LAST_ROW_STYLE,
264 FIRST_COLUMN_STYLE,
265 LAST_COLUMN_STYLE,
266 EVEN_ROWS_STYLE,
267 ODD_ROWS_STYLE,
268 EVEN_COLUMNS_STYLE,
269 ODD_COLUMNS_STYLE,
270 BODY_STYLE,
271 BACKGROUND_STYLE,
272 // loext namespace
273 FIRST_ROW_START_COLUMN_STYLE,
274 FIRST_ROW_END_COLUMN_STYLE,
275 LAST_ROW_START_COLUMN_STYLE,
276 LAST_ROW_END_COLUMN_STYLE,
277 FIRST_ROW_EVEN_COLUMN_STYLE,
278 LAST_ROW_EVEN_COLUMN_STYLE,
279 STYLE_COUNT
282 /// Fills m_aCellStyles with SwXTextCellStyles pointing to children of this style.
283 void UpdateCellStylesMapping();
284 static const CellStyleNameMap& GetCellStyleNameMap();
285 css::uno::Reference<css::style::XStyle> m_aCellStyles[STYLE_COUNT];
286 public:
287 SwXTextTableStyle(SwDocShell* pDocShell, SwTableAutoFormat* pTableAutoFormat);
288 /// Create non physical style
289 SwXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName);
291 /// This function looks for a SwTableAutoFormat with given name. Returns nullptr if could not be found.
292 static SwTableAutoFormat* GetTableAutoFormat(SwDocShell* pDocShell, const OUString& sName);
293 /// Returns box format assigned to this style
294 SwTableAutoFormat* GetTableFormat();
295 void SetPhysical();
297 //XStyle
298 virtual sal_Bool SAL_CALL isUserDefined() override;
299 virtual sal_Bool SAL_CALL isInUse() override;
300 virtual OUString SAL_CALL getParentStyle() override;
301 virtual void SAL_CALL setParentStyle(const OUString& aParentStyle ) override;
303 //XNamed
304 virtual OUString SAL_CALL getName() override;
305 virtual void SAL_CALL setName(const OUString& rName) override;
307 //XPropertySet
308 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
309 virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName, const css::uno::Any& aValue) override;
310 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
311 virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
312 virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference<css::beans::XPropertyChangeListener>& aListener) override;
313 virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
314 virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
316 //XNameAccess
317 virtual css::uno::Any SAL_CALL getByName(const OUString& rName) override;
318 virtual css::uno::Sequence<OUString> SAL_CALL getElementNames() override;
319 virtual sal_Bool SAL_CALL hasByName(const OUString& rName) override;
321 //XNameContainer
322 virtual void SAL_CALL insertByName(const OUString& rName, const css::uno::Any& aElement) override;
323 virtual void SAL_CALL replaceByName(const OUString& rName, const css::uno::Any& aElement) override;
324 virtual void SAL_CALL removeByName(const OUString& rName) override;
326 //XElementAccess
327 virtual css::uno::Type SAL_CALL getElementType() override;
328 virtual sal_Bool SAL_CALL hasElements() override;
330 //XServiceInfo
331 virtual OUString SAL_CALL getImplementationName() override;
332 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
333 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
335 static css::uno::Reference<css::style::XStyle> CreateXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName);
338 class SwBoxAutoFormat;
339 /// A text cell style is a uno api wrapper for a SwBoxAutoFormat core class
340 class SwXTextCellStyle : public cppu::WeakImplHelper
342 css::style::XStyle,
343 css::beans::XPropertySet,
344 css::beans::XPropertyState,
345 css::lang::XServiceInfo
348 SwDocShell* m_pDocShell;
349 SwBoxAutoFormat* m_pBoxAutoFormat;
350 /// Stores SwBoxAutoFormat when this is not a physical style.
351 std::shared_ptr<SwBoxAutoFormat> m_pBoxAutoFormat_Impl;
352 OUString m_sParentStyle;
353 OUString m_sName;
354 /// If true, then it points to a core object, if false, then this is a created, but not-yet-inserted format.
355 bool m_bPhysical;
357 public:
358 SwXTextCellStyle(SwDocShell* pDocShell, SwBoxAutoFormat* pBoxAutoFormat, const OUString& sParentStyle);
359 /// Create non physical style
360 SwXTextCellStyle(SwDocShell* pDocShell, const OUString& sName);
363 * This function looks for a SwBoxAutoFormat with given name. Parses the name and returns parent name.
364 * @param pDocShell pointer to a SwDocShell.
365 * @param sName Name of a SwBoxAutoFormat to look for.
366 * @param pParentName Optional output. Pointer to a OUString where parsed parent name will be returned.
367 * @return Pointer to a SwBoxAutoFormat, nullptr if not found.
369 static SwBoxAutoFormat* GetBoxAutoFormat(SwDocShell* pDocShell, const OUString& sName, OUString* pParentName);
370 /// returns box format assigned to this style
371 SwBoxAutoFormat* GetBoxFormat();
372 /// Sets the address of SwBoxAutoFormat this style is bound to. Usable only when style is physical.
373 void SetBoxFormat(SwBoxAutoFormat* pBoxFormat);
374 void SetPhysical();
375 bool IsPhysical();
377 //XStyle
378 virtual sal_Bool SAL_CALL isUserDefined() override;
379 virtual sal_Bool SAL_CALL isInUse() override;
380 virtual OUString SAL_CALL getParentStyle() override;
381 virtual void SAL_CALL setParentStyle(const OUString& aParentStyle ) override;
383 //XNamed
384 virtual OUString SAL_CALL getName() override;
385 virtual void SAL_CALL setName(const OUString& sName) override;
387 //XPropertySet
388 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
389 virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName, const css::uno::Any& aValue) override;
390 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
391 virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
392 virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference<css::beans::XPropertyChangeListener>& aListener) override;
393 virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
394 virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
396 //XPropertyState
397 virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString& PropertyName) override;
398 virtual css::uno::Sequence<css::beans::PropertyState> SAL_CALL getPropertyStates(const css::uno::Sequence< OUString >& aPropertyName) override;
399 virtual void SAL_CALL setPropertyToDefault(const OUString& PropertyName) override;
400 virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString& aPropertyName) override;
402 //XServiceInfo
403 virtual OUString SAL_CALL getImplementationName() override;
404 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
405 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
407 static css::uno::Reference<css::style::XStyle> CreateXTextCellStyle(SwDocShell* pDocShell, const OUString& sName);
409 #endif
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */