/src/libreoffice/svx/source/table/tabledesign.cxx
Line | Count | Source |
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 | | |
21 | | #include <com/sun/star/style/XStyle.hpp> |
22 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
23 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
24 | | #include <com/sun/star/lang/XComponent.hpp> |
25 | | #include <com/sun/star/lang/XSingleServiceFactory.hpp> |
26 | | #include <com/sun/star/container/XIndexReplace.hpp> |
27 | | #include <com/sun/star/container/XNameContainer.hpp> |
28 | | #include <com/sun/star/beans/XPropertySet.hpp> |
29 | | #include <com/sun/star/util/XModifiable.hpp> |
30 | | #include <com/sun/star/util/XModifyListener.hpp> |
31 | | #include <com/sun/star/form/XReset.hpp> |
32 | | |
33 | | #include <vcl/svapp.hxx> |
34 | | |
35 | | #include <comphelper/compbase.hxx> |
36 | | #include <comphelper/interfacecontainer4.hxx> |
37 | | #include <cppuhelper/implbase.hxx> |
38 | | #include <cppuhelper/supportsservice.hxx> |
39 | | #include <comphelper/sequence.hxx> |
40 | | |
41 | | #include <svx/sdr/table/tabledesign.hxx> |
42 | | #include <svx/dialmgr.hxx> |
43 | | #include <svx/strings.hrc> |
44 | | |
45 | | #include "sdrtableobjimpl.hxx" |
46 | | |
47 | | #include <vector> |
48 | | #include <map> |
49 | | |
50 | | |
51 | | using namespace css; |
52 | | using namespace ::com::sun::star::uno; |
53 | | using namespace ::com::sun::star::style; |
54 | | using namespace ::com::sun::star::lang; |
55 | | using namespace ::com::sun::star::beans; |
56 | | using namespace ::com::sun::star::util; |
57 | | using namespace ::com::sun::star::container; |
58 | | |
59 | | namespace sdr::table { |
60 | | |
61 | | typedef std::map< OUString, sal_Int32 > CellStyleNameMap; |
62 | | |
63 | | typedef ::comphelper::WeakComponentImplHelper< XStyle, XNameReplace, XServiceInfo, XIndexReplace, XModifiable, XModifyListener, XPropertySet > TableDesignStyleBase; |
64 | | |
65 | | namespace { |
66 | | |
67 | | class TableDesignStyle : public TableDesignStyleBase |
68 | | { |
69 | | public: |
70 | | TableDesignStyle(); |
71 | | |
72 | | // XServiceInfo |
73 | | virtual OUString SAL_CALL getImplementationName() override; |
74 | | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
75 | | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
76 | | |
77 | | // XStyle |
78 | | virtual sal_Bool SAL_CALL isUserDefined() override; |
79 | | virtual sal_Bool SAL_CALL isInUse() override; |
80 | | virtual OUString SAL_CALL getParentStyle() override; |
81 | | virtual void SAL_CALL setParentStyle( const OUString& aParentStyle ) override; |
82 | | |
83 | | // XNamed |
84 | | virtual OUString SAL_CALL getName() override; |
85 | | virtual void SAL_CALL setName( const OUString& aName ) override; |
86 | | |
87 | | // XNameAccess |
88 | | virtual Any SAL_CALL getByName( const OUString& aName ) override; |
89 | | virtual Sequence< OUString > SAL_CALL getElementNames() override; |
90 | | virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; |
91 | | |
92 | | // XElementAccess |
93 | | virtual css::uno::Type SAL_CALL getElementType() override; |
94 | | virtual sal_Bool SAL_CALL hasElements() override; |
95 | | |
96 | | // XIndexAccess |
97 | | virtual sal_Int32 SAL_CALL getCount() override ; |
98 | | virtual Any SAL_CALL getByIndex( sal_Int32 Index ) override; |
99 | | |
100 | | // XIndexReplace |
101 | | virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) override; |
102 | | |
103 | | // XNameReplace |
104 | | virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement ) override; |
105 | | |
106 | | // XPropertySet |
107 | | virtual Reference<XPropertySetInfo> SAL_CALL getPropertySetInfo() override; |
108 | | virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) override; |
109 | | virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; |
110 | | virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& xListener ) override; |
111 | | virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& aListener ) override; |
112 | | virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener>& aListener ) override; |
113 | | virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,const Reference<XVetoableChangeListener>&aListener ) override; |
114 | | |
115 | | // XModifiable |
116 | | virtual sal_Bool SAL_CALL isModified() override; |
117 | | virtual void SAL_CALL setModified( sal_Bool bModified ) override; |
118 | | |
119 | | // XModifyBroadcaster |
120 | | virtual void SAL_CALL addModifyListener( const Reference< XModifyListener >& aListener ) override; |
121 | | virtual void SAL_CALL removeModifyListener( const Reference< XModifyListener >& aListener ) override; |
122 | | |
123 | | // XModifyListener |
124 | | virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override; |
125 | | virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; |
126 | | |
127 | | void notifyModifyListener(); |
128 | | void resetUserDefined(); |
129 | | |
130 | | // this function is called upon disposing the component |
131 | | virtual void disposing(std::unique_lock<std::mutex>& aGuard) override; |
132 | | |
133 | | static const CellStyleNameMap& getCellStyleNameMap(); |
134 | | |
135 | | bool mbUserDefined, mbModified; |
136 | | OUString msName; |
137 | | Reference< XStyle > maCellStyles[style_count]; |
138 | | comphelper::OInterfaceContainerHelper4<XModifyListener> maModifyListeners; |
139 | | }; |
140 | | |
141 | | } |
142 | | |
143 | | typedef std::vector< Reference< XStyle > > TableDesignStyleVector; |
144 | | |
145 | | namespace { |
146 | | |
147 | | class TableDesignFamily : public ::cppu::WeakImplHelper< XNameContainer, XNamed, XIndexAccess, XSingleServiceFactory, XServiceInfo, XComponent, XPropertySet, form::XReset > |
148 | | { |
149 | | public: |
150 | | // XServiceInfo |
151 | | virtual OUString SAL_CALL getImplementationName() override; |
152 | | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
153 | | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
154 | | |
155 | | // XNamed |
156 | | virtual OUString SAL_CALL getName( ) override; |
157 | | virtual void SAL_CALL setName( const OUString& aName ) override; |
158 | | |
159 | | // XNameAccess |
160 | | virtual Any SAL_CALL getByName( const OUString& aName ) override; |
161 | | virtual Sequence< OUString > SAL_CALL getElementNames() override; |
162 | | virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; |
163 | | |
164 | | // XElementAccess |
165 | | virtual Type SAL_CALL getElementType() override; |
166 | | virtual sal_Bool SAL_CALL hasElements() override; |
167 | | |
168 | | // XIndexAccess |
169 | | virtual sal_Int32 SAL_CALL getCount() override ; |
170 | | virtual Any SAL_CALL getByIndex( sal_Int32 Index ) override; |
171 | | |
172 | | // XNameContainer |
173 | | virtual void SAL_CALL insertByName( const OUString& aName, const Any& aElement ) override; |
174 | | virtual void SAL_CALL removeByName( const OUString& Name ) override; |
175 | | |
176 | | // XNameReplace |
177 | | virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement ) override; |
178 | | |
179 | | // XSingleServiceFactory |
180 | | virtual Reference< XInterface > SAL_CALL createInstance( ) override; |
181 | | virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& aArguments ) override; |
182 | | |
183 | | // XComponent |
184 | | virtual void SAL_CALL dispose( ) override; |
185 | | virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) override; |
186 | | virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) override; |
187 | | |
188 | | // XPropertySet |
189 | | virtual Reference<XPropertySetInfo> SAL_CALL getPropertySetInfo() override; |
190 | | virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) override; |
191 | | virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; |
192 | | virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& xListener ) override; |
193 | | virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& aListener ) override; |
194 | | virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener>& aListener ) override; |
195 | | virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,const Reference<XVetoableChangeListener>&aListener ) override; |
196 | | |
197 | | // XReset |
198 | | virtual void SAL_CALL reset() override; |
199 | | virtual void SAL_CALL addResetListener( const Reference<form::XResetListener>& aListener ) override; |
200 | | virtual void SAL_CALL removeResetListener( const Reference<form::XResetListener>& aListener ) override; |
201 | | |
202 | | TableDesignStyleVector maDesigns; |
203 | | }; |
204 | | |
205 | | } |
206 | | |
207 | | TableDesignStyle::TableDesignStyle() |
208 | 0 | : mbUserDefined(true) |
209 | 0 | , mbModified(false) |
210 | 0 | { |
211 | 0 | } |
212 | | |
213 | | const CellStyleNameMap& TableDesignStyle::getCellStyleNameMap() |
214 | 0 | { |
215 | 0 | static CellStyleNameMap const aMap |
216 | 0 | { |
217 | 0 | { u"first-row"_ustr , first_row_style }, |
218 | 0 | { u"last-row"_ustr , last_row_style }, |
219 | 0 | { u"first-column"_ustr , first_column_style }, |
220 | 0 | { u"last-column"_ustr , last_column_style }, |
221 | 0 | { u"body"_ustr , body_style }, |
222 | 0 | { u"even-rows"_ustr , even_rows_style }, |
223 | 0 | { u"odd-rows"_ustr , odd_rows_style }, |
224 | 0 | { u"even-columns"_ustr , even_columns_style }, |
225 | 0 | { u"odd-columns"_ustr , odd_columns_style }, |
226 | 0 | { u"background"_ustr , background_style }, |
227 | 0 | }; |
228 | |
|
229 | 0 | return aMap; |
230 | 0 | } |
231 | | |
232 | | // XServiceInfo |
233 | | OUString SAL_CALL TableDesignStyle::getImplementationName() |
234 | 0 | { |
235 | 0 | return u"TableDesignStyle"_ustr; |
236 | 0 | } |
237 | | |
238 | | sal_Bool SAL_CALL TableDesignStyle::supportsService( const OUString& ServiceName ) |
239 | 0 | { |
240 | 0 | return cppu::supportsService( this, ServiceName ); |
241 | 0 | } |
242 | | |
243 | | Sequence< OUString > SAL_CALL TableDesignStyle::getSupportedServiceNames() |
244 | 0 | { |
245 | 0 | return { u"com.sun.star.style.Style"_ustr }; |
246 | 0 | } |
247 | | |
248 | | // XStyle |
249 | | sal_Bool SAL_CALL TableDesignStyle::isUserDefined() |
250 | 0 | { |
251 | 0 | return mbUserDefined; |
252 | 0 | } |
253 | | |
254 | | void TableDesignStyle::resetUserDefined() |
255 | 0 | { |
256 | 0 | mbUserDefined = false; |
257 | 0 | } |
258 | | |
259 | | sal_Bool SAL_CALL TableDesignStyle::isInUse() |
260 | 0 | { |
261 | 0 | std::unique_lock aGuard( m_aMutex ); |
262 | 0 | if (maModifyListeners.getLength(aGuard)) |
263 | 0 | { |
264 | 0 | comphelper::OInterfaceIteratorHelper4 it(aGuard, maModifyListeners); |
265 | 0 | while ( it.hasMoreElements() ) |
266 | 0 | { |
267 | 0 | SdrTableObjImpl* pUser = dynamic_cast< SdrTableObjImpl* >( it.next().get() ); |
268 | 0 | if( pUser && pUser->isInUse() ) |
269 | 0 | return true; |
270 | 0 | } |
271 | 0 | } |
272 | 0 | return false; |
273 | 0 | } |
274 | | |
275 | | |
276 | | OUString SAL_CALL TableDesignStyle::getParentStyle() |
277 | 0 | { |
278 | 0 | return OUString(); |
279 | 0 | } |
280 | | |
281 | | |
282 | | void SAL_CALL TableDesignStyle::setParentStyle( const OUString& ) |
283 | 0 | { |
284 | 0 | } |
285 | | |
286 | | |
287 | | // XNamed |
288 | | |
289 | | |
290 | | OUString SAL_CALL TableDesignStyle::getName() |
291 | 0 | { |
292 | 0 | return msName; |
293 | 0 | } |
294 | | |
295 | | |
296 | | void SAL_CALL TableDesignStyle::setName( const OUString& rName ) |
297 | 0 | { |
298 | 0 | msName = rName; |
299 | 0 | } |
300 | | |
301 | | |
302 | | // XNameAccess |
303 | | |
304 | | |
305 | | Any SAL_CALL TableDesignStyle::getByName( const OUString& rName ) |
306 | 0 | { |
307 | 0 | const CellStyleNameMap& rMap = getCellStyleNameMap(); |
308 | |
|
309 | 0 | CellStyleNameMap::const_iterator iter = rMap.find( rName ); |
310 | 0 | if( iter == rMap.end() ) |
311 | 0 | throw NoSuchElementException(); |
312 | | |
313 | 0 | return Any( maCellStyles[(*iter).second] ); |
314 | 0 | } |
315 | | |
316 | | |
317 | | Sequence< OUString > SAL_CALL TableDesignStyle::getElementNames() |
318 | 0 | { |
319 | 0 | return comphelper::mapKeysToSequence( getCellStyleNameMap() ); |
320 | 0 | } |
321 | | |
322 | | |
323 | | sal_Bool SAL_CALL TableDesignStyle::hasByName( const OUString& rName ) |
324 | 0 | { |
325 | 0 | const CellStyleNameMap& rMap = getCellStyleNameMap(); |
326 | |
|
327 | 0 | CellStyleNameMap::const_iterator iter = rMap.find( rName ); |
328 | 0 | return iter != rMap.end(); |
329 | 0 | } |
330 | | |
331 | | |
332 | | // XElementAccess |
333 | | |
334 | | |
335 | | Type SAL_CALL TableDesignStyle::getElementType() |
336 | 0 | { |
337 | 0 | return cppu::UnoType<XStyle>::get(); |
338 | 0 | } |
339 | | |
340 | | |
341 | | sal_Bool SAL_CALL TableDesignStyle::hasElements() |
342 | 0 | { |
343 | 0 | return true; |
344 | 0 | } |
345 | | |
346 | | |
347 | | // XIndexAccess |
348 | | |
349 | | |
350 | | sal_Int32 SAL_CALL TableDesignStyle::getCount() |
351 | 0 | { |
352 | 0 | return style_count; |
353 | 0 | } |
354 | | |
355 | | |
356 | | Any SAL_CALL TableDesignStyle::getByIndex( sal_Int32 Index ) |
357 | 0 | { |
358 | 0 | if( (Index < 0) || (Index >= style_count) ) |
359 | 0 | throw IndexOutOfBoundsException(); |
360 | | |
361 | 0 | std::unique_lock aGuard( m_aMutex ); |
362 | 0 | return Any( maCellStyles[Index] ); |
363 | 0 | } |
364 | | |
365 | | |
366 | | // XIndexReplace |
367 | | |
368 | | void SAL_CALL TableDesignStyle::replaceByIndex( sal_Int32 Index, const Any& aElement ) |
369 | 0 | { |
370 | 0 | if( (Index < 0) || (Index >= style_count) ) |
371 | 0 | throw IndexOutOfBoundsException(); |
372 | | |
373 | 0 | const CellStyleNameMap& rMap = getCellStyleNameMap(); |
374 | 0 | auto iter = std::find_if(rMap.begin(), rMap.end(), |
375 | 0 | [&Index](const auto& item) { return Index == item.second; }); |
376 | 0 | if (iter != rMap.end()) |
377 | 0 | replaceByName(iter->first, aElement); |
378 | 0 | } |
379 | | |
380 | | |
381 | | // XNameReplace |
382 | | |
383 | | |
384 | | void SAL_CALL TableDesignStyle::replaceByName( const OUString& rName, const Any& aElement ) |
385 | 0 | { |
386 | 0 | const CellStyleNameMap& rMap = getCellStyleNameMap(); |
387 | 0 | CellStyleNameMap::const_iterator iter = rMap.find( rName ); |
388 | 0 | if( iter == rMap.end() ) |
389 | 0 | throw NoSuchElementException(); |
390 | | |
391 | | |
392 | 0 | Reference< XStyle > xNewStyle; |
393 | 0 | if( !(aElement >>= xNewStyle) ) |
394 | 0 | throw IllegalArgumentException(); |
395 | | |
396 | 0 | const sal_Int32 nIndex = (*iter).second; |
397 | |
|
398 | 0 | std::unique_lock aGuard( m_aMutex ); |
399 | |
|
400 | 0 | Reference< XStyle > xOldStyle( maCellStyles[nIndex] ); |
401 | |
|
402 | 0 | if( xNewStyle == xOldStyle ) |
403 | 0 | return; |
404 | | |
405 | 0 | Reference< XModifyListener > xListener( this ); |
406 | | |
407 | | // end listening to old style, if possible |
408 | 0 | Reference< XModifyBroadcaster > xOldBroadcaster( xOldStyle, UNO_QUERY ); |
409 | 0 | if( xOldBroadcaster.is() ) |
410 | 0 | xOldBroadcaster->removeModifyListener( xListener ); |
411 | | |
412 | | // start listening to new style, if possible |
413 | 0 | Reference< XModifyBroadcaster > xNewBroadcaster( xNewStyle, UNO_QUERY ); |
414 | 0 | if( xNewBroadcaster.is() ) |
415 | 0 | xNewBroadcaster->addModifyListener( xListener ); |
416 | |
|
417 | 0 | if (xNewStyle && xNewStyle->isUserDefined()) |
418 | 0 | mbModified = true; |
419 | |
|
420 | 0 | maCellStyles[nIndex] = std::move(xNewStyle); |
421 | 0 | } |
422 | | |
423 | | |
424 | | // XComponent |
425 | | |
426 | | |
427 | | void TableDesignStyle::disposing(std::unique_lock<std::mutex>& aGuard) |
428 | 0 | { |
429 | 0 | maModifyListeners.disposeAndClear(aGuard, EventObject(Reference<XComponent>(this))); |
430 | |
|
431 | 0 | for(Reference<XStyle> & rCellStyle : maCellStyles) |
432 | 0 | { |
433 | 0 | Reference<XModifyBroadcaster> xBroadcaster(rCellStyle, UNO_QUERY); |
434 | 0 | if (xBroadcaster) |
435 | 0 | xBroadcaster->removeModifyListener(this); |
436 | 0 | rCellStyle.clear(); |
437 | 0 | } |
438 | 0 | } |
439 | | |
440 | | // XPropertySet |
441 | | |
442 | | Reference<XPropertySetInfo> TableDesignStyle::getPropertySetInfo() |
443 | 0 | { |
444 | 0 | return {}; |
445 | 0 | } |
446 | | |
447 | | void TableDesignStyle::setPropertyValue( const OUString&, const Any& ) |
448 | 0 | { |
449 | 0 | } |
450 | | |
451 | | Any TableDesignStyle::getPropertyValue( const OUString& PropertyName ) |
452 | 0 | { |
453 | 0 | if (PropertyName != "IsPhysical") |
454 | 0 | throw UnknownPropertyException("unknown property: " + PropertyName, getXWeak()); |
455 | | |
456 | 0 | return Any(mbModified || mbUserDefined); |
457 | 0 | } |
458 | | |
459 | | void TableDesignStyle::addPropertyChangeListener( const OUString&, const Reference<XPropertyChangeListener>& ) |
460 | 0 | { |
461 | 0 | } |
462 | | |
463 | | void TableDesignStyle::removePropertyChangeListener( const OUString&, const Reference<XPropertyChangeListener>& ) |
464 | 0 | { |
465 | 0 | } |
466 | | |
467 | | void TableDesignStyle::addVetoableChangeListener( const OUString&, const Reference<XVetoableChangeListener>& ) |
468 | 0 | { |
469 | 0 | } |
470 | | |
471 | | void TableDesignStyle::removeVetoableChangeListener( const OUString&,const Reference<XVetoableChangeListener>& ) |
472 | 0 | { |
473 | 0 | } |
474 | | |
475 | | // XModifiable |
476 | | |
477 | | sal_Bool TableDesignStyle::isModified() |
478 | 0 | { |
479 | 0 | return mbModified; |
480 | 0 | } |
481 | | |
482 | | void TableDesignStyle::setModified( sal_Bool bModified ) |
483 | 0 | { |
484 | 0 | mbModified = bModified; |
485 | 0 | notifyModifyListener(); |
486 | 0 | } |
487 | | |
488 | | |
489 | | // XModifyBroadcaster |
490 | | |
491 | | |
492 | | void SAL_CALL TableDesignStyle::addModifyListener( const Reference< XModifyListener >& xListener ) |
493 | 0 | { |
494 | 0 | std::unique_lock aGuard( m_aMutex ); |
495 | 0 | if (m_bDisposed) |
496 | 0 | { |
497 | 0 | aGuard.unlock(); |
498 | 0 | EventObject aEvt( getXWeak() ); |
499 | 0 | xListener->disposing( aEvt ); |
500 | 0 | } |
501 | 0 | else |
502 | 0 | { |
503 | 0 | maModifyListeners.addInterface( aGuard, xListener ); |
504 | 0 | } |
505 | 0 | } |
506 | | |
507 | | |
508 | | void SAL_CALL TableDesignStyle::removeModifyListener( const Reference< XModifyListener >& xListener ) |
509 | 0 | { |
510 | 0 | std::unique_lock aGuard( m_aMutex ); |
511 | 0 | maModifyListeners.removeInterface( aGuard, xListener ); |
512 | 0 | } |
513 | | |
514 | | |
515 | | void TableDesignStyle::notifyModifyListener() |
516 | 0 | { |
517 | 0 | std::unique_lock aGuard( m_aMutex ); |
518 | |
|
519 | 0 | if( maModifyListeners.getLength(aGuard) ) |
520 | 0 | { |
521 | 0 | EventObject aEvt( getXWeak() ); |
522 | 0 | maModifyListeners.forEach(aGuard, |
523 | 0 | [&] (Reference<XModifyListener> const& xListener) |
524 | 0 | { return xListener->modified(aEvt); }); |
525 | 0 | } |
526 | 0 | } |
527 | | |
528 | | |
529 | | // XModifyListener |
530 | | |
531 | | |
532 | | // if we get a modify hint from a style, notify all registered XModifyListener |
533 | | void SAL_CALL TableDesignStyle::modified( const css::lang::EventObject& ) |
534 | 0 | { |
535 | 0 | notifyModifyListener(); |
536 | 0 | } |
537 | | |
538 | | |
539 | | void SAL_CALL TableDesignStyle::disposing( const css::lang::EventObject& ) |
540 | 0 | { |
541 | 0 | } |
542 | | |
543 | | |
544 | | // TableStyle |
545 | | |
546 | | |
547 | | // XServiceInfo |
548 | | OUString SAL_CALL TableDesignFamily::getImplementationName() |
549 | 0 | { |
550 | 0 | return u"TableDesignFamily"_ustr; |
551 | 0 | } |
552 | | |
553 | | sal_Bool SAL_CALL TableDesignFamily::supportsService( const OUString& ServiceName ) |
554 | 0 | { |
555 | 0 | return cppu::supportsService( this, ServiceName ); |
556 | 0 | } |
557 | | |
558 | | Sequence< OUString > SAL_CALL TableDesignFamily::getSupportedServiceNames() |
559 | 0 | { |
560 | 0 | return { u"com.sun.star.style.StyleFamily"_ustr }; |
561 | 0 | } |
562 | | |
563 | | // XNamed |
564 | | OUString SAL_CALL TableDesignFamily::getName() |
565 | 14.5k | { |
566 | 14.5k | return u"table"_ustr; |
567 | 14.5k | } |
568 | | |
569 | | void SAL_CALL TableDesignFamily::setName( const OUString& ) |
570 | 0 | { |
571 | 0 | } |
572 | | |
573 | | // XNameAccess |
574 | | Any SAL_CALL TableDesignFamily::getByName( const OUString& rName ) |
575 | 0 | { |
576 | 0 | SolarMutexGuard aGuard; |
577 | |
|
578 | 0 | auto iter = std::find_if(maDesigns.begin(), maDesigns.end(), |
579 | 0 | [&rName](const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; }); |
580 | 0 | if (iter != maDesigns.end()) |
581 | 0 | return Any( (*iter) ); |
582 | | |
583 | 0 | throw NoSuchElementException(); |
584 | 0 | } |
585 | | |
586 | | |
587 | | Sequence< OUString > SAL_CALL TableDesignFamily::getElementNames() |
588 | 79 | { |
589 | 79 | SolarMutexGuard aGuard; |
590 | | |
591 | 79 | Sequence< OUString > aRet( maDesigns.size() ); |
592 | 79 | OUString* pNames = aRet.getArray(); |
593 | | |
594 | 79 | for( const auto& rpStyle : maDesigns ) |
595 | 0 | *pNames++ = rpStyle->getName(); |
596 | | |
597 | 79 | return aRet; |
598 | 79 | } |
599 | | |
600 | | |
601 | | sal_Bool SAL_CALL TableDesignFamily::hasByName( const OUString& aName ) |
602 | 0 | { |
603 | 0 | SolarMutexGuard aGuard; |
604 | |
|
605 | 0 | return std::any_of(maDesigns.begin(), maDesigns.end(), |
606 | 0 | [&aName](const Reference<XStyle>& rpStyle) { return rpStyle->getName() == aName; }); |
607 | 0 | } |
608 | | |
609 | | |
610 | | // XElementAccess |
611 | | |
612 | | |
613 | | Type SAL_CALL TableDesignFamily::getElementType() |
614 | 0 | { |
615 | 0 | return cppu::UnoType<XStyle>::get(); |
616 | 0 | } |
617 | | |
618 | | |
619 | | sal_Bool SAL_CALL TableDesignFamily::hasElements() |
620 | 0 | { |
621 | 0 | SolarMutexGuard aGuard; |
622 | |
|
623 | 0 | return !maDesigns.empty(); |
624 | 0 | } |
625 | | |
626 | | |
627 | | // XIndexAccess |
628 | | |
629 | | |
630 | | sal_Int32 SAL_CALL TableDesignFamily::getCount() |
631 | 79 | { |
632 | 79 | SolarMutexGuard aGuard; |
633 | | |
634 | 79 | return sal::static_int_cast< sal_Int32 >( maDesigns.size() ); |
635 | 79 | } |
636 | | |
637 | | |
638 | | Any SAL_CALL TableDesignFamily::getByIndex( sal_Int32 Index ) |
639 | 0 | { |
640 | 0 | SolarMutexGuard aGuard; |
641 | |
|
642 | 0 | if( (Index >= 0) && (Index < sal::static_int_cast< sal_Int32 >( maDesigns.size() ) ) ) |
643 | 0 | return Any( maDesigns[Index] ); |
644 | | |
645 | 0 | throw IndexOutOfBoundsException(); |
646 | 0 | } |
647 | | |
648 | | |
649 | | // XNameContainer |
650 | | |
651 | | |
652 | | void SAL_CALL TableDesignFamily::insertByName( const OUString& rName, const Any& rElement ) |
653 | 0 | { |
654 | 0 | SolarMutexGuard aGuard; |
655 | |
|
656 | 0 | Reference< XStyle > xStyle( rElement, UNO_QUERY ); |
657 | 0 | if( !xStyle.is() ) |
658 | 0 | throw IllegalArgumentException(); |
659 | | |
660 | 0 | xStyle->setName( rName ); |
661 | 0 | if (std::any_of(maDesigns.begin(), maDesigns.end(), |
662 | 0 | [&rName](const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; })) |
663 | 0 | throw ElementExistException(); |
664 | | |
665 | 0 | maDesigns.push_back( xStyle ); |
666 | 0 | } |
667 | | |
668 | | |
669 | | void SAL_CALL TableDesignFamily::removeByName( const OUString& rName ) |
670 | 0 | { |
671 | 0 | SolarMutexGuard aGuard; |
672 | |
|
673 | 0 | auto iter = std::find_if(maDesigns.begin(), maDesigns.end(), |
674 | 0 | [&rName](const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; }); |
675 | 0 | if (iter != maDesigns.end()) |
676 | 0 | { |
677 | 0 | Reference<XComponent> xComponent(*iter, UNO_QUERY); |
678 | 0 | if (xComponent) |
679 | 0 | xComponent->dispose(); |
680 | 0 | maDesigns.erase( iter ); |
681 | 0 | return; |
682 | 0 | } |
683 | | |
684 | 0 | throw NoSuchElementException(); |
685 | 0 | } |
686 | | |
687 | | |
688 | | // XNameReplace |
689 | | |
690 | | |
691 | | void SAL_CALL TableDesignFamily::replaceByName( const OUString& rName, const Any& aElement ) |
692 | 0 | { |
693 | 0 | SolarMutexGuard aGuard; |
694 | |
|
695 | 0 | Reference< XStyle > xStyle( aElement, UNO_QUERY ); |
696 | 0 | if( !xStyle.is() ) |
697 | 0 | throw IllegalArgumentException(); |
698 | | |
699 | 0 | auto iter = std::find_if(maDesigns.begin(), maDesigns.end(), |
700 | 0 | [&rName](const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; }); |
701 | 0 | if (iter != maDesigns.end()) |
702 | 0 | { |
703 | 0 | if (!(*iter)->isUserDefined()) |
704 | 0 | static_cast<TableDesignStyle*>(xStyle.get())->resetUserDefined(); |
705 | |
|
706 | 0 | Reference<XComponent> xComponent(*iter, UNO_QUERY); |
707 | 0 | if (xComponent) |
708 | 0 | xComponent->dispose(); |
709 | 0 | (*iter) = xStyle; |
710 | 0 | xStyle->setName( rName ); |
711 | 0 | return; |
712 | 0 | } |
713 | | |
714 | 0 | throw NoSuchElementException(); |
715 | 0 | } |
716 | | |
717 | | |
718 | | // XSingleServiceFactory |
719 | | |
720 | | |
721 | | Reference< XInterface > SAL_CALL TableDesignFamily::createInstance() |
722 | 0 | { |
723 | 0 | return Reference< XInterface >( static_cast< XStyle* >( new TableDesignStyle ) ); |
724 | 0 | } |
725 | | |
726 | | |
727 | | Reference< XInterface > SAL_CALL TableDesignFamily::createInstanceWithArguments( const Sequence< Any >& ) |
728 | 0 | { |
729 | 0 | return createInstance(); |
730 | 0 | } |
731 | | |
732 | | |
733 | | // XComponent |
734 | | |
735 | | |
736 | | void SAL_CALL TableDesignFamily::dispose( ) |
737 | 14.5k | { |
738 | 14.5k | TableDesignStyleVector aDesigns; |
739 | 14.5k | aDesigns.swap( maDesigns ); |
740 | | |
741 | 14.5k | for( const auto& rStyle : aDesigns ) |
742 | 0 | { |
743 | 0 | Reference< XComponent > xComp( rStyle, UNO_QUERY ); |
744 | 0 | if( xComp.is() ) |
745 | 0 | xComp->dispose(); |
746 | 0 | } |
747 | 14.5k | } |
748 | | |
749 | | |
750 | | void SAL_CALL TableDesignFamily::addEventListener( const Reference< XEventListener >& ) |
751 | 0 | { |
752 | 0 | } |
753 | | |
754 | | |
755 | | void SAL_CALL TableDesignFamily::removeEventListener( const Reference< XEventListener >& ) |
756 | 0 | { |
757 | 0 | } |
758 | | |
759 | | |
760 | | // XPropertySet |
761 | | |
762 | | |
763 | | Reference<XPropertySetInfo> TableDesignFamily::getPropertySetInfo() |
764 | 0 | { |
765 | 0 | OSL_FAIL( "###unexpected!" ); |
766 | 0 | return Reference<XPropertySetInfo>(); |
767 | 0 | } |
768 | | |
769 | | |
770 | | void TableDesignFamily::setPropertyValue( const OUString& , const Any& ) |
771 | 0 | { |
772 | 0 | OSL_FAIL( "###unexpected!" ); |
773 | 0 | } |
774 | | |
775 | | |
776 | | Any TableDesignFamily::getPropertyValue( const OUString& PropertyName ) |
777 | 0 | { |
778 | 0 | if ( PropertyName != "DisplayName" ) |
779 | 0 | { |
780 | 0 | throw UnknownPropertyException( "unknown property: " + PropertyName, getXWeak() ); |
781 | 0 | } |
782 | | |
783 | 0 | OUString sDisplayName( SvxResId( RID_SVXSTR_STYLEFAMILY_TABLEDESIGN ) ); |
784 | 0 | return Any( sDisplayName ); |
785 | 0 | } |
786 | | |
787 | | |
788 | | void TableDesignFamily::addPropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>& ) |
789 | 0 | { |
790 | 0 | OSL_FAIL( "###unexpected!" ); |
791 | 0 | } |
792 | | |
793 | | |
794 | | void TableDesignFamily::removePropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>& ) |
795 | 0 | { |
796 | 0 | OSL_FAIL( "###unexpected!" ); |
797 | 0 | } |
798 | | |
799 | | |
800 | | void TableDesignFamily::addVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>& ) |
801 | 0 | { |
802 | 0 | OSL_FAIL( "###unexpected!" ); |
803 | 0 | } |
804 | | |
805 | | |
806 | | void TableDesignFamily::removeVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>& ) |
807 | 0 | { |
808 | 0 | OSL_FAIL( "###unexpected!" ); |
809 | 0 | } |
810 | | |
811 | | // XReset |
812 | | |
813 | | void TableDesignFamily::reset() |
814 | 0 | { |
815 | 0 | for (const auto& aDesign : maDesigns) |
816 | 0 | { |
817 | 0 | auto aStyle = static_cast<TableDesignStyle*>(aDesign.get()); |
818 | 0 | aStyle->resetUserDefined(); |
819 | 0 | aStyle->setModified(false); |
820 | 0 | } |
821 | 0 | } |
822 | | |
823 | | void TableDesignFamily::addResetListener( const Reference<form::XResetListener>& ) |
824 | 0 | { |
825 | 0 | } |
826 | | |
827 | | void TableDesignFamily::removeResetListener( const Reference<form::XResetListener>& ) |
828 | 0 | { |
829 | 0 | } |
830 | | |
831 | | Reference< XNameAccess > CreateTableDesignFamily() |
832 | 14.5k | { |
833 | 14.5k | return new TableDesignFamily; |
834 | 14.5k | } |
835 | | |
836 | | } |
837 | | |
838 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |