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 <unotools/pathoptions.hxx> 28 #include <sfx2/viewfrm.hxx> 29 #include "svx/gallery1.hxx" 30 #include "svx/galtheme.hxx" 31 #include "svx/galbrws.hxx" 32 #include "svx/gallery.hxx" 33 #include "galobj.hxx" 34 35 // ----------- 36 // - Statics - 37 // ----------- 38 39 static SfxListener aLockListener; 40 41 // ------------------- 42 // - GalleryExplorer - 43 // ------------------- 44 45 Gallery* GalleryExplorer::ImplGetGallery() 46 { 47 static Gallery* pGallery = NULL; 48 49 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 50 51 if( !pGallery ) 52 pGallery = Gallery::GetGalleryInstance(); 53 54 return pGallery; 55 } 56 57 // ------------------------------------------------------------------------ 58 59 GalleryExplorer* GalleryExplorer::GetGallery() 60 { 61 static GalleryExplorer* pThis = NULL; 62 63 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 64 65 // only create a dummy object which can be accessed 66 if( !pThis ) 67 pThis = new GalleryExplorer; 68 69 return pThis; 70 } 71 72 // ------------------------------------------------------------------------ 73 74 INetURLObject GalleryExplorer::GetURL() const 75 { 76 return GALLERYBROWSER()->GetURL(); 77 } 78 79 String GalleryExplorer::GetFilterName() const 80 { 81 return GALLERYBROWSER()->GetFilterName(); 82 } 83 84 // ------------------------------------------------------------------------ 85 86 Graphic GalleryExplorer::GetGraphic() const 87 { 88 return GALLERYBROWSER()->GetGraphic(); 89 } 90 91 // ------------------------------------------------------------------------ 92 93 sal_Bool GalleryExplorer::GetVCDrawModel( FmFormModel& rModel ) const 94 { 95 return GALLERYBROWSER()->GetVCDrawModel( rModel ); 96 } 97 98 // ------------------------------------------------------------------------ 99 100 sal_Bool GalleryExplorer::IsLinkage() const 101 { 102 return GALLERYBROWSER()->IsLinkage(); 103 } 104 105 // ------------------------------------------------------------------------ 106 107 sal_Bool GalleryExplorer::FillThemeList( List& rThemeList ) 108 { 109 Gallery* pGal = ImplGetGallery(); 110 111 if( pGal ) 112 { 113 for( sal_uIntPtr i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ ) 114 { 115 const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i ); 116 117 if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() ) 118 rThemeList.Insert( new String( pEntry->GetThemeName() ), LIST_APPEND ); 119 } 120 } 121 122 return( rThemeList.Count() > 0 ); 123 } 124 125 // ------------------------------------------------------------------------ 126 127 sal_Bool GalleryExplorer::FillObjList( const String& rThemeName, List& rObjList ) 128 { 129 Gallery* pGal = ImplGetGallery(); 130 131 if( pGal ) 132 { 133 SfxListener aListener; 134 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 135 136 if( pTheme ) 137 { 138 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) 139 rObjList.Insert( new String( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::NO_DECODE ) ), LIST_APPEND ); 140 141 pGal->ReleaseTheme( pTheme, aListener ); 142 } 143 } 144 145 return( rObjList.Count() > 0 ); 146 } 147 148 // ------------------------------------------------------------------------ 149 150 sal_Bool GalleryExplorer::FillObjList( sal_uIntPtr nThemeId, List& rObjList ) 151 { 152 Gallery* pGal = ImplGetGallery(); 153 return( pGal ? FillObjList( pGal->GetThemeName( nThemeId ), rObjList ) : sal_False ); 154 } 155 156 // ------------------------------------------------------------------------ 157 158 sal_Bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< rtl::OUString >& rList ) 159 { 160 Gallery* pGal = ImplGetGallery(); 161 if( pGal ) 162 { 163 SfxListener aListener; 164 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener ); 165 166 if( pTheme ) 167 { 168 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) 169 { 170 SgaObject* pObj = pTheme->AcquireObject( i ); 171 if ( pObj ) 172 { 173 rtl::OUString aTitle( pObj->GetTitle() ); 174 rList.push_back( aTitle ); 175 pTheme->ReleaseObject( pObj ); 176 } 177 } 178 pGal->ReleaseTheme( pTheme, aListener ); 179 } 180 } 181 return( rList.size() > 0 ); 182 } 183 184 // ------------------------------------------------------------------------ 185 186 sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL ) 187 { 188 return InsertURL( rThemeName, rURL, SGA_FORMAT_ALL ); 189 } 190 191 // ------------------------------------------------------------------------ 192 193 sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL ) 194 { 195 return InsertURL( nThemeId, rURL, SGA_FORMAT_ALL ); 196 } 197 198 // ------------------------------------------------------------------------ 199 200 sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL, const sal_uIntPtr ) 201 { 202 Gallery* pGal = ImplGetGallery(); 203 sal_Bool bRet = sal_False; 204 205 if( pGal ) 206 { 207 SfxListener aListener; 208 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 209 210 if( pTheme ) 211 { 212 INetURLObject aURL( rURL ); 213 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 214 bRet = pTheme->InsertURL( aURL ); 215 pGal->ReleaseTheme( pTheme, aListener ); 216 } 217 } 218 219 return bRet; 220 } 221 222 // ------------------------------------------------------------------------ 223 224 sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL, const sal_uIntPtr nSgaFormat ) 225 { 226 Gallery* pGal = ImplGetGallery(); 227 return( pGal ? InsertURL( pGal->GetThemeName( nThemeId ), rURL, nSgaFormat ) : sal_False ); 228 } 229 230 // ------------------------------------------------------------------------ 231 232 sal_uIntPtr GalleryExplorer::GetObjCount( const String& rThemeName ) 233 { 234 Gallery* pGal = ImplGetGallery(); 235 sal_uIntPtr nRet = 0; 236 237 if( pGal ) 238 { 239 SfxListener aListener; 240 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 241 242 if( pTheme ) 243 { 244 nRet = pTheme->GetObjectCount(); 245 pGal->ReleaseTheme( pTheme, aListener ); 246 } 247 } 248 249 return nRet; 250 } 251 252 // ------------------------------------------------------------------------ 253 254 sal_uIntPtr GalleryExplorer::GetObjCount( sal_uIntPtr nThemeId ) 255 { 256 Gallery* pGal = ImplGetGallery(); 257 return( pGal ? GetObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False ); 258 } 259 260 // ------------------------------------------------------------------------ 261 262 sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos, 263 Graphic* pGraphic, Bitmap* pThumb, 264 sal_Bool bProgress ) 265 { 266 Gallery* pGal = ImplGetGallery(); 267 sal_Bool bRet = sal_False; 268 269 if( pGal ) 270 { 271 SfxListener aListener; 272 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 273 274 if( pTheme ) 275 { 276 if( pGraphic ) 277 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress ); 278 279 if( pThumb ) 280 bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress ); 281 282 pGal->ReleaseTheme( pTheme, aListener ); 283 } 284 } 285 286 return bRet; 287 } 288 289 // ------------------------------------------------------------------------ 290 291 sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos, 292 Graphic* pGraphic, Bitmap* pThumb, 293 sal_Bool bProgress ) 294 { 295 Gallery* pGal = ImplGetGallery(); 296 return( pGal ? GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress ) : sal_False ); 297 } 298 299 // ------------------------------------------------------------------------ 300 301 sal_Bool GalleryExplorer::InsertGraphicObj( const String& rThemeName, const Graphic& rGraphic ) 302 { 303 Gallery* pGal = ImplGetGallery(); 304 sal_Bool bRet = sal_False; 305 306 if( pGal ) 307 { 308 SfxListener aListener; 309 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 310 311 if( pTheme ) 312 { 313 bRet = pTheme->InsertGraphic( rGraphic ); 314 pGal->ReleaseTheme( pTheme, aListener ); 315 } 316 } 317 318 return bRet; 319 } 320 321 // ------------------------------------------------------------------------ 322 323 sal_Bool GalleryExplorer::InsertGraphicObj( sal_uIntPtr nThemeId, const Graphic& rGraphic ) 324 { 325 Gallery* pGal = ImplGetGallery(); 326 return( pGal ? InsertGraphicObj( pGal->GetThemeName( nThemeId ), rGraphic ) : sal_False ); 327 } 328 329 // ------------------------------------------------------------------------ 330 331 sal_uIntPtr GalleryExplorer::GetSdrObjCount( const String& rThemeName ) 332 { 333 Gallery* pGal = ImplGetGallery(); 334 sal_uIntPtr nRet = 0; 335 336 if( pGal ) 337 { 338 SfxListener aListener; 339 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 340 341 if( pTheme ) 342 { 343 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) 344 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) ) 345 nRet++; 346 347 pGal->ReleaseTheme( pTheme, aListener ); 348 } 349 } 350 351 return nRet; 352 } 353 354 // ------------------------------------------------------------------------ 355 356 sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId ) 357 { 358 Gallery* pGal = ImplGetGallery(); 359 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False ); 360 } 361 362 // ------------------------------------------------------------------------ 363 364 sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos, 365 SdrModel* pModel, Bitmap* pThumb ) 366 { 367 Gallery* pGal = ImplGetGallery(); 368 sal_Bool bRet = sal_False; 369 370 if( pGal ) 371 { 372 SfxListener aListener; 373 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 374 375 if( pTheme ) 376 { 377 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ ) 378 { 379 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) ) 380 { 381 if( nActPos++ == nSdrModelPos ) 382 { 383 if( pModel ) 384 bRet = bRet || pTheme->GetModel( i, *pModel, sal_False ); 385 386 if( pThumb ) 387 bRet = bRet || pTheme->GetThumb( i, *pThumb ); 388 } 389 } 390 } 391 392 pGal->ReleaseTheme( pTheme, aListener ); 393 } 394 } 395 396 return bRet; 397 } 398 399 // ------------------------------------------------------------------------ 400 401 sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos, 402 SdrModel* pModel, Bitmap* pThumb ) 403 { 404 Gallery* pGal = ImplGetGallery(); 405 return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False ); 406 } 407 408 // ------------------------------------------------------------------------ 409 410 sal_Bool GalleryExplorer::InsertSdrObj( const String& rThemeName, FmFormModel& rModel ) 411 { 412 Gallery* pGal = ImplGetGallery(); 413 sal_Bool bRet = sal_False; 414 415 if( pGal ) 416 { 417 SfxListener aListener; 418 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 419 420 if( pTheme ) 421 { 422 bRet = pTheme->InsertModel( rModel ); 423 pGal->ReleaseTheme( pTheme, aListener ); 424 } 425 } 426 427 return bRet; 428 } 429 430 // ------------------------------------------------------------------------ 431 432 sal_Bool GalleryExplorer::InsertSdrObj( sal_uIntPtr nThemeId, FmFormModel& rModel ) 433 { 434 Gallery* pGal = ImplGetGallery(); 435 return( pGal ? InsertSdrObj( pGal->GetThemeName( nThemeId ), rModel ) : sal_False ); 436 } 437 438 // ----------------------------------------------------------------------------- 439 440 sal_Bool GalleryExplorer::BeginLocking( const String& rThemeName ) 441 { 442 Gallery* pGal = ImplGetGallery(); 443 sal_Bool bRet = sal_False; 444 445 if( pGal ) 446 { 447 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aLockListener ); 448 449 if( pTheme ) 450 { 451 pTheme->LockTheme(); 452 bRet = sal_True; 453 } 454 } 455 456 return bRet; 457 } 458 459 // ----------------------------------------------------------------------------- 460 461 sal_Bool GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId ) 462 { 463 Gallery* pGal = ImplGetGallery(); 464 return( pGal ? BeginLocking( pGal->GetThemeName( nThemeId ) ) : sal_False ); 465 } 466 467 // ----------------------------------------------------------------------------- 468 469 sal_Bool GalleryExplorer::EndLocking( const String& rThemeName ) 470 { 471 Gallery* pGal = ImplGetGallery(); 472 sal_Bool bRet = sal_False; 473 474 if( pGal ) 475 { 476 SfxListener aListener; 477 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 478 479 if( pTheme ) 480 { 481 const sal_Bool bReleaseLockedTheme = pTheme->UnlockTheme(); 482 483 // release acquired theme 484 pGal->ReleaseTheme( pTheme, aListener ); 485 486 if( bReleaseLockedTheme ) 487 { 488 // release locked theme 489 pGal->ReleaseTheme( pTheme, aLockListener ); 490 bRet = sal_True; 491 } 492 } 493 } 494 495 return bRet; 496 } 497 498 // ----------------------------------------------------------------------------- 499 500 sal_Bool GalleryExplorer::EndLocking( sal_uIntPtr nThemeId ) 501 { 502 Gallery* pGal = ImplGetGallery(); 503 return( pGal ? EndLocking( pGal->GetThemeName( nThemeId ) ) : sal_False ); 504 } 505 506 // ----------------------------------------------------------------------------- 507 508 sal_Bool GalleryExplorer::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel ) 509 { 510 return SgaObjectSvDraw::DrawCentered( pOut, rModel ); 511 } 512