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