merge the formfield patch from ooo-build
[ooovba.git] / svx / source / gallery2 / galexpl.cxx
blob4facb96b8a5c8f64be535a1527ce9f239d815652
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: galexpl.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svtools/pathoptions.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include "gallery1.hxx"
37 #include "galtheme.hxx"
38 #include "galbrws.hxx"
39 #include "gallery.hxx"
41 // -----------
42 // - Statics -
43 // -----------
45 static SfxListener aLockListener;
47 // -------------------
48 // - GalleryExplorer -
49 // -------------------
51 Gallery* GalleryExplorer::ImplGetGallery()
53 static Gallery* pGallery = NULL;
55 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
57 if( !pGallery )
58 pGallery = Gallery::GetGalleryInstance();
60 return pGallery;
63 // ------------------------------------------------------------------------
65 GalleryExplorer* GalleryExplorer::GetGallery()
67 static GalleryExplorer* pThis = NULL;
69 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
71 // only create a dummy object which can be accessed
72 if( !pThis )
73 pThis = new GalleryExplorer;
75 return pThis;
78 // ------------------------------------------------------------------------
80 INetURLObject GalleryExplorer::GetURL() const
82 return GALLERYBROWSER()->GetURL();
85 String GalleryExplorer::GetFilterName() const
87 return GALLERYBROWSER()->GetFilterName();
90 // ------------------------------------------------------------------------
92 Graphic GalleryExplorer::GetGraphic() const
94 return GALLERYBROWSER()->GetGraphic();
97 // ------------------------------------------------------------------------
99 BOOL GalleryExplorer::GetVCDrawModel( FmFormModel& rModel ) const
101 return GALLERYBROWSER()->GetVCDrawModel( rModel );
104 // ------------------------------------------------------------------------
106 BOOL GalleryExplorer::IsLinkage() const
108 return GALLERYBROWSER()->IsLinkage();
111 // ------------------------------------------------------------------------
113 BOOL GalleryExplorer::FillThemeList( List& rThemeList )
115 Gallery* pGal = ImplGetGallery();
117 if( pGal )
119 for( ULONG i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
121 const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
123 if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
124 rThemeList.Insert( new String( pEntry->GetThemeName() ), LIST_APPEND );
128 return( rThemeList.Count() > 0 );
131 // ------------------------------------------------------------------------
133 BOOL GalleryExplorer::FillObjList( const String& rThemeName, List& rObjList )
135 Gallery* pGal = ImplGetGallery();
137 if( pGal )
139 SfxListener aListener;
140 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
142 if( pTheme )
144 for( ULONG i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
145 rObjList.Insert( new String( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::NO_DECODE ) ), LIST_APPEND );
147 pGal->ReleaseTheme( pTheme, aListener );
151 return( rObjList.Count() > 0 );
154 // ------------------------------------------------------------------------
156 BOOL GalleryExplorer::FillObjList( ULONG nThemeId, List& rObjList )
158 Gallery* pGal = ImplGetGallery();
159 return( pGal ? FillObjList( pGal->GetThemeName( nThemeId ), rObjList ) : FALSE );
162 // ------------------------------------------------------------------------
164 sal_Bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< rtl::OUString >& rList )
166 Gallery* pGal = ImplGetGallery();
167 if( pGal )
169 SfxListener aListener;
170 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
172 if( pTheme )
174 for( ULONG i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
176 SgaObject* pObj = pTheme->AcquireObject( i );
177 if ( pObj )
179 rtl::OUString aTitle( pObj->GetTitle() );
180 rList.push_back( aTitle );
181 pTheme->ReleaseObject( pObj );
184 pGal->ReleaseTheme( pTheme, aListener );
187 return( rList.size() > 0 );
190 // ------------------------------------------------------------------------
192 BOOL GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL )
194 return InsertURL( rThemeName, rURL, SGA_FORMAT_ALL );
197 // ------------------------------------------------------------------------
199 BOOL GalleryExplorer::InsertURL( ULONG nThemeId, const String& rURL )
201 return InsertURL( nThemeId, rURL, SGA_FORMAT_ALL );
204 // ------------------------------------------------------------------------
206 BOOL GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL, const ULONG )
208 Gallery* pGal = ImplGetGallery();
209 BOOL bRet = FALSE;
211 if( pGal )
213 SfxListener aListener;
214 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
216 if( pTheme )
218 INetURLObject aURL( rURL );
219 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
220 bRet = pTheme->InsertURL( aURL );
221 pGal->ReleaseTheme( pTheme, aListener );
225 return bRet;
228 // ------------------------------------------------------------------------
230 BOOL GalleryExplorer::InsertURL( ULONG nThemeId, const String& rURL, const ULONG nSgaFormat )
232 Gallery* pGal = ImplGetGallery();
233 return( pGal ? InsertURL( pGal->GetThemeName( nThemeId ), rURL, nSgaFormat ) : FALSE );
236 // ------------------------------------------------------------------------
238 ULONG GalleryExplorer::GetObjCount( const String& rThemeName )
240 Gallery* pGal = ImplGetGallery();
241 ULONG nRet = 0;
243 if( pGal )
245 SfxListener aListener;
246 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
248 if( pTheme )
250 nRet = pTheme->GetObjectCount();
251 pGal->ReleaseTheme( pTheme, aListener );
255 return nRet;
258 // ------------------------------------------------------------------------
260 ULONG GalleryExplorer::GetObjCount( ULONG nThemeId )
262 Gallery* pGal = ImplGetGallery();
263 return( pGal ? GetObjCount( pGal->GetThemeName( nThemeId ) ) : FALSE );
266 // ------------------------------------------------------------------------
268 BOOL GalleryExplorer::GetGraphicObj( const String& rThemeName, ULONG nPos,
269 Graphic* pGraphic, Bitmap* pThumb,
270 BOOL bProgress )
272 Gallery* pGal = ImplGetGallery();
273 BOOL bRet = FALSE;
275 if( pGal )
277 SfxListener aListener;
278 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
280 if( pTheme )
282 if( pGraphic )
283 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress );
285 if( pThumb )
286 bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress );
288 pGal->ReleaseTheme( pTheme, aListener );
292 return bRet;
295 // ------------------------------------------------------------------------
297 BOOL GalleryExplorer::GetGraphicObj( ULONG nThemeId, ULONG nPos,
298 Graphic* pGraphic, Bitmap* pThumb,
299 BOOL bProgress )
301 Gallery* pGal = ImplGetGallery();
302 return( pGal ? GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress ) : FALSE );
305 // ------------------------------------------------------------------------
307 BOOL GalleryExplorer::InsertGraphicObj( const String& rThemeName, const Graphic& rGraphic )
309 Gallery* pGal = ImplGetGallery();
310 BOOL bRet = FALSE;
312 if( pGal )
314 SfxListener aListener;
315 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
317 if( pTheme )
319 bRet = pTheme->InsertGraphic( rGraphic );
320 pGal->ReleaseTheme( pTheme, aListener );
324 return bRet;
327 // ------------------------------------------------------------------------
329 BOOL GalleryExplorer::InsertGraphicObj( ULONG nThemeId, const Graphic& rGraphic )
331 Gallery* pGal = ImplGetGallery();
332 return( pGal ? InsertGraphicObj( pGal->GetThemeName( nThemeId ), rGraphic ) : FALSE );
335 // ------------------------------------------------------------------------
337 ULONG GalleryExplorer::GetSdrObjCount( const String& rThemeName )
339 Gallery* pGal = ImplGetGallery();
340 ULONG nRet = 0;
342 if( pGal )
344 SfxListener aListener;
345 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
347 if( pTheme )
349 for( ULONG i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
350 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
351 nRet++;
353 pGal->ReleaseTheme( pTheme, aListener );
357 return nRet;
360 // ------------------------------------------------------------------------
362 ULONG GalleryExplorer::GetSdrObjCount( ULONG nThemeId )
364 Gallery* pGal = ImplGetGallery();
365 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : FALSE );
368 // ------------------------------------------------------------------------
370 BOOL GalleryExplorer::GetSdrObj( const String& rThemeName, ULONG nSdrModelPos,
371 SdrModel* pModel, Bitmap* pThumb )
373 Gallery* pGal = ImplGetGallery();
374 BOOL bRet = FALSE;
376 if( pGal )
378 SfxListener aListener;
379 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
381 if( pTheme )
383 for( ULONG i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
385 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
387 if( nActPos++ == nSdrModelPos )
389 if( pModel )
390 bRet = bRet || pTheme->GetModel( i, *pModel, FALSE );
392 if( pThumb )
393 bRet = bRet || pTheme->GetThumb( i, *pThumb );
398 pGal->ReleaseTheme( pTheme, aListener );
402 return bRet;
405 // ------------------------------------------------------------------------
407 BOOL GalleryExplorer::GetSdrObj( ULONG nThemeId, ULONG nSdrModelPos,
408 SdrModel* pModel, Bitmap* pThumb )
410 Gallery* pGal = ImplGetGallery();
411 return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : FALSE );
414 // ------------------------------------------------------------------------
416 BOOL GalleryExplorer::InsertSdrObj( const String& rThemeName, FmFormModel& rModel )
418 Gallery* pGal = ImplGetGallery();
419 BOOL bRet = FALSE;
421 if( pGal )
423 SfxListener aListener;
424 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
426 if( pTheme )
428 bRet = pTheme->InsertModel( rModel );
429 pGal->ReleaseTheme( pTheme, aListener );
433 return bRet;
436 // ------------------------------------------------------------------------
438 BOOL GalleryExplorer::InsertSdrObj( ULONG nThemeId, FmFormModel& rModel )
440 Gallery* pGal = ImplGetGallery();
441 return( pGal ? InsertSdrObj( pGal->GetThemeName( nThemeId ), rModel ) : FALSE );
444 // -----------------------------------------------------------------------------
446 BOOL GalleryExplorer::BeginLocking( const String& rThemeName )
448 Gallery* pGal = ImplGetGallery();
449 BOOL bRet = FALSE;
451 if( pGal )
453 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aLockListener );
455 if( pTheme )
457 pTheme->LockTheme();
458 bRet = TRUE;
462 return bRet;
465 // -----------------------------------------------------------------------------
467 BOOL GalleryExplorer::BeginLocking( ULONG nThemeId )
469 Gallery* pGal = ImplGetGallery();
470 return( pGal ? BeginLocking( pGal->GetThemeName( nThemeId ) ) : FALSE );
473 // -----------------------------------------------------------------------------
475 BOOL GalleryExplorer::EndLocking( const String& rThemeName )
477 Gallery* pGal = ImplGetGallery();
478 BOOL bRet = FALSE;
480 if( pGal )
482 SfxListener aListener;
483 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
485 if( pTheme )
487 const BOOL bReleaseLockedTheme = pTheme->UnlockTheme();
489 // release acquired theme
490 pGal->ReleaseTheme( pTheme, aListener );
492 if( bReleaseLockedTheme )
494 // release locked theme
495 pGal->ReleaseTheme( pTheme, aLockListener );
496 bRet = TRUE;
501 return bRet;
504 // -----------------------------------------------------------------------------
506 BOOL GalleryExplorer::EndLocking( ULONG nThemeId )
508 Gallery* pGal = ImplGetGallery();
509 return( pGal ? EndLocking( pGal->GetThemeName( nThemeId ) ) : FALSE );
512 // -----------------------------------------------------------------------------
514 BOOL GalleryExplorer::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel )
516 return SgaObjectSvDraw::DrawCentered( pOut, rModel );