1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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() );
46 pGallery
= Gallery::GetGalleryInstance();
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
61 pThis
= new GalleryExplorer
;
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();
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();
120 SfxListener aListener
;
121 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
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();
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
))
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
);
163 // ------------------------------------------------------------------------
165 sal_Bool
GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< OUString
>& rList
)
167 Gallery
* pGal
= ImplGetGallery();
170 SfxListener aListener
;
171 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
175 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
177 SgaObject
* pObj
= pTheme
->AcquireObject( i
);
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
;
214 SfxListener aListener
;
215 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
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
);
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
,
243 Gallery
* pGal
= ImplGetGallery();
244 sal_Bool bRet
= sal_False
;
248 SfxListener aListener
;
249 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
254 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
, bProgress
);
257 bRet
= bRet
|| pTheme
->GetThumb( nPos
, *pThumb
, bProgress
);
259 pGal
->ReleaseTheme( pTheme
, aListener
);
266 // ------------------------------------------------------------------------
268 sal_Bool
GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId
, sal_uIntPtr nPos
,
269 Graphic
* pGraphic
, BitmapEx
* pThumb
,
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;
285 SfxListener aListener
;
286 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
290 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
291 if( SGA_OBJ_SVDRAW
== pTheme
->GetObjectKind( i
) )
294 pGal
->ReleaseTheme( pTheme
, aListener
);
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
;
319 SfxListener aListener
;
320 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
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
)
331 bRet
= bRet
|| pTheme
->GetModel( i
, *pModel
, sal_False
);
334 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
339 pGal
->ReleaseTheme( pTheme
, aListener
);
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
;
364 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, theLockListener::get() );
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
;
393 SfxListener aListener
;
394 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
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() );
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: */