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/gallery.hxx>
31 class theLockListener
: public rtl::Static
< SfxListener
, theLockListener
> {};
35 bool GalleryExplorer::FillThemeList( std::vector
<OUString
>& rThemeList
)
37 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
41 for( sal_uInt32 i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
; i
++ )
43 const GalleryThemeEntry
* pEntry
= pGal
->GetThemeInfo( i
);
45 if( pEntry
&& !pEntry
->IsReadOnly() && !pEntry
->IsHidden() )
46 rThemeList
.push_back(pEntry
->GetThemeName());
50 return !rThemeList
.empty();
53 bool GalleryExplorer::FillObjList( const OUString
& rThemeName
, std::vector
<OUString
> &rObjList
)
55 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
59 SfxListener aListener
;
60 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
64 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
65 rObjList
.push_back( pTheme
->GetObjectURL( i
).GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
67 pGal
->ReleaseTheme( pTheme
, aListener
);
71 return !rObjList
.empty();
74 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId
, std::vector
<OUString
> &rObjList
)
76 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
81 return FillObjList( pGal
->GetThemeName( nThemeId
), rObjList
);
84 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< OUString
>& rList
)
86 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
89 SfxListener aListener
;
90 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
94 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
96 std::unique_ptr
<SgaObject
> pObj
= pTheme
->AcquireObject( i
);
99 OUString
aTitle( pObj
->GetTitle() );
100 rList
.push_back( aTitle
);
103 pGal
->ReleaseTheme( pTheme
, aListener
);
106 return !rList
.empty();
109 bool GalleryExplorer::InsertURL( const OUString
& rThemeName
, const OUString
& rURL
)
111 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
116 SfxListener aListener
;
117 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
121 INetURLObject
aURL( rURL
);
122 DBG_ASSERT( aURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
123 bRet
= pTheme
->InsertURL( aURL
);
124 pGal
->ReleaseTheme( pTheme
, aListener
);
131 bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId
, const OUString
& rURL
)
133 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
134 return pGal
&& InsertURL( pGal
->GetThemeName( nThemeId
), rURL
);
137 bool GalleryExplorer::GetGraphicObj( const OUString
& rThemeName
, sal_uInt32 nPos
,
140 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
145 SfxListener aListener
;
146 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
151 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
);
153 pGal
->ReleaseTheme( pTheme
, aListener
);
160 bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId
, sal_uInt32 nPos
,
163 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
164 return pGal
&& GetGraphicObj( pGal
->GetThemeName( nThemeId
), nPos
, pGraphic
);
167 sal_uInt32
GalleryExplorer::GetSdrObjCount( const OUString
& rThemeName
)
169 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
174 SfxListener aListener
;
175 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
179 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
180 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
183 pGal
->ReleaseTheme( pTheme
, aListener
);
190 sal_uInt32
GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId
)
192 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
193 return( pGal
? GetSdrObjCount( pGal
->GetThemeName( nThemeId
) ) : 0 );
196 bool GalleryExplorer::GetSdrObj( const OUString
& rThemeName
, sal_uInt32 nSdrModelPos
,
197 SdrModel
* pModel
, BitmapEx
* pThumb
)
199 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
204 SfxListener aListener
;
205 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
209 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(), nActPos
= 0; ( i
< nCount
) && !bRet
; i
++ )
211 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
213 if( nActPos
++ == nSdrModelPos
)
216 bRet
= pTheme
->GetModel(i
, *pModel
);
219 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
224 pGal
->ReleaseTheme( pTheme
, aListener
);
231 bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId
, sal_uInt32 nSdrModelPos
,
232 SdrModel
* pModel
, BitmapEx
* pThumb
)
234 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
235 return pGal
&& GetSdrObj( pGal
->GetThemeName( nThemeId
), nSdrModelPos
, pModel
, pThumb
);
238 bool GalleryExplorer::BeginLocking( const OUString
& rThemeName
)
240 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
245 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, theLockListener::get() );
257 bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId
)
259 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
260 return pGal
&& BeginLocking( pGal
->GetThemeName( nThemeId
) );
263 bool GalleryExplorer::EndLocking( const OUString
& rThemeName
)
265 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
270 SfxListener aListener
;
271 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
275 const bool bReleaseLockedTheme
= pTheme
->UnlockTheme();
277 // release acquired theme
278 pGal
->ReleaseTheme( pTheme
, aListener
);
280 if( bReleaseLockedTheme
)
282 // release locked theme
283 pGal
->ReleaseTheme( pTheme
, theLockListener::get() );
292 bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId
)
294 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
295 return pGal
&& EndLocking( pGal
->GetThemeName( nThemeId
) );
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */