fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / gallery2 / galexpl.cxx
blob13899ad21197def8e26e653be62a36be4caf6e68
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <unotools/pathoptions.hxx>
22 #include <rtl/instance.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include "svx/gallery1.hxx"
25 #include "svx/galtheme.hxx"
26 #include "svx/galbrws.hxx"
27 #include "svx/gallery.hxx"
28 #include "galobj.hxx"
30 namespace
32 class theLockListener : public rtl::Static< SfxListener, theLockListener > {};
35 // -------------------
36 // - GalleryExplorer -
37 // -------------------
39 Gallery* GalleryExplorer::ImplGetGallery()
41 static Gallery* pGallery = NULL;
43 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
45 if( !pGallery )
46 pGallery = Gallery::GetGalleryInstance();
48 return pGallery;
51 // ------------------------------------------------------------------------
53 GalleryExplorer* GalleryExplorer::GetGallery()
55 static GalleryExplorer* pThis = NULL;
57 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
59 // only create a dummy object which can be accessed
60 if( !pThis )
61 pThis = new GalleryExplorer;
63 return pThis;
66 // ------------------------------------------------------------------------
68 INetURLObject GalleryExplorer::GetURL() const
70 return GALLERYBROWSER()->GetURL();
73 String GalleryExplorer::GetFilterName() const
75 return GALLERYBROWSER()->GetFilterName();
78 // ------------------------------------------------------------------------
80 Graphic GalleryExplorer::GetGraphic() const
82 return GALLERYBROWSER()->GetGraphic();
85 // ------------------------------------------------------------------------
87 sal_Bool GalleryExplorer::IsLinkage() const
89 return GALLERYBROWSER()->IsLinkage();
92 // ------------------------------------------------------------------------
94 bool GalleryExplorer::FillThemeList( std::vector<String>& rThemeList )
96 Gallery* pGal = ImplGetGallery();
98 if( pGal )
100 for( sal_uIntPtr i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
102 const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
104 if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
105 rThemeList.push_back(pEntry->GetThemeName());
109 return !rThemeList.empty();
112 // ------------------------------------------------------------------------
114 sal_Bool GalleryExplorer::FillObjList( const String& rThemeName, std::vector<String> &rObjList )
116 Gallery* pGal = ImplGetGallery();
118 if( pGal )
120 SfxListener aListener;
121 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
123 if( pTheme )
125 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
126 rObjList.push_back( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::NO_DECODE ) );
128 pGal->ReleaseTheme( pTheme, aListener );
132 return !rObjList.empty();
135 // ------------------------------------------------------------------------
137 sal_Bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<String> &rObjList )
139 Gallery* pGal = ImplGetGallery();
141 if (!pGal)
142 return false;
144 return FillObjList( pGal->GetThemeName( nThemeId ), rObjList );
147 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<OUString> &rObjList )
149 std::vector<String> aObjList;
150 if (!FillObjList(nThemeId, aObjList))
151 return false;
153 std::vector<OUString> aList;
154 aList.reserve(aObjList.size());
155 std::vector<String>::const_iterator it = aObjList.begin(), itEnd = aObjList.end();
156 for (; it != itEnd; ++it)
157 aList.push_back(*it);
159 rObjList.swap(aList);
160 return true;
163 // ------------------------------------------------------------------------
165 sal_Bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< OUString >& rList )
167 Gallery* pGal = ImplGetGallery();
168 if( pGal )
170 SfxListener aListener;
171 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
173 if( pTheme )
175 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
177 SgaObject* pObj = pTheme->AcquireObject( i );
178 if ( pObj )
180 OUString aTitle( pObj->GetTitle() );
181 rList.push_back( aTitle );
182 pTheme->ReleaseObject( pObj );
185 pGal->ReleaseTheme( pTheme, aListener );
188 return !rList.empty();
191 // ------------------------------------------------------------------------
193 sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL )
195 return InsertURL( rThemeName, rURL, SGA_FORMAT_ALL );
198 // ------------------------------------------------------------------------
200 sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL )
202 return InsertURL( nThemeId, rURL, SGA_FORMAT_ALL );
205 // ------------------------------------------------------------------------
207 sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL, const sal_uIntPtr )
209 Gallery* pGal = ImplGetGallery();
210 sal_Bool bRet = sal_False;
212 if( pGal )
214 SfxListener aListener;
215 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
217 if( pTheme )
219 INetURLObject aURL( rURL );
220 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
221 bRet = pTheme->InsertURL( aURL );
222 pGal->ReleaseTheme( pTheme, aListener );
226 return bRet;
229 // ------------------------------------------------------------------------
231 sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL, const sal_uIntPtr nSgaFormat )
233 Gallery* pGal = ImplGetGallery();
234 return( pGal ? InsertURL( pGal->GetThemeName( nThemeId ), rURL, nSgaFormat ) : sal_False );
237 // ------------------------------------------------------------------------
239 sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos,
240 Graphic* pGraphic, BitmapEx* pThumb,
241 sal_Bool bProgress )
243 Gallery* pGal = ImplGetGallery();
244 sal_Bool bRet = sal_False;
246 if( pGal )
248 SfxListener aListener;
249 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
251 if( pTheme )
253 if( pGraphic )
254 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress );
256 if( pThumb )
257 bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress );
259 pGal->ReleaseTheme( pTheme, aListener );
263 return bRet;
266 // ------------------------------------------------------------------------
268 sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos,
269 Graphic* pGraphic, BitmapEx* pThumb,
270 sal_Bool bProgress )
272 Gallery* pGal = ImplGetGallery();
273 return( pGal ? GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress ) : sal_False );
276 // ------------------------------------------------------------------------
278 sal_uIntPtr GalleryExplorer::GetSdrObjCount( const String& rThemeName )
280 Gallery* pGal = ImplGetGallery();
281 sal_uIntPtr nRet = 0;
283 if( pGal )
285 SfxListener aListener;
286 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
288 if( pTheme )
290 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
291 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
292 nRet++;
294 pGal->ReleaseTheme( pTheme, aListener );
298 return nRet;
301 // ------------------------------------------------------------------------
303 sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId )
305 Gallery* pGal = ImplGetGallery();
306 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False );
309 // ------------------------------------------------------------------------
311 sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos,
312 SdrModel* pModel, BitmapEx* pThumb )
314 Gallery* pGal = ImplGetGallery();
315 sal_Bool bRet = sal_False;
317 if( pGal )
319 SfxListener aListener;
320 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
322 if( pTheme )
324 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
326 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
328 if( nActPos++ == nSdrModelPos )
330 if( pModel )
331 bRet = bRet || pTheme->GetModel( i, *pModel, sal_False );
333 if( pThumb )
334 bRet = bRet || pTheme->GetThumb( i, *pThumb );
339 pGal->ReleaseTheme( pTheme, aListener );
343 return bRet;
346 // ------------------------------------------------------------------------
348 sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos,
349 SdrModel* pModel, BitmapEx* pThumb )
351 Gallery* pGal = ImplGetGallery();
352 return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False );
355 // -----------------------------------------------------------------------------
357 sal_Bool GalleryExplorer::BeginLocking( const String& rThemeName )
359 Gallery* pGal = ImplGetGallery();
360 sal_Bool bRet = sal_False;
362 if( pGal )
364 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener::get() );
366 if( pTheme )
368 pTheme->LockTheme();
369 bRet = sal_True;
373 return bRet;
376 // -----------------------------------------------------------------------------
378 sal_Bool GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId )
380 Gallery* pGal = ImplGetGallery();
381 return( pGal ? BeginLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
384 // -----------------------------------------------------------------------------
386 sal_Bool GalleryExplorer::EndLocking( const String& rThemeName )
388 Gallery* pGal = ImplGetGallery();
389 sal_Bool bRet = sal_False;
391 if( pGal )
393 SfxListener aListener;
394 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
396 if( pTheme )
398 const sal_Bool bReleaseLockedTheme = pTheme->UnlockTheme();
400 // release acquired theme
401 pGal->ReleaseTheme( pTheme, aListener );
403 if( bReleaseLockedTheme )
405 // release locked theme
406 pGal->ReleaseTheme( pTheme, theLockListener::get() );
407 bRet = sal_True;
412 return bRet;
415 // -----------------------------------------------------------------------------
417 sal_Bool GalleryExplorer::EndLocking( sal_uIntPtr nThemeId )
419 Gallery* pGal = ImplGetGallery();
420 return( pGal ? EndLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
423 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */