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 "unogalitem.hxx"
31 : : #include "unogaltheme.hxx"
32 : : #include "svx/galtheme.hxx"
33 : : #include "svx/galmisc.hxx"
34 : : #include <svx/fmmodel.hxx>
35 : : #include <osl/mutex.hxx>
36 : : #include <vcl/svapp.hxx>
37 : : #include <vcl/graph.hxx>
38 : : #include <svl/itemprop.hxx>
39 : : #include <svl/itempool.hxx>
40 : : #include <comphelper/servicehelper.hxx>
41 : : #include "galobj.hxx"
42 : :
43 : : #include <com/sun/star/beans/PropertyState.hpp>
44 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
45 : : #include <com/sun/star/gallery/GalleryItemType.hpp>
46 : :
47 : : #define UNOGALLERY_GALLERYITEMTYPE 1
48 : : #define UNOGALLERY_URL 2
49 : : #define UNOGALLERY_TITLE 3
50 : : #define UNOGALLERY_THUMBNAIL 4
51 : : #define UNOGALLERY_GRAPHIC 5
52 : : #define UNOGALLERY_DRAWING 6
53 : :
54 : : using namespace ::com::sun::star;
55 : :
56 : : namespace unogallery {
57 : :
58 : : // -----------------
59 : : // - GalleryItem -
60 : : // -----------------
61 : :
62 : 0 : GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) :
63 : : ::comphelper::PropertySetHelper( createPropertySetInfo() ),
64 : : mpTheme( &rTheme ),
65 [ # # ]: 0 : mpGalleryObject( &rObject )
66 : : {
67 [ # # ]: 0 : mpTheme->implRegisterGalleryItem( *this );
68 : 0 : }
69 : :
70 : : // ------------------------------------------------------------------------------
71 : :
72 : 0 : GalleryItem::~GalleryItem()
73 : 0 : throw()
74 : : {
75 [ # # ]: 0 : if( mpTheme )
76 [ # # ]: 0 : mpTheme->implDeregisterGalleryItem( *this );
77 [ # # ]: 0 : }
78 : :
79 : : // ------------------------------------------------------------------------------
80 : :
81 : 0 : bool GalleryItem::isValid() const
82 : : {
83 : 0 : return( mpTheme != NULL );
84 : : }
85 : :
86 : : // ------------------------------------------------------------------------------
87 : :
88 : 0 : uno::Any SAL_CALL GalleryItem::queryAggregation( const uno::Type & rType )
89 : : throw( uno::RuntimeException )
90 : : {
91 : 0 : uno::Any aAny;
92 : :
93 [ # # ][ # # ]: 0 : if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
94 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< lang::XServiceInfo >(this);
95 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
96 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< lang::XTypeProvider >(this);
97 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< gallery::XGalleryItem >*)0) )
98 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< gallery::XGalleryItem >(this);
99 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
100 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< beans::XPropertySet >(this);
101 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
102 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< beans::XPropertyState >(this);
103 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
104 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
105 : : else
106 [ # # ][ # # ]: 0 : aAny <<= OWeakAggObject::queryAggregation( rType );
107 : :
108 : 0 : return aAny;
109 : : }
110 : :
111 : : // ------------------------------------------------------------------------------
112 : :
113 : 0 : uno::Any SAL_CALL GalleryItem::queryInterface( const uno::Type & rType )
114 : : throw( uno::RuntimeException )
115 : : {
116 : 0 : return OWeakAggObject::queryInterface( rType );
117 : : }
118 : :
119 : : // ------------------------------------------------------------------------------
120 : :
121 : 0 : void SAL_CALL GalleryItem::acquire()
122 : : throw()
123 : : {
124 : 0 : OWeakAggObject::acquire();
125 : 0 : }
126 : :
127 : : // ------------------------------------------------------------------------------
128 : :
129 : 0 : void SAL_CALL GalleryItem::release()
130 : : throw()
131 : : {
132 : 0 : OWeakAggObject::release();
133 : 0 : }
134 : :
135 : : // ------------------------------------------------------------------------------
136 : :
137 : 0 : ::rtl::OUString GalleryItem::getImplementationName_Static()
138 : : throw()
139 : : {
140 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryItem" ) );
141 : : }
142 : :
143 : : // ------------------------------------------------------------------------------
144 : :
145 : 0 : uno::Sequence< ::rtl::OUString > GalleryItem::getSupportedServiceNames_Static()
146 : : throw()
147 : : {
148 : 0 : uno::Sequence< ::rtl::OUString > aSeq( 1 );
149 : :
150 [ # # ][ # # ]: 0 : aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryItem" ) );
151 : :
152 : 0 : return aSeq;
153 : : }
154 : :
155 : : // ------------------------------------------------------------------------------
156 : :
157 : 0 : ::rtl::OUString SAL_CALL GalleryItem::getImplementationName()
158 : : throw( uno::RuntimeException )
159 : : {
160 : 0 : return getImplementationName_Static();
161 : : }
162 : :
163 : : // ------------------------------------------------------------------------------
164 : :
165 : 0 : sal_Bool SAL_CALL GalleryItem::supportsService( const ::rtl::OUString& ServiceName )
166 : : throw( uno::RuntimeException )
167 : : {
168 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
169 : 0 : const ::rtl::OUString* pArray = aSNL.getConstArray();
170 : :
171 [ # # ]: 0 : for( int i = 0; i < aSNL.getLength(); i++ )
172 [ # # ]: 0 : if( pArray[i] == ServiceName )
173 : 0 : return true;
174 : :
175 [ # # ]: 0 : return false;
176 : : }
177 : :
178 : : // ------------------------------------------------------------------------------
179 : :
180 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL GalleryItem::getSupportedServiceNames()
181 : : throw( uno::RuntimeException )
182 : : {
183 : 0 : return getSupportedServiceNames_Static();
184 : : }
185 : :
186 : : // ------------------------------------------------------------------------------
187 : :
188 : 0 : uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes()
189 : : throw(uno::RuntimeException)
190 : : {
191 : 0 : uno::Sequence< uno::Type > aTypes( 6 );
192 [ # # ]: 0 : uno::Type* pTypes = aTypes.getArray();
193 : :
194 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
195 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
196 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryItem>*)0);
197 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
198 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
199 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
200 : :
201 : 0 : return aTypes;
202 : : }
203 : :
204 : : namespace
205 : : {
206 : : class theGalleryItemImplementationId : public rtl::Static< UnoTunnelIdInit, theGalleryItemImplementationId > {};
207 : : }
208 : :
209 : 0 : uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId()
210 : : throw(uno::RuntimeException)
211 : : {
212 : 0 : return theGalleryItemImplementationId::get().getSeq();
213 : : }
214 : :
215 : : // ------------------------------------------------------------------------------
216 : :
217 : 0 : sal_Int8 SAL_CALL GalleryItem::getType()
218 : : throw (uno::RuntimeException)
219 : : {
220 [ # # ]: 0 : const SolarMutexGuard aGuard;
221 : 0 : sal_Int8 nRet = gallery::GalleryItemType::EMPTY;
222 : :
223 [ # # ]: 0 : if( isValid() )
224 : : {
225 [ # # # ]: 0 : switch( implGetObject()->eObjKind )
226 : : {
227 : : case( SGA_OBJ_SOUND ):
228 : : case( SGA_OBJ_VIDEO ):
229 : 0 : nRet = gallery::GalleryItemType::MEDIA;
230 : 0 : break;
231 : :
232 : : case( SGA_OBJ_SVDRAW ):
233 : 0 : nRet = gallery::GalleryItemType::DRAWING;
234 : 0 : break;
235 : :
236 : : default:
237 : 0 : nRet = gallery::GalleryItemType::GRAPHIC;
238 : 0 : break;
239 : : }
240 : : }
241 : :
242 [ # # ]: 0 : return nRet;
243 : : }
244 : :
245 : : // ------------------------------------------------------------------------------
246 : :
247 : 0 : ::comphelper::PropertySetInfo* GalleryItem::createPropertySetInfo()
248 : : {
249 [ # # ]: 0 : SolarMutexGuard aGuard;
250 : 0 : ::comphelper::PropertySetInfo* pRet = new ::comphelper::PropertySetInfo();
251 : :
252 : : static ::comphelper::PropertyMapEntry aEntries[] =
253 : : {
254 [ # # ]: 0 : { MAP_CHAR_LEN( "GalleryItemType" ), UNOGALLERY_GALLERYITEMTYPE, &::getCppuType( (const sal_Int8*)(0)),
255 : : beans::PropertyAttribute::READONLY, 0 },
256 : :
257 [ # # ]: 0 : { MAP_CHAR_LEN( "URL" ), UNOGALLERY_URL, &::getCppuType( (const ::rtl::OUString*)(0)),
258 : : beans::PropertyAttribute::READONLY, 0 },
259 : :
260 [ # # ]: 0 : { MAP_CHAR_LEN( "Title" ), UNOGALLERY_TITLE, &::getCppuType( (const ::rtl::OUString*)(0)),
261 : : 0, 0 },
262 : :
263 [ # # ]: 0 : { MAP_CHAR_LEN( "Thumbnail" ), UNOGALLERY_THUMBNAIL, &::getCppuType( (const uno::Reference< graphic::XGraphic >*)(0)),
264 : : beans::PropertyAttribute::READONLY, 0 },
265 : :
266 [ # # ]: 0 : { MAP_CHAR_LEN( "Graphic" ), UNOGALLERY_GRAPHIC, &::getCppuType( (const uno::Reference< graphic::XGraphic >*)(0)),
267 : : beans::PropertyAttribute::READONLY, 0 },
268 : :
269 [ # # ]: 0 : { MAP_CHAR_LEN( "Drawing" ), UNOGALLERY_DRAWING, &::getCppuType( (const uno::Reference< lang::XComponent >*)(0) ),
270 : : beans::PropertyAttribute::READONLY, 0 },
271 : :
272 : : { 0,0,0,0,0,0}
273 [ # # ][ # # ]: 0 : };
[ # # ]
274 : :
275 : 0 : pRet->acquire();
276 : 0 : pRet->add( aEntries );
277 : :
278 [ # # ]: 0 : return pRet;
279 : : }
280 : :
281 : : // ------------------------------------------------------------------------------
282 : :
283 : 0 : void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
284 : : throw( beans::UnknownPropertyException,
285 : : beans::PropertyVetoException,
286 : : lang::IllegalArgumentException,
287 : : lang::WrappedTargetException )
288 : : {
289 [ # # ]: 0 : const SolarMutexGuard aGuard;
290 : :
291 [ # # ]: 0 : while( *ppEntries )
292 : : {
293 [ # # ]: 0 : if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
294 : : {
295 : 0 : ::rtl::OUString aNewTitle;
296 : :
297 [ # # ]: 0 : if( *pValues >>= aNewTitle )
298 : : {
299 [ # # ][ # # ]: 0 : ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
300 : :
301 [ # # ]: 0 : if( pGalTheme )
302 : : {
303 [ # # ]: 0 : SgaObject* pObj = pGalTheme->ImplReadSgaObject( const_cast< GalleryObject* >( implGetObject() ) );
304 : :
305 [ # # ]: 0 : if( pObj )
306 : : {
307 [ # # ][ # # ]: 0 : if( ::rtl::OUString( pObj->GetTitle() ) != aNewTitle )
[ # # ][ # # ]
308 : : {
309 [ # # ][ # # ]: 0 : pObj->SetTitle( aNewTitle );
[ # # ]
310 [ # # ]: 0 : pGalTheme->InsertObject( *pObj );
311 : : }
312 : :
313 [ # # ][ # # ]: 0 : delete pObj;
314 : : }
315 : : }
316 : : }
317 : : else
318 : : {
319 [ # # ]: 0 : throw lang::IllegalArgumentException();
320 : 0 : }
321 : : }
322 : :
323 : 0 : ++ppEntries;
324 : 0 : ++pValues;
325 [ # # ]: 0 : }
326 : 0 : }
327 : :
328 : : // ------------------------------------------------------------------------------
329 : :
330 : 0 : void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
331 : : throw( beans::UnknownPropertyException,
332 : : lang::WrappedTargetException )
333 : : {
334 [ # # ]: 0 : const SolarMutexGuard aGuard;
335 : :
336 [ # # ]: 0 : while( *ppEntries )
337 : : {
338 [ # # # # : 0 : switch( (*ppEntries)->mnHandle )
# # # ]
339 : : {
340 : : case( UNOGALLERY_GALLERYITEMTYPE ):
341 : : {
342 [ # # ][ # # ]: 0 : *pValue <<= sal_Int8( getType() );
343 : : }
344 : 0 : break;
345 : :
346 : : case( UNOGALLERY_URL ):
347 : : {
348 [ # # ][ # # ]: 0 : ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
349 : :
350 [ # # ]: 0 : if( pGalTheme )
351 [ # # ][ # # ]: 0 : *pValue <<= ::rtl::OUString( implGetObject()->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
352 : : }
353 : 0 : break;
354 : :
355 : : case( UNOGALLERY_TITLE ):
356 : : {
357 [ # # ][ # # ]: 0 : ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
358 : :
359 [ # # ]: 0 : if( pGalTheme )
360 : : {
361 [ # # ][ # # ]: 0 : SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
362 : :
363 [ # # ]: 0 : if( pObj )
364 : : {
365 [ # # ][ # # ]: 0 : *pValue <<= ::rtl::OUString( pObj->GetTitle() );
[ # # ][ # # ]
366 [ # # ]: 0 : pGalTheme->ReleaseObject( pObj );
367 : : }
368 : : }
369 : : }
370 : 0 : break;
371 : :
372 : : case( UNOGALLERY_THUMBNAIL ):
373 : : {
374 [ # # ][ # # ]: 0 : ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
375 : :
376 [ # # ]: 0 : if( pGalTheme )
377 : : {
378 [ # # ][ # # ]: 0 : SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
379 : :
380 [ # # ]: 0 : if( pObj )
381 : : {
382 [ # # ]: 0 : Graphic aThumbnail;
383 : :
384 [ # # ]: 0 : if( pObj->IsThumbBitmap() )
385 [ # # ][ # # ]: 0 : aThumbnail = pObj->GetThumbBmp();
[ # # ][ # # ]
[ # # ]
386 : : else
387 [ # # ][ # # ]: 0 : aThumbnail = pObj->GetThumbMtf();
[ # # ]
388 : :
389 [ # # ][ # # ]: 0 : *pValue <<= aThumbnail.GetXGraphic();
390 [ # # ][ # # ]: 0 : pGalTheme->ReleaseObject( pObj );
391 : : }
392 : : }
393 : : }
394 : 0 : break;
395 : :
396 : : case( UNOGALLERY_GRAPHIC ):
397 : : {
398 [ # # ][ # # ]: 0 : ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
399 [ # # ]: 0 : Graphic aGraphic;
400 : :
401 [ # # ][ # # ]: 0 : if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), aGraphic ) )
[ # # ][ # # ]
[ # # ]
402 [ # # ][ # # ]: 0 : *pValue <<= aGraphic.GetXGraphic();
[ # # ]
403 : : }
404 : 0 : break;
405 : :
406 : : case( UNOGALLERY_DRAWING ):
407 : : {
408 [ # # ][ # # ]: 0 : if( gallery::GalleryItemType::DRAWING == getType() )
409 : : {
410 [ # # ][ # # ]: 0 : ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
411 [ # # ][ # # ]: 0 : FmFormModel* pModel = new FmFormModel;
412 : :
413 [ # # ]: 0 : pModel->GetItemPool().FreezeIdRanges();
414 : :
415 [ # # ][ # # ]: 0 : if( pGalTheme && pGalTheme->GetModel( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), *pModel ) )
[ # # ][ # # ]
[ # # ]
416 : : {
417 [ # # ][ # # ]: 0 : uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
418 : :
419 [ # # ][ # # ]: 0 : pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
420 [ # # ]: 0 : *pValue <<= xDrawing;
421 : : }
422 : : else
423 [ # # ][ # # ]: 0 : delete pModel;
424 : : }
425 : : }
426 : 0 : break;
427 : : }
428 : :
429 : 0 : ++ppEntries;
430 : 0 : ++pValue;
431 [ # # ]: 0 : }
432 : 0 : }
433 : :
434 : : // ------------------------------------------------------------------------------
435 : :
436 : 0 : const ::GalleryObject* GalleryItem::implGetObject() const
437 : : {
438 : 0 : return mpGalleryObject;
439 : : }
440 : :
441 : : // ------------------------------------------------------------------------------
442 : :
443 : 0 : void GalleryItem::implSetInvalid()
444 : : {
445 [ # # ]: 0 : if( mpTheme )
446 : : {
447 : 0 : mpTheme = NULL;
448 : 0 : mpGalleryObject = NULL;
449 : : }
450 : 0 : }
451 : :
452 : : // -----------------------
453 : : // - GalleryDrawingModel -
454 : : // -----------------------
455 : :
456 : 0 : GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc )
457 : : throw() :
458 : 0 : SvxUnoDrawingModel( pDoc )
459 : : {
460 : 0 : }
461 : :
462 : : // -----------------------------------------------------------------------------
463 : :
464 : 0 : GalleryDrawingModel::~GalleryDrawingModel()
465 : 0 : throw()
466 : : {
467 [ # # ][ # # ]: 0 : delete GetDoc();
468 [ # # ]: 0 : }
469 : :
470 : : // -----------------------------------------------------------------------------
471 : :
472 [ # # ][ # # ]: 0 : UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
473 : :
474 : : }
475 : :
476 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|