1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 31 #include "unogalitem.hxx" 32 #include "unogaltheme.hxx" 33 #include "svx/galtheme.hxx" 34 #include "svx/galmisc.hxx" 35 #include <svx/fmmodel.hxx> 36 #include <rtl/uuid.h> 37 #include <vos/mutex.hxx> 38 #include <vcl/svapp.hxx> 39 #include <vcl/graph.hxx> 40 #include <svl/itemprop.hxx> 41 #include <svl/itempool.hxx> 42 #include "galobj.hxx" 43 44 #ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HDL_ 45 #include <com/sun/star/beans/PropertyState.hpp> 46 #endif 47 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HDL_ 48 #include <com/sun/star/beans/PropertyAttribute.hpp> 49 #endif 50 #include <com/sun/star/gallery/GalleryItemType.hpp> 51 52 #define UNOGALLERY_GALLERYITEMTYPE 1 53 #define UNOGALLERY_URL 2 54 #define UNOGALLERY_TITLE 3 55 #define UNOGALLERY_THUMBNAIL 4 56 #define UNOGALLERY_GRAPHIC 5 57 #define UNOGALLERY_DRAWING 6 58 59 using namespace ::com::sun::star; 60 61 namespace unogallery { 62 63 // ----------------- 64 // - GalleryItem - 65 // ----------------- 66 67 GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) : 68 ::comphelper::PropertySetHelper( createPropertySetInfo() ), 69 mpTheme( &rTheme ), 70 mpGalleryObject( &rObject ) 71 { 72 mpTheme->implRegisterGalleryItem( *this ); 73 } 74 75 // ------------------------------------------------------------------------------ 76 77 GalleryItem::~GalleryItem() 78 throw() 79 { 80 if( mpTheme ) 81 mpTheme->implDeregisterGalleryItem( *this ); 82 } 83 84 // ------------------------------------------------------------------------------ 85 86 bool GalleryItem::isValid() const 87 { 88 return( mpTheme != NULL ); 89 } 90 91 // ------------------------------------------------------------------------------ 92 93 uno::Any SAL_CALL GalleryItem::queryAggregation( const uno::Type & rType ) 94 throw( uno::RuntimeException ) 95 { 96 uno::Any aAny; 97 98 if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) ) 99 aAny <<= uno::Reference< lang::XServiceInfo >(this); 100 else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) ) 101 aAny <<= uno::Reference< lang::XTypeProvider >(this); 102 else if( rType == ::getCppuType((const uno::Reference< gallery::XGalleryItem >*)0) ) 103 aAny <<= uno::Reference< gallery::XGalleryItem >(this); 104 else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) ) 105 aAny <<= uno::Reference< beans::XPropertySet >(this); 106 else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) ) 107 aAny <<= uno::Reference< beans::XPropertyState >(this); 108 else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) ) 109 aAny <<= uno::Reference< beans::XMultiPropertySet >(this); 110 else 111 aAny <<= OWeakAggObject::queryAggregation( rType ); 112 113 return aAny; 114 } 115 116 // ------------------------------------------------------------------------------ 117 118 uno::Any SAL_CALL GalleryItem::queryInterface( const uno::Type & rType ) 119 throw( uno::RuntimeException ) 120 { 121 return OWeakAggObject::queryInterface( rType ); 122 } 123 124 // ------------------------------------------------------------------------------ 125 126 void SAL_CALL GalleryItem::acquire() 127 throw() 128 { 129 OWeakAggObject::acquire(); 130 } 131 132 // ------------------------------------------------------------------------------ 133 134 void SAL_CALL GalleryItem::release() 135 throw() 136 { 137 OWeakAggObject::release(); 138 } 139 140 // ------------------------------------------------------------------------------ 141 142 ::rtl::OUString GalleryItem::getImplementationName_Static() 143 throw() 144 { 145 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryItem" ) ); 146 } 147 148 // ------------------------------------------------------------------------------ 149 150 uno::Sequence< ::rtl::OUString > GalleryItem::getSupportedServiceNames_Static() 151 throw() 152 { 153 uno::Sequence< ::rtl::OUString > aSeq( 1 ); 154 155 aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryItem" ) ); 156 157 return aSeq; 158 } 159 160 // ------------------------------------------------------------------------------ 161 162 ::rtl::OUString SAL_CALL GalleryItem::getImplementationName() 163 throw( uno::RuntimeException ) 164 { 165 return getImplementationName_Static(); 166 } 167 168 // ------------------------------------------------------------------------------ 169 170 sal_Bool SAL_CALL GalleryItem::supportsService( const ::rtl::OUString& ServiceName ) 171 throw( uno::RuntimeException ) 172 { 173 uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 174 const ::rtl::OUString* pArray = aSNL.getConstArray(); 175 176 for( int i = 0; i < aSNL.getLength(); i++ ) 177 if( pArray[i] == ServiceName ) 178 return true; 179 180 return false; 181 } 182 183 // ------------------------------------------------------------------------------ 184 185 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryItem::getSupportedServiceNames() 186 throw( uno::RuntimeException ) 187 { 188 return getSupportedServiceNames_Static(); 189 } 190 191 // ------------------------------------------------------------------------------ 192 193 uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes() 194 throw(uno::RuntimeException) 195 { 196 uno::Sequence< uno::Type > aTypes( 6 ); 197 uno::Type* pTypes = aTypes.getArray(); 198 199 *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0); 200 *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0); 201 *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryItem>*)0); 202 *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0); 203 *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0); 204 *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0); 205 206 return aTypes; 207 } 208 209 // ------------------------------------------------------------------------------ 210 211 uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId() 212 throw(uno::RuntimeException) 213 { 214 const vos::OGuard aGuard( Application::GetSolarMutex() ); 215 static uno::Sequence< sal_Int8 > aId; 216 217 if( aId.getLength() == 0 ) 218 { 219 aId.realloc( 16 ); 220 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True ); 221 } 222 223 return aId; 224 } 225 226 // ------------------------------------------------------------------------------ 227 228 sal_Int8 SAL_CALL GalleryItem::getType() 229 throw (uno::RuntimeException) 230 { 231 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 232 sal_Int8 nRet = gallery::GalleryItemType::EMPTY; 233 234 if( isValid() ) 235 { 236 switch( implGetObject()->eObjKind ) 237 { 238 case( SGA_OBJ_SOUND ): 239 case( SGA_OBJ_VIDEO ): 240 nRet = gallery::GalleryItemType::MEDIA; 241 break; 242 243 case( SGA_OBJ_SVDRAW ): 244 nRet = gallery::GalleryItemType::DRAWING; 245 break; 246 247 default: 248 nRet = gallery::GalleryItemType::GRAPHIC; 249 break; 250 } 251 } 252 253 return nRet; 254 } 255 256 // ------------------------------------------------------------------------------ 257 258 ::comphelper::PropertySetInfo* GalleryItem::createPropertySetInfo() 259 { 260 vos::OGuard aGuard( Application::GetSolarMutex() ); 261 ::comphelper::PropertySetInfo* pRet = new ::comphelper::PropertySetInfo(); 262 263 static ::comphelper::PropertyMapEntry aEntries[] = 264 { 265 { MAP_CHAR_LEN( "GalleryItemType" ), UNOGALLERY_GALLERYITEMTYPE, &::getCppuType( (const sal_Int8*)(0)), 266 beans::PropertyAttribute::READONLY, 0 }, 267 268 { MAP_CHAR_LEN( "URL" ), UNOGALLERY_URL, &::getCppuType( (const ::rtl::OUString*)(0)), 269 beans::PropertyAttribute::READONLY, 0 }, 270 271 { MAP_CHAR_LEN( "Title" ), UNOGALLERY_TITLE, &::getCppuType( (const ::rtl::OUString*)(0)), 272 0, 0 }, 273 274 { MAP_CHAR_LEN( "Thumbnail" ), UNOGALLERY_THUMBNAIL, &::getCppuType( (const uno::Reference< graphic::XGraphic >*)(0)), 275 beans::PropertyAttribute::READONLY, 0 }, 276 277 { MAP_CHAR_LEN( "Graphic" ), UNOGALLERY_GRAPHIC, &::getCppuType( (const uno::Reference< graphic::XGraphic >*)(0)), 278 beans::PropertyAttribute::READONLY, 0 }, 279 280 { MAP_CHAR_LEN( "Drawing" ), UNOGALLERY_DRAWING, &::getCppuType( (const uno::Reference< lang::XComponent >*)(0) ), 281 beans::PropertyAttribute::READONLY, 0 }, 282 283 { 0,0,0,0,0,0} 284 }; 285 286 pRet->acquire(); 287 pRet->add( aEntries ); 288 289 return pRet; 290 } 291 292 // ------------------------------------------------------------------------------ 293 294 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues ) 295 throw( beans::UnknownPropertyException, 296 beans::PropertyVetoException, 297 lang::IllegalArgumentException, 298 lang::WrappedTargetException ) 299 { 300 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 301 302 while( *ppEntries ) 303 { 304 if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle ) 305 { 306 ::rtl::OUString aNewTitle; 307 308 if( *pValues >>= aNewTitle ) 309 { 310 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL ); 311 312 if( pGalTheme ) 313 { 314 SgaObject* pObj = pGalTheme->ImplReadSgaObject( const_cast< GalleryObject* >( implGetObject() ) ); 315 316 if( pObj ) 317 { 318 if( ::rtl::OUString( pObj->GetTitle() ) != aNewTitle ) 319 { 320 pObj->SetTitle( aNewTitle ); 321 pGalTheme->InsertObject( *pObj ); 322 } 323 324 delete pObj; 325 } 326 } 327 } 328 else 329 { 330 throw lang::IllegalArgumentException(); 331 } 332 } 333 334 ++ppEntries; 335 ++pValues; 336 } 337 } 338 339 // ------------------------------------------------------------------------------ 340 341 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue ) 342 throw( beans::UnknownPropertyException, 343 lang::WrappedTargetException ) 344 { 345 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 346 347 while( *ppEntries ) 348 { 349 switch( (*ppEntries)->mnHandle ) 350 { 351 case( UNOGALLERY_GALLERYITEMTYPE ): 352 { 353 *pValue <<= sal_Int8( getType() ); 354 } 355 break; 356 357 case( UNOGALLERY_URL ): 358 { 359 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL ); 360 361 if( pGalTheme ) 362 *pValue <<= ::rtl::OUString( implGetObject()->aURL.GetMainURL( INetURLObject::NO_DECODE ) ); 363 } 364 break; 365 366 case( UNOGALLERY_TITLE ): 367 { 368 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL ); 369 370 if( pGalTheme ) 371 { 372 SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) ); 373 374 if( pObj ) 375 { 376 *pValue <<= ::rtl::OUString( pObj->GetTitle() ); 377 pGalTheme->ReleaseObject( pObj ); 378 } 379 } 380 } 381 break; 382 383 case( UNOGALLERY_THUMBNAIL ): 384 { 385 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL ); 386 387 if( pGalTheme ) 388 { 389 SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) ); 390 391 if( pObj ) 392 { 393 Graphic aThumbnail; 394 395 if( pObj->IsThumbBitmap() ) 396 aThumbnail = pObj->GetThumbBmp(); 397 else 398 aThumbnail = pObj->GetThumbMtf(); 399 400 *pValue <<= aThumbnail.GetXGraphic(); 401 pGalTheme->ReleaseObject( pObj ); 402 } 403 } 404 } 405 break; 406 407 case( UNOGALLERY_GRAPHIC ): 408 { 409 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL ); 410 Graphic aGraphic; 411 412 if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), aGraphic ) ) 413 *pValue <<= aGraphic.GetXGraphic(); 414 } 415 break; 416 417 case( UNOGALLERY_DRAWING ): 418 { 419 if( gallery::GalleryItemType::DRAWING == getType() ) 420 { 421 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL ); 422 FmFormModel* pModel = new FmFormModel; 423 424 pModel->GetItemPool().FreezeIdRanges(); 425 426 if( pGalTheme && pGalTheme->GetModel( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), *pModel ) ) 427 { 428 uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) ); 429 430 pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) ); 431 *pValue <<= xDrawing; 432 } 433 else 434 delete pModel; 435 } 436 } 437 break; 438 } 439 440 ++ppEntries; 441 ++pValue; 442 } 443 } 444 445 // ------------------------------------------------------------------------------ 446 447 const ::GalleryObject* GalleryItem::implGetObject() const 448 { 449 return mpGalleryObject; 450 } 451 452 // ------------------------------------------------------------------------------ 453 454 void GalleryItem::implSetInvalid() 455 { 456 if( mpTheme ) 457 { 458 mpTheme = NULL; 459 mpGalleryObject = NULL; 460 } 461 } 462 463 // ----------------------- 464 // - GalleryDrawingModel - 465 // ----------------------- 466 467 GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc ) 468 throw() : 469 SvxUnoDrawingModel( pDoc ) 470 { 471 } 472 473 // ----------------------------------------------------------------------------- 474 475 GalleryDrawingModel::~GalleryDrawingModel() 476 throw() 477 { 478 delete GetDoc(); 479 } 480 481 // ----------------------------------------------------------------------------- 482 483 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel ); 484 485 } 486