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