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 <svx/gallery1.hxx>
22 #include <svx/galtheme.hxx>
23 #include <svx/gallery.hxx>
28 SfxListener
& theLockListener()
30 static SfxListener SINGLETON
;
36 bool GalleryExplorer::FillThemeList( std::vector
<OUString
>& rThemeList
)
38 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
42 for( sal_uInt32 i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
; i
++ )
44 const GalleryThemeEntry
* pEntry
= pGal
->GetThemeInfo( i
);
46 if( pEntry
&& !pEntry
->IsReadOnly() && !pEntry
->IsHidden() )
47 rThemeList
.push_back(pEntry
->GetThemeName());
51 return !rThemeList
.empty();
54 bool GalleryExplorer::FillObjList( std::u16string_view rThemeName
, std::vector
<OUString
> &rObjList
)
56 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
60 SfxListener aListener
;
61 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
65 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
66 rObjList
.push_back( pTheme
->GetObjectURL( i
).GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
68 pGal
->ReleaseTheme( pTheme
, aListener
);
72 return !rObjList
.empty();
75 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId
, std::vector
<OUString
> &rObjList
)
77 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
82 return FillObjList( pGal
->GetThemeName( nThemeId
), rObjList
);
85 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< OUString
>& rList
)
87 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
90 SfxListener aListener
;
91 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
95 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
97 std::unique_ptr
<SgaObject
> pObj
= pTheme
->AcquireObject( i
);
100 OUString
aTitle( pObj
->GetTitle() );
101 rList
.push_back( aTitle
);
104 pGal
->ReleaseTheme( pTheme
, aListener
);
107 return !rList
.empty();
110 bool GalleryExplorer::InsertURL( std::u16string_view rThemeName
, std::u16string_view rURL
)
112 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
117 SfxListener aListener
;
118 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
122 INetURLObject
aURL( rURL
);
123 DBG_ASSERT( aURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
124 bRet
= pTheme
->InsertURL( aURL
);
125 pGal
->ReleaseTheme( pTheme
, aListener
);
132 bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId
, std::u16string_view rURL
)
134 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
135 return pGal
&& InsertURL( pGal
->GetThemeName( nThemeId
), rURL
);
138 bool GalleryExplorer::GetGraphicObj( std::u16string_view rThemeName
, sal_uInt32 nPos
,
141 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
146 SfxListener aListener
;
147 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
152 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
);
154 pGal
->ReleaseTheme( pTheme
, aListener
);
161 bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId
, sal_uInt32 nPos
,
164 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
165 return pGal
&& GetGraphicObj( pGal
->GetThemeName( nThemeId
), nPos
, pGraphic
);
168 sal_uInt32
GalleryExplorer::GetSdrObjCount( std::u16string_view rThemeName
)
170 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
175 SfxListener aListener
;
176 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
180 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
181 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
184 pGal
->ReleaseTheme( pTheme
, aListener
);
191 sal_uInt32
GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId
)
193 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
194 return( pGal
? GetSdrObjCount( pGal
->GetThemeName( nThemeId
) ) : 0 );
197 bool GalleryExplorer::GetSdrObj( std::u16string_view rThemeName
, sal_uInt32 nSdrModelPos
,
198 SdrModel
* pModel
, BitmapEx
* pThumb
)
200 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
205 SfxListener aListener
;
206 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
210 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(), nActPos
= 0; ( i
< nCount
) && !bRet
; i
++ )
212 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
214 if( nActPos
++ == nSdrModelPos
)
217 bRet
= pTheme
->GetModel(i
, *pModel
);
220 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
225 pGal
->ReleaseTheme( pTheme
, aListener
);
232 bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId
, sal_uInt32 nSdrModelPos
,
233 SdrModel
* pModel
, BitmapEx
* pThumb
)
235 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
236 return pGal
&& GetSdrObj( pGal
->GetThemeName( nThemeId
), nSdrModelPos
, pModel
, pThumb
);
239 bool GalleryExplorer::BeginLocking( std::u16string_view rThemeName
)
241 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
246 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, theLockListener() );
258 bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId
)
260 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
261 return pGal
&& BeginLocking( pGal
->GetThemeName( nThemeId
) );
264 bool GalleryExplorer::EndLocking( std::u16string_view rThemeName
)
266 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
271 SfxListener aListener
;
272 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
276 const bool bReleaseLockedTheme
= pTheme
->UnlockTheme();
278 // release acquired theme
279 pGal
->ReleaseTheme( pTheme
, aListener
);
281 if( bReleaseLockedTheme
)
283 // release locked theme
284 pGal
->ReleaseTheme( pTheme
, theLockListener() );
293 bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId
)
295 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
296 return pGal
&& EndLocking( pGal
->GetThemeName( nThemeId
) );
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */