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 sal_Bool GalleryExplorer::FillThemeList( List& rThemeList ) 46 { 47 Gallery* pGal = ::Gallery::GetGalleryInstance(); 48 49 if( pGal ) 50 { 51 for( sal_uIntPtr i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ ) 52 { 53 const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i ); 54 55 if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() ) 56 rThemeList.Insert( new String( pEntry->GetThemeName() ), LIST_APPEND ); 57 } 58 } 59 60 return( rThemeList.Count() > 0 ); 61 } 62 63 // ------------------------------------------------------------------------ 64 65 sal_Bool GalleryExplorer::FillObjList( const String& rThemeName, List& rObjList ) 66 { 67 Gallery* pGal = ::Gallery::GetGalleryInstance(); 68 69 if( pGal ) 70 { 71 SfxListener aListener; 72 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 73 74 if( pTheme ) 75 { 76 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) 77 rObjList.Insert( new String( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::NO_DECODE ) ), LIST_APPEND ); 78 79 pGal->ReleaseTheme( pTheme, aListener ); 80 } 81 } 82 83 return( rObjList.Count() > 0 ); 84 } 85 86 // ------------------------------------------------------------------------ 87 88 sal_Bool GalleryExplorer::FillObjList( sal_uIntPtr nThemeId, List& rObjList ) 89 { 90 Gallery* pGal = ::Gallery::GetGalleryInstance(); 91 return( pGal ? FillObjList( pGal->GetThemeName( nThemeId ), rObjList ) : sal_False ); 92 } 93 94 // ------------------------------------------------------------------------ 95 96 sal_Bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< rtl::OUString >& rList ) 97 { 98 Gallery* pGal = ::Gallery::GetGalleryInstance(); 99 if( pGal ) 100 { 101 SfxListener aListener; 102 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener ); 103 104 if( pTheme ) 105 { 106 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) 107 { 108 SgaObject* pObj = pTheme->AcquireObject( i ); 109 if ( pObj ) 110 { 111 rtl::OUString aTitle( pObj->GetTitle() ); 112 rList.push_back( aTitle ); 113 pTheme->ReleaseObject( pObj ); 114 } 115 } 116 pGal->ReleaseTheme( pTheme, aListener ); 117 } 118 } 119 return( rList.size() > 0 ); 120 } 121 122 // ------------------------------------------------------------------------ 123 124 sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL ) 125 { 126 Gallery* pGal = ::Gallery::GetGalleryInstance(); 127 sal_Bool bRet = sal_False; 128 129 if( pGal ) 130 { 131 SfxListener aListener; 132 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 133 134 if( pTheme ) 135 { 136 INetURLObject aURL( rURL ); 137 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 138 bRet = pTheme->InsertURL( aURL ); 139 pGal->ReleaseTheme( pTheme, aListener ); 140 } 141 } 142 143 return bRet; 144 } 145 146 // ------------------------------------------------------------------------ 147 148 sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL ) 149 { 150 Gallery* pGal = ::Gallery::GetGalleryInstance(); 151 return( pGal ? InsertURL( pGal->GetThemeName( nThemeId ), rURL ) : sal_False ); 152 } 153 154 // ------------------------------------------------------------------------ 155 156 sal_uIntPtr GalleryExplorer::GetObjCount( const String& rThemeName ) 157 { 158 Gallery* pGal = ::Gallery::GetGalleryInstance(); 159 sal_uIntPtr nRet = 0; 160 161 if( pGal ) 162 { 163 SfxListener aListener; 164 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 165 166 if( pTheme ) 167 { 168 nRet = pTheme->GetObjectCount(); 169 pGal->ReleaseTheme( pTheme, aListener ); 170 } 171 } 172 173 return nRet; 174 } 175 176 // ------------------------------------------------------------------------ 177 178 sal_uIntPtr GalleryExplorer::GetObjCount( sal_uIntPtr nThemeId ) 179 { 180 Gallery* pGal = ::Gallery::GetGalleryInstance(); 181 return( pGal ? GetObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False ); 182 } 183 184 // ------------------------------------------------------------------------ 185 186 sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos, 187 Graphic* pGraphic, BitmapEx* pThumb, 188 sal_Bool bProgress ) 189 { 190 Gallery* pGal = ::Gallery::GetGalleryInstance(); 191 sal_Bool bRet = sal_False; 192 193 if( pGal ) 194 { 195 SfxListener aListener; 196 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 197 198 if( pTheme ) 199 { 200 if( pGraphic ) 201 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress ); 202 203 if( pThumb ) 204 bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress ); 205 206 pGal->ReleaseTheme( pTheme, aListener ); 207 } 208 } 209 210 return bRet; 211 } 212 213 // ------------------------------------------------------------------------ 214 215 sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos, 216 Graphic* pGraphic, BitmapEx* pThumb, 217 sal_Bool bProgress ) 218 { 219 Gallery* pGal = ::Gallery::GetGalleryInstance(); 220 return( pGal ? GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress ) : sal_False ); 221 } 222 223 // ------------------------------------------------------------------------ 224 225 sal_Bool GalleryExplorer::InsertGraphicObj( const String& rThemeName, const Graphic& rGraphic ) 226 { 227 Gallery* pGal = ::Gallery::GetGalleryInstance(); 228 sal_Bool bRet = sal_False; 229 230 if( pGal ) 231 { 232 SfxListener aListener; 233 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 234 235 if( pTheme ) 236 { 237 bRet = pTheme->InsertGraphic( rGraphic ); 238 pGal->ReleaseTheme( pTheme, aListener ); 239 } 240 } 241 242 return bRet; 243 } 244 245 // ------------------------------------------------------------------------ 246 247 sal_Bool GalleryExplorer::InsertGraphicObj( sal_uIntPtr nThemeId, const Graphic& rGraphic ) 248 { 249 Gallery* pGal = ::Gallery::GetGalleryInstance(); 250 return( pGal ? InsertGraphicObj( pGal->GetThemeName( nThemeId ), rGraphic ) : sal_False ); 251 } 252 253 // ------------------------------------------------------------------------ 254 255 sal_uIntPtr GalleryExplorer::GetSdrObjCount( const String& rThemeName ) 256 { 257 Gallery* pGal = ::Gallery::GetGalleryInstance(); 258 sal_uIntPtr nRet = 0; 259 260 if( pGal ) 261 { 262 SfxListener aListener; 263 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 264 265 if( pTheme ) 266 { 267 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) 268 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) ) 269 nRet++; 270 271 pGal->ReleaseTheme( pTheme, aListener ); 272 } 273 } 274 275 return nRet; 276 } 277 278 // ------------------------------------------------------------------------ 279 280 sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId ) 281 { 282 Gallery* pGal = ::Gallery::GetGalleryInstance(); 283 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False ); 284 } 285 286 // ------------------------------------------------------------------------ 287 288 sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos, 289 SdrModel* pModel, BitmapEx* pThumb ) 290 { 291 Gallery* pGal = ::Gallery::GetGalleryInstance(); 292 sal_Bool bRet = sal_False; 293 294 if( pGal ) 295 { 296 SfxListener aListener; 297 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 298 299 if( pTheme ) 300 { 301 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ ) 302 { 303 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) ) 304 { 305 if( nActPos++ == nSdrModelPos ) 306 { 307 if( pModel ) 308 bRet = bRet || pTheme->GetModel( i, *pModel, sal_False ); 309 310 if( pThumb ) 311 bRet = bRet || pTheme->GetThumb( i, *pThumb ); 312 } 313 } 314 } 315 316 pGal->ReleaseTheme( pTheme, aListener ); 317 } 318 } 319 320 return bRet; 321 } 322 323 // ------------------------------------------------------------------------ 324 325 sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos, 326 SdrModel* pModel, BitmapEx* pThumb ) 327 { 328 Gallery* pGal = ::Gallery::GetGalleryInstance(); 329 return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False ); 330 } 331 332 // ------------------------------------------------------------------------ 333 334 sal_Bool GalleryExplorer::InsertSdrObj( const String& rThemeName, FmFormModel& rModel ) 335 { 336 Gallery* pGal = ::Gallery::GetGalleryInstance(); 337 sal_Bool bRet = sal_False; 338 339 if( pGal ) 340 { 341 SfxListener aListener; 342 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 343 344 if( pTheme ) 345 { 346 bRet = pTheme->InsertModel( rModel ); 347 pGal->ReleaseTheme( pTheme, aListener ); 348 } 349 } 350 351 return bRet; 352 } 353 354 // ------------------------------------------------------------------------ 355 356 sal_Bool GalleryExplorer::InsertSdrObj( sal_uIntPtr nThemeId, FmFormModel& rModel ) 357 { 358 Gallery* pGal = ::Gallery::GetGalleryInstance(); 359 return( pGal ? InsertSdrObj( pGal->GetThemeName( nThemeId ), rModel ) : sal_False ); 360 } 361 362 // ----------------------------------------------------------------------------- 363 364 sal_Bool GalleryExplorer::BeginLocking( const String& rThemeName ) 365 { 366 Gallery* pGal = ::Gallery::GetGalleryInstance(); 367 sal_Bool bRet = sal_False; 368 369 if( pGal ) 370 { 371 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aLockListener ); 372 373 if( pTheme ) 374 { 375 pTheme->LockTheme(); 376 bRet = sal_True; 377 } 378 } 379 380 return bRet; 381 } 382 383 // ----------------------------------------------------------------------------- 384 385 sal_Bool GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId ) 386 { 387 Gallery* pGal = ::Gallery::GetGalleryInstance(); 388 return( pGal ? BeginLocking( pGal->GetThemeName( nThemeId ) ) : sal_False ); 389 } 390 391 // ----------------------------------------------------------------------------- 392 393 sal_Bool GalleryExplorer::EndLocking( const String& rThemeName ) 394 { 395 Gallery* pGal = ::Gallery::GetGalleryInstance(); 396 sal_Bool bRet = sal_False; 397 398 if( pGal ) 399 { 400 SfxListener aListener; 401 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); 402 403 if( pTheme ) 404 { 405 const sal_Bool bReleaseLockedTheme = pTheme->UnlockTheme(); 406 407 // release acquired theme 408 pGal->ReleaseTheme( pTheme, aListener ); 409 410 if( bReleaseLockedTheme ) 411 { 412 // release locked theme 413 pGal->ReleaseTheme( pTheme, aLockListener ); 414 bRet = sal_True; 415 } 416 } 417 } 418 419 return bRet; 420 } 421 422 // ----------------------------------------------------------------------------- 423 424 sal_Bool GalleryExplorer::EndLocking( sal_uIntPtr nThemeId ) 425 { 426 Gallery* pGal = ::Gallery::GetGalleryInstance(); 427 return( pGal ? EndLocking( pGal->GetThemeName( nThemeId ) ) : sal_False ); 428 } 429 430 // ----------------------------------------------------------------------------- 431 // eof 432