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 <rtl/instance.hxx>
22 #include <svx/gallery1.hxx>
23 #include <svx/galtheme.hxx>
24 #include <svx/gallery.hxx>
29 class theLockListener
: public rtl::Static
< SfxListener
, theLockListener
> {};
33 bool GalleryExplorer::FillThemeList( std::vector
<OUString
>& rThemeList
)
35 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
39 for( sal_uInt32 i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
; i
++ )
41 const GalleryThemeEntry
* pEntry
= pGal
->GetThemeInfo( i
);
43 if( pEntry
&& !pEntry
->IsReadOnly() && !pEntry
->IsHidden() )
44 rThemeList
.push_back(pEntry
->GetThemeName());
48 return !rThemeList
.empty();
51 bool GalleryExplorer::FillObjList( std::u16string_view rThemeName
, std::vector
<OUString
> &rObjList
)
53 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
57 SfxListener aListener
;
58 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
62 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
63 rObjList
.push_back( pTheme
->GetObjectURL( i
).GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
65 pGal
->ReleaseTheme( pTheme
, aListener
);
69 return !rObjList
.empty();
72 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId
, std::vector
<OUString
> &rObjList
)
74 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
79 return FillObjList( pGal
->GetThemeName( nThemeId
), rObjList
);
82 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< OUString
>& rList
)
84 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
87 SfxListener aListener
;
88 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
92 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
94 std::unique_ptr
<SgaObject
> pObj
= pTheme
->AcquireObject( i
);
97 OUString
aTitle( pObj
->GetTitle() );
98 rList
.push_back( aTitle
);
101 pGal
->ReleaseTheme( pTheme
, aListener
);
104 return !rList
.empty();
107 bool GalleryExplorer::InsertURL( std::u16string_view rThemeName
, const OUString
& rURL
)
109 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
114 SfxListener aListener
;
115 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
119 INetURLObject
aURL( rURL
);
120 DBG_ASSERT( aURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
121 bRet
= pTheme
->InsertURL( aURL
);
122 pGal
->ReleaseTheme( pTheme
, aListener
);
129 bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId
, const OUString
& rURL
)
131 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
132 return pGal
&& InsertURL( pGal
->GetThemeName( nThemeId
), rURL
);
135 bool GalleryExplorer::GetGraphicObj( std::u16string_view rThemeName
, sal_uInt32 nPos
,
138 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
143 SfxListener aListener
;
144 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
149 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
);
151 pGal
->ReleaseTheme( pTheme
, aListener
);
158 bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId
, sal_uInt32 nPos
,
161 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
162 return pGal
&& GetGraphicObj( pGal
->GetThemeName( nThemeId
), nPos
, pGraphic
);
165 sal_uInt32
GalleryExplorer::GetSdrObjCount( std::u16string_view rThemeName
)
167 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
172 SfxListener aListener
;
173 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
177 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
178 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
181 pGal
->ReleaseTheme( pTheme
, aListener
);
188 sal_uInt32
GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId
)
190 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
191 return( pGal
? GetSdrObjCount( pGal
->GetThemeName( nThemeId
) ) : 0 );
194 bool GalleryExplorer::GetSdrObj( std::u16string_view rThemeName
, sal_uInt32 nSdrModelPos
,
195 SdrModel
* pModel
, BitmapEx
* pThumb
)
197 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
202 SfxListener aListener
;
203 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
207 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(), nActPos
= 0; ( i
< nCount
) && !bRet
; i
++ )
209 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
211 if( nActPos
++ == nSdrModelPos
)
214 bRet
= pTheme
->GetModel(i
, *pModel
);
217 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
222 pGal
->ReleaseTheme( pTheme
, aListener
);
229 bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId
, sal_uInt32 nSdrModelPos
,
230 SdrModel
* pModel
, BitmapEx
* pThumb
)
232 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
233 return pGal
&& GetSdrObj( pGal
->GetThemeName( nThemeId
), nSdrModelPos
, pModel
, pThumb
);
236 bool GalleryExplorer::BeginLocking( std::u16string_view rThemeName
)
238 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
243 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, theLockListener::get() );
255 bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId
)
257 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
258 return pGal
&& BeginLocking( pGal
->GetThemeName( nThemeId
) );
261 bool GalleryExplorer::EndLocking( std::u16string_view rThemeName
)
263 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
268 SfxListener aListener
;
269 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
273 const bool bReleaseLockedTheme
= pTheme
->UnlockTheme();
275 // release acquired theme
276 pGal
->ReleaseTheme( pTheme
, aListener
);
278 if( bReleaseLockedTheme
)
280 // release locked theme
281 pGal
->ReleaseTheme( pTheme
, theLockListener::get() );
290 bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId
)
292 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
293 return pGal
&& EndLocking( pGal
->GetThemeName( nThemeId
) );
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */