Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <algorithm>
31 : :
32 : : #include "unogaltheme.hxx"
33 : : #include "unogalitem.hxx"
34 : : #include "svx/galtheme.hxx"
35 : : #include "svx/gallery1.hxx"
36 : : #include "svx/galmisc.hxx"
37 : : #include <svx/fmmodel.hxx>
38 : : #include <svx/svdpage.hxx>
39 : : #include <svx/unopage.hxx>
40 : : #include <svl/itempool.hxx>
41 : : #include <osl/mutex.hxx>
42 : : #include <vcl/svapp.hxx>
43 : : #include <unotools/pathoptions.hxx>
44 : : #include <comphelper/servicehelper.hxx>
45 : :
46 : : using namespace ::com::sun::star;
47 : :
48 : : namespace unogallery {
49 : :
50 : : // -----------------
51 : : // - GalleryTheme -
52 : : // -----------------
53 : :
54 [ # # ][ # # ]: 0 : GalleryTheme::GalleryTheme( const ::rtl::OUString& rThemeName )
55 : : {
56 [ # # ]: 0 : mpGallery = ::Gallery::GetGalleryInstance();
57 [ # # ][ # # ]: 0 : mpTheme = ( mpGallery ? mpGallery->AcquireTheme( rThemeName, *this ) : NULL );
[ # # ][ # # ]
[ # # ][ # # ]
58 : :
59 [ # # ]: 0 : if( mpGallery )
60 [ # # ]: 0 : StartListening( *mpGallery );
61 : 0 : }
62 : :
63 : : // ------------------------------------------------------------------------------
64 : :
65 [ # # ]: 0 : GalleryTheme::~GalleryTheme()
66 : : {
67 [ # # ]: 0 : const SolarMutexGuard aGuard;
68 : :
69 : : DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" );
70 : :
71 [ # # ]: 0 : implReleaseItems( NULL );
72 : :
73 [ # # ]: 0 : if( mpGallery )
74 : : {
75 [ # # ]: 0 : EndListening( *mpGallery );
76 : :
77 [ # # ]: 0 : if( mpTheme )
78 [ # # ]: 0 : mpGallery->ReleaseTheme( mpTheme, *this );
79 [ # # ]: 0 : }
80 [ # # ]: 0 : }
81 : :
82 : : // ------------------------------------------------------------------------------
83 : :
84 : 0 : ::rtl::OUString GalleryTheme::getImplementationName_Static()
85 : : throw()
86 : : {
87 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryTheme" ) );
88 : : }
89 : :
90 : : // ------------------------------------------------------------------------------
91 : :
92 : 0 : uno::Sequence< ::rtl::OUString > GalleryTheme::getSupportedServiceNames_Static()
93 : : throw()
94 : : {
95 : 0 : uno::Sequence< ::rtl::OUString > aSeq( 1 );
96 : :
97 [ # # ][ # # ]: 0 : aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryTheme" ) );
98 : :
99 : 0 : return aSeq;
100 : : }
101 : :
102 : : // ------------------------------------------------------------------------------
103 : :
104 : 0 : ::rtl::OUString SAL_CALL GalleryTheme::getImplementationName()
105 : : throw( uno::RuntimeException )
106 : : {
107 : 0 : return getImplementationName_Static();
108 : : }
109 : :
110 : : // ------------------------------------------------------------------------------
111 : :
112 : 0 : sal_Bool SAL_CALL GalleryTheme::supportsService( const ::rtl::OUString& ServiceName )
113 : : throw( uno::RuntimeException )
114 : : {
115 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
116 : 0 : const ::rtl::OUString* pArray = aSNL.getConstArray();
117 : :
118 [ # # ]: 0 : for( int i = 0; i < aSNL.getLength(); i++ )
119 [ # # ]: 0 : if( pArray[i] == ServiceName )
120 : 0 : return true;
121 : :
122 [ # # ]: 0 : return false;
123 : : }
124 : :
125 : : // ------------------------------------------------------------------------------
126 : :
127 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL GalleryTheme::getSupportedServiceNames()
128 : : throw( uno::RuntimeException )
129 : : {
130 : 0 : return getSupportedServiceNames_Static();
131 : : }
132 : :
133 : : // ------------------------------------------------------------------------------
134 : :
135 : 0 : uno::Sequence< uno::Type > SAL_CALL GalleryTheme::getTypes()
136 : : throw(uno::RuntimeException)
137 : : {
138 : 0 : uno::Sequence< uno::Type > aTypes( 5 );
139 [ # # ]: 0 : uno::Type* pTypes = aTypes.getArray();
140 : :
141 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
142 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
143 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< container::XElementAccess>*)0);
144 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< container::XIndexAccess>*)0);
145 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryTheme>*)0);
146 : :
147 : 0 : return aTypes;
148 : : }
149 : :
150 : : namespace
151 : : {
152 : : class theGalleryThemeImplementationId : public rtl::Static< UnoTunnelIdInit, theGalleryThemeImplementationId > {};
153 : : }
154 : :
155 : 0 : uno::Sequence< sal_Int8 > SAL_CALL GalleryTheme::getImplementationId()
156 : : throw(uno::RuntimeException)
157 : : {
158 : 0 : return theGalleryThemeImplementationId::get().getSeq();
159 : : }
160 : :
161 : : // ------------------------------------------------------------------------------
162 : :
163 : 0 : uno::Type SAL_CALL GalleryTheme::getElementType()
164 : : throw (uno::RuntimeException)
165 : : {
166 : 0 : return ::getCppuType( (const uno::Reference< gallery::XGalleryItem >*) 0);
167 : : }
168 : :
169 : : // ------------------------------------------------------------------------------
170 : :
171 : 0 : sal_Bool SAL_CALL GalleryTheme::hasElements()
172 : : throw (uno::RuntimeException)
173 : : {
174 [ # # ]: 0 : const SolarMutexGuard aGuard;
175 : :
176 [ # # ][ # # ]: 0 : return( ( mpTheme != NULL ) && ( mpTheme->GetObjectCount() > 0 ) );
[ # # ]
177 : : }
178 : :
179 : : // ------------------------------------------------------------------------------
180 : :
181 : 0 : sal_Int32 SAL_CALL GalleryTheme::getCount()
182 : : throw (uno::RuntimeException)
183 : : {
184 [ # # ]: 0 : const SolarMutexGuard aGuard;
185 : :
186 [ # # ][ # # ]: 0 : return( mpTheme ? mpTheme->GetObjectCount() : 0 );
187 : : }
188 : :
189 : : // ------------------------------------------------------------------------------
190 : :
191 : 0 : uno::Any SAL_CALL GalleryTheme::getByIndex( ::sal_Int32 nIndex )
192 : : throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
193 : : {
194 [ # # ]: 0 : const SolarMutexGuard aGuard;
195 : 0 : uno::Any aRet;
196 : :
197 [ # # ]: 0 : if( mpTheme )
198 : : {
199 [ # # ][ # # ]: 0 : if( ( nIndex < 0 ) || ( nIndex >= getCount() ) )
[ # # ][ # # ]
200 : : {
201 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
202 : : }
203 : : else
204 : : {
205 [ # # ]: 0 : const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( nIndex );
206 : :
207 [ # # ]: 0 : if( pObj )
208 [ # # ][ # # ]: 0 : aRet = uno::makeAny( uno::Reference< gallery::XGalleryItem >( new GalleryItem( *this, *pObj ) ) );
[ # # ][ # # ]
209 : : }
210 : : }
211 : :
212 [ # # ]: 0 : return aRet;
213 : : }
214 : :
215 : : // ------------------------------------------------------------------------------
216 : :
217 : 0 : ::rtl::OUString SAL_CALL GalleryTheme::getName( )
218 : : throw (uno::RuntimeException)
219 : : {
220 [ # # ]: 0 : const SolarMutexGuard aGuard;
221 : 0 : ::rtl::OUString aRet;
222 : :
223 [ # # ]: 0 : if( mpTheme )
224 [ # # ]: 0 : aRet = mpTheme->GetName();
225 : :
226 [ # # ]: 0 : return aRet;
227 : : }
228 : :
229 : : // ------------------------------------------------------------------------------
230 : :
231 : 0 : void SAL_CALL GalleryTheme::update( )
232 : : throw (uno::RuntimeException)
233 : : {
234 [ # # ]: 0 : const SolarMutexGuard aGuard;
235 : :
236 [ # # ]: 0 : if( mpTheme )
237 : : {
238 [ # # ]: 0 : const Link aDummyLink;
239 [ # # ]: 0 : mpTheme->Actualize( aDummyLink );
240 [ # # ]: 0 : }
241 : 0 : }
242 : :
243 : : // ------------------------------------------------------------------------------
244 : :
245 : 0 : ::sal_Int32 SAL_CALL GalleryTheme::insertURLByIndex(
246 : : const ::rtl::OUString& rURL, ::sal_Int32 nIndex )
247 : : throw (lang::WrappedTargetException, uno::RuntimeException)
248 : : {
249 [ # # ]: 0 : const SolarMutexGuard aGuard;
250 : 0 : sal_Int32 nRet = -1;
251 : :
252 [ # # ]: 0 : if( mpTheme )
253 : : {
254 : : try
255 : : {
256 [ # # ]: 0 : const INetURLObject aURL( rURL );
257 : :
258 [ # # ][ # # ]: 0 : nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
[ # # ]
259 : :
260 [ # # ][ # # ]: 0 : if( ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) && mpTheme->InsertURL( aURL, nIndex ) )
[ # # ][ # # ]
261 : : {
262 [ # # ]: 0 : const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( aURL );
263 : :
264 [ # # ]: 0 : if( pObj )
265 [ # # ]: 0 : nRet = mpTheme->ImplGetGalleryObjectPos( pObj );
266 [ # # ]: 0 : }
267 : : }
268 [ # # ]: 0 : catch( ... )
269 : : {
270 : : }
271 : : }
272 : :
273 [ # # ]: 0 : return nRet;
274 : : }
275 : :
276 : : // ------------------------------------------------------------------------------
277 : :
278 : 0 : ::sal_Int32 SAL_CALL GalleryTheme::insertGraphicByIndex(
279 : : const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nIndex )
280 : : throw (lang::WrappedTargetException, uno::RuntimeException)
281 : : {
282 [ # # ]: 0 : const SolarMutexGuard aGuard;
283 : 0 : sal_Int32 nRet = -1;
284 : :
285 [ # # ]: 0 : if( mpTheme )
286 : : {
287 : : try
288 : : {
289 [ # # ]: 0 : const Graphic aGraphic( rxGraphic );
290 : :
291 [ # # ][ # # ]: 0 : nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
[ # # ]
292 : :
293 [ # # ][ # # ]: 0 : if( mpTheme->InsertGraphic( aGraphic, nIndex ) )
294 [ # # ]: 0 : nRet = nIndex;
295 : : }
296 [ # # ]: 0 : catch( ... )
297 : : {
298 : : }
299 : : }
300 : :
301 [ # # ]: 0 : return nRet;
302 : : }
303 : :
304 : : // ------------------------------------------------------------------------------
305 : :
306 : 0 : ::sal_Int32 SAL_CALL GalleryTheme::insertDrawingByIndex(
307 : : const uno::Reference< lang::XComponent >& Drawing, sal_Int32 nIndex )
308 : : throw (lang::WrappedTargetException, uno::RuntimeException)
309 : : {
310 [ # # ]: 0 : const SolarMutexGuard aGuard;
311 : 0 : sal_Int32 nRet = -1;
312 : :
313 [ # # ]: 0 : if( mpTheme )
314 : : {
315 [ # # ]: 0 : GalleryDrawingModel* pModel = GalleryDrawingModel::getImplementation( Drawing );
316 : :
317 [ # # ][ # # ]: 0 : if( pModel && pModel->GetDoc() && pModel->GetDoc()->ISA( FmFormModel ) )
[ # # ][ # # ]
[ # # ][ # # ]
318 : : {
319 : : //Here we're inserting something that's already a gallery theme drawing
320 : :
321 [ # # ][ # # ]: 0 : nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
[ # # ]
322 : :
323 [ # # ][ # # ]: 0 : if( mpTheme->InsertModel( *static_cast< FmFormModel* >( pModel->GetDoc() ), nIndex ) )
324 : 0 : nRet = nIndex;
325 : : }
326 [ # # ]: 0 : else if (!pModel)
327 : : {
328 : : //#i80184# Try to do the right thing and make a Gallery drawing out of an ordinary
329 : : //Drawing if possible.
330 : : try
331 : : {
332 [ # # ]: 0 : uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier( Drawing, uno::UNO_QUERY_THROW );
333 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
[ # # ]
334 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
[ # # ]
335 [ # # ][ # # ]: 0 : SvxDrawPage* pUnoPage = xPage.is() ? SvxDrawPage::getImplementation( xPage ) : NULL;
336 [ # # ][ # # ]: 0 : SdrModel* pOrigModel = pUnoPage ? pUnoPage->GetSdrPage()->GetModel() : NULL;
337 [ # # ]: 0 : SdrPage* pOrigPage = pUnoPage ? pUnoPage->GetSdrPage() : NULL;
338 : :
339 [ # # ][ # # ]: 0 : if (pOrigPage && pOrigModel)
340 : : {
341 [ # # ][ # # ]: 0 : FmFormModel* pTmpModel = new FmFormModel(&pOrigModel->GetItemPool());
342 [ # # ]: 0 : SdrPage* pNewPage = pOrigPage->Clone();
343 [ # # ]: 0 : pTmpModel->InsertPage(pNewPage, 0);
344 : :
345 [ # # ][ # # ]: 0 : uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pTmpModel ) );
346 [ # # ][ # # ]: 0 : pTmpModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
347 : :
348 [ # # ]: 0 : nRet = insertDrawingByIndex( xDrawing, nIndex );
349 : 0 : return nRet;
350 [ # # ][ # # ]: 0 : }
[ # # ]
351 : : }
352 [ # # ]: 0 : catch (...)
353 : : {
354 : : }
355 : : }
356 : : }
357 : :
358 [ # # ]: 0 : return nRet;
359 : : }
360 : :
361 : : // ------------------------------------------------------------------------------
362 : :
363 : 0 : void SAL_CALL GalleryTheme::removeByIndex( sal_Int32 nIndex )
364 : : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
365 : : {
366 [ # # ]: 0 : const SolarMutexGuard aGuard;
367 : :
368 [ # # ]: 0 : if( mpTheme )
369 : : {
370 [ # # ][ # # ]: 0 : if( ( nIndex < 0 ) || ( nIndex >= getCount() ) )
[ # # ][ # # ]
371 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
372 : : else
373 [ # # ]: 0 : mpTheme->RemoveObject( nIndex );
374 [ # # ]: 0 : }
375 : 0 : }
376 : :
377 : : // ------------------------------------------------------------------------------
378 : :
379 : 0 : void GalleryTheme::Notify( SfxBroadcaster&, const SfxHint& rHint )
380 : : {
381 [ # # ]: 0 : const SolarMutexGuard aGuard;
382 : 0 : const GalleryHint& rGalleryHint = static_cast< const GalleryHint& >( rHint );
383 : :
384 [ # # # ]: 0 : switch( rGalleryHint.GetType() )
385 : : {
386 : : case( GALLERY_HINT_CLOSE_THEME ):
387 : : {
388 : : DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" );
389 : :
390 [ # # ]: 0 : implReleaseItems( NULL );
391 : :
392 [ # # ][ # # ]: 0 : if( mpGallery && mpTheme )
393 : : {
394 [ # # ]: 0 : mpGallery->ReleaseTheme( mpTheme, *this );
395 : 0 : mpTheme = NULL;
396 : : }
397 : : }
398 : 0 : break;
399 : :
400 : : case( GALLERY_HINT_CLOSE_OBJECT ):
401 : : {
402 : 0 : GalleryObject* pObj = reinterpret_cast< GalleryObject* >( rGalleryHint.GetData1() );
403 : :
404 [ # # ]: 0 : if( pObj )
405 [ # # ]: 0 : implReleaseItems( pObj );
406 : : }
407 : 0 : break;
408 : :
409 : : default:
410 : 0 : break;
411 [ # # ]: 0 : }
412 : 0 : }
413 : :
414 : : // ------------------------------------------------------------------------------
415 : :
416 : 0 : void GalleryTheme::implReleaseItems( GalleryObject* pObj )
417 : : {
418 [ # # ]: 0 : const SolarMutexGuard aGuard;
419 : :
420 [ # # ]: 0 : for( GalleryItemList::iterator aIter = maItemList.begin(); aIter != maItemList.end(); )
421 : : {
422 [ # # ][ # # ]: 0 : if( !pObj || ( (*aIter)->implGetObject() == pObj ) )
[ # # ][ # # ]
423 : : {
424 [ # # ]: 0 : (*aIter)->implSetInvalid();
425 [ # # ]: 0 : aIter = maItemList.erase( aIter );
426 : : }
427 : : else
428 : 0 : ++aIter;
429 [ # # ]: 0 : }
430 : 0 : }
431 : :
432 : : // ------------------------------------------------------------------------------
433 : :
434 : 0 : ::GalleryTheme* GalleryTheme::implGetTheme() const
435 : : {
436 : 0 : return mpTheme;
437 : : }
438 : :
439 : : // ------------------------------------------------------------------------------
440 : :
441 : 0 : void GalleryTheme::implRegisterGalleryItem( ::unogallery::GalleryItem& rItem )
442 : : {
443 [ # # ]: 0 : const SolarMutexGuard aGuard;
444 : :
445 : : // DBG_ASSERT( maItemList.find( &rItem ) == maItemList.end(), "Item already registered" );
446 [ # # ][ # # ]: 0 : maItemList.push_back( &rItem );
447 : 0 : }
448 : :
449 : : // ------------------------------------------------------------------------------
450 : :
451 : 0 : void GalleryTheme::implDeregisterGalleryItem( ::unogallery::GalleryItem& rItem )
452 : : {
453 [ # # ]: 0 : const SolarMutexGuard aGuard;
454 : :
455 : : // DBG_ASSERT( maItemList.find( &rItem ) != maItemList.end(), "Item is not registered" );
456 [ # # ][ # # ]: 0 : maItemList.remove( &rItem );
457 : 0 : }
458 : :
459 : : }
460 : :
461 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|